3 |
use base 'CGI::Application'; |
use base 'CGI::Application'; |
4 |
use strict; |
use strict; |
5 |
|
|
|
use HTML::Pager; |
|
6 |
use HTML::FillInForm; |
use HTML::FillInForm; |
7 |
use SWISH; |
use SWISH::API; |
8 |
use Text::Iconv; |
use Text::Iconv; |
9 |
use DBI; |
use DBI; |
10 |
use Config::IniFiles; |
use Config::IniFiles; |
11 |
use Text::Unaccent; |
use Text::Unaccent; |
12 |
|
use Data::Pageset; |
13 |
|
use POSIX qw(locale_h); |
14 |
|
|
15 |
use lib '..'; |
use lib '..'; |
16 |
use index_DBI_cache; |
use index_DBI_filter; |
17 |
use back2html; |
use back2html; |
18 |
|
|
19 |
|
|
29 |
my $ON_PAGE =$cfg_global->val('webpac', 'on_page') || 10; |
my $ON_PAGE =$cfg_global->val('webpac', 'on_page') || 10; |
30 |
my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1; |
my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1; |
31 |
my $TEMPLATE =$cfg_global->val('webpac', 'template'); |
my $TEMPLATE =$cfg_global->val('webpac', 'template'); |
32 |
my $UNAC_FILTER =$cfg_global->val('global', 'unac_filter'); |
my $UNAC_FILTER =$cfg_global->val('global', 'my_unac_filter'); |
33 |
my $BASE_PATH =$cfg_global->val('webpac', 'base_path'); |
my $BASE_PATH =$cfg_global->val('webpac', 'base_path'); |
34 |
|
# for pager |
35 |
if ($UNAC_FILTER) { |
my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10; |
36 |
require $UNAC_FILTER; |
my $locale = $cfg_global->val('locale') || 'hr_HR'; |
|
} |
|
37 |
|
|
38 |
Text::Iconv->raise_error(0); # Conversion errors raise exceptions |
Text::Iconv->raise_error(0); # Conversion errors raise exceptions |
39 |
|
|
40 |
my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); |
my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); |
41 |
|
|
42 |
|
setlocale(LC_CTYPE, $locale); |
43 |
|
setlocale(LC_COLLATE, $locale); |
44 |
|
|
45 |
|
if ($UNAC_FILTER) { |
46 |
|
require $UNAC_FILTER; |
47 |
|
} else { |
48 |
|
sub WebPac::my_unac_string { |
49 |
|
my ($charset, $string) = (@_); |
50 |
|
return $string; |
51 |
|
} |
52 |
|
} |
53 |
|
|
54 |
# use path from cgi script to support templates in subdirs |
# use path from cgi script to support templates in subdirs |
55 |
sub url_ex { |
sub url_ex { |
56 |
my $q = shift || die "suff2file needs CGI object!"; |
my $q = shift || die "suff2file needs CGI object!"; |
57 |
my $tpl = shift || die "url_ex needs template name!"; |
my $tpl = shift || die "url_ex needs template name!"; |
58 |
return suff2file($BASE_PATH, $q->url(-path => 1),$TEMPLATE_PATH,$tpl); |
return suff2file($BASE_PATH, $q->url(-absolute => 1,-path => 1),$TEMPLATE_PATH,$tpl); |
59 |
} |
} |
60 |
|
|
61 |
sub suff2file($$$$) { |
sub suff2file($$$$) { |
63 |
|
|
64 |
return $tpl if (! $base_path); |
return $tpl if (! $base_path); |
65 |
|
|
66 |
|
#warn "base_path: $base_path, p: $p, path: $path, tpl: $tpl\n"; |
67 |
|
|
68 |
|
$p =~ s#/[^/]*$##; |
69 |
|
|
70 |
# strip everything to and including base path, leaving only |
# strip everything to and including base path, leaving only |
71 |
# additional (virtual) path |
# additional (virtual) path |
72 |
if ($p =~ s,^.*?$base_path,,) { |
if ($base_path eq "/") { |
73 |
|
$p =~ s,/*,,g; |
74 |
|
my ($name,$ext) = split(/\./,$tpl); |
75 |
|
$p = $name . "-" . $p . "." . $ext; |
76 |
|
} elsif ($p =~ s,^.*?$base_path,,) { |
77 |
$p =~ s,/*,,g; |
$p =~ s,/*,,g; |
78 |
my ($name,$ext) = split(/\./,$tpl); |
my ($name,$ext) = split(/\./,$tpl); |
79 |
$p = $name . $p . "." . $ext; |
$p = $name . $p . "." . $ext; |
117 |
die "can't parse TEMPLATE path"; |
die "can't parse TEMPLATE path"; |
118 |
} |
} |
119 |
|
|
120 |
my $master_tpl = suff2file($BASE_PATH, $q->url(-path => 1),$dir,$tpl); |
my $master_tpl = suff2file($BASE_PATH, $q->url(-absolute => 1, -path => 1),$dir,$tpl); |
121 |
if (open(T, $master_tpl)) { |
if (open(T, $master_tpl)) { |
122 |
my $template_html = join("\n",<T>); |
my $template_html = join("\n",<T>); |
123 |
close(T); |
close(T); |
128 |
} |
} |
129 |
} |
} |
130 |
|
|
131 |
|
#-------------------------------------------------------------------------- |
132 |
|
|
133 |
|
# |
134 |
|
# make pager navigation and fill template variables |
135 |
|
# compatibile with HTML::Pager |
136 |
|
# |
137 |
|
|
138 |
|
sub make_pager($$$) { |
139 |
|
my ($q,$tmpl,$pager) = @_; |
140 |
|
|
141 |
|
# |
142 |
|
# pager navigation |
143 |
|
# |
144 |
|
my ($pager_prev,$pager_next, $pager_jump) = ('','',''); |
145 |
|
|
146 |
|
my $nav_fmt=qq{ <a href="%s">%s</a> }; |
147 |
|
|
148 |
|
if ($pager->current_page() > $pager->first_page) { |
149 |
|
$q->param('PAGER_offset', $pager->current_page - 1); |
150 |
|
$pager_prev .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'<<'); |
151 |
|
} |
152 |
|
|
153 |
|
if ($pager->previous_set) { |
154 |
|
$q->param('PAGER_offset', $pager->previous_set); |
155 |
|
$pager_prev .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'..'); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
foreach my $p (@{$pager->pages_in_set()}) { |
160 |
|
next if ($p <= 0); |
161 |
|
if($p == $pager->current_page()) { |
162 |
|
$pager_jump .= "<b>$p</b> "; |
163 |
|
} else { |
164 |
|
$q->param('PAGER_offset', $p); |
165 |
|
$pager_jump .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),$p); |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
if ($pager->next_set) { |
170 |
|
$q->param('PAGER_offset', $pager->next_set); |
171 |
|
$pager_next .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'..'); |
172 |
|
} |
173 |
|
|
174 |
|
if ($pager->current_page() < $pager->last_page) { |
175 |
|
$q->param('PAGER_offset', $pager->current_page + 1); |
176 |
|
$pager_next .= sprintf($nav_fmt,$q->url(-relative=>1, -query=>1),'>>'); |
177 |
|
} |
178 |
|
|
179 |
|
$tmpl->param('PAGER_PREV', $pager_prev); |
180 |
|
$tmpl->param('PAGER_JUMP', $pager_jump); |
181 |
|
$tmpl->param('PAGER_NEXT', $pager_next); |
182 |
|
|
183 |
|
} |
184 |
|
|
185 |
|
# |
186 |
|
# put persisten variables in template |
187 |
|
# |
188 |
|
|
189 |
|
sub make_pager_vars { |
190 |
|
my $q = shift @_; |
191 |
|
my $tmpl = shift @_; |
192 |
|
my @persist_vars = @_; |
193 |
|
my $hidden_vars = ''; |
194 |
|
my $hidden_search = ''; |
195 |
|
foreach my $v (@persist_vars) { |
196 |
|
foreach my $val ($q->param($v)) { |
197 |
|
next if (! $val || $val eq ''); |
198 |
|
$val =~ s/"/"/g; |
199 |
|
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
200 |
|
$hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm"); |
201 |
|
} |
202 |
|
} |
203 |
|
|
204 |
|
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
205 |
|
$tmpl->param('SEARCH_HIDDEN', $hidden_search); |
206 |
|
$tmpl->param('PAGER_JAVASCRIPT', qq# |
207 |
|
<SCRIPT LANGUAGE="Javascript"> |
208 |
|
<!-- Begin |
209 |
|
// dummy emulator for HTML::Pager templates |
210 |
|
function PAGER_set_offset_and_submit() { |
211 |
|
return true; |
212 |
|
} |
213 |
|
// End --> |
214 |
|
</script> |
215 |
|
#); |
216 |
|
} |
217 |
|
|
218 |
|
#-------------------------------------------------------------------------- |
219 |
|
|
220 |
sub show_search_form { |
sub show_search_form { |
221 |
my $self = shift; |
my $self = shift; |
222 |
|
|
237 |
|
|
238 |
my $q = $self->query(); |
my $q = $self->query(); |
239 |
|
|
240 |
my @swish_results; # results from swish |
# submit was reset? |
241 |
|
if ($q->param('reset')) { |
242 |
|
$q->delete_all; |
243 |
|
return $self->show_search_form(); |
244 |
|
} |
245 |
|
|
246 |
# load template for this page |
# load template for this page |
247 |
|
|
250 |
my @path_arr = $q->param('path'); |
my @path_arr = $q->param('path'); |
251 |
my $full = $q->param('full'); |
my $full = $q->param('full'); |
252 |
|
|
253 |
my @persist_vars = ( 'rm' ); |
my @persist_vars = ( 'rm', 'persist_search' ); |
254 |
my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.$q->param('PAGER_offset') || 0 ); |
my $url_params = { |
255 |
|
'rm' => 'results', |
256 |
|
'show_full' => 1, |
257 |
|
'last_PAGER_offset' => ($q->param('PAGER_offset') || 0), |
258 |
|
}; |
259 |
|
|
260 |
|
my @persist_search_vars; |
261 |
|
my $url_params_persist = {}; |
262 |
|
if ($q->param("persist_search")) { |
263 |
|
@persist_search_vars = split(/\s*,\s*/, $q->param("persist_search")); |
264 |
|
$url_params_persist->{'persist_search'} = $q->url_param("persist_search"); |
265 |
|
$url_params->{'persist_search'} = $q->url_param("persist_search"); |
266 |
|
} |
267 |
|
|
268 |
# support parametars "f" and "v" for start |
# support parametars "f" and "v" for start |
269 |
for(my $i = ""; $i <=30; $i++) { |
for(my $i = 0; $i <=30; $i++) { |
270 |
|
|
271 |
|
$i = '' if ($i == 0); |
272 |
|
|
273 |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
274 |
|
|
275 |
next if (! $q->param("v$i")); |
next if (! $q->param("v$i") || $q->param("v$i") eq ''); |
276 |
next if (! $q->param("f$i")); |
next if (! $q->param("f$i")); |
277 |
|
|
278 |
|
my $persist = grep(/^$i$/,@persist_search_vars); |
279 |
|
|
280 |
push @persist_vars, "f$i"; |
push @persist_vars, "f$i"; |
281 |
push @persist_vars, "v$i"; |
push @persist_vars, "v$i"; |
282 |
push @persist_vars, "e$i" if ($q->param("e$i")); |
push @persist_vars, "e$i" if ($q->param("e$i")); |
283 |
|
|
284 |
push @url_params,"f$i=".$q->url_param("f$i"); |
# create url parametars (and persistent ones) |
285 |
|
|
286 |
|
$url_params->{"f$i"} = $q->url_param("f$i"); |
287 |
|
$url_params_persist->{"f$i"} = $q->url_param("f$i") if ($persist); |
288 |
|
|
289 |
|
my @v; |
290 |
|
|
291 |
foreach my $v ($q->url_param("v$i")) { |
foreach my $v ($q->url_param("v$i")) { |
292 |
push @url_params,"v$i=$v"; |
# escape quotes so that phrase search work |
293 |
|
$v =~ s/"/%22/g; |
294 |
|
push @v, $v; |
295 |
|
} |
296 |
|
$url_params->{"v$i"} = \@v; |
297 |
|
$url_params_persist->{"v$i"} = \@v if ($persist); |
298 |
|
|
299 |
|
if ($q->param("e$i")) { |
300 |
|
$url_params->{"e$i"} = $q->url_param("e$i"); |
301 |
|
# $url_params_persist->{"e$i"} = $q->url_param("e$i"); |
302 |
} |
} |
|
push @url_params,"e$i=".$q->url_param("e$i"); |
|
303 |
|
|
304 |
my $wc="*"; # swish wildcard |
my $wc="*"; # swish wildcard |
305 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
311 |
while (my $search = shift @param_vals) { |
while (my $search = shift @param_vals) { |
312 |
my $s; |
my $s; |
313 |
# remove accents |
# remove accents |
314 |
$search = unac_string($CHARSET,$search); |
$search = my_unac_string($CHARSET,$search); |
315 |
while ($search =~ s/\s*("[^"]+")\s*/ /) { |
while ($search =~ s/\s*("[^"]+")\s*/ /) { |
316 |
$s .= "$1 "; |
$s .= "$1 "; |
317 |
} |
} |
320 |
|
|
321 |
# filed e[nr] is exact match bitmask |
# filed e[nr] is exact match bitmask |
322 |
# 1 = beginning, 2=end, 3=both |
# 1 = beginning, 2=end, 3=both |
323 |
$pre = '"xxbxx ' if ($q->param("e$i") & 1); |
my $exact_flag = $q->param("e$i") || 0; |
324 |
$post = ' xxexx"' if ($q->param("e$i") & 2); |
$pre = '"xxbxx ' if ($exact_flag & 1); |
325 |
|
$post = ' xxexx"' if ($exact_flag & 2); |
326 |
# add qotes on other side |
# add qotes on other side |
327 |
if ($q->param("e$i")) { |
if ($q->param("e$i")) { |
328 |
$pre = '"' if (! $pre); |
$pre = '"' if (! $pre); |
348 |
} |
} |
349 |
} |
} |
350 |
$s =~ s/\*+/*/g; |
$s =~ s/\*+/*/g; |
351 |
|
$s =~ s/[()]//g; # () are used in query language |
352 |
$s = $pre.$s.$post if ($q->param("e$i")); |
$s = $pre.$s.$post if ($q->param("e$i")); |
353 |
push @swish_q,$s; |
push @swish_q,$s; |
354 |
} |
} |
357 |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
358 |
} |
} |
359 |
|
|
360 |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); |
361 |
|
|
362 |
sub esc_html { |
sub esc_html { |
363 |
my $html = shift; |
my $html = shift; |
372 |
push @persist_vars, "sort"; |
push @persist_vars, "sort"; |
373 |
} |
} |
374 |
|
|
375 |
# call swish |
my $sortby = $q->param("sortby"); |
376 |
my $sh = SWISH->connect('Fork', |
if ($sortby) { |
377 |
prog => $SWISH, |
$sort = $sortby; |
378 |
indexes => $INDEX, |
push @persist_vars, "sortby"; |
379 |
properties => [qw/swishdocpath swishrank swishtitle headline html/], |
} |
380 |
results => sub { |
# used to filter entries in index and swish |
381 |
my ($sh,$hit) = @_; |
my $filter = $q->param("filter"); |
|
|
|
|
push @swish_results, { |
|
|
nr => ($#swish_results + 2), |
|
|
path => $hit->swishdocpath, |
|
|
headline => esc_html($from_utf8->convert($hit->headline)), |
|
|
html => back2html($from_utf8->convert($hit->html)), |
|
|
rank => $hit->swishrank }; |
|
|
|
|
|
}, |
|
|
#startnum => 0, |
|
|
maxhits => $MAX_HITS, |
|
|
sortorder => $sort, |
|
|
); |
|
382 |
|
|
|
die $SWISH::errstr unless $sh; |
|
383 |
# construct swish query |
# construct swish query |
384 |
my $sw_q = join(" and ",@s_arr); |
my $sw_q = join(" and ",@s_arr); |
385 |
if (@path_arr && $q->param('show_full')) { |
if (@path_arr && $q->param('show_full')) { |
386 |
$sw_q .= "and (swishdocpath=\""; |
$sw_q .= " and (swishdocpath=\""; |
387 |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
388 |
$sw_q .= "\")"; |
$sw_q .= "\")"; |
389 |
$tmpl->param('full',1); # show full records |
$tmpl->param('full',1); # show full records |
390 |
|
# } elsif (@path_arr && $#path_arr == 0) { |
391 |
|
# # I will assume that it's a filter since there isn't show_full |
392 |
|
# $filter = shift @path_arr; |
393 |
} elsif ($q->param('show_full')) { |
} elsif ($q->param('show_full')) { |
394 |
# just show full path, no path defined |
# just show full path, no path defined |
395 |
$tmpl->param('full',1); |
$tmpl->param('full',1); |
397 |
$tmpl->param('full',0); |
$tmpl->param('full',0); |
398 |
} |
} |
399 |
|
|
400 |
my $hits = $sh->query($sw_q); |
if ($filter) { |
401 |
|
$sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr); |
402 |
|
push @persist_vars, "filter"; |
403 |
|
$url_params->{'filter'} = $filter; |
404 |
|
$url_params_persist->{'filter'} = $filter; |
405 |
|
} |
406 |
|
|
407 |
|
my $swish_msg = ' '; |
408 |
|
|
409 |
|
# create new swish instance |
410 |
|
my $swish = SWISH::API->new($INDEX); |
411 |
|
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
412 |
|
|
413 |
|
# execute query and get number of results from SWISH-E |
414 |
|
my $search = $swish->New_Search_Object; |
415 |
|
|
416 |
|
$search->SetSort($sort); |
417 |
|
|
418 |
|
my $results = $search->Execute($sw_q); |
419 |
|
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
420 |
|
|
421 |
|
my $hits = $results->Hits; |
422 |
|
|
423 |
$tmpl->param('hits',$hits); |
$tmpl->param('hits',$hits); |
424 |
$tmpl->param('search',$sw_q); |
my $search_msg = $sw_q; |
425 |
|
$search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg); |
426 |
|
$tmpl->param('search', $search_msg); |
427 |
|
|
428 |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
429 |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
430 |
|
|
431 |
$tmpl->param('url_params',"?".join("&",@url_params)); |
# URL parametars for search results |
432 |
|
sub cook_url_params { |
433 |
# create a Pager object |
my $hash = shift || return; |
434 |
my $pager = HTML::Pager->new( |
return join("&", map { |
435 |
# required parameters |
my $var = $_; |
436 |
query => $q, |
if (ref($hash->{$var}) eq 'ARRAY') { |
437 |
get_data_callback => sub { |
join('&', |
438 |
my ($offset, $rows) = @_; |
map { $var.'='.$_ } @{$hash->{$var}} |
439 |
|
); |
440 |
my @result; |
} else { |
441 |
for (my $i=0; $i<$rows; $i++) { |
$var."=".$hash->{$var}; |
|
my $r = $swish_results[$offset+$i]; |
|
|
if ($r && $tmpl->param('full')) { |
|
|
push @result, $r; |
|
|
} elsif ($r) { |
|
|
# if not full output, skip html |
|
|
delete $r->{html}; |
|
|
push @result, $r; |
|
|
} |
|
442 |
} |
} |
443 |
return \@result; |
} keys %{$hash}); |
444 |
}, |
} |
445 |
rows => $hits, |
|
446 |
page_size => $ON_PAGE, |
$tmpl->param('url_params',"?".cook_url_params($url_params)); |
447 |
# some optional parameters |
$tmpl->param('url_params_paths',"?".cook_url_params($url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
448 |
persist_vars => [ @persist_vars ], |
|
449 |
#cell_space_color => '#000000', |
|
450 |
#cell_background_color => '#ffffff', |
|
451 |
#nav_background_color => '#dddddd', |
# |
452 |
#javascript_presubmit => 'last_minute_javascript()', |
# build pager |
453 |
debug => 1, |
# |
454 |
template => $tmpl, |
|
455 |
); |
my $current_page = $q->param('PAGER_offset') || 1; |
456 |
|
|
457 |
my $html = $pager->output; |
my $pager = Data::Pageset->new({ |
458 |
|
'total_entries' => $hits, |
459 |
|
'entries_per_page' => $ON_PAGE, |
460 |
|
'current_page' => $current_page, |
461 |
|
'pages_per_set' => $pages_per_set, |
462 |
|
}); |
463 |
|
|
464 |
|
$results->SeekResult( $pager->first - 1 ); |
465 |
|
|
466 |
|
# get number of entries on this page |
467 |
|
my $i = $pager->entries_on_this_page; |
468 |
|
|
469 |
|
# results from swish for template |
470 |
|
my @pager_data_list; |
471 |
|
|
472 |
|
for(my $i=$pager->first; $i<=$pager->last; $i++) { |
473 |
|
|
474 |
|
my $result = $results->NextResult; |
475 |
|
last if (! $result); |
476 |
|
|
477 |
|
my $r = { |
478 |
|
nr => $i, |
479 |
|
path => $result->Property('swishdocpath'), |
480 |
|
headline => esc_html($from_utf8->convert($result->Property('headline'))), |
481 |
|
rank => $result->Property('swishrank') |
482 |
|
}; |
483 |
|
|
484 |
|
#$r->{html} = back2html($from_utf8->convert($result->Property('html')), cook_url_params($url_params_persist)) if ($q->param('show_full')); |
485 |
|
$r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full')); |
486 |
|
|
487 |
|
push @pager_data_list, $r; |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
# put something in template |
493 |
|
make_pager($q, $tmpl, $pager); |
494 |
|
make_pager_vars($q, $tmpl, @persist_vars); |
495 |
|
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
496 |
|
|
497 |
|
my $html = $tmpl->output; |
498 |
|
|
499 |
return in_template($q,$html); |
return in_template($q,$html); |
500 |
} |
} |
508 |
my $field = $q->param("f$i"); |
my $field = $q->param("f$i"); |
509 |
my $limit = $q->param("v$i"); |
my $limit = $q->param("v$i"); |
510 |
|
|
511 |
|
my $filter = $q->param("filter"); |
512 |
|
|
513 |
my $html; |
my $html; |
514 |
|
|
515 |
my $index = new index_DBI( |
my $index = new index_DBI( |
519 |
$cfg_global->val('global', 'dbi_passwd') || '' |
$cfg_global->val('global', 'dbi_passwd') || '' |
520 |
); |
); |
521 |
|
|
522 |
my $total = $index->count($field,$limit); |
my $total = $index->count($field,$limit,$filter); |
523 |
if (! $total) { |
|
524 |
|
if (! defined($total)) { |
525 |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
526 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
527 |
$html = $tmpl->output; |
$html = $tmpl->output; |
528 |
return $html; |
return $html; |
529 |
} |
} |
530 |
|
|
531 |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0); |
532 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
533 |
$tmpl->param('limit',$limit); |
$tmpl->param('limit',$limit); |
534 |
$tmpl->param('total',$total); |
$tmpl->param('total',$total); |
535 |
|
$tmpl->param('filter',$filter); |
536 |
|
|
537 |
# FIXME I should set offset and leave out limit from fetch!! |
# FIXME I should set offset and leave out limit from fetch!! |
538 |
# if (! $q->param("PAGER_offset") { |
# if (! $q->param("PAGER_offset") { |
539 |
# $q->param("Pager_offet) |
# $q->param("Pager_offet) |
540 |
# } |
# } |
541 |
|
|
|
my $pager = HTML::Pager->new( |
|
|
query => $q, |
|
|
get_data_callback => sub { |
|
|
my ($offset, $rows) = @_; |
|
|
|
|
|
my @result = $index->fetch($field,$limit, $offset, $rows); |
|
|
return \@result; |
|
|
}, |
|
|
rows => $total, |
|
|
page_size => $ON_PAGE, |
|
|
persist_vars => [ |
|
|
'rm', |
|
|
"f$i", "v$i", "f".$i."_index", |
|
|
'offset', |
|
|
], |
|
|
debug => 1, |
|
|
template => $tmpl, |
|
|
); |
|
542 |
|
|
543 |
return in_template($q,$pager->output); |
# |
544 |
|
# build pager |
545 |
|
# |
546 |
|
my $pager = Data::Pageset->new({ |
547 |
|
'total_entries' => $total, |
548 |
|
'entries_per_page' => $ON_PAGE, |
549 |
|
'current_page' => $q->param('PAGER_offset') || 1, |
550 |
|
'pages_per_set' => $pages_per_set |
551 |
|
}); |
552 |
|
|
553 |
|
my @persist_vars = qw{rm f$i v$i f$i_index offset}; |
554 |
|
|
555 |
|
make_pager($q, $tmpl, $pager); |
556 |
|
make_pager_vars($q, $tmpl, @persist_vars); |
557 |
|
|
558 |
|
my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page, $filter); |
559 |
|
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
560 |
|
|
561 |
|
return in_template($q,$tmpl->output); |
562 |
} |
} |
563 |
|
|
564 |
1; |
1; |