/
general.php
3847 lines (3298 loc) · 152 KB
/
general.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @copyright Copyright 2003-2021 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: DrByte 2021 Feb 19 Modified in v1.5.7c $
*/
////
// Redirect to another page or site
function zen_redirect($url) {
// clean up URL before executing it
$url = preg_replace('/&{2,}/', '&', $url);
$url = preg_replace('/(&)+/', '&', $url);
// header locates should not have the & in the address it breaks things
$url = str_replace('&', '&', $url);
session_write_close();
header('Location: ' . $url);
exit;
}
////
// Parse the data used in the html tags to ensure the tags will not break
function zen_parse_input_field_data($data, $parse) {
return strtr(trim($data), $parse);
}
function zen_customers_name($customers_id) {
global $db;
$customers_values = $db->Execute("SELECT customers_firstname, customers_lastname
FROM " . TABLE_CUSTOMERS . "
WHERE customers_id = " . (int)$customers_id);
if ($customers_values->EOF) return '';
return $customers_values->fields['customers_firstname'] . ' ' . $customers_values->fields['customers_lastname'];
}
/**
* Generate a cPath string from current category conditions
*/
function zen_get_path($current_category_id = '') {
global $cPath_array, $db;
if ($current_category_id === '' || empty($cPath_array)) {
return 'cPath=' . (!empty($cPath_array) ? implode('_', $cPath_array) : $current_category_id);
}
// make copy so we can manipulate it later
$cPath_categories = $cPath_array;
$last_category_query = "SELECT parent_id
FROM " . TABLE_CATEGORIES . "
WHERE categories_id = " . (int)$cPath_categories[count($cPath_categories)-1];
$last_category = $db->Execute($last_category_query);
$current_category_query = "SELECT parent_id
FROM " . TABLE_CATEGORIES . "
WHERE categories_id = " . (int)$current_category_id;
$current_category = $db->Execute($current_category_query);
// Eject last category from array if not found or same as current
if (!isset($last_category->fields['parent_id'], $current_category->fields['parent_id'])) {
array_pop($cPath_categories);
} elseif ($last_category->fields['parent_id'] == $current_category->fields['parent_id']) {
array_pop($cPath_categories);
}
$cPath_new = implode('_', $cPath_categories) . '_' . $current_category_id;
unset($cPath_categories);
return 'cPath=' . trim($cPath_new, '_');
}
function zen_get_all_get_params($exclude_array = array())
{
if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array('error', 'x', 'y', 'cmd'));
if (function_exists('zen_session_name')) {
$exclude_array[] = zen_session_name();
}
$get_url = '';
if (is_array($_GET) && (count($_GET) > 0)) {
foreach ($_GET as $key => $value) {
if (!in_array($key, $exclude_array)) {
if (!is_array($value)) {
if (strlen($value) > 0) {
$get_url .= rawurlencode(stripslashes($key)) . '=' . rawurlencode(stripslashes($value)) . '&';
}
}
}
}
}
$get_url = preg_replace('/&{2,}/', '&', $get_url);
$get_url = preg_replace('/(&)+/', '&', $get_url);
return $get_url;
}
/**
* Return all GET params as (usually hidden) POST params
* @param array $exclude_array
* @param boolean $hidden
* @return string
*/
function zen_post_all_get_params($exclude_array = array(), $hidden = true) {
if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array(zen_session_name(), 'error', 'x', 'y'));
$fields = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
foreach($_GET as $key => $value) {
if (!in_array($key, $exclude_array)) {
if (!is_array($value)) {
if (strlen($value) > 0) {
if ($hidden) {
$fields .= zen_draw_hidden_field($key, $value);
} else {
$fields .= zen_draw_input_field($key, $value, 'class="form-control"');
}
}
} else {
foreach(array_filter($value) as $arr){
if ($hidden) {
$fields .= zen_draw_hidden_field($key . '[]', $arr);
} else {
$fields .= zen_draw_input_field($key . '[]', $arr, 'class="form-control"');
}
}
}
}
}
}
return $fields;
}
function zen_date_long($raw_date) {
if (empty($raw_date) || $raw_date <= '0001-01-01 00:00:00') return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
$retVal = strftime(DATE_FORMAT_LONG, mktime($hour, $minute, $second, $month, $day, $year));
if (stristr(PHP_OS, 'win')) return utf8_encode($retVal);
return $retVal;
}
////
// Output a raw date string in the selected locale date format
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
// NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers
function zen_date_short($raw_date) {
if (empty($raw_date) || $raw_date <= '0001-01-01 00:00:00') return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
// error on 1969 only allows for leap year
if ($year != 1969 && @date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) {
return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
} else {
return preg_replace('/2037$/', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
}
}
function zen_datetime_short($raw_datetime) {
if (empty($raw_datetime) || $raw_datetime <= '0001-01-01 00:00:00') return false;
$year = (int)substr($raw_datetime, 0, 4);
$month = (int)substr($raw_datetime, 5, 2);
$day = (int)substr($raw_datetime, 8, 2);
$hour = (int)substr($raw_datetime, 11, 2);
$minute = (int)substr($raw_datetime, 14, 2);
$second = (int)substr($raw_datetime, 17, 2);
return strftime(DATE_TIME_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
}
function zen_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = array(), $include_itself = false, $category_has_products = false, $limit = false) {
global $db;
if ($limit) {
$limit_count = " limit 1";
} else {
$limit_count = '';
}
if (!is_array($category_tree_array)) $category_tree_array = array();
if ( (sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
if ($include_itself) {
$category = $db->Execute("SELECT cd.categories_name
FROM " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE cd.language_id = " . (int)$_SESSION['languages_id'] . "
AND cd.categories_id = " . (int)$parent_id);
$category_tree_array[] = array('id' => $parent_id, 'text' => $category->fields['categories_name']);
}
$categories = $db->Execute("SELECT c.categories_id, cd.categories_name, c.parent_id
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.categories_id = cd.categories_id
AND cd.language_id = " . (int)$_SESSION['languages_id'] . "
AND c.parent_id = " . (int)$parent_id . "
ORDER BY c.sort_order, cd.categories_name");
while (!$categories->EOF) {
if ($category_has_products == true and zen_products_in_category_count($categories->fields['categories_id'], '', false, true) >= 1) {
$mark = '*';
} else {
$mark = ' ';
}
if ($exclude != $categories->fields['categories_id']) {
$category_tree_array[] = array('id' => $categories->fields['categories_id'], 'text' => $spacing . $categories->fields['categories_name'] . $mark);
}
$category_tree_array = zen_get_category_tree($categories->fields['categories_id'], $spacing . ' ', $exclude, $category_tree_array, '', $category_has_products);
$categories->MoveNext();
}
return $category_tree_array;
}
////
// products with name, model and price pulldown
function zen_draw_products_pull_down($name, $parameters = '', $exclude = '', $show_id = false, $set_selected = false, $show_model = false, $show_current_category = false) {
global $currencies, $db, $current_category_id, $prev_next_order;
// $prev_next_order set by products_previous_next.php, if category navigation in use
$order_by = $db->prepare_input(!empty($prev_next_order) ? $prev_next_order : ' ORDER BY products_name');
if ($exclude == '') {
$exclude = array();
}
$select_string = '<select name="' . $name . '"';
if ($parameters) {
$select_string .= ' ' . $parameters;
}
$select_string .= '>';
if ($show_current_category) {
// only show $current_categories_id
$products = $db->Execute("SELECT p.products_id, pd.products_name, p.products_sort_order, p.products_price, p.products_model, ptc.categories_id
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc ON ptc.products_id = p.products_id, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id = pd.products_id
and pd.language_id = " . (int)$_SESSION['languages_id'] . "
and ptc.categories_id = " . (int)$current_category_id .
$order_by);
} else {
$products = $db->Execute("SELECT p.products_id, pd.products_name, p.products_sort_order, p.products_price, p.products_model
FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
WHERE p.products_id = pd.products_id
AND pd.language_id = " . (int)$_SESSION['languages_id'] .
$order_by);
}
while (!$products->EOF) {
if (!in_array($products->fields['products_id'], $exclude)) {
$display_price = zen_get_products_base_price($products->fields['products_id']);
$select_string .= '<option value="' . $products->fields['products_id'] . '"';
if ($set_selected == $products->fields['products_id']) $select_string .= ' SELECTED';
$select_string .= '>' . $products->fields['products_name'] . ' (' . $currencies->format($display_price) . ')' . ($show_model ? ' [' . $products->fields['products_model'] . '] ' : '') . ($show_id ? ' - ID# ' . $products->fields['products_id'] : '') . '</option>';
}
$products->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
function zen_options_name($options_id) {
global $db;
$options_id = str_replace('txt_','',$options_id);
$options_values = $db->Execute("SELECT products_options_name
FROM " . TABLE_PRODUCTS_OPTIONS . "
WHERE products_options_id = " . (int)$options_id . "
AND language_id = " . (int)$_SESSION['languages_id']);
if ($options_values->EOF) return '';
return $options_values->fields['products_options_name'];
}
function zen_values_name($values_id) {
global $db;
$values_values = $db->Execute("SELECT products_options_values_name
FROM " . TABLE_PRODUCTS_OPTIONS_VALUES . "
WHERE products_options_values_id = " . (int)$values_id . "
AND language_id = " . (int)$_SESSION['languages_id']);
if ($values_values->EOF) return '';
return $values_values->fields['products_options_values_name'];
}
function zen_info_image($image, $alt, $width = '', $height = '', $params = '') {
if (zen_not_null($image) && (file_exists(DIR_FS_CATALOG_IMAGES . $image)) ) {
$image = zen_image(DIR_WS_CATALOG_IMAGES . $image, $alt, $width, $height, $params);
} else {
$image = TEXT_IMAGE_NONEXISTENT;
}
return $image;
}
function zen_get_country_name($country_id) {
global $db;
$country = $db->Execute("SELECT countries_name
FROM " . TABLE_COUNTRIES . "
WHERE countries_id = " . (int)$country_id);
if ($country->RecordCount() < 1) {
return $country_id;
} else {
return $country->fields['countries_name'];
}
}
function zen_get_country_name_cfg() {
global $db;
$country = $db->Execute("SELECT countries_name
FROM " . TABLE_COUNTRIES . "
WHERE countries_id = " . (int)$country_id);
if ($country->RecordCount() < 1) {
return $country_id;
} else {
return $country->fields['countries_name'];
}
}
function zen_get_zone_name($country_id, $zone_id, $default_zone) {
global $db;
$zone = $db->Execute("SELECT zone_name
FROM " . TABLE_ZONES . "
WHERE zone_country_id = " . (int)$country_id . "
AND zone_id = " . (int)$zone_id);
if ($zone->RecordCount() > 0) {
return $zone->fields['zone_name'];
} else {
return $default_zone;
}
}
function zen_browser_detect($component) {
return stristr($_SERVER['HTTP_USER_AGENT'], $component);
}
function zen_tax_classes_pull_down($parameters, $selected = '') {
global $db;
$select_string = '<select ' . $parameters . '>';
$classes = $db->Execute("SELECT tax_class_id, tax_class_title
FROM " . TABLE_TAX_CLASS . "
ORDER BY tax_class_title");
while (!$classes->EOF) {
$select_string .= '<option value="' . $classes->fields['tax_class_id'] . '"';
if ($selected == $classes->fields['tax_class_id']) $select_string .= ' SELECTED';
$select_string .= '>' . $classes->fields['tax_class_title'] . '</option>';
$classes->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
function zen_geo_zones_pull_down($parameters, $selected = '') {
global $db;
$select_string = '<select ' . $parameters . '>';
$zones = $db->Execute("SELECT geo_zone_id, geo_zone_name
FROM " . TABLE_GEO_ZONES . "
ORDER BY geo_zone_name");
while (!$zones->EOF) {
$select_string .= '<option value="' . $zones->fields['geo_zone_id'] . '"';
if ($selected == $zones->fields['geo_zone_id']) $select_string .= ' SELECTED';
$select_string .= '>' . $zones->fields['geo_zone_name'] . '</option>';
$zones->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
function zen_get_geo_zone_name($geo_zone_id) {
global $db;
$zones = $db->Execute("SELECT geo_zone_name
FROM " . TABLE_GEO_ZONES . "
WHERE geo_zone_id = " . (int)$geo_zone_id);
if ($zones->RecordCount() < 1) {
$geo_zone_name = $geo_zone_id;
} else {
$geo_zone_name = $zones->fields['geo_zone_name'];
}
return $geo_zone_name;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//
// Function : zen_get_zone_code
//
// Arguments : country_id country code string
// zone_id state/province zone_id
// default_zone default string if zone==0
//
// Return : state_prov_code s tate/province code
//
// Description : Function to retrieve the state/province code (as in FL for Florida etc)
//
////////////////////////////////////////////////////////////////////////////////////////////////
function zen_get_zone_code($country_id, $zone_id, $default_zone) {
global $db;
$zone_query = "SELECT zone_code
FROM " . TABLE_ZONES . "
WHERE zone_country_id = " . (int)$country_id . "
AND zone_id = " . (int)$zone_id;
$zone = $db->Execute($zone_query);
if ($zone->RecordCount() > 0) {
return $zone->fields['zone_code'];
} else {
return $default_zone;
}
}
function zen_get_languages() {
global $db;
$languages = $db->Execute("SELECT languages_id, name, code, image, directory
FROM " . TABLE_LANGUAGES . " ORDER BY sort_order");
while (!$languages->EOF) {
$languages_array[] = array('id' => $languages->fields['languages_id'],
'name' => $languages->fields['name'],
'code' => $languages->fields['code'],
'image' => $languages->fields['image'],
'directory' => $languages->fields['directory']);
$languages->MoveNext();
}
return $languages_array;
}
function zen_get_category_name($category_id, $language_id) {
global $db;
$category = $db->Execute("SELECT categories_name
FROM " . TABLE_CATEGORIES_DESCRIPTION . "
WHERE categories_id = " . (int)$category_id . "
AND language_id = " . (int)$language_id);
if ($category->EOF) return '';
return $category->fields['categories_name'];
}
function zen_get_category_description($category_id, $language_id) {
global $db;
$category = $db->Execute("SELECT categories_description
FROM " . TABLE_CATEGORIES_DESCRIPTION . "
WHERE categories_id = " . (int)$category_id . "
AND language_id = " . (int)$language_id);
if ($category->EOF) return '';
return $category->fields['categories_description'];
}
function zen_get_orders_status_name($orders_status_id, $language_id = '') {
global $db;
if (!$language_id) $language_id = $_SESSION['languages_id'];
$orders_status = $db->Execute("SELECT orders_status_name
FROM " . TABLE_ORDERS_STATUS . "
WHERE orders_status_id = " . (int)$orders_status_id . "
AND language_id = " . (int)$language_id);
if ($orders_status->EOF) return '';
return $orders_status->fields['orders_status_name'];
}
function zen_get_orders_status() {
global $db;
$orders_status_array = array();
$orders_status = $db->Execute("SELECT orders_status_id, orders_status_name
FROM " . TABLE_ORDERS_STATUS . "
WHERE language_id = " . (int)$_SESSION['languages_id'] . "
ORDER BY orders_status_id");
while (!$orders_status->EOF) {
$orders_status_array[] = array('id' => $orders_status->fields['orders_status_id'],
'text' => $orders_status->fields['orders_status_name']);
$orders_status->MoveNext();
}
return $orders_status_array;
}
function zen_get_products_name($product_id, $language_id = 0) {
global $db;
if ($language_id == 0) $language_id = $_SESSION['languages_id'];
$product = $db->Execute("SELECT products_name
FROM " . TABLE_PRODUCTS_DESCRIPTION . "
WHERE products_id = " . (int)$product_id . "
AND language_id = " . (int)$language_id);
if ($product->EOF) return '';
return $product->fields['products_name'];
}
function zen_get_products_description($product_id, $language_id) {
global $db;
$product = $db->Execute("SELECT products_description
FROM " . TABLE_PRODUCTS_DESCRIPTION . "
WHERE products_id = " . (int)$product_id . "
AND language_id = " . (int)$language_id);
if ($product->EOF) return '';
return $product->fields['products_description'];
}
function zen_get_products_url($product_id, $language_id) {
global $db;
$product = $db->Execute("SELECT products_url
FROM " . TABLE_PRODUCTS_DESCRIPTION . "
WHERE products_id = " . (int)$product_id . "
AND language_id = " . (int)$language_id);
if ($product->EOF) return '';
return $product->fields['products_url'];
}
////
// Return the manufacturers URL in the needed language
// TABLES: manufacturers_info
function zen_get_manufacturer_url($manufacturer_id, $language_id) {
global $db;
$manufacturer = $db->Execute("SELECT manufacturers_url
FROM " . TABLE_MANUFACTURERS_INFO . "
WHERE manufacturers_id = " . (int)$manufacturer_id . "
AND languages_id = " . (int)$language_id);
if ($manufacturer->EOF) return '';
return $manufacturer->fields['manufacturers_url'];
}
////
// Count how many products exist in a category
// TABLES: products, products_to_categories, categories
function zen_products_in_category_count($categories_id, $include_deactivated = false, $include_child = true, $limit = false) {
global $db;
$products_count = 0;
if ($limit) {
$limit_count = ' limit 1';
} else {
$limit_count = '';
}
if ($include_deactivated) {
$products = $db->Execute("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)$categories_id . $limit_count);
} else {
$products = $db->Execute("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)$categories_id . $limit_count);
}
$products_count += $products->fields['total'];
if ($include_child) {
$childs = $db->Execute("SELECT categories_id FROM " . TABLE_CATEGORIES . "
WHERE parent_id = " . (int)$categories_id);
if ($childs->RecordCount() > 0 ) {
while (!$childs->EOF) {
$products_count += zen_products_in_category_count($childs->fields['categories_id'], $include_deactivated);
$childs->MoveNext();
}
}
}
return $products_count;
}
////
// Count how many subcategories exist in a category
// TABLES: categories
function zen_childs_in_category_count($categories_id) {
global $db;
$categories_count = 0;
$categories = $db->Execute("SELECT categories_id
FROM " . TABLE_CATEGORIES . "
WHERE parent_id = " . (int)$categories_id);
while (!$categories->EOF) {
$categories_count++;
$categories_count += zen_childs_in_category_count($categories->fields['categories_id']);
$categories->MoveNext();
}
return $categories_count;
}
////
// Returns an array with countries
// TABLES: countries
function zen_get_countries($default = '') {
global $db;
$countries_array = array();
if ($default) {
$countries_array[] = array('id' => '',
'text' => $default);
}
$countries = $db->Execute("SELECT countries_id, countries_name, status
FROM " . TABLE_COUNTRIES . "
ORDER BY countries_name");
while (!$countries->EOF) {
$countries_array[] = array('id' => $countries->fields['countries_id'],
'text' => $countries->fields['countries_name'],
'status' => $countries->fields['status'],
);
$countries->MoveNext();
}
return $countries_array;
}
////
// return an array with country zones
function zen_get_country_zones($country_id) {
global $db;
$zones_array = array();
$zones = $db->Execute("SELECT zone_id, zone_name
FROM " . TABLE_ZONES . "
WHERE zone_country_id = " . (int)$country_id . "
ORDER BY zone_name");
while (!$zones->EOF) {
$zones_array[] = array('id' => $zones->fields['zone_id'],
'text' => $zones->fields['zone_name']);
$zones->MoveNext();
}
return $zones_array;
}
function zen_prepare_country_zones_pull_down($country_id = '') {
// preset the width of the drop-down for Netscape
$pre = '';
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<45; $i++) $pre .= ' ';
}
$zones = zen_get_country_zones($country_id);
if (sizeof($zones) > 0) {
$zones_select = array(array('id' => '', 'text' => PLEASE_SELECT));
$zones = array_merge($zones_select, $zones);
} else {
$zones = array(array('id' => '', 'text' => TYPE_BELOW));
// create dummy options for Netscape to preset the height of the drop-down
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<9; $i++) {
$zones[] = array('id' => '', 'text' => $pre);
}
}
}
return $zones;
}
////
// Get list of address_format_id's
function zen_get_address_formats() {
global $db;
$address_format_values = $db->Execute("SELECT address_format_id
FROM " . TABLE_ADDRESS_FORMAT . "
ORDER BY address_format_id");
$address_format_array = array();
while (!$address_format_values->EOF) {
$address_format_array[] = array('id' => $address_format_values->fields['address_format_id'],
'text' => $address_format_values->fields['address_format_id']);
$address_format_values->MoveNext();
}
return $address_format_array;
}
////
function zen_cfg_select_coupon_id($coupon_id, $key = '') {
global $db;
$coupon_array = array();
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$coupons = $db->execute("SELECT cd.coupon_name, c.coupon_id FROM " . TABLE_COUPONS ." c, ". TABLE_COUPONS_DESCRIPTION . " cd WHERE cd.coupon_id = c.coupon_id AND cd.language_id = " . (int)$_SESSION['languages_id']);
$coupon_array[] = array('id' => '0',
'text' => 'None');
while (!$coupons->EOF) {
$coupon_array[] = array('id' => $coupons->fields['coupon_id'],
'text' => $coupons->fields['coupon_name']);
$coupons->MoveNext();
}
return zen_draw_pull_down_menu($name, $coupon_array, $coupon_id, 'class="form-control"');
}
////
// Alias function for Store configuration values in the Administration Tool
function zen_cfg_pull_down_country_list($country_id, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_pull_down_menu($name, zen_get_countries(), $country_id, 'class="form-control"');
}
////
function zen_cfg_pull_down_country_list_none($country_id, $key = '') {
$country_array = zen_get_countries('None');
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_pull_down_menu($name, $country_array, $country_id, 'class="form-control"');
}
////
function zen_cfg_pull_down_zone_list($zone_id, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_pull_down_menu($name, zen_get_country_zones(STORE_COUNTRY), $zone_id, 'class="form-control"');
}
////
function zen_cfg_pull_down_tax_classes($tax_class_id, $key = '') {
global $db;
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
$tax_class = $db->Execute("SELECT tax_class_id, tax_class_title
FROM " . TABLE_TAX_CLASS . "
ORDER BY tax_class_title");
while (!$tax_class->EOF) {
$tax_class_array[] = array('id' => $tax_class->fields['tax_class_id'],
'text' => $tax_class->fields['tax_class_title']);
$tax_class->MoveNext();
}
return zen_draw_pull_down_menu($name, $tax_class_array, $tax_class_id, 'class="form-control"');
}
////
// Function to read in text area in admin
function zen_cfg_textarea($text, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_textarea_field($name, false, 60, 5, htmlspecialchars($text, ENT_COMPAT, CHARSET, FALSE), 'class="form-control"');
}
////
// Function to read in text area in admin
function zen_cfg_textarea_small($text, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_textarea_field($name, false, 35, 1, htmlspecialchars($text, ENT_COMPAT, CHARSET, FALSE), 'class="noEditor form-control" autofocus');
}
function zen_cfg_get_zone_name($zone_id) {
global $db;
$zone = $db->Execute("SELECT zone_name
FROM " . TABLE_ZONES . "
WHERE zone_id = " . (int)$zone_id);
if ($zone->RecordCount() < 1) {
return $zone_id;
} else {
return $zone->fields['zone_name'];
}
}
function zen_cfg_pull_down_htmleditors($html_editor, $index = null) {
global $editors_list;
$name = $index ? 'configuration[' . $index . ']' : 'configuration_value';
$editors_pulldown = array();
foreach($editors_list as $key=>$value) {
$editors_pulldown[] = array('id' => $key, 'text' => $value['desc']);
}
return zen_draw_pull_down_menu($name, $editors_pulldown, $html_editor, 'class="form-control"');
}
function zen_cfg_pull_down_exchange_rate_sources($source, $key = '') {
$name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
$pulldown = array();
$pulldown[] = array('id' => TEXT_NONE, 'text' => TEXT_NONE);
$funcs = get_defined_functions();
$funcs = $funcs['user'];
sort($funcs);
foreach ($funcs as $func) {
if (preg_match('/quote_(.*)_currency/', $func, $regs)) {
$pulldown[] = array('id' => $regs[1], 'text' => $regs[1]);
}
}
return zen_draw_pull_down_menu($name, $pulldown, $source);
}
function zen_cfg_password_input($value, $key = '') {
if (function_exists('dbenc_is_encrypted_value_key') && dbenc_is_encrypted_value_key($key)) {
$value = dbenc_decrypt($value);
}
return zen_draw_password_field('configuration[' . $key . ']', $value, 'class="form-control"');
}
function zen_cfg_password_display($value) {
$length = strlen($value);
return str_repeat('*', ($length > 16 ? 16 : $length));
}
/**
* Sets the status of a product
* @global object $db
* @param int $products_id
* @param int $status
*/
function zen_set_product_status($products_id, $status)
{
global $db;
$db->Execute("UPDATE " . TABLE_PRODUCTS . "
SET products_status = " . (int)$status . ",
products_last_modified = now()
WHERE products_id = " . (int)$products_id);
return;
}
////
// Sets timeout for the current script.
function zen_set_time_limit($limit) {
@set_time_limit($limit);
}
////
// Alias function for Store configuration values in the Administration Tool
function zen_cfg_select_option($select_array, $key_value, $key = '') {
$string = '';
for ($i=0, $n=sizeof($select_array); $i<$n; $i++) {
$name = ((zen_not_null($key)) ? 'configuration[' . $key . ']' : 'configuration_value');
$string .= '<div class="radio"><label>' . zen_draw_radio_field($name, $select_array[$i], ($key_value == $select_array[$i] ? true : false), '', 'id="' . strtolower($select_array[$i] . '-' . $name) . '" class="inputSelect"') . $select_array[$i] . '</label></div>';
}
return $string;
}
function zen_cfg_select_drop_down($select_array, $key_value, $key = '') {
$string = '';
$name = ((zen_not_null($key)) ? 'configuration[' . $key . ']' : 'configuration_value');
return zen_draw_pull_down_menu($name, $select_array, (int)$key_value, 'class="form-control"');
}
////
// Alias function for module configuration keys
function zen_mod_select_option($select_array, $key_name, $key_value) {
$string = '';
foreach($select_array as $key => $value) {
if (is_int($key)) $key = $value;
$string .= '<div class="radio"><label>' . zen_draw_radio_field('configuration[' . $key_name . ']', $key, ($key_value == $key ? true : false)) . $value . '</label></div>';
}
return $string;
}
////
// Collect server information
function zen_get_system_information($privacy = false) {
global $db;
// determine database size stats
$indsize = 0;
$datsize = 0;
$result = $db->Execute("SHOW TABLE STATUS" . (DB_PREFIX == '' ? '' : " LIKE '" . str_replace('_', '\_', DB_PREFIX) . "%'"));
while (!$result->EOF) {
$datsize += $result->fields['Data_length'];
$indsize += $result->fields['Index_length'];
$result->MoveNext();
}
$strictmysql = false;
$mysql_mode = '';
$result = $db->Execute("SHOW VARIABLES LIKE 'sql\_mode'");
if (!$result->EOF) {
$mysql_mode = $result->fields['Value'];
if (strstr($result->fields['Value'], 'strict_')) $strictmysql = true;
}
$mysql_slow_query_log_status = '';
$result = $db->Execute("SHOW VARIABLES LIKE 'slow\_query\_log'");
if (!$result->EOF) {
$mysql_slow_query_log_status = $result->fields['Value'];
}
$mysql_slow_query_log_file = '';
$result = $db->Execute("SHOW VARIABLES LIKE 'slow\_query\_log\_file'");
if (!$result->EOF) {
$mysql_slow_query_log_file = $result->fields['Value'];
}
$result = $db->Execute("select now() as datetime");
$mysql_date = $result->fields['datetime'];
$errnum = 0;
$system = $host = $kernel = $output = '';
list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());
$uptime = (DISPLAY_SERVER_UPTIME == 'true') ? 'Unsupported' : 'Disabled/Unavailable';
// check to see if "exec()" is disabled in PHP -- if not, get additional info via command line
$exec_disabled = false;
$php_disabled_functions = @ini_get("disable_functions");
if ($php_disabled_functions != '') {
if (in_array('exec', preg_split('/,/', str_replace(' ', '', $php_disabled_functions)))) {
$exec_disabled = true;
}
}
if (!$exec_disabled) {
@exec('uname -a 2>&1', $output, $errnum);
if ($errnum == 0 && sizeof($output)) list($system, $host, $kernel) = preg_split('/[\s,]+/', $output[0], 5);
$output = '';
if (DISPLAY_SERVER_UPTIME == 'true') {
@exec('uptime 2>&1', $output, $errnum);
if ($errnum == 0) {
$uptime = $output[0];
}
}
}
$timezone = date_default_timezone_get();
$systemInfo = array('date' => zen_datetime_short(date('Y-m-d H:i:s')),
'timezone' => $timezone,
'system' => $system,
'kernel' => $kernel,
'host' => $host,
'ip' => gethostbyname($host),
'uptime' => $uptime,
'http_server' => $_SERVER['SERVER_SOFTWARE'],
'php' => PHP_VERSION,
'zend' => (function_exists('zend_version') ? zend_version() : ''),
'db_server' => DB_SERVER,
'db_ip' => gethostbyname(DB_SERVER),
'db_version' => 'MySQL ' . $db->get_server_info(),
'db_date' => zen_datetime_short($mysql_date),
'php_memlimit' => @ini_get('memory_limit'),
'php_file_uploads' => strtolower(@ini_get('file_uploads')),
'php_uploadmaxsize' => @ini_get('upload_max_filesize'),
'php_postmaxsize' => @ini_get('post_max_size'),