This is a language commit. I've gone through most of the templates and
[koha.git] / barcodes / label-item-search.pl
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20
21 use strict;
22 require Exporter;
23 use CGI;
24 use C4::Koha;
25 use C4::Auth;
26
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Biblio;
31 use C4::Acquisition;
32 use C4::Koha;    # XXX subfield_is_koha_internal_p
33
34 # Creates a scrolling list with the associated default value.
35 # Using more than one scrolling list in a CGI assigns the same default value to all the
36 # scrolling lists on the page !?!? That's why this function was written.
37
38 my $query = new CGI;
39 my $type  = $query->param('type');
40 my $op    = $query->param('op');
41 my $dbh   = C4::Context->dbh;
42
43 my $startfrom = $query->param('startfrom');
44 $startfrom = 0 if ( !defined $startfrom );
45 my ( $template, $loggedinuser, $cookie );
46 my $resultsperpage;
47
48 if ( $op eq "do_search" ) {
49     my @marclist  = $query->param('marclist');
50     my @and_or    = $query->param('and_or');
51     my @excluding = $query->param('excluding');
52     my @operator  = $query->param('operator');
53     my @value     = $query->param('value');
54
55     $resultsperpage = $query->param('resultsperpage');
56     $resultsperpage = 19 if ( !defined $resultsperpage );
57     my $orderby = $query->param('orderby');
58
59     # builds tag and subfield arrays
60     my @tags;
61
62     foreach my $marc (@marclist) {
63         if ($marc) {
64             my ( $tag, $subfield ) =
65               GetMarcFromKohaField( $marc );
66             if ($tag) {
67                 push @tags, $dbh->quote("$tag$subfield");
68             }
69             else {
70                 push @tags, $dbh->quote( substr( $marc, 0, 4 ) );
71             }
72         }
73         else {
74             push @tags, "";
75         }
76     }
77     my ( $results, $total ) =
78       catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
79         $startfrom * $resultsperpage,
80         $resultsperpage, $orderby );
81
82     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
83         {
84             template_name   => "barcodes/result.tmpl",
85             query           => $query,
86             type            => "intranet",
87             authnotrequired => 0,
88             flagsrequired   => { tools => 1 },
89             debug           => 1,
90         }
91     );
92
93     # multi page display gestion
94     my $displaynext = 0;
95     my $displayprev = $startfrom;
96     if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
97         $displaynext = 1;
98     }
99
100     my @field_data = ();
101
102     for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
103         push @field_data, { term => "marclist",  val => $marclist[$i] };
104         push @field_data, { term => "and_or",    val => $and_or[$i] };
105         push @field_data, { term => "excluding", val => $excluding[$i] };
106         push @field_data, { term => "operator",  val => $operator[$i] };
107         push @field_data, { term => "value",     val => $value[$i] };
108     }
109
110     my @numbers = ();
111
112     if ( $total > $resultsperpage ) {
113         for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
114             if ( $i < 16 ) {
115                 my $highlight = 0;
116                 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
117                 push @numbers,
118                   {
119                     number     => $i,
120                     highlight  => $highlight,
121                     searchdata => \@field_data,
122                     startfrom  => ( $i - 1 )
123                   };
124             }
125         }
126     }
127
128     my $from = $startfrom * $resultsperpage + 1;
129     my $to;
130
131     if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
132         $to = $total;
133     }
134     else {
135         $to = ( ( $startfrom + 1 ) * $resultsperpage );
136     }
137
138     # this gets the results of the search (which are bibs)
139     # and then does a lookup on all items that exist for that bib
140     # then pushes the items onto a new array, as we really want the
141     # items attached to the bibs not thew bibs themselves
142
143     my @results2;
144     my $i;
145     for ( $i = 0 ; $i <= ( $total - 1 ) ; $i++ )
146     {    #total-1 coz the array starts at 0
147             #warn $i;
148
149         my $type         = 'intra';
150         my @item_results =
151           &GetItemsInfo( $results->[$i]{'biblionumber'}, $type );
152
153         foreach my $item (@item_results) {
154
155             #warn Dumper $item;
156             push @results2, $item;
157         }
158
159     }
160
161     $template->param(
162         result         => \@results2,
163         startfrom      => $startfrom,
164         displaynext    => $displaynext,
165         displayprev    => $displayprev,
166         resultsperpage => $resultsperpage,
167         startfromnext  => $startfrom + 1,
168         startfromprev  => $startfrom - 1,
169         searchdata     => \@field_data,
170         total          => $total,
171         from           => $from,
172         to             => $to,
173         numbers        => \@numbers,
174     );
175 }
176 else {
177     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
178         {
179             template_name   => "barcodes/search.tmpl",
180             query           => $query,
181             type            => "intranet",
182             authnotrequired => 0,
183             flagsrequired   => { tools => 1 },
184             debug           => 1,
185         }
186     );
187     my $sth =
188       $dbh->prepare(
189         "Select itemtype,description from itemtypes order by description");
190     $sth->execute;
191     my @itemtype;
192     my %itemtypes;
193     push @itemtype, "";
194     $itemtypes{''} = "";
195     while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
196         push @itemtype, $value;
197         $itemtypes{$value} = $lib;
198     }
199
200     my $CGIitemtype = CGI::scrolling_list(
201         -name     => 'value',
202         -values   => \@itemtype,
203         -labels   => \%itemtypes,
204         -size     => 1,
205         -multiple => 0
206     );
207     $sth->finish;
208
209     $template->param( CGIitemtype => $CGIitemtype, );
210 }
211
212 # Print the page
213 $template->param(
214     intranetcolorstylesheet =>
215       C4::Context->preference("intranetcolorstylesheet"),
216     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
217     IntranetNav        => C4::Context->preference("IntranetNav"),
218 );
219 output_html_with_http_headers $query, $cookie, $template->output;
220
221 # Local Variables:
222 # tab-width: 4
223 # End: