";
13
|
0
|
|
|
|
|
|
my $types = $$o{oq}->get_col_types('filter'); |
14
|
0
|
|
|
|
|
|
my $s = $$o{schema}{select}; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $filter = $$o{q}->param('filter'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# add new field to filter? |
19
|
0
|
0
|
|
|
|
|
if ($$o{q}->param('field') ne '') { |
20
|
0
|
|
|
|
|
|
my $field = $$o{q}->param('field'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# if named filter exists for this field, use the named filter |
23
|
0
|
0
|
|
|
|
|
if (exists $$o{schema}{named_filters}{$field}) { |
|
|
0
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
$filter .= " AND " if $filter; |
25
|
0
|
|
|
|
|
|
$filter .= $field.'()'; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif (! $$s{$field}[3]{disable_filter}) { |
28
|
0
|
0
|
|
|
|
|
$filter .= " AND " if $filter; |
29
|
0
|
0
|
0
|
|
|
|
if ($$types{$field} eq 'char' || $$types{$field} eq 'clob') { |
30
|
0
|
|
|
|
|
|
$filter .= "$field contains ''"; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
|
$filter .= "$field=''"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @cols = grep { |
39
|
|
|
|
|
|
|
$$s{$_}[2] ne '' && ! $$s{$_}[3]{disable_filter} && ! $$s{$_}[3]{is_hidden} |
40
|
0
|
0
|
0
|
|
|
|
} sort { $$s{$a}[2] cmp $$s{$b}[2] } keys %$s; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my @op = (qw( = != < <= > >= like ), 'not like', 'contains', 'not contains'); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $seq = 0; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $parsedFilter = $$o{oq}->parseFilter($filter); |
46
|
0
|
|
|
|
|
|
foreach my $f (@$parsedFilter) { |
47
|
0
|
|
|
|
|
|
$buf .= " |
";
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $typenum; |
50
|
0
|
0
|
|
|
|
|
$typenum = $$f[0] if ref($f) eq 'ARRAY'; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
0
|
|
|
|
if (! $typenum) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$buf .= " | |
54
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $f eq 'OR'; |
55
|
0
|
|
|
|
|
|
$buf .= ">OR | ";
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# else if (selectalias operator literal) |
59
|
|
|
|
|
|
|
elsif ($typenum == 1 || $typenum == 3) { |
60
|
0
|
|
|
|
|
|
$buf .= " | "; |
61
|
0
|
|
|
|
|
|
my ($type,$numLeftParen,$leftExp,$operator,$rightExp,$numRightParen) = @$f; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ($numLeftParen == 0) { |
64
|
0
|
|
|
|
|
|
$buf .= ""; |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$buf .= " |
67
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==1; |
68
|
0
|
|
|
|
|
|
$buf .= ">( |
69
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==2; |
70
|
0
|
|
|
|
|
|
$buf .= ">(( |
71
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==3; |
72
|
0
|
|
|
|
|
|
$buf .= ">((("; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
$buf .= " | ";
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $colOpts = $$o{schema}{select}{$leftExp}[3]; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# if lexp is not something that user is allowed to filter or is hidden |
79
|
0
|
0
|
0
|
|
|
|
if ($$colOpts{disable_filter} || $$colOpts{is_hidden}) { |
80
|
0
|
|
|
|
|
|
my $exp = $leftExp; |
81
|
0
|
|
|
|
|
|
my $label = $o->get_nice_name($leftExp); |
82
|
0
|
0
|
|
|
|
|
if ($operator =~ /\w/) { |
83
|
0
|
|
|
|
|
|
$exp .= ' '.$operator.' '; |
84
|
0
|
|
|
|
|
|
$label .= ' '.$operator.' '; |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
$exp .= $operator; |
87
|
0
|
|
|
|
|
|
$label .= $operator; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
# if rightExp is a literal |
90
|
0
|
0
|
|
|
|
|
if ($typenum == 1) { |
91
|
0
|
0
|
|
|
|
|
if ($rightExp =~ /[\ \'\"]/) { |
92
|
0
|
0
|
|
|
|
|
if ($rightExp !~ /\'/) { |
93
|
0
|
|
|
|
|
|
$exp .= "'".$rightExp."'"; |
94
|
0
|
|
|
|
|
|
$label .= "'".$rightExp."'"; |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
my $x = $rightExp; $x =~ s/\"//g; |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$exp .= '"'.$x.'"'; |
98
|
0
|
|
|
|
|
|
$label .= '"'.$x.'"'; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
|
$exp .= $rightExp; |
102
|
0
|
|
|
|
|
|
$label .= $rightExp; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
# else lexp is col |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
|
$exp .= $rightExp; |
108
|
0
|
|
|
|
|
|
$label .= $o->get_nice_name($rightExp); |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
$buf .= " | ".escapeHTML($label)." | ";
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# else present a widget to modify expression |
114
|
|
|
|
|
|
|
else { |
115
|
0
|
|
|
|
|
|
$buf .= " | |
116
|
0
|
|
|
|
|
|
foreach my $c (@cols) { |
117
|
0
|
|
|
|
|
|
$buf .= " |
118
|
0
|
0
|
0
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char' && $$types{$c} ne 'clob'; |
119
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $c eq $leftExp; |
120
|
0
|
|
|
|
|
|
$buf .= ">".escapeHTML($o->get_nice_name($c)); |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
$buf .= " | |
123
|
0
|
|
|
|
|
|
foreach my $op (@op) { |
124
|
0
|
|
|
|
|
|
$buf .= " |
125
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $op eq $operator; |
126
|
0
|
|
|
|
|
|
$buf .= ">$op"; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
$buf .= " | |
129
|
0
|
|
|
|
|
|
my $rightSelectedField; |
130
|
0
|
0
|
|
|
|
|
$rightSelectedField = $rightExp if $type == 3; |
131
|
0
|
|
|
|
|
|
foreach my $c (@cols) { |
132
|
0
|
|
|
|
|
|
$buf .= " |
133
|
0
|
0
|
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char'; |
134
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $c eq $rightSelectedField; |
135
|
0
|
|
|
|
|
|
$buf .= ">".escapeHTML($o->get_nice_name($c)); |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
|
$buf .= "
|
138
|
0
|
0
|
|
|
|
|
if ($rightSelectedField) { |
139
|
0
|
|
|
|
|
|
$buf .= " style='display: none;'"; |
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
|
|
|
|
|
$buf .= " value='".escapeHTML($rightExp)."'"; |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
$buf .= "> | ";
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$buf .= " | "; |
148
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
149
|
0
|
|
|
|
|
|
$buf .= ""; |
150
|
|
|
|
|
|
|
} else { |
151
|
0
|
|
|
|
|
|
$buf .= " |
152
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
153
|
0
|
|
|
|
|
|
$buf .= ">) |
154
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
155
|
0
|
|
|
|
|
|
$buf .= ">)) |
156
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
157
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
$buf .= " | | ";
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# else if (namedfilter, arguments) |
163
|
|
|
|
|
|
|
elsif ($typenum == 2) { |
164
|
0
|
|
|
|
|
|
$buf .= " | "; |
165
|
0
|
|
|
|
|
|
my ($type,$numLeftParen,$namedFilter,$argArray,$numRightParen) = @$f; |
166
|
0
|
0
|
|
|
|
|
if ($numLeftParen == 0) { |
167
|
0
|
|
|
|
|
|
$buf .= ""; |
168
|
|
|
|
|
|
|
} else { |
169
|
0
|
|
|
|
|
|
$buf .= " |
170
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==1; |
171
|
0
|
|
|
|
|
|
$buf .= ">( |
172
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==2; |
173
|
0
|
|
|
|
|
|
$buf .= ">(( |
174
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==3; |
175
|
0
|
|
|
|
|
|
$buf .= ">((("; |
176
|
|
|
|
|
|
|
} |
177
|
0
|
|
|
|
|
|
$buf .= " | "; |
178
|
0
|
|
|
|
|
|
my $nf = $$o{schema}{named_filters}{$namedFilter}; |
179
|
0
|
0
|
|
|
|
|
if (ref($nf) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
180
|
0
|
|
0
|
|
|
|
my $title = $$nf[2] || $namedFilter; |
181
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
182
|
|
|
|
|
|
|
.'
183
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
184
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
elsif (ref($nf) eq 'HASH') { |
187
|
0
|
0
|
|
|
|
|
if (ref($$nf{html_generator}) eq 'CODE') { |
188
|
|
|
|
|
|
|
#before we call the html_generator, set the params up |
189
|
0
|
|
|
|
|
|
my %args; |
190
|
0
|
|
|
|
|
|
for (my $i=0; $i <= $#$argArray; $i+=2) { |
191
|
0
|
|
|
|
|
|
my $name = $$argArray[$i]; |
192
|
0
|
|
|
|
|
|
my $val = $$argArray[$i + 1]; |
193
|
0
|
|
0
|
|
|
|
$args{$name}||=[]; |
194
|
0
|
|
|
|
|
|
push @{$args{$name}}, $val; |
|
0
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
|
my $prefix = '_nfarg'.++$seq; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
while (my ($name,$vals) = each %args) { |
199
|
0
|
|
|
|
|
|
$$o{q}->param($prefix.$name, @$vals); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
$buf .= |
202
|
|
|
|
|
|
|
'' |
203
|
0
|
|
|
|
|
|
.$$nf{html_generator}->($$o{q}, $prefix) |
204
|
|
|
|
|
|
|
.''; |
205
|
|
|
|
|
|
|
} else { |
206
|
0
|
|
|
|
|
|
my $title; |
207
|
0
|
0
|
|
|
|
|
if (ref($$nf{sql_generator}) eq 'CODE') { |
208
|
0
|
|
|
|
|
|
my $ar = $$nf{sql_generator}->(@$argArray); |
209
|
0
|
|
|
|
|
|
$title = $$ar[2]; |
210
|
|
|
|
|
|
|
} |
211
|
0
|
|
0
|
|
|
|
$title ||= $$nf{title} || $namedFilter; |
|
|
|
0
|
|
|
|
|
212
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
213
|
|
|
|
|
|
|
.'
214
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
215
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
0
|
|
|
|
|
|
$buf .= " | "; |
219
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
220
|
0
|
|
|
|
|
|
$buf .= ""; |
221
|
|
|
|
|
|
|
} else { |
222
|
0
|
|
|
|
|
|
$buf .= " |
223
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
224
|
0
|
|
|
|
|
|
$buf .= ">) |
225
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
226
|
0
|
|
|
|
|
|
$buf .= ">)) |
227
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
228
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
229
|
|
|
|
|
|
|
} |
230
|
0
|
|
|
|
|
|
$buf .= " | | ";
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
else { |
234
|
0
|
|
|
|
|
|
die "invalid typenum: $typenum; this should never happen"; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
$buf .= " |
";
239
|
|
|
|
|
|
|
} |
240
|
0
|
|
|
|
|
|
$buf .= " |