query("SELECT cid FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE 1"); if ($xoopsDB->getRowsNum($result) > 0){ $set = ''; while($row = $xoopsDB->fetchArray($result)) $set .= $row['cid'] . ','; $set = '('.substr($set, 0, -1).')'; $sql = "UPDATE ".$xoopsDB->prefix("xcgal_categories")." ". "SET parent = '0' ". "WHERE parent=cid OR parent NOT IN $set"; $result = $xoopsDB->queryf($sql); } } function get_subcat_data($parent, $ident='') { global $CAT_LIST, $xoopsDB, $myts; $sql = "SELECT cid, name, description ". "FROM ".$xoopsDB->prefix("xcgal_categories")." ". "WHERE parent = '$parent' ". "ORDER BY pos"; $result = $xoopsDB->query($sql); if (($cat_count = $xoopsDB->getRowsNum($result)) > 0){ $rowset = db_fetch_rowset($result); $pos=0; foreach ($rowset as $subcat){ if($pos>0){ $CAT_LIST[]=array( 'cid' => $subcat['cid'], 'parent' => $parent, 'pos' => $pos++, 'prev' => $prev_cid, 'cat_count' => $cat_count, 'name' => $ident.$myts->makeTboxData4Show($subcat['name'])); $CAT_LIST[$last_index]['next'] = $subcat['cid']; } else { $CAT_LIST[]=array( 'cid' => $subcat['cid'], 'parent' => $parent, 'pos' => $pos++, 'cat_count' => $cat_count, 'name' => $ident.$myts->makeTboxData4Show($subcat['name'])); } $prev_cid = $subcat['cid']; $last_index = count($CAT_LIST) -1; get_subcat_data($subcat['cid'], $ident.'   '); } } } function update_cat_order() { global $CAT_LIST, $xoopsDB; foreach ($CAT_LIST as $category) $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET pos='{$category['pos']}' WHERE cid = '{$category['cid']}' LIMIT 1"); } function cat_list_box($highlight=0, $curr_cat, $on_change_refresh = true) { global $CAT_LIST, $PHP_SELF, $myts; if($on_change_refresh){ $lb = <<< EOT EOT; } $lb .= ' \n"; foreach($CAT_LIST as $category) if ($category['cid'] != 1 && $category['cid'] != $curr_cat) { $lb .= ' \n"; } elseif ($category['cid'] != 1 && $category['cid'] == $curr_cat){ $lb .= ' \n"; } $lb .= << EOT; return $lb; } function display_cat_list() { global $CAT_LIST, $PHP_SELF, $myts; $CAT_LIST3 = $CAT_LIST; foreach ($CAT_LIST3 as $key => $category){ echo " \n"; echo ' '.$category['name'].''."\n"; if ($category['pos']>0) { echo ' '.''.''."\n"; } else { echo ' '.' '.''."\n"; } if ($category['pos'] < $category['cat_count']-1) { echo ' '.''.''."\n"; } else { echo ' '.' '.''."\n"; } if ($category['cid'] != 1) { echo ' '.''.''."\n"; } else { echo ' '.' '.''."\n"; } echo ' '.''.''.''."\n"; echo ' '."\n".cat_list_box($category['parent'], $category['cid'])."\n".''."\n"; echo " \n"; } } $op = isset($HTTP_GET_VARS['op']) ? $HTTP_GET_VARS['op'] : ''; $current_category = array('cid' => '0', 'name'=>'', 'parent' => '0', 'description'=>''); switch($op){ case 'move': if (!isset($HTTP_GET_VARS['cid1']) || !isset($HTTP_GET_VARS['cid2']) || !isset($HTTP_GET_VARS['pos1']) || !isset($HTTP_GET_VARS['pos2'])) redirect_header('index.php',2,sprintf(_AM_CAT_MISS_PARAM, 'move')); $cid1 = (int)$HTTP_GET_VARS['cid1']; $cid2 = (int)$HTTP_GET_VARS['cid2']; $pos1 = (int)$HTTP_GET_VARS['pos1']; $pos2 = (int)$HTTP_GET_VARS['pos2']; $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET pos='$pos1' WHERE cid = '$cid1' LIMIT 1"); $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET pos='$pos2' WHERE cid = '$cid2' LIMIT 1"); break; case 'setparent': if (!isset($HTTP_GET_VARS['cid']) || !isset($HTTP_GET_VARS['parent'])) redirect_header('index.php',2,sprintf(_AM_CAT_MISS_PARAM, 'setparent')); $cid = (int)$HTTP_GET_VARS['cid']; $parent = (int)$HTTP_GET_VARS['parent']; $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET parent='$parent', pos='-1' WHERE cid = '$cid' LIMIT 1"); break; case 'editcat': if (!isset($HTTP_GET_VARS['cid'])) redirect_header('index.php',2,sprintf(_AM_CAT_MISS_PARAM, 'editcat')); $cid = (int)$HTTP_GET_VARS['cid']; $result = $xoopsDB->query("SELECT cid, name, parent, description FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE cid = '$cid' LIMIT 1"); if(!$xoopsDB->getRowsNum($result)) redirect_header('index.php',2,_AM_CAT_UNKOWN); $current_category = $xoopsDB->fetchArray($result); break; case 'updatecat': if (!isset($HTTP_POST_VARS['cid']) || !isset($HTTP_POST_VARS['parent']) || !isset($HTTP_POST_VARS['name']) || !isset($HTTP_POST_VARS['description'])) redirect_header('index.php',2,_AM_CAT_MISS_PARAM, 'updatecat'); $cid = (int)$HTTP_POST_VARS['cid']; $parent = (int)$HTTP_POST_VARS['parent']; $name = trim($HTTP_POST_VARS['name']) ? $myts->makeTboxData4Save($HTTP_POST_VARS['name']) : '<???>'; $description = $myts->makeTareaData4Save($HTTP_POST_VARS['description']); $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET parent='$parent', name='$name', description='$description' WHERE cid = '$cid' LIMIT 1"); break; case 'createcat': if (!isset($HTTP_POST_VARS['parent']) || !isset($HTTP_POST_VARS['name']) || !isset($HTTP_POST_VARS['description'])) redirect_header('index.php',2,_AM_CAT_MISS_PARAM, 'createcat'); $parent = (int)$HTTP_POST_VARS['parent']; $name = trim($HTTP_POST_VARS['name']) ? $myts->makeTboxData4Save($HTTP_POST_VARS['name']) : '<???>'; $description = $myts->makeTareaData4Save($HTTP_POST_VARS['description']); $xoopsDB->query("INSERT INTO ".$xoopsDB->prefix("xcgal_categories")." (pos, parent, name, description) VALUES ('10000', '$parent', '$name', '$description')"); break; case 'deletecat': if (!isset($HTTP_GET_VARS['cid'])) redirect_header('index.php',2,sprintf(_AM_CAT_MISS_PARAM, 'deletecat')); $cid = (int)$HTTP_GET_VARS['cid']; $result = $xoopsDB->query("SELECT parent FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE cid = '$cid' LIMIT 1"); if($cid == 1) redirect_header('index.php',2,_AM_CAT_UGAL_CAT_RO); if(!$xoopsDB->getRowsNum($result)) redirect_header('index.php',2, _AM_CAT_UNKOWN); $del_category = $xoopsDB->fetchArray($result); $parent = $del_category['parent']; $result = $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_categories")." SET parent='$parent' WHERE parent = '$cid'"); $result = $xoopsDB->queryf("UPDATE ".$xoopsDB->prefix("xcgal_albums")." SET category='$parent' WHERE category = '$cid'"); $result = $xoopsDB->queryf("DELETE FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE cid='$cid' LIMIT 1"); break; } fix_cat_table(); get_subcat_data(0); update_cat_order(); xoops_cp_header(); echo " "; //starttable('100%'); echo " "; display_cat_list(); echo ""; echo "
"._AM_CAT_MNGCAT."
"._AM_CAT_CAT." "._AM_CAT_OP." "._AM_CAT_MOVE."

\n"; $lb = cat_list_box($current_category['parent'], $current_category['cid'], false); $op = $current_category['cid'] ? 'updatecat' : 'createcat'; $current_category['name']= $myts->makeTboxData4Edit($current_category['name']); $current_category['description']= $myts->makeTareaData4Edit($current_category['description']); echo << EOT; echo _AM_CAT_UPCR; echo <<
EOT; echo _AM_CAT_PARENT; echo << $lb EOT; echo _AM_CAT_TITLE; echo << EOT; echo _AM_CAT_DESC; echo << EOT; echo ""; echo ""; //endtable(); //pagefooter(); //ob_end_flush(); xoops_cp_footer(); ?>