|
Administrator loginBog'liq Ilyos EQ
Go to front-end...
function deleteSubCategories($parent) //deletes all subcategories of
category with categoryID=$parent
{
//subcategories
$q = db_query("SELECT categoryID FROM ".CATEGORIES_TABLE."
WHERE parent=$parent and categoryID<>0") or die (db_error());
while ($row = db_fetch_row($q))
{
deleteSubCategories($row[0]); //recurrent call
}
$q = db_query("DELETE FROM ".CATEGORIES_TABLE." WHERE
parent=$parent and categoryID<>0") or die (db_error());
//move all product of this category to the root category
$q = db_query("UPDATE ".PRODUCTS_TABLE." SET categoryID=0
WHERE categoryID=$parent") or die (db_error());
}
function category_Moves_To_Its_SubDirectories($cid, $new_parent)
{
//return true/false
$a = false;
$q = db_query("SELECT categoryID FROM ".CATEGORIES_TABLE."
WHERE parent=$cid and categoryID<>0") or die (db_error());
while ($row = db_fetch_row($q))
{
if ($row[0] == $new_parent) $a = true;
else
$a =
category_Moves_To_Its_SubDirectories($row[0],$new_parent);
}
return $a;
}
if (!isset($w)) $w=-1; //parent
if (isset($_GET["picture_remove"])) //delete category thumbnail from
server
{
$q = db_query("SELECT picture FROM ".CATEGORIES_TABLE." WHERE
categoryID='".$_GET["c_id"]."' and categoryID<>0") or die (db_error());
$r = db_fetch_row($q);
if ($r[0] && file_exists("./products_pictures/$r[0]"))
unlink("./products_pictures/$r[0]");
db_query("UPDATE ".CATEGORIES_TABLE." SET picture='' WHERE
categoryID='".$_GET["c_id"]."'") or die (db_error());
}
if (isset($_POST["save"]) && $_POST["name"]) { //save changes
if (!isset($_POST["must_delete"])) //add new category
{
$q = db_query("INSERT INTO ".CATEGORIES_TABLE." (name,
parent, products_count, description, picture, products_count_admin) VALUES
('".$_POST["name"]."',".$_POST["parent"].",0,'".$_POST["desc"]."','',0)") or
die (db_error());
$pid = db_insert_id();
}
else //update existing category
{
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<>0 and
categoryID='".$_POST["must_delete"]."'") or die (db_error());
$r = db_fetch_row($q);
//lift up
db_query("UPDATE ".CATEGORIES_TABLE."
SET parent='$r[0]' WHERE parent='".$_POST["must_delete"]."'") or die
(db_error());
//move edited category
db_query("UPDATE ".CATEGORIES_TABLE."
SET name='".str_replace("<","<",$_POST["name"])."',
description='".$_POST["desc"]."', parent='".$_POST["parent"]."' WHERE
categoryID='".$_POST["must_delete"]."'") or die (db_error());
}
else //just move category
db_query("UPDATE ".CATEGORIES_TABLE."
SET name='".str_replace("<","<",$_POST["name"])."',
description='".$_POST["desc"]."', parent='".$_POST["parent"]."' WHERE
categoryID='".$_POST["must_delete"]."'") or die (db_error());
}
$pid = $_POST["must_delete"];
update_products_Count_Value_For_Categories(0);
}
if (isset($_FILES["picture"]) && $_FILES["picture"]["name"] &&
preg_match('/\.(jpg|jpeg|gif|jpe|pcx|bmp)$/i', $_FILES["picture"]["name"]))
//upload category thumbnail
{
//old picture
$q = db_query("SELECT picture FROM ".CATEGORIES_TABLE."
WHERE categoryID='$pid' and categoryID<>0") or die (db_error());
$row = db_fetch_row($q);
//upload new photo
$picture_name = str_replace(" ","_",
$_FILES["picture"]["name"]);
if (!move_uploaded_file($_FILES["picture"]["tmp_name"],
"./products_pictures/$picture_name")) //failed to upload
{
echo " color=red>".ERROR_FAILED_TO_UPLOAD_FILE."\n
\n";
echo "href=\"javascript:window.close();\">".CLOSE_BUTTON."
|
| |