Ejemplo n.º 1
0
 public static function save($id = null, $data)
 {
     global $lC_Database, $lC_Language;
     $category_id = '';
     $error = false;
     $lC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qcat = $lC_Database->query('update :table_categories set categories_image = :categories_image, parent_id = :parent_id, sort_order = :sort_order, categories_mode = :categories_mode, categories_link_target = :categories_link_target, categories_custom_url = :categories_custom_url, categories_status = :categories_status, categories_visibility_nav = :categories_visibility_nav, categories_visibility_box = :categories_visibility_box, last_modified = now() where categories_id = :categories_id');
         $Qcat->bindInt(':categories_id', $id);
     } else {
         $Qcat = $lC_Database->query('insert into :table_categories (categories_image, parent_id, sort_order, categories_mode, categories_link_target, categories_custom_url, categories_status, categories_visibility_nav, categories_visibility_box, date_added) values (:categories_image, :parent_id, :sort_order, :categories_mode, :categories_link_target, :categories_custom_url, :categories_status, :categories_visibility_nav, :categories_visibility_box, now())');
         $Qcat->bindInt(':parent_id', $data['parent_id']);
         $Qcat->bindValue(':date_added', $data['date_added']);
     }
     $Qcat->bindTable(':table_categories', TABLE_CATEGORIES);
     $Qcat->bindValue(':categories_image', $data['image']);
     $Qcat->bindInt(':parent_id', $data['parent_id']);
     $Qcat->bindInt(':sort_order', $data['sort_order']);
     $Qcat->bindValue(':categories_mode', $data['mode']);
     $Qcat->bindInt(':categories_link_target', $data['link_target']);
     $Qcat->bindValue(':categories_custom_url', $data['custom_url']);
     $Qcat->bindInt(':categories_status', $data['status']);
     $Qcat->bindInt(':categories_visibility_nav', $data['nav']);
     $Qcat->bindInt(':categories_visibility_box', $data['box']);
     $Qcat->setLogging($_SESSION['module'], $id);
     $Qcat->execute();
     if (!$lC_Database->isError()) {
         $category_id = is_numeric($id) ? $id : $lC_Database->nextID();
         $lC_CategoryTree = new lC_CategoryTree_Admin();
         $cPath = $data['parent_id'] != 0 ? $lC_CategoryTree->getcPath($data['parent_id']) . '_' . $category_id : $category_id;
         foreach ($lC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qcd = $lC_Database->query('update :table_categories_description set categories_name = :categories_name, categories_menu_name = :categories_menu_name, categories_blurb = :categories_blurb, categories_description = :categories_description, categories_tags = :categories_tags where categories_id = :categories_id and language_id = :language_id');
             } else {
                 $Qcd = $lC_Database->query('insert into :table_categories_description (categories_id, language_id, categories_name, categories_menu_name, categories_blurb, categories_description, categories_tags) values (:categories_id, :language_id, :categories_name, :categories_menu_name, :categories_blurb, :categories_description, :categories_tags)');
             }
             $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
             $Qcd->bindInt(':categories_id', $category_id);
             $Qcd->bindInt(':language_id', $l['id']);
             $Qcd->bindValue(':categories_name', $data['name'][$l['id']]);
             $Qcd->bindValue(':categories_menu_name', $data['menu_name'][$l['id']]);
             $Qcd->bindValue(':categories_blurb', $data['blurb'][$l['id']]);
             $Qcd->bindValue(':categories_description', $data['description'][$l['id']]);
             $Qcd->bindValue(':categories_tags', $data['tags'][$l['id']]);
             $Qcd->setLogging($_SESSION['module'], $category_id);
             $Qcd->execute();
             if ($lC_Database->isError()) {
                 $error = true;
                 break;
             }
             // added for permalink
             if (!empty($data['permalink'][$l['id']])) {
                 if ($data['permalink'][$l['id']] != 'no-permalink') {
                     if (is_numeric($id) && lC_Categories_Admin::validatePermalink(array($data['permalink'][$l['id']]), $category_id, 1, $l['id']) == 1) {
                         $Qpl = $lC_Database->query('update :table_permalinks set permalink = :permalink where item_id = :item_id and type = :type and language_id = :language_id');
                     } else {
                         $Qpl = $lC_Database->query('insert into :table_permalinks (item_id, language_id, type, query, permalink) values (:item_id, :language_id, :type, :query, :permalink)');
                     }
                     $Qpl->bindTable(':table_permalinks', TABLE_PERMALINKS);
                     $Qpl->bindInt(':item_id', $category_id);
                     $Qpl->bindInt(':language_id', $l['id']);
                     $Qpl->bindInt(':type', 1);
                     $Qpl->bindValue(':query', 'cPath=' . $cPath);
                     $Qpl->bindValue(':permalink', $data['permalink'][$l['id']]);
                     $Qpl->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 } else {
                     $Qpl = $lC_Database->query('delete from :table_permalinks where item_id = :item_id and type = :type and language_id = :language_id');
                     $Qpl->bindTable(':table_permalinks', TABLE_PERMALINKS);
                     $Qpl->bindInt(':item_id', $category_id);
                     $Qpl->bindInt(':language_id', $l['id']);
                     $Qpl->bindInt(':type', 1);
                     $Qpl->execute();
                 }
             }
         }
     }
     if ($error === false) {
         $lC_Database->commitTransaction();
         lC_Cache::clear('categories');
         lC_Cache::clear('category_tree');
         lC_Cache::clear('also_purchased');
         return $category_id;
         // used for the save_close buttons
     }
     $lC_Database->rollbackTransaction();
     return false;
 }
