예제 #1
0
 public static function delete($id, $categories = null)
 {
     global $lC_Database;
     $lC_Image = new lC_Image_Admin();
     $delete_product = true;
     $error = false;
     $lC_Database->startTransaction();
     if (is_array($categories) && !empty($categories)) {
         $Qpc = $lC_Database->query('delete from :table_products_to_categories where products_id = :products_id and categories_id in :categories_id');
         $Qpc->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
         $Qpc->bindInt(':products_id', $id);
         $Qpc->bindRaw(':categories_id', '("' . implode('", "', $categories) . '")');
         $Qpc->setLogging($_SESSION['module'], $id);
         $Qpc->execute();
         if (!$lC_Database->isError()) {
             $Qcheck = $lC_Database->query('select products_id from :table_products_to_categories where products_id = :products_id limit 1');
             $Qcheck->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qcheck->bindInt(':products_id', $id);
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() > 0) {
                 $delete_product = false;
             }
         } else {
             $error = true;
         }
     }
     if ($error === false && $delete_product === true) {
         $Qvariants = $lC_Database->query('select products_id from :table_products where parent_id = :parent_id');
         $Qvariants->bindTable(':table_products', TABLE_PRODUCTS);
         $Qvariants->bindInt(':parent_id', $id);
         $Qvariants->execute();
         while ($Qvariants->next()) {
             $Qsc = $lC_Database->query('delete from :table_shopping_carts where products_id = :products_id');
             $Qsc->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
             $Qsc->bindInt(':products_id', $Qvariants->valueInt('products_id'));
             $Qsc->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
             if ($error === false) {
                 $Qsccvv = $lC_Database->query('delete from :table_shopping_carts_custom_variants_values where products_id = :products_id');
                 $Qsccvv->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
                 $Qsccvv->bindInt(':products_id', $Qvariants->valueInt('products_id'));
                 $Qsccvv->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                 }
             }
             if ($error === false) {
                 $Qpa = $lC_Database->query('delete from :table_products_variants where products_id = :products_id');
                 $Qpa->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qpa->bindInt(':products_id', $Qvariants->valueInt('products_id'));
                 $Qpa->setLogging($_SESSION['module'], $id);
                 $Qpa->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                 }
             }
             if ($error === false) {
                 $Qp = $lC_Database->query('delete from :table_products where products_id = :products_id');
                 $Qp->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qp->bindInt(':products_id', $Qvariants->valueInt('products_id'));
                 $Qp->setLogging($_SESSION['module'], $id);
                 $Qp->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                 }
             }
             // QPB
             if ($error === false) {
                 $Qpb = $lC_Database->query('delete from :table_products_pricing where products_id = :products_id');
                 $Qpb->bindTable(':table_products_pricing', TABLE_PRODUCTS_PRICING);
                 $Qpb->bindInt(':products_id', $Qvariants->valueInt('products_id'));
                 $Qpb->setLogging($_SESSION['module'], $id);
                 $Qpb->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                 }
             }
         }
         if ($error === false) {
             $Qr = $lC_Database->query('delete from :table_reviews where products_id = :products_id');
             $Qr->bindTable(':table_reviews', TABLE_REVIEWS);
             $Qr->bindInt(':products_id', $id);
             $Qr->setLogging($_SESSION['module'], $id);
             $Qr->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qsc = $lC_Database->query('delete from :table_shopping_carts where products_id = :products_id');
             $Qsc->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
             $Qsc->bindInt(':products_id', $id);
             $Qsc->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qsccvv = $lC_Database->query('delete from :table_shopping_carts_custom_variants_values where products_id = :products_id');
             $Qsccvv->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
             $Qsccvv->bindInt(':products_id', $id);
             $Qsccvv->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qp2c = $lC_Database->query('delete from :table_products_to_categories where products_id = :products_id');
             $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qp2c->bindInt(':products_id', $id);
             $Qp2c->setLogging($_SESSION['module'], $id);
             $Qp2c->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qs = $lC_Database->query('delete from :table_specials where products_id = :products_id');
             $Qs->bindTable(':table_specials', TABLE_SPECIALS);
             $Qs->bindInt(':products_id', $id);
             $Qs->setLogging($_SESSION['module'], $id);
             $Qs->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qpa = $lC_Database->query('delete from :table_products_variants where products_id = :products_id');
             $Qpa->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
             $Qpa->bindInt(':products_id', $id);
             $Qpa->setLogging($_SESSION['module'], $id);
             $Qpa->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qpd = $lC_Database->query('delete from :table_products_description where products_id = :products_id');
             $Qpd->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qpd->bindInt(':products_id', $id);
             $Qpd->setLogging($_SESSION['module'], $id);
             $Qpd->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qp = $lC_Database->query('delete from :table_products where products_id = :products_id');
             $Qp->bindTable(':table_products', TABLE_PRODUCTS);
             $Qp->bindInt(':products_id', $id);
             $Qp->setLogging($_SESSION['module'], $id);
             $Qp->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         if ($error === false) {
             $Qim = $lC_Database->query('select id, image from :table_products_images where products_id = :products_id');
             $Qim->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qim->bindInt(':products_id', $id);
             $Qim->execute();
             // added to check for other products using same image and do not delete
             $Qop = $lC_Database->query('select id from :table_products_images where image = :image');
             $Qop->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qop->bindInt(':image', $Qim->value('image'));
             $Qop->execute();
             if ($Qop->numberOfRows() < 2) {
                 while ($Qim->next()) {
                     $lC_Image->delete($Qim->valueInt('id'));
                 }
             }
         }
         // featured products
         if ($error === false) {
             $Qfp = $lC_Database->query('delete from :table_featured_products where products_id = :products_id');
             $Qfp->bindTable(':table_featured_products', TABLE_FEATURED_PRODUCTS);
             $Qfp->bindInt(':products_id', $id);
             $Qfp->setLogging($_SESSION['module'], $id);
             $Qfp->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         // QPB
         if ($error === false) {
             $Qpb = $lC_Database->query('delete from :table_products_pricing where products_id = :products_id');
             $Qpb->bindTable(':table_products_pricing', TABLE_PRODUCTS_PRICING);
             $Qpb->bindInt(':products_id', $id);
             $Qpb->setLogging($_SESSION['module'], $id);
             $Qpb->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
         // permalink
         if ($error === false) {
             $Qpb = $lC_Database->query('delete from :table_permalinks where item_id = :item_id');
             $Qpb->bindTable(':table_permalinks', TABLE_PERMALINKS);
             $Qpb->bindInt(':item_id', $id);
             $Qpb->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             }
         }
     }
     // delete subproducts
     if ($error === false && $delete_product === true) {
         $Qcheck = $lC_Database->query('select products_id from :table_products where parent_id = :parent_id');
         $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
         $Qcheck->bindInt(':parent_id', $id);
         $Qcheck->execute();
         while ($Qcheck->next()) {
             // delete the description data
             $Qdel = $lC_Database->query('delete from :table_products_description where products_id = :products_id');
             $Qdel->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
             $Qdel->setLogging($_SESSION['module'], $id);
             $Qdel->execute();
             // delete the image data
             $Qdel = $lC_Database->query('delete from :table_products_images where products_id = :products_id');
             $Qdel->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
             $Qdel->setLogging($_SESSION['module'], $id);
             $Qdel->execute();
         }
         // delete the subproduct
         $Qdel = $lC_Database->query('delete from :table_products where products_id = :products_id');
         $Qdel->bindTable(':table_products', TABLE_PRODUCTS);
         $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
         $Qdel->setLogging($_SESSION['module'], $id);
         $Qdel->execute();
         if ($lC_Database->isError()) {
             $error = true;
         }
     }
     // delete simple options
     if ($error === false && $delete_product === true) {
         $Qcheck = $lC_Database->query('select options_id from :table_products_simple_options where products_id = :products_id');
         $Qcheck->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS);
         $Qcheck->bindInt(':products_id', $id);
         $Qcheck->execute();
         // delete the simple options values
         while ($Qcheck->next()) {
             $Qdel = $lC_Database->query('delete from :table_products_simple_options_values where options_id = :options_id AND products_id = :products_id');
             $Qdel->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES);
             $Qdel->bindInt(':options_id', $Qcheck->valueInt('options_id'));
             $Qdel->bindInt(':products_id', $id);
             $Qdel->setLogging($_SESSION['module'], $id);
             $Qdel->execute();
         }
         // delete the simple option
         $Qdel = $lC_Database->query('delete from :table_products_simple_options where products_id = :products_id');
         $Qdel->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS);
         $Qdel->bindInt(':products_id', $id);
         $Qdel->setLogging($_SESSION['module'], $id);
         $Qdel->execute();
         $Qcheck->freeResult();
         if ($lC_Database->isError()) {
             $error = true;
         }
     }
     if ($error === false) {
         $lC_Database->commitTransaction();
         lC_Cache::clear('categories');
         lC_Cache::clear('category_tree');
         lC_Cache::clear('also_purchased');
         lC_Cache::clear('box-whats_new');
         return true;
     }
     $lC_Database->rollbackTransaction();
     return false;
 }
