line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# HTML::EP - A Perl based HTML extension. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (C) 1998 Jochen Wiedmann |
7
|
|
|
|
|
|
|
# Am Eisteich 9 |
8
|
|
|
|
|
|
|
# 72555 Metzingen |
9
|
|
|
|
|
|
|
# Germany |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Phone: +49 7123 14887 |
12
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# All rights reserved. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# You may distribute this module under the terms of either |
17
|
|
|
|
|
|
|
# the GNU General Public License or the Artistic License, as |
18
|
|
|
|
|
|
|
# specified in the Perl README file. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require 5.004; |
23
|
2
|
|
|
2
|
|
1394
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3642
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require HTML::EP::Session; |
26
|
|
|
|
|
|
|
require HTML::EP::Locale; |
27
|
|
|
|
|
|
|
require Storable; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package HTML::EP::Shop; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$HTML::EP::Shop::VERSION = '0.1001'; |
33
|
|
|
|
|
|
|
@HTML::EP::Shop::ISA = qw(HTML::EP::Session HTML::EP::Locale HTML::EP); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
0
|
0
|
|
|
|
|
if (!$self->{'_ep_language'}) { |
39
|
0
|
|
|
|
|
|
$self->HTML::EP::Session::init(@_); |
40
|
0
|
|
|
|
|
|
$self->HTML::EP::Locale::init(@_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _ep_shop_upload { |
46
|
0
|
|
|
0
|
|
|
my $self = shift; my $attr = shift; |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $cgi = $self->{'cgi'}; |
48
|
0
|
|
|
|
|
|
my $debug = $self->{'debug'}; |
49
|
0
|
|
0
|
|
|
|
my $cgivar = $attr->{'cgivar'} || die "Missing CGI variable"; |
50
|
0
|
|
0
|
|
|
|
my $dsn = $attr->{'dsn'} || "DBI:CSV:"; |
51
|
0
|
0
|
|
|
|
|
if ($debug) { $self->print("Making secondary DSN: $dsn\n") } |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $dbhf = DBI->connect($dsn, undef, undef, |
54
|
|
|
|
|
|
|
{'RaiseError' => 1, 'Warn' => 0, |
55
|
|
|
|
|
|
|
'PrintError' => 0}); |
56
|
0
|
|
0
|
|
|
|
my $csv = Text::CSV_XS->new |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
57
|
|
|
|
|
|
|
({ 'binary' => 1, 'eol' => "\r\n", |
58
|
|
|
|
|
|
|
'sep_char' => $cgi->param('sep') || ';', |
59
|
|
|
|
|
|
|
'quote_char' => $cgi->param('escape') || '"', |
60
|
|
|
|
|
|
|
'escape_char' => $cgi->param('quote') || $cgi->param('escape') |
61
|
|
|
|
|
|
|
|| '"' |
62
|
|
|
|
|
|
|
}); |
63
|
0
|
|
|
|
|
|
$dbhf->{'csv_csv'} = $csv; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
|
my $table = $attr->{'table'} || die "Missing table name"; |
66
|
0
|
|
|
|
|
|
my $fileName = $cgi->param($cgivar); |
67
|
0
|
|
0
|
|
|
|
my $tmpFile = $cgi->tmpFileName($fileName) || die "Missing file"; |
68
|
0
|
0
|
|
|
|
|
if ($debug) { |
69
|
0
|
|
|
|
|
|
$self->printf("Reading table %s, file name %s, tmpfile %s.\n", |
70
|
|
|
|
|
|
|
$table, $fileName, $tmpFile); |
71
|
0
|
|
|
|
|
|
$self->printf("Using separator %s, quote char %s, escape char %s\n", |
72
|
|
|
|
|
|
|
$csv->{'sep_char'}, $csv->{'quote_char'}, |
73
|
|
|
|
|
|
|
$csv->{'escape_char'}); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
$dbhf->{'csv_tables'}->{$table} = { |
76
|
|
|
|
|
|
|
'file' => $tmpFile |
77
|
|
|
|
|
|
|
}; |
78
|
0
|
|
|
|
|
|
my $query = "SELECT * FROM $table"; |
79
|
0
|
0
|
|
|
|
|
if ($debug) { $self->print("SELECT query: $query\n") } |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $sth = $dbhf->prepare($query); |
81
|
0
|
|
|
|
|
|
$sth->execute(); |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if (my $namevar = $attr->{'names'}) { |
84
|
0
|
|
|
|
|
|
$self->{$namevar} = $sth->{'NAME'}; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
0
|
|
|
|
|
if (my $templatevar = $attr->{'template'}) { |
87
|
0
|
|
|
|
|
|
my $template = ''; |
88
|
0
|
|
|
|
|
|
for (my $i = 0; $i <= $sth->{'NUM_OF_FIELDS'}; $i++) { |
89
|
0
|
|
|
|
|
|
$template .= " | \$r->$i\$ | ";
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
$self->{$templatevar} = $template . "\n"; |
92
|
0
|
0
|
|
|
|
|
if ($self->{'debug'}) { |
93
|
0
|
|
|
|
|
|
$self->print("Template = $template\n"); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
my $numRecords = 0; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$query = "DELETE FROM $table"; |
101
|
0
|
0
|
|
|
|
|
if ($debug) { $self->print("Cleaning query: $query\n") } |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$dbh->do($query); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$query = "INSERT INTO $table VALUES ("; |
105
|
0
|
|
|
|
|
|
my $add = ""; |
106
|
0
|
|
|
|
|
|
for (my $i = 0; $i <= $sth->{'NUM_OF_FIELDS'}; $i++) { |
107
|
0
|
|
|
|
|
|
$query .= $add . "?"; |
108
|
0
|
|
|
|
|
|
$add = ", "; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
$query .= ")"; |
111
|
0
|
0
|
|
|
|
|
if ($debug) { $self->print("INSERT query: $query\n") } |
|
0
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $sthi = $dbh->prepare($query); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my @rows; |
115
|
0
|
|
|
|
|
|
my $result = $attr->{'result'}; |
116
|
0
|
|
|
|
|
|
while (my $ref = $sth->fetchrow_arrayref()) { |
117
|
0
|
|
|
|
|
|
$sthi->execute(++$numRecords, @$ref); |
118
|
0
|
0
|
|
|
|
|
if ($result) { |
119
|
0
|
|
|
|
|
|
push(@rows, [$numRecords, @$ref]); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
0
|
0
|
|
|
|
|
if ($result) { |
123
|
0
|
|
|
|
|
|
$self->{$result} = \@rows; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
''; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _ep_shop_download { |
131
|
0
|
|
|
0
|
|
|
my $self = shift; my $attr = shift; |
|
0
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $cgi = $self->{'cgi'}; |
133
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
134
|
0
|
|
0
|
|
|
|
my $table = $attr->{'table'} || die "Missing table name"; |
135
|
0
|
|
0
|
|
|
|
my $removeId = $attr->{'removeid'} || 1; |
136
|
0
|
|
0
|
|
|
|
my $csv = Text::CSV_XS->new |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
137
|
|
|
|
|
|
|
({'binary' => 1, |
138
|
|
|
|
|
|
|
'eol' => "\r\n", |
139
|
|
|
|
|
|
|
'sep_char' => $attr->{'sep'} || ';', |
140
|
|
|
|
|
|
|
'escape_char' => $attr->{'escape'} || '"', |
141
|
|
|
|
|
|
|
'quote_char' => $attr->{'quote'} || $attr->{'escape'} || '"' }); |
142
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare("SELECT * FROM $table"); |
143
|
0
|
|
|
|
|
|
$sth->execute(); |
144
|
0
|
|
|
|
|
|
$self->print($cgi->header(-type => 'text/plain')); |
145
|
0
|
|
|
|
|
|
my $names = [@{$sth->{'NAME'}}]; |
|
0
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ($removeId) { |
147
|
0
|
|
|
|
|
|
shift @$names; |
148
|
|
|
|
|
|
|
} |
149
|
0
|
0
|
|
|
|
|
if ($self->{'debug'}) { |
150
|
0
|
|
|
|
|
|
$self->print("Names = ", join(", ", @$names), "\n"); |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
$csv->print($self, [@$names]); |
153
|
0
|
|
|
|
|
|
while (my $ref = $sth->fetchrow_arrayref()) { |
154
|
0
|
0
|
|
|
|
|
if ($removeId) { |
155
|
0
|
|
|
|
|
|
my @row = @$ref; |
156
|
0
|
|
|
|
|
|
shift @row; |
157
|
0
|
|
|
|
|
|
$ref = \@row; |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
$csv->print($self, $ref); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
$self->Stop(); |
163
|
0
|
|
|
|
|
|
''; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _ep_shop_prefs_write { |
168
|
0
|
|
|
0
|
|
|
my $self = shift; my $attr = shift; |
|
0
|
|
|
|
|
|
|
169
|
0
|
|
0
|
|
|
|
my $table = $attr->{'table'} || 'prefs'; |
170
|
0
|
|
0
|
|
|
|
my $pvar = $attr->{'var'} || 'prefs'; |
171
|
0
|
|
0
|
|
|
|
my $prefs = $self->{$pvar} || die "No prefs set in variable $pvar"; |
172
|
0
|
|
0
|
|
|
|
my $tvar = $attr->{'tvar'} || 'prefs'; |
173
|
0
|
|
0
|
|
|
|
my $dbh = $self->{'dbh'} || die "Missing database handle"; |
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
if ($self->{'debug'}) { |
176
|
0
|
|
|
|
|
|
$self->print("Saving prefs: ", join(" ", %$prefs), "\n"); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
my $uquery = "UPDATE $table SET val = ? WHERE var = " |
180
|
|
|
|
|
|
|
. $dbh->quote($tvar); |
181
|
0
|
|
|
|
|
|
my $freezed_prefs = Storable::nfreeze($prefs); |
182
|
0
|
|
|
|
|
|
eval {$dbh->do($uquery, undef, $freezed_prefs) }; |
|
0
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if ($@) { |
184
|
0
|
|
|
|
|
|
my $error = $@; |
185
|
0
|
|
|
|
|
|
my $cquery = "CREATE TABLE $table (" |
186
|
|
|
|
|
|
|
. " var VARCHAR(32) NOT NULL," |
187
|
|
|
|
|
|
|
. " val BLOB NOT NULL)"; |
188
|
0
|
0
|
|
|
|
|
if (eval { $dbh->do($cquery) }) { |
|
0
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
$cquery = "INSERT INTO $table VALUES (" . $dbh->quote($tvar) |
190
|
|
|
|
|
|
|
. ", ?)"; |
191
|
0
|
|
|
|
|
|
eval { $dbh->do($cquery, undef, $freezed_prefs) }; |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} |
193
|
0
|
0
|
|
|
|
|
if ($@) { |
194
|
0
|
|
|
|
|
|
die "While updating: Catched error\n$error\n" . |
195
|
|
|
|
|
|
|
"Update query was: $uquery\n" . |
196
|
|
|
|
|
|
|
"While inserting: Catched error\n$@\n" . |
197
|
|
|
|
|
|
|
"Insert query was: $cquery\n"; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
0
|
|
|
|
|
|
''; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub _ep_shop_prefs_read { |
204
|
0
|
|
|
0
|
|
|
my $self = shift; my $attr = shift; |
|
0
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
my $cgi = $self->{'cgi'}; |
206
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
207
|
0
|
|
0
|
|
|
|
my $table = $self->{'table'} || 'prefs'; |
208
|
0
|
|
0
|
|
|
|
my $pvar = $attr->{'var'} || 'prefs'; |
209
|
0
|
|
0
|
|
|
|
my $tvar = $attr->{'tvar'} || 'prefs'; |
210
|
0
|
|
|
|
|
|
my $prefs = $self->{$pvar}; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# Read Prefs |
213
|
0
|
0
|
|
|
|
|
if (!$prefs) { |
214
|
0
|
|
|
|
|
|
my $ref; |
215
|
0
|
|
|
|
|
|
eval { |
216
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare("SELECT val FROM prefs WHERE var = ?"); |
217
|
0
|
|
|
|
|
|
$sth->execute($tvar); |
218
|
0
|
|
|
|
|
|
$ref = $sth->fetchrow_arrayref(); |
219
|
|
|
|
|
|
|
}; |
220
|
0
|
0
|
|
|
|
|
$prefs = $ref ? Storable::thaw($ref->[0]) : {}; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
$self->{$pvar} = $prefs; |
224
|
0
|
0
|
0
|
|
|
|
if ($attr->{'write'} && defined($cgi->{'prefs_company'})) { |
225
|
|
|
|
|
|
|
# Save Prefs |
226
|
0
|
|
|
|
|
|
foreach my $var ($cgi->param()) { |
227
|
0
|
0
|
|
|
|
|
if ($var =~ /^prefs_(.*)/) { |
228
|
0
|
|
|
|
|
|
$prefs->{$1} = $cgi->param($var); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
0
|
|
|
|
|
|
$self->_ep_shop_prefs_write($attr); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
''; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
__END__ |