isLoggedIn()) doError('You\'re not logged in.'); include($DIR_LIBS . 'PLUGINADMIN.php'); // create the admin area page $oPluginAdmin = new PluginAdmin('MultipleCategories'); // ------------------------------------------------------------------ class NpMCategories_ADMIN { function NpMCategories_ADMIN() { global $oPluginAdmin; $this->plug =& $oPluginAdmin->plugin; $this->plugname = $this->plug->getName(); $this->url = $this->plug->getAdminURL(); $this->table = sql_table('plug_multiple_categories_sub'); //modify start+++++++++ $this->version = $this->plug->checkMSCVersion(); // include language file for this plugin // $language = ereg_replace( '[\\|/]', '', getLanguageName()); $language = preg_replace( '![\\|/]!', '', getLanguageName()); if (file_exists($this->plug->getDirectory().'language/'.$language.'.php')) include_once($this->plug->getDirectory().'language/'.$language.'.php'); else include_once($this->plug->getDirectory().'language/'.'english.php'); //modify end+++++++++ } //------------------- function action_overview($msg='') { global $member, $oPluginAdmin; global $manager; // $member->isAdmin() or $this->disallow(); $oPluginAdmin->start(); echo '

('._PLUGS_BACK.')

'; echo '

' .$this->plugname. '

'."\n"; if ($msg) echo "

"._MESSAGE.": $msg

"; echo '

['._MC_EDIT_PLUGIN_OPTIONS.']

'; //modify start+++++++++ if($this->version == 2){ echo '
Upgarde Information:
'; echo _MC_SCAT_TABLE_UPDATE_INFO; ?>
$manager->addTicketHidden(); // ?>
'; } $res = sql_query('SELECT bnumber, bname FROM '.sql_table('blog')); while ($o = mysql_fetch_object($res)) { echo '

' . htmlspecialchars($o->bname) . '

'; ?> plug->_getCategories($o->bnumber); foreach ($cats as $cat) { $snum = quickQuery("SELECT count(*) as result FROM ".$this->table." WHERE catid=".intval($cat['catid']));// $snum = intval($snum); ?>
end(); } //----- function action_scatoverview($msg = '') { global $member, $oPluginAdmin; global $manager; // $member->isAdmin() or $this->disallow(); $catid = intRequestVar('catid'); $catname = $this->plug->_getCatNameFromID($catid); $oPluginAdmin->start(); ?>

(Go Back)

\n"; if ($msg) echo "

"._MESSAGE.": $msg

"; $defines = $this->plug->_getDefinedScats($catid); if (count($defines) > 0) { //modify start+++++++++ if($this->version > 2){ echo $this->listupSubcategories($catid, $subcatid); echo $this->showOrderMenu($catid, $subcatid); }else{ //modify end+++++++++ ?>
0) echo "\n\n".'

'._MC_CREATE_NEW_SUB_CATEGORY.'

'."\n\n"; ?>
$manager->addTicketHidden(); // ?> version > 2){ ?>
getCategoryList($catid); echo $this->printCategoryList($catid, $subcategoryList, 1, 0); ?>
end(); } function action_scatedit($msg = '') {//----- global $member, $oPluginAdmin; global $manager; // $member->isAdmin() or $this->disallow(); $scatid = intRequestVar('scatid'); $catid = intRequestVar('catid'); $res = sql_query("SELECT * FROM ".$this->table." WHERE scatid=$scatid and catid=$catid"); if ($o = mysql_fetch_object($res)) { $oPluginAdmin->start(); ?>

(Go Back to OVERVIEW)

sname)."'

\n"; if ($msg) echo "

"._MESSAGE.": $msg

