コード例 #1
0
ファイル: categories.php プロジェクト: abhiesa-tolexo/loaded7
 public static function delete($id)
 {
     global $lC_Database;
     $lC_CategoryTree = new lC_CategoryTree_Admin();
     if (is_numeric($id)) {
         $lC_CategoryTree->setBreadcrumbUsage(false);
         $categories = array_merge(array(array('id' => $id, 'text' => '')), $lC_CategoryTree->getArray($id));
         $products = array();
         $products_delete = array();
         foreach ($categories as $category) {
             $Qproducts = $lC_Database->query('select products_id from :table_products_to_categories where categories_id = :categories_id');
             $Qproducts->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qproducts->bindInt(':categories_id', $category['id']);
             $Qproducts->execute();
             while ($Qproducts->next()) {
                 $products[$Qproducts->valueInt('products_id')]['categories'][] = $category['id'];
             }
         }
         foreach ($products as $key => $value) {
             $Qcheck = $lC_Database->query('select categories_id from :table_products_to_categories where products_id = :products_id and categories_id not in :categories_id limit 1');
             $Qcheck->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qcheck->bindInt(':products_id', $key);
             $Qcheck->bindRaw(':categories_id', '("' . implode('", "', $value['categories']) . '")');
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() === 0) {
                 $products_delete[$key] = $key;
             }
         }
         lc_set_time_limit(0);
         foreach ($categories as $category) {
             $lC_Database->startTransaction();
             $Qimage = $lC_Database->query('select categories_image from :table_categories where categories_id = :categories_id');
             $Qimage->bindTable(':table_categories', TABLE_CATEGORIES);
             $Qimage->bindInt(':categories_id', $category['id']);
             $Qimage->execute();
             $Qc = $lC_Database->query('delete from :table_categories where categories_id = :categories_id');
             $Qc->bindTable(':table_categories', TABLE_CATEGORIES);
             $Qc->bindInt(':categories_id', $category['id']);
             $Qc->setLogging($_SESSION['module'], $id);
             $Qc->execute();
             if (!$lC_Database->isError()) {
                 $Qcd = $lC_Database->query('delete from :table_categories_description where categories_id = :categories_id');
                 $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
                 $Qcd->bindInt(':categories_id', $category['id']);
                 $Qcd->setLogging($_SESSION['module'], $id);
                 $Qcd->execute();
                 if (!$lC_Database->isError()) {
                     $Qp2c = $lC_Database->query('delete from :table_products_to_categories where categories_id = :categories_id');
                     $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                     $Qp2c->bindInt(':categories_id', $category['id']);
                     $Qp2c->setLogging($_SESSION['module'], $id);
                     $Qp2c->execute();
                     if (!$lC_Database->isError()) {
                         // permalink
                         $Qpb = $lC_Database->query('delete from :table_permalinks where item_id = :item_id');
                         $Qpb->bindTable(':table_permalinks', TABLE_PERMALINKS);
                         $Qpb->bindInt(':item_id', $category['id']);
                         $Qpb->execute();
                         if (!$lC_Database->isError()) {
                             $lC_Database->commitTransaction();
                             lC_Cache::clear('categories');
                             lC_Cache::clear('category_tree');
                             lC_Cache::clear('also_purchased');
                             if (!lc_empty($Qimage->value('categories_image'))) {
                                 $Qcheck = $lC_Database->query('select count(*) as total from :table_categories where categories_image = :categories_image');
                                 $Qcheck->bindTable(':table_categories', TABLE_CATEGORIES);
                                 $Qcheck->bindValue(':categories_image', $Qimage->value('categories_image'));
                                 $Qcheck->execute();
                                 if ($Qcheck->numberOfRows() === 0) {
                                     if (file_exists(realpath('../' . DIR_WS_IMAGES . 'categories/' . $Qimage->value('categories_image')))) {
                                         @unlink(realpath('../' . DIR_WS_IMAGES . 'categories/' . $Qimage->value('categories_image')));
                                     }
                                 }
                             }
                         } else {
                             $lC_Database->rollbackTransaction();
                         }
                     } else {
                         $lC_Database->rollbackTransaction();
                     }
                 } else {
                     $lC_Database->rollbackTransaction();
                 }
             } else {
                 $lC_Database->rollbackTransaction();
             }
         }
         foreach ($products_delete as $id) {
             lC_Products_Admin::remove($id);
         }
         lC_Cache::clear('categories');
         lC_Cache::clear('category_tree');
         lC_Cache::clear('also_purchased');
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: products.php プロジェクト: abhiesa-tolexo/loaded7
 public static function getAll($category_id = null)
 {
     global $lC_Database, $lC_Language, $lC_Currencies, $_module;
     if (!is_numeric($category_id)) {
         $category_id = 0;
     }
     $lC_Language->loadIniFile('products.php');
     $media = $_GET['media'];
     $result = array('aaData' => array());
     /* Total Records */
     $QresultTotal = $lC_Database->query('SELECT count(p.products_id) as total from :table_products p where p.parent_id = 0');
     $QresultTotal->bindTable(':table_products', TABLE_PRODUCTS);
     $QresultTotal->execute();
     $result['iTotalRecords'] = $QresultTotal->valueInt('total');
     $QresultTotal->freeResult();
     /* Paging */
     $sLimit = " LIMIT 0,25 ";
     if (isset($_GET['iDisplayStart'])) {
         if ($_GET['iDisplayLength'] != -1) {
             $sLimit = " LIMIT " . $_GET['iDisplayStart'] . ", " . $_GET['iDisplayLength'];
         }
     }
     /* Ordering */
     if (isset($_GET['iSortCol_0'])) {
         $sOrder = " ORDER BY ";
         for ($i = 0; $i < (int) $_GET['iSortingCols']; $i++) {
             $sOrder .= lC_Products_Admin::_fnColumnToField($_GET['iSortCol_' . $i]) . " " . $_GET['sSortDir_' . $i] . ", ";
         }
         $sOrder = substr_replace($sOrder, "", -2);
     }
     /* Filtering */
     $sWhere = " WHERE p.parent_id = 0 ";
     if ($_GET['sSearch'] != "") {
         $sWhere .= " and (pd.products_name LIKE '%" . $_GET['sSearch'] . "%' or p.products_model LIKE '%" . $_GET['sSearch'] . "%' or p.products_sku LIKE '%" . $_GET['sSearch'] . "%'  or p.products_id = '" . $_GET['sSearch'] . "')";
     }
     /* Main Listing Query */
     if ($category_id > 0) {
         $lC_CategoryTree = new lC_CategoryTree_Admin();
         $lC_CategoryTree->setBreadcrumbUsage(false);
         $in_categories = array($category_id);
         foreach ($lC_CategoryTree->getArray($category_id) as $category) {
             $in_categories[] = $category['id'];
         }
         /* Total Filtered Records */
         $QresultFilterTotal = $lC_Database->query('SELECT count(p.products_id) as total, pd.products_name from :table_products p LEFT JOIN :table_products_description pd on (pd.products_id = p.products_id and pd.language_id = :language_id) LEFT JOIN :table_products_to_categories p2c on (p.products_id = p2c.products_id)' . $sWhere . ' and p2c.categories_id in (:categories_id) ' . $sOrder);
         // $QresultFilterTotal = $lC_Database->query("SELECT count(p.products_id) as total, pd.products_name from :table_products p LEFT JOIN :table_products_description pd on (pd.products_id = p.products_id and pd.language_id = :language_id) " . $sWhere . ' and p2c.categories_id in (:categories_id) ' . $sOrder);
         $QresultFilterTotal->bindTable(':table_products', TABLE_PRODUCTS);
         $QresultFilterTotal->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
         $QresultFilterTotal->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
         $QresultFilterTotal->bindInt(':language_id', $lC_Language->getID());
         $QresultFilterTotal->bindRaw(':categories_id', implode(',', $in_categories));
         $QresultFilterTotal->execute();
         $result['iTotalDisplayRecords'] = $QresultFilterTotal->valueInt('total');
         $QresultFilterTotal->freeResult();
         $Qproducts = $lC_Database->query('SELECT p.*, pd.products_name, pd.products_keyword from :table_products p LEFT JOIN :table_products_description pd on (p.products_id = pd.products_id and pd.language_id = :language_id) LEFT JOIN :table_products_to_categories p2c on (p.products_id = p2c.products_id)' . $sWhere . ' and p2c.categories_id in (:categories_id) ' . $sOrder . $sLimit);
         $Qproducts->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
         $Qproducts->bindRaw(':categories_id', implode(',', $in_categories));
     } else {
         /* Total Filtered Records */
         $QresultFilterTotal = $lC_Database->query("SELECT count(p.products_id) as total, pd.products_name from :table_products p LEFT JOIN :table_products_description pd on (pd.products_id = p.products_id and pd.language_id = :language_id) " . $sWhere . $sOrder);
         $QresultFilterTotal->bindTable(':table_products', TABLE_PRODUCTS);
         $QresultFilterTotal->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
         $QresultFilterTotal->bindInt(':language_id', $lC_Language->getID());
         $QresultFilterTotal->execute();
         $result['iTotalDisplayRecords'] = $QresultFilterTotal->valueInt('total');
         $QresultFilterTotal->freeResult();
         $Qproducts = $lC_Database->query('SELECT p.*, pd.products_name, pd.products_keyword from :table_products p LEFT JOIN :table_products_description pd on (p.products_id = pd.products_id and pd.language_id = :language_id) ' . $sWhere . $sOrder . $sLimit);
     }
     $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
     $Qproducts->bindInt(':language_id', $lC_Language->getID());
     $Qproducts->execute();
     while ($Qproducts->next()) {
         $Qproductscategories = $lC_Database->query('select p2c.categories_id, cd.categories_name, c.categories_status from :table_products_to_categories p2c left join :table_categories c on (p2c.categories_id = c.categories_id) left join lc_categories_description cd on (p2c.categories_id = cd.categories_id) where p2c.products_id = :products_id and cd.language_id = :language_id');
         $Qproductscategories->bindTable(':table_categories', TABLE_CATEGORIES);
         $Qproductscategories->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
         $Qproductscategories->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
         $Qproductscategories->bindRaw(':products_id', $Qproducts->valueInt('products_id'));
         $Qproductscategories->bindInt(':language_id', $lC_Language->getID());
         $Qproductscategories->execute();
         $catCount = $Qproductscategories->numberOfRows() - 1;
         while ($Qproductscategories->next()) {
             $Qcategories[] = array('name' => $Qproductscategories->value('categories_name'), 'status' => $Qproductscategories->valueInt('categories_status'));
         }
         $cnt = 0;
         $catArr = is_array($Qcategories) ? $Qcategories : array();
         foreach ($catArr as $cat) {
             $categories .= '<small title="' . $cat['name'] . '" class="with-tooltip cursor-pointer no-wrap tag mid-margin-right glossy ' . ($cat['status'] == 1 ? ' green-gradient' : ' red-gradient') . '">' . (strlen($cat['name']) < 15 ? $cat['name'] : trim(substr($cat['name'], 0, 12)) . '...') . '</small>';
             if ($cnt > 2) {
                 $categories .= '<br />';
                 $cnt = 0;
             }
             $cnt++;
         }
         $Qcategories = null;
         $lC_Image = new lC_Image_Admin();
         $Qimage = $lC_Database->query('select image from :table_products_images where products_id = :products_id and default_flag = 1');
         $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
         $Qimage->bindInt(':products_id', $Qproducts->valueInt('products_id'));
         $Qimage->execute();
         $cost = $lC_Currencies->format($Qproducts->value('products_cost'));
         $msrp = $lC_Currencies->format($Qproducts->value('products_msrp'));
         $products_status = $Qproducts->valueInt('products_status') === 1;
         $products_keyword = $Qproducts->value('products_keyword');
         // VQMOD-hookpoint; DO NOT MODIFY OR REMOVE THE LINE BELOW
         $products_quantity = lC_Products_Admin::getProductsListingQty($Qproducts->toArray());
         // VQMOD-hookpoint; DO NOT MODIFY OR REMOVE THE LINE BELOW
         $price = lC_Products_Admin::getProductsListingPrice($Qproducts->toArray());
         // VQMOD-hookpoint; DO NOT MODIFY OR REMOVE THE LINE BELOW
         $icons = lC_Products_Admin::getlistingIcons($Qproducts->valueInt('products_id'));
         $extra_data = array('products_cost_formatted' => $cost, 'products_price_formatted' => $price, 'products_msrp_formatted' => $msrp, 'products_status' => $products_status, 'products_quantity' => $products_quantity, 'products_keyword' => $products_keyword);
         $check = '<td><input class="batch" type="checkbox" name="batch[]" value="' . $Qproducts->valueInt('products_id') . '" id="' . $Qproducts->valueInt('products_id') . '"></td>';
         $products = '<td><div class="products-listing-thumb">' . $lC_Image->show($Qimage->value('image'), '', 'class="mid-margin-right float-left" width="28" height="28"', 'mini') . '</div><div class="products-listing-name-model"><a href="javascript:void(0);" onclick="showPreview(\'' . $Qproducts->valueInt('products_id') . '\')" class="bold">' . $Qproducts->value('products_name') . '</a><br /><span class="small grey mid-margin-right">' . $Qproducts->value('products_model') . '</span><span class="mid-margin-right">' . $icons . '</span></div></td>';
         $cats = '<td>' . $categories . '</td>';
         $categories = null;
         $class = '<td>' . $lC_Language->get('text_common') . '</td>';
         $price = '<td><div class="no-wrap">' . $price . '</div></td>';
         $qty = '<td>' . $products_quantity . '</td>';
         $status = '<td><span class="align-center" id="status_' . $Qproducts->valueInt('products_id') . '" onclick="updateStatus(\'' . $Qproducts->valueInt('products_id') . '\', \'' . ($Qproducts->valueInt('products_status') == 1 ? 0 : 1) . '\');">' . ($Qproducts->valueInt('products_status') == 1 ? '<span class="icon-tick icon-size2 icon-green cursor-pointer with-tooltip" title="' . $lC_Language->get('text_disable_product') . '"></span>' : '<span class="icon-cross icon-size2 icon-red cursor-pointer with-tooltip" title="' . $lC_Language->get('text_enable_product') . '"></span>') . '</span></td>';
         $action = '<td class="align-right vertical-center">
                <span class="button-group">
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? '#' : lc_href_link_admin(FILENAME_DEFAULT, $_module . '=' . $Qproducts->valueInt('products_id') . '&cID=' . $category_id . '&action=save')) . '" class="button icon-pencil' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? ' disabled' : NULL) . '">' . ($media === 'mobile-portrait' || $media === 'mobile-landscape' ? NULL : $lC_Language->get('icon_edit')) . '</a>
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? '#' : 'javascript://" onclick="copyProduct(\'' . $Qproducts->valueInt('products_id') . '\', \'' . urlencode($Qproducts->value('products_name')) . '\')') . '" class="button icon-pages with-tooltip' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_copy') . '"></a>
                  <a target="_blank" href="' . lc_href_link(FILENAME_PRODUCTS, $Qproducts->value('products_keyword'), 'NONSSL', null, null, true) . '" class="button icon-monitor with-tooltip" title="' . $lC_Language->get('icon_view_in_catalog') . '"></a>
                </span>
                <span class="button-group">
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 4) ? '#' : 'javascript://" onclick="deleteProduct(\'' . $Qproducts->valueInt('products_id') . '\', \'' . urlencode($Qproducts->value('products_name')) . '\')') . '" class="button icon-trash with-tooltip' . ((int) ($_SESSION['admin']['access'][$_module] < 4) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_delete') . '"></a>
                </span>
              </td>';
         $result['aaData'][] = array("{$check}", "{$products}", "{$cats}", "{$class}", "{$price}", "{$qty}", "{$status}", "{$action}");
         $result['entries'][] = array_merge($Qproducts->toArray(), $extra_data);
         $Qproductscategories->freeResult();
         $Qimage->freeResult();
     }
     $result['sEcho'] = intval($_GET['sEcho']);
     $Qproducts->freeResult();
     return $result;
 }