1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* osCommerce Online Merchant |
4
|
|
|
* |
5
|
|
|
* @copyright (c) 2016 osCommerce; https://www.oscommerce.com |
6
|
|
|
* @license MIT; https://www.oscommerce.com/license/mit.txt |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use OSC\OM\OSCOM; |
10
|
|
|
|
11
|
|
|
require('includes/application_top.php'); |
12
|
|
|
|
13
|
|
|
$OSCOM_Language->loadDefinitions('specials'); |
14
|
|
|
|
15
|
|
|
$breadcrumb->add(OSCOM::getDef('navbar_title'), OSCOM::link('specials.php')); |
16
|
|
|
|
17
|
|
|
require($oscTemplate->getFile('template_top.php')); |
18
|
|
|
?> |
19
|
|
|
|
20
|
|
|
<div class="page-header"> |
21
|
|
|
<h1><?php echo OSCOM::getDef('heading_title'); ?></h1> |
22
|
|
|
</div> |
23
|
|
|
|
24
|
|
|
<?php |
25
|
|
|
// create column list |
26
|
|
|
$define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, |
27
|
|
|
'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, |
28
|
|
|
'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, |
29
|
|
|
'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, |
30
|
|
|
'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, |
31
|
|
|
'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, |
32
|
|
|
'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, |
33
|
|
|
'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW); |
34
|
|
|
|
35
|
|
|
asort($define_list); |
36
|
|
|
|
37
|
|
|
$column_list = array(); |
38
|
|
|
reset($define_list); |
39
|
|
|
while (list($key, $value) = each($define_list)) { |
40
|
|
|
if ($value > 0) $column_list[] = $key; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$select_column_list = ''; |
44
|
|
|
|
45
|
|
View Code Duplication |
for ($i=0, $n=sizeof($column_list); $i<$n; $i++) { |
|
|
|
|
46
|
|
|
switch ($column_list[$i]) { |
47
|
|
|
case 'PRODUCT_LIST_MODEL': |
48
|
|
|
$select_column_list .= 'p.products_model, '; |
49
|
|
|
break; |
50
|
|
|
case 'PRODUCT_LIST_NAME': |
51
|
|
|
$select_column_list .= 'pd.products_name, '; |
52
|
|
|
break; |
53
|
|
|
case 'PRODUCT_LIST_MANUFACTURER': |
54
|
|
|
$select_column_list .= 'm.manufacturers_name, '; |
55
|
|
|
break; |
56
|
|
|
case 'PRODUCT_LIST_QUANTITY': |
57
|
|
|
$select_column_list .= 'p.products_quantity, '; |
58
|
|
|
break; |
59
|
|
|
case 'PRODUCT_LIST_IMAGE': |
60
|
|
|
$select_column_list .= 'p.products_image, '; |
61
|
|
|
break; |
62
|
|
|
case 'PRODUCT_LIST_WEIGHT': |
63
|
|
|
$select_column_list .= 'p.products_weight, '; |
64
|
|
|
break; |
65
|
|
|
} |
66
|
|
|
} |
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
|
|
View Code Duplication |
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
|
|
|
|
109
|
|
|
$Qlisting = $OSCOM_Db->prepare($listing_sql); |
110
|
|
|
$Qlisting->bindInt(':language_id', $OSCOM_Language->getId()); |
111
|
|
|
$Qlisting->setPageSet(MAX_DISPLAY_SEARCH_RESULTS); |
112
|
|
|
$Qlisting->execute(); |
113
|
|
|
|
114
|
|
|
include('includes/content/product_listing.php'); |
115
|
|
|
|
116
|
|
|
require($oscTemplate->getFile('template_bottom.php')); |
117
|
|
|
require('includes/application_bottom.php'); |
118
|
|
|
?> |
119
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.