templating newbasket2.pl. (Done by hdl, new french developer !)
[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
31 my $env;
32 my $input = new CGI;
33
34 #print $input->header;
35
36 #whether it is called from the opac of the intranet
37 my $type=$input->param('type');
38 if ($type eq ''){
39   $type = 'intra';
40 }
41 #setup colours
42 my $main;
43 my $secondary;
44   $main='#cccc99';
45   $secondary='#ffffcc';
46
47
48 #print $input->dump;
49 my $blah;
50 my %search;
51 #build hash of users input
52 my $title=$input->param('search');
53 $search{'title'}=$title;
54 my $keyword=$input->param('d');
55 $search{'keyword'}=$keyword;
56 my $author=$input->param('author');
57 $search{'author'}=$author;
58
59 my @results;
60 my $offset=$input->param('offset');
61 if ($offset eq ''){
62   $offset=0;
63 }
64 my $num=$input->param('num');
65 if ($num eq ''){
66   $num=10;
67 }
68 my $id=$input->param('id');
69 my $basket=$input->param('basket');
70 my $sub=$input->param('sub');
71 my $donation;
72 if ($id == 72){
73   $donation='yes';
74 }
75 #print $sub;
76 my ($count,@booksellers)=bookseller($id);
77
78 my $template = gettemplate("acqui/newbasket2.tmpl");
79 #print startpage();
80 #print startmenu('acquisitions');
81
82 my $testdonation = ($donation ne 'yes'); #tests if donation = true
83
84     if ($keyword ne ''){
85       ($count,@results)=KeywordSearch(undef,'intra',\%search,$num,$offset);
86     } elsif ($search{'front'} ne '') {
87     ($count,@results)=FrontSearch(undef,'intra',\%search,$num,$offset);
88     }else {
89       ($count,@results)=CatSearch(undef,'loose',\%search,$num,$offset);
90     }
91
92 my @loopsearch;
93
94 while ( my ($key, $value) = each %search) {
95   if ($value ne ''){
96         my %linesearch;
97         $value=~ s/\\//g;
98         $linesearch{key}=$key;
99         $linesearch{value}=$value;
100         push(@loopsearch,\%linesearch);
101   }
102 }
103
104 my $offset2=$num+$offset;
105 my $dispnum=$offset+1;
106 if ($offset2>$count) {
107         $offset2=$count
108 }
109
110
111 my $count2=@results;
112 if ($keyword ne '' && $offset > 0){
113   $count2=$count-$offset;
114   if ($count2 > 10){
115     $count2=10;
116   }
117 }
118 #print $count2;
119 my $i=0;
120 my $colour=0;
121
122 my @loopresult;
123
124 while ($i < $count2){
125 #    print $results[$i]."\n";
126 #    my @stuff=split('\t',$results[$i]);
127
128         my %lineres;
129         my $coltab;
130
131     my $result=$results[$i];
132     $result->{'title'}=~ s/\`/\\\'/g;
133     my $title2=$result->{'title'};
134     my $author2=$result->{'author'};
135     $author2=~ s/ /%20/g;
136     $title2=~ s/ /%20/g;
137     $title2=~ s/\#/\&\#x23;/g;
138     $title2=~ s/\"/\&quot\;/g;
139
140         my $itemcount;
141     my $location='';
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       }
159       if ($lcount > 0){
160          $location .= "Levin";
161          if ($lcount >1 ){
162           $location .= " ($lcount)";
163          }
164          $location.=" ";
165       }
166       if ($fcount > 0){
167         $location .= "Foxton";
168          if ($fcount >1 ){
169           $location .= " ($fcount)";
170          }
171          $location.=" ";
172       }
173       if ($scount > 0){
174         $location .= "Shannon";
175          if ($scount >1 ){
176           $location .= " ($scount)";
177          }
178          $location.=" ";
179       }
180       if ($lostcount > 0){
181         $location .= "Lost";
182          if ($lostcount >1 ){
183           $location .= " ($lostcount)";
184          }
185          $location.=" ";
186       }
187       if ($mending > 0){
188         $location .= "Mending";
189          if ($mending >1 ){
190           $location .= " ($mending)";
191          }
192          $location.=" ";
193       }
194       if ($transit > 0){
195         $location .= "In Transit";
196          if ($transit >1 ){
197           $location .= " ($transit)";
198          }
199          $location.=" ";
200       }
201         if ($colour == 1){
202                 $coltab=$secondary;
203                 $colour=0;
204     } else{
205                 $coltab=$main;
206                 $colour=1;
207     }
208     $lineres{author2}=$author2;
209     $lineres{title2}=$title2;
210     $lineres{copyright}=$result->{'copyrightdate'};
211         $lineres{id}=$id;
212         $lineres{basket}=$basket;
213         $lineres{sub}=$sub;
214         $lineres{biblionumber}=$result->{biblionumber};
215         $lineres{title}=$result->{title};
216     $lineres{author}=$result->{author};
217         $lineres{coltab}=$coltab;
218         $lineres{itemcount}=$count;
219         $lineres{location}=$location;
220         push(@loopresult,\%lineres);
221     $i++;
222 }
223
224 $offset=$num+$offset;
225
226 #print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','/images/background-mem.gif');
227
228 #print mktableft();
229 $template->param(       bookselname => $booksellers[0]->{'name'},
230                                                                 id => $id,
231                                                                 basket => $basket,
232                                                                 parsub => $sub,
233                                                                 testdonation => $testdonation,
234                                                                 count => $count,
235                                                                 offset2 =>$offset2,
236                                                                 dispnum => $dispnum,
237                                                                 offsetover => ($offset < $count ),
238                                                                 num => $num,
239                                                                 offset => $offset,
240                                                                 type =>  $type,
241                                                                 id => $id,
242                                                                 basket => $basket,
243                                                                 title => $title,
244                                                                 author => $author,
245                                                                 loopsearch =>\@loopsearch,
246                                                                 loopresult =>\@loopresult);
247
248
249 print "Content-Type: text/html\n\n", $template->output;