"; ?>
$manager->addTicketHidden(); // ?>
version > 2){ ?>
' . _MC_SCAT_PARENT_NAME_DESC ?> table.' WHERE scatid='.$scatid); // //$subcategoryList = $this->getCategoryList($catid, $pid); //echo $this->printCategoryList($catid, $subcategoryList, 1); echo $this->printCategoryListUD($catid, $pid); // ?>
version > 2) echo $this->showOrderMenu($catid, $scatid); $oPluginAdmin->end(); } else $this->error(_MC_SCAT_MISSING); }//----- function action_scatnew() { global $member; $member->isAdmin() or $this->disallow(); $sname = postVar('sname'); if (!trim($sname)){ $this->action_scatoverview(_MC_SCAT_ERROR_NAME); } else{ $newid = $this->createSubcat($sname); $array = array( 'catid'=>postVar('catid'), 'sdesc'=>postVar('sdesc') ); if($this->version > 2) $array['parentid'] = postVar('parentid'); $this->updateSubcat($newid,$array); $this->action_scatoverview(); } } function action_scatupdate() { global $member; $scatid = intRequestVar('scatid'); $member->isAdmin() or $this->disallow(); $sname = postVar('sname'); if (!trim($sname)) { $this->action_scatoverview("Error! Input a name."); } else { $this->addToScat($scatid); $this->action_scatedit(_MC_SCAT_DATA_UPDATE); } } //modify start+++++++++ function action_tableUpgrade() { if($this->version == 2){ $q = "ALTER TABLE `".$this->table."` ADD `parentid` INT( 11 ) DEFAULT '0' NOT NULL AFTER `scatid` , ADD `ordid` INT( 11 ) DEFAULT '100' NOT NULL AFTER `parentid` ;"; }elseif($this->version == 3){ $q = "ALTER TABLE `".$this->table."` ADD `ordid` INT( 11 ) DEFAULT '100' NOT NULL AFTER `parentid` ;"; } if($q) sql_query($q); $this->version = 4; $this->action_overview('
'._MC_SCAT_TABLE_UPDATE.'
'); } function action_scatOrder() { global $member; $scatid = intRequestVar('scatid'); $member->isAdmin() or $this->disallow(); $order = array(); $order = explode(",", requestVar('orderList')); $x=1; foreach($order as $o){ $o = trim(rtrim($o)); $query = 'UPDATE '.$this->table.' SET ordid='.intval($x).' WHERE scatid='.intval($o); //ultrarich sql_query($query); $x++; } if(requestVar('redirect') == 'scatoverview'){ $this->action_scatoverview(_MC_SCAT_ORDER_UPDATE); }else{ $this->action_scatedit(_MC_SCAT_ORDER_UPDATE); } } //modify end+++++++++ function action_scatdelete() { global $member, $oPluginAdmin; global $manager; // $member->isAdmin() or $this->disallow(); $scatid = intRequestVar('scatid'); $catid = intRequestVar('catid'); //modify start+++++++++ if($this->version > 2){ $sname = $this->plug->_getScatNameFromID($scatid); $sdesc = $this->plug->_getScatDescFromID($scatid); if($sdesc) $sdesc = ' ('.$sdesc.')'; $modChildren = $this->_getDefinedScatsFromScat($scatid); $pid = quickQuery('SELECT parentid as result FROM '.$this->table.' WHERE scatid='.intval($scatid)); //ultrarich $pid = intval($pid); //ultrarich $pname = ($pid)? $this->plug->_getScatNameFromID($pid).' ('._MC_SUB_CATEGORIES.')': quickQuery('SELECT cname as result FROM '.sql_table('category').' WHERE catid='.intval($catid)).' (' . _EBLOG_CAT_TITLE . ')'; } //modify end+++++++++ $oPluginAdmin->start(); ?>

?>

Note:
'; echo _MC_SCAT_DELETE_NOTE_LIST; echo '
    '; for($i=0;$i'.htmlspecialchars($modChildren[$i]['sname'], ENT_QUOTES)."\n"; // $modList .= intval($modChildren[$i]['scatid']).'/'; //ultrarich } echo '
'; echo _MC_SCAT_DELETE_NOTE_PARENT.'
  • '.htmlspecialchars($pname, ENT_QUOTES).'
'; // echo '
'; $extraInput = ''."\n"; } ?>
$manager->addTicketHidden(); // ?>
end(); } function action_scatdeleteconfirm() { global $member, $manager; $scatid = intRequestVar('scatid'); $catid = intRequestVar('catid'); $member->isAdmin() or $this->disallow(); //modify start+++++++++ $modList = requestVar('modlist'); if($modList){ list($parent, $children) = explode("-", $modList); $children = explode("/", $children); for($i=0;$itable.' SET parentid='.intval($parent).' WHERE scatid='.intval($c); //ultrarich sql_query($query); } } //modify end+++++++++ $this->deleteSubcat($scatid); $this->action_scatoverview("Sub category has been deleted."); } function addToScat($nowid) { if($this->version >= 3) $datanames = array('catid','sname','sdesc','parentid'); else $datanames = array('catid','sname','sdesc'); foreach ($datanames as $val) { $scat[$val] = postVar($val); } $this->updateSubcat($nowid,$scat); } function createSubcat($name) { sql_query('INSERT INTO '.$this->table.' SET sname="'. addslashes($name) .'"'); $newid = mysql_insert_id(); global $manager; $manager->notify( 'PostAddSubcat', array( 'subcatid' => $newid ) ); return $newid; } // //printCategoryList for update function printCategoryListUD($catid, $parentid) { $catName = quickQuery('SELECT cname as result FROM '.sql_table('category').' WHERE catid='.intval($catid)); $catName = htmlspecialchars($catName, ENT_QUOTES); // $text .= "\n"; return $text; } function getDepth($scatid, $level) { $parentid = quickQuery('SELECT parentid as result FROM '.$this->table.' WHERE scatid='.$scatid); return ($parentid == 0) ? $level : $this->getDepth($parentid, $level + 1); } function descendantCheck($parentid, $checkid){ $res = sql_query("SELECT scatid FROM ".$this->table." WHERE parentid=".intval($parentid)); // while ($o = mysql_fetch_object($res)) { if ($o->scatid == $checkid) { return TRUE; } else { if ($this->descendantCheck($o->scatid, $checkid)) return TRUE; } } return FALSE; } // function updateSubcat($id, $scat) { // $old_parentid = quickQuery('SELECT parentid as result FROM '.$this->table.' WHERE scatid='.$id); if ($id == $scat['parentid']) $branch = 'Self'; else $branch = ($this->descendantCheck($id, $scat['parentid']) ? 'Descendant' : 'Other'); switch ($branch){ case 'Self': //cancel $scat['parentid'] = $old_parentid; //echo '----------------------------------------Self'; break; case 'Descendant': //Succession //echo '----------------------------------------Descendant'; $query = 'UPDATE '.$this->table.' SET parentid='.intval($old_parentid).' WHERE parentid='.intval($id); // sql_query($query); break; case 'Other': //Nothing is done. //echo '----------------------------------------Other'; } // $query = 'UPDATE '.$this->table.' SET '; foreach ($scat as $k => $v) { $query .= $k.'="'.addslashes($v).'",'; } $query = substr($query,0,-1); $query .= ' WHERE scatid='.intval($id); // sql_query($query); } function deleteSubcat($id) { $id = intval($id); // sql_query('DELETE FROM '.$this->table.' WHERE scatid=' . $id); global $manager; $manager->notify( 'PostDeleteSubcat', array( 'subcatid' => $id ) ); $res = sql_query("SELECT categories, subcategories, item_id FROM ". sql_table("plug_multiple_categories") ." WHERE subcategories REGEXP '(^|,)$id(,|$)'"); $dell = array(); $up = array(); while ($o = mysql_fetch_object($res)) { $o->subcategories = preg_replace("/^(?:(.*),)?$catid(?:,(.*))?$/","$1,$2",$o->subcategories); if (!$o->categories && (!$o->subcategories || $o->subcategories == ',')) { $del[] = intval($o->item_id); //ultrarich } else { $o->subcategories = preg_replace("/(^,+|(?<=,),+|,+$)/","",$o->subcategories); $up[] = "UPDATE ". sql_table("plug_multiple_categories") ." SET categories='".addslashes($o->categories)."', subcategories='".addslashes($o->subcategories)."' WHERE item_id=".$o->item_id; } } if (count($del) > 0) { sql_query("DELETE FROM ". sql_table("plug_multiple_categories") . " WHERE item_id in (".implode(",",$del).")"); } if (count($up) > 0) { foreach ($up as $v) { sql_query($v); } } } function action($action) { // global $manager; $methodName = 'action_' . $action; $this->action = strtolower($action); $aActionsNotToCheck = array( 'overview', 'scatoverview', 'scatedit', 'scatdelete', ); if (!in_array($this->action, $aActionsNotToCheck)) { if (!$manager->checkTicket()) $this->error(_ERROR_BADTICKET); } // if (method_exists($this, $methodName)) { call_user_func(array(&$this, $methodName)); } else { $this->error(_BADACTION . " ($action)"); } } function disallow() { global $HTTP_SERVER_VARS; ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . $HTTP_SERVER_VARS['REQUEST_URI']); $this->error(_ERROR_DISALLOWED); } function error($msg) { global $oPluginAdmin; $oPluginAdmin->start(); $dir=$oPluginAdmin->plugin->getAdminURL(); ?>

Error!

"; echo ""._BACK.""; $oPluginAdmin->end(); exit; } //modify start+++++++++ /* START OF UNLIMITED DEPTH SUBCATEGORY HELPER FUNCTIONS */ function listupSubcategories($catid, $subcatid){ $cat .= "
\n"; $cat .= "\n"; $subcategoryList = $this->getCategoryList($catid); //print_r($subcategoryList); $subcategories = $this->printCategoryList($catid, $subcategoryList, 2, 0); if ($subcategories == "") { $cat .= "No subcategories currently exist in this category.\n"; } else { $cat .= $subcategories; } $cat .= "
\n"; $cat .= "
\n"; return $cat; } function showOrderMenu($catid, $subcatid=0){// global $manager; // $text = "

"._MC_MODIFY_CHILDREN_ORDER."

\n"; if ($sorder = $this->subcatOrd($catid, $subcatid)){ $text .= "\n"; $text .= "\n"; $text .= "\n"; $text .= "\n"; $text .= "\n"; // $text .= "\n"; $text .= "\n"; // global $CONF; $actionUrl = htmlspecialchars($CONF['ActionURL'], ENT_QUOTES). '?action=plugin&name=MultipleCategories&catid='.intval($catid).'&subcatid='.intval($subcatid); // echo ''; $text .= ' '; // $text .= $sorder; $text .= "\n"; $text .= "
'._MC_SHOW_ORDER_MENU_KEY.'
ID Move Up
Move Down
[ '._MC_SHOW_ORDER_MENU_SNAME.' ] Move Up
Move Down
'._MC_SHOW_ORDER_MENU_SDESC.' Move Up
Move Down
\n"; } else { $text .= _MC_NO_CHILDREN_ORDER; } return $text; } function getCategoryList($catid, $selected = 0) {//$selected : parentid /** Returns a list of the gallery categories **/ $queryString = "SELECT * FROM ".$this->table; $queryString .= " WHERE catid=".intval($catid); // $queryString .= ($this->version >= 4)? " ORDER BY parentid ASC, ordid ASC, scatid ASC" : " ORDER BY scatid ASC"; $resultSet = sql_query($queryString); $categoryArray = array(); $flatList = array(); if (!mysql_num_rows($resultSet)) return $categoryArray; while ($row = mysql_fetch_array($resultSet)) { $isSelected = ($row["scatid"] == $selected)?1:0; $flatList[] = array( // "id" => intval($row["scatid"]), "title" => htmlspecialchars($row['sname'], ENT_QUOTES), "description" => htmlspecialchars($row['sdesc'], ENT_QUOTES), "children" => array(), "parent" => intval($row["parentid"]), // "selected" => $isSelected ); } while (count($flatList)) { // Check the first one in the list $temp = array_shift($flatList); // Is it a top level category? if ($temp["parent"] == 0 || $temp["id"] == $selected) { // No parent, so just push it to the end of the big array $categoryArray[] = $temp; } else { // Has a parent, so search for parent, and push it to the end of the parent's child array if (!$this->appendChildCategory($categoryArray, $temp)) { // Failed, so push category back onto the end of the array $flatList[] = $temp; } } } return $categoryArray; } function appendChildCategory(&$categoryArray, $child) { if (empty($categoryArray)) return false; for($i=0; $iappendChildCategory($category["children"], $child)) { return true; } } } return false; } function printCategoryList($catid, $categoryList, $type=1, $selectedCategory=0, $def='') { $text = ""; $catName = quickQuery('SELECT cname as result FROM '.sql_table('category').' WHERE catid='.intval($catid)); $catName = htmlspecialchars($catName, ENT_QUOTES); // if ($type == 1) { // Select box $text .= "\n"; } elseif ($type == 2) { // Table: with action cell $text .= " $catName "._LISTS_ACTIONS."\n"; $text .= $this->walkCategoryList($categoryList, $catid, $type, $selectedCategory); } elseif ($type == 3) { // $selected = ($selectedCategory == 0) ? " selected='selected'" : ''; $text .= "\n"; $text .= $this->walkCategoryList($categoryList, $catid, $type, $selectedCategory); } return $text; } function walkCategoryList(&$categoryList, $catid, $type = 1, $selectedCategory = 0, $level = 0, $childrenLevel = array()) { $text = ""; if ($type == 1) { // Select box foreach ($categoryList as $category) { if ($category["selected"] == 1) { $text .= "\n"; // $text .= $this->walkCategoryList($category["children"], $catid, $type, $selectedCategory, $level+1); } } elseif ($type == 2) { // Table for ($j=0; $j < count($categoryList); $j++) { $category = $categoryList[$j]; $hasSiblings = (($j < (count($categoryList)-1))?1:0); // are there more categories on the same level as this category? $childrenLevel[$level] = $hasSiblings; $children = $this->walkCategoryList($category["children"], $catid, $type, $selectedCategory, $level+1, $childrenLevel); if ($selectedCategory == $category["id"]) { $text .= "\n"; } else { $text .= "\n"; } $text .= "\n"; if ($level == 0) { if ($hasSiblings) { $text .= " \n"; } else { $text .= " \n"; } } else { for ($i=0;$i<$level;$i++) { if ($childrenLevel[$i]) { $text .= " \n"; } else { $text .= ""; } } if ($hasSiblings) { if ($children != "") { $text .= " \n"; } else { $text .= " \n"; } } else { if ($children != "") { $text .= " \n"; } else { $text .= " \n"; } } } if ($row[group] != 0){ $group = "(Private)"; } else { $group = ''; } if ($selectedCategory == $category["id"]) { $text .= "".htmlspecialchars($category["title"], ENT_QUOTES). " ".htmlspecialchars($category["description"], ENT_QUOTES).""." $group\n"; } else { $text .= htmlspecialchars($category["title"], ENT_QUOTES). " ".htmlspecialchars($category["description"], ENT_QUOTES).""." $group\n"; } $subcatid = $category["id"]; if ($type == 2) { // ALL ACTIONS // $text .= "url}index.php?action=scatedit&catid=$catid&scatid=$subcatid>"._LISTS_EDIT." \nurl}index.php?action=scatdelete&catid=$catid&scatid=$subcatid>"._LISTS_DELETE."\n"; } $text .= "\n"; $text .= $children; } } elseif ($type == 3) { // Select box foreach ($categoryList as $category) { if ($category["id"] == $selectedCategory) { $text .= "\n"; $text .= $this->walkCategoryList($category["children"], $catid, $type, $selectedCategory, $level+1); } } return $text; } function subcatOrd($catid, $subcatid=0){ // $catid = intval($catid); $subcatid = intval($subcatid); // $q = "select scatid, sname, sdesc from ".$this->table." where parentid = '$subcatid' and catid=$catid";// $q .= ($this->version >= 4) ? ' order by ordid, scatid ASC': ' order by scatid ASC'; $result = sql_query($q); if(mysql_num_rows($result) < 2){ return FALSE; } $text .= ""._MC_SHOW_ORDER_MENU_INDIVIDUAL." "; // $text .= "Move Up "; $text .= "Move Down"; return $text; } function _getDefinedScatsFromScat($id){ $aResult = array(); $query = 'SELECT * FROM '.sql_table('plug_multiple_categories_sub').' WHERE parentid=' . intval($id); $res = sql_query($query); while ($a = mysql_fetch_assoc($res)){ array_push($aResult,$a); } return $aResult; } //modify end+++++++++ } // NpMCategories_ADMIN end // ------------------------------------------------------------------ $myAdmin = new NpMCategories_ADMIN(); if (requestVar('action')) { $myAdmin->action(requestVar('action')); } else { $myAdmin->action('overview'); } ?>