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