New scripts for translation into Chinese and other languages where English
[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 $word=$result->{'author'};
142         $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
143         $word=~ s/  //g;
144         $word=~ s/ /%20/g;
145         $word=~ s/\,/\,%20/g;
146         $word=~ s/\n//g;
147         $lineres{word}=$word;
148         $lineres{type}=$type;
149
150         my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=C4::Search::itemcount($env,$result->{'biblionumber'},$type);
151         if ($nacount > 0){
152                 $location .= "On Loan";
153                 if ($nacount >1 ){
154                         $location .= " ($nacount)";
155                 }
156                 $location.=" ";
157         }
158         if ($lcount > 0){
159                 $location .= "Levin";
160                 if ($lcount >1 ){
161                         $location .= " ($lcount)";
162                 }
163                 $location.=" ";
164         }
165         if ($fcount > 0){
166                 $location .= "Foxton";
167                 if ($fcount >1 ){
168                         $location .= " ($fcount)";
169                 }
170                 $location.=" ";
171         }
172         if ($scount > 0){
173                 $location .= "Shannon";
174                 if ($scount >1 ){
175                         $location .= " ($scount)";
176                 }
177                 $location.=" ";
178         }
179         if ($lostcount > 0){
180                 $location .= "Lost";
181                 if ($lostcount >1 ){
182                         $location .= " ($lostcount)";
183                 }
184                 $location.=" ";
185         }
186         if ($mending > 0){
187                 $location .= "Mending";
188                 if ($mending >1 ){
189                         $location .= " ($mending)";
190                 }
191                 $location.=" ";
192         }
193         if ($transit > 0){
194                 $location .= "In Transit";
195                 if ($transit >1 ){
196                         $location .= " ($transit)";
197                 }
198                 $location.=" ";
199         }
200         if ($colour == 1){
201                 $toggle='#ffffcc';
202                 $colour = 0;
203         } else{
204                 $colour = 1;
205                 $toggle='white';
206         }
207         $lineres{author2}=$author2;
208         $lineres{title2}=$title2;
209         $lineres{copyright}=$result->{'copyrightdate'};
210         $lineres{id}=$id;
211         $lineres{basket}=$basket;
212         $lineres{sub}=$sub;
213         $lineres{biblionumber}=$result->{biblionumber};
214         $lineres{title}=$result->{title};
215         $lineres{author}=$result->{author};
216         $lineres{toggle}=$toggle;
217         $lineres{itemcount}=$count;
218         $lineres{location}=$location;
219         push(@loopresult,\%lineres);
220         $i++;
221 }
222
223 $offset=$num+$offset;
224 $template->param(       bookselname => $booksellers[0]->{'name'},
225                                                                 id => $id,
226                                                                 basket => $basket,
227                                                                 parsub => $sub,
228                                                                 testdonation => $testdonation,
229                                                                 count => $count,
230                                                                 offset2 =>$offset2,
231                                                                 dispnum => $dispnum,
232                                                                 offsetover => ($offset < $count ),
233                                                                 num => $num,
234                                                                 offset => $offset,
235                                                                 type =>  $type,
236                                                                 id => $id,
237                                                                 basket => $basket,
238                                                                 title => $title,
239                                                                 author => $author,
240                                                                 loopsearch =>\@loopsearch,
241                                                                 loopresult =>\@loopresult);
242
243 output_html_with_http_headers $input, $cookie, $template->output;