2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Interface::CGI::Output;
33 use C4::Koha; # XXX subfield_is_koha_internal_p
35 # Creates a scrolling list with the associated default value.
36 # Using more than one scrolling list in a CGI assigns the same default value to all the
37 # scrolling lists on the page !?!? That's why this function was written.
40 my $type = $query->param('type');
41 my $op = $query->param('op');
42 my $dbh = C4::Context->dbh;
44 my $startfrom = $query->param('startfrom');
45 $startfrom = 0 if ( !defined $startfrom );
46 my ( $template, $loggedinuser, $cookie );
49 if ( $op eq "do_search" ) {
50 my @marclist = $query->param('marclist');
51 my @and_or = $query->param('and_or');
52 my @excluding = $query->param('excluding');
53 my @operator = $query->param('operator');
54 my @value = $query->param('value');
56 $resultsperpage = $query->param('resultsperpage');
57 $resultsperpage = 19 if ( !defined $resultsperpage );
58 my $orderby = $query->param('orderby');
60 # builds tag and subfield arrays
63 foreach my $marc (@marclist) {
65 my ( $tag, $subfield ) =
66 GetMarcFromKohaField( $dbh, $marc );
68 push @tags, $dbh->quote("$tag$subfield");
71 push @tags, $dbh->quote( substr( $marc, 0, 4 ) );
78 my ( $results, $total ) =
79 catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
80 $startfrom * $resultsperpage,
81 $resultsperpage, $orderby );
83 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85 template_name => "barcodes/result.tmpl",
89 flagsrequired => { tools => 1 },
94 # multi page display gestion
96 my $displayprev = $startfrom;
97 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
103 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
104 push @field_data, { term => "marclist", val => $marclist[$i] };
105 push @field_data, { term => "and_or", val => $and_or[$i] };
106 push @field_data, { term => "excluding", val => $excluding[$i] };
107 push @field_data, { term => "operator", val => $operator[$i] };
108 push @field_data, { term => "value", val => $value[$i] };
113 if ( $total > $resultsperpage ) {
114 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
117 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
121 highlight => $highlight,
122 searchdata => \@field_data,
123 startfrom => ( $i - 1 )
129 my $from = $startfrom * $resultsperpage + 1;
132 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
136 $to = ( ( $startfrom + 1 ) * $resultsperpage );
139 # this gets the results of the search (which are bibs)
140 # and then does a lookup on all items that exist for that bib
141 # then pushes the items onto a new array, as we really want the
142 # items attached to the bibs not thew bibs themselves
146 for ( $i = 0 ; $i <= ( $total - 1 ) ; $i++ )
147 { #total-1 coz the array starts at 0
152 &GetItemsInfo( $results->[$i]{'biblionumber'}, $type );
154 foreach my $item (@item_results) {
157 push @results2, $item;
163 result => \@results2,
164 startfrom => $startfrom,
165 displaynext => $displaynext,
166 displayprev => $displayprev,
167 resultsperpage => $resultsperpage,
168 startfromnext => $startfrom + 1,
169 startfromprev => $startfrom - 1,
170 searchdata => \@field_data,
174 numbers => \@numbers,
178 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
180 template_name => "barcodes/search.tmpl",
183 authnotrequired => 0,
184 flagsrequired => { tools => 1 },
190 "Select itemtype,description from itemtypes order by description");
196 while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
197 push @itemtype, $value;
198 $itemtypes{$value} = $lib;
201 my $CGIitemtype = CGI::scrolling_list(
203 -values => \@itemtype,
204 -labels => \%itemtypes,
210 $template->param( CGIitemtype => $CGIitemtype, );
215 intranetcolorstylesheet =>
216 C4::Context->preference("intranetcolorstylesheet"),
217 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
218 IntranetNav => C4::Context->preference("IntranetNav"),
220 output_html_with_http_headers $query, $cookie, $template->output;