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