[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * category_tree Class. 4 * 5 * @package classes 6 * @copyright Copyright 2003-2006 Zen Cart Development Team 7 * @copyright Portions Copyright 2003 osCommerce 8 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 9 * @version $Id: category_tree.php 3041 2006-02-15 21:56:45Z wilt $ 10 */ 11 if (!defined('IS_ADMIN_FLAG')) { 12 die('Illegal Access'); 13 } 14 /** 15 * category_tree Class. 16 * This class is used to generate the category tree used for the categories sidebox 17 * 18 * @package classes 19 */ 20 class category_tree extends base { 21 22 function zen_category_tree($product_type = "all") { 23 global $db, $cPath, $cPath_array; 24 if ($product_type != 'all') { 25 $sql = "select type_master_type from " . TABLE_PRODUCT_TYPES . " 26 where type_master_type = " . $product_type . ""; 27 $master_type_result = $db->Execute($sql); 28 $master_type = $master_type_result->fields['type_master_type']; 29 } 30 $this->tree = array(); 31 if ($product_type == 'all') { 32 $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image 33 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd 34 where c.parent_id = 0 35 and c.categories_id = cd.categories_id 36 and cd.language_id='" . (int)$_SESSION['languages_id'] . "' 37 and c.categories_status= 1 38 order by sort_order, cd.categories_name"; 39 } else { 40 $categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id, c.categories_image 41 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc 42 where c.parent_id = 0 43 and ptc.category_id = cd.categories_id 44 and ptc.product_type_id = " . $master_type . " 45 and c.categories_id = ptc.category_id 46 and cd.language_id=" . (int)$_SESSION['languages_id'] ." 47 and c.categories_status= 1 48 order by sort_order, cd.categories_name"; 49 } 50 $categories = $db->Execute($categories_query, '', true, 150); 51 while (!$categories->EOF) { 52 $this->tree[$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 53 'parent' => $categories->fields['parent_id'], 54 'level' => 0, 55 'path' => $categories->fields['categories_id'], 56 'image' => $categories->fields['categories_image'], 57 'next_id' => false); 58 59 if (isset($parent_id)) { 60 $this->tree[$parent_id]['next_id'] = $categories->fields['categories_id']; 61 } 62 63 $parent_id = $categories->fields['categories_id']; 64 65 if (!isset($first_element)) { 66 $first_element = $categories->fields['categories_id']; 67 } 68 $categories->MoveNext(); 69 } 70 if (zen_not_null($cPath)) { 71 $new_path = ''; 72 reset($cPath_array); 73 while (list($key, $value) = each($cPath_array)) { 74 unset($parent_id); 75 unset($first_id); 76 if ($product_type == 'all') { 77 $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image 78 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd 79 where c.parent_id = " . (int)$value . " 80 and c.categories_id = cd.categories_id 81 and cd.language_id=" . (int)$_SESSION['languages_id'] . " 82 and c.categories_status= 1 83 order by sort_order, cd.categories_name"; 84 } else { 85 /* 86 $categories_query = "select ptc.category_id as categories, cd.categories_name, c.parent_id, c.categories_image 87 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc 88 where c.parent_id = '" . (int)$value . "' 89 and ptc.category_id = cd.categories_id 90 and ptc.product_type_id = '" . $master_type . "' 91 and cd.language_id='" . (int)$_SESSION['languages_id'] . "' 92 and c.categories_status= '1' 93 order by sort_order, cd.categories_name"; 94 */ 95 $categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id, c.categories_image 96 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc 97 where c.parent_id = " . (int)$value . " 98 and ptc.category_id = cd.categories_id 99 and ptc.product_type_id = " . $master_type . " 100 and c.categories_id = ptc.category_id 101 and cd.language_id=" . (int)$_SESSION['languages_id'] ." 102 and c.categories_status= 1 103 order by sort_order, cd.categories_name"; 104 105 } 106 107 $rows = $db->Execute($categories_query); 108 109 if ($rows->RecordCount()>0) { 110 $new_path .= $value; 111 while (!$rows->EOF) { 112 $this->tree[$rows->fields['categories_id']] = array('name' => $rows->fields['categories_name'], 113 'parent' => $rows->fields['parent_id'], 114 'level' => $key+1, 115 'path' => $new_path . '_' . $rows->fields['categories_id'], 116 'image' => $categories->fields['categories_image'], 117 'next_id' => false); 118 119 if (isset($parent_id)) { 120 $this->tree[$parent_id]['next_id'] = $rows->fields['categories_id']; 121 } 122 123 $parent_id = $rows->fields['categories_id']; 124 if (!isset($first_id)) { 125 $first_id = $rows->fields['categories_id']; 126 } 127 128 $last_id = $rows->fields['categories_id']; 129 $rows->MoveNext(); 130 } 131 $this->tree[$last_id]['next_id'] = $this->tree[$value]['next_id']; 132 $this->tree[$value]['next_id'] = $first_id; 133 $new_path .= '_'; 134 } else { 135 break; 136 } 137 } 138 } 139 $row = 0; 140 return $this->zen_show_category($first_element, $row); 141 } 142 143 function zen_show_category($counter,$ii) { 144 global $cPath_array; 145 146 $this->categories_string = ""; 147 148 for ($i=0; $i<$this->tree[$counter]['level']; $i++) { 149 if ($this->tree[$counter]['parent'] != 0) { 150 $this->categories_string .= CATEGORIES_SUBCATEGORIES_INDENT; 151 } 152 } 153 154 155 if ($this->tree[$counter]['parent'] == 0) { 156 $cPath_new = 'cPath=' . $counter; 157 $this->box_categories_array[$ii]['top'] = 'true'; 158 } else { 159 $this->box_categories_array[$ii]['top'] = 'false'; 160 $cPath_new = 'cPath=' . $this->tree[$counter]['path']; 161 $this->categories_string .= CATEGORIES_SEPARATOR_SUBS; 162 } 163 $this->box_categories_array[$ii]['path'] = $cPath_new; 164 165 if (isset($cPath_array) && in_array($counter, $cPath_array)) { 166 $this->box_categories_array[$ii]['current'] = true; 167 } else { 168 $this->box_categories_array[$ii]['current'] = false; 169 } 170 171 // display category name 172 $this->box_categories_array[$ii]['name'] = $this->categories_string . $this->tree[$counter]['name']; 173 174 // make category image available in case needed 175 $this->box_categories_array[$ii]['image'] = $this->tree[$counter]['image']; 176 177 if (zen_has_category_subcategories($counter)) { 178 $this->box_categories_array[$ii]['has_sub_cat'] = true; 179 } else { 180 $this->box_categories_array[$ii]['has_sub_cat'] = false; 181 } 182 183 if (SHOW_COUNTS == 'true') { 184 $products_in_category = zen_count_products_in_category($counter); 185 if ($products_in_category > 0) { 186 $this->box_categories_array[$ii]['count'] = $products_in_category; 187 } else { 188 $this->box_categories_array[$ii]['count'] = 0; 189 } 190 } 191 192 if ($this->tree[$counter]['next_id'] != false) { 193 $ii++; 194 $this->zen_show_category($this->tree[$counter]['next_id'], $ii); 195 } 196 return $this->box_categories_array; 197 } 198 } 199 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |