1) {
echo '
' . tep_draw_form('filter', FILENAME_DEFAULT, 'get') . TEXT_SHOW . ' ';
$all_categories = array();
$filter_max_levels = 0;
echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']);
while ($filterlist = tep_db_fetch_array($filterlist_query)) {
//$categories_level1 = array();
//$categories_level2 = array();
//$categories_level3 = array();
$categories_list = array();
// GET ALL CATEGORY PATHS FROM THIS MFG
$this_category = $filterlist['id'];
$this_category_path = tep_get_cat_path($this_category);
if (tep_not_null($this_category_path) && !in_array($this_category_path, $all_categories)) {
$all_categories[] = $this_category_path;
//echo '$this_category=' . $this_category_path . ' ';
// GET MAX LEVELS
$split_cats = split("_", $this_category_path);
if (sizeof($split_cats) > $filter_max_levels) $filter_max_levels = sizeof($split_cats);
}
}
//echo 'MAX=' . $filter_max_levels . ' ';
define('FILTER_MAX_LEVELS', $filter_max_levels);
//SORT CATEGORIES INTO ARRAYS
echo "\n"; //temp
$ac = sizeof($all_categories);
for ($i=0, $n=$ac; $i<$n; ++$i) {
//$all_categories_hidden .= $all_categories[$i] . ',';
//echo $all_categories[$i] . ' ';
$split_cats = split("_", $all_categories[$i], FILTER_MAX_LEVELS);
$max_level = sizeof($split_cats);
for ($cl=0, $ml=$max_level; $cl<$ml; ++$cl) {
$catID = $split_cats[$cl];
$catName = tep_get_cat_name($catID);
$cat_lvl = $cl+1;
if (!in_array($catID, $categories_list)) {
$categories_list[] = $catID;
$categories_level[$cat_lvl][] = array('id' => $catID, 'text' => $catName);
}
//echo ' cat_level=' . $cat_lvl . ' $cl=' . $cl . ' $max_level=' . $max_level . ' $catID=' . $catID . ' $catName=' . $catName . ' ';
}
}
//echo tep_draw_hidden_field('all_categories_hidden', $all_categories_hidden);
// SORT MAIN ARRAY
$categories_level[1][] = array('id' => '', 'text' => FILTER_DEFAULT_TEXT);
foreach($categories_level[1] as $key => $val) {
//echo " $key => (" . $val['id'] . " ," . $val['text'] . ")";
$category_id[$key] = $val['id'];
$category_name[$key] = $val['text'];
}
array_multisort($category_name, SORT_ASC, $categories_level[1]);
// SORT CATEGORIES INTO JAVASCRIPT OPTIONS
$options = '';
for ($lvl=1, $m=FILTER_MAX_LEVELS; $lvl<$m; ++$lvl) {
$level_to_sort = $lvl;
//echo '';
$this_level_ID = 0;
foreach($categories_level[$level_to_sort] as $key => $val) {
//echo " $key => (" . $val['id'] . " ," . $val['text'] . ")";
$this_level_ID = $val['id'];
$this_level_option_names = '';
$this_level_option_values = '';
$this_level_list = array();
for ($i=0, $n=$ac; $i<$n; ++$i) {
$split_levels = split("_", $all_categories[$i], FILTER_MAX_LEVELS);
$current_level = $split_levels[$level_to_sort - 1];
$level_to_get = $split_levels[$level_to_sort];
$next_level = $split_levels[$level_to_sort + 1];
$this_level_sub_name = tep_get_cat_name($level_to_get);
if ($current_level == $this_level_ID && !in_array($level_to_get, $this_level_list) && $this_level_sub_name != '') {
$this_level_list[] = $level_to_get;
$this_level_option_names .= '"' . $this_level_sub_name . '",';
$this_level_option_values .= $level_to_get . ',';
}
}
if ($this_level_ID != '' && $this_level_option_names != '' && $this_level_option_values != '') {
$this_level_option_names = substr_replace($this_level_option_names,"",-1);
$this_level_option_values = substr_replace($this_level_option_values,"",-1);
$options .= 'optionsArray[' . $this_level_ID . '] = new Array(' . $this_level_option_names . ')' . "\n";
$options .= 'valuesArray[' . $this_level_ID . '] = new Array(' . $this_level_option_values . ')' . "\n";
//echo 'key=' . $this_level_ID . ' names=' . $this_level_option_names . ' values=' . $this_level_option_values . ' ';
}
$main_check = $level_to_sort - 1;
if ($main_check != 0) {
unset($categories_level[$level_to_sort][$key]); //delete element to speed up array search
}
}
//echo '';
//print_r($categories_level[$level_to_sort]);
//echo ' '; //temp
}
$default_text = array(array('id' => '', 'text' => FILTER_DEFAULT_TEXT));
//DRAW THE FIRST MAIN DROP DOWN
echo tep_draw_pull_down_menu('Menu', $categories_level[1], '', 'onChange="updateOptions(0,this.options[this.selectedIndex].value);"');
// DRAW THE REST OF THE DROP DOWNS
for ($i=1, $n=FILTER_MAX_LEVELS; $i<$n; ++$i) {
echo FILTER_DROP_DOWN_DEVIDER;
echo tep_draw_pull_down_menu('Menu', $default_text, '', 'onChange="updateOptions(' . $i . ',this.options[this.selectedIndex].value);"');
}
//DRAW HIDDEN MFG_ID INPUT
echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']);
//DRAW HIDDEN FILTER_ID INPUT
echo tep_draw_hidden_field('filter_id', '', 'value=""');
echo ' | ' . "\n";
}
else { // NOTHING TO DISPLAY
echo ' | ';
}
//echo 'ALL CATEGORIES:
';
//print_r($all_categories);
// ###############################
// # FUNCTIONS START
// ###############################
function tep_get_cat_path($category_id) {
$cPath = '';
$category_query = tep_db_query("select distinct c.categories_id from " . TABLE_CATEGORIES . " c where c.categories_id = '" . (int)$category_id . "'");
if (tep_db_num_rows($category_query)) {
$category = tep_db_fetch_array($category_query);
$categories = array();
tep_get_parent_categories($categories, $category['categories_id']);
$categories = array_reverse($categories);
$cPath = implode('_', $categories);
if (tep_not_null($cPath)) $cPath .= '_';
$cPath .= $category['categories_id'];
}
return $cPath;
}
function tep_get_cat_name($category_id) {
global $languages_id;
$cName = '';
$category_sql = ("select distinct
cd.categories_name
from " . TABLE_CATEGORIES_DESCRIPTION . " cd
where cd.categories_id = '" . (int)$category_id . "' and
cd.language_id = '" . (int)$languages_id . "'");
$category_query = tep_db_query($category_sql);
while ($category = tep_db_fetch_array($category_query)) {
$cName = $category['categories_name'];
}
return $cName;
}
// ###############################
// # FUNCTIONS STOP
// ###############################
?>
|