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