";
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 $parsedFilter = $$o{oq}->parseFilter($filter); |
44
|
0
|
|
|
|
|
|
foreach my $f (@$parsedFilter) { |
45
|
0
|
|
|
|
|
|
$buf .= " |
";
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $typenum; |
48
|
0
|
0
|
|
|
|
|
$typenum = $$f[0] if ref($f) eq 'ARRAY'; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
|
if (! $typenum) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$buf .= " | |
52
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $f eq 'OR'; |
53
|
0
|
|
|
|
|
|
$buf .= ">OR | ";
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# else if (selectalias operator literal) |
57
|
|
|
|
|
|
|
elsif ($typenum == 1 || $typenum == 3) { |
58
|
0
|
|
|
|
|
|
$buf .= " | "; |
59
|
0
|
|
|
|
|
|
my ($type,$numLeftParen,$leftExp,$operator,$rightExp,$numRightParen) = @$f; |
60
|
0
|
0
|
|
|
|
|
if ($numLeftParen == 0) { |
61
|
0
|
|
|
|
|
|
$buf .= ""; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
$buf .= " |
64
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==1; |
65
|
0
|
|
|
|
|
|
$buf .= ">( |
66
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==2; |
67
|
0
|
|
|
|
|
|
$buf .= ">(( |
68
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==3; |
69
|
0
|
|
|
|
|
|
$buf .= ">((("; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
$buf .= " | |
72
|
0
|
|
|
|
|
|
foreach my $c (@cols) { |
73
|
0
|
|
|
|
|
|
$buf .= " |
74
|
0
|
0
|
0
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char' && $$types{$c} ne 'clob'; |
75
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $c eq $leftExp; |
76
|
0
|
|
|
|
|
|
$buf .= ">".escapeHTML($$o{schema}{select}{$c}[2]); |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
$buf .= " | |
79
|
0
|
|
|
|
|
|
foreach my $op (@op) { |
80
|
0
|
|
|
|
|
|
$buf .= " |
81
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $op eq $operator; |
82
|
0
|
|
|
|
|
|
$buf .= ">$op"; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
$buf .= " | |
85
|
0
|
|
|
|
|
|
my $rightSelectedField; |
86
|
0
|
0
|
|
|
|
|
$rightSelectedField = $rightExp if $type == 3; |
87
|
0
|
|
|
|
|
|
foreach my $c (@cols) { |
88
|
0
|
|
|
|
|
|
$buf .= " |
89
|
0
|
0
|
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char'; |
90
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $c eq $rightSelectedField; |
91
|
0
|
|
|
|
|
|
$buf .= ">".escapeHTML($$o{schema}{select}{$c}[2]); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
$buf .= "
|
94
|
0
|
0
|
|
|
|
|
if ($rightSelectedField) { |
95
|
0
|
|
|
|
|
|
$buf .= " style='display: none;'"; |
96
|
|
|
|
|
|
|
} else { |
97
|
0
|
|
|
|
|
|
$buf .= " value='".escapeHTML($rightExp)."'"; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
$buf .= "> | "; |
100
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
101
|
0
|
|
|
|
|
|
$buf .= ""; |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
$buf .= " |
104
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
105
|
0
|
|
|
|
|
|
$buf .= ">) |
106
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
107
|
0
|
|
|
|
|
|
$buf .= ">)) |
108
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
109
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
$buf .= " | | ";
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# else if (namedfilter, arguments) |
115
|
|
|
|
|
|
|
elsif ($typenum == 2) { |
116
|
0
|
|
|
|
|
|
$buf .= " | "; |
117
|
0
|
|
|
|
|
|
my ($type,$numLeftParen,$namedFilter,$argArray,$numRightParen) = @$f; |
118
|
0
|
0
|
|
|
|
|
if ($numLeftParen == 0) { |
119
|
0
|
|
|
|
|
|
$buf .= ""; |
120
|
|
|
|
|
|
|
} else { |
121
|
0
|
|
|
|
|
|
$buf .= " |
122
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==1; |
123
|
0
|
|
|
|
|
|
$buf .= ">( |
124
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==2; |
125
|
0
|
|
|
|
|
|
$buf .= ">(( |
126
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==3; |
127
|
0
|
|
|
|
|
|
$buf .= ">((("; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
$buf .= " | "; |
130
|
0
|
|
|
|
|
|
my $nf = $$o{schema}{named_filters}{$namedFilter}; |
131
|
0
|
0
|
|
|
|
|
if (ref($nf) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
132
|
0
|
|
0
|
|
|
|
my $title = $$nf[2] || $namedFilter; |
133
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
134
|
|
|
|
|
|
|
.'
135
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
136
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
elsif (ref($nf) eq 'HASH') { |
139
|
0
|
0
|
|
|
|
|
if (ref($$nf{html_generator}) eq 'CODE') { |
140
|
|
|
|
|
|
|
#before we call the html_generator, set the params up |
141
|
0
|
|
|
|
|
|
my %args; |
142
|
0
|
|
|
|
|
|
for (my $i=0; $i <= $#$argArray; $i+=2) { |
143
|
0
|
|
|
|
|
|
my $name = $$argArray[$i]; |
144
|
0
|
|
|
|
|
|
my $val = $$argArray[$i + 1]; |
145
|
0
|
|
0
|
|
|
|
$args{$name}||=[]; |
146
|
0
|
|
|
|
|
|
push @{$args{$name}}, $val; |
|
0
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
0
|
|
|
|
|
|
while (my ($name,$vals) = each %args) { |
149
|
0
|
|
|
|
|
|
$$o{q}->param('_nf_arg_'.$name, @$vals); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
$buf .= |
152
|
|
|
|
|
|
|
'' |
153
|
0
|
|
|
|
|
|
.$$nf{html_generator}->($$o{q}, '_nf_arg_') |
154
|
|
|
|
|
|
|
.''; |
155
|
|
|
|
|
|
|
} else { |
156
|
0
|
|
|
|
|
|
my $title; |
157
|
0
|
0
|
|
|
|
|
if (ref($$nf{sql_generator}) eq 'CODE') { |
158
|
0
|
|
|
|
|
|
my $ar = $$nf{sql_generator}->(@$argArray); |
159
|
0
|
|
|
|
|
|
$title = $$ar[2]; |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
0
|
|
|
|
$title ||= $$nf{title} || $namedFilter; |
|
|
|
0
|
|
|
|
|
162
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
163
|
|
|
|
|
|
|
.'
164
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
165
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
$buf .= " | "; |
169
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
170
|
0
|
|
|
|
|
|
$buf .= ""; |
171
|
|
|
|
|
|
|
} else { |
172
|
0
|
|
|
|
|
|
$buf .= " |
173
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
174
|
0
|
|
|
|
|
|
$buf .= ">) |
175
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
176
|
0
|
|
|
|
|
|
$buf .= ">)) |
177
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
178
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
179
|
|
|
|
|
|
|
} |
180
|
0
|
|
|
|
|
|
$buf .= " | | ";
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
else { |
184
|
0
|
|
|
|
|
|
die "invalid typenum: $typenum; this should never happen"; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$buf .= " |
";
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
|
$buf .= " |