function category_Moves_To_Its_SubDirectories($cid, $new_parent) { $a = false; $q = db_query("select categoryID FROM " . CATEGORIES_TABLE . " WHERE parent=" . (int) $cid . " and categoryID>1"); while ($row = db_fetch_row($q)) { if (!$a) { if ($row[0] == $new_parent) { return true; } else { $a = category_Moves_To_Its_SubDirectories($row[0], $new_parent); } } } return $a; }
meta_keywords="' . xToText(trim($_POST["meta_k"])) . '", title="' . xToText(trim($_POST["title"])) . '"'; $q = db_query($sql); $pid = db_insert_id("CATEGORIES_GEN"); } else { //update existing category if (isset($_POST["removeto"])) { if ($_POST["removeto"] != "zero") { db_query("update " . PRODUCTS_TABLE . " SET categoryID=" . (int) $_POST["removeto"] . " WHERE categoryID=" . (int) $_POST["must_delete"]); } } if ($_POST["must_delete"] != $_POST["parent"]) { //if not moving category to itself //if category is being moved to any of it's subcategories - it's //neccessary to 'lift up' all it's subcategories if (category_Moves_To_Its_SubDirectories($_POST["must_delete"], $_POST["parent"])) { //lift up is required //get parent $q = db_query("select parent FROM " . CATEGORIES_TABLE . " WHERE categoryID=" . (int) $_POST["must_delete"]); $r = db_fetch_row($q); //lift up db_query("update " . CATEGORIES_TABLE . " SET parent=" . (int) $r[0] . " WHERE parent=" . (int) $_POST["must_delete"]); } $sql = ' UPDATE ' . CATEGORIES_TABLE . ' SET name="' . xToText(trim($_POST["name"])) . '", description="' . xEscSQL($_POST["desc"]) . '", description2="' . xEscSQL($_POST["desc2"]) . '", zapros="' . xEscSQL($_POST["zapros"]) . '", parent=' . (int) $_POST['parent'] . ',