function get_cat_selectlist($current_cat_id, $count) { static $option_results; global $tableprefix; // if there is no current category id set, start off at the top level (zero) if (!isset($current_cat_id)) { $current_cat_id = 0; } // increment the counter by 1 $count = $count + 1; // query the database for the sub-categories of whatever the parent category is $sql = "SELECT category_id as id, category_name as name\n\t\t FROM " . $tableprefix . "categories WHERE gift_certificate_flag !='Y' and parent_id = '" . addslashes($current_cat_id) . "' ORDER BY name ASC "; $get_options = mysql_query($sql); $num_options = mysql_num_rows($get_options); // our category is apparently valid, so go ahead €¦ if ($num_options > 0) { while (list($cat_id, $cat_name) = mysql_fetch_row($get_options)) { // if its not a top-level category, indent it to //show that its a child category if ($current_cat_id != 0) { $indent_flag = '-'; for ($x = 2; $x <= $count; $x++) { $indent_flag .= '-> '; } } $subcatCount = categoryHasChildren($cat_id); if ($subcatCount) { $leaf = 0; } else { $leaf = 1; } $cat_name = $indent_flag . $cat_name; $option_results[$cat_id] = array('category_name' => stripslashes($cat_name), "leaflevel" => $leaf, 'category_id' => $cat_id); // now call the function again, to recurse through the child categories get_cat_selectlist($cat_id, $count); } } return $option_results; }
mysql_query($del_opts); if (count($catOptArr)) { foreach ($catOptArr as $opt) { $sqlinsertcat = "INSERT INTO " . $tableprefix . "category_options(category_id,option_id)\n\t\t\t\t\t\t\t\t VALUES ('" . addslashes($catid) . "', '" . addslashes($opt) . "') "; mysql_query($sqlinsertcat); } } $update_message = "Category Updated Successfully !!"; header("Location:catalog.php?catid={$parentcatid}&message={$update_message}"); exit; } else { $message = "<br>Please correct the following errors to continue!<br>" . $message; } } else { if ($_POST["btnDelete"] == "Delete") { if (categoryHasChildren($catid)) { $message .= "Category in use! Please delete the subcategories to continue!<br>"; } if (categoryHasProducts($catid)) { $message .= "Category in use! Please delete the products in this category to continue!<br>"; } if ($message == "") { $sql = "DELETE FROM " . $tableprefix . "categories \n\t\tWHERE \tcategory_id = '" . addslashes($catid) . "'\n\t\t"; $res = mysql_query($sql); if (intval($parentcatid) == 0) { header("Location:catalog.php"); exit; } else { header("Location:catalog.php?catid={$parentcatid}"); exit; }