[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/ -> advanced_search_result.php (source)

   1  <?php
   2  /*
   3    $Id: advanced_search_result.php,v 1.72 2003/06/23 06:50:11 project3000 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    require ('includes/application_top.php');
  14  
  15    require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADVANCED_SEARCH);
  16  
  17    $error = false;
  18  
  19    if ( (isset($HTTP_GET_VARS['keywords']) && empty($HTTP_GET_VARS['keywords'])) &&
  20         (isset($HTTP_GET_VARS['dfrom']) && (empty($HTTP_GET_VARS['dfrom']) || ($HTTP_GET_VARS['dfrom'] == DOB_FORMAT_STRING))) &&
  21         (isset($HTTP_GET_VARS['dto']) && (empty($HTTP_GET_VARS['dto']) || ($HTTP_GET_VARS['dto'] == DOB_FORMAT_STRING))) &&
  22         (isset($HTTP_GET_VARS['pfrom']) && !is_numeric($HTTP_GET_VARS['pfrom'])) &&
  23         (isset($HTTP_GET_VARS['pto']) && !is_numeric($HTTP_GET_VARS['pto'])) ) {
  24      $error = true;
  25  
  26      $messageStack->add_session('search', ERROR_AT_LEAST_ONE_INPUT);
  27    } else {
  28      $dfrom = '';
  29      $dto = '';
  30      $pfrom = '';
  31      $pto = '';
  32      $keywords = '';
  33  
  34      if (isset($HTTP_GET_VARS['dfrom'])) {
  35        $dfrom = (($HTTP_GET_VARS['dfrom'] == DOB_FORMAT_STRING) ? '' : $HTTP_GET_VARS['dfrom']);
  36      }
  37  
  38      if (isset($HTTP_GET_VARS['dto'])) {
  39        $dto = (($HTTP_GET_VARS['dto'] == DOB_FORMAT_STRING) ? '' : $HTTP_GET_VARS['dto']);
  40      }
  41  
  42      if (isset($HTTP_GET_VARS['pfrom'])) {
  43        $pfrom = $HTTP_GET_VARS['pfrom'];
  44      }
  45  
  46      if (isset($HTTP_GET_VARS['pto'])) {
  47        $pto = $HTTP_GET_VARS['pto'];
  48      }
  49  
  50      if (isset($HTTP_GET_VARS['keywords'])) {
  51        $keywords = $HTTP_GET_VARS['keywords'];
  52      }
  53  
  54      $date_check_error = false;
  55      if (tep_not_null($dfrom)) {
  56        if (!tep_checkdate($dfrom, DOB_FORMAT_STRING, $dfrom_array)) {
  57          $error = true;
  58          $date_check_error = true;
  59  
  60          $messageStack->add_session('search', ERROR_INVALID_FROM_DATE);
  61        }
  62      }
  63  
  64      if (tep_not_null($dto)) {
  65        if (!tep_checkdate($dto, DOB_FORMAT_STRING, $dto_array)) {
  66          $error = true;
  67          $date_check_error = true;
  68  
  69          $messageStack->add_session('search', ERROR_INVALID_TO_DATE);
  70        }
  71      }
  72  
  73      if (($date_check_error == false) && tep_not_null($dfrom) && tep_not_null($dto)) {
  74        if (mktime(0, 0, 0, $dfrom_array[1], $dfrom_array[2], $dfrom_array[0]) > mktime(0, 0, 0, $dto_array[1], $dto_array[2], $dto_array[0])) {
  75          $error = true;
  76  
  77          $messageStack->add_session('search', ERROR_TO_DATE_LESS_THAN_FROM_DATE);
  78        }
  79      }
  80  
  81      $price_check_error = false;
  82      if (tep_not_null($pfrom)) {
  83        if (!settype($pfrom, 'double')) {
  84          $error = true;
  85          $price_check_error = true;
  86  
  87          $messageStack->add_session('search', ERROR_PRICE_FROM_MUST_BE_NUM);
  88        }
  89      }
  90  
  91      if (tep_not_null($pto)) {
  92        if (!settype($pto, 'double')) {
  93          $error = true;
  94          $price_check_error = true;
  95  
  96          $messageStack->add_session('search', ERROR_PRICE_TO_MUST_BE_NUM);
  97        }
  98      }
  99  
 100      if (($price_check_error == false) && is_float($pfrom) && is_float($pto)) {
 101        if ($pfrom >= $pto) {
 102          $error = true;
 103  
 104          $messageStack->add_session('search', ERROR_PRICE_TO_LESS_THAN_PRICE_FROM);
 105        }
 106      }
 107  
 108      if (tep_not_null($keywords)) {
 109        if (!tep_parse_search_string($keywords, $search_keywords)) {
 110          $error = true;
 111  
 112          $messageStack->add_session('search', ERROR_INVALID_KEYWORDS);
 113        }
 114      }
 115    }
 116  
 117    if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
 118      $error = true;
 119  
 120      $messageStack->add_session('search', ERROR_AT_LEAST_ONE_INPUT);
 121    }
 122  
 123    if ($error == true) {
 124      tep_redirect(tep_href_link(FILENAME_ADVANCED_SEARCH, tep_get_all_get_params(), 'NONSSL', true, false));
 125    }
 126  
 127    $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ADVANCED_SEARCH));
 128    $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, tep_get_all_get_params(), 'NONSSL', true, false));
 129  ?>
 130  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 131  <html <?php echo HTML_PARAMS; ?>>
 132  <head>
 133  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 134  <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
 135  <title><?php echo TITLE; ?></title>
 136  <link rel="stylesheet" type="text/css" href="stylesheet.css">
 137  </head>
 138  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
 139  <!-- header //-->
 140  <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 141  <!-- header_eof //-->
 142  
 143  <!-- body //-->
 144  <table border="0" width="100%" cellspacing="3" cellpadding="3">
 145    <tr>
 146      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
 147  <!-- left_navigation //-->
 148  <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
 149  <!-- left_navigation_eof //-->
 150      </table></td>
 151  <!-- body_text //-->
 152      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 153        <tr>
 154          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 155            <tr>
 156              <td class="pageHeading"><?php echo HEADING_TITLE_2; ?></td>
 157              <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>
 158            </tr>
 159          </table></td>
 160        </tr>
 161        <tr>
 162          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
 163        </tr>
 164        <tr>
 165          <td>
 166  <?php
 167  // create column list
 168    $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
 169                         'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
 170                         'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
 171                         'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
 172                         'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
 173                         'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
 174                         'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
 175                         'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
 176  
 177    asort($define_list);
 178  
 179    $column_list = array();
 180    reset($define_list);
 181    while (list($key, $value) = each($define_list)) {
 182      if ($value > 0) $column_list[] = $key;
 183    }
 184  
 185    $select_column_list = '';
 186  
 187    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
 188      switch ($column_list[$i]) {
 189        case 'PRODUCT_LIST_MODEL':
 190          $select_column_list .= 'p.products_model, ';
 191          break;
 192        case 'PRODUCT_LIST_MANUFACTURER':
 193          $select_column_list .= 'm.manufacturers_name, ';
 194          break;
 195        case 'PRODUCT_LIST_QUANTITY':
 196          $select_column_list .= 'p.products_quantity, ';
 197          break;
 198        case 'PRODUCT_LIST_IMAGE':
 199          $select_column_list .= 'p.products_image, ';
 200          break;
 201        case 'PRODUCT_LIST_WEIGHT':
 202          $select_column_list .= 'p.products_weight, ';
 203          break;
 204      }
 205    }
 206  
 207    $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 ";
 208  
 209    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 210      $select_str .= ", SUM(tr.tax_rate) as tax_rate ";
 211    }
 212  
 213    $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id";
 214  
 215    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 216      if (!tep_session_is_registered('customer_country_id')) {
 217        $customer_country_id = STORE_COUNTRY;
 218        $customer_zone_id = STORE_ZONE;
 219      }
 220      $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 . "')";
 221    }
 222  
 223    $from_str .= ", " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";
 224  
 225    $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 ";
 226  
 227    if (isset($HTTP_GET_VARS['categories_id']) && tep_not_null($HTTP_GET_VARS['categories_id'])) {
 228      if (isset($HTTP_GET_VARS['inc_subcat']) && ($HTTP_GET_VARS['inc_subcat'] == '1')) {
 229        $subcategories_array = array();
 230        tep_get_subcategories($subcategories_array, $HTTP_GET_VARS['categories_id']);
 231  
 232        $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'] . "'";
 233  
 234        for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
 235          $where_str .= " or p2c.categories_id = '" . (int)$subcategories_array[$i] . "'";
 236        }
 237  
 238        $where_str .= ")";
 239      } else {
 240        $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'] . "'";
 241      }
 242    }
 243  
 244    if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
 245      $where_str .= " and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
 246    }
 247  
 248    if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {
 249      $where_str .= " and (";
 250      for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {
 251        switch ($search_keywords[$i]) {
 252          case '(':
 253          case ')':
 254          case 'and':
 255          case 'or':
 256            $where_str .= " " . $search_keywords[$i] . " ";
 257            break;
 258          default:
 259            $keyword = tep_db_prepare_input($search_keywords[$i]);
 260            $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) . "%'";
 261            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) . "%'";
 262            $where_str .= ')';
 263            break;
 264        }
 265      }
 266      $where_str .= " )";
 267    }
 268  
 269    if (tep_not_null($dfrom)) {
 270      $where_str .= " and p.products_date_added >= '" . tep_date_raw($dfrom) . "'";
 271    }
 272  
 273    if (tep_not_null($dto)) {
 274      $where_str .= " and p.products_date_added <= '" . tep_date_raw($dto) . "'";
 275    }
 276  
 277    if (tep_not_null($pfrom)) {
 278      if ($currencies->is_set($currency)) {
 279        $rate = $currencies->get_value($currency);
 280  
 281        $pfrom = $pfrom / $rate;
 282      }
 283    }
 284  
 285    if (tep_not_null($pto)) {
 286      if (isset($rate)) {
 287        $pto = $pto / $rate;
 288      }
 289    }
 290  
 291    if (DISPLAY_PRICE_WITH_TAX == 'true') {
 292      if ($pfrom > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) >= " . (double)$pfrom . ")";
 293      if ($pto > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . (double)$pto . ")";
 294    } else {
 295      if ($pfrom > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) >= " . (double)$pfrom . ")";
 296      if ($pto > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) <= " . (double)$pto . ")";
 297    }
 298  
 299    if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {
 300      $where_str .= " group by p.products_id, tr.tax_priority";
 301    }
 302  
 303    if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
 304      for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
 305        if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
 306          $HTTP_GET_VARS['sort'] = $i+1 . 'a';
 307          $order_str = ' order by pd.products_name';
 308          break;
 309        }
 310      }
 311    } else {
 312      $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
 313      $sort_order = substr($HTTP_GET_VARS['sort'], 1);
 314      $order_str = ' order by ';
 315      switch ($column_list[$sort_col-1]) {
 316        case 'PRODUCT_LIST_MODEL':
 317          $order_str .= "p.products_model " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 318          break;
 319        case 'PRODUCT_LIST_NAME':
 320          $order_str .= "pd.products_name " . ($sort_order == 'd' ? "desc" : "");
 321          break;
 322        case 'PRODUCT_LIST_MANUFACTURER':
 323          $order_str .= "m.manufacturers_name " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 324          break;
 325        case 'PRODUCT_LIST_QUANTITY':
 326          $order_str .= "p.products_quantity " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 327          break;
 328        case 'PRODUCT_LIST_IMAGE':
 329          $order_str .= "pd.products_name";
 330          break;
 331        case 'PRODUCT_LIST_WEIGHT':
 332          $order_str .= "p.products_weight " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 333          break;
 334        case 'PRODUCT_LIST_PRICE':
 335          $order_str .= "final_price " . ($sort_order == 'd' ? "desc" : "") . ", pd.products_name";
 336          break;
 337      }
 338    }
 339  
 340    $listing_sql = $select_str . $from_str . $where_str . $order_str;
 341  
 342    require(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING);
 343  ?>
 344          </td>
 345        </tr>
 346        <tr>
 347          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
 348        </tr>
 349        <tr>
 350          <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>
 351        </tr>
 352      </table></td>
 353  <!-- body_text_eof //-->
 354      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
 355  <!-- right_navigation //-->
 356  <?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
 357  <!-- right_navigation_eof //-->
 358      </table></td>
 359    </tr>
 360  </table>
 361  <!-- body_eof //-->
 362  
 363  <!-- footer //-->
 364  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 365  <!-- footer_eof //-->
 366  <br>
 367  </body>
 368  </html>
 369  <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics