trail('/'), "/"), 1); if (empty($currency_type)) { $currency_type = $_SESSION['currency']; } $currency_symbol = $currencies->currencies[$currency_type]['symbol_left']; $conversion_rate = $currencies->get_value($_SESSION['currency']); $resetParms = array(); $display_limit = zen_get_new_date_range(); if (FILTER_GOOGLE_TRACKING == 'Asynchronous') { $trackingStart = '_gaq.push([\'_trackEvent\', '; $trackingEnd = ']);'; } else if (FILTER_GOOGLE_TRACKING == 'ga.js') { $trackingStart = 'pageTracker._trackEvent('; $trackingEnd = ');'; } // draw filter form $content = ''; $content .= '
'; $content .= zen_draw_form('product_filter_form','', 'get'); // draw hidden fields reset($_GET); while(list($key, $value) = each ($_GET)) { if ( ($key != 'main_page' || $key == 'main_page' && (!defined('CEON_URI_MAPPING_ENABLED') || CEON_URI_MAPPING_ENABLED == 0 || $current_page_base == 'advanced_search_result')) && ($key != zen_session_name()) && ($key != 'error') && ($key != 'currency') && ($key != 'x') && ($key != 'y') && ($key != 'filter_id') ) { if ((substr($key,0,strlen(DYNAMIC_FILTER_PREFIX)) != DYNAMIC_FILTER_PREFIX) ) { $content .= zen_draw_hidden_field($key, $value); } } } // use $listing_sql to populate dynamic filter $query_lower = strtolower($listing_sql); $pos_from = strpos($query_lower, ' from', 0); $pos_where = strpos($query_lower, ' where', 0); $pos_group = strpos($query_lower, ' group by', 0); $pos_to = strlen($query_lower); if ($pos_group == 0) { $pos_group = $pos_to; } // list filtered and unfiltered products for category $unfiltered = $db->Execute(str_replace(array($filter, $having), array("",""), "SELECT p.products_id, p.products_price_sorter, p.master_categories_id, p.manufacturers_id" . substr($listing_sql, $pos_from, ($pos_where - $pos_from)) . substr($listing_sql, $pos_where, ($pos_group - $pos_where)))); $filtered = $db->Execute("SELECT p.products_id, p.products_price_sorter, p.master_categories_id, p.manufacturers_id" . substr($listing_sql, $pos_from, ($pos_where - $pos_from)) . substr($listing_sql, $pos_where, ($pos_to - $pos_where))); if ($filtered->RecordCount() == 0) { $filtered = $db->Execute(str_replace(array($filter, $having), array("",""), "SELECT p.products_id, p.products_price_sorter, p.master_categories_id, p.manufacturers_id" . substr($listing_sql, $pos_from, ($pos_where - $pos_from)) . substr($listing_sql, $pos_where, ($pos_group - $pos_where)))); } // retrieve filtered and unfiltered product options $min = 0; $max = 0; while (!$unfiltered->EOF) { if ($min == 0 or round($unfiltered->fields['products_price_sorter'], 2) < $min) { $min = round($unfiltered->fields['products_price_sorter'], 2); } if (round($unfiltered->fields['products_price_sorter'], 2) > $max) { $max = round($unfiltered->fields['products_price_sorter'], 2); } $unfilteredProducts[] = $unfiltered->fields['products_id']; $unfilteredManufacturers[] = $unfiltered->fields['manufacturers_id']; $unfilteredCategories[] = $unfiltered->fields['master_categories_id']; $unfiltered->MoveNext(); } while (!$filtered->EOF) { $priceArray[] = round($filtered->fields['products_price_sorter'], 2); $filteredProducts[] = $filtered->fields['products_id']; $filteredManufacturers[] = $filtered->fields['manufacturers_id']; $filteredCategories[] = $filtered->fields['master_categories_id']; $filtered->MoveNext(); } if (count($unfilteredManufacturers) > 1) { $unfilteredManufacturers = array_filter(array_unique($unfilteredManufacturers)); } if (count($unfilteredCategories) > 1) { $unfilteredCategories = array_filter(array_unique($unfilteredCategories)); } if (count($unfilteredProducts) > 1) { $unfilteredProducts = array_filter(array_unique($unfilteredProducts)); } if (count($filteredManufacturers) > 1) { $filteredManufacturers = array_filter(array_unique($filteredManufacturers)); } if (count($filteredCategories) > 1) { $filteredCategories = array_filter(array_unique($filteredCategories)); } if (count($filteredProducts) > 1) { $filteredProducts = array_filter(array_unique($filteredProducts)); } if (count($priceArray) > 1) { $priceArray = array_filter(array_unique($priceArray)); } /* * start manufacturer/category drop down/link/check boxes */ // Only display if standard zen cart category/manufacturer dropdown is disabled if (PRODUCT_LIST_FILTER == 0) { if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] != '' || $current_page_base == 'products_all' || $current_page_base == 'products_new' || $current_page_base == 'specials' || $current_page_base == 'featured_products' || $current_page_base == 'advanced_search_result') { if (count($unfilteredCategories) > 0) { $group = DYNAMIC_FILTER_PREFIX . str_replace(' ', '', DYNAMIC_FILTER_CATEGORY_GROUP); $resetParms[] = $group; $parameters = zen_get_all_get_params(); $dropdownDefault = str_replace('%n', DYNAMIC_FILTER_CATEGORY_GROUP, DYNAMIC_FILTER_DROPDOWN_DEFAULT); // BOF language fix by a_berezin $categories = $db->Execute("SELECT categories_id, categories_name, IF(categories_id IN (" . implode(',', $filteredCategories) . "), 'Y', 'N') as flag" . " FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id IN (" . implode(',', $unfilteredCategories) . ")" . " AND language_id=" . (int)$_SESSION['languages_id'] . " ORDER BY categories_name"); // EOF language fix $content .= '

