  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: category_tree.php 151 2005-08-02 14:33:25Z mattice $ |
| |
| 3 | + | $Id: category_tree.php 368 2005-12-22 16:27:23Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
35 | 35 | | $category_product_count_end_string = ')'; |
| |
36 | 36 | | |
| |
37 | 37 | | function osC_CategoryTree($load_from_database = true) { |
  |
38 | | - | global $osC_Database, $osC_Session, $osC_Cache; |
| |
| 38 | + | global $osC_Database, $osC_Cache; |
|
39 | 39 | | |
  |
40 | | - | if (SHOW_COUNTS == 'true') { |
| |
| 40 | + | if (SERVICES_CATEGORY_PATH_CALCULATE_PRODUCT_COUNT == '1') { |
|
41 | 41 | | $this->show_category_product_count = true; |
| |
42 | 42 | | } |
| |
43 | 43 | | |
| |
44 | 44 | | if ($load_from_database === true) { |
  |
45 | | - | if ($osC_Cache->read('category_tree-' . $osC_Session->value('language'), 720)) { |
| |
| 45 | + | if ($osC_Cache->read('category_tree-' . $_SESSION['language'], 720)) { |
|
46 | 46 | | $this->data = $osC_Cache->getCache(); |
| |
47 | 47 | | } else { |
  |
48 | | - | $Qcategories = $osC_Database->query('select c.categories_id, cd.categories_name, c.parent_id from :table_categories c, :table_categories_description cd where c.categories_id = cd.categories_id and cd.language_id = :language_id order by c.parent_id, c.sort_order, cd.categories_name'); |
| |
49 | | - | $Qcategories->bindRaw(':table_categories', TABLE_CATEGORIES); |
| |
50 | | - | $Qcategories->bindRaw(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION); |
| |
51 | | - | $Qcategories->bindInt(':language_id', $osC_Session->value('languages_id')); |
| |
| 48 | + | $Qcategories = $osC_Database->query('select c.categories_id, c.parent_id, c.categories_image, cd.categories_name from :table_categories c, :table_categories_description cd where c.categories_id = cd.categories_id and cd.language_id = :language_id order by c.parent_id, c.sort_order, cd.categories_name'); |
| |
| 49 | + | $Qcategories->bindTable(':table_categories', TABLE_CATEGORIES); |
| |
| 50 | + | $Qcategories->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION); |
| |
| 51 | + | $Qcategories->bindInt(':language_id', $_SESSION['languages_id']); |
|
52 | 52 | | $Qcategories->execute(); |
| |
53 | 53 | | |
| |
54 | 54 | | $this->data = array(); |
| |
55 | 55 | | |
| |
56 | 56 | | while ($Qcategories->next()) { |
  |
57 | | - | $this->data[$Qcategories->valueInt('parent_id')][$Qcategories->valueInt('categories_id')] = array('name' => $Qcategories->value('categories_name'), 'count' => 0); |
| |
| 57 | + | $this->data[$Qcategories->valueInt('parent_id')][$Qcategories->valueInt('categories_id')] = array('name' => $Qcategories->value('categories_name'), 'image' => $Qcategories->value('categories_image'), 'count' => 0); |
|
58 | 58 | | } |
| |
59 | 59 | | |
| |
60 | 60 | | $Qcategories->freeResult(); |
| |
|
|
 |
… |
|
78 | 78 | | } |
| |
79 | 79 | | } |
| |
80 | 80 | | |
  |
| 81 | + | function reset() { |
| |
| 82 | + | $this->root_category_id = 0; |
| |
| 83 | + | $this->max_level = 0; |
| |
| 84 | + | $this->root_start_string = ''; |
| |
| 85 | + | $this->root_end_string = ''; |
| |
| 86 | + | $this->parent_start_string = ''; |
| |
| 87 | + | $this->parent_end_string = ''; |
| |
| 88 | + | $this->parent_group_start_string = '<ul>'; |
| |
| 89 | + | $this->parent_group_end_string = '</ul>'; |
| |
| 90 | + | $this->child_start_string = '<li>'; |
| |
| 91 | + | $this->child_end_string = '</li>'; |
| |
| 92 | + | $this->breadcrumb_separator = '_'; |
| |
| 93 | + | $this->breadcrumb_usage = true; |
| |
| 94 | + | $this->spacer_string = ''; |
| |
| 95 | + | $this->spacer_multiplier = 1; |
| |
| 96 | + | $this->follow_cpath = false; |
| |
| 97 | + | $this->cpath_array = array(); |
| |
| 98 | + | $this->cpath_start_string = ''; |
| |
| 99 | + | $this->cpath_end_string = ''; |
| |
| 100 | + | $this->show_category_product_count = (SERVICES_CATEGORY_PATH_CALCULATE_PRODUCT_COUNT == '1') ? true : false; |
| |
| 101 | + | $this->category_product_count_start_string = ' ('; |
| |
| 102 | + | $this->category_product_count_end_string = ')'; |
| |
| 103 | + | } |
| |
| 104 | + | |
|
81 | 105 | | function buildBranch($parent_id, $level = 0) { |
| |
82 | 106 | | $result = $this->parent_group_start_string; |
| |
83 | 107 | | |
| |
|
|
 |
… |
|
203 | 227 | | return $this->buildBranchArray((empty($parent_id) ? $this->root_category_id : $parent_id)); |
| |
204 | 228 | | } |
| |
205 | 229 | | |
  |
| 230 | + | function exists($id) { |
| |
| 231 | + | foreach ($this->data as $parent => $categories) { |
| |
| 232 | + | foreach ($categories as $category_id => $info) { |
| |
| 233 | + | if ($id == $category_id) { |
| |
| 234 | + | return true; |
| |
| 235 | + | } |
| |
| 236 | + | } |
| |
| 237 | + | } |
| |
| 238 | + | |
| |
| 239 | + | return false; |
| |
| 240 | + | } |
| |
| 241 | + | |
| |
| 242 | + | function getData($id) { |
| |
| 243 | + | foreach ($this->data as $parent => $categories) { |
| |
| 244 | + | foreach ($categories as $category_id => $info) { |
| |
| 245 | + | if ($id == $category_id) { |
| |
| 246 | + | return array('id' => $id, |
| |
| 247 | + | 'name' => $info['name'], |
| |
| 248 | + | 'parent_id' => $parent, |
| |
| 249 | + | 'image' => $info['image'], |
| |
| 250 | + | 'count' => $info['count'] |
| |
| 251 | + | ); |
| |
| 252 | + | } |
| |
| 253 | + | } |
| |
| 254 | + | } |
| |
| 255 | + | |
| |
| 256 | + | return false; |
| |
| 257 | + | } |
| |
| 258 | + | |
  |
206 | 259 | | function calculateCategoryProductCount() { |
| |
207 | 260 | | foreach ($this->data as $parent => $categories) { |
| |
208 | 261 | | foreach ($categories as $id => $info) { |