(bug #3197) Subfield code box was not present on new subfield tab in Admin/Authority
[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} = 
326                         "<label><input type=\"text\" name=\"tagsubfield\" value=\""
327                         . $data->{'tagsubfield'}
328                         . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" /></label>";
329                 $row_data{tagsubfield} = $data->{'tagsubfield'};
330                 $row_data{liblibrarian} = "";
331                 $row_data{libopac} = "";
332                 $row_data{seealso} = "";
333                 $row_data{hidden} = "000";
334                 $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
335                                 -id => "repeatable$i",
336                                 -checked => '',
337                                 -value => 1,
338                                 -label => '');
339                 $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
340                         -id => "mandatory$i",
341                         -checked => '',
342                         -value => 1,
343                         -label => '');
344                 $row_data{isurl} = CGI::checkbox(-name => 'isurl',
345                         -id => "isurl$i",
346                         -checked => '',
347                         -value => 1,
348                         -label => '');
349                 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
350                                         -id => "kohafield$i",
351                                         -values=> \@kohafields,
352                                         -default=> "",
353                                         -size=>1,
354                                         -multiple=>0,
355                                         );
356                 $row_data{frameworkcode}  = CGI::scrolling_list(-name=>'frameworkcode',
357                                         -id=>'frameworkcode',
358                                         -values=> \@authtypes,
359                                         -default=>$data->{'frameworkcode'},
360                                         -size=>1,
361                                         -tabindex=>'',
362                                         -multiple=>0,
363                                         );
364                 $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
365                                         -id => 'authorised_value',
366                                         -values=> \@authorised_values,
367                                         -size=>1,
368                                         -tabindex=>'',
369                                         -multiple=>0,
370                                         );
371                 $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
372                                         -id=>'value_builder',
373                                         -values=> \@value_builder,
374                                         -default=>$data->{'value_builder'},
375                                         -size=>1,
376                                         -tabindex=>'',
377                                         -multiple=>0,
378                                         );
379                 $row_data{toggle} = $toggle;
380                 $row_data{row} = $i;
381                 push(@loop_data, \%row_data);
382         }
383         $template->param('use-heading-flags-p' => 1);
384         $template->param('heading-edit-subfields-p' => 1);
385         $template->param(action => "Edit subfields",
386                                                         tagfield => $tagfield,
387                                                         tagfieldinput => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
388                                                         loop => \@loop_data,
389                                                         more_subfields => $more_subfields,
390                                                         more_tag => $tagfield);
391
392                                                                                                 # END $OP eq ADD_FORM
393 ################## ADD_VALIDATE ##################################
394 # called by add_form, used to insert/modify data in DB
395 } elsif ($op eq 'add_validate') {
396         my $dbh = C4::Context->dbh;
397         $template->param(tagfield => "$input->param('tagfield')");
398 #       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)
399 #                                                                       values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
400         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)
401                                                                         values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
402         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=?
403                                                                         where authtypecode=? and tagfield=? and tagsubfield=?");
404         my @tagsubfield = $input->param('tagsubfield');
405         my @liblibrarian        = $input->param('liblibrarian');
406         my @libopac             = $input->param('libopac');
407         my @kohafield           = ''.$input->param('kohafield');
408         my @tab                         = $input->param('tab');
409         my @seealso             = $input->param('seealso');
410         my @hidden;
411         my @ohidden             = $input->param('ohidden');
412         my @ihidden             = $input->param('ihidden');
413         my @ehidden             = $input->param('ehidden');
414         my @authorised_values   = $input->param('authorised_value');
415         my $authtypecode        = $input->param('authtypecode');
416         my @frameworkcodes      = $input->param('frameworkcode');
417         my @value_builder       =$input->param('value_builder');
418         for (my $i=0; $i<= $#tagsubfield ; $i++) {
419                 my $tagfield                    =$input->param('tagfield');
420                 my $tagsubfield         =$tagsubfield[$i];
421                 $tagsubfield="@" unless $tagsubfield ne '';
422                 my $liblibrarian                =$liblibrarian[$i];
423                 my $libopac                     =$libopac[$i];
424                 my $repeatable          =$input->param("repeatable$i")?1:0;
425                 my $mandatory           =$input->param("mandatory$i")?1:0;
426                 my $kohafield           =$kohafield[$i];
427                 my $tab                         =$tab[$i];
428                 my $seealso                             =$seealso[$i];
429                 my $authorised_value            =$authorised_values[$i];
430                 my $frameworkcode               =$frameworkcodes[$i];
431                 my $value_builder=$value_builder[$i];
432                 my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
433                 my $isurl = $input->param("isurl$i")?1:0;
434                 if ($liblibrarian) {
435                         unless (C4::Context->config('demo') eq 1) {
436                                 if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) {
437                                         $sth_update->execute(
438                                                 $authtypecode,
439                                                 $tagfield,
440                                                 $tagsubfield,
441                                                 $liblibrarian,
442                                                 $libopac,
443                                                 $repeatable,
444                                                 $mandatory,
445                                                 $kohafield,
446                                                 $tab,
447                                                 $seealso,
448                                                 $authorised_value,
449                                                 $frameworkcode,
450                                                 $value_builder,
451                                                 $hidden,
452                                                 $isurl,
453                                                 (
454                                                         $authtypecode,
455                                                         $tagfield,
456                                                         $tagsubfield
457                                                 ),
458                                         );
459                                 } else {
460                                         $sth_insert->execute(
461                                                 $authtypecode,
462                                                 $tagfield,
463                                                 $tagsubfield,
464                                                 $liblibrarian,
465                                                 $libopac,
466                                                 $repeatable,
467                                                 $mandatory,
468                                                 $kohafield,
469                                                 $tab,
470                                                 $seealso,
471                                                 $authorised_value,
472                                                 $frameworkcode,
473                                                 $value_builder,
474                                                 $hidden,
475                                                 $isurl,
476                                         );
477                                 }
478                         }
479                 }
480         }
481         $sth_insert->finish;
482         $sth_update->finish;
483         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
484         exit;
485
486                                                                                                         # END $OP eq ADD_VALIDATE
487 ################## DELETE_CONFIRM ##################################
488 # called by default form, used to confirm deletion of data in DB
489 } elsif ($op eq 'delete_confirm') {
490         my $dbh = C4::Context->dbh;
491         my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
492         $sth->execute($tagfield,$tagsubfield,$authtypecode);
493         my $data=$sth->fetchrow_hashref;
494         $sth->finish;
495         $template->param(liblibrarian => $data->{'liblibrarian'},
496                                                         tagsubfield => $data->{'tagsubfield'},
497                                                         delete_link => $script_name,
498                                                         tagfield      =>$tagfield,
499                                                         tagsubfield => $tagsubfield,
500                                                         authtypecode => $authtypecode,
501                                                         );
502                                                                                                         # END $OP eq DELETE_CONFIRM
503 ################## DELETE_CONFIRMED ##################################
504 # called by delete_confirm, used to effectively confirm deletion of data in DB
505 } elsif ($op eq 'delete_confirmed') {
506         my $dbh = C4::Context->dbh;
507         unless (C4::Context->config('demo') eq 1) {
508                 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
509                 $sth->execute($tagfield,$tagsubfield,$authtypecode);
510                 $sth->finish;
511         }
512         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
513         exit;
514         $template->param(tagfield => $tagfield);
515                                                                                                         # END $OP eq DELETE_CONFIRMED
516 ################## DEFAULT ##################################
517 } else { # DEFAULT
518         my ($count,$results)=string_search($tagfield,$authtypecode);
519         my $toggle=1;
520         my @loop_data = ();
521         for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
522                 if ($toggle eq 1){
523                         $toggle=0;
524                 } else {
525                         $toggle=1;
526                 }
527                 my %row_data;  # get a fresh hash for the row data
528                 $row_data{tagfield} = $results->[$i]{'tagfield'};
529                 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
530                 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
531                 $row_data{kohafield} = $results->[$i]{'kohafield'};
532                 $row_data{repeatable} = $results->[$i]{'repeatable'};
533                 $row_data{mandatory} = $results->[$i]{'mandatory'};
534                 $row_data{tab} = $results->[$i]{'tab'};
535                 $row_data{seealso} = $results->[$i]{'seealso'};
536                 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
537                 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
538                 $row_data{value_builder}        = $results->[$i]{'value_builder'};
539                 $row_data{hidden}       = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
540                 $row_data{isurl}        = $results->[$i]{'isurl'};
541                 $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&amp;authtypecode=$authtypecode";
542                 $row_data{toggle} = $toggle;
543                 if ($row_data{tab} eq -1) {
544                         $row_data{subfield_ignored} = 1;
545                 }
546
547                 push(@loop_data, \%row_data);
548         }
549         $template->param(loop => \@loop_data);
550         $template->param(edit_tagfield => $tagfield,
551                 edit_authtypecode => $authtypecode);
552         
553         if ($offset>0) {
554                 my $prevpage = $offset-$pagesize;
555                 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
556         }
557         if ($offset+$pagesize<$count) {
558                 my $nextpage =$offset+$pagesize;
559                 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
560         }
561 } #---- END $OP eq DEFAULT
562 output_html_with_http_headers $input, $cookie, $template->output;