-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.php
More file actions
1410 lines (1080 loc) · 66.8 KB
/
Copy pathupgrade.php
File metadata and controls
1410 lines (1080 loc) · 66.8 KB
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
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
include(WB_PATH.'/framework/class.secure.php');
} elseif (file_exists($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php')) {
include($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php');
} else {
$subs = explode('/', dirname($_SERVER['SCRIPT_NAME'])); $dir = $_SERVER['DOCUMENT_ROOT'];
$inc = false;
foreach ($subs as $sub) {
if (empty($sub)) continue; $dir .= '/'.$sub;
if (file_exists($dir.'/framework/class.secure.php')) {
include($dir.'/framework/class.secure.php'); $inc = true; break;
}
}
if (!$inc) trigger_error(sprintf("[ <strong>%s</strong> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
// end include class.secure.php
require_once(WB_PATH.'/framework/functions.php');
$database = new database();
// Setup styles to help id errors
echo'
<style type="text/css">
.good { color: green; }
.bad { color: red; }
.ok { color: blue; }
.warn { color: yellow; }
</style>
';
// get current module version from 'addons' table
if (!($query_addons = $database->query("SELECT `version` FROM `".TABLE_PREFIX."addons` WHERE `directory` = 'bakery'"))) {
exit("ERROR: ".mysql_error());
}
$bakery_settings = $query_addons->fetchRow();
// UPGRADE TO VERSION 0.7
// **********************
if ($bakery_settings['version'] < '0.7') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.7:</h3>';
// Get ITEMS table to see what needs to be created
$itemstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_items`");
$items = $itemstable->fetchRow();
// Adding new fields to the existing ITEMS table
echo'<h4>Adding new fields to the items table</h4>';
if (!array_key_exists('option_attributes', $items)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `option_attributes` TEXT NOT NULL AFTER `shipping`")) {
echo '<p class="good">Database field option_attributes added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field option_attributes exists, update not needed</p>'; }
if (!array_key_exists('option_name', $items)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `option_name` VARCHAR(255) NOT NULL DEFAULT '' AFTER `shipping`")) {
echo '<p class="good">Database field option_name added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field option_name exists, update not needed</p>'; }
// Get CUSTOMER table to see what needs to be created
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
$num_customers = $customertable->numRows();
if ($num_customers == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_customer (order_id) VALUES ('0')");
}
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
$customer = $customertable->fetchRow();
// Modifying fields or adding new fields to the existing CUSTOMER table
echo'<h4>Modifying fields and adding new fields to the customer table</h4>';
if (array_key_exists('cust_name', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` CHANGE `cust_name` `cust_first_name` VARCHAR(50)")) {
echo '<p class="good">Changed database field cust_name to cust_first_name successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field cust_last_name exists, update not needed</p>'; }
if (!array_key_exists('cust_last_name', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `cust_last_name` VARCHAR(50) AFTER `cust_first_name`")) {
echo '<p class="good">Database field cust_last_name added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field cust_last_name exists, update not needed</p>'; }
// Get ORDER table to see what needs to be created
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
$num_orders = $ordertable->numRows();
if ($num_orders == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_order (order_id) VALUES ('0')");
}
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
$order = $ordertable->fetchRow();
// Adding new field to the existing ORDER table
echo'<h4>Adding new field to the order table</h4>';
if (!array_key_exists('attribute', $order)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_order` ADD `attribute` VARCHAR(50) NOT NULL AFTER `item_id`")) {
echo '<p class="good">Database field attribute added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field attribute exists, update not needed</p>'; }
// Get SETTINGS table to see what needs to be created
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_settings`");
if ($settings = $settingstable->fetchRow()) {
// Adding new fields to the existing SETTINGS table
echo'<h4>Adding new fields to the settings table</h4>';
if (!array_key_exists('offline_text', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` ADD `offline_text` TINYTEXT NOT NULL AFTER `page_id`")) {
echo '<p class="good">Database field offline_text added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field offline_text exists, update not needed</p>'; }
if (!array_key_exists('page_offline', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` ADD `page_offline` ENUM('yes','no') NOT NULL DEFAULT 'no' AFTER `page_id`")) {
echo '<p class="good">Database field page_offline added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field page_offline exists, update not needed</p>'; }
if (array_key_exists('shop_url', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` CHANGE `shop_url` `proceed_url` VARCHAR(255) NOT NULL")) {
echo '<p class="good">Changed database field shop_url to proceed_url successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field proceed_url exists, update not needed</p>'; }
if (array_key_exists('paypal_return', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` DROP `paypal_return`")) {
echo '<p class="good">Database field paypal_return deleted successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field paypal_return does not exist, update not needed</p>'; }
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` CHANGE `shipping_method` `shipping_method` VARCHAR(20) NOT NULL")) {
echo '<p class="good">Database field shipping_method changed successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
if (!array_key_exists('free_shipping_msg', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` ADD `free_shipping_msg` ENUM('show','hide') NOT NULL DEFAULT 'hide' AFTER `shipping_method`")) {
echo '<p class="good">Database field free_shipping_msg added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field free_shipping_msg exists, update not needed</p>'; }
if (!array_key_exists('free_shipping', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_settings` ADD `free_shipping` DECIMAL(6,2) NOT NULL AFTER `shipping_method`")) {
echo '<p class="good">Database field free_shipping added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field free_shipping exists, update not needed</p>'; }
} else {
echo '<p class="warn">Database settings table does not exist, update not needed</p>';
}
echo"<br />";
// Separat settings table into a general settings table and page settings table
// Add new general settings table to the database
echo'<h4>Adding new general settings table to the database</h4>';
// Create new GENERAL SETTINGS table
$mod_bakery = 'CREATE TABLE `'.TABLE_PREFIX.'mod_bakery_general_settings` ( '
. '`shop_id` INT NOT NULL DEFAULT \'0\','
. '`shop_name` VARCHAR(100) NOT NULL ,'
. '`use_captcha` ENUM(\'yes\',\'no\') NOT NULL ,'
. '`tac_url` VARCHAR(255) NOT NULL ,'
. '`shop_email` VARCHAR(50) NOT NULL ,'
. '`shop_country` VARCHAR(2) NOT NULL ,'
. '`shop_currency` VARCHAR(3) NOT NULL ,'
. '`bank_account` TEXT NOT NULL ,'
. '`paypal_email` VARCHAR(50) NOT NULL ,'
. '`paypal_page` VARCHAR(255) NOT NULL ,'
. '`payment_method` VARCHAR(20) NOT NULL ,'
. '`tax_rate` DECIMAL(5,3) NOT NULL ,'
. '`tax_included` ENUM(\'included\',\'excluded\') NOT NULL ,'
. '`shipping_domestic` DECIMAL(6,2) NOT NULL ,'
. '`shipping_abroad` DECIMAL(6,2) NOT NULL ,'
. '`shipping_method` VARCHAR(20) NOT NULL ,'
. '`free_shipping` DECIMAL(6,2) NOT NULL ,'
. '`free_shipping_msg` ENUM(\'show\',\'hide\') NOT NULL ,'
. '`email_subject_advance` TEXT NOT NULL ,'
. '`email_pay_advance` TEXT NOT NULL ,'
. '`email_subject_paypal` TEXT NOT NULL ,'
. '`email_paypal` TEXT NOT NULL ,'
. 'PRIMARY KEY (shop_id)'
. ' )';
if ($database->query($mod_bakery)) {
echo '<p class="good">Created new general_settings table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Get "old" settings to insert them into the new general_settings table
if ($settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_settings` ORDER BY section_id DESC LIMIT 1")) {
$settings = $settingstable->fetchRow();
if ($settings['section_id'] == '') {
echo '<p class="warn">No old settings in database to insert into general_settings table</p>';
}
else {
echo '<p class="good">Got old settings from database section_id='.$settings['section_id'].' successfully</p>';
}
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Set default general_settings
$shop_id = 0;
$shop_name = $settings['shop_name'];
$use_captcha = $settings['use_captcha'];
$tac_url = $settings['tac_url'];
$shop_email = $settings['shop_email'];
$shop_country = $settings['shop_country'];
$shop_currency = $settings['shop_currency'];
$bank_account = $settings['bank_account'];
$paypal_email = $settings['paypal_email'];
$paypal_page = $settings['paypal_page'];
$payment_method = "all";
$tax_rate = $settings['tax_rate'];
$tax_included = $settings['tax_included'];
$shipping_domestic = $settings['shipping_domestic'];
$shipping_abroad = $settings['shipping_abroad'];
if ($settings['shipping_method'] == '') {$shipping_method = "flat"; } else {$shipping_method = $settings['shipping_method']; }
if ($settings['free_shipping'] == '') {$settings['free_shipping'] = 0; } else {$free_shipping = $settings['free_shipping']; }
if ($settings['free_shipping_msg'] == '') {$settings['free_shipping_msg'] = "all"; } else {$free_shipping_msg = $settings['free_shipping_msg']; }
$email_subject_advance = $settings['email_subject_advance'];
$email_pay_advance = $settings['email_pay_advance'];
$email_subject_paypal = $settings['email_subject_paypal'];
$email_paypal = $settings['email_paypal'];
// Insert values into general_settings table
if ($database->query("INSERT INTO ".TABLE_PREFIX."mod_bakery_general_settings (shop_id, shop_name, use_captcha, tac_url, shop_email, shop_country, shop_currency, bank_account, paypal_email, paypal_page, payment_method, tax_rate, tax_included, shipping_domestic, shipping_abroad, shipping_method, free_shipping, free_shipping_msg, email_subject_advance, email_pay_advance, email_subject_paypal, email_paypal)
VALUES ('$shop_id', '$shop_name', '$use_captcha', '$tac_url', '$shop_email', '$shop_country', '$shop_currency', '$bank_account', '$paypal_email', '$paypal_page', '$payment_method', '$tax_rate', '$tax_included', '$shipping_domestic', '$shipping_abroad', '$shipping_method', '$free_shipping', '$free_shipping_msg', '$email_subject_advance', '$email_pay_advance', '$email_subject_paypal', '$email_paypal')")) {
echo '<p class="good">Added default settings into general_settings table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Insert default settings
// Set default page_settings
if ($settings['page_offline'] == '') { $page_offline = "no"; } else {$page_offline = $settings['page_offline']; }
if ($settings['offline_text'] == '') {
if (LANGUAGE_LOADED) {
include(WB_PATH.'/modules/bakery/languages/EN.php');
if (file_exists(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php')) {
include(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php');
}
}
$offline_text = $MOD_BAKERY['ERR_OFFLINE_TEXT'];
}
else {
$offline_text = $settings['offline_text'];
}
// Adding default settings to the new fields
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_bakery_settings WHERE section_id != 0 and page_id != 0");
while ($result = $query_dates->fetchRow()) {
echo '<h4>Adding default settings to database for bakery section_id='.$result['section_id'].'</h4>';
$section_id = $result['section_id'];
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_settings` SET `page_offline` = '$page_offline' WHERE `section_id` = $section_id")) {
echo '<p class="good">Database data page_offline added successfully</p>';
}
echo '<p class="bad">'.mysql_error().'</p>';
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_settings` SET `offline_text` = '$offline_text' WHERE `section_id` = $section_id")) {
echo '<p class="good">Database data offline_text added successfully</p>';
}
echo '<p class="bad">'.mysql_error().'</p>';
}
echo"<br />";
// Rename settings table to page_settings table
echo'<h4>Renaming settings table to page_settings table</h4>';
if ($database->query("RENAME TABLE `".TABLE_PREFIX."mod_bakery_settings` TO `".TABLE_PREFIX."mod_bakery_page_settings`")) {
echo '<p class="good">Renamed settings table to page_settings table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Delete all fields which have been moved to general_settings table
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_page_settings` DROP `shop_name`, DROP `tac_url`, DROP `use_captcha`, DROP `shop_email`, DROP `shop_country`, DROP `shop_currency`, DROP `bank_account`, DROP `paypal_email`, DROP `paypal_page`, DROP `tax_rate`, DROP `tax_included`, DROP `shipping_domestic`, DROP `shipping_abroad`, DROP `shipping_method`, DROP `free_shipping`, DROP `free_shipping_msg`, DROP `email_subject_advance`, DROP `email_pay_advance`, DROP `email_subject_paypal`, DROP `email_paypal`")) {
echo '<p class="good">Deleted all fields of page_settings (which have been created newly in the general_settings table) successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
// UPGRADE TO VERSION 0.8
// **********************
if ($bakery_settings['version'] < '0.8') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.8:</h3>';
// Get ITEMS table to see what needs to be created
$itemstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_items`");
$items = $itemstable->fetchRow();
// Adding new fields to the existing ITEMS table
echo'<h4>Adding new field to the items table</h4>';
if (!array_key_exists('tax_rate', $items)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `tax_rate` DECIMAL(5,3) NOT NULL AFTER `shipping`")) {
echo '<p class="good">Database field tax_rate added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_rate exists, update not needed</p>'; }
// Get CUSTOMER table to see what needs to be created
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
$num_customers = $customertable->numRows();
if ($num_customers == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_customer (order_id) VALUES ('0')");
}
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
$customer = $customertable->fetchRow();
// Modifying fields or adding new fields to the existing CUSTOMER table
echo'<h4>Adding new fields to the customer table</h4>';
if (!array_key_exists('user_id', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `user_id` INT(6) NOT NULL AFTER `submitted`")) {
echo '<p class="good">Database field user_id added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field user_id exists, update not needed</p>'; }
if (!array_key_exists('cust_state', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `cust_state` VARCHAR(50) NOT NULL AFTER `cust_city`")) {
echo '<p class="good">Database field cust_state added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field cust_state exists, update not needed</p>'; }
// Get ORDER table to see what needs to be created
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
$num_orders = $ordertable->numRows();
if ($num_orders == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_order (order_id) VALUES ('0')");
}
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
$order = $ordertable->fetchRow();
// Adding new field to the existing ORDER table
echo'<h4>Adding new field to the order table</h4>';
if (!array_key_exists('tax_rate', $order)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_order` ADD `tax_rate` DECIMAL(5,3) NOT NULL AFTER `price`")) {
echo '<p class="good">Database field attribute added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_rate exists, update not needed</p>'; }
// Get GENERAL SETTINGS table to see what needs to be created
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
$settings = $settingstable->fetchRow();
// Adding new fields to the existing SETTINGS table
echo'<h4>Adding new fields to the general_settings table</h4>';
if (!array_key_exists('zip_location', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `zip_location` ENUM('inside','end') NOT NULL DEFAULT 'inside' AFTER `shop_country`")) {
echo '<p class="good">Database field zip_location added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field zip_location exists, update not needed</p>'; }
if (!array_key_exists('state_field', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `state_field` ENUM('show','hide') NOT NULL DEFAULT 'hide' AFTER `shop_country`")) {
echo '<p class="good">Database field state_field added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field state_field exists, update not needed</p>'; }
if (!array_key_exists('tax_rate2', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `tax_rate2` DECIMAL(5,3) NOT NULL AFTER `tax_rate`")) {
echo '<p class="good">Database field tax_rate2 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_rate2 exists, update not needed</p>'; }
if (!array_key_exists('tax_rate1', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `tax_rate1` DECIMAL(5,3) NOT NULL AFTER `tax_rate`")) {
echo '<p class="good">Database field tax_rate1 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_rate1 exists, update not needed</p>'; }
if (!array_key_exists('zone_countries', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `zone_countries` TEXT NOT NULL AFTER `shipping_abroad`")) {
echo '<p class="good">Database field zone_countries added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field zone_countries exists, update not needed</p>'; }
if (!array_key_exists('shipping_zone', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `shipping_zone` DECIMAL(6,2) NOT NULL AFTER `shipping_abroad`")) {
echo '<p class="good">Database field shipping_zone added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field shipping_zone exists, update not needed</p>'; }
echo"<br />";
// Insert default settings into items table
// Get "old" settings
if ($settingstable = $database->query("SELECT tax_rate FROM `".TABLE_PREFIX."mod_bakery_general_settings`")) {
$settings = $settingstable->fetchRow();
if ($settings['tax_rate'] == '') {
echo '<p class="warn">No old tax_rate setting in database to insert into items table</p>';
}
else {
echo '<p class="good">Got old tax_rate setting (<strong>'.$settings['tax_rate'].'%</strong>) from database to insert into items table</p>';
}
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Insert values into general_settings table
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_items` SET `tax_rate` = '$tax_rate'")) {
echo '<p class="good">Added default tax_rate setting into items table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
// UPGRADE TO VERSION 0.8.1
// ************************
if ($bakery_settings['version'] < '0.81') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.8.1:</h3>';
// Get SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_page_settings`");
if ($settings = $settingstable->fetchRow()) {
if (array_key_exists('proceed_url', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_page_settings` CHANGE `proceed_url` `continue_url` VARCHAR(255) NOT NULL")) {
echo '<p class="good">Changed database field proceed_url to continue_url successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field continue_url exists, update not needed</p>'; }
}
}
// UPGRADE TO VERSION 0.8.3
// ************************
if ($bakery_settings['version'] < '0.83') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.8.3:</h3>';
// Get SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
if ($settings = $settingstable->fetchRow()) {
if (!array_key_exists('tax_rate_shipping', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `tax_rate_shipping` DECIMAL(5,3) NOT NULL AFTER `tax_included`")) {
echo '<p class="good">Database field tax_rate_shipping added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_rate_shipping exists, update not needed</p>'; }
}
}
// UPGRADE TO VERSION 0.9
// ************************
if ($bakery_settings['version'] < '0.9') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.9:</h3>';
// Add new options table to the database
echo'<h4>Adding new options table to the database</h4>';
// Create new OPTIONS table
$mod_bakery = 'CREATE TABLE `'.TABLE_PREFIX.'mod_bakery_options` ( '
. ' `option_id` INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `option_name` VARCHAR(50) NOT NULL'
. ' )';
if ($database->query($mod_bakery)) {
echo '<p class="good">Created new options table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Add new attributes table to the database
echo'<h4>Adding new attributes table to the database</h4>';
// Create new ATTRIBUTES table
$mod_bakery = 'CREATE TABLE `'.TABLE_PREFIX.'mod_bakery_attributes` ( '
. ' `attribute_id` INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `option_id` INT(6) NOT NULL, '
. ' `attribute_name` VARCHAR(50) NOT NULL'
. ' )';
if ($database->query($mod_bakery)) {
echo '<p class="good">Created new attributes table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// Add new items attributes table to the database
echo'<h4>Adding new item attributes table to the database</h4>';
// Create new ITEMS ATTRIBUTES table
$mod_bakery = 'CREATE TABLE `'.TABLE_PREFIX.'mod_bakery_item_attributes` ( '
. ' `assign_id` INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `item_id` INT(6) NOT NULL, '
. ' `option_id` INT(6) NOT NULL, '
. ' `attribute_id` INT(6) NOT NULL, '
. ' `price` DECIMAL(9,2) NOT NULL, '
. ' `operator` VARCHAR(1) NOT NULL'
. ' )';
if ($database->query($mod_bakery)) {
echo '<p class="good">Created new item attributes table successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// There has to be at least one row in the ITEMS table - if not, insert blank row
$itemstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_items`");
$num_items = $itemstable->numRows();
if ($num_items == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_items (item_id) VALUES ('0')");
}
// Get ITEMS table to see what needs to be added
$itemstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_items`");
if ($item = $itemstable->fetchRow()) {
if (!array_key_exists('stock', $item)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `stock` VARCHAR(20) NOT NULL DEFAULT '' AFTER `sku`")) {
echo '<p class="good">Database field stock added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field stock exists, update not needed</p>'; }
}
// There has to be at least one row in the CUSTOMER table - if not, insert blank row
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
$num_customers = $customertable->numRows();
if ($num_customers == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_customer (order_id) VALUES ('0')");
}
// Get CUSTOMER table to see what needs to be changed
$customertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_customer`");
if ($customer = $customertable->fetchRow()) {
if (array_key_exists('submitted', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` CHANGE `submitted` `submitted` VARCHAR(3) NOT NULL")) {
echo '<p class="good">Changed database field submitted to type VARCHAR(3) successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
}
if (!array_key_exists('status', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `status` VARCHAR(20) NOT NULL DEFAULT 'none' AFTER `submitted`")) {
echo '<p class="good">Database field status added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field status exists, update not needed</p>'; }
if (!array_key_exists('invoice', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `invoice` TEXT NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field invoice added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field invoice exists, update not needed</p>'; }
if (!array_key_exists('ship_zip', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_zip` VARCHAR(10) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_zip added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_zip exists, update not needed</p>'; }
if (!array_key_exists('ship_country', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_country` VARCHAR(2) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_country added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_country exists, update not needed</p>'; }
if (!array_key_exists('ship_state', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_state` VARCHAR(50) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_state added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_state exists, update not needed</p>'; }
if (!array_key_exists('ship_city', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_city` VARCHAR(50) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_city added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_city exists, update not needed</p>'; }
if (!array_key_exists('ship_street', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_street` VARCHAR(50) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_street added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_street exists, update not needed</p>'; }
if (!array_key_exists('ship_last_name', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_last_name` VARCHAR(50) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_last_name added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_last_name exists, update not needed</p>'; }
if (!array_key_exists('ship_first_name', $customer)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_customer` ADD `ship_first_name` VARCHAR(50) NOT NULL AFTER `cust_phone`")) {
echo '<p class="good">Database field ship_first_name added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field ship_first_name exists, update not needed</p>'; }
}
// There has to be at least one row in the ORDER table - if not, insert blank row
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
$num_order = $ordertable->numRows();
if ($num_order == 0) {
$database->query("INSERT INTO " .TABLE_PREFIX."mod_bakery_order (order_id) VALUES ('0')");
}
// Get ORDER table to see what needs to be added
$ordertable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_order`");
if ($order = $ordertable->fetchRow()) {
if (array_key_exists('attribute', $order)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_order` CHANGE `attribute` `attributes` VARCHAR(50) NOT NULL")) {
echo '<p class="good">Changed database field attribute to attribute<strong>s</strong> successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_order` SET `attributes` = ''")) {
echo '<p class="good">Deleted outdated order attributes successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
}
// Get GENERAL SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
if ($settings = $settingstable->fetchRow()) {
if (!array_key_exists('shipping_form', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `shipping_form` VARCHAR(10) NOT NULL AFTER `shop_country`")) {
echo '<p class="good">Database field shipping_form added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field shipping_form exists, update not needed</p>'; }
if (!array_key_exists('invoice', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `invoice` TEXT NOT NULL AFTER `email_paypal`")) {
echo '<p class="good">Database field invoice added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field invoice exists, update not needed</p>'; }
if (!array_key_exists('email_invoice', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `email_invoice` TEXT NOT NULL AFTER `email_paypal`")) {
echo '<p class="good">Database field email_invoice added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field email_invoice exists, update not needed</p>'; }
if (!array_key_exists('email_subject_invoice', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `email_subject_invoice` TEXT NOT NULL AFTER `email_paypal`")) {
echo '<p class="good">Database field email_subject_invoice added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field email_subject_invoice exists, update not needed</p>'; }
}
// Insert default settings into general settings table
if (LANGUAGE_LOADED) {
include(WB_PATH.'/modules/bakery/languages/EN.php');
include(WB_PATH.'/modules/bakery/payment_methods/invoice/languages/EN.php');
if (file_exists(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php')) {
include(WB_PATH.'/modules/bakery/languages/'.LANGUAGE.'.php');
}
$payment_method = "invoice";
if (file_exists(WB_PATH.'/modules/bakery/payment_methods/invoice/languages/'.LANGUAGE.'.php')) {
include(WB_PATH.'/modules/bakery/payment_methods/invoice/languages/'.LANGUAGE.'.php');
}
}
$email_subject_invoice = $MOD_BAKERY[$payment_method]['EMAIL_SUBJECT_CUSTOMER'];
$email_invoice = $MOD_BAKERY[$payment_method]['EMAIL_BODY_CUSTOMER'];
$invoice = $admin->add_slashes($MOD_BAKERY[$payment_method]['INVOICE_TEMPLATE']);
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_general_settings` SET `email_subject_invoice` = '$email_subject_invoice', `email_invoice` = '$email_invoice', `invoice` = '$invoice'")) {
echo '<p class="good">Added default general settings successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
// General upgrade note
echo '
<div style="margin: 15px 0; padding: 10px 10px 10px 60px; text-align: left; color: red; border: solid 1px red; background-color: #FFDCD9; background-image: url('.WB_URL.'/modules/bakery/images/information.gif); background-position: 15px 15px; background-repeat: no-repeat;">
<p style="font-weight: bold;">IMPORTANT UPGRADE NOTE UPGRADING TO v0.9</p>
<ul style="padding-left: 20px;">
<li><strong>Stylesheet</strong>: If you keep your current Bakery stylesheets, make sure you are changing the class names from mod<strong>e</strong>_ to mod_ (mod without "<strong>e</strong>", eg. mod_bakery_anything_f).</li><br />
<li><strong>Item options</strong>: Due to a new system handling the item options you lost all your item options. Use your database backup to restore the options and attributes to their former condition.</li>
</ul>
</div>
';
}
// UPGRADE TO VERSION 0.9.6
// ************************
if ($bakery_settings['version'] < '0.96') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.9.6:</h3>';
// Get SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
if ($settings = $settingstable->fetchRow()) {
if (!array_key_exists('shop_state', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `shop_state` VARCHAR(2) NOT NULL AFTER `shop_country`")) {
echo '<p class="good">Database field shop_state added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field shop_state exists, update not needed</p>'; }
if (!array_key_exists('tax_by', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `tax_by` VARCHAR(10) NOT NULL AFTER `tax_included`")) {
echo '<p class="good">Database field tax_by added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field tax_by exists, update not needed</p>'; }
// Insert default settings into general settings table
if ($database->query("UPDATE `".TABLE_PREFIX."mod_bakery_general_settings` SET `tax_by` = 'country'")) {
echo '<p class="good">Added default general settings successfully</p>';
}
else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
}
// UPGRADE TO VERSION 0.9.7
// ************************
if ($bakery_settings['version'] < '0.97') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 0.9.7:</h3>';
// Get SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
if ($settings = $settingstable->fetchRow()) {
echo "<h4>Modifying table general_settings:</h4>";
if (!array_key_exists('definable_field_0', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `definable_field_0` VARCHAR(50) NOT NULL AFTER `use_captcha`")) {
echo '<p class="good">Database field definable_field_0 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_0 exists, update not needed</p>'; }
if (!array_key_exists('definable_field_1', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `definable_field_1` VARCHAR(50) NOT NULL AFTER `definable_field_0`")) {
echo '<p class="good">Database field definable_field_1 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_1 exists, update not needed</p>'; }
if (!array_key_exists('definable_field_2', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `definable_field_2` VARCHAR(50) NOT NULL AFTER `definable_field_1`")) {
echo '<p class="good">Database field definable_field_2 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_2 exists, update not needed</p>'; }
if (!array_key_exists('stock_mode', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `stock_mode` VARCHAR(10) NOT NULL AFTER `definable_field_2`")) {
echo '<p class="good">Database field stock_mode added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field stock_mode exists, update not needed</p>'; }
if (!array_key_exists('stock_limit', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `stock_limit` INT(3) NOT NULL AFTER `stock_mode`")) {
echo '<p class="good">Database field stock_limit added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field stock_limit exists, update not needed</p>'; }
}
// Change continue_url to a link not containing domain name nor page directory
echo "<h4>Modifying table page_settings:</h4>";
$settingstable = $database->query("SELECT section_id, continue_url FROM `".TABLE_PREFIX."mod_bakery_page_settings`");
while ($settings = $settingstable->fetchRow()) {
$section_id = $settings['section_id'];
$continue_url = str_replace(array(WB_URL.PAGES_DIRECTORY, PAGE_EXTENSION), array("", ""), $settings['continue_url']);
if ($database->query("UPDATE ".TABLE_PREFIX."mod_bakery_page_settings SET continue_url = '$continue_url' WHERE section_id = '$section_id'")) {
echo '<p class="good">Changed continue_url of section_id='.$section_id.' successfully to a link not containing domain name nor page directory</p>';
} else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
// Get ITEMS table to see what needs to be added
echo "<h4>Modifying table items:</h4>";
$itemstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_items`");
if ($item = $itemstable->fetchRow()) {
if (!array_key_exists('definable_field_0', $item)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `definable_field_0` VARCHAR(150) NOT NULL AFTER `tax_rate`")) {
echo '<p class="good">Database field definable_field_0 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_0 exists, update not needed</p>'; }
if (!array_key_exists('definable_field_1', $item)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `definable_field_1` VARCHAR(150) NOT NULL AFTER `definable_field_0`")) {
echo '<p class="good">Database field definable_field_1 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_1 exists, update not needed</p>'; }
if (!array_key_exists('definable_field_2', $item)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_items` ADD `definable_field_2` VARCHAR(150) NOT NULL AFTER `definable_field_1`")) {
echo '<p class="good">Database field definable_field_2 added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field definable_field_2 exists, update not needed</p>'; }
}
// Change item link to a link not containing domain name nor page directory
while ($item = $itemstable->fetchRow()) {
$item_id = $item['item_id'];
$link = str_replace(PAGES_DIRECTORY, "", $item['link']);
if ($database->query("UPDATE ".TABLE_PREFIX."mod_bakery_items SET link = '$link' WHERE item_id = '$item_id'")) {
echo '<p class="good">Changed item link of item_id='.$item_id.' successfully to a link not containing domain name nor page directory</p>';
} else {
echo '<p class="bad">'.mysql_error().'</p>';
}
}
}
// UPGRADE TO VERSION 1.1
// **********************
if ($bakery_settings['version'] < '1.1') {
// Titel: Upgrading to
echo'<h3>Upgrading to version 1.1:</h3>';
// Add new fields to the general settings table
echo'<h4>Adding new fields to the general_settings table</h4>';
// Get SETTINGS table to see what needs to be changed
$settingstable = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_bakery_general_settings`");
if ($settings = $settingstable->fetchRow()) {
if (!array_key_exists('display_settings', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `display_settings` ENUM('1','0') NOT NULL DEFAULT '1' AFTER `zip_location`")) {
echo '<p class="good">Database field display_settings added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field display_settings exists, update not needed</p>'; }
if (!array_key_exists('out_of_stock_orders', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `out_of_stock_orders` ENUM('1','0') NOT NULL DEFAULT '0' AFTER `stock_limit`")) {
echo '<p class="good">Database field out_of_stock_orders added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field out_of_stock_orders exists, update not needed</p>'; }
if (!array_key_exists('thousands_sep', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `thousands_sep` VARCHAR(1) NOT NULL DEFAULT '\'' AFTER `shop_currency`")) {
echo '<p class="good">Database field thousands_sep added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field thousands_sep exists, update not needed</p>'; }
if (!array_key_exists('dec_point', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `dec_point` VARCHAR(1) NOT NULL DEFAULT '.' AFTER `shop_currency`")) {
echo '<p class="good">Database field dec_point added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field dec_point exists, update not needed</p>'; }
if (!array_key_exists('skip_checkout', $settings)){
if ($database->query("ALTER TABLE `".TABLE_PREFIX."mod_bakery_general_settings` ADD `skip_checkout` ENUM('1','0') NOT NULL DEFAULT '0' AFTER `tax_included`")) {
echo '<p class="good">Database field skip_checkout added successfully</p>';
} else { echo '<p class="bad">'.mysql_error().'</p>'; }
} else { echo '<p class="ok">Database field skip_checkout exists, update not needed</p>'; }
}
// Add new payment methods table to the database
echo'<h4>Adding new payment methods table to the database</h4>';
// Create new PAYMENT METHODS table
$mod_bakery = 'CREATE TABLE `'.TABLE_PREFIX.'mod_bakery_payment_methods` ( '
. '`pm_id` INT(11) NOT NULL AUTO_INCREMENT ,'
. '`active` INT(1) NOT NULL ,'
. '`directory` VARCHAR(50) NOT NULL ,'
. '`name` VARCHAR(50) NOT NULL ,'
. '`version` VARCHAR(6) NOT NULL ,'
. '`author` VARCHAR(50) NOT NULL ,'
. '`requires` VARCHAR(6) NOT NULL ,'
. '`field_1` VARCHAR(150) NOT NULL ,'
. '`value_1` TEXT NOT NULL ,'
. '`field_2` VARCHAR(150) NOT NULL ,'