/[webpac2]/trunk/vhost/webpac2.cgi
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/vhost/webpac2.cgi

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

revision 1138 by dpavlin, Wed Apr 22 10:14:56 2009 UTC revision 1142 by dpavlin, Thu Apr 23 10:59:00 2009 UTC
# Line 13  use Data::Dump qw/dump/; Line 13  use Data::Dump qw/dump/;
13    
14  my $range_around = 5;  my $range_around = 5;
15  my $entries_per_page = 30;  my $entries_per_page = 30;
16    my $debug = param('debug');
17    
18  print header;  print header(
19            -charset => 'utf-8',
20    );
21    
22  sub dump_yaml {  sub dump_yaml {
23          my $name = shift;          my $name = shift;
24          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>| if $debug;
25  }  }
26    
27  sub show_pages {  sub show_pager {
28          my ($pager,$coderef) = @_;          my ($pager) = @_;
29    
30          my @show_pages;          my @show_pages;
31          my $after_current = 0;          my $after_current = 0;
# Line 34  sub show_pages { Line 37  sub show_pages {
37                  @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );                  @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );
38          }          }
39    
40          if ( $pager->current_page + $range_around + 1 >= $pager->last_page ) {          if ( $pager->current_page + $after_current + $range_around + 1 >= $pager->last_page ) {
41                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
42          } else {          } else {
43                  push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );                  push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );
44          }          }
45    
46          warn "## show_pages = ",dump( @show_pages );  #       dump_yaml( 'show_pages', \@show_pages );
47    
48          return join( ' ', map {          return '' unless $#show_pages;
49                  if ( $_ == $pager->current_page ) {  
50                          qq|<b>$_</b>|;          my ( $prev, $next ) = ( '&lt;&lt;', '&gt;&gt;' );
51                  } elsif ( $_ eq '' ) {  
52                          qq|...|;          sub li_a_href {
53                  } else {                  my ( $page, $label, $attr ) = @_;
54                          $coderef->( $_ );                  param( 'current_page', $page );
55                  }                  my $url = self_url( -query => 1 );
56          } @show_pages );                  $attr ||= '';
57                    $label ||= $page;
58                    qq|<li$attr><a href="$url" title="$page">$label</a></li>|;
59            }
60    
61            return
62                      $pager->previous_page ? li_a_href( $pager->previous_page, $prev ) : qq|<li class=skip>$prev</li>|
63                    , ( map {
64                            if ( $_ eq $pager->current_page ) {
65                                    qq|<li class=current_page>$_</li>|;
66                            } elsif ( $_ eq '' ) {
67                                    qq|<li class=skip>...</li>|;
68                            } else {
69                                    li_a_href( $_ );
70                            }
71                    } @show_pages )
72                    , $pager->next_page ? li_a_href( $pager->next_page, $next ) : qq|<li class=skip>$next</li>|
73                    ;
74                    
75  }  }
76    
77  my $path = $ENV{PATH_INFO} || 'ecas';  my $path = $ENV{PATH_INFO} || 'ecas';
# Line 84  print Line 105  print
105          ),          ),
106          h1( $db->{name} ),          h1( $db->{name} ),
107          qq|<div id=description>|, $db->{description}, qq|</div>|,          qq|<div id=description>|, $db->{description}, qq|</div>|,
108          start_form,          start_form( -action => self_url( query => 0 ) ),
109                  radio_group(                  radio_group(
110                          -name => 'attr',                          -name => 'attr',
111                          -values => [ @attr ],                          -values => [ @attr ],
112  #                       -linebreak => 0,  #                       -linebreak => 0,
113                  ),                  ),
114                  textfield( -name => 'search' ),                  textfield( -name => 'search' ),
115                    popup_menu( -name => 'attr_operator', -values => [ '', 'STRBW', 'STREQ' ],
116                            -labels => {
117                                    '' => 'Bilo koja riječ',
118                                    'STRBW' => 'Početak',
119                                    'STREQ' => 'Točan oblik',
120                            },
121                    ),
122                  submit,                  submit,
123                  textfield( -name => 'entries_per_page', -default => $entries_per_page ),                  hidden( -name => 'entries_per_page', -default => $entries_per_page ),
124                  textfield( -name => 'current_page', -default => 1 ),                  hidden( -name => 'current_page', -default => 1 ),
125                    checkbox( -name => 'debug', -default => 0 ), # FIXME hidden?
126  ;  ;
127    
128  print   end_form;  print   end_form;
# Line 108  if ( my $search = param('search') ) { Line 137  if ( my $search = param('search') ) {
137          );          );
138    
139          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
140            my $pager = Data::Page->new;
141            $pager->total_entries( param('current_page') * param('entries_per_page') );
142            $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ );
143    
144          my $cond = Search::Estraier::Condition->new;          dump_yaml( 'pager', $pager );
145    
146            my $cond = Search::Estraier::Condition->new( debug => $debug );
147          $cond->set_phrase( $search );          $cond->set_phrase( $search );
148          $cond->set_skip( param('current_page') );          $cond->set_skip( $pager->skipped );
149          $cond->set_max( param('entries_per_page') );          $cond->set_max(  $pager->entries_per_page );
150    
151            if ( my $op = param('attr_operator') ) {
152                    $cond->add_attr( param('attr') . " $op " . param('search') );
153            }
154    
155          my $nres = $node->search( $cond, 0 );          my $nres = $node->search( $cond, 0 );
156            $pager->total_entries( $nres->hits );
157    
158          my $pager = Data::Page->new( $nres->hits, param('entries_per_page'), param('current_page') );          dump_yaml( 'cond', $cond );
159            dump_yaml( 'nres', $nres );
160    
161          if ( ! $nres ) {          if ( ! $nres ) {
162                  my $no_results = "No results for search '%s'";                  my $no_results = "No results for search '%s'";
163                  printf qq|<div class="error">$no_results</div>|, $search;                  printf qq|<div class="error">$no_results</div>\n\n|, $search;
164          } else {          } else {
165    
166                  my $results = "Got %d results for search '%s'";                  my $results = "%d results for search '%s' showing results %d - %d on page %d";
167                  printf qq|<div class="message">$results</div>|, $nres->hits, $search;                  printf qq|<div class="message">$results</div>\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page;
168    
169                  print                  my $pager_html = join("\n", show_pager( $pager ));
170                          qq|<div class=pager>|,  
171                          show_pages( $pager,                  print qq|<ul class="pager">$pager_html</ul>\n\n| if $pager_html;
                                 sub {  
                                         my ($page) = @_;  
                                         param( 'current_page', $page );  
                                         my $url = self_url( -query => 1 );  
                                         qq|<a href="$url">$_</a>|;  
                                 }  
                         ),  
                         qq|</div>|  
                 ;  
172    
173                  my $start = $pager->first;                  my $start = $pager->first;
174                  print qq|<ol start=$start>|;                  print qq|<ol start=$start>\n|;
175    
176                  foreach my $i ( 1 .. $nres->doc_num ) {                  foreach my $i ( 1 .. $nres->doc_num ) {
177                          my $rdoc = $nres->get_doc( $i - 1 );                          my $rdoc = $nres->get_doc( $i - 1 );
# Line 158  if ( my $search = param('search') ) { Line 190  if ( my $search = param('search') ) {
190                          }                          }
191                          print qq|</li>\n|;                          print qq|</li>\n|;
192                  }                  }
193                  print qq|</ol>|;                  print qq|</ol>\n\n|;
194    
195                    print qq|<ul class="pager bottom">$pager_html</ul>\n\n| if $pager_html;
196          }          }
197          print qq|</div>|;          print qq|</div>|;
198    

Legend:
Removed from v.1138  
changed lines
  Added in v.1142

  ViewVC Help
Powered by ViewVC 1.1.26