/** @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); }
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 getProductFormData($id = null) { global $_module, $lC_Database, $lC_Language; $lC_Language->loadIniFile('products.php'); $lC_CategoryTree = new lC_CategoryTree_Admin(); $result = array(); if (isset($id) && is_numeric($id)) { $Qcategories = $lC_Database->query('select categories_id from :table_products_to_categories where products_id = :products_id'); $Qcategories->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qcategories->bindInt(':products_id', $id); $Qcategories->execute(); $in_categories = array(); while ($Qcategories->next()) { $in_categories[] = $Qcategories->valueInt('categories_id'); } $cnt = 0; $in_categories_path = ''; foreach ($in_categories as $category_id) { $in_categories_path .= $lC_CategoryTree->getPath($category_id, 0, ' » ') . '<br />'; if ($category_id == 0) { $categories_array[] = array('id' => $category_id, 'text' => $lC_Language->get('top_category')); } else { $categories_array[] = array('id' => $category_id, 'text' => $lC_CategoryTree->getPath($category_id, 0, ' » ')); } $cnt++; } $result['inCategoriesCount'] = $cnt; $result['inCategoriesCheckbox'] = lc_draw_checkbox_field('product_categories[]', $categories_array, true, null, ' <br />'); if (!empty($in_categories_path)) { $in_categories_path = substr($in_categories_path, 0, -6); if (substr($in_categories_path, 0, 6) == '<br />') { $in_categories_path = $lC_Language->get('top_category') . '<br />' . $in_categories_path; } } $result['categoryPath'] = $in_categories_path; } $categories_array = array('0' => '-- ' . $lC_Language->get('top_category') . ' --'); foreach ($lC_CategoryTree->getArray() as $value) { $pid = end(explode('_', $value['id'])); if (lC_Categories_Admin::getParent($pid) != 0) { foreach (explode('_', $value['id']) as $cats) { if ($pid != $cats) { $Qcpn = $lC_Database->query('select categories_name from :table_categories_description where categories_id = :categories_id and language_id = :language_id'); $Qcpn->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION); $Qcpn->bindInt(':language_id', $lC_Language->getID()); $Qcpn->bindInt(':categories_id', $cats); $Qcpn->execute(); $titlestr .= $Qcpn->value('categories_name') . ' » '; } } $title = $titlestr . $value['title']; unset($titlestr); } else { $title = $value['title']; } $categories_array[$value['id']] = $title; } $result['categoriesArray'] = $categories_array; return $result; }