6 use C4::Interface::CGI::Output;
18 my $dbh=C4::Context->dbh;
19 my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
21 while (my ($description,$itemtype) = $sth->fetchrow) {
22 $classlist.="<option value=\"$itemtype\">$description</option>\n";
27 my $op = $query->param("op");
28 my $type=$query->param('type');
30 my $startfrom=$query->param('startfrom');
31 $startfrom=0 if(!defined $startfrom);
32 my ($template, $loggedinuser, $cookie);
36 if ($op eq "do_search") {
37 my @marclist = $query->param('marclist');
38 my @and_or = $query->param('and_or');
39 my @excluding = $query->param('excluding');
40 my @operator = $query->param('operator');
41 my @value = $query->param('value');
43 for (my $i=0;$i<=$#marclist;$i++) {
44 if ($searchdesc) { # don't put the and_or on the 1st search term
45 $searchdesc .= $and_or[$i]." ".$excluding[$i]." ".($marclist[$i]?$marclist[$i]:"*")." ".$operator[$i]." ".$value[$i]." " if ($value[$i]);
47 $searchdesc = $excluding[$i]." ".($marclist[$i]?$marclist[$i]:"*")." ".$operator[$i]." ".$value[$i]." " if ($value[$i]);
50 $resultsperpage= $query->param('resultsperpage');
51 $resultsperpage = 19 if(!defined $resultsperpage);
52 my $orderby = $query->param('orderby');
54 # builds tag and subfield arrays
57 foreach my $marc (@marclist) {
59 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,$marc,'');
61 push @tags,$dbh->quote("$tag$subfield");
63 push @tags, $dbh->quote(substr($marc,0,4));
69 findseealso($dbh,\@tags);
70 my ($results,$total) = catalogsearch($dbh, \@tags,\@and_or,
71 \@excluding, \@operator, \@value,
72 $startfrom*$resultsperpage, $resultsperpage,$orderby);
74 ($template, $loggedinuser, $cookie)
75 = get_template_and_user({template_name => "opac-searchresults.tmpl",
82 # multi page display gestion
84 my $displayprev=$startfrom;
85 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
92 for(my $i = 0 ; $i <= $#marclist ; $i++)
94 push @field_data, { term => "marclist", val=>$marclist[$i] };
95 push @field_data, { term => "and_or", val=>$and_or[$i] };
96 push @field_data, { term => "excluding", val=>$excluding[$i] };
97 push @field_data, { term => "operator", val=>$operator[$i] };
98 push @field_data, { term => "value", val=>$value[$i] };
103 if ($total>$resultsperpage)
105 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
110 ($startfrom==($i-1)) && ($highlight=1);
111 push @numbers, { number => $i,
112 highlight => $highlight ,
113 searchdata=> \@field_data,
114 startfrom => ($i-1)};
119 my $from = $startfrom*$resultsperpage+1;
122 if($total < (($startfrom+1)*$resultsperpage))
126 $to = (($startfrom+1)*$resultsperpage);
128 $template->param(results => $results,
129 startfrom=> $startfrom,
130 displaynext=> $displaynext,
131 displayprev=> $displayprev,
132 resultsperpage => $resultsperpage,
134 startfromnext => $startfrom+1,
135 startfromprev => $startfrom-1,
136 searchdata=>\@field_data,
141 searchdesc=> $searchdesc,
145 ($template, $loggedinuser, $cookie)
146 = get_template_and_user({template_name => "opac-search.tmpl",
149 authnotrequired => 1,
153 $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
159 while (my ($value,$lib) = $sth->fetchrow_array) {
160 push @itemtype, $value;
161 $itemtypes{$value}=$lib;
164 my $CGIitemtype=CGI::scrolling_list( -name => 'value',
165 -values => \@itemtype,
166 -labels => \%itemtypes,
174 my ($count2,@branches)=branches();
175 push @select_branch, "";
176 $select_branches{''} = "";
177 for (my $i=0;$i<$count2;$i++){
178 push @select_branch, $branches[$i]->{'branchcode'};#
179 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
181 my $CGIbranch=CGI::scrolling_list( -name => 'value',
182 -values => \@select_branch,
183 -labels => \%select_branches,
188 $template->param(classlist => $classlist,
189 CGIitemtype => $CGIitemtype,
190 CGIbranch => $CGIbranch,
194 output_html_with_http_headers $query, $cookie, $template->output;