|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00010 if (!defined('IS_ADMIN_FLAG')) { 00011 die('Illegal Access'); 00012 } 00013 // NOTE: Debug code left in to help with creating additional product type delete-scripts 00014 00015 // test if demo mode active 00016 if (zen_admin_demo()) { 00017 $_GET['action']= ''; 00018 $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution'); 00019 zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $_GET['cPath'] . '&pID=' . $_GET['pID'] . (isset($_GET['page']) ? '&page=' . $_GET['page'] : ''))); 00020 } 00021 00022 $do_delete_flag = false; 00023 //echo 'products_id=' . $_POST['products_id'] . '<br />'; 00024 if (isset($_POST['products_id']) && isset($_POST['product_categories']) && is_array($_POST['product_categories'])) { 00025 $product_id = zen_db_prepare_input($_POST['products_id']); 00026 $product_categories = $_POST['product_categories']; 00027 $do_delete_flag = true; 00028 if (!isset($delete_linked)) $delete_linked = 'true'; 00029 } 00030 00031 if (zen_not_null($cascaded_prod_id_for_delete) && zen_not_null($cascaded_prod_cat_for_delete) ) { 00032 $product_id = $cascaded_prod_id_for_delete; 00033 $product_categories = $cascaded_prod_cat_for_delete; 00034 $do_delete_flag = true; 00035 // no check for $delete_linked here, because it should already be passed from categories.php 00036 } 00037 00038 if ($do_delete_flag) { 00039 //--------------PRODUCT_TYPE_SPECIFIC_INSTRUCTIONS_GO__BELOW_HERE-------------------------------------------------------- 00040 00041 00042 //--------------PRODUCT_TYPE_SPECIFIC_INSTRUCTIONS_GO__ABOVE__HERE-------------------------------------------------------- 00043 00044 00045 // now do regular non-type-specific delete: 00046 00047 // remove product from all its categories: 00048 for ($k=0, $m=sizeof($product_categories); $k<$m; $k++) { 00049 $db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " 00050 where products_id = '" . (int)$product_id . "' 00051 and categories_id = '" . (int)$product_categories[$k] . "'"); 00052 } 00053 // confirm that product is no longer linked to any categories 00054 $count_categories = $db->Execute("select count(categories_id) as total 00055 from " . TABLE_PRODUCTS_TO_CATEGORIES . " 00056 where products_id = '" . (int)$product_id . "'"); 00057 // echo 'count of category links for this product=' . $count_categories->fields['total'] . '<br />'; 00058 00059 // if not linked to any categories, do delete: 00060 if ($count_categories->fields['total'] == '0') { 00061 zen_remove_product($product_id, $delete_linked); 00062 } 00063 00064 } // endif $do_delete_flag 00065 00066 // if this is a single-product delete, redirect to categories page 00067 // if not, then this file was called by the cascading delete initiated by the category-delete process 00068 if ($action == 'delete_product_confirm') zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath)); 00069 ?>