Minor consistency changes
[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::Catalogue;
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 $id=$input->param('id');
65 my $basket=$input->param('basket');
66 my $sub=$input->param('sub');
67 my $donation;
68 if ($id == 72){
69   $donation='yes';
70 }
71 #print $sub;
72 my ($count,@booksellers)=bookseller($id);
73 my ($template, $loggedinuser, $cookie)
74     = get_template_and_user({template_name => "acqui/newbasket2.tmpl",
75                              query => $input,
76                              type => "intranet",
77                              authnotrequired => 0,
78                              flagsrequired => {superlibrarian => 1},
79                              debug => 1,
80                              });
81
82 #my $template = gettemplate("acqui/newbasket2.tmpl");
83 #print startpage();
84 #print startmenu('acquisitions');
85
86 my $testdonation = ($donation ne 'yes'); #tests if donation = true
87 if ($keyword ne ''){
88         ($count,@results)=KeywordSearch(undef,'intra',\%search,$num,$offset);
89 } elsif ($search{'front'} ne '') {
90         ($count,@results)=FrontSearch(undef,'intra',\%search,$num,$offset);
91 }else {
92         ($count,@results)=CatSearch(undef,'loose',\%search,$num,$offset);
93 }
94
95 my @loopsearch;
96
97 while ( my ($key, $value) = each %search) {
98         if ($value ne ''){
99                 my %linesearch;
100                 $value=~ s/\\//g;
101                 $linesearch{key}=$key;
102                 $linesearch{value}=$value;
103                 push(@loopsearch,\%linesearch);
104         }
105 }
106
107 my $offset2=$num+$offset;
108 my $dispnum=$offset+1;
109 if ($offset2>$count) {
110         $offset2=$count
111 }
112
113
114 my $count2=@results;
115 if ($keyword ne '' && $offset > 0){
116         $count2=$count-$offset;
117         if ($count2 > 10){
118                 $count2=10;
119         }
120 }
121 my $i=0;
122 my $colour=0;
123
124 my @loopresult;
125
126 while ($i < $count2){
127                 my %lineres;
128                 my $toggle;
129
130         my $result=$results[$i];
131         $result->{'title'}=~ s/\`/\\\'/g;
132         my $title2=$result->{'title'};
133         my $author2=$result->{'author'};
134         $author2=~ s/ /%20/g;
135         $title2=~ s/ /%20/g;
136         $title2=~ s/\#/\&\#x23;/g;
137         $title2=~ s/\"/\&quot\;/g;
138
139                 my $itemcount;
140         my $location='';
141         my $location_only='';
142         my $word=$result->{'author'};
143         $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
144         $word=~ s/  //g;
145         $word=~ s/ /%20/g;
146         $word=~ s/\,/\,%20/g;
147         $word=~ s/\n//g;
148         $lineres{word}=$word;
149         $lineres{type}=$type;
150
151         my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=C4::Search::itemcount($env,$result->{'biblionumber'},$type);
152         if ($nacount > 0){
153                 $location .= "On Loan";
154                 if ($nacount >1 ){
155                         $location .= " ($nacount)";
156                 }
157                 $location.=" ";
158                 $lineres{'on-loan-p'}=1;
159         }
160         if ($lcount > 0){
161                 $location .= "Levin";
162                 $location_only .= "Levin";
163                 if ($lcount >1 ){
164                         $location .= " ($lcount)";
165                         $location_only .= " ($lcount)";
166                 }
167                 $location.=" ";
168                 $location_only.=" ";
169         }
170         if ($fcount > 0){
171                 $location .= "Foxton";
172                 $location_only .= "Foxton";
173                 if ($fcount >1 ){
174                         $location .= " ($fcount)";
175                         $location_only .= " ($fcount)";
176                 }
177                 $location.=" ";
178                 $location_only.=" ";
179         }
180         if ($scount > 0){
181                 $location .= "Shannon";
182                 $location_only .= "Shannon";
183                 if ($scount >1 ){
184                         $location .= " ($scount)";
185                         $location_only .= " ($scount)";
186                 }
187                 $location.=" ";
188                 $location_only.=" ";
189         }
190         if ($lostcount > 0){
191                 $location .= "Lost";
192                 if ($lostcount >1 ){
193                         $location .= " ($lostcount)";
194                 }
195                 $location.=" ";
196                 $lineres{'lost-p'}=1;
197         }
198         if ($mending > 0){
199                 $location .= "Mending";
200                 if ($mending >1 ){
201                         $location .= " ($mending)";
202                 }
203                 $location.=" ";
204                 $lineres{'mending-p'}=1;
205         }
206         if ($transit > 0){
207                 $location .= "In Transit";
208                 if ($transit >1 ){
209                         $location .= " ($transit)";
210                 }
211                 $location.=" ";
212                 $lineres{'in-transit-p'}=1;
213         }
214         if ($colour == 1){
215                 $toggle='#ffffcc';
216                 $colour = 0;
217         } else{
218                 $colour = 1;
219                 $toggle='white';
220         }
221         $lineres{author2}=$author2;
222         $lineres{title2}=$title2;
223         $lineres{copyright}=$result->{'copyrightdate'};
224         $lineres{id}=$id;
225         $lineres{basket}=$basket;
226         $lineres{sub}=$sub;
227         $lineres{biblionumber}=$result->{biblionumber};
228         $lineres{title}=$result->{title};
229         $lineres{author}=$result->{author};
230         $lineres{toggle}=$toggle;
231         $lineres{itemcount}=$count;
232         $lineres{location}=$location;
233         $lineres{'location-only'}=$location_only;
234         push(@loopresult,\%lineres);
235         $i++;
236 }
237
238 $offset=$num+$offset;
239 $template->param(       bookselname => $booksellers[0]->{'name'},
240                                                                 id => $id,
241                                                                 basket => $basket,
242                                                                 parsub => $sub,
243                                                                 testdonation => $testdonation,
244                                                                 count => $count,
245                                                                 offset2 =>$offset2,
246                                                                 dispnum => $dispnum,
247                                                                 offsetover => ($offset < $count ),
248                                                                 num => $num,
249                                                                 offset => $offset,
250                                                                 type =>  $type,
251                                                                 id => $id,
252                                                                 basket => $basket,
253                                                                 title => $title,
254                                                                 author => $author,
255                                                                 loopsearch =>\@loopsearch,
256                                                                 loopresult =>\@loopresult,
257                                                                 'use-location-flags-p' => 1);
258
259 output_html_with_http_headers $input, $cookie, $template->output;