' . DYNAMIC_FILTER_TEXT_PREFIX . DYNAMIC_FILTER_TEXT_CATEGORY . DYNAMIC_FILTER_TEXT_SUFFIX . '

'; if (isset($_GET[$group]) && array_filter($_GET[$group])) $content .= ''; if (strtok(FILTER_STYLE, " ") == 'Dropdown') $content .= ''; } else { $content .= ''; } if (FILTER_OPTIONS_STYLE == 'Expand' && count($unfilteredCategories) > FILTER_MAX_OPTIONS) { $content .= '' . TEXT_DYNAMIC_FILTER_SHOW_MORE . zen_image(DIR_WS_TEMPLATE_IMAGES . 'arrow_more.gif', TEXT_DYNAMIC_FILTER_SHOW_MORE, '', '', 'class="dFilterToggleImg"') . ''; } $content .= '
'; } } if (!isset($_GET['manufacturers_id'])) { if (count($unfilteredManufacturers) > 0) { $group = DYNAMIC_FILTER_PREFIX . str_replace(' ', '', DYNAMIC_FILTER_MANUFACTURER_GROUP); $resetParms[] = $group; $parameters = zen_get_all_get_params(array($group)); $dropdownDefault = str_replace('%n', DYNAMIC_FILTER_MANUFACTURER_GROUP, DYNAMIC_FILTER_DROPDOWN_DEFAULT); // BOF fix by a_berezin if (sizeof($filteredManufacturers) > 0) { $manufacturers = $db->Execute("SELECT manufacturers_id, manufacturers_name, IF(manufacturers_id IN(" . implode(',', $filteredManufacturers) . "), 'Y', 'N') as flag" . " FROM " . TABLE_MANUFACTURERS . " WHERE manufacturers_id IN (" . implode(',', $unfilteredManufacturers) . ")" . " ORDER BY manufacturers_name"); } else { $manufacturers = $db->Execute("SELECT manufacturers_id, manufacturers_name, 'N' as flag" . " FROM " . TABLE_MANUFACTURERS . " WHERE manufacturers_id IN (" . implode(',', $unfilteredManufacturers) . ")" . " ORDER BY manufacturers_name"); } // EOF fix $content .= ''; $content .= '

