/[webpac]/trunk/WebPac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/WebPac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by dpavlin, Sun Jun 1 18:49:49 2003 UTC revision 789 by dpavlin, Mon May 25 13:49:51 2009 UTC
# Line 3  package WebPac; Line 3  package WebPac;
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;
12    use Data::Pageset;
13    use POSIX qw(locale_h);
14    
15  use lib '..';  use lib '..';
16  use index_DBI;  use index_DBI_filter;
17  use back2html;  use back2html;
18    
19  # configuration options  
20  # FIXME they really should go in configuration file!  # read global.conf configuration
21  my $TEMPLATE_PATH = '/data/webpac/template_html';  my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'";
22  my $CHARSET = 'ISO-8859-2';  
23  my $SWISH = '/usr/bin/swish-e';  # configuration options from global.conf
24  my $INDEX = '/data/webpac/index/isis.index';  my $TEMPLATE_PATH = $cfg_global->val('webpac', 'template_html') || die "need template_html in global.conf, section webpac";
25  my $MAX_HITS = 500;  my $CHARSET = $cfg_global->val('webpac', 'charset') || 'ISO-8859-1';
26  my $ON_PAGE = 10;  my $SWISH = $cfg_global->val('webpac', 'swish') || '/usr/bin/swish-e';
27    my $INDEX = $cfg_global->val('webpac', 'index') || die "need index in global.conf, section webpac";
28    my $MAX_HITS = $cfg_global->val('webpac', 'max_hits') || 0;
29    my $ON_PAGE =$cfg_global->val('webpac', 'on_page') || 10;
30    my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1;
31    my $TEMPLATE =$cfg_global->val('webpac', 'template');
32    my $UNAC_FILTER =$cfg_global->val('global', 'my_unac_filter');
33    my $BASE_PATH =$cfg_global->val('webpac', 'base_path');
34    # for pager
35    my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;
36    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  # read global.conf configuration  setlocale(LC_CTYPE, $locale);
43  my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'";  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
55    sub url_ex {
56            my $q = shift || die "suff2file needs CGI object!";
57            my $tpl = shift || die "url_ex needs template name!";
58            return suff2file($BASE_PATH, $q->url(-absolute => 1,-path => 1),$TEMPLATE_PATH,$tpl);
59    }
60    
61    sub suff2file($$$$) {
62            my ($base_path, $p, $path, $tpl) = @_;
63    
64            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
71            # additional (virtual) path
72            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;
78                    my ($name,$ext) = split(/\./,$tpl);
79                    $p = $name . $p . "." . $ext;
80            } else {
81                    # if unable reset it!
82                    $p = $tpl;
83            }
84    
85            if ( -e "$path/$p") {
86                    return $p;
87            } else {
88                    return $tpl;
89            }
90    
91    }
92    
93  sub setup {  sub setup {
94          my $self = shift;          my $self = shift;
# Line 46  sub setup { Line 105  sub setup {
105          $self->header_props(-charset=>$CHARSET);          $self->header_props(-charset=>$CHARSET);
106  }  }
107    
108    sub in_template {
109            my $q = shift || die "need CGI object!";
110            my $html = shift || die "This page is left unintentionally blank";
111            return $html if (! defined($TEMPLATE));
112    
113            my ($dir,$tpl);
114            if ($TEMPLATE =~ m,^(.*?/*)([^/]+)$,) {
115                    ($dir,$tpl) = ($1,$2);
116            } else {
117                    die "can't parse TEMPLATE path";
118            }
119    
120            my $master_tpl = suff2file($BASE_PATH, $q->url(-absolute => 1, -path => 1),$dir,$tpl);
121            if (open(T, $master_tpl)) {
122                    my $template_html = join("\n",<T>);
123                    close(T);
124                    $template_html =~ s/##webpac##/$html/gsi;
125                    return $template_html;
126            } else {
127                    return "Can't read template '$master_tpl'";
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            sub url_with_params {
147                    my ($q,$text) = @_;
148                    my %param = $q->Vars;
149                    my @p;
150                    foreach my $p ( keys %param ) {
151                            my $v = $param{$p};
152                            next unless defined $v and length($v) > 0;
153                            if ( $v =~ m{\0} ) {
154                                    push @p, $p . '=' . my_unac_string($CHARSET, $_)
155                                            foreach (split(/\0/, $v ));
156                            } else {
157                                    push @p, $p . '=' . my_unac_string($CHARSET, $v);
158                            }
159                    }
160    
161                    return
162                      qq{ <a href="}
163                    . $q->url( -relative => 1 )
164                    . '?'
165                    . join(';', @p)
166                    . qq{">$text</a> };
167            }
168    
169            if ($pager->current_page() > $pager->first_page) {
170                    $q->param('PAGER_offset', $pager->current_page - 1);
171                    $pager_prev .= url_with_params( $q, '&lt;&lt;');
172            }
173    
174            if ($pager->previous_set) {
175                    $q->param('PAGER_offset', $pager->previous_set);
176                    $pager_prev .= url_with_params( $q,'..');
177            }
178    
179    
180            foreach my $p (@{$pager->pages_in_set()}) {
181                    next if ($p <= 0);
182                    if($p == $pager->current_page()) {
183                            $pager_jump .= "<b>$p</b> ";
184                    } else {
185                            $q->param('PAGER_offset', $p);
186                            $pager_jump .= url_with_params($q,$p);
187                    }
188            }
189    
190            if ($pager->next_set) {
191                    $q->param('PAGER_offset', $pager->next_set);
192                    $pager_next .= url_with_params($q,'..');
193            }
194    
195            if ($pager->current_page() < $pager->last_page) {
196                    $q->param('PAGER_offset', $pager->current_page + 1);
197                    $pager_next .= url_with_params($q,'&gt;&gt;');
198            }
199    
200            $tmpl->param('PAGER_PREV', $pager_prev);
201            $tmpl->param('PAGER_JUMP', $pager_jump);
202            $tmpl->param('PAGER_NEXT', $pager_next);
203    
204    }
205    
206    #
207    # put persisten variables in template
208    #
209    
210    sub make_pager_vars {
211            my $q = shift @_;
212            my $tmpl = shift @_;
213            my @persist_vars = @_;
214            my $hidden_vars = '';
215            my $hidden_search = '';
216            foreach my $v (@persist_vars) {
217                    foreach my $val ($q->param($v)) {
218                            next if (! $val || $val eq '');
219                            $val =~ s/"/&quot;/g;
220                            $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
221                            $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");
222                    }
223            }
224    
225            $tmpl->param('PAGER_HIDDEN', $hidden_vars);
226            $tmpl->param('SEARCH_HIDDEN', $hidden_search);
227            $tmpl->param('PAGER_JAVASCRIPT', qq#
228    <SCRIPT LANGUAGE="Javascript">
229    <!-- Begin
230            // dummy emulator for HTML::Pager templates
231            function PAGER_set_offset_and_submit() {
232                    return true;
233            }
234    // End -->
235    </script>  
236            #);
237    }
238    
239    #--------------------------------------------------------------------------
240    
241  sub show_search_form {  sub show_search_form {
242          my $self = shift;          my $self = shift;
243    
244          # Get the CGI.pm query object          # Get the CGI.pm query object
245          my $q = $self->query();          my $q = $self->query();
246    
247          my $tmpl = $self->load_tmpl('search.html');          my $tmpl = $self->load_tmpl(url_ex($q,'search.html'));
248          my $html = $tmpl->output;          my $html = $tmpl->output;
249    
250          my $fif = new HTML::FillInForm;          my $fif = new HTML::FillInForm;
251    
252          return $fif->fill(scalarref => \$html, fobject => $q,          return in_template($q,$fif->fill(scalarref => \$html, fobject => $q,
253                  target => 'search');                  target => 'search'));
254  }  }
255    
256  sub show_results_list {  sub show_results_list {
# Line 66  sub show_results_list { Line 258  sub show_results_list {
258    
259          my $q = $self->query();          my $q = $self->query();
260    
261          my @swish_results;      # results from swish          # submit was reset?
262            if ($q->param('reset')) {
263                    $q->delete_all;
264                    return $self->show_search_form();
265            }
266    
267          # load template for this page          # load template for this page
268    
# Line 75  sub show_results_list { Line 271  sub show_results_list {
271          my @path_arr = $q->param('path');          my @path_arr = $q->param('path');
272          my $full = $q->param('full');          my $full = $q->param('full');
273    
274          for(my $i = 1; $i <=10; $i++) {          my @persist_vars = ( 'rm', 'persist_search' );
275            my $url_params = {
276                    'rm' => 'results',
277                    'show_full' => 1,
278                    'last_PAGER_offset' => ($q->param('PAGER_offset') || 0),
279            };
280    
281            my @persist_search_vars;
282            my $url_params_persist = {};
283            if ($q->param("persist_search")) {
284                    @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
285                    $url_params_persist->{'persist_search'} = $q->url_param("persist_search");
286                    $url_params->{'persist_search'} = $q->url_param("persist_search");
287            }
288    
289            # support parametars "f" and "v" for start
290            for(my $i = 0; $i <=30; $i++) {
291    
292                    $i = '' if ($i == 0);
293    
294                  return show_index($self, $i) if ($q->param("f".$i."_index"));                  return show_index($self, $i) if ($q->param("f".$i."_index"));
295    
296                    next if (! $q->param("v$i") || $q->param("v$i") eq '');
297                  next if (! $q->param("f$i"));                  next if (! $q->param("f$i"));
298                  next if (! $q->param("v$i"));  
299                    my $persist = grep(/^$i$/,@persist_search_vars);
300            
301                    push @persist_vars, "f$i";
302                    push @persist_vars, "v$i";
303                    push @persist_vars, "e$i" if ($q->param("e$i"));
304    
305                    # create url parametars (and persistent ones)
306    
307                    $url_params->{"f$i"} = $q->url_param("f$i");
308                    $url_params_persist->{"f$i"} = $q->url_param("f$i") if ($persist);
309    
310                    my @v;
311    
312                    foreach my $v ($q->url_param("v$i")) {
313                            # escape quotes so that phrase search work
314                            $v =~ s/"/%22/g;
315                            push @v, $v;
316                    }
317                    $url_params->{"v$i"} = \@v;
318                    $url_params_persist->{"v$i"} = \@v if ($persist);
319    
320                    if ($q->param("e$i")) {
321                            $url_params->{"e$i"} = $q->url_param("e$i");
322    #                       $url_params_persist->{"e$i"} = $q->url_param("e$i");
323                    }
324    
325                    my $wc="*";     # swish wildcard
326                    $wc="" if ($i eq "");   # don't apply wildcard on field 0
327    
328                  # re-write query from +/- to and/and not                  # re-write query from +/- to and/and not
329                  my $s;                  my @param_vals = $q->param("v$i");
330                  my $search = $q->param("v$i");                  my @swish_q;
331                  while ($search =~ s/\s*("[^"]+")\s*/ /) {                  my ($pre,$post,$exact) = ('','','');
332                          $s .= "$1 ";                  while (my $search = shift @param_vals) {
333                  }                          my $s;
334                  $search =~ s/^\s+//;                          # remove accents
335                  $search =~ s/\s+$//;                          $search = my_unac_string($CHARSET,$search);
336                            while ($search =~ s/\s*("[^"]+")\s*/ /) {
337                  foreach (split(/\s+/,$search)) {                                  $s .= "$1 ";
                         if (m/^([+-])(\S+)/) {  
                                 $s.= ($s) ? "and " : "";  
                                 $s.="not " if ($1 eq "-");  
                                 $s.="$2* ";  
                         } elsif (m/(and|or|not)/i) {  
                                 $s.="$_ ";  
                         } else {  
                                 $s.="$_* ";  
338                          }                          }
339                  }                          $search =~ s/^\s+//;
340                  $s =~ s/\*+/*/g;                          $search =~ s/\s+$//;
341    
342                  push @s_arr,$q->param("f$i")."_swish=($s)";                          # filed e[nr] is exact match bitmask
343                            # 1 = beginning, 2=end, 3=both
344                            my $exact_flag = $q->param("e$i") || 0;
345                            $pre = '"xxbxx ' if ($exact_flag & 1);
346                            $post = ' xxexx"' if ($exact_flag & 2);
347                            # add qotes on other side
348                            if ($q->param("e$i")) {
349                                    $pre = '"' if (! $pre);
350                                    $post = '"' if (! $post);
351                                    # what about wildcards?
352                                    $wc = '';
353                                    $wc = '*' if ($q->param("e$i") & 4);
354                                    $exact = '_exact';
355                            }
356    
357                            foreach (split(/\s+/,$search)) {
358                                    if (m/^([+-])(\S+)/) {
359                                            $s.= ($s) ? "and " : "";
360                                            $s.="not " if ($1 eq "-");
361                                            $s.=$2.$wc." ";
362                                    } elsif (m/^\s*(and|or|not)\s*$/i) {
363                                            $s.=$_." ";
364                                    # don't add * to words with less than x chars
365                                    } elsif (length($_) <= $MIN_WILDCARD) {
366                                            $s.=$_." ";
367                                    } else {
368                                            $s.=$_.$wc." ";
369                                    }
370                            }
371                            $s =~ s/\*+/*/g;
372                            $s =~ s/[()]//g;        # () are used in query language
373                            $s = $pre.$s.$post if ($q->param("e$i"));
374                            push @swish_q,$s;
375                    }
376                    # FIXME default operator for multi-value fields is or. There is
377                    # no way to change it, except here for now. Is there need?
378                    push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";
379          }          }
380    
381          my $tmpl = $self->load_tmpl('results.html');          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0);
382    
383          # call swish          sub esc_html {
384          my $sh = SWISH->connect('Fork',                  my $html = shift;
385                  prog     => $SWISH,                  $html =~ s/</&lt;/g;
386                  indexes  => $INDEX,                  $html =~ s/>/&gt;/g;
387                  properties  => [qw/swishdocpath swishrank swishtitle headline html/],                  return $html;
388                  results  => sub {          }
                         my ($sh,$hit) = @_;  
   
                         push @swish_results, {  
                                 nr => ($#swish_results + 2),  
                                 path => $hit->swishdocpath,  
                                 headline => $from_utf8->convert($hit->headline),  
                                 html => back2html($from_utf8->convert($hit->html)),  
                                 rank => $hit->swishrank };  
   
                 },  
                 #startnum => 0,  
                 maxhits => $MAX_HITS  
         );  
