loadmodules.pl allows redirection to different modules based on systemprefs
[koha.git] / opac-search.pl
blob10084797a3e5194020905b0f4133acafc686b98c
1 #!/usr/bin/perl
2 #script to provide intranet (librarian) advanced search facility
3 #modified 9/11/1999 by chris@katipo.co.nz
4 #adding an extra comment to play with CVS (Si, 19/11/99)
6 use strict;
7 #use DBI;
8 use C4::Search;
9 use CGI;
10 use C4::Output;
12 my $env;
13 my $input = new CGI;
14 print $input->header;
15 #print $input->Dump;
16 my $blah;
17 my %search;
18 #build hash of users input
21 my $keyword=validateinp($input->param('keyword'));
22 #my $keyword=$input->param('keyword');
23 #$keyword=~ s/'/\'/g;
24 $search{'keyword'}=$keyword;
26 my @results;
27 my $offset=$input->param('offset');
28 if ($offset eq ''){
29 $offset=0;
31 my $num=$input->param('num');
32 if ($num eq ''){
33 $num=10;
35 print startpage();
36 print startmenu('opac');
37 print mkheadr(1,"Opac Search Results for $keyword");
38 print center();
39 my $count;
40 my @results;
41 if ($search{'keyword'} ne ''){
42 ($count,@results)=&OpacSearch(\$blah,'loose',\%search,$num,$offset);
44 #print "You searched on <b>$keyword</b>";
46 print " $count results found";
47 my $offset2=$num+$offset;
48 my $disp=$offset+1;
49 print ", Results $disp to $offset2 displayed";
50 print mktablehdr;
52 print mktablerow(4,'#99cccc','<b>TITLE</b>','<b>AUTHOR</b>','<b>COUNT</b>',bold('BRANCH'));
54 my $count2=@results;
55 my $i=0;
56 my $colour=1;
57 while ($i < $count2){
58 my @stuff=split('\t',$results[$i]);
59 $stuff[1]=~ s/\`/\'/g;
60 my $title2=$stuff[1];
61 $title2=~ s/ /%20/g;
63 $stuff[1]=mklink("/cgi-bin/koha/detail.pl?bib=$stuff[2]&title=$title2&type=opac",$stuff[1]);
64 my $word=$stuff[0];
65 $word=~ s/ //g;
66 $word=~ s/ /%20/g;
67 $word=~ s/\,/\,%20/g;
68 $word=~ s/\n//g;
69 my $url="/cgi-bin/koha/search.pl?author=$word&type=opac";
70 $stuff[0]=mklink($url,$stuff[0]);
71 my ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit)=itemcount($env,$stuff[2]);
72 $stuff[3]=$count;
73 if ($nacount > 0){
74 $stuff[4]=$stuff[4]."On Loan";
75 if ($nacount >1 ){
76 $stuff[4]=$stuff[4]." ($nacount)";
78 $stuff[4].=" ";
80 if ($lcount > 0){
81 $stuff[4]=$stuff[4]."Levin";
82 if ($lcount >1 ){
83 $stuff[4]=$stuff[4]." ($lcount)";
85 $stuff[4].=" ";
87 if ($fcount > 0){
88 $stuff[4]=$stuff[4]."Foxton";
89 if ($fcount >1 ){
90 $stuff[4]=$stuff[4]." ($fcount)";
92 $stuff[4].=" ";
94 if ($scount > 0){
95 $stuff[4]=$stuff[4]."Shannon";
96 if ($scount >1 ){
97 $stuff[4]=$stuff[4]." ($scount)";
99 $stuff[4].=" ";
101 if ($mending > 0){
102 $stuff[4]=$stuff[4]."Mending";
103 if ($mending >1 ){
104 $stuff[4]=$stuff[4]." ($mending)";
106 $stuff[4].=" ";
108 if ($transit > 0){
109 $stuff[4]=$stuff[4]."In Transit";
110 if ($transit >1 ){
111 $stuff[4]=$stuff[4]." ($transit)";
113 $stuff[4].=" ";
115 if ($colour == 1){
116 print mktablerow(4,'#efe5ef',$stuff[1],$stuff[0],$stuff[3],$stuff[4]);
117 $colour=0;
118 } else{
119 print mktablerow(4,'white',$stuff[1],$stuff[0],$stuff[3],$stuff[4]);
120 $colour=1;
122 $i++;
124 $offset=$num+$offset;
125 if ($offset < $count){
126 $keyword=~ s/ /%20/g;
127 my $search="num=$num&offset=$offset&keyword=$keyword";
128 my $stuff=mklink("/cgi-bin/koha/opac-search.pl?$search",'Next Results');
129 # print $stuff;
130 print "<tr valign=top bgcolor=#99cccc><td colspan=4>$stuff
131 </td></tr>";
132 } else {
133 print mktablerow(4,'#99cccc',' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;');
135 print mktableft();
138 print endcenter();
139 print endmenu('opac');
140 print endpage();
143 sub validateinp {
144 my ($input)=@_;
145 $input=~ s/\<[a-z]+\>//gi;
146 $input=~ s/\<\/[a-z]+\>//gi;
147 $input=~ s/\<//g;
148 $input=~ s/\>//g;
149 $input=~ s/%//g;
150 return($input);