static function getName($cPath, $languages_id, $languages_code) { $cache_filename = self::buildFileName($cPath, $languages_code); if (($name = SSUCache::read($cache_filename, self::$identifier)) !== false) { return $name; } // do not trust the passed cPath, always rebuild it $current_categories_id = self::getID($cPath, '_'); $category_ids = array(); zen_get_parent_categories($category_ids, $current_categories_id); $category_ids = array_reverse($category_ids); $category_ids[] = $current_categories_id; $cat_count = count($category_ids); $counter = $cat_count - SSUConfig::registry('configs', 'max_level'); if ($counter < 0) { $counter = 0; } $result = ''; // this may not be the best way to build the category name, but we do this once per cPath only while ($counter <= $cat_count - 1) { $category_ids[$counter] = (int) $category_ids[$counter]; $sql_query = "SELECT categories_name FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id ='" . $category_ids[$counter] . "' AND language_id= '{$languages_id}' LIMIT 1"; $result .= self::getNameFromDB($sql_query, self::$name_field) . SSUConfig::registry('delimiters', 'name'); $counter++; } $result = trim(SSULanguage::parseName($result, $languages_code)); if (empty($result)) { $result = self::$name_field; } $result = $result . SSUConfig::registry('identifiers', self::$identifier) . $cPath; // write to file EVEN if we get an empty content SSUCache::write($cache_filename, self::$identifier, $result); return $result; }
function zen_get_product_path($products_id) { global $db; $cPath = ''; $category_query = "select p2c.categories_id\r\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\r\n where p.products_id = '" . (int) $products_id . "'\r\n and p.products_status = '1'\r\n and p.products_id = p2c.products_id limit 1"; $category = $db->Execute($category_query); if ($category->RecordCount() > 0) { $categories = array(); zen_get_parent_categories($categories, $category->fields['categories_id']); $categories = array_reverse($categories); $cPath = implode('_', $categories); if (zen_not_null($cPath)) { $cPath .= '_'; } $cPath .= $category->fields['categories_id']; } return $cPath; }
function zen_get_generated_category_path_rev($this_categories_id) { $categories = array(); zen_get_parent_categories($categories, $this_categories_id); $categories = array_reverse($categories); $categories_imploded = implode('_', $categories); if (zen_not_null($categories_imploded)) { $categories_imploded .= '_'; } $categories_imploded .= $this_categories_id; return $categories_imploded; }
function zen_get_product_path($products_id) { global $gBitDb; $cPath = ''; $category_query = "select p2c.`categories_id`\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n where p.`products_id` = '" . (int) $products_id . "'\n and p.`products_status` = '1'\n and p.`products_id` = p2c.`products_id`"; if ($category = $gBitDb->getOne($category_query)) { $categories = array(); zen_get_parent_categories($categories, $category); $categories = array_reverse($categories); $cPath = implode('_', $categories); if (zen_not_null($cPath)) { $cPath .= '_'; } $cPath .= $category; } return $cPath; }
* Once the data is prepared, it calls the standard tpl_list_box_content template for display. * * @package page * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: category_row.php 4084 2006-08-06 23:59:36Z drbyte $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $title = ''; $current_sub_categories = array(); if ($number_of_categories == 0) { unset($sub_categories); zen_get_parent_categories($sub_categories, $current_category_id); //$current_sub_categories = $sub_categories; //echo '<pre>';print_r($current_sub_categories);exit; if (!empty($sub_categories)) { $pc_id = $sub_categories[0]; $subcategories_array = zen_get_categories('', $pc_id); $arr = array(); foreach ($subcategories_array as $key => $val) { $arr[] = $val['id']; } if (count($arr)) { $id_str = implode(",", $arr); $categories_query = "select c.categories_id,c.categories_image,cd.categories_name\n\t\t\t from categories c\n\t\t\t inner join categories_description cd on c.categories_id=cd.categories_id\n\t\t\t where c.categories_id in (" . $id_str . ") and c.categories_status=1"; $categories = $db->Execute($categories_query); $number_of_categories = $categories->RecordCount(); }
/** * Recursively go through the categories and retreive all parent categories IDs * TABLES: categories */ function zen_get_parent_categories(&$categories, $categories_id) { global $db; $parent_categories_query = "select parent_id\n from " . TABLE_CATEGORIES . "\n where categories_id = '" . (int) $categories_id . "'"; $parent_categories = $db->Execute($parent_categories_query); while (!$parent_categories->EOF) { if ($parent_categories->fields['parent_id'] == 0) { return true; } $categories[sizeof($categories)] = $parent_categories->fields['parent_id']; if ($parent_categories->fields['parent_id'] != $categories_id) { zen_get_parent_categories($categories, $parent_categories->fields['parent_id']); } $parent_categories->MoveNext(); } }
function getCategorys($cid, $lang_id = 1) { global $db; static $category = array(); if (isset($category[$cid])) { return $category[$cid]; } zen_get_parent_categories($tmp, $cid); if (empty($tmp)) { $tmp = array(); } $tmp = array_reverse($tmp); $tmp[] = $cid; $i = 0; foreach ($tmp as $id) { $r = $db->Execute('SELECT * FROM ' . TABLE_CATEGORIES_DESCRIPTION . ' WHERE categories_id=' . $id . ' AND language_id=' . $lang_id); $category[$cid][$i]['name'] = $r->fields['categories_name']; $category[$cid][$i]['desc'] = $r->fields['categories_description']; $r = $db->Execute('SELECT * FROM ' . TABLE_METATAGS_CATEGORIES_DESCRIPTION . ' WHERE categories_id=' . $id . ' AND language_id=' . $lang_id); $category[$cid][$i]['meta_title'] = $r->fields['metatags_title']; $category[$cid][$i]['meta_key'] = $r->fields['metatags_keywords']; $category[$cid][$i]['meta_desc'] = $r->fields['metatags_description']; ++$i; } for ($i = count($category[$cid]); $i < 7; ++$i) { $category[$cid][$i] = array('name' => '', 'desc' => '', 'meta_title' => '', 'meta_key' => '', 'meta_desc' => ''); } return $category[$cid]; }
function getProductPath($products_id, $cPath) { global $db; $categories_id = self::getID($cPath, '_'); $category_query = "select p2c.categories_id, p.master_categories_id\n\t\t\t from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\t\t where p.products_id = '" . $products_id . "'\n\t\t\t and p.products_id = p2c.products_id \n\t\t\t and (p.master_categories_id = '{$categories_id}' or p2c.categories_id='{$categories_id}') limit 1"; $category = $db->Execute($category_query); // fall back if needed to if ($category->RecordCount() == 0) { $category_query = "select p.master_categories_id\n\t\t\t \t\t\t\t\t\tfrom " . TABLE_PRODUCTS . " p \n\t\t\t \t\t\t\t\t\twhere p.products_id = '" . $products_id . "' limit 1"; $category = $db->Execute($category_query); if ($category->RecordCount() > 0) { $categories_id = $category->fields['master_categories_id']; } } $cPath = ""; $categories = array(); zen_get_parent_categories($categories, $categories_id); $categories = array_reverse($categories); $cPath = implode('_', $categories); if (zen_not_null($cPath)) { $cPath .= '_'; } $cPath .= $categories_id; return $cPath; }
function updateHeaderStartAdvancedSearchResults() { global $_GET; if (empty($_GET['cPath'])) { $parent = array(); zen_get_parent_categories($parent, $_GET['categories_id']); $parent = array_reverse($parent); $cPath = implode('_', $parent); if (zen_not_null($cPath)) { $cPath .= '_'; } $_GET['cPath'] = $cPath . $_GET['categories_id']; } define('HEADING_TITLE', sprintf(HEADING_TITLE_1, htmlspecialchars($_GET['keyword'], ENT_QUOTES))); }
function zen_get_categories_with_depth($category_id, $depth) { global $db; $categories = array(); $categories_array = array(); $columns = array(); $tables = array(); $conditions = array(); $join = ''; $on = ''; // get categories for ($i = 0; $i < $depth; $i++) { $columns[] = 'c' . $i . '.categories_id as c' . $i . 'id'; if ($i > 0) { $join = ' LEFT JOIN '; $on = ' ON c' . ($i - 1) . '.categories_id=c' . $i . '.parent_id'; } $tables[] = $join . TABLE_CATEGORIES . ' as c' . $i . $on; $conditions[] = 'c' . $i . '.categories_id=' . zen_db_input($category_id); } $sql = 'SELECT ' . implode(',', $columns) . ' FROM ' . implode('', $tables) . ' WHERE c0.parent_id=0'; if ($category_id != 0) { $sql .= ' AND (' . implode(' OR ', $conditions) . ')'; } $categories_record = $db->Execute($sql); while (!$categories_record->EOF) { $data = array(); foreach ($categories_record->fields as $id) { $data[] = $id; } $categories[] = $data; $categories_record->MoveNext(); } if (count($categories) == 0) { zen_get_parent_categories($categories_array, $category_id); if (count($categories_array) > 0) { $categories_array = array_reverse($categories_array); $categories_array[] = $category_id; if (count($categories_array) >= $depth) { $categories = array(array_slice($categories_array, 0, $depth)); } } } return $categories; }
function getExportDataCategory($category_id, $format, $products_id = 0) { // prepare data static $category = array(); $category_id = zen_db_input($category_id); $ignore_column = $this->getFormatColumnIgnore($format['csv_format_type_id']); $delete_column = $this->getFormatColumnDelete($format['csv_format_type_id']); $ignore_id = $ignore_column['csv_column_id']; $delete_id = $delete_column['csv_column_id']; $return = array(); // store category_id if (!array_key_exists($category_id, $category)) { $category[$category_id] = array(); } elseif (zen_childs_in_category_count($category_id) > 0) { // has child categories return false; } // get category tree $parent_category_tree = array(); zen_get_parent_categories($parent_category_tree, $category_id); $parent_category_id = array_reverse($parent_category_tree); $parent_category_id[] = $category_id; // fetch data foreach ($format['columns'] as $val) { if ($val['csv_column_id'] == $delete_id) { $return[] = 0; } elseif ($val['csv_column_id'] == $ignore_id) { $return[] = ''; } elseif ($val['csv_columns_dbtable'] == 'products') { $sql = 'SELECT p.products_id, p.products_model FROM ' . TABLE_PRODUCTS_TO_CATEGORIES . ' as p2c LEFT JOIN ' . TABLE_PRODUCTS . ' as p ON p2c.products_id=p.products_id WHERE p2c.categories_id=' . $category_id . ''; if ($products_id > 0) { $sql .= " and p.products_id=" . (int) $products_id; } $products = $this->db->Execute($sql); while (!$products->EOF) { $products_id = $products->fields['products_id']; if (!in_array($products_id, $category[$category_id])) { $category[$category_id][] = $products_id; $model = $products->fields['products_model']; break; } $products->MoveNext(); } $return[] = $model; } elseif ($val['csv_columns_dbtable'] == 'categories_description' && $val['csv_columns_dbcolumn'] == 'categories_name') { if (!array_key_exists($val['number'] - 1, $parent_category_id)) { $return[] = ''; continue; } $sql = 'SELECT ' . $val['csv_columns_dbcolumn'] . ' FROM ' . DB_PREFIX . $val['csv_columns_dbtable'] . ' WHERE categories_id=' . $parent_category_id[$val['number'] - 1] . ' AND language_id=' . $val['language_id'] . ''; $name = $this->db->Execute($sql); if ($name->RecordCount() == 1) { $return[] = $name->fields[$val['csv_columns_dbcolumn']]; } else { $return[] = ''; } } else { $sql = 'SELECT ' . $val['csv_columns_dbcolumn'] . ' FROM ' . DB_PREFIX . $val['csv_columns_dbtable'] . ' WHERE categories_id=' . $category_id . ''; if (isset($val['language_id'])) { $sql .= ' AND language_id=' . $val['language_id'] . ''; } $column = $this->db->Execute($sql); if ($column->RecordCount() == 1) { $return[] = $column->fields[$val['csv_columns_dbcolumn']]; } else { $return[] = ''; } } } return $return; }
static function rebuildCpath($cPath) { // do not trust the passed cPath, always rebuild it $current_categories_id = self::getID($cPath, '_'); $category_ids = array(); zen_get_parent_categories($category_ids, (int) $current_categories_id); $category_ids = array_reverse($category_ids); $category_ids[] = (int) $current_categories_id; return implode('_', $category_ids); }