389    
390          die $SWISH::errstr unless $sh;          my $sort = 'swishrank';
391            if ($q->param("sort")) {
392                    $sort = 'headline';
393                    push @persist_vars, "sort";
394            }
395    
396            my $sortby = $q->param("sortby");
397            if ($sortby) {
398                    $sort = $sortby;
399                    push @persist_vars, "sortby";
400            }
401            # used to filter entries in index and swish
402            my $filter = $q->param("filter");
403    
404          # construct swish query          # construct swish query
405          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
406          if (@path_arr) {          if (@path_arr && $q->param('show_full')) {
407                  $sw_q .= "and (swishdocpath=\"";                  $sw_q .= " and (swishdocpath=\"";
408                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);
409                  $sw_q .= "\")";                  $sw_q .= "\")";
410                  $tmpl->param('full',1); # show full records                  $tmpl->param('full',1); # show full records
411    #       } elsif (@path_arr && $#path_arr == 0) {
412    #               # I will assume that it's a filter since there isn't show_full
413    #               $filter = shift @path_arr;
414            } elsif ($q->param('show_full')) {
415                    # just show full path, no path defined
416                    $tmpl->param('full',1);
417            } else {
418                    $tmpl->param('full',0);
419            }
420    
421            if ($filter) {
422                    $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr);
423                    push @persist_vars, "filter";
424                    $url_params->{'filter'} = $filter;
425                    $url_params_persist->{'filter'} = $filter;
426          }          }
427    
428          my $hits = $sh->query($sw_q);          my $swish_msg = ' ';
429    
430            # create new swish instance
431            my $swish = SWISH::API->new($INDEX);
432            $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
433    
434            # execute query and get number of results from SWISH-E
435            my $search = $swish->New_Search_Object;
436    
437            $search->SetSort($sort);
438    
439            my $results = $search->Execute($sw_q);
440            $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
441    
442            my $hits = $results->Hits;
443    
444          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
445          $tmpl->param('search',$sw_q);          my $search_msg = $sw_q;
446            $search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg);
447            $tmpl->param('search', $search_msg);
448    
449          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
450          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
451    
452          # create a Pager object          # URL parametars for search results
453          my $pager = HTML::Pager->new(          sub cook_url_params {
454                  # required parameters                  my $hash = shift || return;
455                  query => $q,                  return join("&", map {
456                  get_data_callback => sub {                          my $var = $_;
457                          my ($offset, $rows) = @_;                          if (ref($hash->{$var}) eq 'ARRAY') {
458                                    join('&',
459                          my @result;                                          map { $var.'='.$_ } @{$hash->{$var}}
460                          for (my $i=0; $i<$rows; $i++) {                                  );
461                                  push @result, $swish_results[$offset+$i] if $swish_results[$offset+$i];                          } else {
462                                    $var."=".$hash->{$var};
463                          }                          }
464                          return \@result;                  } keys %{$hash});
465                  },          }
466                  rows => $hits,  
467                  page_size => $ON_PAGE,          $tmpl->param('url_params',"?".cook_url_params($url_params));
468                  # 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));
469                  persist_vars => [  
470                          'rm',  
471                          'f1', 'v1',  
472                          'f2', 'v2',          #
473                          'f3', 'v3',          # build pager
474                          'f4', 'v4',          #
475                          'f5', 'v5',  
476                          'f6', 'v6',          my $current_page = $q->param('PAGER_offset') || 1;
477                          'f7', 'v7',  
478                          'f8', 'v8',          my $pager = Data::Pageset->new({
479                          'f9', 'v9',                  'total_entries' => $hits,
480                          ],                  'entries_per_page' => $ON_PAGE,
481                  #cell_space_color => '#000000',                  'current_page' => $current_page,
482                  #cell_background_color => '#ffffff',                  'pages_per_set' => $pages_per_set,
483                  #nav_background_color => '#dddddd',          });
484                  #javascript_presubmit => 'last_minute_javascript()',  
485                  debug => 1,          $results->SeekResult( $pager->first - 1 );
486                  template => $tmpl,  
487          );          # get number of entries on this page
488            my $i = $pager->entries_on_this_page;
489    
490            # results from swish for template
491            my @pager_data_list;
492    
493            for(my $i=$pager->first; $i<=$pager->last; $i++) {
494    
495                    my $result = $results->NextResult;
496                    last if (! $result);
497    
498                    my $r = {
499                            nr => $i,
500                            path => $result->Property('swishdocpath'),
501                            headline => esc_html($from_utf8->convert($result->Property('headline'))),
502                            rank => $result->Property('swishrank')
503                    };
504    
505          my $html = $pager->output;                  #$r->{html} = back2html($from_utf8->convert($result->Property('html')), cook_url_params($url_params_persist)) if ($q->param('show_full'));
506                    $r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full'));
507    
508          return $html;                  push @pager_data_list, $r;
509            }
510    
511    
512    
513            # put something in template
514            make_pager($q, $tmpl, $pager);
515            make_pager_vars($q, $tmpl, @persist_vars);
516            $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
517    
518            my $html = $tmpl->output;
519    
520            return in_template($q,$html);
521  }  }
522    
523  sub show_index {  sub show_index {
# Line 197  sub show_index { Line 529  sub show_index {
529          my $field = $q->param("f$i");          my $field = $q->param("f$i");
530          my $limit = $q->param("v$i");          my $limit = $q->param("v$i");
531    
532            my $filter = $q->param("filter");
533    
534          my $html;          my $html;
535    
536          my $index = new index_DBI(          my $index = new index_DBI(
# Line 206  sub show_index { Line 540  sub show_index {
540                  $cfg_global->val('global', 'dbi_passwd') || ''                  $cfg_global->val('global', 'dbi_passwd') || ''
541          );          );
542    
543          my $total = $index->check($field);          my $total = $index->count($field,$limit,$filter);
544          if (! $total) {  
545                  my $tmpl = $self->load_tmpl('no_index.html');          if (! defined($total)) {
546                    my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
547                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
548                  $html = $tmpl->output;                  $html = $tmpl->output;
549                  return $html;                  return $html;
550          }          }
551    
552          my $tmpl = $self->load_tmpl('index_res.html');          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0);
553          $tmpl->param('field',$field);          $tmpl->param('field',$field);
554          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
555          $tmpl->param('total',$total);          $tmpl->param('total',$total);
556            $tmpl->param('filter',$filter);
557    
558  # FIXME I should set offset and leave out limit from fetch!!  # FIXME I should set offset and leave out limit from fetch!!
559  #       if (! $q->param("PAGER_offset") {  #       if (! $q->param("PAGER_offset") {
560  #               $q->param("Pager_offet)  #               $q->param("Pager_offet)
561  #       }  #       }
562    
         my $pager = HTML::Pager->new(  
                 query => $q,  
                 get_data_callback => sub {  
                         my ($offset, $rows) = @_;  
   
                         my @result = $index->fetch($field,'item',$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,  
         );  
563    
564          return $pager->output;          #
565            # build pager
566            #
567            my $pager = Data::Pageset->new({
568                    'total_entries' => $total,
569                    'entries_per_page' => $ON_PAGE,
570                    'current_page' => $q->param('PAGER_offset') || 1,
571                    'pages_per_set' => $pages_per_set
572            });
573    
574            my @persist_vars = qw{rm f$i v$i f$i_index offset};
575    
576            make_pager($q, $tmpl, $pager);
577            make_pager_vars($q, $tmpl, @persist_vars);
578    
579            my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page, $filter);
580            $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
581    
582            return in_template($q,$tmpl->output);
583  }  }
584    
585  1;  1;

Legend:
Removed from v.53  
changed lines
  Added in v.789

  ViewVC Help
Powered by ViewVC 1.1.26