1) { echo ' ' . tep_draw_form('filter', FILENAME_DEFAULT, 'get') . TEXT_SHOW . ' '; $options = ''; $num_max_cats = 0; $category_options = array(); while ($filterlist = tep_db_fetch_array($filterlist_query)) { $filter_id = $filterlist['id']; $categories = array(); tep_get_parent_categories($categories, $filter_id); $categories = array_reverse($categories); $categories[] = $filter_id; //add this category to the end for ($i=0, $n=sizeof($categories); $i<$n; ++$i) { //FILTER_MAX_LEVELS //sizeof($categories) if (tep_not_null($categories[($i+1)]) && !in_arrayr($categories[($i+1)], $category_options)) { if ($i == 0 && !in_arrayr($categories[$i], $category_main)) { $category_options_name = tep_get_cat_name($categories[$i]); $category_main[] = array('id' => $categories[$i], 'text' => $category_options_name); $category_options_name = tep_get_cat_name($categories[($i+1)]); $category_options[$categories[$i]][] = array('id' => $categories[($i+1)], 'text' => $category_options_name); } else { $category_options_name = tep_get_cat_name($categories[($i+1)]); $category_options[$categories[$i]][] = array('id' => $categories[($i+1)], 'text' => $category_options_name); } $category_options[$categories[$i]] = tep_sort_array_names($category_options[$categories[$i]]); } if (($i+1) > $num_max_cats) $num_max_cats = ($i+1); } } while (list ($key, $val) = each ($category_options)) { $this_level_option_names = ''; $this_level_option_values = ''; foreach($category_options[$key] as $key2 => $val2) { $this_level_option_names .= '"' . $val2['text'] . '",'; $this_level_option_values .= $val2['id'] . ','; } $this_level_option_names = substr_replace($this_level_option_names,"",-1); $this_level_option_values = substr_replace($this_level_option_values,"",-1); if (sizeof($category_options[$key]) == 1) { //add this for single category javascript redirect $this_level_option_names = $this_level_option_names . ',""'; $this_level_option_values = $this_level_option_values . ',-1'; } $options .= 'optionsArray[' . $key . '] = new Array(' . $this_level_option_names . ')' . "\n"; $options .= 'valuesArray[' . $key . '] = new Array(' . $this_level_option_values . ')' . "\n"; } $category_main = tep_sort_array_names($category_main); array_unshift($category_main, array('id' => '', 'text' => FILTER_DEFAULT_TEXT)); //DRAW THE FIRST MAIN DROP DOWN echo tep_draw_pull_down_menu('Menu', $category_main, '', 'onChange="updateOptions(0,this.options[this.selectedIndex].value);"'); $default_text = array(array('id' => '', 'text' => FILTER_DEFAULT_TEXT_INACTIVE)); // DRAW THE REST OF THE DROP DOWNS - start at 1, 0 is already drawn for ($i=1, $n=$num_max_cats; $i<$n; ++$i) { $menu_number = $i; echo FILTER_DROP_DOWN_DEVIDER; echo tep_draw_pull_down_menu('Menu', $default_text, '', 'onChange="updateOptions(' . $menu_number . ',this.options[this.selectedIndex].value);"'); } //DRAW DEFAULT HIDDEN FIELDS echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']); echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']); echo tep_draw_hidden_field('filter_id', '', 'value=""'); echo '' . "\n"; } else { // NOTHING TO DISPLAY echo '  '; } // ############################### // # FUNCTIONS START // ############################### function in_arrayr($needle, $haystack) { if (is_array($haystack)) { foreach ($haystack as $v) { if ($needle == $v) return true; elseif (is_array($v)) { if (in_arrayr($needle, $v) === true) return true; } } } return false; } function tep_sort_array_names($array) { if (is_array($array)) { foreach($array as $key => $val) { $array_id[$key] = $val['id']; $array_name[$key] = $val['text']; } array_multisort($array_name, SORT_ASC, $array); } return $array; } 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 // ############################### ?>