Removing reference to the FrontSearch subroutine as its never called
[srvgit] / search.pl
1 #!/usr/bin/perl
2 #script to provide intranet (librarian) advanced search facility
3
4 use strict;
5 use C4::Search;
6 use CGI;
7 use C4::Output;
8
9 my $env;
10 my $input = new CGI;
11 print $input->header;
12 #print $input->dump;
13 #whether it is called from the opac of the intranet                                                            
14 my $type=$input->param('type');                                                  
15 if ($type eq ''){
16   $type = 'intra';
17 }
18 my $ttype=$input->param('ttype');
19 #setup colours                                                                                                 
20 my $main;                                                                                                      
21 my $secondary;                                                                                                 
22 if ($type eq 'opac'){                                                                                          
23   $main='#99cccc';    
24   $secondary='#efe5ef';
25 } else {                                                                                                       
26   $main='#cccc99';                                                                                             
27   $secondary='#ffffcc';                                                                                        
28 }       
29
30 #print $input->Dump;
31 my $blah;
32 my %search;
33 #build hash of users input
34 my $title=validate($input->param('title'));
35 $search{'title'}=$title;
36 my $keyword=validate($input->param('keyword'));
37 $search{'keyword'}=$keyword;
38 $search{'front'}=validate($input->param('front'));
39 my $author=validate($input->param('author'));
40 $search{'author'}=$author;
41 my $illustrator=validate($input->param('illustrator'));
42 $search{'illustrator'}=$illustrator;
43 my $subject=validate($input->param('subject'));
44 $search{'subject'}=$subject;
45 my $itemnumber=validate($input->param('item'));
46 $search{'item'}=$itemnumber;
47 my $isbn=validate($input->param('isbn'));
48 $search{'isbn'}=$isbn;
49 my $datebefore=validate($input->param('date-before'));
50 $search{'date-before'};
51 my $class=$input->param('class');
52 $search{'class'}=$class;
53 $search{'ttype'}=$ttype;
54 my $dewey=validate($input->param('dewey'));
55 $search{'dewey'}=$dewey;
56 my $branch=validate($input->param('branch'));
57 $search{'branch'}=$branch;
58 my @results;
59 my $offset=$input->param('offset');
60 if ($offset eq ''){
61   $offset=0;
62 }
63 my $num=$input->param('num');
64 if ($num eq ''){
65   $num=10;
66 }
67 print startpage();
68 print startmenu($type);
69 #print $type;
70 #print $search{'ttype'};
71 if ($type eq 'intra'){
72   print mkheadr(1,'Catalogue Search Results');
73 } elsif ($type eq 'catmain'){
74   print mkheadr(1,'Catalogue Maintenance');
75 } else {
76   print mkheadr(1,'Opac Search Results');
77 }
78 print center();
79 my $count;
80 my @results;
81 if ($itemnumber ne '' || $isbn ne ''){
82     ($count,@results)=&CatSearch(\$blah,'precise',\%search,$num,$offset);
83 } else {
84   if ($subject ne ''){
85     ($count,@results)=&CatSearch(\$blah,'subject',\%search,$num,$offset);
86   } else {
87     if ($keyword ne ''){
88       ($count,@results)=&KeywordSearch(\$blah,'intra',\%search,$num,$offset);
89     }elsif ($title ne '' || $author ne '' || $illustrator ne '' || $dewey ne '' || $class ne '') {
90       ($count,@results)=&CatSearch(\$blah,'loose',\%search,$num,$offset);
91     }
92   }
93 }
94 print "You searched on ";
95 while ( my ($key, $value) = each %search) {                                 
96   if ($value ne '' && $key ne 'ttype'){
97     $value=~ s/\\//g;
98     print bold("$key $value,");
99   }                          
100 }
101 print " $count results found";
102 my $offset2=$num+$offset;
103 my $dispnum=$offset+1;
104 print "<br> Results $dispnum to $offset2 displayed";
105 print mktablehdr;
106 if ($type ne 'opac'){
107   if ($subject ne ''){
108    print mktablerow(1,$main,'<b>SUBJECT</b>','/images/background-mem.gif');
109   } elsif ($illustrator ne '') {
110    print mktablerow(7,$main,'<b>TITLE</b>','<b>AUTHOR</b>', '<b>ILLUSTRATOR<b>', bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'','/images/background-mem.gif');
111   } else {
112    print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'','/images/background-mem.gif');
113   }
114 } else {
115   if ($subject ne ''){
116    print mktablerow(6,$main,'<b>SUBJECT</b>',' &nbsp; ',' &nbsp; ');
117   } elsif ($illustrator ne '') {
118    print mktablerow(7,$main,'<b>TITLE</b>','<b>AUTHOR</b>','<b>ILLUSTRATOR</b>', bold('&copy;'),'<b>COUNT</b>',bold('BRANCH'),'');
119   } else {
120    print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('BRANCH'),'');
121   }
122 }
123 my $count2=@results;
124 if ($keyword ne '' && $offset > 0){
125   $count2=$count-$offset;
126   if ($count2 > 10){
127     $count2=10;
128   }
129 }
130 #print $count2;
131 my $i=0;
132 my $colour=1;
133 while ($i < $count2){
134 #    print $results[$i]."\n";
135     my @stuff=split('\t',$results[$i]);
136     $stuff[1]=~ s/\`/\\\'/g;
137     my $title2=$stuff[1];
138     $title2=~ s/ /%20/g;
139     if ($subject eq ''){
140 #      print $stuff[0];
141       $stuff[1]=mklink("/cgi-bin/koha/detail.pl?type=$type&bib=$stuff[2]&title=$title2",$stuff[1]);
142       my $word=$stuff[0];
143 #      print $word;
144       $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
145       $word=~ s/  //g;
146       $word=~ s/ /%20/g;
147       $word=~ s/\,/\,%20/g;
148       $word=~ s/\n//g;
149       my $url="/cgi-bin/koha/search.pl?author=$word&type=$type";
150       $stuff[7]=$stuff[5];
151       $stuff[5]='';
152       $stuff[0]=mklink($url,$stuff[0]);
153       my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount)=itemcount($env,$stuff[2],$type);
154       $stuff[4]=$count;
155       if ($nacount > 0){
156         $stuff[5]=$stuff[5]."On Loan";
157         if ($nacount >1 ){                                                                                                         
158           $stuff[5]=$stuff[5]." ($nacount)";                                                                                            
159          }                                                                                                                         
160          $stuff[5].=" ";
161       }
162       if ($lcount > 0){
163          $stuff[5]=$stuff[5]."Levin";
164          if ($lcount >1 ){                                                                                                         
165           $stuff[5]=$stuff[5]." ($lcount)";                                                                                            
166          }                                                                                                                         
167          $stuff[5].=" ";
168       }
169       if ($fcount > 0){
170         $stuff[5]=$stuff[5]."Foxton";
171          if ($fcount >1 ){                                                                                                         
172           $stuff[5]=$stuff[5]." ($fcount)";                                                                                            
173          }                                                                                                                         
174          $stuff[5].=" ";        
175       }
176       if ($scount > 0){
177         $stuff[5]=$stuff[5]."Shannon";
178          if ($scount >1 ){                                                                                                         
179           $stuff[5]=$stuff[5]." ($scount)";                                                                                            
180          }                                                                                                                         
181          $stuff[5].=" ";        
182       }
183       if ($lostcount > 0){
184         $stuff[5]=$stuff[5]."Lost";
185          if ($lostcount >1 ){                                                                                                         
186           $stuff[5]=$stuff[5]." ($lostcount)";                                                                                            
187          }                                                                                                                         
188          $stuff[5].=" ";        
189       }
190       if ($mending > 0){
191         $stuff[5]=$stuff[5]."Mending";
192          if ($mending >1 ){                                                                                                         
193           $stuff[5]=$stuff[5]." ($mending)";                                                                                            
194          }                                                                                                                         
195          $stuff[5].=" ";        
196       }
197       if ($transit > 0){
198         $stuff[5]=$stuff[5]."In Transiit";
199          if ($transit >1 ){                                                                                                         
200           $stuff[5]=$stuff[5]." ($transit)";                                                                                            
201          }                                                                                                                         
202          $stuff[5].=" ";        
203       }
204       if ($ocount > 0){
205         $stuff[5]=$stuff[5]."On Order";
206          if ($ocount >1 ){                                                                                                         
207           $stuff[5]=$stuff[5]." ($ocount)";                                                                                            
208          }                                                                                                                         
209          $stuff[5].=" ";        
210       }
211       
212       if ($type ne 'opac'){
213         $stuff[6]=mklink("/cgi-bin/koha/request.pl?bib=$stuff[2]","Request");
214       }
215     } else {
216       my $word=$stuff[1];
217       $word=~ s/ /%20/g;
218       
219         $stuff[1]=mklink("/cgi-bin/koha/subjectsearch.pl?subject=$word&type=$type",$stuff[1]);
220
221     }
222
223     if ($colour == 1){
224       if ($illustrator) {
225           print mktablerow(7,$secondary,$stuff[1],$stuff[0],$stuff[7],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
226       } else {
227           print mktablerow(6,$secondary,$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
228       }
229       $colour=0;
230     } else {
231       if ($illustrator) {
232           print mktablerow(7,'white',$stuff[1],$stuff[0],$stuff[7],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
233       } else {
234           print mktablerow(6,'white',$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
235       }
236       $colour=1;
237     }
238     $i++;
239 }
240 $offset=$num+$offset;
241 if ($type ne 'opac'){
242     if ($illustrator) {
243          print mktablerow(7,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','','/images/background-mem.gif');
244     } else {
245          print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','/images/background-mem.gif');
246     }
247 } else {
248  if ($illustrator) {
249      print mktablerow(7,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp; ','', '','');
250  } else {
251      print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp; ','','');
252  }
253 }
254 print mktableft();
255 my $search;
256
257     $search="num=$num&offset=$offset&type=$type";
258     if ($subject ne ''){
259       $subject=~ s/ /%20/g;
260       $search=$search."&subject=$subject";
261     }
262     if ($title ne ''){
263       $title=~ s/ /%20/g;
264       $search=$search."&title=$title";
265     }
266     if ($author ne ''){
267       $author=~ s/ /%20/g;
268       $search=$search."&author=$author";
269     }
270     if ($keyword ne ''){
271       $keyword=~ s/ /%20/g;
272       $search=$search."&keyword=$keyword";
273     }
274     if ($class ne ''){
275       $keyword=~ s/ /%20/g;
276       $search=$search."&class=$class";
277     }
278     if ($dewey ne ''){
279       $search=$search."&dewey=$dewey";
280     }
281     $search.="&ttype=$ttype";    
282 if ($offset < $count){    
283     my $stuff=mklink("/cgi-bin/koha/search.pl?$search",'Next');
284     print $stuff;
285 }
286 print "<br>";
287 my $pages=$count/10;
288 $pages++;
289 for (my $i=1;$i<$pages;$i++){
290   my $temp=$i*10;
291   $temp=$temp-10;
292   $search=~ s/offset=[0-9]+/offset=$temp/;
293   my $stuff=mklink("/cgi-bin/koha/search.pl?$search",$i);
294   print "$stuff ";
295 }
296   
297 print endcenter();
298 print endmenu($type);
299 print endpage();
300
301
302 sub validate {
303   my ($input)=@_;
304   $input=~ s/\<[a-z]+\>//gi;
305   $input=~ s/\<\/[a-z]+\>//gi;
306   $input=~ s/\<//g;
307   $input=~ s/\>//g;
308   $input=~ s/^%//g;
309   return($input);
310 }