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