[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/templates/fallback/content/ -> advanced_search_result.tpl.php (source)

   1      <table border="0" width="100%" cellspacing="0" cellpadding="0">
   2        <tr>
   3          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
   4            <tr>
   5              <td class="pageHeading"><?php echo HEADING_TITLE_2; ?></td>
   6              <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_browse.gif', HEADING_TITLE_2, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
   7            </tr>
   8          </table></td>
   9        </tr>
  10        <tr>
  11          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  12        </tr>
  13        <tr>
  14          <td>
  15  <?php
  16  // create column list
  17    $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
  18                         'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
  19                         'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
  20                         'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
  21                         'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
  22                         'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
  23                         'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
  24                         'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
  25  
  26    asort($define_list);
  27  
  28    $column_list = array();
  29    reset($define_list);
  30    while (list($key, $value) = each($define_list)) {
  31      if ($value > 0) $column_list[] = $key;
  32    }
  33  
  34     // BOF Separate Pricing Per Customer
  35       if(!tep_session_is_registered('sppc_customer_group_id')) { 
  36       $customer_group_id = '0';
  37       } else {
  38        $customer_group_id = $sppc_customer_group_id;
  39       }
  40     // EOF Separate Pricing Per Customer
  41    $select_column_list = '';
  42  
  43    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
  44      switch ($column_list[$i]) {
  45        case 'PRODUCT_LIST_MODEL':
  46          $select_column_list .= 'p.products_model, ';
  47          break;
  48        case 'PRODUCT_LIST_MANUFACTURER':
  49          $select_column_list .= 'm.manufacturers_name, ';
  50          break;
  51        case 'PRODUCT_LIST_QUANTITY':
  52          $select_column_list .= 'p.products_quantity, ';
  53          break;
  54        case 'PRODUCT_LIST_IMAGE':
  55          $select_column_list .= 'p.products_image, ';
  56          break;
  57        case 'PRODUCT_LIST_WEIGHT':
  58          $select_column_list .= 'p.products_weight, ';
  59          break;
  60      }
  61    }
  62  
  63     // BOF Separate Pricing Per Customer
  64     $status_tmp_product_prices_table = false;
  65     $status_need_to_get_prices = false;
  66     // find out if sorting by price has been requested
  67     if ( (isset($HTTP_GET_VARS['sort'])) && (ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) && (substr($HTTP_GET_VARS['sort'], 0, 1) <= sizeof($column_list)) ){
  68      $_sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
  69      if ($column_list[$_sort_col-1] == 'PRODUCT_LIST_PRICE') {
  70        $status_need_to_get_prices = true;
  71        }
  72     }
  73     
  74     if ((tep_not_null($pfrom) || tep_not_null($pto) || $status_need_to_get_prices == true) && $customer_group_id != '0') { 
  75     $product_prices_table = TABLE_PRODUCTS_GROUP_PRICES.$customer_group_id;
  76     // the table with product prices for a particular customer group is re-built only a number of times per hour
  77     // (setting in /includes/database_tables.php called MAXIMUM_DELAY_UPDATE_PG_PRICES_TABLE, in minutes)
  78     // to trigger the update the next function is called (new function that should have been
  79     // added to includes/functions/database.php)
  80     tep_db_check_age_products_group_prices_cg_table($customer_group_id);
  81     $status_tmp_product_prices_table = true;   
  82     } elseif ((tep_not_null($pfrom) || tep_not_null($pto) || $status_need_to_get_prices == true) && $customer_group_id == '0') {
  83     // to be able to sort on retail prices we *need* to get the special prices instead of leaving them
  84     // NULL and do product_listing the job of getting the special price
  85     // first make sure that table exists and needs no updating
  86     tep_db_check_age_specials_retail_table();
  87     $status_tmp_special_prices_table = true;
  88     } // end elseif ((tep_not_null($pfrom) || (tep_not_null($pfrom)) && .... 
  89     
  90     if ($status_tmp_product_prices_table == true) {
  91     $select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, tmp_pp.products_price, p.products_tax_class_id, if(tmp_pp.status, tmp_pp.specials_new_products_price, NULL) as specials_new_products_price, IF(tmp_pp.status, tmp_pp.specials_new_products_price, tmp_pp.products_price) as final_price ";
  92     } elseif ($status_tmp_special_prices_table == true) {
  93       $select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, if(s.status, s.specials_new_products_price, p.products_price) as final_price ";    
  94     } else {
  95       $select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, NULL as specials_new_products_price, NULL as final_price ";    
  96     }
  97     // next line original select query
  98     // $select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price ";
  99  
 100    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 101      $select_str .= ", SUM(tr.tax_rate) as tax_rate ";
 102    }
 103  
 104  // LINES CHANGED: MS2 update 501112
 105  // Moved to below: " . TABLE_PRODUCTS_DESCRIPTION . " pd
 106  // and : TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
 107  // $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";
 108        if ($status_tmp_product_prices_table == true) {
 109    $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id) left join " . $product_prices_table . " as tmp_pp using(products_id)";
 110        } elseif ($status_tmp_special_prices_table == true) {
 111    $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id) left join " . TABLE_SPECIALS_RETAIL_PRICES . " s on p.products_id = s.products_id";
 112        } else {
 113    $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id)";
 114        }
 115    // EOF Separate Pricing Per Customer
 116    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 117      if (!tep_session_is_registered('customer_country_id')) {
 118        $customer_country_id = STORE_COUNTRY;
 119        $customer_zone_id = STORE_ZONE;
 120      }
 121      $from_str .= " left join " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on tr.tax_zone_id = gz.geo_zone_id and (gz.zone_country_id is null or gz.zone_country_id = '0' or gz.zone_country_id = '" . (int)$customer_country_id . "') and (gz.zone_id is null or gz.zone_id = '0' or gz.zone_id = '" . (int)$customer_zone_id . "')";
 122    }
 123  // LINE ADDED: MS2 update 501112
 124    $from_str .= ", " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";
 125  
 126    $where_str = " where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id ";
 127  
 128    if (isset($HTTP_GET_VARS['categories_id']) && tep_not_null($HTTP_GET_VARS['categories_id'])) {
 129      if (isset($HTTP_GET_VARS['inc_subcat']) && ($HTTP_GET_VARS['inc_subcat'] == '1')) {
 130        $subcategories_array = array();
 131        tep_get_subcategories($subcategories_array, $HTTP_GET_VARS['categories_id']);
 132  
 133        $where_str .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = '" . (int)$HTTP_GET_VARS['categories_id'] . "'";
 134  
 135        for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
 136          $where_str .= " or p2c.categories_id = '" . (int)$subcategories_array[$i] . "'";
 137        }
 138  
 139        $where_str .= ")";
 140      } else {
 141        $where_str .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['categories_id'] . "'";
 142      }
 143    }
 144  
 145    if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
 146      $where_str .= " and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
 147    }
 148  
 149    if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {
 150      $where_str .= " and (";
 151      for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {
 152        switch ($search_keywords[$i]) {
 153          case '(':
 154          case ')':
 155          case 'and':
 156          case 'or':
 157            $where_str .= " " . $search_keywords[$i] . " ";
 158            break;
 159          default:
 160            $keyword = tep_db_prepare_input($search_keywords[$i]);
 161            $where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
 162            if (isset($HTTP_GET_VARS['search_in_description']) && ($HTTP_GET_VARS['search_in_description'] == '1')) $where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";
 163            $where_str .= ')';
 164            break;
 165        }
 166      }
 167      $where_str .= " )";
 168    }
 169  
 170    if (tep_not_null($dfrom)) {
 171      $where_str .= " and p.products_date_added >= '" . tep_date_raw($dfrom) . "'";
 172    }
 173  
 174    if (tep_not_null($dto)) {
 175      $where_str .= " and p.products_date_added <= '" . tep_date_raw($dto) . "'";
 176    }
 177  
 178    if (tep_not_null($pfrom)) {
 179      if ($currencies->is_set($currency)) {
 180        $rate = $currencies->get_value($currency);
 181  
 182        $pfrom = $pfrom / $rate;
 183      }
 184    }
 185  
 186    if (tep_not_null($pto)) {
 187      if (isset($rate)) {
 188        $pto = $pto / $rate;
 189      }
 190    }
 191    // BOF Separate Pricing Per Customer
 192     if ($status_tmp_product_prices_table == true) {
 193    if (DISPLAY_PRICE_WITH_TAX == 'true') {
 194      if ($pfrom > 0) $where_str .= " and (IF(tmp_pp.status, tmp_pp.specials_new_products_price, tmp_pp.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) >= " . (double)$pfrom . ")";
 195      if ($pto > 0) $where_str .= " and (IF(tmp_pp.status, tmp_pp.specials_new_products_price, tmp_pp.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . (double)$pto . ")";
 196    } else {
 197      if ($pfrom > 0) $where_str .= " and (IF(tmp_pp.status, tmp_pp.specials_new_products_price, tmp_pp.products_price) >= " . (double)$pfrom . ")";
 198      if ($pto > 0) $where_str .= " and (IF(tmp_pp.status, tmp_pp.specials_new_products_price, tmp_pp.products_price) <= " . (double)$pto . ")";
 199    }
 200     } else { // $status_tmp_product_prices_table is not true: uses p.products_price instead of cg_products_price
 201         // because in the where clause for the case $status_tmp_special_prices is true, the table 
 202         // specials_retail_prices is abbreviated with "s" also we can use the same code for "true" and for "false"
 203           if (DISPLAY_PRICE_WITH_TAX == 'true') {
 204      if ($pfrom > 0) $where_str .= " and (IF(s.status AND s.customers_group_id = '" . $customer_group_id . "', s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) >= " . (double)$pfrom . ")";
 205      if ($pto > 0) $where_str .= " and (IF(s.status AND s.customers_group_id = '" . $customer_group_id . "', s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . (double)$pto . ")";
 206    } else {
 207      if ($pfrom > 0) $where_str .= " and (IF(s.status AND s.customers_group_id = '" . $customer_group_id . "', s.specials_new_products_price, p.products_price) >= " . (double)$pfrom . ")";
 208      if ($pto > 0) $where_str .= " and (IF(s.status AND s.customers_group_id = '" . $customer_group_id . "', s.specials_new_products_price, p.products_price) <= " . (double)$pto . ")";
 209     }
 210     } 
 211      // EOF Separate Pricing Per Customer
 212  
 213    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 214      $where_str .= " group by p.products_id, tr.tax_priority";
 215    }
 216  
 217    if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
 218      for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
 219        if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
 220          $HTTP_GET_VARS['sort'] = $i+1 . 'a';
 221          $order_str = ' order by pd.products_name';
 222          break;
 223        }
 224      }
 225    } else {
 226      $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
 227      $sort_order = substr($HTTP_GET_VARS['sort'], 1);
 228      $order_str = ' order by ';
 229      switch ($column_list[$sort_col-1]) {
 230        case 'PRODUCT_LIST_MODEL':
 231          $order_str .= "p.products_model " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 232          break;
 233        case 'PRODUCT_LIST_NAME':
 234          $order_str .= "pd.products_name " . ($sort_order == 'd' ? "desc" : "");
 235          break;
 236        case 'PRODUCT_LIST_MANUFACTURER':
 237          $order_str .= "m.manufacturers_name " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 238          break;
 239        case 'PRODUCT_LIST_QUANTITY':
 240          $order_str .= "p.products_quantity " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 241          break;
 242        case 'PRODUCT_LIST_IMAGE':
 243          $order_str .= "pd.products_name";
 244          break;
 245        case 'PRODUCT_LIST_WEIGHT':
 246          $order_str .= "p.products_weight " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 247          break;
 248        case 'PRODUCT_LIST_PRICE':
 249          $order_str .= "final_price " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 250          break;
 251      }
 252    }
 253  
 254    $listing_sql = $select_str . $from_str . $where_str . $order_str;
 255  
 256    require(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING);
 257  ?>
 258          </td>
 259        </tr>
 260        <tr>
 261          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
 262        </tr>
 263        <tr>
 264          <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_ADVANCED_SEARCH, tep_get_all_get_params(array('sort', 'page')), 'NONSSL', true, false) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
 265        </tr>
 266      </table>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7