synch'ing 2.2 and head
[koha.git] / acqui / newbasket2.pl
1 #!/usr/bin/perl
2 #origninally script to provide intranet (librarian) advanced search facility
3 #now script to do searching for acquisitions
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Search;
25 use CGI;
26 use C4::Output;
27 use C4::Acquisition;
28 use C4::Biblio;
29 use HTML::Template;
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32
33 my $env;
34 my $input = new CGI;
35
36 #print $input->header;
37
38 #whether it is called from the opac of the intranet
39 my $type=$input->param('type');
40 if ($type eq ''){
41   $type = 'intra';
42 }
43
44 #print $input->dump;
45 my $blah;
46 my %search;
47 #build hash of users input
48 my $title=$input->param('search');
49 $search{'title'}=$title;
50 my $keyword=$input->param('d');
51 $search{'keyword'}=$keyword;
52 my $author=$input->param('author');
53 $search{'author'}=$author;
54
55 my @results;
56 my $offset=$input->param('offset');
57 if ($offset eq ''){
58   $offset=0;
59 }
60 my $num=$input->param('num');
61 if ($num eq ''){
62   $num=10;
63 }
64 my $booksellerid=$input->param('booksellerid');
65 my $basketno=$input->param('basketno');
66 my $sub=$input->param('sub');
67 #print $sub;
68 my ($count,@booksellers)=bookseller($booksellerid);
69 my ($template, $loggedinuser, $cookie)
70     = get_template_and_user({template_name => "acqui/newbasket2.tmpl",
71                              query => $input,
72                              type => "intranet",
73                              authnotrequired => 0,
74                              flagsrequired => {acquisition => 1},
75                              debug => 1,
76                              });
77
78 #my $template = gettemplate("acqui/newbasket2.tmpl");
79 #print startpage();
80 #print startmenu('acquisitions');
81
82 if ($keyword ne ''){
83         ($count,@results)=KeywordSearch(undef,'intra',\%search,$num,$offset);
84 } elsif ($search{'front'} ne '') {
85         ($count,@results)=FrontSearch(undef,'intra',\%search,$num,$offset);
86 }else {
87         ($count,@results)=CatSearch(undef,'loose',\%search,$num,$offset);
88 }
89
90 my @loopsearch;
91
92 while ( my ($key, $value) = each %search) {
93         if ($value ne ''){
94                 my %linesearch;
95                 $value=~ s/\\//g;
96                 $linesearch{key}=$key;
97                 $linesearch{value}=$value;
98                 push(@loopsearch,\%linesearch);
99         }
100 }
101
102 my $offset2=$num+$offset;
103 my $dispnum=$offset+1;
104 if ($offset2>$count) {
105         $offset2=$count
106 }
107
108
109 my $count2=@results;
110 if ($keyword ne '' && $offset > 0){
111         $count2=$count-$offset;
112         if ($count2 > 10){
113                 $count2=10;
114         }
115 }
116 my $i=0;
117 my $colour=0;
118
119 my @loopresult;
120
121 while ($i < $count2){
122                 my %lineres;
123                 my $toggle;
124
125         my $result=$results[$i];
126         $result->{'title'}=~ s/\`/\\\'/g;
127         my $title2=$result->{'title'};
128         my $author2=$result->{'author'};
129         $author2=~ s/ /%20/g;
130         $title2=~ s/ /%20/g;
131         $title2=~ s/\#/\&\#x23;/g;
132         $title2=~ s/\"/\&quot\;/g;
133
134                 my $itemcount;
135         my $location='';
136         my $location_only='';
137         my $word=$result->{'author'};
138         $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
139         $word=~ s/  //g;
140         $word=~ s/ /%20/g;
141         $word=~ s/\,/\,%20/g;
142         $word=~ s/\n//g;
143         $lineres{word}=$word;
144         $lineres{type}=$type;
145
146         my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=C4::Search::itemcount($env,$result->{'biblionumber'},$type);
147         if ($nacount > 0){
148                 $location .= "On Loan";
149                 if ($nacount >1 ){
150                         $location .= " ($nacount)";
151                 }
152                 $location.=" ";
153                 $lineres{'on-loan-p'}=1;
154         }
155         if ($lcount > 0){
156                 $location .= "Levin";
157                 $location_only .= "Levin";
158                 if ($lcount >1 ){
159                         $location .= " ($lcount)";
160                         $location_only .= " ($lcount)";
161                 }
162                 $location.=" ";
163                 $location_only.=" ";
164         }
165         if ($fcount > 0){
166                 $location .= "Foxton";
167                 $location_only .= "Foxton";
168                 if ($fcount >1 ){
169                         $location .= " ($fcount)";
170                         $location_only .= " ($fcount)";
171                 }
172                 $location.=" ";
173                 $location_only.=" ";
174         }
175         if ($scount > 0){
176                 $location .= "Shannon";
177                 $location_only .= "Shannon";
178                 if ($scount >1 ){
179                         $location .= " ($scount)";
180                         $location_only .= " ($scount)";
181                 }
182                 $location.=" ";
183                 $location_only.=" ";
184         }
185         if ($lostcount > 0){
186                 $location .= "Lost";
187                 if ($lostcount >1 ){
188                         $location .= " ($lostcount)";
189                 }
190                 $location.=" ";
191                 $lineres{'lost-p'}=1;
192         }
193         if ($mending > 0){
194                 $location .= "Mending";
195                 if ($mending >1 ){
196                         $location .= " ($mending)";
197                 }
198                 $location.=" ";
199                 $lineres{'mending-p'}=1;
200         }
201         if ($transit > 0){
202                 $location .= "In Transit";
203                 if ($transit >1 ){
204                         $location .= " ($transit)";
205                 }
206                 $location.=" ";
207                 $lineres{'in-transit-p'}=1;
208         }
209         if ($colour == 1){
210                 $toggle='#ffffcc';
211                 $colour = 0;
212         } else{
213                 $colour = 1;
214                 $toggle='white';
215         }
216         $lineres{author2}=$author2;
217         $lineres{title2}=$title2;
218         $lineres{copyright}=$result->{'copyrightdate'};
219         $lineres{booksellerid}=$booksellerid;
220         $lineres{basketno}=$basketno;
221         $lineres{sub}=$sub;
222         $lineres{biblionumber}=$result->{biblionumber};
223         $lineres{title}=$result->{title};
224         $lineres{author}=$result->{author};
225         $lineres{toggle}=$toggle;
226         $lineres{itemcount}=$count;
227         $lineres{location}=$location;
228         $lineres{'location-only'}=$location_only;
229         push(@loopresult,\%lineres);
230         $i++;
231 }
232
233 $offset=$num+$offset;
234 $template->param(       bookselname => $booksellers[0]->{'name'},
235                                                                 booksellerid => $booksellerid,
236                                                                 basketno => $basketno,
237                                                                 parsub => $sub,
238                                                                 count => $count,
239                                                                 offset2 =>$offset2,
240                                                                 dispnum => $dispnum,
241                                                                 offsetover => ($offset < $count ),
242                                                                 num => $num,
243                                                                 offset => $offset,
244                                                                 type =>  $type,
245                                                                 title => $title,
246                                                                 author => $author,
247                                                                 loopsearch =>\@loopsearch,
248                                                                 loopresult =>\@loopresult,
249                                                                 'use-location-flags-p' => 1);
250
251 output_html_with_http_headers $input, $cookie, $template->output;