Ejemplo n.º 2
0
 public static function copy($id, $category_id, $type)
 {
     global $lC_Database, $lC_CategoryTree;
     $category_array = explode('_', $category_id);
     if ($type == 'link') {
         $Qcheck = $lC_Database->query('select count(*) as total from :table_products_to_categories where products_id = :products_id and categories_id = :categories_id');
         $Qcheck->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
         $Qcheck->bindInt(':products_id', $id);
         $Qcheck->bindInt(':categories_id', end($category_array));
         $Qcheck->execute();
         if ($Qcheck->valueInt('total') < 1) {
             $Qcat = $lC_Database->query('insert into :table_products_to_categories (products_id, categories_id) values (:products_id, :categories_id)');
             $Qcat->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qcat->bindInt(':products_id', $id);
             $Qcat->bindInt(':categories_id', end($category_array));
             $Qcat->setLogging($_SESSION['module'], $id);
             $Qcat->execute();
             if ($Qcat->affectedRows()) {
                 return true;
             }
         }
     } elseif ($type == 'duplicate') {
         $Qproduct = $lC_Database->query('select * from :table_products where products_id = :products_id');
         $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
         $Qproduct->bindInt(':products_id', $id);
         $Qproduct->execute();
         if ($Qproduct->numberOfRows() === 1) {
             $error = false;
             $lC_Database->startTransaction();
             $Qnew = $lC_Database->query('insert into :table_products (products_quantity, products_cost, products_price, products_msrp, products_model, products_sku, products_date_added, products_weight, products_weight_class, products_status, products_tax_class_id, manufacturers_id) values (:products_quantity, :products_cost, :products_price, :products_msrp, :products_model, :products_sku, now(), :products_weight, :products_weight_class, 0, :products_tax_class_id, :manufacturers_id)');
             $Qnew->bindTable(':table_products', TABLE_PRODUCTS);
             $Qnew->bindInt(':products_quantity', $Qproduct->valueInt('products_quantity'));
             $Qnew->bindValue(':products_cost', $Qproduct->value('products_cost'));
             $Qnew->bindValue(':products_price', $Qproduct->value('products_price'));
             $Qnew->bindValue(':products_msrp', $Qproduct->value('products_msrp'));
             $Qnew->bindValue(':products_model', $Qproduct->value('products_model'));
             $Qnew->bindValue(':products_sku', $Qproduct->value('products_sku'));
             $Qnew->bindValue(':products_weight', $Qproduct->value('products_weight'));
             $Qnew->bindInt(':products_weight_class', $Qproduct->valueInt('products_weight_class'));
             $Qnew->bindInt(':products_tax_class_id', $Qproduct->valueInt('products_tax_class_id'));
             $Qnew->bindInt(':manufacturers_id', $Qproduct->valueInt('manufacturers_id'));
             $Qnew->setLogging($_SESSION['module']);
             $Qnew->execute();
             if ($Qnew->affectedRows()) {
                 $new_product_id = $lC_Database->nextID();
                 $Qdesc = $lC_Database->query('select * from :table_products_description where products_id = :products_id');
                 $Qdesc->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
                 $Qdesc->bindInt(':products_id', $id);
                 $Qdesc->execute();
                 while ($Qdesc->next()) {
                     $Qnewdesc = $lC_Database->query('insert into :table_products_description (products_id, language_id, products_name, products_blurb, products_description, products_keyword, products_tags, products_url, products_viewed) values (:products_id, :language_id, :products_name, :products_blurb, :products_description, :products_keyword, :products_tags, :products_url, 0)');
                     $Qnewdesc->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
                     $Qnewdesc->bindInt(':products_id', $new_product_id);
                     $Qnewdesc->bindInt(':language_id', $Qdesc->valueInt('language_id'));
                     $Qnewdesc->bindValue(':products_name', $Qdesc->value('products_name') . '_Copy');
                     $Qnewdesc->bindValue(':products_blurb', $Qdesc->value('products_blurb'));
                     $Qnewdesc->bindValue(':products_description', $Qdesc->value('products_description'));
                     $Qnewdesc->bindValue(':products_keyword', $Qdesc->value('products_keyword') . '-copy');
                     $Qnewdesc->bindValue(':products_tags', $Qdesc->value('products_tags'));
                     $Qnewdesc->bindValue(':products_url', $Qdesc->value('products_url'));
                     $Qnewdesc->setLogging($_SESSION['module'], $new_product_id);
                     $Qnewdesc->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                     // permalink addition
                     $lC_CategoryTree = new lC_CategoryTree_Admin();
                     $cPath = end($category_array) != 0 ? $lC_CategoryTree->getcPath(end($category_array)) : 0;
                     $Qpl = $lC_Database->query('insert into :table_permalinks (item_id, language_id, type, query, permalink) values (:item_id, :language_id, :type, :query, :permalink)');
                     $Qpl->bindTable(':table_permalinks', TABLE_PERMALINKS);
                     $Qpl->bindInt(':item_id', $new_product_id);
                     $Qpl->bindInt(':language_id', $Qdesc->valueInt('language_id'));
                     $Qpl->bindInt(':type', 2);
                     $Qpl->bindValue(':query', 'cPath=' . $cPath);
                     $Qpl->bindValue(':permalink', $Qdesc->value('products_keyword') . '-copy');
                     $Qpl->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
                 $Qpb = $lC_Database->query('select * from :table_products_pricing where products_id = :products_id');
                 $Qpb->bindTable(':table_products_pricing', TABLE_PRODUCTS_PRICING);
                 $Qpb->bindInt(':products_id', $id);
                 $Qpb->execute();
                 while ($Qpb->next()) {
                     $Qnewpb = $lC_Database->query('insert into :table_products_pricing (products_id, group_id, tax_class_id, qty_break, price_break, date_added) values (:products_id, :group_id, :tax_class_id, :qty_break, :price_break, :date_added)');
                     $Qnewpb->bindTable(':table_products_pricing', TABLE_PRODUCTS_PRICING);
                     $Qnewpb->bindInt(':products_id', $new_product_id);
                     $Qnewpb->bindInt(':group_id', $Qpb->valueInt('group_id'));
                     $Qnewpb->bindInt(':tax_class_id', $Qpb->valueInt('tax_class_id'));
                     $Qnewpb->bindInt(':qty_break', $Qpb->valueInt('qty_break'));
                     $Qnewpb->bindValue(':price_break', $Qpb->value('price_break'));
                     $Qnewpb->bindRaw(':date_added', 'now()');
                     $Qnewpb->setLogging($_SESSION['module'], $new_product_id);
                     $Qnewpb->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
                 if ($error === false) {
                     $Qp2c = $lC_Database->query('insert into :table_products_to_categories (products_id, categories_id) values (:products_id, :categories_id)');
                     $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                     $Qp2c->bindInt(':products_id', $new_product_id);
                     $Qp2c->bindInt(':categories_id', end($category_array));
                     $Qp2c->setLogging($_SESSION['module'], $new_product_id);
                     $Qp2c->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                     }
                 }
                 if ($error === false) {
                     $Qproductimages = $lC_Database->query('select * from :table_products_images where products_id = :products_id');
                     $Qproductimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                     $Qproductimages->bindInt(':products_id', $id);
                     $Qproductimages->execute();
                     while ($Qproductimages->next()) {
                         $Qpi = $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)');
                         $Qpi->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                         $Qpi->bindInt(':products_id', $new_product_id);
                         $Qpi->bindValue(':image', $Qproductimages->value('image'));
                         $Qpi->bindInt(':default_flag', $Qproductimages->value('default_flag'));
                         $Qpi->bindInt(':sort_order', $Qproductimages->value('sort_order'));
                         $Qpi->bindRaw(':date_added', 'now()');
                         $Qpi->execute();
                         if ($lC_Database->isError()) {
                             $error = true;
                             break;
                         }
                     }
                 }
             } else {
                 $error = true;
             }
             if ($error === false) {
                 $lC_Database->commitTransaction();
                 lC_Cache::clear('categories');
                 lC_Cache::clear('category_tree');
                 lC_Cache::clear('also_purchased');
                 return true;
             } else {
                 $lC_Database->rollbackTransaction();
             }
         }
     }
     return false;
 }