Code Duplication    Length = 36-36 lines in 3 locations

catalog/index.php 1 location

@@ 149-184 (lines=36) @@
146
      }
147
    }
148
149
    if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
150
      for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
151
        if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
152
          $_GET['sort'] = $i+1 . 'a';
153
          $search_query .= ' order by pd.products_name';
154
          break;
155
        }
156
      }
157
    } else {
158
      $sort_col = substr($_GET['sort'], 0 , 1);
159
      $sort_order = substr($_GET['sort'], 1);
160
161
      switch ($column_list[$sort_col-1]) {
162
        case 'PRODUCT_LIST_MODEL':
163
          $search_query .= ' order by p.products_model ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
164
          break;
165
        case 'PRODUCT_LIST_NAME':
166
          $search_query .= ' order by pd.products_name ' . ($sort_order == 'd' ? 'desc' : '');
167
          break;
168
        case 'PRODUCT_LIST_MANUFACTURER':
169
          $search_query .= ' order by m.manufacturers_name ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
170
          break;
171
        case 'PRODUCT_LIST_QUANTITY':
172
          $search_query .= ' order by p.products_quantity ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
173
          break;
174
        case 'PRODUCT_LIST_IMAGE':
175
          $search_query .= ' order by pd.products_name';
176
          break;
177
        case 'PRODUCT_LIST_WEIGHT':
178
          $search_query .= ' order by p.products_weight ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
179
          break;
180
        case 'PRODUCT_LIST_PRICE':
181
          $search_query .= ' order by final_price ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
182
          break;
183
      }
184
    }
185
186
    $search_query .= ' limit :page_set_offset, :page_set_max_results';
187

catalog/advanced_search_result.php 1 location

@@ 283-318 (lines=36) @@
280
    $search_query .= ' group by p.products_id, tr.tax_priority';
281
  }
282
283
  if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
284
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
285
      if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
286
        $_GET['sort'] = $i+1 . 'a';
287
        $search_query .= ' order by pd.products_name';
288
        break;
289
      }
290
    }
291
  } else {
292
    $sort_col = substr($_GET['sort'], 0 , 1);
293
    $sort_order = substr($_GET['sort'], 1);
294
295
    switch ($column_list[$sort_col-1]) {
296
      case 'PRODUCT_LIST_MODEL':
297
        $search_query .= ' order by p.products_model ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
298
        break;
299
      case 'PRODUCT_LIST_NAME':
300
        $search_query .= ' order by pd.products_name ' . ($sort_order == 'd' ? 'desc' : '');
301
        break;
302
      case 'PRODUCT_LIST_MANUFACTURER':
303
        $search_query .= ' order by m.manufacturers_name ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
304
        break;
305
      case 'PRODUCT_LIST_QUANTITY':
306
        $search_query .= ' order by p.products_quantity ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
307
        break;
308
      case 'PRODUCT_LIST_IMAGE':
309
        $search_query .= ' order by pd.products_name';
310
        break;
311
      case 'PRODUCT_LIST_WEIGHT':
312
        $search_query .= ' order by p.products_weight ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
313
        break;
314
      case 'PRODUCT_LIST_PRICE':
315
        $search_query .= ' order by final_price ' . ($sort_order == 'd' ? 'desc' : '') . ', pd.products_name';
316
        break;
317
    }
318
  }
319
320
  $search_query .= ' limit :page_set_offset, :page_set_max_results';
321

catalog/specials.php 1 location

@@ 70-105 (lines=36) @@
67
68
  $listing_sql = "select SQL_CALC_FOUND_ROWS " . $select_column_list . " p.products_id, SUBSTRING_INDEX(pd.products_description, ' ', 20) as products_description, p.manufacturers_id, 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 from :table_products_description pd, :table_products p left join :table_manufacturers m on p.manufacturers_id = m.manufacturers_id left join :table_specials s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = :language_id and s.status = '1'";
69
70
  if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
71
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
72
      if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
73
        $_GET['sort'] = $i+1 . 'a';
74
        $listing_sql .= " order by pd.products_name";
75
        break;
76
      }
77
    }
78
  } else {
79
    $sort_col = substr($_GET['sort'], 0 , 1);
80
    $sort_order = substr($_GET['sort'], 1);
81
82
    switch ($column_list[$sort_col-1]) {
83
      case 'PRODUCT_LIST_MODEL':
84
        $listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
85
        break;
86
      case 'PRODUCT_LIST_NAME':
87
        $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
88
        break;
89
      case 'PRODUCT_LIST_MANUFACTURER':
90
        $listing_sql .= " order by m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
91
        break;
92
      case 'PRODUCT_LIST_QUANTITY':
93
        $listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
94
        break;
95
      case 'PRODUCT_LIST_IMAGE':
96
        $listing_sql .= " order by pd.products_name";
97
        break;
98
      case 'PRODUCT_LIST_WEIGHT':
99
        $listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
100
        break;
101
      case 'PRODUCT_LIST_PRICE':
102
        $listing_sql .= " order by final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
103
        break;
104
    }
105
  }
106
107
  $listing_sql .= ' limit :page_set_offset, :page_set_max_results';
108