' . DYNAMIC_FILTER_TEXT_PREFIX . DYNAMIC_FILTER_TEXT_MANUFACTURER . DYNAMIC_FILTER_TEXT_SUFFIX . '

'; if (isset($_GET[$group]) && array_filter($_GET[$group])) $content .= ''; if (strtok(FILTER_STYLE, " ") == 'Dropdown') $content .= ''; else $content .= ''; if (FILTER_OPTIONS_STYLE == 'Expand' && count($unfilteredManufacturers) > FILTER_MAX_OPTIONS) $content .= '' . TEXT_DYNAMIC_FILTER_SHOW_MORE . zen_image(DIR_WS_TEMPLATE_IMAGES . 'arrow_more.gif', TEXT_DYNAMIC_FILTER_SHOW_MORE, '', '', 'class="dFilterToggleImg"') . ''; $content .= '
'; } } } /* * end manufacturer/category drop down/link/check boxes */ /* * start price range link/check boxes */ if (PRODUCT_LIST_FILTER == 0) { if (count($priceArray) > 0) { $priceGap = floor(($max - $min) / (FILTER_MAX_RANGES - 1)); if (FILTER_MIN_PRICE > 0 && $priceGap < FILTER_MIN_PRICE) { $priceGap = FILTER_MIN_PRICE; } if (FILTER_MAX_PRICE > 0 && $priceGap > FILTER_MAX_PRICE) { $priceGap = FILTER_MAX_PRICE; } $group = DYNAMIC_FILTER_PREFIX . str_replace(' ', '', DYNAMIC_FILTER_PRICE_GROUP); $resetParms[] = $group; $parameters = zen_get_all_get_params(); $dropdownDefault = str_replace('%n', DYNAMIC_FILTER_PRICE_GROUP, DYNAMIC_FILTER_DROPDOWN_DEFAULT); $priceCount = 0; $prices = ''; for ($start = $min - 0.5; $start < $max; $start = $end + 0.01) { $end = round($start + $priceGap); if ($end < $max) { // BOF tax fix by design75 $text = $currency_symbol . round(zen_add_tax($start, $products_tax) * $conversion_rate) . TEXT_DYNAMIC_FILTER_DIVIDER . $currency_symbol . round(zen_add_tax($end, $products_tax) * $conversion_rate); } else { $text = $currency_symbol . round(zen_add_tax($start, $products_tax) * $conversion_rate) . TEXT_DYNAMIC_FILTER_AND_OVER; // EOF tax fix } foreach($priceArray as $price ) { if ($start <= $price && $end >= $price) { if (isset($_GET[$group]) && in_array($start . '--' . $end,$_GET[$group])) { $linkClass = 'selected'; } else { $linkClass = 'enabled'; } break; } else { $linkClass = 'disabled'; } } $onClick = ''; if (FILTER_GOOGLE_TRACKING != 'No') $onClick .= $trackingStart . '\'filterAction\', \'' . ($linkClass != 'selected' ? 'addFilter' : 'removeFilter') . '\', \'' . $pageName . ';' . DYNAMIC_FILTER_PRICE_GROUP . '=' . $start . '-' . $end . '\'' . $trackingEnd; if (FILTER_STYLE == 'Checkbox - Single') $onClick .= ' this.form.submit();'; if (FILTER_METHOD != 'Hidden' || $linkClass != 'disabled') { $hrefLink = $group . '[]=' . $start . '--' . $end; switch(strtok(FILTER_STYLE, " ")) { case 'Checkbox': $prices .= ''; break; case 'Link': $prices .= ''; break; case 'Dropdown': $prices .= ''; break; } } ++$priceCount; } $content .= ''; $content .= '

' . DYNAMIC_FILTER_TEXT_PREFIX . DYNAMIC_FILTER_TEXT_PRICE . DYNAMIC_FILTER_TEXT_SUFFIX . '

'; if (isset($_GET[$group]) && array_filter($_GET[$group])) $content .= ''; if (strtok(FILTER_STYLE, " ") == 'Dropdown') $content .= ''; else $content .= ''; if (FILTER_OPTIONS_STYLE == 'Expand' && $priceCount > FILTER_MAX_OPTIONS) $content .= '' . TEXT_DYNAMIC_FILTER_SHOW_MORE . zen_image(DIR_WS_TEMPLATE_IMAGES . 'arrow_more.gif', TEXT_DYNAMIC_FILTER_SHOW_MORE, '', '', 'class="dFilterToggleImg"') . ''; $content .= '
'; } } /* * end price range link/check boxes */ /* * start attribute link/check boxes */ if(count($filteredProducts) > 0) { // Below line counts up all quantities of each item. e.g. if a glove is available in Small and Medium, quantity = 2. //$attributes = $db->Execute("SELECT po.products_options_name, pov.products_options_values_name, count( p2as.quantity ) as quantity" . // BOF language fix by a_berezin $attributes = $db->Execute("SELECT count(DISTINCT p2a.products_id) as quantity, po.products_options_name, pov.products_options_values_name," . " SUM(IF(p2a.products_id IN(" . implode(',', $filteredProducts) . "), 1, 0)) as flag" . " FROM " . TABLE_PRODUCTS_ATTRIBUTES . " p2a ". " JOIN " . TABLE_PRODUCTS_OPTIONS . " po ON p2a.options_id = po.products_options_id AND po.language_id=" . (int)$_SESSION['languages_id'] . " JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES ." pov ON p2a.options_values_id = pov.products_options_values_id AND pov.language_id=" . (int)$_SESSION['languages_id'] . (defined('TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK') ? " JOIN " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " p2as ON p2a.products_id = p2as.products_id AND p2as.stock_attributes LIKE CONCAT('%', p2a.products_attributes_id, '%')" : "") . " WHERE p2a.products_id IN (" . implode(',', $unfilteredProducts) . ")" . (FILTER_OPTIONS_INCLUDE != '' ? " AND p2a.options_id IN (" . FILTER_OPTIONS_INCLUDE . ")" : '') . (FILTER_OPTIONS_EXCLUDE != '' ? " AND p2a.options_id NOT IN (" . FILTER_OPTIONS_EXCLUDE . ")" : '') . (defined('TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK') ? " AND p2as.quantity > 0" : "") . " GROUP BY po.products_options_name, pov.products_options_values_name" . " ORDER BY po.products_options_name, pov.products_options_values_sort_order"); // EOF language fix $savName = ''; $savValue = ''; while (!$attributes->EOF) { // output if option name changes!!! if ($attributes->fields['products_options_name'] != $savName) { $options_array = array(); if ($savName != "") { $content .= ''; $content .= '

' . DYNAMIC_FILTER_TEXT_PREFIX . htmlspecialchars(html_entity_decode($savName, ENT_QUOTES)) . DYNAMIC_FILTER_TEXT_SUFFIX . '

