-
Notifications
You must be signed in to change notification settings - Fork 27
/
interchange.PL
2997 lines (2579 loc) · 77.3 KB
/
interchange.PL
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
my $base = $ARGV[0] || '/work/interchange';
$self = {
INSTALLARCHLIB => $base,
INSTALLBIN => "$base/bin",
INSTALLDIRS => 'perl',
INSTALLMAN1DIR => "$base/doc",
INSTALLMAN3DIR => "$base/doc",
INSTALLPRIVLIB => "$base/lib",
INSTALLSCRIPT => "$base/bin",
};
my %Special;
use Config;
eval {
require 'scripts/initp.pl';
};
if(! $MV::Self ) {
$MV::Self = $self;
$Special{perlpath} = $Config{perlpath};
$Special{perlpath} .= <<EOF;
eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
if 0; # not running under some shell
EOF
$Special{perlpath} =~ s/\s+$//;
}
sub doit {
my ($key) = @_;
my $val;
if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
$val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
return $val;
}
return $MV::Self->{$key} unless $key =~ /[a-z]/;
return $Special{$key} if defined $Special{$key};
$Config{$key};
}
DOIT: {
local ($/);
local($_) = <<'_EoP_';
#!/usr/bin/perl
##!~_~perlpath~_~
#
# Interchange version 4.7.6
#
# $Id: interchange.PL,v 1.15.2.56 2001-07-17 15:30:08 ton Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
# This program was originally based on Vend 0.2 and 0.3
# Copyright 1995 by Andrew M. Wilcox <awilcox@world.std.com>
#
# See the files 'README' and 'WHATSNEW' for information.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
use lib '/usr/local/interchange/lib';
#use lib '~_~INSTALLPRIVLIB~_~';
use lib '/usr/local/interchange';
#use lib '~_~INSTALLARCHLIB~_~';
use strict;
BEGIN {
$Global::Foreground = 1;
($Global::VendRoot = $ENV{MINIVEND_ROOT})
if defined $ENV{MINIVEND_ROOT};
$Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
# $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
if(-f "$Global::VendRoot/interchange.cfg") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
elsif(-f "$Global::VendRoot/minivend.cfg") {
$Global::ExeName = 'minivend';
$Global::ConfigFile = 'minivend.cfg';
}
elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
$Global::InitialErrorFile = $Global::ErrorFile = "$Global::VendRoot/error.log";
if($^O =~ /cygwin|win32/i) {
$Global::Windows = 1;
}
# Uncomment next line if you want to guarantee use of DB_File
#$ENV{MINIVEND_DBFILE} = 1;
# Uncomment next line in the unlikely event you want to ignore
# GDBM and DB_File and force use of SDBM.
#$ENV{MINIVEND_SDBM} = 1;
# Uncomment next line if you want to guarantee use of GDBM and not DB_File
#$ENV{MINIVEND_GDBM} = 1;
# Uncomment next line if you want to use no DBM, sessions
# stored in files and databases in memory (or SQL)
#$ENV{MINIVEND_NODBM} = 1;
# Uncomment next line if you want the ability to use ALL DBM.
# Otherwise we use only the first choice to save memory.
#$ENV{MINIVEND_ALLDBM} = 1;
# Uncomment next line if you DON'T want to use DBI, can
# save a bit on code size
#$ENV{MINIVEND_NO_DBI} = 1;
# Uncomment next line if you want to use the Storable
# module for storing session data. It improves session performance
# to a good degree. We will also do a bit of auto-detect below.
#$ENV{MINIVEND_STORABLE} = 1;
# Uncomment next line if you want to use the Storable
# module for storing database data. It improves GBDM/DB_File performance
# to a good degree. We will also do a bit of auto-detect below.
#$ENV{MINIVEND_STORABLE_DB} = 1;
# Uncomment AND SET next line to set PGP path to somewhere besides
# the Interchange user path
#$ENV{PGPPATH} = '/usr/local/pgp';
# Use the Storable module for storing data in DBM files.
if(-f "$Global::VendRoot/_session_storable") {
$ENV{MINIVEND_STORABLE} = 1;
}
if(-f "$Global::VendRoot/_db_storable") {
$ENV{MINIVEND_STORABLE_DB} = 1;
}
# Interchange can use syslog via the "logger" command
# This prevents parsing of the value, default is syslog off
$Global::SysLog = '';
}
### END CONFIGURATION VARIABLES
use vars qw($VERSION);
require Exporter;
BEGIN {
$VERSION = '4.7.6';
}
use Fcntl;
# BSD, among others, defines sendmail to be in /usr/sbin, and
# we want to make sure the program is there. Insert the location
# of you sendmail binary (the configure script should do this)
$Global::SendMailLocation = '' if ! $Global::SendMailLocation;
$Global::SendMailLocation = ($Global::Windows and $Global::SendMailLocation) ||
($Global::SendMailLocation and -x $Global::SendMailLocation and $Global::SendMailLocation) ||
(-x '/usr/lib/sendmail' and '/usr/lib/sendmail') ||
(-x '/usr/sbin/sendmail' and '/usr/sbin/sendmail') ||
'';
# '~_~sendmail~_~';
#select a DBM
BEGIN {
$Global::GDBM = $Global::DB_File = $Global::SDBM =
# LDAP
$Global::LDAP =
# END LDAP
# SQL
$Global::DBI =
# END SQL
0;
# SQL
# This is for standard DBI
eval {
die if $ENV{MINIVEND_NODBI};
require DBI and $Global::DBI = 1
};
# END SQL
# LDAP
eval {
die if $ENV{MINIVEND_NOLDAP};
require Net::LDAP and $Global::LDAP = 1
};
# END LDAP
# Now can use any type of database
AUTO: {
last AUTO if
(defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
last AUTO if
(defined $ENV{MINIVEND_SDBM} and $Global::SDBM = 1);
last AUTO if
(defined $ENV{MINIVEND_NODBM});
eval {require GDBM_File and $Global::GDBM = 1};
last AUTO if
(defined $ENV{MINIVEND_GDBM} and $Global::GDBM = 1);
last AUTO if
! $ENV{MINIVEND_ALLDBM}
and $Global::GDBM;
eval {require DB_File and $Global::DB_File = 1};
last AUTO if
! $ENV{MINIVEND_ALLDBM}
and $Global::GDBM || $Global::DB_File;
eval {require SDBM_File and $Global::SDBM = 1};
}
if($Global::GDBM) {
require Vend::Table::GDBM;
import GDBM_File;
$Global::GDBM = 1;
$Global::Default_database = 'GDBM'
unless defined $Global::Default_database;
}
if($Global::DB_File) {
require Vend::Table::DB_File;
import DB_File;
$Global::DB_File = 1;
$Global::Default_database = 'DB_FILE'
unless defined $Global::Default_database;
}
if($Global::SDBM) {
require Vend::Table::SDBM;
import SDBM_File;
$Global::SDBM = 1;
$Global::Default_database = 'SDBM'
unless defined $Global::Default_database;
}
$Global::Default_database = 'MEMORY'
unless defined $Global::Default_database;
require Vend::Table::InMemory;
}
use Vend::Util;
use Vend::Server;
use Vend::Session;
use Vend::Config;
use Vend::Payment;
# You might try commenting out these lines and uncommenting the ones
# below to compact memory size
# NOAUTOUSE
use Vend::Order;
#use Vend::Imagemap;
#use Vend::Error;
#use Vend::Control;
# END NOAUTOUSE
# You might try commenting out these lines and uncommenting the ones
# below to do development or test for strange problems
# AUTOUSE
use autouse 'Vend::Error' => qw/get_locale_message interaction_error do_lockout full_dump/;
use autouse 'Vend::Imagemap' => qw/action_map/;
use autouse 'Vend::Control' => qw/
signal_reconfig
signal_add
signal_remove
control_interchange
remove_catalog
add_catalog
change_catalog_directive
change_global_directive
/;
#use autouse 'Vend::Order' => qw/
# add_items
# check_order
# check_required
# cyber_charge
# encrypt_standard_cc
# mail_order
# onfly
# route_order
# validate_whole_cc
# /;
# END AUTOUSE
# GLIMPSE
use Vend::Glimpse;
# END GLIMPSE
# TRACK
use Vend::Track;
# END TRACK
use Vend::Scan;
use Vend::TextSearch;
use Vend::DbSearch;
use Vend::Data;
use Vend::UserDB;
use Vend::Interpolate;
use Vend::Page;
use File::CounterFile;
if( ! $Global::Windows and $> == -1 || scalar(getpwuid($>)) eq 'nobody' ) {
warn errmsg("\aYou probably don't want to run as nobody!\n");
sleep 1;
warn errmsg("The security problems are on your head, though. Continuing...\n");
}
## This was set to 1 in Vend::Config, so that external programs calling it
## would act properly by default
undef $Vend::ExternalProgram;
my $H;
sub http {
return $H;
}
sub response {
my ($output) = @_;
my $out = ref $output ? $output : \$output;
if (defined $Vend::CheckHTML) {
require Vend::External;
Vend::External::check_html($out);
}
$H->respond($out);
}
## DO ORDER
# Order an item with product code CODE.
sub do_order {
my($path) = @_;
my $code = $CGI::values{mv_arg};
#::logDebug("do_order: path=$path");
my $cart;
my $page;
# LEGACY
if($path =~ s:/(.*)::) {
$cart = $1;
if($cart =~ s:/(.*)::) {
$page = $1;
}
}
# END LEGACY
if(defined $CGI::values{mv_pc} and $CGI::values{mv_pc} =~ /_(\d+)/) {
$CGI::values{mv_order_quantity} = $1;
}
$CGI::values{mv_cartname} = $cart if $cart;
$CGI::values{mv_nextpage} = $page if $page;
# LEGACY
$CGI::values{mv_nextpage} = $CGI::values{mv_orderpage}
|| find_special_page('order')
if ! $CGI::values{mv_nextpage};
# END LEGACY
add_items($code);
return 1;
}
my @Scan_modifiers = qw/
mv_ad
mv_an
mv_bd
mv_bd
/;
# Returns undef if interaction error
sub update_quantity {
return 1 unless defined $CGI::values{"quantity0"}
|| $CGI::values{mv_quantity_update};
my($h, $i, $quantity, $modifier, $cart);
$cart = Vend::Cart::get_cart($CGI::values{mv_cartname});
my @mods;
@mods = @{$Vend::Cfg->{UseModifier}} if $Vend::Cfg->{UseModifier};
#::logDebug("adding modifiers");
push(@mods, (grep $_ !~ /^mv_/, split /\0/, $CGI::values{mv_item_option}))
if defined $CGI::values{mv_item_option};
my %seen;
push @mods, grep defined $CGI::values{"${_}0"}, @Scan_modifiers;
@mods = grep ! $seen{$_}++, @mods;
foreach $h (@mods) {
delete @{$::Values}{grep /^$h\d+$/, keys %$::Values};
foreach $i (0 .. $#$cart) {
#::logDebug("updating line $i modifiers: " . ::uneval($cart->[$i]));
#::logDebug(qq{CGI value=$CGI::values{"$h$i"}});
$modifier = $CGI::values{"$h$i"}
|| (defined $cart->[$i]{$h} ? '' : undef);
#::logDebug("line $i modifier $h now $modifier");
if (defined($modifier)) {
$modifier =~ s/\0+/\0/g;
$modifier =~ s/\0$//;
$modifier =~ s/^\0//;
$modifier =~ s/\0/, /g;
$cart->[$i]->{$h} = $modifier;
$::Values->{"$h$i"} = $modifier;
delete $CGI::values{"$h$i"};
}
}
}
foreach $i (0 .. $#$cart) {
#::logDebug("updating line $i quantity: " . ::uneval($cart->[$i]));
my $line = $cart->[$i];
$line->{mv_ip} = $i;
$quantity = $CGI::values{"quantity$i"};
next unless defined $quantity;
if ($quantity =~ m/^\d*$/) {
$line->{'quantity'} = $quantity || 0;
}
elsif ($quantity =~ m/^[\d.]+$/
and $Vend::Cfg->{FractionalItems} ) {
$line->{'quantity'} = $quantity;
}
# This allows a last-positioned input of item quantity to
# remove the item
elsif ($quantity =~ s/.*\00$/0/) {
$CGI::values{"quantity$i"} = $quantity;
redo;
}
# This allows a multiple input of item quantity to
# pass -- FIRST ONE CONTROLS
elsif ($quantity =~ s/\0.*//) {
$CGI::values{"quantity$i"} = $quantity;
redo;
}
else {
my $item = $line->{'code'};
$line->{quantity} = int $line->{quantity};
$Vend::Session->{errors}{mv_order_quantity} =
errmsg("'%s' for item %s is not numeric/integer", $quantity, $item);
}
$::Values->{"quantity$i"} = delete $CGI::values{"quantity$i"};
SKUSET: {
my $sku;
my $found_option;
last SKUSET unless $sku = delete $CGI::values{"mv_sku$i"};
my @sku = split /\0/, $sku, -1;
for(@sku[1..$#sku]) {
if (not length $_) {
$_ = $::Variable->{MV_VARIANT_JOINER} || '0';
next;
}
$found_option++;
}
if(@sku > 1 and ! $found_option) {
splice @sku, 1;
}
$sku = join "-", @sku;
my $ib;
unless($ib = ::product_code_exists_tag($sku)) {
push @{$Vend::Session->{warnings} ||= []},
errmsg("Not a valid option combination: %s", $sku);
last SKUSET;
}
$line->{mv_ib} = $ib;
if($sku ne $line->{code}) {
if($line->{mv_mp}) {
$line->{mv_sku} = $line->{code} = $sku;
}
elsif (! $line->{mv_sku}) {
$line->{mv_sku} = $line->{code};
$line->{code} = $sku;
}
else {
$line->{code} = $sku;
}
}
}
}
#::logDebug("after update, cart is: " . ::uneval($cart));
# If the user has put in "0" for any quantity, delete that item
# from the order list. Handles sub-items.
Vend::Cart::toss_cart($cart);
#::logDebug("after toss, cart is: " . ::uneval($cart));
1;
}
sub set_db {
my ($base, $thing) = @_;
return ($base, $thing) unless $thing =~ /^(\w+):+(.*)/;
my $t = $1;
my $c = $2;
$Vend::WriteDatabase = 1 if $::Scratch->{mv_data_enable} =~ / $t[: ]/;
my $db = ::database_exists_ref($t);
return undef unless $db;
return ($db->ref(), $c);
}
## Update the user-entered fields.
sub update_data {
my($key,$value);
# Update a database record
# Check to see if this is allowed
if(! $::Scratch->{mv_data_enable}) {
logError(
"Attempted database update without permission, table=%s key=%s.",
$CGI::values{mv_data_table},
$CGI::values{$CGI::values{mv_data_key}},
);
return undef;
}
unless (defined $CGI::values{mv_data_table} and
defined $CGI::values{mv_data_key} ) {
logError("Attempted database operation without table, fields, or key.\n" .
"Table: '%s'\n" .
"Fields:'%s'\n" .
"Key: '%s'\n",
$CGI::values{mv_data_table},
$CGI::values{mv_data_fields},
$CGI::values{mv_data_key},
);
return undef;
}
my $function = lc (delete $CGI::values{mv_data_function});
if($function eq 'delete' and ! delete $CGI::values{mv_data_verify}) {
logError("update_data: DELETE without VERIFY, abort");
return undef;
}
my $table = $CGI::values{mv_data_table};
my $prikey = $CGI::values{mv_data_key};
my $decode = is_yes($CGI::values{mv_data_decode});
my ($ref, $db, $database);
my $en_col;
#::logDebug("data_enable=$::Scratch->{mv_data_enable}, checking");
if($::Scratch->{mv_data_enable} =~ /^(\w+):(.*?):/) {
# check for single key and possible set of columns
my $en_table = $1;
$en_col = $2;
my $en_key = $::Scratch->{mv_data_enable_key};
#::logDebug("en_table=$en_table en_col=$en_col, en_key=$en_key, checking");
if( $en_table ne $table
or
($en_key and $CGI::values{$prikey} ne $en_key)
)
{
logError("Attempted database operation without permission:\n" .
"Permission: '%s' (key='$en_key')\n" .
"Table: '%s'\n" .
"Fields:'%s'\n" .
"Key: '%s'\n",
$::Scratch->{mv_data_enable},
$CGI::values{mv_data_table},
$CGI::values{mv_data_fields},
$CGI::values{$CGI::values{mv_data_key}},
);
return undef;
}
}
if (! $Vend::Cfg->{Database}{$table}) {
logError("set: non-existent table %s", $table);
return undef;
}
$Vend::WriteDatabase{$table} = 1;
my $base_db = database_exists_ref($table)
or die "Not a defined database '$table': $!\n";
$base_db = $base_db->ref();
my @fields = grep $_ && $_ ne $prikey,
split /[\s\0,]+/, $CGI::values{mv_data_fields};
unshift(@fields, $prikey);
my @file_fields = split /[\s\0,]+/, $CGI::values{mv_data_file_field};
my @file_paths = split /[\s\0,]+/, $CGI::values{mv_data_file_path};
my @file_oldfiles = split /[\s\0,]+/, $CGI::values{mv_data_file_oldfile};
if($en_col) {
$en_col =~ s/^\s+//;
$en_col =~ s/\s+$//;
my %col_present;
@col_present{ grep /\S/, split /[\s\0,]+/, $en_col } = ();
$col_present{$prikey} = 1;
for(@fields, $CGI::values{mv_blob_field}, $CGI::values{mv_blob_pointer}) {
next unless $_;
next if exists $col_present{$_};
next if /:/ and $::Scratch->{mv_data_enable} =~ / $_ /;
logError("Attempted database operation without permission:\n" .
"Permission: '%s'\n" .
"Table: '%s'\n" .
"Fields:'%s'\n" .
"Key: '%s'\n",
$::Scratch->{mv_data_enable},
$CGI::values{mv_data_table},
$CGI::values{mv_data_fields},
$CGI::values{$CGI::values{mv_data_key}},
);
return undef;
}
}
$function = 'update' unless $function;
my (%data);
for(@fields) {
$data{$_} = [];
}
my $count;
my $multi = $CGI::values{$prikey} =~ tr/\0/\0/;
my $max = 0;
my $min = 9999;
my ($minname, $maxname);
while (($key, $value) = each %CGI::values) {
next unless defined $data{$key};
$count = (@{$data{$key}} = split /\0/, $value);
$max = $count, $maxname = $key if $count > $max;
$min = $count, $minname = $key if $count < $min;
}
if( $multi and ($max - $min) > 1 and ! $CGI::values{mv_data_force}) {
my $msg = errmsg(
"probable bad form -- number of values min=%s (%s) max=%s (%s)",
$min, $minname, $max, $maxname,
);
Vend::Interpolate::set_error($msg);
return;
}
my $autonumber;
if ($CGI::values{mv_data_auto_number}) {
$autonumber = 1;
my $ref = $data{$prikey};
while (scalar @$ref < $max) {
push @$ref, '';
}
$base_db->config('AUTO_NUMBER', '000001')
if ! $base_db->config('_Auto_number');
$CGI::values{mv_data_return_key} = $prikey
unless $CGI::values{mv_data_return_key};
}
elsif($function eq 'insert' and $base_db->config('_Auto_number') ) {
$autonumber = 1;
}
if(@file_fields) {
my $Tag = new Vend::Tags;
my $acl_func;
my $outfile;
if($Vend::Session->{logged_in} and $Vend::admin) {
$acl_func = sub {
return $Tag->if_mm('files', shift);
};
}
elsif($Vend::Session->{logged_in} and ! $Vend::admin) {
$acl_func = sub {
my $file = shift;
return 1 if $::Scratch->{$file} == 1;
return $Tag->userdb(
function => 'check_file_acl',
location => $file,
mode => 'w'
);
};
}
else {
$acl_func = sub { return $::Scratch->{shift(@_)} == 1 }
}
for (my $i = 0; $i < @file_fields; $i++) {
unless (length($data{$file_fields[$i]}->[0])) {
# no need for a file update
$data{$file_fields[$i]}->[0] = $file_oldfiles[$i];
next;
}
# remove path components
$data{$file_fields[$i]}->[0] =~ s:.*/::;
if (length ($file_paths[$i])) {
# real file upload
$outfile = join('/', $file_paths[$i], $data{$file_fields[$i]}->[0]);
#::logDebug("file upload: field=$file_fields[$i] path=$file_paths[$i] outfile=$outfile");
my $ok;
if (-f $outfile) {
eval {
$ok = $acl_func->($outfile);
};
} else {
eval {
$ok = $acl_func->($file_paths[$i]);
};
}
if (! $ok) {
if($@) {
::logError ("ACL function failed on '%s': %s", $outfile, $@);
}
else {
::logError ("Not allowed to upload \"%s\"", $outfile);
}
next;
}
my $err;
Vend::Interpolate::tag_value_extended(
$file_fields[$i],
{
test => 'isfile'
}
)
or do {
::logError("%s is not a file.", $data{$file_fields[$i]}->[0]);
next;
};
Vend::Interpolate::tag_value_extended(
$file_fields[$i],
{
outfile => $outfile,
umask => '022',
yes => '1',
}
)
or do {
::logError("failed to write %s: %s", $outfile, $!);
next;
};
}
else {
# preparing to dump file contents into database column
$data{$file_fields[$i]}->[0]
= Vend::Interpolate::tag_value_extended ($file_fields[$i],
{file_contents => 1});
}
}
}
if (not defined $data{$prikey}) {
logError("No key '%s' in field specifier %s", $prikey, 'mv_data_fields');
return undef;
}
elsif ( ! @{$data{$prikey}}) {
if($autonumber) {
@{$data{$prikey}} = map { '' } @{ $data{$fields[1]} };
}
else {
logError("No key '%s' found for function='%s' table='%s'",
$prikey, $function, $CGI::values{mv_data_table},
);
return undef;
}
}
my ($query,$i);
my (@k);
my (@v);
my (@c);
my (@rows_set);
my (@email_rows);
my $safe;
my $blob_field;
my $blob_nick;
my $blob_ptr;
# Fields to set in database despite mv_blob_only
my %blob_exception;
if($CGI::values{mv_blob_field} and $CGI::values{mv_blob_nick}) {
#::logDebug("update_data: blob processing enabled");
$blob_field = $CGI::values{mv_blob_field};
$blob_nick = $CGI::values{mv_blob_nick};
$blob_ptr = $CGI::values{mv_blob_pointer};
%blob_exception =
map { ($_, 1) } split /[\s,\0]+/, $CGI::values{mv_blob_exception};
if( ! $base_db->column_exists($blob_field) ) {
undef $blob_field;
undef $blob_nick;
logError("No blob field '%s' found for table='%s', skipping blob save.",
$CGI::values{mv_blob_field}, $CGI::values{mv_data_table},
);
}
elsif ($MVSAFE::Safe) {
$safe = $Vend::Interpolate::ready_safe;
}
else {
$safe = new Safe;
}
$base_db->column_exists($blob_ptr)
or undef $blob_ptr;
#::logDebug("update_data: blob safe object=$safe");
}
#::logDebug("update_data:db=$db key=$prikey VALUES=" . ::uneval(\%CGI::values));
#::logDebug("update_data:db=$db key=$prikey data=" . ::uneval(\%data));
my $select_key;
for($i = 0; $i < @{$data{$prikey}}; $i++) {
#::logDebug("iteration of update_data:db=$db key=$prikey data=" . ::uneval(\%data));
@k = (); @v = ();
for(keys %data) {
#::logDebug("iteration of field $_");
next unless (length($value = $data{$_}->[$i]) || $CGI::values{mv_update_empty} );
push(@k, $_);
# LEGACY
HTML::Entities::decode($value) if $decode;
# END LEGACY
if(defined $CGI::values{"mv_data_filter_$_"}) {
$value = Vend::Interpolate::filter_value(
$CGI::values{"mv_data_filter_$_"},
$value,
$i,
);
}
$select_key = $value if $_ eq $prikey;
push(@v, $value);
}
if($function eq 'delete') {
$base_db->delete_record($select_key);
}
else {
my $field;
$key = $data{$prikey}->[$i];
if(! length($key) and $autonumber) {
## KEY IS possibly SET HERE
$key = $base_db->set_row($key);
}
push(@rows_set, $key);
# allow form submissions to go to database and to mail
if ($CGI::values{mv_data_email}) {
push( @email_rows,
[ ::errmsg("### Form Submission from %s", $key), $blob_nick, ],
[ $prikey, $key, ],
);
}
my $qd = {};
my $qf = {};
my $qv = {};
my $qret;
my $blob;
my $brec;
if($blob_field) {
my $string = $base_db->field($key, $blob_field);
#::logDebug("update_data: blob string=$string");
$blob = $safe->reval($string);
#::logDebug("update_data: blob object=$blob");
$blob = {} if ! $blob;
$blob->{$blob_nick} = {}
if ! $blob->{$blob_nick};
$brec = $blob->{$blob_nick};
}
while($field = shift @k) {
$value = shift @v;
next if $field eq $prikey;
## DATA IS SET HERE
# We are going to set the field unless it is only for
# storing in a blob (and possibly emailing)
my ($d, $f);
if ($CGI::values{mv_blob_only} and ! $blob_exception{$field}) {
#::logDebug("$field not storing, only blob");
$f = $field;
}
else {
#::logDebug("storing d=$d $field blob_only=$CGI::values{mv_blob_only}");
($d, $f) = set_db($base_db, $field);
#::logDebug("storing table=$table d=$d f=$f key=$key");
if(! defined $qd->{$d}) {
$qd->{$d} = $d;
$qf->{$d} = [$f];
$qv->{$d} = [$value];
}
else {
push @{$qf->{$d}}, $f;
push @{$qv->{$d}}, $value;
}
#$d->set_field($key, $f, $value);
}
push(@email_rows, [$f, $value])
if $CGI::values{mv_data_email};
#::logDebug("update_data:db=$d key=$key field=$f value=$value");
$brec->{$f} = $value if $brec;
}
for(keys %$qd) {
$qret = $qd->{$_}->set_slice($key, $qf->{$_}, $qv->{$_});
$rows_set[$i] = $qret unless $rows_set[$i];
}
if($blob) {
$brec->{mv_data_fields} = join " ", @fields;
my $string = ::uneval_it($blob);
#::logDebug("update_data: blob saving string=$string");
$base_db->set_field($key, $blob_field, $string);
if($blob_ptr) {
$base_db->set_field($key, $blob_ptr, $blob_nick);
}
}
push(
@email_rows,
[ ::errmsg("### END FORM SUBMISSION %s", $key), $blob_nick, ]
)
if $CGI::values{mv_data_email};
}
}
if($CGI::values{mv_data_return_key}) {
my @keys = split /\0/, $CGI::values{mv_data_return_key};
for(@keys) {
#::logDebug("return_key, setting $_");
$CGI::values{$_} = join("\0", @rows_set);
}
}
if($CGI::values{mv_auto_export}) {
Vend::Data::export_database($table);
}
if($CGI::values{mv_data_email}) {
push @email_rows, [ 'mv_data_fields', \@fields ];
Vend::Interpolate::tag_mail('', { log_error => 1 }, \@email_rows);
}
# Allow setting in one then returning to another
if($CGI::values{mv_return_table}) {
$CGI::values{mv_data_table} = $CGI::values{mv_return_table};
}
return;
}
# Parse the mv_click and mv_check special variables
sub parse_click {
my ($ref, $click, $extra) = @_;
my($codere) = '[-\w_#/.]+';
my $params;
#::logDebug("Looking for click $click");
if($params = $::Scratch->{$click}) {
# Do nothing, we found the click
#::logDebug("Found scratch click $click = |$params|");
}
elsif(defined ($params = $Vend::Cfg->{OrderProfileName}{$click}) ) {
# Do nothing, we found the click
$params = $Vend::Cfg->{OrderProfile}[$params];
#::logDebug("Found profile click $click = |$params|");
}
elsif(defined ($params = $Global::ProfilesName->{$click}) ) {
# Do nothing, we found the click
$params = $Global::Profiles->[$params];
#::logDebug("Found profile click $click = |$params|");
}
elsif($params = $::Scratch->{"mv_click $click"}) {
$::Scratch->{mv_click_arg} = $click;
}
elsif($params = $::Scratch->{mv_click}) {
$::Scratch->{mv_click_arg} = $click;
}
else {
#::logDebug("Found NO click $click");
return 1;
} # No click processor
my($var,$val,$parameter);
$params = interpolate_html($params);
my(@param) = split /\n+/, $params;
for(@param) {
next unless /\S/;
next if /^\s*#/;