| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Lazy::DB::RecordSet; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1428
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
990
|
use Tie::IxHash; |
|
|
1
|
|
|
|
|
5339
|
|
|
|
1
|
|
|
|
|
32
|
|
|
6
|
1
|
|
|
1
|
|
1313
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
8838
|
|
|
|
1
|
|
|
|
|
6236
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#------------------------------------------------------------------ |
|
9
|
|
|
|
|
|
|
sub basewhere { |
|
10
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
11
|
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
return $self->{_basewhere}; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
16
|
|
|
|
|
|
|
sub checkboxes { |
|
17
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return $self->{_checkboxes}; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
23
|
|
|
|
|
|
|
sub createSelect { |
|
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $joinstring = ''; |
|
27
|
0
|
0
|
|
|
|
|
my $orderbystring = $self->orderby ? ' order by '.$self->orderby : ''; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $wherestring; |
|
30
|
|
|
|
|
|
|
my @binds; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (ref $self->where) { |
|
33
|
0
|
|
|
|
|
|
my @wherelist = @{$self->where}; |
|
|
0
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $where = shift @wherelist; |
|
35
|
0
|
|
|
|
|
|
@binds = @wherelist; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if ($self->basewhere) { |
|
38
|
0
|
0
|
|
|
|
|
$wherestring = $self->where ? ' where '.$self->basewhere. ' and '.$where : ' where '.$self->basewhere; |
|
39
|
|
|
|
|
|
|
} else { |
|
40
|
0
|
0
|
|
|
|
|
$wherestring = $self->where ? ' where '.$where : ''; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
0
|
|
|
|
|
if ($self->basewhere) { |
|
45
|
0
|
0
|
|
|
|
|
$wherestring = $self->where ? ' where '.$self->basewhere. ' and '.$self->where : ' where '.$self->basewhere; |
|
46
|
|
|
|
|
|
|
} else { |
|
47
|
0
|
0
|
|
|
|
|
$wherestring = $self->where ? ' where '.$self->where : ''; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my @fieldlist; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
foreach my $field (keys %{$self->fieldlist}) { |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
unless ($self->displayOnly($field)) { |
|
55
|
0
|
0
|
|
|
|
|
if ($self->readfunc($field)) { |
|
|
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
push @fieldlist, $self->readfunc($field); |
|
57
|
|
|
|
|
|
|
} elsif ($self->passwd($field)) { |
|
58
|
0
|
|
|
|
|
|
next; |
|
59
|
|
|
|
|
|
|
} else { |
|
60
|
0
|
|
|
|
|
|
push @fieldlist, $field; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ($self->joins) { |
|
66
|
0
|
|
|
|
|
|
foreach (@{$self->joins}) { |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$joinstring .= " " if $joinstring; |
|
68
|
0
|
|
|
|
|
|
my $type = $_->{type}; |
|
69
|
0
|
|
|
|
|
|
my $table = $_->{table}; |
|
70
|
0
|
|
|
|
|
|
my $field1 = $_->{field1}; |
|
71
|
0
|
|
|
|
|
|
my $field2 = $_->{field2}; |
|
72
|
0
|
|
|
|
|
|
my $and = $_->{and}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$joinstring .= " $type join $table on $field1 = $field2 "; |
|
75
|
0
|
0
|
|
|
|
|
$joinstring .= " and $and" if $and; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return "select ". join (', ', @fieldlist)." from ".$self->table.$joinstring.$wherestring.$orderbystring, @binds; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------------------------------------------------ |
|
83
|
|
|
|
|
|
|
sub data { |
|
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
85
|
0
|
|
|
|
|
|
return $self->{_data}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#------------------------------------------------------------------ |
|
89
|
|
|
|
|
|
|
sub db { |
|
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->{_db}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
96
|
|
|
|
|
|
|
sub delete { |
|
97
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
|
my $data = shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $table = $self->table; |
|
101
|
0
|
|
|
|
|
|
my $primarykey = $self->primarykey; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
foreach my $ID (keys %$data) { |
|
104
|
0
|
|
|
|
|
|
my $query = "delete from $table where $primarykey = ?"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $ID; |
|
|
0
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# $self->q->util->debug->edump($query.", $ID"); |
|
108
|
0
|
|
|
|
|
|
$self->db->do($query, $ID); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
114
|
|
|
|
|
|
|
sub displayOnly { |
|
115
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
116
|
0
|
|
|
|
|
|
my $field = shift; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
119
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{displayOnly}) { |
|
|
|
0
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{displayOnly}; |
|
121
|
|
|
|
|
|
|
} elsif ($self->fieldlist->{$field}->{displayonly}) { |
|
122
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{displayonly}; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} else { |
|
125
|
0
|
|
|
|
|
|
return; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
130
|
|
|
|
|
|
|
sub fieldlist { |
|
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $self->{_fieldlist}; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#------------------------------------------------------------------ |
|
137
|
|
|
|
|
|
|
sub handle { |
|
138
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
139
|
0
|
|
|
|
|
|
my $field = shift; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
142
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{handle}; |
|
143
|
|
|
|
|
|
|
} else { |
|
144
|
0
|
|
|
|
|
|
return; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
149
|
|
|
|
|
|
|
sub hidden { |
|
150
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
151
|
0
|
|
|
|
|
|
my $field = shift; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
154
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{hidden}; |
|
155
|
|
|
|
|
|
|
} else { |
|
156
|
0
|
|
|
|
|
|
return; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
161
|
|
|
|
|
|
|
sub inputMask { |
|
162
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
163
|
0
|
|
|
|
|
|
my $field = shift; |
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
166
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{inputMask}) { |
|
|
|
0
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{inputMask}; |
|
168
|
|
|
|
|
|
|
} elsif ($self->fieldlist->{$field}->{inputmask}) { |
|
169
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{inputmask}; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
} else { |
|
172
|
0
|
|
|
|
|
|
return; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
177
|
|
|
|
|
|
|
sub insert { |
|
178
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
179
|
0
|
|
|
|
|
|
my $data = shift; |
|
180
|
0
|
|
|
|
|
|
my $vars = shift; |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $table = $self->table; |
|
183
|
0
|
|
|
|
|
|
my $primarykey = $self->primarykey; |
|
184
|
0
|
|
|
|
|
|
my $defaults = $self->insertdefaults; |
|
185
|
0
|
|
|
|
|
|
my $additional = $self->insertadditional; |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
foreach my $row (keys %$data) { |
|
188
|
0
|
|
|
|
|
|
my @fieldlist; |
|
189
|
|
|
|
|
|
|
my @binds; |
|
190
|
0
|
|
|
|
|
|
my @bindvalues; |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
if (%$vars) { |
|
193
|
0
|
|
|
|
|
|
foreach (keys %$vars) { |
|
194
|
0
|
0
|
|
|
|
|
if ($vars->{$_}->{value}) { |
|
195
|
0
|
0
|
|
|
|
|
$data->{$row}->{$_} = ref $vars->{$_}->{value} ? ${$vars->{$_}->{value}} : $vars->{$_}->{value}; |
|
|
0
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# $self->q->util->debug->edump("var: ".$vars->{$_}->{value}." -- ".${$vars->{$_}->{value}}); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
if ($defaults) { |
|
202
|
0
|
|
|
|
|
|
foreach my $field (keys %$defaults) { |
|
203
|
0
|
0
|
|
|
|
|
if ($defaults->{$field}->{value}) { #static quanities |
|
204
|
0
|
|
|
|
|
|
$data->{$row}->{$field} = $defaults->{$field}->{value}; |
|
205
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
206
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $defaults->{$field}->{value}; |
|
|
0
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} else { #values pulled from queries and such |
|
209
|
0
|
|
|
|
|
|
my $result = $self->db->getarray(@{$defaults->{$field}->{sql}}); |
|
|
0
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
0
|
0
|
0
|
|
|
|
if (defined $result->[1] || defined $result->[0]->[1]) { #we got more than a single value, better warn |
|
212
|
0
|
|
|
|
|
|
$self->q->errorHandler->dbReturnedMoreThanSingleValue; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $value = $result->[0]->[0]; |
|
216
|
0
|
|
|
|
|
|
$data->{$row}->{$field} = $value; |
|
217
|
|
|
|
|
|
|
|
|
218
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
219
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $value; |
|
|
0
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{primarykey}) { |
|
223
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $value; |
|
|
0
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
foreach (keys %{$data->{$row}}) { |
|
|
0
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $field = $self->verify($_); |
|
231
|
0
|
0
|
|
|
|
|
if ($field) { |
|
232
|
0
|
0
|
0
|
|
|
|
unless ($self->displayOnly($field) || $self->readOnly($field)) { |
|
233
|
0
|
|
|
|
|
|
push @fieldlist, $field; |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
my $value; |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
|
238
|
0
|
0
|
|
|
|
|
if ($self->inputMask($field)) { |
|
|
|
0
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
$value = sprintf $self->inputMask($field), $data->{$row}->{$field}; |
|
240
|
|
|
|
|
|
|
} elsif ($self->passwd($field)){ |
|
241
|
0
|
0
|
|
|
|
|
if ($self->q->authn) { |
|
242
|
0
|
|
|
|
|
|
$value = $self->q->authn->passwdhash($data->{$row}->{$self->passwd($field)->{userField}}, $data->{$row}->{$field}); |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} else { |
|
245
|
0
|
|
|
|
|
|
$value = $data->{$row}->{$field}; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
|
|
248
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
249
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $value; |
|
|
0
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
0
|
0
|
|
|
|
|
if ($field eq $self->primarykey) { |
|
253
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $value; |
|
|
0
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
push @bindvalues, $value; |
|
258
|
|
|
|
|
|
|
|
|
259
|
0
|
0
|
|
|
|
|
if ($self->writefunc($field) ) { |
|
260
|
0
|
|
|
|
|
|
push @binds, $self->fieldlist->{$field}->{writefunc}; |
|
261
|
|
|
|
|
|
|
} else { |
|
262
|
0
|
|
|
|
|
|
push @binds, "?"; |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
my $insertclause = join ', ', @fieldlist; |
|
270
|
0
|
|
|
|
|
|
my $binds = join ', ', @binds; |
|
271
|
0
|
|
|
|
|
|
my $query = "insert into $table ($insertclause) values ($binds)"; |
|
272
|
|
|
|
|
|
|
# $self->q->util->debug->edump($query."\n".join ',', @bindvalues); |
|
273
|
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
$self->db->do($query, @bindvalues); |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
0
|
|
|
|
|
if ($self->mysqlAuto) { |
|
277
|
0
|
|
|
|
|
|
my $query = 'select LAST_INSERT_ID()'; |
|
278
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $self->db->get($query); |
|
|
0
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
0
|
|
|
|
|
if ($additional) { #addional queries run on insert |
|
283
|
0
|
|
|
|
|
|
foreach my $field (keys %$additional) { |
|
284
|
0
|
|
|
|
|
|
my $result = $self->db->getarray($additional->{$field}->{sql}); |
|
285
|
|
|
|
|
|
|
|
|
286
|
0
|
0
|
0
|
|
|
|
if (defined $result->[1] || defined $result->[0]->[1]) { #we got more than a single value, better warn |
|
287
|
0
|
|
|
|
|
|
$self->q->errorHandler->dbReturnedMoreThanSingleValue; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
my $value = $result->[0]->[0]; |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
0
|
|
|
|
|
if ($additional->{$field}->{handle}) { |
|
293
|
0
|
|
|
|
|
|
${$additional->{$field}->{handle}} = $value ; |
|
|
0
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
} |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
} |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
301
|
|
|
|
|
|
|
sub insertadditional { |
|
302
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
303
|
|
|
|
|
|
|
|
|
304
|
0
|
|
|
|
|
|
return $self->{_insertadditional}; |
|
305
|
|
|
|
|
|
|
} |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
308
|
|
|
|
|
|
|
sub insertdefaults { |
|
309
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
310
|
|
|
|
|
|
|
|
|
311
|
0
|
|
|
|
|
|
return $self->{_insertdefaults}; |
|
312
|
|
|
|
|
|
|
} |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
315
|
|
|
|
|
|
|
sub joins { |
|
316
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
317
|
|
|
|
|
|
|
|
|
318
|
0
|
0
|
|
|
|
|
return wantarray ? @{$self->{_joins}} : $self->{_joins}; |
|
|
0
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
322
|
|
|
|
|
|
|
sub label { |
|
323
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
324
|
0
|
|
|
|
|
|
my $field = shift; |
|
325
|
|
|
|
|
|
|
|
|
326
|
0
|
0
|
|
|
|
|
return $self->fieldlist->{$field}->{label} ? $self->fieldlist->{$field}->{label} : $self->fieldlist->{$field}->{name}; |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
330
|
|
|
|
|
|
|
sub new { |
|
331
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
332
|
0
|
|
|
|
|
|
my $db = shift; |
|
333
|
0
|
|
|
|
|
|
my $args = shift; |
|
334
|
|
|
|
|
|
|
|
|
335
|
0
|
|
|
|
|
|
my $var = undef; |
|
336
|
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
|
my $self = { |
|
338
|
|
|
|
|
|
|
_data => [], |
|
339
|
|
|
|
|
|
|
_db => $db, |
|
340
|
|
|
|
|
|
|
_table => $args->{table}, |
|
341
|
|
|
|
|
|
|
_basewhere => $args->{basewhere}, |
|
342
|
|
|
|
|
|
|
_primarykey => $args->{primarykey}, |
|
343
|
|
|
|
|
|
|
_orderby => $args->{orderby}, |
|
344
|
|
|
|
|
|
|
_joins => $args->{joins}, |
|
345
|
|
|
|
|
|
|
_insertdefaults => $args->{insertdefaults}, |
|
346
|
|
|
|
|
|
|
_insertadditional => $args->{insertadditional}, |
|
347
|
|
|
|
|
|
|
_updatedefaults => $args->{updatedefaults}, |
|
348
|
|
|
|
|
|
|
_updateadditional => $args->{updateadditional}, |
|
349
|
|
|
|
|
|
|
_where => '', |
|
350
|
|
|
|
|
|
|
_mysqlAuto => $args->{mysqlAuto}, |
|
351
|
|
|
|
|
|
|
_primarykeyhandle => \$var, |
|
352
|
|
|
|
|
|
|
_checkboxes => [], |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
}; |
|
355
|
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
|
$self->{_fieldlist} = {}; |
|
357
|
0
|
|
|
|
|
|
tie (%{$self->{_fieldlist}}, 'Tie::IxHash'); |
|
|
0
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
|
|
359
|
0
|
|
|
|
|
|
foreach (@{$args->{fieldlist}}) { |
|
|
0
|
|
|
|
|
|
|
|
360
|
0
|
|
|
|
|
|
$self->{_fieldlist}{$_->{name}} = $_; |
|
361
|
0
|
0
|
0
|
|
|
|
if ($_->{webcontrol} && ($_->{webcontrol}->{type} eq 'checkbox')) { |
|
362
|
0
|
|
|
|
|
|
push @{$self->{_checkboxes}}, $_->{name}; |
|
|
0
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
} |
|
364
|
|
|
|
|
|
|
} |
|
365
|
|
|
|
|
|
|
|
|
366
|
0
|
|
|
|
|
|
return bless $self, $class; |
|
367
|
|
|
|
|
|
|
} |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
370
|
|
|
|
|
|
|
sub noLabel { |
|
371
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
372
|
0
|
|
|
|
|
|
my $field = shift; |
|
373
|
|
|
|
|
|
|
|
|
374
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
375
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{noLabel}; |
|
376
|
|
|
|
|
|
|
} else { |
|
377
|
0
|
|
|
|
|
|
return; |
|
378
|
|
|
|
|
|
|
} |
|
379
|
|
|
|
|
|
|
} |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
382
|
|
|
|
|
|
|
sub orderby { |
|
383
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
384
|
0
|
|
|
|
|
|
my $value = shift; |
|
385
|
|
|
|
|
|
|
|
|
386
|
0
|
0
|
|
|
|
|
if ($value) { |
|
387
|
0
|
|
|
|
|
|
return $self->{_orderby} = $value; |
|
388
|
|
|
|
|
|
|
} else { |
|
389
|
0
|
|
|
|
|
|
return $self->{_orderby}; |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
394
|
|
|
|
|
|
|
sub outputMask { |
|
395
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
396
|
0
|
|
|
|
|
|
my $field = shift; |
|
397
|
|
|
|
|
|
|
|
|
398
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
399
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{outputMask}) { |
|
|
|
0
|
|
|
|
|
|
|
400
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{outputMask}; |
|
401
|
|
|
|
|
|
|
} elsif ($self->fieldlist->{$field}->{outputmask}) { |
|
402
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{outputmask}; |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
} else { |
|
405
|
0
|
|
|
|
|
|
return; |
|
406
|
|
|
|
|
|
|
} |
|
407
|
|
|
|
|
|
|
} |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
410
|
|
|
|
|
|
|
sub multipleField { |
|
411
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
412
|
0
|
|
|
|
|
|
my $field = shift; |
|
413
|
|
|
|
|
|
|
|
|
414
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
415
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{multi}; |
|
416
|
|
|
|
|
|
|
} else { |
|
417
|
0
|
|
|
|
|
|
return; |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
} |
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
|
422
|
|
|
|
|
|
|
sub multipleFieldList { |
|
423
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
424
|
|
|
|
|
|
|
|
|
425
|
0
|
|
|
|
|
|
my @multipleFieldList; |
|
426
|
0
|
|
|
|
|
|
foreach my $field (keys %{$self->{_fieldlist}}) { |
|
|
0
|
|
|
|
|
|
|
|
427
|
0
|
0
|
|
|
|
|
if ($self->multipleField($field)) { |
|
428
|
0
|
|
|
|
|
|
push @multipleFieldList, $self->fieldlist->{$field}->{name}; |
|
429
|
|
|
|
|
|
|
} |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
|
|
432
|
0
|
0
|
|
|
|
|
return wantarray ? @multipleFieldList : \@multipleFieldList; |
|
433
|
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
437
|
|
|
|
|
|
|
sub multipleFieldLabels { |
|
438
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
439
|
|
|
|
|
|
|
|
|
440
|
0
|
|
|
|
|
|
my @multipleFieldLabels; |
|
441
|
0
|
|
|
|
|
|
foreach my $field (keys %{$self->{_fieldlist}}) { |
|
|
0
|
|
|
|
|
|
|
|
442
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{multi}) { |
|
443
|
0
|
0
|
|
|
|
|
push @multipleFieldLabels, $self->fieldlist->{$field}->{label} ? $self->fieldlist->{$field}->{label} : $self->fieldlist->{$field}->{name}; |
|
444
|
|
|
|
|
|
|
} |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
447
|
0
|
0
|
|
|
|
|
return wantarray ? @multipleFieldLabels : \@multipleFieldLabels; |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
452
|
|
|
|
|
|
|
sub mysqlAuto { |
|
453
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
454
|
|
|
|
|
|
|
|
|
455
|
0
|
|
|
|
|
|
return $self->{_mysqlAuto}; |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
} |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
460
|
|
|
|
|
|
|
sub passwd { |
|
461
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
462
|
0
|
|
|
|
|
|
my $field = shift; |
|
463
|
|
|
|
|
|
|
|
|
464
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
465
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{passwd}) { |
|
466
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{passwd}; |
|
467
|
|
|
|
|
|
|
} else { |
|
468
|
0
|
|
|
|
|
|
return; |
|
469
|
|
|
|
|
|
|
} |
|
470
|
|
|
|
|
|
|
} else { |
|
471
|
0
|
|
|
|
|
|
return; |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
476
|
|
|
|
|
|
|
sub primarykey { |
|
477
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
478
|
0
|
|
|
|
|
|
my $value = shift; |
|
479
|
|
|
|
|
|
|
|
|
480
|
0
|
0
|
|
|
|
|
if ($value) { |
|
481
|
0
|
|
|
|
|
|
return $self->{_primarykey} = $value; |
|
482
|
|
|
|
|
|
|
} else { |
|
483
|
0
|
|
|
|
|
|
return $self->{_primarykey}; |
|
484
|
|
|
|
|
|
|
} |
|
485
|
|
|
|
|
|
|
} |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
488
|
|
|
|
|
|
|
sub primarykeyhandle { |
|
489
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
490
|
|
|
|
|
|
|
|
|
491
|
0
|
|
|
|
|
|
return $self->{_primarykeyhandle}; |
|
492
|
|
|
|
|
|
|
} |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
#------------------------------------------------------------------ |
|
495
|
|
|
|
|
|
|
sub q { |
|
496
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
497
|
|
|
|
|
|
|
|
|
498
|
0
|
|
|
|
|
|
return $self->db->q; |
|
499
|
|
|
|
|
|
|
} |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
502
|
|
|
|
|
|
|
sub readfunc { |
|
503
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
504
|
0
|
|
|
|
|
|
my $field = shift; |
|
505
|
|
|
|
|
|
|
|
|
506
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
507
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{readfunc}; |
|
508
|
|
|
|
|
|
|
} else { |
|
509
|
0
|
|
|
|
|
|
return; |
|
510
|
|
|
|
|
|
|
} |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
514
|
|
|
|
|
|
|
sub readOnly { |
|
515
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
516
|
0
|
|
|
|
|
|
my $field = shift; |
|
517
|
|
|
|
|
|
|
|
|
518
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
519
|
0
|
0
|
|
|
|
|
if ($self->fieldlist->{$field}->{readOnly}) { |
|
|
|
0
|
|
|
|
|
|
|
520
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{readOnly}; |
|
521
|
|
|
|
|
|
|
} elsif ($self->fieldlist->{$field}->{readonly}) { |
|
522
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{readonly}; |
|
523
|
|
|
|
|
|
|
} |
|
524
|
|
|
|
|
|
|
} else { |
|
525
|
0
|
|
|
|
|
|
return; |
|
526
|
|
|
|
|
|
|
} |
|
527
|
|
|
|
|
|
|
} |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
|
530
|
|
|
|
|
|
|
sub select { |
|
531
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
532
|
0
|
|
|
|
|
|
my @bindvars = @_; |
|
533
|
|
|
|
|
|
|
|
|
534
|
0
|
|
|
|
|
|
my ($query, @wherebinds) = $self->createSelect; |
|
535
|
|
|
|
|
|
|
|
|
536
|
0
|
0
|
|
|
|
|
if (@wherebinds) { |
|
537
|
0
|
|
|
|
|
|
unshift @bindvars, $_ for @wherebinds; |
|
538
|
|
|
|
|
|
|
} |
|
539
|
|
|
|
|
|
|
|
|
540
|
0
|
|
|
|
|
|
my @data; |
|
541
|
|
|
|
|
|
|
my $sth; |
|
542
|
|
|
|
|
|
|
|
|
543
|
0
|
|
|
|
|
|
my ($pkg, $file, $line) = caller; |
|
544
|
|
|
|
|
|
|
|
|
545
|
0
|
|
|
|
|
|
eval { |
|
546
|
0
|
|
|
|
|
|
$sth = $self->db->dbh->prepare($query); |
|
547
|
0
|
|
|
|
|
|
$sth->execute(@bindvars); |
|
548
|
|
|
|
|
|
|
# $self->q->util->debug->edump($query, @bindvars); |
|
549
|
|
|
|
|
|
|
}; |
|
550
|
|
|
|
|
|
|
|
|
551
|
0
|
0
|
|
|
|
|
if ($@) { |
|
552
|
0
|
|
|
|
|
|
$self->q->errorHandler->dbError($pkg, $file, $line, $query); |
|
553
|
|
|
|
|
|
|
} else { |
|
554
|
|
|
|
|
|
|
|
|
555
|
0
|
|
|
|
|
|
while (my @record = $sth->fetchrow_array) { |
|
556
|
0
|
|
|
|
|
|
my @fieldlist = keys %{$self->fieldlist}; |
|
|
0
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
|
|
558
|
0
|
|
|
|
|
|
my $record = {}; |
|
559
|
0
|
|
|
|
|
|
tie (%$record, 'Tie::IxHash'); |
|
560
|
|
|
|
|
|
|
|
|
561
|
0
|
|
|
|
|
|
for (0..$#fieldlist) { |
|
562
|
0
|
0
|
|
|
|
|
next if $self->passwd($fieldlist[$_]); |
|
563
|
0
|
|
|
|
|
|
$record->{$fieldlist[$_]} = $record[$_]; |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
|
|
566
|
0
|
|
|
|
|
|
push @data, $record; |
|
567
|
|
|
|
|
|
|
} |
|
568
|
|
|
|
|
|
|
} |
|
569
|
|
|
|
|
|
|
|
|
570
|
0
|
|
|
|
|
|
$self->{_data} = \@data; |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
#$self->q->util->debug->edump(\@data); |
|
573
|
0
|
|
|
|
|
|
return $self->{_data}; |
|
574
|
|
|
|
|
|
|
} |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
577
|
|
|
|
|
|
|
sub table { |
|
578
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
579
|
0
|
|
|
|
|
|
my $value = shift; |
|
580
|
|
|
|
|
|
|
|
|
581
|
0
|
0
|
|
|
|
|
if ($value) { |
|
582
|
0
|
|
|
|
|
|
return $self->{_table} = $value; |
|
583
|
|
|
|
|
|
|
} else { |
|
584
|
0
|
|
|
|
|
|
return $self->{_table}; |
|
585
|
|
|
|
|
|
|
} |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
589
|
|
|
|
|
|
|
sub update { |
|
590
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
591
|
0
|
|
|
|
|
|
my $data = shift; |
|
592
|
0
|
|
|
|
|
|
my $vars = shift; |
|
593
|
|
|
|
|
|
|
|
|
594
|
0
|
|
|
|
|
|
my $table = $self->table; |
|
595
|
0
|
|
|
|
|
|
my $primarykey = $self->primarykey; |
|
596
|
0
|
|
|
|
|
|
my $defaults = $self->updatedefaults; |
|
597
|
0
|
|
|
|
|
|
my $additional = $self->updateadditional; |
|
598
|
|
|
|
|
|
|
|
|
599
|
0
|
|
|
|
|
|
foreach my $ID (keys %$data) { |
|
600
|
0
|
|
|
|
|
|
my @updates; |
|
601
|
|
|
|
|
|
|
my @binds; |
|
602
|
|
|
|
|
|
|
|
|
603
|
0
|
0
|
|
|
|
|
if (%$vars) { |
|
604
|
0
|
|
|
|
|
|
foreach (keys %$vars) { |
|
605
|
0
|
0
|
|
|
|
|
if ($vars->{$_}->{value}) { |
|
606
|
0
|
0
|
|
|
|
|
$data->{$ID}->{$_} = ref $vars->{$_}->{value} ? ${$vars->{$_}->{value}} : $vars->{$_}->{value}; |
|
|
0
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
# $self->q->util->debug->edump("var: ".$vars->{$_}->{value}." -- ".${$vars->{$_}->{value}}); |
|
608
|
|
|
|
|
|
|
} |
|
609
|
|
|
|
|
|
|
} |
|
610
|
|
|
|
|
|
|
} |
|
611
|
|
|
|
|
|
|
|
|
612
|
0
|
0
|
|
|
|
|
if ($defaults) { |
|
613
|
0
|
|
|
|
|
|
foreach my $field (keys %$defaults) { |
|
614
|
0
|
0
|
|
|
|
|
if ($defaults->{$field}->{value}) { #static quanities |
|
615
|
0
|
|
|
|
|
|
$data->{$ID}->{$field} = $defaults->{$field}->{value}; |
|
616
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
617
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $defaults->{$field}->{value}; |
|
|
0
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
} |
|
619
|
|
|
|
|
|
|
} else { #values pulled from queries and such |
|
620
|
0
|
|
|
|
|
|
my $result = $self->db->getarray(@{$defaults->{$field}->{sql}}); |
|
|
0
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
|
|
622
|
0
|
0
|
0
|
|
|
|
if (defined $result->[1] || defined $result->[0]->[1]) { #we got more than a single value, better warn |
|
623
|
0
|
|
|
|
|
|
$self->q->errorHandler->dbReturnedMoreThanSingleValue; |
|
624
|
|
|
|
|
|
|
} |
|
625
|
|
|
|
|
|
|
|
|
626
|
0
|
|
|
|
|
|
my $value = $result->[0]->[0]; |
|
627
|
0
|
|
|
|
|
|
$data->{$ID}->{$field} = $value; |
|
628
|
|
|
|
|
|
|
|
|
629
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
630
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $value; |
|
|
0
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
} |
|
632
|
|
|
|
|
|
|
} |
|
633
|
|
|
|
|
|
|
} |
|
634
|
|
|
|
|
|
|
} |
|
635
|
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
|
|
637
|
0
|
|
|
|
|
|
foreach (keys %{$data->{$ID}}) { |
|
|
0
|
|
|
|
|
|
|
|
638
|
0
|
|
|
|
|
|
my $field = $self->verify($_); |
|
639
|
|
|
|
|
|
|
|
|
640
|
0
|
0
|
|
|
|
|
if ($field) { |
|
641
|
0
|
0
|
0
|
|
|
|
unless ($self->displayOnly($field) || $self->readOnly($field)) { |
|
642
|
0
|
0
|
|
|
|
|
if ($vars->{$field}->{handle}) { |
|
643
|
0
|
|
|
|
|
|
${$vars->{$field}->{handle}} = $data->{$ID}->{$field}; |
|
|
0
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
} |
|
646
|
|
|
|
|
|
|
|
|
647
|
0
|
0
|
|
|
|
|
if ($field eq $self->primarykey) { |
|
648
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $data->{$ID}->{$field}; |
|
|
0
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
} |
|
651
|
|
|
|
|
|
|
|
|
652
|
0
|
0
|
|
|
|
|
if ($self->inputMask($field)) { |
|
|
|
0
|
|
|
|
|
|
|
653
|
0
|
|
|
|
|
|
push @binds, sprintf $self->inputMask($field), $data->{$ID}->{$field}; |
|
654
|
|
|
|
|
|
|
} elsif ($self->passwd($field)){ |
|
655
|
0
|
0
|
|
|
|
|
if ($data->{$ID}->{$field}) { |
|
656
|
0
|
0
|
|
|
|
|
if ($self->q->authn) { |
|
657
|
0
|
|
|
|
|
|
push @binds, $self->q->authn->passwdhash($data->{$ID}->{$self->passwd($field)->{userField}}, $data->{$ID}->{$field}); |
|
658
|
|
|
|
|
|
|
} |
|
659
|
|
|
|
|
|
|
} |
|
660
|
|
|
|
|
|
|
} else { |
|
661
|
0
|
|
|
|
|
|
push @binds, $data->{$ID}->{$field}; |
|
662
|
|
|
|
|
|
|
} |
|
663
|
|
|
|
|
|
|
|
|
664
|
0
|
0
|
|
|
|
|
if ($self->writefunc($field) ) { |
|
|
|
0
|
|
|
|
|
|
|
665
|
0
|
|
|
|
|
|
push @updates, "$field = ".$self->fieldlist->{$field}->{writefunc}; |
|
666
|
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
} elsif ($self->passwd($field)) { |
|
668
|
0
|
0
|
|
|
|
|
if ($self->q->authn) { |
|
669
|
0
|
0
|
|
|
|
|
if ($data->{$ID}->{$field}) { |
|
670
|
0
|
|
|
|
|
|
push @updates, "$field = ?"; |
|
671
|
|
|
|
|
|
|
} |
|
672
|
|
|
|
|
|
|
} |
|
673
|
|
|
|
|
|
|
} else { |
|
674
|
0
|
|
|
|
|
|
push @updates, "$field = ?"; |
|
675
|
|
|
|
|
|
|
} |
|
676
|
|
|
|
|
|
|
} |
|
677
|
|
|
|
|
|
|
} |
|
678
|
|
|
|
|
|
|
} |
|
679
|
|
|
|
|
|
|
|
|
680
|
0
|
0
|
|
|
|
|
if (@{$self->checkboxes}) { |
|
|
0
|
|
|
|
|
|
|
|
681
|
0
|
|
|
|
|
|
foreach (@{$self->checkboxes}) { |
|
|
0
|
|
|
|
|
|
|
|
682
|
0
|
0
|
|
|
|
|
next if exists $data->{$ID}->{$_}; |
|
683
|
|
|
|
|
|
|
|
|
684
|
0
|
0
|
|
|
|
|
if ($vars->{$_}->{handle}) { |
|
685
|
0
|
|
|
|
|
|
${$vars->{$_}->{handle}} = ''; |
|
|
0
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
} |
|
687
|
|
|
|
|
|
|
|
|
688
|
0
|
|
|
|
|
|
push @updates, "$_ = ?"; |
|
689
|
0
|
|
|
|
|
|
push @binds, ''; |
|
690
|
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
} |
|
692
|
|
|
|
|
|
|
} |
|
693
|
|
|
|
|
|
|
|
|
694
|
0
|
|
|
|
|
|
my $updateclause = join ',', @updates; |
|
695
|
|
|
|
|
|
|
|
|
696
|
0
|
|
|
|
|
|
my $query = "update $table set $updateclause where $primarykey = ?"; |
|
697
|
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
# $self->q->util->debug->edump($query, join ',', @binds. " key: $ID"); |
|
699
|
|
|
|
|
|
|
|
|
700
|
0
|
|
|
|
|
|
$self->db->do($query, @binds, $ID); |
|
701
|
|
|
|
|
|
|
|
|
702
|
0
|
|
|
|
|
|
${$self->primarykeyhandle} = $ID; |
|
|
0
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
|
|
704
|
0
|
0
|
|
|
|
|
if ($additional) { #addional queries run on insert |
|
705
|
0
|
|
|
|
|
|
foreach my $field (keys %$additional) { |
|
706
|
0
|
|
|
|
|
|
my $result = $self->db->getarray($additional->{$field}->{sql}); |
|
707
|
|
|
|
|
|
|
|
|
708
|
0
|
0
|
0
|
|
|
|
if (defined $result->[1] || defined $result->[0]->[1]) { #we got more than a single value, better warn |
|
709
|
0
|
|
|
|
|
|
$self->q->errorHandler->dbReturnedMoreThanSingleValue; |
|
710
|
|
|
|
|
|
|
} |
|
711
|
|
|
|
|
|
|
|
|
712
|
0
|
|
|
|
|
|
my $value = $result->[0]->[0]; |
|
713
|
|
|
|
|
|
|
|
|
714
|
0
|
0
|
|
|
|
|
if ($additional->{$field}->{handle}) { |
|
715
|
0
|
|
|
|
|
|
${$additional->{$field}->{handle}} = $value ; |
|
|
0
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
} |
|
717
|
|
|
|
|
|
|
} |
|
718
|
|
|
|
|
|
|
} |
|
719
|
|
|
|
|
|
|
} |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
} |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
725
|
|
|
|
|
|
|
sub updateadditional { |
|
726
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
727
|
|
|
|
|
|
|
|
|
728
|
0
|
|
|
|
|
|
return $self->{_updateadditional}; |
|
729
|
|
|
|
|
|
|
} |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
732
|
|
|
|
|
|
|
sub updatedefaults { |
|
733
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
734
|
|
|
|
|
|
|
|
|
735
|
0
|
|
|
|
|
|
return $self->{_updatedefaults}; |
|
736
|
|
|
|
|
|
|
} |
|
737
|
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
739
|
|
|
|
|
|
|
sub validator { |
|
740
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
741
|
0
|
|
|
|
|
|
my $field = shift; |
|
742
|
|
|
|
|
|
|
|
|
743
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
744
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{validator}; |
|
745
|
|
|
|
|
|
|
} else { |
|
746
|
0
|
|
|
|
|
|
return; |
|
747
|
|
|
|
|
|
|
} |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
} |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
|
752
|
|
|
|
|
|
|
sub verify { |
|
753
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
754
|
0
|
|
|
|
|
|
my $value = shift; |
|
755
|
|
|
|
|
|
|
|
|
756
|
0
|
|
|
|
|
|
$value =~ /^([\w\d\-\.]+)$/; #letters, numbers, underscores, dots, and dashes only please. |
|
757
|
0
|
|
|
|
|
|
my $field = $1; |
|
758
|
|
|
|
|
|
|
|
|
759
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { #fieldname has to be in recordset |
|
760
|
0
|
0
|
|
|
|
|
if ($field =~ /\./) { #if there's a . in the fieldname |
|
761
|
0
|
|
|
|
|
|
my $table = $self->table; |
|
762
|
0
|
0
|
|
|
|
|
if ($field =~ /^$table/) { #the first part has to be the recordset's table |
|
763
|
0
|
|
|
|
|
|
return $field; |
|
764
|
|
|
|
|
|
|
} else { # its a joined field, no modification allowed |
|
765
|
0
|
|
|
|
|
|
return; |
|
766
|
|
|
|
|
|
|
} |
|
767
|
|
|
|
|
|
|
} |
|
768
|
0
|
|
|
|
|
|
return $field; |
|
769
|
|
|
|
|
|
|
} |
|
770
|
|
|
|
|
|
|
|
|
771
|
0
|
|
|
|
|
|
return; |
|
772
|
|
|
|
|
|
|
} |
|
773
|
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
775
|
|
|
|
|
|
|
sub visibleFieldLabels { |
|
776
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
777
|
|
|
|
|
|
|
|
|
778
|
0
|
|
|
|
|
|
my @visibleFieldLabels; |
|
779
|
0
|
|
|
|
|
|
foreach my $field (keys %{$self->{_fieldlist}}) { |
|
|
0
|
|
|
|
|
|
|
|
780
|
0
|
0
|
|
|
|
|
unless ($self->fieldlist->{$field}->{hidden}) { |
|
781
|
0
|
0
|
|
|
|
|
push @visibleFieldLabels, $self->fieldlist->{$field}->{label} ? $self->fieldlist->{$field}->{label} : $self->fieldlist->{$field}->{name}; |
|
782
|
|
|
|
|
|
|
} |
|
783
|
|
|
|
|
|
|
} |
|
784
|
|
|
|
|
|
|
|
|
785
|
0
|
0
|
|
|
|
|
return wantarray ? @visibleFieldLabels : \@visibleFieldLabels; |
|
786
|
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
} |
|
788
|
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
790
|
|
|
|
|
|
|
sub visibleFields { |
|
791
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
792
|
|
|
|
|
|
|
|
|
793
|
0
|
|
|
|
|
|
my @visibleFieldList; |
|
794
|
0
|
|
|
|
|
|
foreach my $field (keys %{$self->{_fieldlist}}) { |
|
|
0
|
|
|
|
|
|
|
|
795
|
0
|
0
|
|
|
|
|
unless ($self->fieldlist->{$field}->{hidden}) { |
|
796
|
0
|
|
|
|
|
|
push @visibleFieldList, $self->fieldlist->{$field}->{name}; |
|
797
|
|
|
|
|
|
|
} |
|
798
|
|
|
|
|
|
|
} |
|
799
|
|
|
|
|
|
|
|
|
800
|
0
|
0
|
|
|
|
|
return wantarray ? @visibleFieldList : \@visibleFieldList; |
|
801
|
|
|
|
|
|
|
} |
|
802
|
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
804
|
|
|
|
|
|
|
sub webcontrol { |
|
805
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
806
|
0
|
|
|
|
|
|
my $field = shift; |
|
807
|
|
|
|
|
|
|
|
|
808
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
809
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{webcontrol}; |
|
810
|
|
|
|
|
|
|
} else { |
|
811
|
0
|
|
|
|
|
|
return; |
|
812
|
|
|
|
|
|
|
} |
|
813
|
|
|
|
|
|
|
} |
|
814
|
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
816
|
|
|
|
|
|
|
sub where { |
|
817
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
818
|
0
|
|
|
|
|
|
my @values = @_; |
|
819
|
|
|
|
|
|
|
|
|
820
|
0
|
0
|
|
|
|
|
if (@values) { |
|
821
|
0
|
0
|
|
|
|
|
if (scalar @values > 1) { |
|
822
|
0
|
|
|
|
|
|
return $self->{_where} = \@values; #theres a list, store an arrayref |
|
823
|
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
} else { |
|
825
|
0
|
|
|
|
|
|
return $self->{_where} = $values[0]; #where is a single string, store a scalar |
|
826
|
|
|
|
|
|
|
} |
|
827
|
|
|
|
|
|
|
} else { |
|
828
|
0
|
|
|
|
|
|
return $self->{_where}; |
|
829
|
|
|
|
|
|
|
} |
|
830
|
|
|
|
|
|
|
} |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
833
|
|
|
|
|
|
|
sub writefunc { |
|
834
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
835
|
0
|
|
|
|
|
|
my $field = shift; |
|
836
|
|
|
|
|
|
|
|
|
837
|
0
|
0
|
|
|
|
|
if (exists $self->fieldlist->{$field}) { |
|
838
|
0
|
|
|
|
|
|
return $self->fieldlist->{$field}->{writefunc}; |
|
839
|
|
|
|
|
|
|
} else { |
|
840
|
0
|
|
|
|
|
|
return; |
|
841
|
|
|
|
|
|
|
} |
|
842
|
|
|
|
|
|
|
} |
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
1; |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
__END__ |