예제 #2
0
 public static function fileUpload()
 {
     global $lC_Database, $lC_Vqmod, $_module;
     $lC_Image = new lC_Image_Admin();
     if (is_numeric($_GET[$_module])) {
         require_once $lC_Vqmod->modCheck('includes/classes/ajax_upload.php');
         // list of valid extensions, ex. array("jpeg", "xml", "bmp")
         $allowedExtensions = array('gif', 'jpg', 'jpeg', 'png');
         // max file size in bytes
         $sizeLimit = 10 * 1024 * 1024;
         $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
         $products_image = $uploader->handleUpload('../images/products/originals/');
         if ($products_image['exists'] == true) {
             if (isset($products_image['filename']) && $products_image['filename'] != null) {
                 $default_flag = 1;
                 $Qcheck = $lC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1');
                 $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qcheck->bindInt(':products_id', $_GET[$_module]);
                 $Qcheck->bindInt(':default_flag', 1);
                 $Qcheck->execute();
                 if ($Qcheck->numberOfRows() === 1) {
                     // is default image uploaded, remove the old default image first.
                     if (isset($_GET['default']) && $_GET['default'] == '1') {
                         $lC_Image->delete($Qcheck->value('id'));
                     } else {
                         $default_flag = 0;
                     }
                 }
                 $Qimage = $lC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
                 $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qimage->bindInt(':products_id', $_GET[$_module]);
                 $Qimage->bindValue(':image', $products_image['filename']);
                 $Qimage->bindInt(':default_flag', $default_flag);
                 $Qimage->bindInt(':sort_order', 0);
                 $Qimage->bindRaw(':date_added', 'now()');
                 $Qimage->setLogging($_SESSION['module'], $_GET[$_module]);
                 $Qimage->execute();
                 foreach ($lC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $lC_Image->resize($products_image['filename'], $group['id']);
                     }
                 }
             }
         }
     }
     $result = array('result' => 1, 'success' => true, 'rpcStatus' => RPC_STATUS_SUCCESS);
     echo json_encode($result);
 }