+ }
+ $debug && warn $query;
+ $resultsperpage= $input->param('resultsperpage');
+ $resultsperpage = 20 if(!defined $resultsperpage);
+
+ my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
+ my $total = scalar @$marcrecords;
+
+ if (defined $error) {
+ $template->param(query_error => $error);
+ warn "error: ".$error;
+ output_html_with_http_headers $input, $cookie, $template->output;
+ exit;
+ }
+ my @results;
+
+ for(my $i=0;$i<$total;$i++) {
+ my %resultsloop;
+ my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
+ my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
+
+ #build the hash for the template.
+ $resultsloop{highlight} = ($i % 2)?(1):(0);
+ $resultsloop{title} = $biblio->{'title'};
+ $resultsloop{subtitle} = $biblio->{'subtitle'};
+ $resultsloop{biblionumber} = $biblio->{'biblionumber'};
+ $resultsloop{author} = $biblio->{'author'};
+ $resultsloop{publishercode} = $biblio->{'publishercode'};
+ $resultsloop{publicationyear} = $biblio->{'publicationyear'};
+
+ push @results, \%resultsloop;
+ }
+
+ ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "serials/result.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {serials => 1},
+ flagsrequired => {catalogue => 1},
+ debug => 1,
+ });
+
+ # multi page display gestion
+ my $displaynext=0;
+ my $displayprev=$startfrom;
+ if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
+ $displaynext = 1;
+ }
+
+
+ my @numbers = ();
+
+ if ($total_hits>$resultsperpage)
+ {
+ for (my $i=1; $i<$total/$resultsperpage+1; $i++)
+ {
+ if ($i<16)
+ {
+ my $highlight=0;
+ ($startfrom==($i-1)) && ($highlight=1);
+ push @numbers, { number => $i,
+ highlight => $highlight ,
+ searchdata=> \@results,
+ startfrom => ($i-1)};
+ }
+ }
+ }
+
+ my $from = 0;
+ $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
+ my $to;
+
+ if($total_hits < (($startfrom+1)*$resultsperpage))
+ {
+ $to = $total;
+ } else {
+ $to = (($startfrom+1)*$resultsperpage);
+ }
+ $template->param(
+ query => $query,
+ resultsloop => \@results,
+ startfrom=> $startfrom,
+ displaynext=> $displaynext,
+ displayprev=> $displayprev,
+ resultsperpage => $resultsperpage,
+ startfromnext => $startfrom+1,
+ startfromprev => $startfrom-1,
+ total=>$total_hits,
+ from=>$from,
+ to=>$to,
+ numbers=>\@numbers,
+ );
+} # end of if ($op eq "do_search" & $query)
+ else {
+ my @itemtypesloop;
+ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
+ # load the itemtypes
+ my $itemtypes = GetItemTypes;
+ my $selected=1;
+ my $cnt;
+ foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
+ my %row =(
+ code => $thisitemtype,
+ selected => $selected,
+ description => $itemtypes->{$thisitemtype}->{'description'},
+ );
+ $selected = 0 if ($selected) ;
+ push @itemtypesloop, \%row;