line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::Widget; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1598
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
147
|
use Tie::IxHash; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
7
|
1
|
|
|
1
|
|
6
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
108
|
|
8
|
1
|
|
|
1
|
|
755
|
use CGI::Lazy::Widget::Dataset; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
646
|
use CGI::Lazy::Widget::DomLoader; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
618
|
use CGI::Lazy::Widget::Composite; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
11
|
1
|
|
|
1
|
|
626
|
use CGI::Lazy::Widget::Controller; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3852
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
sub ajaxBlank { |
15
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
16
|
0
|
|
|
|
|
0
|
my %args = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
$args{mode} = 'blank'; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
return $self->rawContents(%args); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub ajaxReturn { |
25
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $widgets = shift; |
27
|
0
|
|
|
|
|
0
|
my $data = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
0
|
my @widgetlist = ref $widgets eq 'ARRAY' ? @$widgets : ($widgets); |
30
|
0
|
0
|
|
|
|
0
|
my @datalist = ref $data eq 'ARRAY' ? @$data : ($data); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my $outgoingdata; |
33
|
0
|
|
|
|
|
0
|
$outgoingdata .= $_ for @datalist; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $validator = {}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
$validator->{$_->widgetID} = $_->validator for @widgetlist; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
my $json = to_json($validator); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
return '{"validator" : '.$json.', "html" : "'.$outgoingdata .'"}'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
sub ajaxSelect { |
47
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
48
|
0
|
|
|
|
|
0
|
my %args = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
my $output = $self->select(%args); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return $self->ajaxReturn($self, $output); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
56
|
|
|
|
|
|
|
sub composite { |
57
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
58
|
0
|
|
|
|
|
0
|
my $vars = shift; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
return CGI::Lazy::Widget::Composite->new($self->q, $vars); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
64
|
|
|
|
|
|
|
sub config { |
65
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
return $self->q->config; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
71
|
|
|
|
|
|
|
sub controller { |
72
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
73
|
0
|
|
|
|
|
0
|
my $vars = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return CGI::Lazy::Widget::Controller->new($self->q, $vars); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
79
|
|
|
|
|
|
|
sub dataset { |
80
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
81
|
0
|
|
|
|
|
0
|
my $vars = shift; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
return CGI::Lazy::Widget::Dataset->new($self->q, $vars); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
87
|
|
|
|
|
|
|
sub db { |
88
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return $self->q->db; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
94
|
|
|
|
|
|
|
sub dbwrite { |
95
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
96
|
0
|
|
|
|
|
0
|
my %args = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
0
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
99
|
0
|
|
|
|
|
0
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
0
|
|
100
|
0
|
|
|
|
|
0
|
$_->dbwrite; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
0
|
my %deleteargs = %{$args{delete}} if $args{delete}; |
|
0
|
|
|
|
|
0
|
|
106
|
0
|
|
|
|
|
0
|
delete $args{delete}; |
107
|
0
|
0
|
|
|
|
0
|
my %updateargs = %{$args{update}} if $args{update}; |
|
0
|
|
|
|
|
0
|
|
108
|
0
|
|
|
|
|
0
|
delete $args{update}; |
109
|
0
|
0
|
|
|
|
0
|
my %insertargs = %{$args{insert}} if $args{insert}; |
|
0
|
|
|
|
|
0
|
|
110
|
0
|
|
|
|
|
0
|
delete $args{insert}; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
$deleteargs{$_} = $args{$_} for keys %args; |
113
|
0
|
|
|
|
|
0
|
$updateargs{$_} = $args{$_} for keys %args; |
114
|
0
|
|
|
|
|
0
|
$insertargs{$_} = $args{$_} for keys %args; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
$self->rundelete(%deleteargs); |
117
|
0
|
|
|
|
|
0
|
$self->update(%updateargs); |
118
|
0
|
|
|
|
|
0
|
$self->insert(%insertargs); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
0
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
125
|
|
|
|
|
|
|
sub displaySelect { |
126
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
127
|
0
|
|
|
|
|
0
|
my %args = @_; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
my $vars = $args{vars}; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
0
|
my @fields; |
132
|
0
|
|
|
|
|
0
|
my $binds = []; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# $self->q->util->debug->edump($incoming); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
0
|
foreach my $field (grep {!/vars/} keys %args) { |
|
0
|
|
|
|
|
0
|
|
137
|
0
|
0
|
|
|
|
0
|
unless ($field =~ /['"&;]/) { |
138
|
0
|
0
|
|
|
|
0
|
if ($args{$field}) { |
139
|
0
|
|
|
|
|
0
|
push @fields, $field." = ? "; |
140
|
0
|
0
|
|
|
|
0
|
if (ref $args{$field}) { |
141
|
0
|
|
|
|
|
0
|
push @$binds, ${$args{$field}}; |
|
0
|
|
|
|
|
0
|
|
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
0
|
push @$binds, $args{$field}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
0
|
my $bindstring = join ' and ', @fields; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
$self->recordset->where($bindstring); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# $self->q->util->debug->edump("bindstring: $bindstring binds: @$binds"); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
return $self->display(mode => 'select', binds => $binds, vars => $vars ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
159
|
|
|
|
|
|
|
sub deletes { |
160
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
0
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
163
|
0
|
|
|
|
|
0
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
0
|
|
164
|
0
|
|
|
|
|
0
|
$_->deletes; |
165
|
|
|
|
|
|
|
} |
166
|
0
|
|
|
|
|
0
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
0
|
my $data; |
170
|
0
|
|
|
|
|
0
|
my $widgetID = $self->vars->{id}; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
foreach my $key (grep {/^$widgetID-:DELETE:/} $self->q->param) { |
|
0
|
|
|
|
|
0
|
|
173
|
0
|
0
|
|
|
|
0
|
if ($key =~ /^($widgetID-:DELETE:)(.+)-:-(.+)::(\d+)$/) { |
|
|
0
|
|
|
|
|
|
174
|
0
|
|
|
|
|
0
|
my ($pre, $fieldname, $ID, $row) = ($1, $2, $3, $4); |
175
|
0
|
0
|
|
|
|
0
|
$data->{$ID}->{$fieldname} = $self->q->param($key) if $self->q->param($key); |
176
|
|
|
|
|
|
|
} elsif ($key =~ /^($widgetID-:DELETE:)(.+)-:-(.+)$/) { |
177
|
0
|
|
|
|
|
0
|
my ($pre, $fieldname, $ID) = ($1, $2, $3); |
178
|
0
|
0
|
|
|
|
0
|
$data->{$ID}->{$fieldname} = $self->q->param($key) if $self->q->param($key); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
0
|
|
|
|
|
0
|
return $data; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
185
|
|
|
|
|
|
|
sub deleteIds { |
186
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
my @deletes = sort keys %{$self->deletes}; |
|
0
|
|
|
|
|
0
|
|
189
|
|
|
|
|
|
|
|
190
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
191
|
0
|
|
|
|
|
0
|
return @deletes; |
192
|
|
|
|
|
|
|
} else { |
193
|
0
|
|
|
|
|
0
|
return \@deletes; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
198
|
|
|
|
|
|
|
sub displayblank { |
199
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
return $self->display(mode => 'blank'); #run display function with blank argument |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
205
|
|
|
|
|
|
|
sub domload { |
206
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
0
|
my $objectJs; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
0
|
foreach my $object (keys %{$self->vars->{objects};}) { |
|
0
|
|
|
|
|
0
|
|
211
|
0
|
|
|
|
|
0
|
$objectJs .= "var $object = JSON.parse('".to_json($self->vars->{objects}->{$object})."');\n"; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
0
|
0
|
|
|
|
0
|
$objectJs = $self->q->jswrap($objectJs) if $objectJs; |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
0
|
return $objectJs; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
220
|
|
|
|
|
|
|
sub domloader { |
221
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
222
|
0
|
|
|
|
|
0
|
my $vars = shift; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
0
|
return CGI::Lazy::Widget::DomLoader->new($self->q, $vars); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
228
|
|
|
|
|
|
|
sub insert { |
229
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
230
|
0
|
|
|
|
|
0
|
my %vars = @_; |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
0
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
233
|
0
|
|
|
|
|
0
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
0
|
|
234
|
0
|
|
|
|
|
0
|
$_->insert(%vars); |
235
|
|
|
|
|
|
|
} |
236
|
0
|
|
|
|
|
0
|
return; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
$self->recordset->insert($self->inserts, \%vars); |
240
|
0
|
|
|
|
|
0
|
return; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
244
|
|
|
|
|
|
|
sub inserts { |
245
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
246
|
|
|
|
|
|
|
|
247
|
0
|
0
|
|
|
|
0
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
248
|
0
|
|
|
|
|
0
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
0
|
|
249
|
0
|
|
|
|
|
0
|
$_->inserts; |
250
|
|
|
|
|
|
|
} |
251
|
0
|
|
|
|
|
0
|
return; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
0
|
my $data = {}; |
255
|
0
|
|
|
|
|
0
|
tie %{$data}, 'Tie::IxHash'; |
|
0
|
|
|
|
|
0
|
|
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
0
|
my $widgetID = $self->vars->{id}; |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
0
|
foreach my $key (sort _byWidgetRow grep {/^$widgetID-:INSERT:/} $self->q->param) { |
|
0
|
|
|
|
|
0
|
|
260
|
0
|
0
|
|
|
|
0
|
if ($key =~ /^($widgetID-:INSERT:)(.+)--$/) { |
|
|
0
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# $self->q->util->debug->edump($key); |
262
|
0
|
|
|
|
|
0
|
my ($pre, $field) = ($1, $2); |
263
|
0
|
0
|
|
|
|
0
|
$data->{1}->{$field} = $self->q->param($key) if $self->q->param($key); |
264
|
|
|
|
|
|
|
} elsif ($key =~ /^($widgetID-:INSERT:)(.+)--(\d+)$/) { |
265
|
0
|
|
|
|
|
0
|
my ($pre, $field, $row) = ($1, $2, $3); |
266
|
0
|
0
|
|
|
|
0
|
$data->{$row}->{$field} = $self->q->param($key) if $self->q->param($key); |
267
|
|
|
|
|
|
|
# $self->q->util->debug->edump($field, $self->q->param($key)) if $self->q->param($key); |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# $self->q->util->debug->edump($data); |
272
|
0
|
|
|
|
|
0
|
return $data; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
276
|
|
|
|
|
|
|
sub _byWidgetRow { |
277
|
|
|
|
|
|
|
|
278
|
0
|
|
|
0
|
|
0
|
my $rowa; |
279
|
|
|
|
|
|
|
my $rowb; |
280
|
|
|
|
|
|
|
|
281
|
0
|
0
|
|
|
|
0
|
if ($a =~ /^(.+-:INSERT:)(.+)--(\d+)$/) { |
282
|
0
|
|
|
|
|
0
|
$rowa = $3; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
0
|
0
|
|
|
|
0
|
if ($b =~ /^(.+-:INSERT:)(.+)--(\d+)$/) { |
286
|
0
|
|
|
|
|
0
|
$rowb = $3; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
0
|
|
|
|
|
0
|
return $rowa <=> $rowb; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
293
|
|
|
|
|
|
|
sub insertIds { |
294
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
295
|
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
0
|
my @inserts = sort keys %{$self->inserts}; |
|
0
|
|
|
|
|
0
|
|
297
|
|
|
|
|
|
|
|
298
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
299
|
0
|
|
|
|
|
0
|
return @inserts; |
300
|
|
|
|
|
|
|
} else { |
301
|
0
|
|
|
|
|
0
|
return \@inserts; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
306
|
|
|
|
|
|
|
sub jsonescape { |
307
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
308
|
0
|
|
|
|
|
0
|
my $target = shift; |
309
|
|
|
|
|
|
|
|
310
|
0
|
0
|
|
|
|
0
|
if (ref $target eq 'HASH') { |
|
|
0
|
|
|
|
|
|
311
|
0
|
|
|
|
|
0
|
foreach (keys %$target) { |
312
|
0
|
|
|
|
|
0
|
foreach (values %{$target->{$_}}) { |
|
0
|
|
|
|
|
0
|
|
313
|
0
|
|
|
|
|
0
|
s/'//g; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
} elsif (ref $target eq 'ARRAY') { #finish this |
318
|
0
|
|
|
|
|
0
|
foreach (@$target) { |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
} else { |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
328
|
|
|
|
|
|
|
sub q { |
329
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
330
|
|
|
|
|
|
|
|
331
|
0
|
|
|
|
|
0
|
return $self->{_q}; |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
335
|
|
|
|
|
|
|
sub new { |
336
|
1
|
|
|
1
|
0
|
2
|
my $class = shift; |
337
|
1
|
|
|
|
|
2
|
my $q = shift; |
338
|
|
|
|
|
|
|
|
339
|
1
|
|
|
|
|
7
|
return bless {_q => $q }, $class; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
343
|
|
|
|
|
|
|
sub postdata { |
344
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
345
|
|
|
|
|
|
|
|
346
|
0
|
0
|
|
|
|
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
347
|
0
|
|
|
|
|
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
|
|
348
|
0
|
|
|
|
|
|
$_->postdata; |
349
|
|
|
|
|
|
|
} |
350
|
0
|
|
|
|
|
|
return; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
my $data; |
354
|
0
|
|
|
|
|
|
my $widgetID = $self->vars->{id}; |
355
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
|
foreach my $key (grep {/^$widgetID/} $self->q->param) { |
|
0
|
|
|
|
|
|
|
357
|
0
|
|
|
|
|
|
$key =~ /^($widgetID-)(.+)(\d*)$/; |
358
|
0
|
|
|
|
|
|
my ($pre, $field, $row) = ($1, $2, $3); |
359
|
0
|
0
|
|
|
|
|
$data->{$row}->{$field} = $self->q->param($key) if $self->q->param($key); |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
0
|
|
|
|
|
|
return $data; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
366
|
|
|
|
|
|
|
sub preloadLookup { |
367
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
368
|
|
|
|
|
|
|
|
369
|
0
|
|
|
|
|
|
my $preloadLookupJs; |
370
|
0
|
|
|
|
|
|
my $lookups = $self->vars->{lookups}; |
371
|
0
|
|
|
|
|
|
my %lookuptype = ( |
372
|
|
|
|
|
|
|
hash => 'gethash', |
373
|
|
|
|
|
|
|
hashlist => 'gethashlist', |
374
|
|
|
|
|
|
|
array => 'getarray', |
375
|
|
|
|
|
|
|
); |
376
|
|
|
|
|
|
|
|
377
|
0
|
|
|
|
|
|
foreach my $queryname (keys %$lookups) { |
378
|
0
|
0
|
|
|
|
|
if ($lookups->{$queryname}->{preload}) { |
379
|
0
|
|
|
|
|
|
my $query = $lookups->{$queryname}->{sql}; |
380
|
0
|
|
|
|
|
|
my $binds = $lookups->{$queryname}->{binds}; |
381
|
0
|
|
|
|
|
|
my $output = $lookups->{$queryname}->{output}; |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
my $orderby = $lookups->{$queryname}->{orderby}; |
384
|
|
|
|
|
|
|
|
385
|
0
|
0
|
|
|
|
|
if ($orderby) { |
386
|
0
|
|
|
|
|
|
$query .= " order by ". join ',', @$orderby; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
0
|
|
|
|
|
|
my $results; |
390
|
|
|
|
|
|
|
|
391
|
0
|
0
|
|
|
|
|
if ($lookuptype{$output} eq 'gethash') { |
392
|
0
|
|
|
|
|
|
$results = $self->db->gethash($query, $lookups->{$queryname}->{primarykey}, @$binds); |
393
|
|
|
|
|
|
|
} else { |
394
|
0
|
|
|
|
|
|
my $type = $lookuptype{$output}; |
395
|
0
|
|
|
|
|
|
$results = $self->db->$type($query, @$binds); |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
0
|
0
|
|
|
|
|
$results = [] unless ref $results; |
399
|
0
|
|
|
|
|
|
$self->jsonescape($results); |
400
|
|
|
|
|
|
|
|
401
|
0
|
|
|
|
|
|
$preloadLookupJs .= "var $queryname = JSON.parse('".to_json($results)."');\n"; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
} |
404
|
0
|
0
|
|
|
|
|
$preloadLookupJs = $self->q->jswrap($preloadLookupJs) if $preloadLookupJs; |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
|
return $preloadLookupJs; |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
410
|
|
|
|
|
|
|
sub rawContents { |
411
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
412
|
0
|
|
|
|
|
|
my %args = @_; |
413
|
|
|
|
|
|
|
|
414
|
0
|
|
|
|
|
|
my $output = $self->contents(%args); |
415
|
0
|
|
|
|
|
|
$output =~ s/\\/\\\\/g; |
416
|
0
|
|
|
|
|
|
$output =~ s/"/\\"/g; |
417
|
0
|
|
|
|
|
|
$output =~ s/[\t\n]//g; |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
|
return $output; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
423
|
|
|
|
|
|
|
sub recordset { |
424
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
425
|
|
|
|
|
|
|
|
426
|
0
|
|
|
|
|
|
return $self->{_recordset}; |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
430
|
|
|
|
|
|
|
sub rundelete { |
431
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
432
|
0
|
|
|
|
|
|
my %vars = @_; |
433
|
|
|
|
|
|
|
|
434
|
0
|
0
|
|
|
|
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
435
|
0
|
|
|
|
|
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
|
|
436
|
0
|
|
|
|
|
|
$_->rundelete(%vars); |
437
|
|
|
|
|
|
|
} |
438
|
0
|
|
|
|
|
|
return; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
|
$self->recordset->delete($self->deletes); |
442
|
|
|
|
|
|
|
|
443
|
0
|
|
|
|
|
|
return; |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
447
|
|
|
|
|
|
|
sub select { |
448
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
449
|
0
|
|
|
|
|
|
my %args = @_; |
450
|
|
|
|
|
|
|
|
451
|
0
|
0
|
|
|
|
|
$args{searchLike} = $self->vars->{searchLike} if $self->vars->{searchLike}; |
452
|
0
|
0
|
|
|
|
|
$args{searchLikeVars} = $self->vars->{searchLikeVars} if $self->vars->{searchLikeVars}; |
453
|
|
|
|
|
|
|
|
454
|
0
|
|
0
|
|
|
|
my $incoming = $args{incoming} || from_json(($self->q->param('POSTDATA') || $self->q->param('keywords') || $self->q->param('XForms:Model'))); |
455
|
0
|
|
|
|
|
|
my $div = $args{div}; |
456
|
0
|
|
|
|
|
|
my $vars = $args{vars}; |
457
|
0
|
|
|
|
|
|
my $like = $args{searchLike}; |
458
|
0
|
|
|
|
|
|
my $likevars = $args{searchLikeVars}; |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
|
461
|
0
|
|
|
|
|
|
my $widgetID = $self->widgetID; |
462
|
0
|
|
|
|
|
|
my @fields; |
463
|
|
|
|
|
|
|
my $bind; |
464
|
0
|
|
|
|
|
|
my $binds = []; |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
# $self->q->util->debug->edump($incoming); |
467
|
|
|
|
|
|
|
|
468
|
0
|
0
|
|
|
|
|
if ($incoming->{noSearchLike}) { |
469
|
0
|
|
|
|
|
|
$like = undef; |
470
|
0
|
|
|
|
|
|
delete $incoming->{noSearchLike}; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
0
|
|
|
|
|
|
delete $incoming->{CGILazyID}; #key/value pair only used at cgi level, will cause problems here (set automatically by Dataset with name of widget) |
474
|
|
|
|
|
|
|
|
475
|
0
|
0
|
|
|
|
|
if ($like) { |
476
|
0
|
|
|
|
|
|
$bind = " like ? "; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
} else { |
479
|
0
|
|
|
|
|
|
$bind = " = ? "; |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
0
|
|
|
0
|
|
|
my %likemap = ( |
483
|
|
|
|
|
|
|
'%?%' => sub {return '%'.$_[0].'%';}, |
484
|
0
|
|
|
0
|
|
|
'?%' => sub {return $_[0].'%';}, |
485
|
0
|
|
|
0
|
|
|
'%?' => sub {return '%'.$_[0];}, |
486
|
|
|
|
|
|
|
|
487
|
0
|
|
|
|
|
|
); |
488
|
|
|
|
|
|
|
|
489
|
0
|
|
|
|
|
|
foreach my $field (keys %$incoming) { |
490
|
0
|
0
|
|
|
|
|
unless ($field =~ /['"&;]\(\)/) { |
491
|
0
|
0
|
|
|
|
|
if ($incoming->{$field}) { |
492
|
0
|
|
|
|
|
|
(my $fieldname = $field) =~ s/^$widgetID-//; |
493
|
0
|
|
|
|
|
|
push @fields, $fieldname.$bind; |
494
|
0
|
0
|
|
|
|
|
if (ref $incoming->{$field}) { |
495
|
0
|
0
|
|
|
|
|
if ($likevars) { |
496
|
0
|
|
|
|
|
|
my $value = $likemap{$likevars}->(${$incoming->{$field}}); |
|
0
|
|
|
|
|
|
|
497
|
0
|
|
|
|
|
|
push @$binds, $value; |
498
|
|
|
|
|
|
|
} else { |
499
|
0
|
|
|
|
|
|
push @$binds, ${$incoming->{$field}}; |
|
0
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
} else { |
502
|
0
|
0
|
|
|
|
|
if ($like) { |
503
|
0
|
|
|
|
|
|
my $value = $likemap{$like}->($incoming->{$field}); |
504
|
0
|
|
|
|
|
|
push @$binds, $value; |
505
|
|
|
|
|
|
|
} else { |
506
|
0
|
|
|
|
|
|
push @$binds, $incoming->{$field}; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
|
513
|
0
|
|
|
|
|
|
my $bindstring = join ' and ', @fields; |
514
|
|
|
|
|
|
|
|
515
|
0
|
|
|
|
|
|
$self->recordset->where($bindstring); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
# $self->q->util->debug->edump("bindstring: $bindstring binds: @$binds"); |
518
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
my %parameters = ( |
520
|
|
|
|
|
|
|
mode => 'select', |
521
|
|
|
|
|
|
|
binds => $binds, |
522
|
|
|
|
|
|
|
vars => $vars, |
523
|
|
|
|
|
|
|
); |
524
|
|
|
|
|
|
|
|
525
|
0
|
0
|
|
|
|
|
$parameters{nodiv} = 1 unless $div; #pass the div tag if we prefer |
526
|
|
|
|
|
|
|
|
527
|
0
|
|
|
|
|
|
return $self->rawContents(%parameters); |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
531
|
|
|
|
|
|
|
sub update { |
532
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
533
|
0
|
|
|
|
|
|
my %vars = @_; |
534
|
|
|
|
|
|
|
|
535
|
0
|
0
|
|
|
|
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
536
|
0
|
|
|
|
|
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
|
|
537
|
0
|
|
|
|
|
|
$_->update(%vars); |
538
|
|
|
|
|
|
|
} |
539
|
0
|
|
|
|
|
|
return; |
540
|
|
|
|
|
|
|
} |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
# $self->q->util->debug->edump('fromupdate', $self->updates, \%vars); |
543
|
0
|
|
|
|
|
|
$self->recordset->update($self->updates, \%vars); |
544
|
|
|
|
|
|
|
|
545
|
0
|
|
|
|
|
|
return; |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
549
|
|
|
|
|
|
|
sub updates { |
550
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
551
|
|
|
|
|
|
|
|
552
|
0
|
0
|
|
|
|
|
if (ref $self eq 'CGI::Lazy::Widget::Composite') { |
553
|
0
|
|
|
|
|
|
foreach (@{$self->memberarray}) { |
|
0
|
|
|
|
|
|
|
554
|
0
|
|
|
|
|
|
$_->updates; |
555
|
|
|
|
|
|
|
} |
556
|
0
|
|
|
|
|
|
return; |
557
|
|
|
|
|
|
|
} |
558
|
|
|
|
|
|
|
|
559
|
0
|
|
|
|
|
|
my $data; |
560
|
0
|
|
|
|
|
|
my $widgetID = $self->widgetID; |
561
|
|
|
|
|
|
|
|
562
|
0
|
|
|
|
|
|
foreach my $key (grep {/^$widgetID-:UPDATE:/} $self->q->param) { |
|
0
|
|
|
|
|
|
|
563
|
0
|
0
|
|
|
|
|
if ($key =~ /^($widgetID-:UPDATE:)(.+)-:-(.+)::(\d+)$/) { |
|
|
0
|
|
|
|
|
|
564
|
0
|
|
|
|
|
|
my ($pre, $fieldname, $ID, $row) = ($1, $2, $3, $4); |
565
|
0
|
|
|
|
|
|
$data->{$ID}->{$fieldname} = $self->q->param($key);# if $self->q->param($key); #if this is set, won't blank fields deliberately left blank |
566
|
|
|
|
|
|
|
} elsif ($key =~ /^($widgetID-:UPDATE:)(.+)-:-(.+)$/) { |
567
|
0
|
|
|
|
|
|
my ($pre, $fieldname, $ID) = ($1, $2, $3); |
568
|
0
|
|
|
|
|
|
$data->{$ID}->{$fieldname} = $self->q->param($key);# if $self->q->param($key); |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
} |
571
|
|
|
|
|
|
|
# $self->q->util->debug->edump($data); |
572
|
0
|
|
|
|
|
|
return $data; |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
576
|
|
|
|
|
|
|
sub updateIds { |
577
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
578
|
|
|
|
|
|
|
|
579
|
0
|
|
|
|
|
|
my @updates = sort keys %{$self->updates}; |
|
0
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
|
581
|
0
|
0
|
|
|
|
|
if (wantarray) { |
582
|
0
|
|
|
|
|
|
return @updates; |
583
|
|
|
|
|
|
|
} else { |
584
|
0
|
|
|
|
|
|
return \@updates; |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
589
|
|
|
|
|
|
|
sub validator { |
590
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
591
|
|
|
|
|
|
|
|
592
|
0
|
|
|
|
|
|
return $self->{_validator}; |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
596
|
|
|
|
|
|
|
sub vars { |
597
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
598
|
|
|
|
|
|
|
|
599
|
0
|
|
|
|
|
|
return $self->{_vars}; |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
603
|
|
|
|
|
|
|
sub widgetID { |
604
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
605
|
|
|
|
|
|
|
|
606
|
0
|
|
|
|
|
|
return $self->{_widgetID}; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
1 |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
__END__ |