'; if (isset($_GET[$group]) && array_filter($_GET[$group])) $content .= ''; if (strtok(FILTER_STYLE, " ") == 'Dropdown') $content .= ''; else $content .= ''; if (FILTER_OPTIONS_STYLE == 'Expand' && $attrCount > FILTER_MAX_OPTIONS) $content .= '' . TEXT_DYNAMIC_FILTER_SHOW_MORE . zen_image(DIR_WS_TEMPLATE_IMAGES . 'arrow_more.gif', TEXT_DYNAMIC_FILTER_SHOW_MORE, '', '', 'class="dFilterToggleImg"') . ''; $content .= '
'; } $group = DYNAMIC_FILTER_PREFIX . str_replace(' ', '', $attributes->fields['products_options_name']); $resetParms[] = $group; $parameters = zen_get_all_get_params(); $dropdownDefault = str_replace('%n', $attributes->fields['products_options_name'], DYNAMIC_FILTER_DROPDOWN_DEFAULT); $filters = ''; $attrCount = 0; } if ($attributes->fields['products_options_values_name'] != $savValue) { if (isset($_GET[$group]) && in_array($attributes->fields['products_options_values_name'],$_GET[$group])) $linkClass = 'selected'; else if (isset($_GET[$group]) && array_filter($_GET[$group]) && !in_array($attributes->fields['products_options_values_name'],$_GET[$group]) || $attributes->fields['flag'] == 0) $linkClass = 'disabled'; //else if ($attributes->fields['flag'] == 0) $linkClass = 'disabled'; else $linkClass = 'enabled'; $onClick = ''; if (FILTER_GOOGLE_TRACKING != 'No') $onClick .= $trackingStart . '\'filterAction\', \'' . ($linkClass != 'selected' ? 'addFilter' : 'removeFilter') . '\', \'' . $pageName . ';' . $attributes->fields['products_options_name'] . '=' . htmlspecialchars(html_entity_decode($attributes->fields['products_options_values_name'], ENT_QUOTES)) . '\'' . $trackingEnd; if (FILTER_STYLE == 'Checkbox - Single') $onClick .= ' this.form.submit();'; if (FILTER_METHOD != 'Hidden' || $linkClass != 'disabled') { $hrefLink = $group . '[]=' . rawurlencode($attributes->fields['products_options_values_name']); switch(strtok(FILTER_STYLE, " ")) { case 'Checkbox': $filters .= ''; break; case 'Link': $filters .= ''; break; case 'Dropdown': $filters .= ''; break; } ++$attrCount; } } $savValue = $attributes->fields['products_options_values_name']; $savName = $attributes->fields['products_options_name']; $attributes->MoveNext(); } if ($savName != "") { $content .= ''; $content .= '

' . DYNAMIC_FILTER_TEXT_PREFIX . htmlspecialchars(html_entity_decode($savName, ENT_QUOTES)) . DYNAMIC_FILTER_TEXT_SUFFIX . '

'; if (isset($_GET[$group]) && array_filter($_GET[$group])) $content .= ''; if (strtok(FILTER_STYLE, " ") == 'Dropdown') $content .= ''; else $content .= ''; if (FILTER_OPTIONS_STYLE == 'Expand' && $attrCount > FILTER_MAX_OPTIONS) $content .= '' . TEXT_DYNAMIC_FILTER_SHOW_MORE . zen_image(DIR_WS_TEMPLATE_IMAGES . 'arrow_more.gif', TEXT_DYNAMIC_FILTER_SHOW_MORE, '', '', 'class="dFilterToggleImg"') . ''; $content .= '
'; } /* * end attribute link/check boxes */ /* * start filter buttons */ if (FILTER_STYLE == 'Dropdown - Multi' || FILTER_STYLE == 'Checkbox - Multi') { $content .= '
'; $content .= zen_image_submit('button_filter.png', DYNAMIC_FILTER_BUTTON_FILTER_ALT) . '
'; $content .= '
'; } $content .= '
'; foreach($resetParms as $reset) { if (isset($_GET[$reset])) { $content .= '' . zen_image_button('button_clear_all_filters.png', DYNAMIC_FILTER_BUTTON_CLEAR_ALL_FILTER_ALT) . ''; break; } } $content .= '
'; /* * end filter buttons */ $content .= ''; if ($savName != "") { $content .= '
';} if(count($filteredProducts) < 1) { $content .= '';} ?>