public function __construct() { global $lC_Language, $lC_MessageStack, $lC_Currencies, $lC_Tax, $lC_CategoryTree, $lC_Image, $current_category_id, $lC_Vqmod; $this->_page_title = $lC_Language->get('heading_title'); $current_category_id = 0; if (isset($_GET['cID']) && is_numeric($_GET['cID'])) { $current_category_id = $_GET['cID']; } else { $_GET['cID'] = $current_category_id; } require $lC_Vqmod->modCheck('../includes/classes/currencies.php'); $lC_Currencies = new lC_Currencies(); require $lC_Vqmod->modCheck('includes/classes/tax.php'); $lC_Tax = new lC_Tax_Admin(); require_once $lC_Vqmod->modCheck('includes/classes/category_tree.php'); $lC_CategoryTree = new lC_CategoryTree_Admin(); $lC_CategoryTree->setSpacerString(' ', 2); require $lC_Vqmod->modCheck('includes/classes/image.php'); $lC_Image = new lC_Image_Admin(); // check if the products image directory exists and is writeable if (is_dir('../images/products')) { if (!is_writeable('../images/products')) { $_SESSION['error'] = true; $_SESSION['errmsg'] = sprintf($lC_Language->get('ms_error_image_directory_not_writable'), realpath('../images/products')); } } else { $_SESSION['error'] = true; $_SESSION['errmsg'] = sprintf($lC_Language->get('ms_error_image_directory_non_existant'), realpath('../images/products')); } }
/** @package admin::functions @author Loaded Commerce @copyright Copyright 2003-2014 Loaded Commerce, LLC @copyright Portions Copyright 2003 osCommerce @license https://github.com/loadedcommerce/loaded7/blob/master/LICENSE.txt @version $Id: lc_cfg_set_categories_top_category.php v1.0 2013-08-08 datazen $ */ function lc_cfg_set_categories_top_category($default = 0, $key = null) { global $lC_Database, $lC_Language, $lC_Vqmod; include_once $lC_Vqmod->modCheck(DIR_FS_ADMIN . 'includes/classes/category_tree.php'); include_once $lC_Vqmod->modCheck(DIR_FS_ADMIN . 'includes/applications/categories/classes/categories.php'); $lC_Language->loadIniFile('categories.php'); $lC_CategoryTree = new lC_CategoryTree_Admin(); $categories = array('0' => $lC_Language->get('top_category')); foreach ($lC_CategoryTree->getArray() as $value) { // added switch for only category mode categories in selection dropdown. if ($value['mode'] == 'category') { $cid = explode('_', $value['id']); $count = count($cid); $cid = end($cid); $acArr = lC_Categories_Admin::getAllChildren($id); $categories[$cid] = str_repeat(" ", $count - 1) . ' ' . $value['title']; } } $css_class = 'class="input with-small-padding mid-margin-top"'; $name = empty($key) ? 'configuration_value' : 'configuration[' . $key . ']'; $array = array(); $array[] = array('id' => '', 'text' => $lC_Language->get('text_select_category')); foreach ($categories as $key => $value) { $array[] = array('id' => $key, 'text' => $value); } return lc_draw_pull_down_menu($name, $array, $default, $css_class); }
function __construct() { global $lC_Language, $breadcrumb_string; $this->_page_title = $lC_Language->get('heading_title'); $current_category_id = 0; if (is_numeric($_GET[$this->_module])) { $current_category_id = $_GET[$this->_module]; } $lC_CategoryTree = new lC_CategoryTree_Admin(); if (!isset($_GET['action'])) { $_GET['action'] = ''; } // check if the categories image directory exists if (is_dir('../images/categories')) { if (!is_writeable('../images/categories')) { $_SESSION['error'] = true; $_SESSION['errmsg'] = sprintf($lC_Language->get('ms_error_image_directory_not_writable'), realpath('../images/categories')); } } else { $_SESSION['error'] = true; $_SESSION['errmsg'] = sprintf($lC_Language->get('ms_error_image_directory_non_existant'), realpath('../images/categories')); } // setup the breadcrumb $breadcrumb_array = array(lc_link_object(lc_href_link_admin(FILENAME_DEFAULT, $this->_module), $lC_Language->get('text_top'))); foreach ($lC_CategoryTree->getPathArray($current_category_id) as $category) { $breadcrumb_array[] = lc_link_object(lc_href_link_admin(FILENAME_DEFAULT, $this->_module . '=' . $category['id']), $category['name']); } $breadcrumb_string = '<ul>'; foreach ($breadcrumb_array as $key => $value) { $breadcrumb_string .= '<li>' . $value . '</li>'; } $breadcrumb_string .= '</ul>'; }
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; }
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; }