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