Added copyright statement to all .pl and .pm files
[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
30 my $env;
31 my $input = new CGI;
32 print $input->header;
33 #whether it is called from the opac of the intranet                                                            
34 my $type=$input->param('type');                                                  
35 if ($type eq ''){
36   $type = 'intra';
37 }
38 #setup colours                                                                                                 
39 my $main;                                                                                                      
40 my $secondary;                                                                                                 
41   $main='#cccc99';                                                                                             
42   $secondary='#ffffcc';                                                                                        
43
44
45 #print $input->dump;
46 my $blah;
47 my %search;
48 #build hash of users input
49 my $title=$input->param('search');
50 $search{'title'}=$title;
51 my $keyword=$input->param('d');
52 $search{'keyword'}=$keyword;
53 my $author=$input->param('author');
54 $search{'author'}=$author;
55
56 my @results;
57 my $offset=$input->param('offset');
58 if ($offset eq ''){
59   $offset=0;
60 }
61 my $num=$input->param('num');
62 if ($num eq ''){
63   $num=10;
64 }
65 my $id=$input->param('id');
66 my $basket=$input->param('basket');
67 my $sub=$input->param('sub');
68 my $donation;
69 if ($id == 72){
70   $donation='yes';
71 }
72 #print $sub;
73 my ($count,@booksellers)=bookseller($id);
74
75 print startpage();
76 print startmenu('acquisitions');
77 print mkheadr(1,"Shopping Basket For: $booksellers[0]->{'name'}");
78
79 if ($donation ne 'yes'){
80   print "<a href=newbiblio.pl?id=$id&basket=$basket&sub=$sub>";
81 } else {
82   print "<a href=newdonation.pl?id=$id&basket=$basket&sub=$sub>";
83 }
84 print <<printend
85 <img src=/images/add-biblio.gif width=187 heigth=42 border=0 align=right alt="Add New Biblio"></a>
86 <a href=basket.pl?basket=$basket><img src=/images/view-basket.gif width=187 heigth=42 border=0 align=right alt="View Basket"></a>
87
88 <FORM ACTION="/cgi-bin/koha/acqui/newbasket2.pl">
89 <input type=hidden name=id value="$id">
90 <input type=hidden name=basket value="$basket">
91 <b>New Search: </b><INPUT TYPE="text"  SIZE="25"   NAME="search"></form>
92 <br clear=all>
93
94 printend
95 ;
96
97 print center();
98
99
100     if ($keyword ne ''){
101 #      print "hey";
102       ($count,@results)=KeywordSearch(undef,'intra',\%search,$num,$offset);
103     } elsif ($search{'front'} ne '') {
104     ($count,@results)=FrontSearch(undef,'intra',\%search,$num,$offset);
105     }else {
106       ($count,@results)=CatSearch(undef,'loose',\%search,$num,$offset);
107 #            print "hey";
108     }
109
110 print "You searched on ";
111 while ( my ($key, $value) = each %search) {                                 
112   if ($value ne ''){
113     $value=~ s/\\//g;
114     print bold("$key $value,");
115   }                          
116 }
117 print " $count results found";
118 my $offset2=$num+$offset;
119 my $dispnum=$offset+1;
120 print "<br> Results $dispnum to $offset2 displayed";
121 print mktablehdr;
122
123
124 print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'','/images/background-mem.gif');
125
126
127 my $count2=@results;
128 if ($keyword ne '' && $offset > 0){
129   $count2=$count-$offset;
130   if ($count2 > 10){
131     $count2=10;
132   }
133 }
134 #print $count2;
135 my $i=0;
136 my $colour=1;
137 while ($i < $count2){
138 #    print $results[$i]."\n";
139 #    my @stuff=split('\t',$results[$i]);
140     my $result=$results[$i];
141     $result->{'title'}=~ s/\`/\\\'/g;
142     my $title2=$result->{'title'};
143     my $author2=$result->{'author'};
144     my $copyright=$result->{'copyrightdate'};
145     $author2=~ s/ /%20/g;
146     $title2=~ s/ /%20/g;
147     $title2=~ s/\#/\&\#x23;/g;
148     $title2=~ s/\"/\&quot\;/g;
149     my $itemcount;
150     my $location='';
151     if ($donation eq 'yes'){
152       $result->{'title'}=mklink("/cgi-bin/koha/acqui/newdonation.pl?author=$author2&copyright=$copyright&id=$id&basket=$basket&biblio=$result->{'biblionumber'}&title=$title2",$result->{'title'});
153     } else {
154       $result->{'title'}=mklink("/cgi-bin/koha/acqui/newbiblio.pl?sub=$sub&author=$author2&copyright=$copyright&id=$id&basket=$basket&biblio=$result->{'biblionumber'}&title=$title2",$result->{'title'});
155     }  
156     my $word=$result->{'author'};
157       $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
158       $word=~ s/  //g;
159       $word=~ s/ /%20/g;
160       $word=~ s/\,/\,%20/g;
161       $word=~ s/\n//g;
162       my $url="/cgi-bin/koha/search.pl?author=$word&type=$type";
163       $result->{'author'}=mklink($url,$result->{'author'});
164       my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=C4::Search::itemcount($env,$result->{'biblionumber'},$type);
165       $itemcount=$count;
166       if ($nacount > 0){
167         $location=$location."On Loan";
168         if ($nacount >1 ){                                                                                                         
169           $location=$location." ($nacount)";                                                                                            
170          }                                                                                                                         
171          $location.=" ";
172       }
173       if ($lcount > 0){
174          $location=$location."Levin";
175          if ($lcount >1 ){                                                                                                         
176           $location=$location." ($lcount)";                                                                                            
177          }                                                                                                                         
178          $location.=" ";
179       }
180       if ($fcount > 0){
181         $location=$location."Foxton";
182          if ($fcount >1 ){                                                                                                         
183           $location=$location." ($fcount)";                                                                                            
184          }                                                                                                                         
185          $location.=" ";        
186       }
187       if ($scount > 0){
188         $location=$location."Shannon";
189          if ($scount >1 ){                                                                                                         
190           $location=$location." ($scount)";                                                                                            
191          }                                                                                                                         
192          $location.=" ";        
193       }
194       if ($lostcount > 0){
195         $location=$location."Lost";
196          if ($lostcount >1 ){                                                                                                         
197           $location=$location." ($lostcount)";                                                                                            
198          }                                                                                                                         
199          $location.=" ";        
200       }
201       if ($mending > 0){
202         $location=$location."Mending";
203          if ($mending >1 ){                                                                                                         
204           $location=$location." ($mending)";                                                                                            
205          }                                                                                                                         
206          $location.=" ";        
207       }
208       if ($transit > 0){
209         $location=$location."In Transiit";
210          if ($transit >1 ){                                                                                                         
211           $location=$location." ($transit)";                                                                                            
212          }                                                                                                                         
213          $location.=" ";        
214       }
215       
216     if ($colour == 1){
217       print mktablerow(6,$secondary,$result->{'title'},$result->{'author'},$result->{'copyrightdate'},$itemcount,$location);
218       $colour=0;
219     } else{
220       print mktablerow(6,'white',$result->{'title'},$result->{'author'},$result->{'copyrightdate'},$itemcount,$location);
221       $colour=1;
222     }
223     $i++;
224 }
225 $offset=$num+$offset;
226
227  print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','/images/background-mem.gif');
228
229 print mktableft();
230 if ($offset < $count){
231     my $search="num=$num&offset=$offset&type=$type&id=$id&basket=$basket&search=$title&author=$author";
232     my $stuff=mklink("/cgi-bin/koha/acqui/newbasket2.pl?$search",'Next');
233     print $stuff;
234 }
235
236 print endcenter();
237 print endmenu('acquisitions');
238 print endpage();