";
14
|
0
|
|
|
|
|
|
my $types = $$o{oq}->get_col_types('filter'); |
15
|
0
|
|
|
|
|
|
my $s = $$o{schema}{select}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $filter = $$o{q}->param('filter'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# add new field to filter? |
20
|
0
|
0
|
|
|
|
|
if ($$o{q}->param('field') ne '') { |
21
|
0
|
|
|
|
|
|
my $field = $$o{q}->param('field'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# if named filter exists for this field, use the named filter |
24
|
0
|
0
|
|
|
|
|
if (exists $$o{schema}{named_filters}{$field}) { |
|
|
0
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
$filter .= " AND " if $filter; |
26
|
0
|
|
|
|
|
|
$filter .= $field.'()'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif (! $$s{$field}[3]{disable_filter}) { |
29
|
0
|
0
|
|
|
|
|
$filter .= " AND " if $filter; |
30
|
0
|
0
|
|
|
|
|
if ($$types{$field} eq 'char') { |
31
|
0
|
|
|
|
|
|
$filter .= "[$field] contains ''"; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
|
$filter .= "[$field] = ''"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @cols = grep { |
40
|
|
|
|
|
|
|
$$s{$_}[2] ne '' && ! $$s{$_}[3]{disable_filter} && ! $$s{$_}[3]{is_hidden} |
41
|
0
|
0
|
0
|
|
|
|
} sort { $$s{$a}[2] cmp $$s{$b}[2] } keys %$s; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @op = (qw( = != < <= > >= like ), 'not like', 'contains', 'not contains'); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $parsedFilter = CGI::OptimalQuery::FilterParser::parseFilter($o, $filter); |
45
|
0
|
|
|
|
|
|
foreach my $f (@$parsedFilter) { |
46
|
0
|
|
|
|
|
|
$buf .= " |
";
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
my $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
|
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char'; |
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
|
0
|
|
|
|
|
my $rightSelectedField = $rightExp if $type == 3; |
86
|
0
|
|
|
|
|
|
foreach my $c (@cols) { |
87
|
0
|
|
|
|
|
|
$buf .= " |
88
|
0
|
0
|
|
|
|
|
$buf .= " data-type=".$$types{$c} if $$types{$c} ne 'char'; |
89
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $c eq $rightSelectedField; |
90
|
0
|
|
|
|
|
|
$buf .= ">".escapeHTML($$o{schema}{select}{$c}[2]); |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
$buf .= "
|
93
|
0
|
0
|
|
|
|
|
if ($rightSelectedField) { |
94
|
0
|
|
|
|
|
|
$buf .= " style='display: none;'"; |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
$buf .= " value='".escapeHTML($rightExp)."'"; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
$buf .= "> | "; |
99
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
100
|
0
|
|
|
|
|
|
$buf .= ""; |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
|
$buf .= " |
103
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
104
|
0
|
|
|
|
|
|
$buf .= ">) |
105
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
106
|
0
|
|
|
|
|
|
$buf .= ">)) |
107
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
108
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
$buf .= " | | ";
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# else if (namedfilter, arguments) |
114
|
|
|
|
|
|
|
elsif ($typenum == 2) { |
115
|
0
|
|
|
|
|
|
$buf .= " | "; |
116
|
0
|
|
|
|
|
|
my ($type,$numLeftParen,$namedFilter,$argArray,$numRightParen) = @$f; |
117
|
0
|
0
|
|
|
|
|
if ($numLeftParen == 0) { |
118
|
0
|
|
|
|
|
|
$buf .= ""; |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
|
$buf .= " |
121
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==1; |
122
|
0
|
|
|
|
|
|
$buf .= ">( |
123
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==2; |
124
|
0
|
|
|
|
|
|
$buf .= ">(( |
125
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numLeftParen==3; |
126
|
0
|
|
|
|
|
|
$buf .= ">((("; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
$buf .= " | "; |
129
|
0
|
|
|
|
|
|
my $nf = $$o{schema}{named_filters}{$namedFilter}; |
130
|
0
|
0
|
|
|
|
|
if (ref($nf) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
131
|
0
|
|
0
|
|
|
|
my $title = $$nf[2] || $namedFilter; |
132
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
133
|
|
|
|
|
|
|
.'
134
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
135
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif (ref($nf) eq 'HASH') { |
138
|
0
|
0
|
|
|
|
|
if (ref($$nf{html_generator}) eq 'CODE') { |
139
|
|
|
|
|
|
|
#before we call the html_generator, set the params up |
140
|
0
|
|
|
|
|
|
my %args; |
141
|
0
|
|
|
|
|
|
for (my $i=0; $i <= $#$argArray; $i+=2) { |
142
|
0
|
|
|
|
|
|
my $name = $$argArray[$i]; |
143
|
0
|
|
|
|
|
|
my $val = $$argArray[$i + 1]; |
144
|
0
|
|
0
|
|
|
|
$args{$name}||=[]; |
145
|
0
|
|
|
|
|
|
push @{$args{$name}}, $val; |
|
0
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
while (my ($name,$vals) = each %args) { |
148
|
0
|
|
|
|
|
|
$$o{q}->param('_nf_arg_'.$name, @$vals); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
$buf .= |
151
|
|
|
|
|
|
|
'' |
152
|
0
|
|
|
|
|
|
.$$nf{html_generator}->($$o{q}, '_nf_arg_') |
153
|
|
|
|
|
|
|
.''; |
154
|
|
|
|
|
|
|
} else { |
155
|
0
|
|
0
|
|
|
|
my $title = $$nf{title} || $namedFilter; |
156
|
|
|
|
|
|
|
$buf .= ''.escapeHTML($title).'' |
157
|
|
|
|
|
|
|
.'
158
|
|
|
|
|
|
|
.escapeHTML("$namedFilter(" |
159
|
0
|
|
|
|
|
|
.join(',', map { '"'.$_.'"' } @$argArray).")").'">'; |
|
0
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
$buf .= " | "; |
163
|
0
|
0
|
|
|
|
|
if ($numRightParen == 0) { |
164
|
0
|
|
|
|
|
|
$buf .= ""; |
165
|
|
|
|
|
|
|
} else { |
166
|
0
|
|
|
|
|
|
$buf .= " |
167
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==1; |
168
|
0
|
|
|
|
|
|
$buf .= ">) |
169
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==2; |
170
|
0
|
|
|
|
|
|
$buf .= ">)) |
171
|
0
|
0
|
|
|
|
|
$buf .= " selected" if $numRightParen==3; |
172
|
0
|
|
|
|
|
|
$buf .= ">)))"; |
173
|
|
|
|
|
|
|
} |
174
|
0
|
|
|
|
|
|
$buf .= " | | ";
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
else { |
178
|
0
|
|
|
|
|
|
die "invalid typenum: $typenum; this should never happen"; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$buf .= " |
";
183
|
|
|
|
|
|
|
} |
184
|
0
|
|
|
|
|
|
$buf .= " |