ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/modules/product_music/delete_product_confirm.php
Go to the documentation of this file.
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     // Delete media components, but only if the product is no longer cross-linked to another:
00041     $resVal = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . "
00042                                    where products_id = '" . (int)$product_id . "'");
00043     if ($resVal->RecordCount() < 2) {
00044       // First we delete related records from related product-type tables:
00045       //echo 'SQL=' . "select media_id from " . TABLE_MEDIA_TO_PRODUCTS . " where product_id = '" . (int)$product_id . "'<br />";
00046 
00047       $product_media = $db->Execute("select media_id from " . TABLE_MEDIA_TO_PRODUCTS . "
00048                                      where product_id = '" . (int)$product_id . "'");
00049       //echo 'media count =' . $product_media->RecordCount() . '<br />';
00050       while (!$product_media->EOF) {
00051         //echo 'media delete=' . $product_media->fields['media_id'] . '<br />';
00052         $db->Execute("delete from " . TABLE_MEDIA_TO_PRODUCTS . "
00053                       where media_id='" . (int)zen_db_input($product_media->fields['media_id']) . "'
00054                       and product_id = '" . (int)$product_id . "'");
00055         $product_media->MoveNext();
00056       }
00057 
00058       //echo 'SQL=' . "select artists_id, record_company_id, music_genre_id from " . TABLE_PRODUCT_MUSIC_EXTRA . "                                 where products_id = '" . (int)$product_id . "'<br />";
00059       $music_extra = $db->Execute("select artists_id, record_company_id, music_genre_id from " . TABLE_PRODUCT_MUSIC_EXTRA . "
00060                                        where products_id = '" . (int)$product_id . "'");
00061       //echo 'media count =' . $music_extra->RecordCount() . '<br />';
00062       if ($music_extra->RecordCount()>0) {
00063         //echo 'artists_id delete=' . $music_extra->fields['artists_id'] . '<br />';
00064         //echo 'record_company_id delete=' . $music_extra->fields['record_company_id'] . '<br />';
00065         //echo 'music_genre_id delete=' . $music_extra->fields['music_genre_id'] . '<br />';
00066         $db->Execute("delete from " . TABLE_PRODUCT_MUSIC_EXTRA . "
00067                       where products_id = '" . (int)$product_id . "'
00068                       and artists_id = '" . zen_db_input($music_extra->fields['artists_id']) . "'
00069                       and record_company_id = '" . zen_db_input($music_extra->fields['record_company_id']) . "'
00070                       and music_genre_id = '" . zen_db_input($music_extra->fields['music_genre_id']) . "'");
00071       }
00072     }
00073 
00074     //--------------PRODUCT_TYPE_SPECIFIC_INSTRUCTIONS_GO__ABOVE__HERE--------------------------------------------------------
00075 
00076 
00077     // now do regular non-type-specific delete:
00078 
00079     // remove product from all its categories:
00080     for ($k=0, $m=sizeof($product_categories); $k<$m; $k++) {
00081       $db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . "
00082                     where products_id = '" . (int)$product_id . "'
00083                     and categories_id = '" . (int)$product_categories[$k] . "'");
00084     }
00085 
00086     // confirm that product is no longer linked to any categories
00087     $count_categories = $db->Execute("select count(categories_id) as total
00088                                       from " . TABLE_PRODUCTS_TO_CATEGORIES . "
00089                                       where products_id = '" . (int)$product_id . "'");
00090     // echo 'count of category links for this product=' . $count_categories->fields['total'] . '<br />';
00091 
00092     // if not linked to any categories, do delete:
00093     if ($count_categories->fields['total'] == '0') {
00094       zen_remove_product($product_id, $delete_linked);
00095     }
00096 
00097   } // endif $do_delete_flag
00098 
00099   // if this is a single-product delete, redirect to categories page
00100   // if not, then this file was called by the cascading delete initiated by the category-delete process
00101   if ($action == 'delete_product_confirm') zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
 All Data Structures Namespaces Files Functions Variables Enumerations