bug 1546 - replacing REPLACE statements
[koha.git] / admin / auth_subfields_structure.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use C4::Output;
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25
26
27 sub string_search  {
28         my ($searchstring,$authtypecode)=@_;
29         my $dbh = C4::Context->dbh;
30         $searchstring=~ s/\'/\\\'/g;
31         my @data=split(' ',$searchstring);
32         my $count=@data;
33         my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
34         $sth->execute("$searchstring%",$authtypecode);
35         my @results;
36         my $cnt=0;
37         my $u=1;
38         while (my $data=$sth->fetchrow_hashref){
39                 push(@results,$data);
40                 $cnt ++;
41                 $u++;
42         }
43         $sth->finish;
44         return ($cnt,\@results);
45 }
46
47 sub auth_subfield_structure_exists {
48         my ($authtypecode, $tagfield, $tagsubfield) = @_;
49         my $dbh  = C4::Context->dbh;
50         my $sql  = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
51         my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
52         return @$rows > 0;
53 }
54
55 my $input = new CGI;
56 my $tagfield=$input->param('tagfield');
57 my $tagsubfield=$input->param('tagsubfield');
58 my $authtypecode=$input->param('authtypecode');
59 my $pkfield="tagfield";
60 my $offset=$input->param('offset');
61 my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
62
63 my ($template, $borrowernumber, $cookie)
64     = get_template_and_user({template_name => "admin/auth_subfields_structure.tmpl",
65                              query => $input,
66                              type => "intranet",
67                              authnotrequired => 0,
68                              flagsrequired => {parameters => 1},
69                              debug => 1,
70                              });
71 my $pagesize=30;
72 my $op = $input->param('op');
73 $tagfield=~ s/\,//g;
74
75 if ($op) {
76 $template->param(script_name => $script_name,
77                                                 tagfield =>$tagfield,
78                                                 authtypecode => $authtypecode,
79                                                 $op              => 1); # we show only the TMPL_VAR names $op
80 } else {
81 $template->param(script_name => $script_name,
82                                                 tagfield =>$tagfield,
83                                                 authtypecode => $authtypecode,
84                                                 else              => 1); # we show only the TMPL_VAR names $op
85 }
86
87 ################## ADD_FORM ##################################
88 # called by default. Used to create form to add or  modify a record
89 if ($op eq 'add_form') {
90         my $data;
91         my $dbh = C4::Context->dbh;
92         my $more_subfields = $input->param("more_subfields")+1;
93         # builds kohafield tables
94         my @kohafields;
95         push @kohafields, "";
96         my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
97         $sth2->execute;
98         while ((my $field) = $sth2->fetchrow_array) {
99                 push @kohafields, "auth_header.".$field;
100         }
101         
102         # build authorised value list
103         $sth2->finish;
104         $sth2 = $dbh->prepare("select distinct category from authorised_values");
105         $sth2->execute;
106         my @authorised_values;
107         push @authorised_values,"";
108         while ((my $category) = $sth2->fetchrow_array) {
109                 push @authorised_values, $category;
110         }
111         push (@authorised_values,"branches");
112         push (@authorised_values,"itemtypes");
113     
114     # build thesaurus categories list
115     $sth2->finish;
116     $sth2 = $dbh->prepare("select authtypecode from auth_types");
117     $sth2->execute;
118     my @authtypes;
119     push @authtypes, "";
120     while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
121         push @authtypes, $authtypecode;
122     }
123
124         # build value_builder list
125         my @value_builder=('');
126
127         # read value_builder directory.
128         # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
129         # on a standard install, /cgi-bin need to be added. 
130         # test one, then the other
131         my $cgidir = C4::Context->intranetdir ."/cgi-bin";
132         unless (opendir(DIR, "$cgidir/cataloguing/value_builder")) {
133                 $cgidir = C4::Context->intranetdir;
134                 opendir(DIR, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
135         } 
136         while (my $line = readdir(DIR)) {
137                 if ($line =~ /\.pl$/) {
138                         push (@value_builder,$line);
139                 }
140         }
141         @value_builder= sort {$a cmp $b} @value_builder;
142         closedir DIR;
143
144         # build values list
145         my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
146         $sth->execute($tagfield,$authtypecode);
147         my @loop_data = ();
148         my $toggle=1;
149         my $i=0;
150         while ($data =$sth->fetchrow_hashref) {
151
152                 my %row_data;  # get a fresh hash for the row data
153                 if ($toggle eq 1){
154                         $toggle=0;
155                 } else {
156                         $toggle=1;
157                 }
158                 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
159                                         -id=>"tab$i",
160                                         -values =>
161                                         [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
162                                         -labels => {
163                                             '-1' => 'ignore',
164                                             '0'  => '0',
165                                             '1'  => '1',
166                                             '2'  => '2',
167                                             '3'  => '3',
168                                             '4'  => '4',
169                                             '5'  => '5',
170                                             '6'  => '6',
171                                             '7'  => '7',
172                                             '8'  => '8',
173                                             '9'  => '9',
174                                         },
175                                         -default=>$data->{'tab'},
176                                         -size=>1,
177                                         -tabindex=>'',
178                                         -multiple=>0,
179                                         );
180                 $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
181                                         -id=>"ohidden$i",
182                                         -values=>['0','1','2'],
183                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
184                                                                         '2' =>'Hide',
185                                                                         },
186                                         -default=>substr($data->{'hidden'},0,1),
187                                         -size=>1,
188                                         -multiple=>0,
189                                         );
190                 $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
191                                         -id=>"ihidden$i",
192                                         -values=>['0','1','2'],
193                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
194                                                                         '2' =>'Hide',
195                                                                         },
196                                         -default=>substr($data->{'hidden'},1,1),
197                                         -size=>1,
198                                         -multiple=>0,
199                                         );
200                 $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
201                                         -id=>"ehidden$i",
202                                         -values=>['0','1','2'],
203                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
204                                                                         '2' =>'Hide',
205                                                                         },
206                                         -default=>substr($data->{'hidden'}."  ",2,1),
207                                         -size=>1,
208                                         -multiple=>0,
209                                         );
210                 $row_data{tagsubfieldinput} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
211                 $row_data{tagsubfield} = $data->{'tagsubfield'};
212                 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
213                 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
214                 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
215                 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
216                                         -id=>"kohafield$i",
217                                         -values=> \@kohafields,
218                                         -default=> "$data->{'kohafield'}",
219                                         -size=>1,
220                                         -multiple=>0,
221                                         );
222                 $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
223                                         -id=>"authorised_value$i",
224                                         -values=> \@authorised_values,
225                                         -default=>$data->{'authorised_value'},
226                                         -size=>1,
227                                         -tabindex=>'',
228                                         -multiple=>0,
229                                         );
230                 $row_data{frameworkcode}  = CGI::scrolling_list(-name=>'frameworkcode',
231                                         -id=>"frameworkcode$i",
232                                         -values=> \@authtypes,
233                                         -default=>$data->{'frameworkcode'},
234                                         -size=>1,
235                                         -tabindex=>'',
236                                         -multiple=>0,
237                                         );
238                 $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
239                                         -id=>"value_builder$i",
240                                         -values=> \@value_builder,
241                                         -default=>$data->{'value_builder'},
242                                         -size=>1,
243                                         -tabindex=>'',
244                                         -multiple=>0,
245                                         );
246                 
247                 $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
248         -checked => $data->{'repeatable'}?'checked':'',
249         -value => 1,
250         -label => '',
251         -id => "repeatable$i");
252                 $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
253         -checked => $data->{'mandatory'}?'checked':'',
254         -value => 1,
255         -label => '',
256         -id => "mandatory$i");
257                 $row_data{hidden} = CGI::escapeHTML($data->{hidden}) ;
258                 $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
259                         -id => "isurl$i",
260                         -checked => $data->{'isurl'}?'checked':'',
261                         -value => 1,
262                         -label => '');
263                 $row_data{row} = $i;
264                 $row_data{toggle} = $toggle;
265                 push(@loop_data, \%row_data);
266                 $i++;
267         }
268         # add more_subfields empty lines for add if needed
269         for (my $i=1;$i<=$more_subfields;$i++) {
270                 my %row_data;  # get a fresh hash for the row data
271         $row_data{'new_subfield'} = 1;
272                 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
273                                         -id => "tab$i",
274                                         -values =>
275                                         [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
276                                         -labels => {
277                                             '-1' => 'ignore',
278                                             '0'  => '0',
279                                             '1'  => '1',
280                                             '2'  => '2',
281                                             '3'  => '3',
282                                             '4'  => '4',
283                                             '5'  => '5',
284                                             '6'  => '6',
285                                             '7'  => '7',
286                                             '8'  => '8',
287                                             '9'  => '9',
288                                         },
289                                         -default=>"",
290                                         -size=>1,
291                                         -tabindex=>'',
292                                         -multiple=>0,
293                                         );
294                 $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
295                                         -id=>"ohidden$i",
296                                         -values=>['0','1','2'],
297                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
298                                                                         '2' =>'Hide',
299                                                                         },
300                                         -default=>"0",
301                                         -size=>1,
302                                         -multiple=>0,
303                                         );
304
305                 $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
306                                         -id=>"ihidden$i",
307                                         -values=>['0','1','2'],
308                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
309                                                                         '2' =>'Hide',
310                                                                         },
311                                         -default=>"0",
312                                         -size=>1,
313                                         -multiple=>0,
314                                         );
315                 $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
316                                         -id=>"ehidden$i",
317                                         -values=>['0','1','2'],
318                                         -labels => {'0'=>'Show','1'=>'Show Collapsed',
319                                                                         '2' =>'Hide',
320                                                                         },
321                                         -default=>"0",
322                                         -size=>1,
323                                         -multiple=>0,
324                                         );
325                 $row_data{tagsubfieldinput} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
326                 $row_data{tagsubfield} = $data->{'tagsubfield'};
327                 $row_data{liblibrarian} = "";
328                 $row_data{libopac} = "";
329                 $row_data{seealso} = "";
330                 $row_data{hidden} = "000";
331                 $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
332                                 -id => "repeatable$i",
333                                 -checked => '',
334                                 -value => 1,
335                                 -label => '');
336                 $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
337                         -id => "mandatory$i",
338                         -checked => '',
339                         -value => 1,
340                         -label => '');
341                 $row_data{isurl} = CGI::checkbox(-name => 'isurl',
342                         -id => "isurl$i",
343                         -checked => '',
344                         -value => 1,
345                         -label => '');
346                 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
347                                         -id => "kohafield$i",
348                                         -values=> \@kohafields,
349                                         -default=> "",
350                                         -size=>1,
351                                         -multiple=>0,
352                                         );
353                 $row_data{frameworkcode}  = CGI::scrolling_list(-name=>'frameworkcode',
354                                         -id=>'frameworkcode',
355                                         -values=> \@authtypes,
356                                         -default=>$data->{'frameworkcode'},
357                                         -size=>1,
358                                         -tabindex=>'',
359                                         -multiple=>0,
360                                         );
361                 $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
362                                         -id => 'authorised_value',
363                                         -values=> \@authorised_values,
364                                         -size=>1,
365                                         -tabindex=>'',
366                                         -multiple=>0,
367                                         );
368                 $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
369                                         -id=>'value_builder',
370                                         -values=> \@value_builder,
371                                         -default=>$data->{'value_builder'},
372                                         -size=>1,
373                                         -tabindex=>'',
374                                         -multiple=>0,
375                                         );
376                 $row_data{toggle} = $toggle;
377                 $row_data{row} = $i;
378                 push(@loop_data, \%row_data);
379         }
380         $template->param('use-heading-flags-p' => 1);
381         $template->param('heading-edit-subfields-p' => 1);
382         $template->param(action => "Edit subfields",
383                                                         tagfield => $tagfield,
384                                                         tagfieldinput => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
385                                                         loop => \@loop_data,
386                                                         more_subfields => $more_subfields,
387                                                         more_tag => $tagfield);
388
389                                                                                                 # END $OP eq ADD_FORM
390 ################## ADD_VALIDATE ##################################
391 # called by add_form, used to insert/modify data in DB
392 } elsif ($op eq 'add_validate') {
393         my $dbh = C4::Context->dbh;
394         $template->param(tagfield => "$input->param('tagfield')");
395 #       my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
396 #                                                                       values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
397         my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
398                                                                         values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
399         my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?
400                                                                         where authtypecode=? and tagfield=? and tagsubfield=?");
401         my @tagsubfield = $input->param('tagsubfield');
402         my @liblibrarian        = $input->param('liblibrarian');
403         my @libopac             = $input->param('libopac');
404         my @kohafield           = ''.$input->param('kohafield');
405         my @tab                         = $input->param('tab');
406         my @seealso             = $input->param('seealso');
407         my @hidden;
408         my @ohidden             = $input->param('ohidden');
409         my @ihidden             = $input->param('ihidden');
410         my @ehidden             = $input->param('ehidden');
411         my @authorised_values   = $input->param('authorised_value');
412         my $authtypecode        = $input->param('authtypecode');
413         my @frameworkcodes      = $input->param('frameworkcode');
414         my @value_builder       =$input->param('value_builder');
415         for (my $i=0; $i<= $#tagsubfield ; $i++) {
416                 my $tagfield                    =$input->param('tagfield');
417                 my $tagsubfield         =$tagsubfield[$i];
418                 $tagsubfield="@" unless $tagsubfield ne '';
419                 my $liblibrarian                =$liblibrarian[$i];
420                 my $libopac                     =$libopac[$i];
421                 my $repeatable          =$input->param("repeatable$i")?1:0;
422                 my $mandatory           =$input->param("mandatory$i")?1:0;
423                 my $kohafield           =$kohafield[$i];
424                 my $tab                         =$tab[$i];
425                 my $seealso                             =$seealso[$i];
426                 my $authorised_value            =$authorised_values[$i];
427                 my $frameworkcode               =$frameworkcodes[$i];
428                 my $value_builder=$value_builder[$i];
429                 my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
430                 my $isurl = $input->param("isurl$i")?1:0;
431                 if ($liblibrarian) {
432                         unless (C4::Context->config('demo') eq 1) {
433                                 if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) {
434                                         $sth_update->execute(
435                                                 $authtypecode,
436                                                 $tagfield,
437                                                 $tagsubfield,
438                                                 $liblibrarian,
439                                                 $libopac,
440                                                 $repeatable,
441                                                 $mandatory,
442                                                 $kohafield,
443                                                 $tab,
444                                                 $seealso,
445                                                 $authorised_value,
446                                                 $frameworkcode,
447                                                 $value_builder,
448                                                 $hidden,
449                                                 $isurl,
450                                                 (
451                                                         $authtypecode,
452                                                         $tagfield,
453                                                         $tagsubfield
454                                                 ),
455                                         );
456                                 } else {
457                                         $sth_insert->execute(
458                                                 $authtypecode,
459                                                 $tagfield,
460                                                 $tagsubfield,
461                                                 $liblibrarian,
462                                                 $libopac,
463                                                 $repeatable,
464                                                 $mandatory,
465                                                 $kohafield,
466                                                 $tab,
467                                                 $seealso,
468                                                 $authorised_value,
469                                                 $frameworkcode,
470                                                 $value_builder,
471                                                 $hidden,
472                                                 $isurl,
473                                         );
474                                 }
475                         }
476                 }
477         }
478         $sth_insert->finish;
479         $sth_update->finish;
480         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
481         exit;
482
483                                                                                                         # END $OP eq ADD_VALIDATE
484 ################## DELETE_CONFIRM ##################################
485 # called by default form, used to confirm deletion of data in DB
486 } elsif ($op eq 'delete_confirm') {
487         my $dbh = C4::Context->dbh;
488         my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
489         $sth->execute($tagfield,$tagsubfield,$authtypecode);
490         my $data=$sth->fetchrow_hashref;
491         $sth->finish;
492         $template->param(liblibrarian => $data->{'liblibrarian'},
493                                                         tagsubfield => $data->{'tagsubfield'},
494                                                         delete_link => $script_name,
495                                                         tagfield      =>$tagfield,
496                                                         tagsubfield => $tagsubfield,
497                                                         authtypecode => $authtypecode,
498                                                         );
499                                                                                                         # END $OP eq DELETE_CONFIRM
500 ################## DELETE_CONFIRMED ##################################
501 # called by delete_confirm, used to effectively confirm deletion of data in DB
502 } elsif ($op eq 'delete_confirmed') {
503         my $dbh = C4::Context->dbh;
504         unless (C4::Context->config('demo') eq 1) {
505                 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
506                 $sth->execute($tagfield,$tagsubfield,$authtypecode);
507                 $sth->finish;
508         }
509         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
510         exit;
511         $template->param(tagfield => $tagfield);
512                                                                                                         # END $OP eq DELETE_CONFIRMED
513 ################## DEFAULT ##################################
514 } else { # DEFAULT
515         my ($count,$results)=string_search($tagfield,$authtypecode);
516         my $toggle=1;
517         my @loop_data = ();
518         for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
519                 if ($toggle eq 1){
520                         $toggle=0;
521                 } else {
522                         $toggle=1;
523                 }
524                 my %row_data;  # get a fresh hash for the row data
525                 $row_data{tagfield} = $results->[$i]{'tagfield'};
526                 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
527                 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
528                 $row_data{kohafield} = $results->[$i]{'kohafield'};
529                 $row_data{repeatable} = $results->[$i]{'repeatable'};
530                 $row_data{mandatory} = $results->[$i]{'mandatory'};
531                 $row_data{tab} = $results->[$i]{'tab'};
532                 $row_data{seealso} = $results->[$i]{'seealso'};
533                 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
534                 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
535                 $row_data{value_builder}        = $results->[$i]{'value_builder'};
536                 $row_data{hidden}       = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
537                 $row_data{isurl}        = $results->[$i]{'isurl'};
538                 $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&amp;authtypecode=$authtypecode";
539                 $row_data{toggle} = $toggle;
540                 if ($row_data{tab} eq -1) {
541                         $row_data{subfield_ignored} = 1;
542                 }
543
544                 push(@loop_data, \%row_data);
545         }
546         $template->param(loop => \@loop_data);
547         $template->param(edit_tagfield => $tagfield,
548                 edit_authtypecode => $authtypecode);
549         
550         if ($offset>0) {
551                 my $prevpage = $offset-$pagesize;
552                 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
553         }
554         if ($offset+$pagesize<$count) {
555                 my $nextpage =$offset+$pagesize;
556                 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
557         }
558 } #---- END $OP eq DEFAULT
559 output_html_with_http_headers $input, $cookie, $template->output;