first cut at a release testing howto
[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 use C4::Biblio;
11
12 my $env;
13 my $input = new CGI;
14 print $input->header;
15 #whether it is called from the opac of the intranet                                                            
16 my $type=$input->param('type');                                                  
17 if ($type eq ''){
18   $type = 'intra';
19 }
20 #setup colours                                                                                                 
21 my $main;                                                                                                      
22 my $secondary;                                                                                                 
23   $main='#cccc99';                                                                                             
24   $secondary='#ffffcc';                                                                                        
25
26
27 #print $input->dump;
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
72
73     if ($keyword ne ''){
74 #      print "hey";
75       ($count,@results)=KeywordSearch(undef,'intra',\%search,$num,$offset);
76     } elsif ($search{'front'} ne '') {
77     ($count,@results)=FrontSearch(undef,'intra',\%search,$num,$offset);
78     }else {
79       ($count,@results)=CatSearch(undef,'loose',\%search,$num,$offset);
80 #            print "hey";
81     }
82
83 print "You searched on ";
84 while ( my ($key, $value) = each %search) {                                 
85   if ($value ne ''){
86     $value=~ s/\\//g;
87     print bold("$key $value,");
88   }                          
89 }
90 print " $count results found";
91 my $offset2=$num+$offset;
92 my $dispnum=$offset+1;
93 print "<br> Results $dispnum to $offset2 displayed";
94 print mktablehdr;
95
96
97 print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'','/images/background-mem.gif');
98
99
100 my $count2=@results;
101 if ($keyword ne '' && $offset > 0){
102   $count2=$count-$offset;
103   if ($count2 > 10){
104     $count2=10;
105   }
106 }
107 #print $count2;
108 my $i=0;
109 my $colour=1;
110 while ($i < $count2){
111 #    print $results[$i]."\n";
112     my @stuff=split('\t',$results[$i]);
113     $stuff[1]=~ s/\`/\\\'/g;
114     my $title2=$stuff[1];
115     my $author2=$stuff[0];
116     my $copyright=$stuff[3];
117     $author2=~ s/ /%20/g;
118     $title2=~ s/ /%20/g;
119     $title2=~ s/\#/\&\#x23;/g;
120       $stuff[1]=mklink("/cgi-bin/koha/acqui/newbiblio.pl?title=$title2&author=$author2&copyright=$copyright&id=$id&basket=$basket&biblio=$stuff[2]",$stuff[1]);
121       my $word=$stuff[0];
122 #      print $word;
123       $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
124       $word=~ s/  //g;
125       $word=~ s/ /%20/g;
126       $word=~ s/\,/\,%20/g;
127       $word=~ s/\n//g;
128       my $url="/cgi-bin/koha/search.pl?author=$word&type=$type";
129       $stuff[0]=mklink($url,$stuff[0]);
130       my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=itemcount($env,$stuff[2],$type);
131       $stuff[4]=$count;
132       if ($nacount > 0){
133         $stuff[5]=$stuff[5]."On Loan";
134         if ($nacount >1 ){                                                                                                         
135           $stuff[5]=$stuff[5]." ($nacount)";                                                                                            
136          }                                                                                                                         
137          $stuff[5].=" ";
138       }
139       if ($lcount > 0){
140          $stuff[5]=$stuff[5]."Levin";
141          if ($lcount >1 ){                                                                                                         
142           $stuff[5]=$stuff[5]." ($lcount)";                                                                                            
143          }                                                                                                                         
144          $stuff[5].=" ";
145       }
146       if ($fcount > 0){
147         $stuff[5]=$stuff[5]."Foxton";
148          if ($fcount >1 ){                                                                                                         
149           $stuff[5]=$stuff[5]." ($fcount)";                                                                                            
150          }                                                                                                                         
151          $stuff[5].=" ";        
152       }
153       if ($scount > 0){
154         $stuff[5]=$stuff[5]."Shannon";
155          if ($scount >1 ){                                                                                                         
156           $stuff[5]=$stuff[5]." ($scount)";                                                                                            
157          }                                                                                                                         
158          $stuff[5].=" ";        
159       }
160       if ($lostcount > 0){
161         $stuff[5]=$stuff[5]."Lost";
162          if ($lostcount >1 ){                                                                                                         
163           $stuff[5]=$stuff[5]." ($lostcount)";                                                                                            
164          }                                                                                                                         
165          $stuff[5].=" ";        
166       }
167       if ($mending > 0){
168         $stuff[5]=$stuff[5]."Mending";
169          if ($mending >1 ){                                                                                                         
170           $stuff[5]=$stuff[5]." ($mending)";                                                                                            
171          }                                                                                                                         
172          $stuff[5].=" ";        
173       }
174       if ($transit > 0){
175         $stuff[5]=$stuff[5]."In Transiit";
176          if ($transit >1 ){                                                                                                         
177           $stuff[5]=$stuff[5]." ($transit)";                                                                                            
178          }                                                                                                                         
179          $stuff[5].=" ";        
180       }
181       
182     if ($colour == 1){
183       print mktablerow(6,$secondary,$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
184       $colour=0;
185     } else{
186       print mktablerow(6,'white',$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
187       $colour=1;
188     }
189     $i++;
190 }
191 $offset=$num+$offset;
192
193  print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','/images/background-mem.gif');
194
195 print mktableft();
196 if ($offset < $count){
197     my $search="num=$num&offset=$offset&type=$type&id=$id&basket=$basket&search=$keyword";
198     my $stuff=mklink("/cgi-bin/koha/acqui/newbasket2.pl?$search",'Next');
199     print $stuff;
200 }
201
202 print endcenter();
203 print endmenu('acquisitions');
204 print endpage();