1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
$Id$ |
4
|
|
|
|
5
|
|
|
osCommerce, Open Source E-Commerce Solutions |
6
|
|
|
http://www.oscommerce.com |
7
|
|
|
|
8
|
|
|
Copyright (c) 2014 osCommerce |
9
|
|
|
|
10
|
|
|
Released under the GNU General Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
//// |
14
|
|
|
// Get the installed version number |
15
|
|
View Code Duplication |
function tep_get_version() { |
|
|
|
|
16
|
|
|
static $v; |
17
|
|
|
|
18
|
|
|
if (!isset($v)) { |
19
|
|
|
$v = trim(implode('', file(DIR_FS_CATALOG . 'includes/version.php'))); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return $v; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
//// |
26
|
|
|
// Stop from parsing any further PHP code |
27
|
|
|
// v2.3.3.1 now closes the session through a registered shutdown function |
28
|
|
|
function tep_exit() { |
29
|
|
|
exit(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
//// |
33
|
|
|
// Redirect to another page or site |
34
|
|
|
function tep_redirect($url) { |
|
|
|
|
35
|
|
View Code Duplication |
if ( (strstr($url, "\n") != false) || (strstr($url, "\r") != false) ) { |
|
|
|
|
36
|
|
|
tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page |
|
|
|
|
40
|
|
|
if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_HTTP_CATALOG)) == HTTP_SERVER . DIR_WS_HTTP_CATALOG) { // NONSSL url |
41
|
|
|
$url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_HTTP_CATALOG)); // Change it to SSL |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ( strpos($url, '&') !== false ) { |
46
|
|
|
$url = str_replace('&', '&', $url); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
header('Location: ' . $url); |
50
|
|
|
|
51
|
|
|
tep_exit(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
//// |
55
|
|
|
// Parse the data used in the html tags to ensure the tags will not break |
56
|
|
|
function tep_parse_input_field_data($data, $parse) { |
|
|
|
|
57
|
|
|
return strtr(trim($data), $parse); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
function tep_output_string($string, $translate = false, $protected = false) { |
|
|
|
|
61
|
|
|
if ($protected == true) { |
|
|
|
|
62
|
|
|
return htmlspecialchars($string); |
63
|
|
|
} else { |
64
|
|
|
if ($translate == false) { |
|
|
|
|
65
|
|
|
return tep_parse_input_field_data($string, array('"' => '"')); |
66
|
|
|
} else { |
67
|
|
|
return tep_parse_input_field_data($string, $translate); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function tep_output_string_protected($string) { |
|
|
|
|
73
|
|
|
return tep_output_string($string, false, true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function tep_sanitize_string($string) { |
|
|
|
|
77
|
|
|
$patterns = array ('/ +/','/[<>]/'); |
78
|
|
|
$replace = array (' ', '_'); |
79
|
|
|
return preg_replace($patterns, $replace, trim($string)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
//// |
83
|
|
|
// Return a random row from a database query |
84
|
|
|
function tep_random_select($query) { |
85
|
|
|
$random_product = ''; |
86
|
|
|
$random_query = tep_db_query($query); |
87
|
|
|
$num_rows = tep_db_num_rows($random_query); |
88
|
|
|
if ($num_rows > 0) { |
89
|
|
|
$random_row = tep_rand(0, ($num_rows - 1)); |
90
|
|
|
tep_db_data_seek($random_query, $random_row); |
91
|
|
|
$random_product = tep_db_fetch_array($random_query); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $random_product; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
//// |
98
|
|
|
// Return a product's name |
99
|
|
|
// TABLES: products |
100
|
|
View Code Duplication |
function tep_get_products_name($product_id, $language = '') { |
|
|
|
|
101
|
|
|
global $languages_id; |
102
|
|
|
|
103
|
|
|
if (empty($language)) $language = $languages_id; |
104
|
|
|
|
105
|
|
|
$product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'"); |
106
|
|
|
$product = tep_db_fetch_array($product_query); |
107
|
|
|
|
108
|
|
|
return $product['products_name']; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
//// |
112
|
|
|
// Return a product's special price (returns nothing if there is no offer) |
113
|
|
|
// TABLES: products |
114
|
|
|
function tep_get_products_special_price($product_id) { |
115
|
|
|
$product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status = 1"); |
116
|
|
|
$product = tep_db_fetch_array($product_query); |
117
|
|
|
|
118
|
|
|
return $product['specials_new_products_price']; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
//// |
122
|
|
|
// Return a product's stock |
123
|
|
|
// TABLES: products |
124
|
|
|
function tep_get_products_stock($products_id) { |
125
|
|
|
$products_id = tep_get_prid($products_id); |
126
|
|
|
$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); |
127
|
|
|
$stock_values = tep_db_fetch_array($stock_query); |
128
|
|
|
|
129
|
|
|
return $stock_values['products_quantity']; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
//// |
133
|
|
|
// Check if the required stock is available |
134
|
|
|
// If insufficent stock is available return an out of stock message |
135
|
|
|
function tep_check_stock($products_id, $products_quantity) { |
136
|
|
|
$stock_left = tep_get_products_stock($products_id) - $products_quantity; |
137
|
|
|
$out_of_stock = ''; |
138
|
|
|
|
139
|
|
|
if ($stock_left < 0) { |
140
|
|
|
$out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>'; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $out_of_stock; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
//// |
147
|
|
|
// Break a word in a string if it is longer than a specified length ($len) |
148
|
|
View Code Duplication |
function tep_break_string($string, $len, $break_char = '-') { |
|
|
|
|
149
|
|
|
$l = 0; |
150
|
|
|
$output = ''; |
151
|
|
|
for ($i=0, $n=strlen($string); $i<$n; $i++) { |
152
|
|
|
$char = substr($string, $i, 1); |
153
|
|
|
if ($char != ' ') { |
154
|
|
|
$l++; |
155
|
|
|
} else { |
156
|
|
|
$l = 0; |
157
|
|
|
} |
158
|
|
|
if ($l > $len) { |
159
|
|
|
$l = 1; |
160
|
|
|
$output .= $break_char; |
161
|
|
|
} |
162
|
|
|
$output .= $char; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $output; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
//// |
169
|
|
|
// Return all HTTP GET variables, except those passed as a parameter |
170
|
|
|
function tep_get_all_get_params($exclude_array = '') { |
|
|
|
|
171
|
|
|
global $HTTP_GET_VARS; |
172
|
|
|
|
173
|
|
|
if (!is_array($exclude_array)) $exclude_array = array(); |
174
|
|
|
|
175
|
|
|
$get_url = ''; |
176
|
|
|
if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) { |
177
|
|
|
foreach ($HTTP_GET_VARS as $key => $value) { |
178
|
|
|
if ( is_string($value) && (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) { |
179
|
|
|
$get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&'; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $get_url; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
//// |
188
|
|
|
// Returns an array with countries |
189
|
|
|
// TABLES: countries |
190
|
|
|
function tep_get_countries($countries_id = '', $with_iso_codes = false) { |
|
|
|
|
191
|
|
|
$countries_array = array(); |
192
|
|
|
if (tep_not_null($countries_id)) { |
193
|
|
|
if ($with_iso_codes == true) { |
|
|
|
|
194
|
|
|
$countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "' order by countries_name"); |
195
|
|
|
$countries_values = tep_db_fetch_array($countries); |
196
|
|
|
$countries_array = array('countries_name' => $countries_values['countries_name'], |
197
|
|
|
'countries_iso_code_2' => $countries_values['countries_iso_code_2'], |
198
|
|
|
'countries_iso_code_3' => $countries_values['countries_iso_code_3']); |
199
|
|
|
} else { |
200
|
|
|
$countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'"); |
201
|
|
|
$countries_values = tep_db_fetch_array($countries); |
202
|
|
|
$countries_array = array('countries_name' => $countries_values['countries_name']); |
203
|
|
|
} |
204
|
|
|
} else { |
205
|
|
|
$countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name"); |
206
|
|
View Code Duplication |
while ($countries_values = tep_db_fetch_array($countries)) { |
|
|
|
|
207
|
|
|
$countries_array[] = array('countries_id' => $countries_values['countries_id'], |
208
|
|
|
'countries_name' => $countries_values['countries_name']); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return $countries_array; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
//// |
216
|
|
|
// Alias function to tep_get_countries, which also returns the countries iso codes |
217
|
|
|
function tep_get_countries_with_iso_codes($countries_id) { |
218
|
|
|
return tep_get_countries($countries_id, true); |
|
|
|
|
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
//// |
222
|
|
|
// Generate a path to categories |
223
|
|
|
function tep_get_path($current_category_id = '') { |
|
|
|
|
224
|
|
|
global $cPath_array; |
225
|
|
|
|
226
|
|
View Code Duplication |
if (tep_not_null($current_category_id)) { |
|
|
|
|
227
|
|
|
$cp_size = sizeof($cPath_array); |
228
|
|
|
if ($cp_size == 0) { |
229
|
|
|
$cPath_new = $current_category_id; |
230
|
|
|
} else { |
231
|
|
|
$cPath_new = ''; |
232
|
|
|
$last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$cPath_array[($cp_size-1)] . "'"); |
233
|
|
|
$last_category = tep_db_fetch_array($last_category_query); |
234
|
|
|
|
235
|
|
|
$current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'"); |
236
|
|
|
$current_category = tep_db_fetch_array($current_category_query); |
237
|
|
|
|
238
|
|
|
if ($last_category['parent_id'] == $current_category['parent_id']) { |
239
|
|
|
for ($i=0; $i<($cp_size-1); $i++) { |
240
|
|
|
$cPath_new .= '_' . $cPath_array[$i]; |
241
|
|
|
} |
242
|
|
|
} else { |
243
|
|
|
for ($i=0; $i<$cp_size; $i++) { |
244
|
|
|
$cPath_new .= '_' . $cPath_array[$i]; |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
$cPath_new .= '_' . $current_category_id; |
248
|
|
|
|
249
|
|
|
if (substr($cPath_new, 0, 1) == '_') { |
250
|
|
|
$cPath_new = substr($cPath_new, 1); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
} else { |
254
|
|
|
$cPath_new = implode('_', $cPath_array); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
return 'cPath=' . $cPath_new; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
//// |
261
|
|
|
// Returns the clients browser |
262
|
|
|
function tep_browser_detect($component) { |
|
|
|
|
263
|
|
|
return stristr(getenv('HTTP_USER_AGENT'), $component); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
//// |
267
|
|
|
// Alias function to tep_get_countries() |
268
|
|
|
function tep_get_country_name($country_id) { |
|
|
|
|
269
|
|
|
$country_array = tep_get_countries($country_id); |
270
|
|
|
|
271
|
|
|
return $country_array['countries_name']; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
//// |
275
|
|
|
// Returns the zone (State/Province) name |
276
|
|
|
// TABLES: zones |
277
|
|
View Code Duplication |
function tep_get_zone_name($country_id, $zone_id, $default_zone) { |
|
|
|
|
278
|
|
|
$zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"); |
279
|
|
|
if (tep_db_num_rows($zone_query)) { |
280
|
|
|
$zone = tep_db_fetch_array($zone_query); |
281
|
|
|
return $zone['zone_name']; |
282
|
|
|
} else { |
283
|
|
|
return $default_zone; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
//// |
288
|
|
|
// Returns the zone (State/Province) code |
289
|
|
|
// TABLES: zones |
290
|
|
View Code Duplication |
function tep_get_zone_code($country_id, $zone_id, $default_zone) { |
|
|
|
|
291
|
|
|
$zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"); |
292
|
|
|
if (tep_db_num_rows($zone_query)) { |
293
|
|
|
$zone = tep_db_fetch_array($zone_query); |
294
|
|
|
return $zone['zone_code']; |
295
|
|
|
} else { |
296
|
|
|
return $default_zone; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
//// |
301
|
|
|
// Wrapper function for round() |
302
|
|
|
function tep_round($number, $precision) { |
|
|
|
|
303
|
|
|
if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) { |
304
|
|
|
$number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1); |
305
|
|
|
|
306
|
|
|
if (substr($number, -1) >= 5) { |
307
|
|
|
if ($precision > 1) { |
308
|
|
|
$number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1'); |
309
|
|
|
} elseif ($precision == 1) { |
310
|
|
|
$number = substr($number, 0, -1) + 0.1; |
311
|
|
|
} else { |
312
|
|
|
$number = substr($number, 0, -1) + 1; |
313
|
|
|
} |
314
|
|
|
} else { |
315
|
|
|
$number = substr($number, 0, -1); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
return $number; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
//// |
323
|
|
|
// Returns the tax rate for a zone / class |
324
|
|
|
// TABLES: tax_rates, zones_to_geo_zones |
325
|
|
|
function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) { |
|
|
|
|
326
|
|
|
global $customer_zone_id, $customer_country_id; |
327
|
|
|
static $tax_rates = array(); |
328
|
|
|
|
329
|
|
View Code Duplication |
if ( ($country_id == -1) && ($zone_id == -1) ) { |
|
|
|
|
330
|
|
|
if (!tep_session_is_registered('customer_id')) { |
331
|
|
|
$country_id = STORE_COUNTRY; |
332
|
|
|
$zone_id = STORE_ZONE; |
333
|
|
|
} else { |
334
|
|
|
$country_id = $customer_country_id; |
335
|
|
|
$zone_id = $customer_zone_id; |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
if (!isset($tax_rates[$class_id][$country_id][$zone_id]['rate'])) { |
340
|
|
|
$tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority"); |
341
|
|
|
if (tep_db_num_rows($tax_query)) { |
342
|
|
|
$tax_multiplier = 1.0; |
343
|
|
|
while ($tax = tep_db_fetch_array($tax_query)) { |
344
|
|
|
$tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
$tax_rates[$class_id][$country_id][$zone_id]['rate'] = ($tax_multiplier - 1.0) * 100; |
348
|
|
|
} else { |
349
|
|
|
$tax_rates[$class_id][$country_id][$zone_id]['rate'] = 0; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return $tax_rates[$class_id][$country_id][$zone_id]['rate']; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
//// |
357
|
|
|
// Return the tax description for a zone / class |
358
|
|
|
// TABLES: tax_rates; |
359
|
|
|
function tep_get_tax_description($class_id, $country_id, $zone_id) { |
360
|
|
|
static $tax_rates = array(); |
361
|
|
|
|
362
|
|
|
if (!isset($tax_rates[$class_id][$country_id][$zone_id]['description'])) { |
363
|
|
|
$tax_query = tep_db_query("select tax_description from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' order by tr.tax_priority"); |
364
|
|
|
if (tep_db_num_rows($tax_query)) { |
365
|
|
|
$tax_description = ''; |
366
|
|
|
while ($tax = tep_db_fetch_array($tax_query)) { |
367
|
|
|
$tax_description .= $tax['tax_description'] . ' + '; |
368
|
|
|
} |
369
|
|
|
$tax_description = substr($tax_description, 0, -3); |
370
|
|
|
|
371
|
|
|
$tax_rates[$class_id][$country_id][$zone_id]['description'] = $tax_description; |
372
|
|
|
} else { |
373
|
|
|
$tax_rates[$class_id][$country_id][$zone_id]['description'] = TEXT_UNKNOWN_TAX_RATE; |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
return $tax_rates[$class_id][$country_id][$zone_id]['description']; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
//// |
381
|
|
|
// Add tax to a products price |
382
|
|
|
function tep_add_tax($price, $tax) { |
|
|
|
|
383
|
|
View Code Duplication |
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) { |
|
|
|
|
384
|
|
|
return $price + tep_calculate_tax($price, $tax); |
385
|
|
|
} else { |
386
|
|
|
return $price; |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
// Calculates Tax rounding the result |
391
|
|
|
function tep_calculate_tax($price, $tax) { |
|
|
|
|
392
|
|
|
return $price * $tax / 100; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
//// |
396
|
|
|
// Return the number of products in a category |
397
|
|
|
// TABLES: products, products_to_categories, categories |
398
|
|
View Code Duplication |
function tep_count_products_in_category($category_id, $include_inactive = false) { |
|
|
|
|
399
|
|
|
$products_count = 0; |
400
|
|
|
if ($include_inactive == true) { |
|
|
|
|
401
|
|
|
$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'"); |
402
|
|
|
} else { |
403
|
|
|
$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'"); |
404
|
|
|
} |
405
|
|
|
$products = tep_db_fetch_array($products_query); |
406
|
|
|
$products_count += $products['total']; |
407
|
|
|
|
408
|
|
|
$child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'"); |
409
|
|
|
if (tep_db_num_rows($child_categories_query)) { |
410
|
|
|
while ($child_categories = tep_db_fetch_array($child_categories_query)) { |
411
|
|
|
$products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive); |
412
|
|
|
} |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
return $products_count; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
//// |
419
|
|
|
// Return true if the category has subcategories |
420
|
|
|
// TABLES: categories |
421
|
|
|
function tep_has_category_subcategories($category_id) { |
422
|
|
|
$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'"); |
423
|
|
|
$child_category = tep_db_fetch_array($child_category_query); |
424
|
|
|
|
425
|
|
|
if ($child_category['count'] > 0) { |
426
|
|
|
return true; |
427
|
|
|
} else { |
428
|
|
|
return false; |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
//// |
433
|
|
|
// Returns the address_format_id for the given country |
434
|
|
|
// TABLES: countries; |
435
|
|
View Code Duplication |
function tep_get_address_format_id($country_id) { |
|
|
|
|
436
|
|
|
$address_format_query = tep_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'"); |
437
|
|
|
if (tep_db_num_rows($address_format_query)) { |
438
|
|
|
$address_format = tep_db_fetch_array($address_format_query); |
439
|
|
|
return $address_format['format_id']; |
440
|
|
|
} else { |
441
|
|
|
return '1'; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
//// |
446
|
|
|
// Return a formatted address |
447
|
|
|
// TABLES: address_format |
448
|
|
|
function tep_address_format($address_format_id, $address, $html, $boln, $eoln) { |
|
|
|
|
449
|
|
|
$address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . (int)$address_format_id . "'"); |
450
|
|
|
$address_format = tep_db_fetch_array($address_format_query); |
451
|
|
|
|
452
|
|
|
$company = tep_output_string_protected($address['company']); |
453
|
|
View Code Duplication |
if (isset($address['firstname']) && tep_not_null($address['firstname'])) { |
|
|
|
|
454
|
|
|
$firstname = tep_output_string_protected($address['firstname']); |
|
|
|
|
455
|
|
|
$lastname = tep_output_string_protected($address['lastname']); |
|
|
|
|
456
|
|
|
} elseif (isset($address['name']) && tep_not_null($address['name'])) { |
457
|
|
|
$firstname = tep_output_string_protected($address['name']); |
|
|
|
|
458
|
|
|
$lastname = ''; |
|
|
|
|
459
|
|
|
} else { |
460
|
|
|
$firstname = ''; |
|
|
|
|
461
|
|
|
$lastname = ''; |
|
|
|
|
462
|
|
|
} |
463
|
|
|
$street = tep_output_string_protected($address['street_address']); |
464
|
|
|
$suburb = tep_output_string_protected($address['suburb']); |
465
|
|
|
$city = tep_output_string_protected($address['city']); |
|
|
|
|
466
|
|
|
$state = tep_output_string_protected($address['state']); |
467
|
|
View Code Duplication |
if (isset($address['country_id']) && tep_not_null($address['country_id'])) { |
|
|
|
|
468
|
|
|
$country = tep_get_country_name($address['country_id']); |
|
|
|
|
469
|
|
|
|
470
|
|
|
if (isset($address['zone_id']) && tep_not_null($address['zone_id'])) { |
471
|
|
|
$state = tep_get_zone_code($address['country_id'], $address['zone_id'], $state); |
472
|
|
|
} |
473
|
|
|
} elseif (isset($address['country']) && tep_not_null($address['country'])) { |
474
|
|
|
$country = tep_output_string_protected($address['country']['title']); |
|
|
|
|
475
|
|
|
} else { |
476
|
|
|
$country = ''; |
|
|
|
|
477
|
|
|
} |
478
|
|
|
$postcode = tep_output_string_protected($address['postcode']); |
479
|
|
|
$zip = $postcode; |
|
|
|
|
480
|
|
|
|
481
|
|
View Code Duplication |
if ($html) { |
|
|
|
|
482
|
|
|
// HTML Mode |
483
|
|
|
$HR = '<hr />'; |
|
|
|
|
484
|
|
|
$hr = '<hr />'; |
|
|
|
|
485
|
|
|
if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults |
486
|
|
|
$CR = '<br />'; |
|
|
|
|
487
|
|
|
$cr = '<br />'; |
488
|
|
|
$eoln = $cr; |
|
|
|
|
489
|
|
|
} else { // Use values supplied |
490
|
|
|
$CR = $eoln . $boln; |
491
|
|
|
$cr = $CR; |
492
|
|
|
} |
493
|
|
|
} else { |
494
|
|
|
// Text Mode |
495
|
|
|
$CR = $eoln; |
496
|
|
|
$cr = $CR; |
497
|
|
|
$HR = '----------------------------------------'; |
|
|
|
|
498
|
|
|
$hr = '----------------------------------------'; |
|
|
|
|
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$statecomma = ''; |
|
|
|
|
502
|
|
|
$streets = $street; |
|
|
|
|
503
|
|
|
if ($suburb != '') $streets = $street . $cr . $suburb; |
|
|
|
|
504
|
|
|
if ($state != '') $statecomma = $state . ', '; |
|
|
|
|
505
|
|
|
|
506
|
|
|
$fmt = $address_format['format']; |
507
|
|
|
eval("\$address = \"$fmt\";"); |
508
|
|
|
|
509
|
|
View Code Duplication |
if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) { |
|
|
|
|
510
|
|
|
$address = $company . $cr . $address; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
return $address; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
//// |
517
|
|
|
// Return a formatted address |
518
|
|
|
// TABLES: customers, address_book |
519
|
|
|
function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") { |
520
|
|
|
if (is_array($address_id) && !empty($address_id)) { |
521
|
|
|
return tep_address_format($address_id['address_format_id'], $address_id, $html, $boln, $eoln); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
$address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "' and address_book_id = '" . (int)$address_id . "'"); |
525
|
|
|
$address = tep_db_fetch_array($address_query); |
526
|
|
|
|
527
|
|
|
$format_id = tep_get_address_format_id($address['country_id']); |
528
|
|
|
|
529
|
|
|
return tep_address_format($format_id, $address, $html, $boln, $eoln); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
function tep_row_number_format($number) { |
533
|
|
|
if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number; |
534
|
|
|
|
535
|
|
|
return $number; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') { |
539
|
|
|
global $languages_id; |
540
|
|
|
|
541
|
|
|
if (!is_array($categories_array)) $categories_array = array(); |
542
|
|
|
|
543
|
|
|
$categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name"); |
544
|
|
View Code Duplication |
while ($categories = tep_db_fetch_array($categories_query)) { |
|
|
|
|
545
|
|
|
$categories_array[] = array('id' => $categories['categories_id'], |
546
|
|
|
'text' => $indent . $categories['categories_name']); |
547
|
|
|
|
548
|
|
|
if ($categories['categories_id'] != $parent_id) { |
549
|
|
|
$categories_array = tep_get_categories($categories_array, $categories['categories_id'], $indent . ' '); |
|
|
|
|
550
|
|
|
} |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
return $categories_array; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
View Code Duplication |
function tep_get_manufacturers($manufacturers_array = '') { |
|
|
|
|
557
|
|
|
if (!is_array($manufacturers_array)) $manufacturers_array = array(); |
558
|
|
|
|
559
|
|
|
$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"); |
560
|
|
|
while ($manufacturers = tep_db_fetch_array($manufacturers_query)) { |
561
|
|
|
$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
return $manufacturers_array; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
//// |
568
|
|
|
// Return all subcategory IDs |
569
|
|
|
// TABLES: categories |
570
|
|
View Code Duplication |
function tep_get_subcategories(&$subcategories_array, $parent_id = 0) { |
|
|
|
|
571
|
|
|
$subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$parent_id . "'"); |
572
|
|
|
while ($subcategories = tep_db_fetch_array($subcategories_query)) { |
573
|
|
|
$subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id']; |
574
|
|
|
if ($subcategories['categories_id'] != $parent_id) { |
575
|
|
|
tep_get_subcategories($subcategories_array, $subcategories['categories_id']); |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
// Output a raw date string in the selected locale date format |
581
|
|
|
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS |
582
|
|
View Code Duplication |
function tep_date_long($raw_date) { |
|
|
|
|
583
|
|
|
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false; |
584
|
|
|
|
585
|
|
|
$year = (int)substr($raw_date, 0, 4); |
586
|
|
|
$month = (int)substr($raw_date, 5, 2); |
587
|
|
|
$day = (int)substr($raw_date, 8, 2); |
588
|
|
|
$hour = (int)substr($raw_date, 11, 2); |
589
|
|
|
$minute = (int)substr($raw_date, 14, 2); |
590
|
|
|
$second = (int)substr($raw_date, 17, 2); |
591
|
|
|
|
592
|
|
|
return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year)); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
//// |
596
|
|
|
// Output a raw date string in the selected locale date format |
597
|
|
|
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS |
598
|
|
|
// NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers |
599
|
|
View Code Duplication |
function tep_date_short($raw_date) { |
|
|
|
|
600
|
|
|
if ( ($raw_date == '0000-00-00 00:00:00') || empty($raw_date) ) return false; |
601
|
|
|
|
602
|
|
|
$year = substr($raw_date, 0, 4); |
603
|
|
|
$month = (int)substr($raw_date, 5, 2); |
604
|
|
|
$day = (int)substr($raw_date, 8, 2); |
605
|
|
|
$hour = (int)substr($raw_date, 11, 2); |
606
|
|
|
$minute = (int)substr($raw_date, 14, 2); |
607
|
|
|
$second = (int)substr($raw_date, 17, 2); |
608
|
|
|
|
609
|
|
|
if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { |
610
|
|
|
return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year)); |
611
|
|
|
} else { |
612
|
|
|
return preg_replace('/2037$/', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
//// |
617
|
|
|
// Parse search string into indivual objects |
618
|
|
|
function tep_parse_search_string($search_str = '', &$objects) { |
619
|
|
|
$search_str = trim(strtolower($search_str)); |
620
|
|
|
|
621
|
|
|
// Break up $search_str on whitespace; quoted string will be reconstructed later |
622
|
|
|
$pieces = preg_split('/[[:space:]]+/', $search_str); |
623
|
|
|
$objects = array(); |
624
|
|
|
$tmpstring = ''; |
|
|
|
|
625
|
|
|
$flag = ''; |
|
|
|
|
626
|
|
|
|
627
|
|
|
for ($k=0; $k<count($pieces); $k++) { |
|
|
|
|
628
|
|
View Code Duplication |
while (substr($pieces[$k], 0, 1) == '(') { |
|
|
|
|
629
|
|
|
$objects[] = '('; |
630
|
|
|
if (strlen($pieces[$k]) > 1) { |
631
|
|
|
$pieces[$k] = substr($pieces[$k], 1); |
632
|
|
|
} else { |
633
|
|
|
$pieces[$k] = ''; |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
$post_objects = array(); |
638
|
|
|
|
639
|
|
View Code Duplication |
while (substr($pieces[$k], -1) == ')') { |
|
|
|
|
640
|
|
|
$post_objects[] = ')'; |
641
|
|
|
if (strlen($pieces[$k]) > 1) { |
642
|
|
|
$pieces[$k] = substr($pieces[$k], 0, -1); |
643
|
|
|
} else { |
644
|
|
|
$pieces[$k] = ''; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
// Check individual words |
649
|
|
|
|
650
|
|
|
if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) { |
651
|
|
|
$objects[] = trim($pieces[$k]); |
652
|
|
|
|
653
|
|
|
for ($j=0; $j<count($post_objects); $j++) { |
|
|
|
|
654
|
|
|
$objects[] = $post_objects[$j]; |
655
|
|
|
} |
656
|
|
|
} else { |
657
|
|
|
/* This means that the $piece is either the beginning or the end of a string. |
658
|
|
|
So, we'll slurp up the $pieces and stick them together until we get to the |
659
|
|
|
end of the string or run out of pieces. |
660
|
|
|
*/ |
661
|
|
|
|
662
|
|
|
// Add this word to the $tmpstring, starting the $tmpstring |
663
|
|
|
$tmpstring = trim(preg_replace('/"/', ' ', $pieces[$k])); |
664
|
|
|
|
665
|
|
|
// Check for one possible exception to the rule. That there is a single quoted word. |
666
|
|
View Code Duplication |
if (substr($pieces[$k], -1 ) == '"') { |
|
|
|
|
667
|
|
|
// Turn the flag off for future iterations |
668
|
|
|
$flag = 'off'; |
|
|
|
|
669
|
|
|
|
670
|
|
|
$objects[] = trim(preg_replace('/"/', ' ', $pieces[$k])); |
671
|
|
|
|
672
|
|
|
for ($j=0; $j<count($post_objects); $j++) { |
|
|
|
|
673
|
|
|
$objects[] = $post_objects[$j]; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
unset($tmpstring); |
677
|
|
|
|
678
|
|
|
// Stop looking for the end of the string and move onto the next word. |
679
|
|
|
continue; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
// Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string. |
683
|
|
|
$flag = 'on'; |
684
|
|
|
|
685
|
|
|
// Move on to the next word |
686
|
|
|
$k++; |
687
|
|
|
|
688
|
|
|
// Keep reading until the end of the string as long as the $flag is on |
689
|
|
|
|
690
|
|
|
while ( ($flag == 'on') && ($k < count($pieces)) ) { |
691
|
|
View Code Duplication |
while (substr($pieces[$k], -1) == ')') { |
|
|
|
|
692
|
|
|
$post_objects[] = ')'; |
693
|
|
|
if (strlen($pieces[$k]) > 1) { |
694
|
|
|
$pieces[$k] = substr($pieces[$k], 0, -1); |
695
|
|
|
} else { |
696
|
|
|
$pieces[$k] = ''; |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
// If the word doesn't end in double quotes, append it to the $tmpstring. |
701
|
|
|
if (substr($pieces[$k], -1) != '"') { |
702
|
|
|
// Tack this word onto the current string entity |
703
|
|
|
$tmpstring .= ' ' . $pieces[$k]; |
704
|
|
|
|
705
|
|
|
// Move on to the next word |
706
|
|
|
$k++; |
707
|
|
|
continue; |
708
|
|
View Code Duplication |
} else { |
|
|
|
|
709
|
|
|
/* If the $piece ends in double quotes, strip the double quotes, tack the |
710
|
|
|
$piece onto the tail of the string, push the $tmpstring onto the $haves, |
711
|
|
|
kill the $tmpstring, turn the $flag "off", and return. |
712
|
|
|
*/ |
713
|
|
|
$tmpstring .= ' ' . trim(preg_replace('/"/', ' ', $pieces[$k])); |
714
|
|
|
|
715
|
|
|
// Push the $tmpstring onto the array of stuff to search for |
716
|
|
|
$objects[] = trim($tmpstring); |
717
|
|
|
|
718
|
|
|
for ($j=0; $j<count($post_objects); $j++) { |
|
|
|
|
719
|
|
|
$objects[] = $post_objects[$j]; |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
unset($tmpstring); |
723
|
|
|
|
724
|
|
|
// Turn off the flag to exit the loop |
725
|
|
|
$flag = 'off'; |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
// add default logical operators if needed |
732
|
|
|
$temp = array(); |
733
|
|
|
for($i=0; $i<(count($objects)-1); $i++) { |
734
|
|
|
$temp[] = $objects[$i]; |
735
|
|
|
if ( ($objects[$i] != 'and') && |
736
|
|
|
($objects[$i] != 'or') && |
737
|
|
|
($objects[$i] != '(') && |
738
|
|
|
($objects[$i+1] != 'and') && |
739
|
|
|
($objects[$i+1] != 'or') && |
740
|
|
|
($objects[$i+1] != ')') ) { |
741
|
|
|
$temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR; |
742
|
|
|
} |
743
|
|
|
} |
744
|
|
|
$temp[] = $objects[$i]; |
745
|
|
|
$objects = $temp; |
746
|
|
|
|
747
|
|
|
$keyword_count = 0; |
748
|
|
|
$operator_count = 0; |
749
|
|
|
$balance = 0; |
750
|
|
|
for($i=0; $i<count($objects); $i++) { |
|
|
|
|
751
|
|
|
if ($objects[$i] == '(') $balance --; |
752
|
|
|
if ($objects[$i] == ')') $balance ++; |
753
|
|
|
if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) { |
754
|
|
|
$operator_count ++; |
755
|
|
|
} elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) { |
756
|
|
|
$keyword_count ++; |
757
|
|
|
} |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
if ( ($operator_count < $keyword_count) && ($balance == 0) ) { |
761
|
|
|
return true; |
762
|
|
|
} else { |
763
|
|
|
return false; |
764
|
|
|
} |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
//// |
768
|
|
|
// Check date |
769
|
|
|
function tep_checkdate($date_to_check, $format_string, &$date_array) { |
770
|
|
|
$separator_idx = -1; |
|
|
|
|
771
|
|
|
|
772
|
|
|
$separators = array('-', ' ', '/', '.'); |
773
|
|
|
$month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); |
774
|
|
|
$no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
775
|
|
|
|
776
|
|
|
$format_string = strtolower($format_string); |
777
|
|
|
|
778
|
|
|
if (strlen($date_to_check) != strlen($format_string)) { |
779
|
|
|
return false; |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
$size = sizeof($separators); |
783
|
|
View Code Duplication |
for ($i=0; $i<$size; $i++) { |
|
|
|
|
784
|
|
|
$pos_separator = strpos($date_to_check, $separators[$i]); |
785
|
|
|
if ($pos_separator != false) { |
|
|
|
|
786
|
|
|
$date_separator_idx = $i; |
787
|
|
|
break; |
788
|
|
|
} |
789
|
|
|
} |
790
|
|
|
|
791
|
|
View Code Duplication |
for ($i=0; $i<$size; $i++) { |
|
|
|
|
792
|
|
|
$pos_separator = strpos($format_string, $separators[$i]); |
793
|
|
|
if ($pos_separator != false) { |
|
|
|
|
794
|
|
|
$format_separator_idx = $i; |
795
|
|
|
break; |
796
|
|
|
} |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
if ($date_separator_idx != $format_separator_idx) { |
|
|
|
|
800
|
|
|
return false; |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
if ($date_separator_idx != -1) { |
804
|
|
|
$format_string_array = explode( $separators[$date_separator_idx], $format_string ); |
805
|
|
|
if (sizeof($format_string_array) != 3) { |
806
|
|
|
return false; |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
$date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check ); |
810
|
|
|
if (sizeof($date_to_check_array) != 3) { |
811
|
|
|
return false; |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
$size = sizeof($format_string_array); |
815
|
|
|
for ($i=0; $i<$size; $i++) { |
816
|
|
|
if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i]; |
817
|
|
|
if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i]; |
818
|
|
|
if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i]; |
819
|
|
|
} |
820
|
|
|
} else { |
821
|
|
|
if (strlen($format_string) == 8 || strlen($format_string) == 9) { |
822
|
|
|
$pos_month = strpos($format_string, 'mmm'); |
823
|
|
|
if ($pos_month != false) { |
|
|
|
|
824
|
|
|
$month = substr( $date_to_check, $pos_month, 3 ); |
825
|
|
|
$size = sizeof($month_abbr); |
826
|
|
|
for ($i=0; $i<$size; $i++) { |
827
|
|
|
if ($month == $month_abbr[$i]) { |
828
|
|
|
$month = $i; |
829
|
|
|
break; |
830
|
|
|
} |
831
|
|
|
} |
832
|
|
|
} else { |
833
|
|
|
$month = substr($date_to_check, strpos($format_string, 'mm'), 2); |
834
|
|
|
} |
835
|
|
|
} else { |
836
|
|
|
return false; |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
$day = substr($date_to_check, strpos($format_string, 'dd'), 2); |
840
|
|
|
$year = substr($date_to_check, strpos($format_string, 'yyyy'), 4); |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
if (strlen($year) != 4) { |
|
|
|
|
844
|
|
|
return false; |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) { |
848
|
|
|
return false; |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
if ($month > 12 || $month < 1) { |
852
|
|
|
return false; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
if ($day < 1) { |
856
|
|
|
return false; |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
if (tep_is_leap_year($year)) { |
860
|
|
|
$no_of_days[1] = 29; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
if ($day > $no_of_days[$month - 1]) { |
864
|
|
|
return false; |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
$date_array = array($year, $month, $day); |
868
|
|
|
|
869
|
|
|
return true; |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
//// |
873
|
|
|
// Check if year is a leap year |
874
|
|
|
function tep_is_leap_year($year) { |
875
|
|
|
if ($year % 100 == 0) { |
876
|
|
|
if ($year % 400 == 0) return true; |
877
|
|
|
} else { |
878
|
|
|
if (($year % 4) == 0) return true; |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
return false; |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
//// |
885
|
|
|
// Return table heading with sorting capabilities |
886
|
|
|
function tep_create_sort_heading($sortby, $colnum, $heading) { |
887
|
|
|
global $PHP_SELF; |
888
|
|
|
|
889
|
|
|
$sort_prefix = ''; |
890
|
|
|
$sort_suffix = ''; |
891
|
|
|
|
892
|
|
|
if ($sortby) { |
893
|
|
|
$sort_prefix = '<a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('page', 'info', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" title="' . tep_output_string(TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading) . '" class="productListing-heading">' ; |
|
|
|
|
894
|
|
|
$sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</a>'; |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
return $sort_prefix . $heading . $sort_suffix; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
//// |
901
|
|
|
// Recursively go through the categories and retreive all parent categories IDs |
902
|
|
|
// TABLES: categories |
903
|
|
View Code Duplication |
function tep_get_parent_categories(&$categories, $categories_id) { |
|
|
|
|
904
|
|
|
$parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$categories_id . "'"); |
905
|
|
|
while ($parent_categories = tep_db_fetch_array($parent_categories_query)) { |
906
|
|
|
if ($parent_categories['parent_id'] == 0) return true; |
907
|
|
|
$categories[sizeof($categories)] = $parent_categories['parent_id']; |
908
|
|
|
if ($parent_categories['parent_id'] != $categories_id) { |
909
|
|
|
tep_get_parent_categories($categories, $parent_categories['parent_id']); |
910
|
|
|
} |
911
|
|
|
} |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
//// |
915
|
|
|
// Construct a category path to the product |
916
|
|
|
// TABLES: products_to_categories |
917
|
|
|
function tep_get_product_path($products_id) { |
918
|
|
|
$cPath = ''; |
919
|
|
|
|
920
|
|
|
$category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_status = '1' and p.products_id = p2c.products_id limit 1"); |
921
|
|
|
if (tep_db_num_rows($category_query)) { |
922
|
|
|
$category = tep_db_fetch_array($category_query); |
923
|
|
|
|
924
|
|
|
$categories = array(); |
925
|
|
|
tep_get_parent_categories($categories, $category['categories_id']); |
926
|
|
|
|
927
|
|
|
$categories = array_reverse($categories); |
928
|
|
|
|
929
|
|
|
$cPath = implode('_', $categories); |
930
|
|
|
|
931
|
|
|
if (tep_not_null($cPath)) $cPath .= '_'; |
932
|
|
|
$cPath .= $category['categories_id']; |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
return $cPath; |
936
|
|
|
} |
937
|
|
|
|
938
|
|
|
//// |
939
|
|
|
// Return a product ID with attributes |
940
|
|
|
function tep_get_uprid($prid, $params) { |
|
|
|
|
941
|
|
|
if (is_numeric($prid)) { |
942
|
|
|
$uprid = (int)$prid; |
943
|
|
|
|
944
|
|
|
if (is_array($params) && (sizeof($params) > 0)) { |
945
|
|
|
$attributes_check = true; |
946
|
|
|
$attributes_ids = ''; |
947
|
|
|
|
948
|
|
|
foreach ($params as $option => $value) { |
949
|
|
|
if (is_numeric($option) && is_numeric($value)) { |
950
|
|
|
$attributes_ids .= '{' . (int)$option . '}' . (int)$value; |
951
|
|
|
} else { |
952
|
|
|
$attributes_check = false; |
953
|
|
|
break; |
954
|
|
|
} |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
if ($attributes_check == true) { |
|
|
|
|
958
|
|
|
$uprid .= $attributes_ids; |
959
|
|
|
} |
960
|
|
|
} |
961
|
|
|
} else { |
962
|
|
|
$uprid = tep_get_prid($prid); |
963
|
|
|
|
964
|
|
|
if (is_numeric($uprid)) { |
965
|
|
|
if (strpos($prid, '{') !== false) { |
966
|
|
|
$attributes_check = true; |
967
|
|
|
$attributes_ids = ''; |
968
|
|
|
|
969
|
|
|
// strpos()+1 to remove up to and including the first { which would create an empty array element in explode() |
970
|
|
|
$attributes = explode('{', substr($prid, strpos($prid, '{')+1)); |
971
|
|
|
|
972
|
|
|
for ($i=0, $n=sizeof($attributes); $i<$n; $i++) { |
973
|
|
|
$pair = explode('}', $attributes[$i]); |
974
|
|
|
|
975
|
|
|
if (is_numeric($pair[0]) && is_numeric($pair[1])) { |
976
|
|
|
$attributes_ids .= '{' . (int)$pair[0] . '}' . (int)$pair[1]; |
977
|
|
|
} else { |
978
|
|
|
$attributes_check = false; |
979
|
|
|
break; |
980
|
|
|
} |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
if ($attributes_check == true) { |
|
|
|
|
984
|
|
|
$uprid .= $attributes_ids; |
985
|
|
|
} |
986
|
|
|
} |
987
|
|
|
} else { |
988
|
|
|
return false; |
989
|
|
|
} |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
return $uprid; |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
//// |
996
|
|
|
// Return a product ID from a product ID with attributes |
997
|
|
|
function tep_get_prid($uprid) { |
|
|
|
|
998
|
|
|
$pieces = explode('{', $uprid); |
999
|
|
|
|
1000
|
|
|
if (is_numeric($pieces[0])) { |
1001
|
|
|
return (int)$pieces[0]; |
1002
|
|
|
} else { |
1003
|
|
|
return false; |
1004
|
|
|
} |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
//// |
1008
|
|
|
// Return a customer greeting |
1009
|
|
|
function tep_customer_greeting() { |
1010
|
|
|
global $customer_id, $customer_first_name; |
1011
|
|
|
|
1012
|
|
|
if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) { |
1013
|
|
|
$greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name), tep_href_link(FILENAME_PRODUCTS_NEW)); |
1014
|
|
|
} else { |
1015
|
|
|
$greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL')); |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
return $greeting_string; |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
//// |
1022
|
|
|
//! Send email (text/html) using MIME |
1023
|
|
|
// This is the central mail function. The SMTP Server should be configured |
1024
|
|
|
// correct in php.ini |
1025
|
|
|
// Parameters: |
1026
|
|
|
// $to_name The name of the recipient, e.g. "Jan Wildeboer" |
1027
|
|
|
// $to_email_address The eMail address of the recipient, |
1028
|
|
|
// e.g. [email protected] |
1029
|
|
|
// $email_subject The subject of the eMail |
1030
|
|
|
// $email_text The text of the eMail, may contain HTML entities |
1031
|
|
|
// $from_email_name The name of the sender, e.g. Shop Administration |
1032
|
|
|
// $from_email_adress The eMail address of the sender, |
1033
|
|
|
// e.g. [email protected] |
1034
|
|
|
|
1035
|
|
View Code Duplication |
function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) { |
|
|
|
|
1036
|
|
|
if (SEND_EMAILS != 'true') return false; |
1037
|
|
|
|
1038
|
|
|
// Instantiate a new mail object |
1039
|
|
|
$message = new email(array('X-Mailer: osCommerce')); |
|
|
|
|
1040
|
|
|
|
1041
|
|
|
// Build the text version |
1042
|
|
|
$text = strip_tags($email_text); |
1043
|
|
|
if (EMAIL_USE_HTML == 'true') { |
1044
|
|
|
$message->add_html($email_text, $text); |
1045
|
|
|
} else { |
1046
|
|
|
$message->add_text($text); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
// Send message |
1050
|
|
|
$message->build_message(); |
1051
|
|
|
$message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject); |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
//// |
1055
|
|
|
// Check if product has attributes |
1056
|
|
|
function tep_has_product_attributes($products_id) { |
1057
|
|
|
$attributes_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "'"); |
1058
|
|
|
$attributes = tep_db_fetch_array($attributes_query); |
1059
|
|
|
|
1060
|
|
|
if ($attributes['count'] > 0) { |
1061
|
|
|
return true; |
1062
|
|
|
} else { |
1063
|
|
|
return false; |
1064
|
|
|
} |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
//// |
1068
|
|
|
// Get the number of times a word/character is present in a string |
1069
|
|
|
function tep_word_count($string, $needle) { |
1070
|
|
|
$temp_array = preg_split('/' . $needle . '/', $string); |
1071
|
|
|
|
1072
|
|
|
return sizeof($temp_array); |
1073
|
|
|
} |
1074
|
|
|
|
1075
|
|
|
function tep_count_modules($modules = '') { |
1076
|
|
|
$count = 0; |
1077
|
|
|
|
1078
|
|
|
if (empty($modules)) return $count; |
1079
|
|
|
|
1080
|
|
|
$modules_array = explode(';', $modules); |
1081
|
|
|
|
1082
|
|
|
for ($i=0, $n=sizeof($modules_array); $i<$n; $i++) { |
1083
|
|
|
$class = substr($modules_array[$i], 0, strrpos($modules_array[$i], '.')); |
1084
|
|
|
|
1085
|
|
|
if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) { |
1086
|
|
|
if ($GLOBALS[$class]->enabled) { |
1087
|
|
|
$count++; |
1088
|
|
|
} |
1089
|
|
|
} |
1090
|
|
|
} |
1091
|
|
|
|
1092
|
|
|
return $count; |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
function tep_count_payment_modules() { |
1096
|
|
|
return tep_count_modules(MODULE_PAYMENT_INSTALLED); |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
function tep_count_shipping_modules() { |
1100
|
|
|
return tep_count_modules(MODULE_SHIPPING_INSTALLED); |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
function tep_create_random_value($length, $type = 'mixed') { |
1104
|
|
|
if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed'; |
1105
|
|
|
|
1106
|
|
|
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
1107
|
|
|
$digits = '0123456789'; |
1108
|
|
|
|
1109
|
|
|
$base = ''; |
1110
|
|
|
|
1111
|
|
|
if ( ($type == 'mixed') || ($type == 'chars') ) { |
1112
|
|
|
$base .= $chars; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
if ( ($type == 'mixed') || ($type == 'digits') ) { |
1116
|
|
|
$base .= $digits; |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
$value = ''; |
1120
|
|
|
|
1121
|
|
|
if (!class_exists('PasswordHash')) { |
1122
|
|
|
include(DIR_WS_CLASSES . 'passwordhash.php'); |
1123
|
|
|
} |
1124
|
|
|
|
1125
|
|
|
$hasher = new PasswordHash(10, true); |
1126
|
|
|
|
1127
|
|
|
do { |
1128
|
|
|
$random = base64_encode($hasher->get_random_bytes($length)); |
1129
|
|
|
|
1130
|
|
|
for ($i = 0, $n = strlen($random); $i < $n; $i++) { |
1131
|
|
|
$char = substr($random, $i, 1); |
1132
|
|
|
|
1133
|
|
|
if ( strpos($base, $char) !== false ) { |
1134
|
|
|
$value .= $char; |
1135
|
|
|
} |
1136
|
|
|
} |
1137
|
|
|
} while ( strlen($value) < $length ); |
1138
|
|
|
|
1139
|
|
|
if ( strlen($value) > $length ) { |
1140
|
|
|
$value = substr($value, 0, $length); |
1141
|
|
|
} |
1142
|
|
|
|
1143
|
|
|
return $value; |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') { |
1147
|
|
|
if (!is_array($exclude)) $exclude = array(); |
1148
|
|
|
|
1149
|
|
|
$get_string = ''; |
1150
|
|
|
if (sizeof($array) > 0) { |
1151
|
|
|
foreach ($array as $key => $value) { |
1152
|
|
|
if ( (!in_array($key, $exclude)) && ($key != 'x') && ($key != 'y') ) { |
1153
|
|
|
$get_string .= $key . $equals . $value . $separator; |
1154
|
|
|
} |
1155
|
|
|
} |
1156
|
|
|
$remove_chars = strlen($separator); |
1157
|
|
|
$get_string = substr($get_string, 0, -$remove_chars); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
return $get_string; |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
View Code Duplication |
function tep_not_null($value) { |
|
|
|
|
1164
|
|
|
if (is_array($value)) { |
1165
|
|
|
if (sizeof($value) > 0) { |
1166
|
|
|
return true; |
1167
|
|
|
} else { |
1168
|
|
|
return false; |
1169
|
|
|
} |
1170
|
|
|
} else { |
1171
|
|
|
if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) { |
1172
|
|
|
return true; |
1173
|
|
|
} else { |
1174
|
|
|
return false; |
1175
|
|
|
} |
1176
|
|
|
} |
1177
|
|
|
} |
1178
|
|
|
|
1179
|
|
|
//// |
1180
|
|
|
// Output the tax percentage with optional padded decimals |
1181
|
|
View Code Duplication |
function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) { |
|
|
|
|
1182
|
|
|
if (strpos($value, '.')) { |
1183
|
|
|
$loop = true; |
1184
|
|
|
while ($loop) { |
1185
|
|
|
if (substr($value, -1) == '0') { |
1186
|
|
|
$value = substr($value, 0, -1); |
1187
|
|
|
} else { |
1188
|
|
|
$loop = false; |
1189
|
|
|
if (substr($value, -1) == '.') { |
1190
|
|
|
$value = substr($value, 0, -1); |
1191
|
|
|
} |
1192
|
|
|
} |
1193
|
|
|
} |
1194
|
|
|
} |
1195
|
|
|
|
1196
|
|
|
if ($padding > 0) { |
1197
|
|
|
if ($decimal_pos = strpos($value, '.')) { |
1198
|
|
|
$decimals = strlen(substr($value, ($decimal_pos+1))); |
1199
|
|
|
for ($i=$decimals; $i<$padding; $i++) { |
1200
|
|
|
$value .= '0'; |
1201
|
|
|
} |
1202
|
|
|
} else { |
1203
|
|
|
$value .= '.'; |
1204
|
|
|
for ($i=0; $i<$padding; $i++) { |
1205
|
|
|
$value .= '0'; |
1206
|
|
|
} |
1207
|
|
|
} |
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
return $value; |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
//// |
1214
|
|
|
// Checks to see if the currency code exists as a currency |
1215
|
|
|
// TABLES: currencies |
1216
|
|
View Code Duplication |
function tep_currency_exists($code) { |
|
|
|
|
1217
|
|
|
$code = tep_db_prepare_input($code); |
1218
|
|
|
|
1219
|
|
|
$currency_query = tep_db_query("select code from " . TABLE_CURRENCIES . " where code = '" . tep_db_input($code) . "' limit 1"); |
1220
|
|
|
if (tep_db_num_rows($currency_query)) { |
1221
|
|
|
$currency = tep_db_fetch_array($currency_query); |
1222
|
|
|
return $currency['code']; |
1223
|
|
|
} else { |
1224
|
|
|
return false; |
1225
|
|
|
} |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
function tep_string_to_int($string) { |
|
|
|
|
1229
|
|
|
return (int)$string; |
1230
|
|
|
} |
1231
|
|
|
|
1232
|
|
|
//// |
1233
|
|
|
// Parse and secure the cPath parameter values |
1234
|
|
View Code Duplication |
function tep_parse_category_path($cPath) { |
|
|
|
|
1235
|
|
|
// make sure the category IDs are integers |
1236
|
|
|
$cPath_array = array_map('tep_string_to_int', explode('_', $cPath)); |
1237
|
|
|
|
1238
|
|
|
// make sure no duplicate category IDs exist which could lock the server in a loop |
1239
|
|
|
$tmp_array = array(); |
1240
|
|
|
$n = sizeof($cPath_array); |
1241
|
|
|
for ($i=0; $i<$n; $i++) { |
1242
|
|
|
if (!in_array($cPath_array[$i], $tmp_array)) { |
1243
|
|
|
$tmp_array[] = $cPath_array[$i]; |
1244
|
|
|
} |
1245
|
|
|
} |
1246
|
|
|
|
1247
|
|
|
return $tmp_array; |
1248
|
|
|
} |
1249
|
|
|
|
1250
|
|
|
//// |
1251
|
|
|
// Return a random value |
1252
|
|
View Code Duplication |
function tep_rand($min = null, $max = null) { |
|
|
|
|
1253
|
|
|
static $seeded; |
1254
|
|
|
|
1255
|
|
|
if (!isset($seeded)) { |
1256
|
|
|
$seeded = true; |
1257
|
|
|
|
1258
|
|
|
if ( (PHP_VERSION < '4.2.0') ) { |
1259
|
|
|
mt_srand((double)microtime()*1000000); |
1260
|
|
|
} |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
if (isset($min) && isset($max)) { |
1264
|
|
|
if ($min >= $max) { |
1265
|
|
|
return $min; |
1266
|
|
|
} else { |
1267
|
|
|
return mt_rand($min, $max); |
1268
|
|
|
} |
1269
|
|
|
} else { |
1270
|
|
|
return mt_rand(); |
1271
|
|
|
} |
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) { |
1275
|
|
|
setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure); |
1276
|
|
|
} |
1277
|
|
|
|
1278
|
|
View Code Duplication |
function tep_validate_ip_address($ip_address) { |
|
|
|
|
1279
|
|
|
if (function_exists('filter_var') && defined('FILTER_VALIDATE_IP')) { |
1280
|
|
|
return filter_var($ip_address, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4)); |
1281
|
|
|
} |
1282
|
|
|
|
1283
|
|
|
if (preg_match('/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip_address)) { |
1284
|
|
|
$parts = explode('.', $ip_address); |
1285
|
|
|
|
1286
|
|
|
foreach ($parts as $ip_parts) { |
1287
|
|
|
if ( (intval($ip_parts) > 255) || (intval($ip_parts) < 0) ) { |
1288
|
|
|
return false; // number is not within 0-255 |
1289
|
|
|
} |
1290
|
|
|
} |
1291
|
|
|
|
1292
|
|
|
return true; |
1293
|
|
|
} |
1294
|
|
|
|
1295
|
|
|
return false; |
1296
|
|
|
} |
1297
|
|
|
|
1298
|
|
View Code Duplication |
function tep_get_ip_address() { |
|
|
|
|
1299
|
|
|
global $HTTP_SERVER_VARS; |
1300
|
|
|
|
1301
|
|
|
$ip_address = null; |
1302
|
|
|
$ip_addresses = array(); |
1303
|
|
|
|
1304
|
|
|
if (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) && !empty($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) { |
1305
|
|
|
foreach ( array_reverse(explode(',', $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) as $x_ip ) { |
1306
|
|
|
$x_ip = trim($x_ip); |
1307
|
|
|
|
1308
|
|
|
if (tep_validate_ip_address($x_ip)) { |
1309
|
|
|
$ip_addresses[] = $x_ip; |
1310
|
|
|
} |
1311
|
|
|
} |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
if (isset($HTTP_SERVER_VARS['HTTP_CLIENT_IP']) && !empty($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])) { |
1315
|
|
|
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_CLIENT_IP']; |
1316
|
|
|
} |
1317
|
|
|
|
1318
|
|
|
if (isset($HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP']) && !empty($HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP'])) { |
1319
|
|
|
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP']; |
1320
|
|
|
} |
1321
|
|
|
|
1322
|
|
|
if (isset($HTTP_SERVER_VARS['HTTP_PROXY_USER']) && !empty($HTTP_SERVER_VARS['HTTP_PROXY_USER'])) { |
1323
|
|
|
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_PROXY_USER']; |
1324
|
|
|
} |
1325
|
|
|
|
1326
|
|
|
$ip_addresses[] = $HTTP_SERVER_VARS['REMOTE_ADDR']; |
1327
|
|
|
|
1328
|
|
|
foreach ( $ip_addresses as $ip ) { |
1329
|
|
|
if (!empty($ip) && tep_validate_ip_address($ip)) { |
1330
|
|
|
$ip_address = $ip; |
1331
|
|
|
break; |
1332
|
|
|
} |
1333
|
|
|
} |
1334
|
|
|
|
1335
|
|
|
return $ip_address; |
1336
|
|
|
} |
1337
|
|
|
|
1338
|
|
|
function tep_count_customer_orders($id = '', $check_session = true) { |
1339
|
|
|
global $customer_id, $languages_id; |
1340
|
|
|
|
1341
|
|
View Code Duplication |
if (is_numeric($id) == false) { |
|
|
|
|
1342
|
|
|
if (tep_session_is_registered('customer_id')) { |
1343
|
|
|
$id = $customer_id; |
1344
|
|
|
} else { |
1345
|
|
|
return 0; |
1346
|
|
|
} |
1347
|
|
|
} |
1348
|
|
|
|
1349
|
|
View Code Duplication |
if ($check_session == true) { |
|
|
|
|
1350
|
|
|
if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) { |
|
|
|
|
1351
|
|
|
return 0; |
1352
|
|
|
} |
1353
|
|
|
} |
1354
|
|
|
|
1355
|
|
|
$orders_check_query = tep_db_query("select count(*) as total from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$id . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.public_flag = '1'"); |
1356
|
|
|
$orders_check = tep_db_fetch_array($orders_check_query); |
1357
|
|
|
|
1358
|
|
|
return $orders_check['total']; |
1359
|
|
|
} |
1360
|
|
|
|
1361
|
|
|
function tep_count_customer_address_book_entries($id = '', $check_session = true) { |
1362
|
|
|
global $customer_id; |
1363
|
|
|
|
1364
|
|
View Code Duplication |
if (is_numeric($id) == false) { |
|
|
|
|
1365
|
|
|
if (tep_session_is_registered('customer_id')) { |
1366
|
|
|
$id = $customer_id; |
1367
|
|
|
} else { |
1368
|
|
|
return 0; |
1369
|
|
|
} |
1370
|
|
|
} |
1371
|
|
|
|
1372
|
|
View Code Duplication |
if ($check_session == true) { |
|
|
|
|
1373
|
|
|
if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) { |
|
|
|
|
1374
|
|
|
return 0; |
1375
|
|
|
} |
1376
|
|
|
} |
1377
|
|
|
|
1378
|
|
|
$addresses_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$id . "'"); |
1379
|
|
|
$addresses = tep_db_fetch_array($addresses_query); |
1380
|
|
|
|
1381
|
|
|
return $addresses['total']; |
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
// nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n) |
1385
|
|
View Code Duplication |
function tep_convert_linefeeds($from, $to, $string) { |
|
|
|
|
1386
|
|
|
if ((PHP_VERSION < "4.0.5") && is_array($from)) { |
1387
|
|
|
return preg_replace('/(' . implode('|', $from) . ')/', $to, $string); |
1388
|
|
|
} else { |
1389
|
|
|
return str_replace($from, $to, $string); |
1390
|
|
|
} |
1391
|
|
|
} |
1392
|
|
|
?> |
|
|
|
|
1393
|
|
|
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.