Kumara - predecessor to Koha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.9 KiB

  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)
  5. #modified 29/12/99 by chris@katipo.co.nz to be usavle by opac as well
  6. use strict;
  7. use C4::Search;
  8. use CGI;
  9. use C4::Output;
  10. my $env;
  11. my $input = new CGI;
  12. print $input->header;
  13. #whether it is called from the opac of the intranet
  14. my $type=$input->param('type');
  15. #setup colours
  16. my $main;
  17. my $secondary;
  18. if ($type eq 'opac'){
  19. $main='#99cccc';
  20. $secondary='#efe5ef';
  21. } else {
  22. $main='#99cc33';
  23. $secondary='#ffffcc';
  24. }
  25. #print $input->dump;
  26. my $blah;
  27. my %search;
  28. #build hash of users input
  29. my $title=$input->param('title');
  30. $search{'title'}=$title;
  31. my $keyword=$input->param('keyword');
  32. $search{'keyword'}=$keyword;
  33. my $author=$input->param('author');
  34. $search{'author'}=$author;
  35. my $subject=$input->param('subject');
  36. $search{'subject'}=$subject;
  37. my $itemnumber=$input->param('item');
  38. $search{'item'}=$itemnumber;
  39. my $isbn=$input->param('isbn');
  40. $search{'isbn'}=$isbn;
  41. my $datebefore=$input->param('date-before');
  42. $search{'date-before'};
  43. my $class=$input->param('class');
  44. $search{'class'}=$class;
  45. my @results;
  46. my $offset=$input->param('offset');
  47. if ($offset eq ''){
  48. $offset=0;
  49. }
  50. my $num=$input->param('num');
  51. if ($num eq ''){
  52. $num=10;
  53. }
  54. print startpage();
  55. print startmenu($type);
  56. print mkheadr(1,'Catalogue Search Results');
  57. print center();
  58. my $count;
  59. my @results;
  60. if ($itemnumber ne '' || $isbn ne ''){
  61. ($count,@results)=&CatSearch(\$blah,'precise',\%search,$num,$offset);
  62. } else {
  63. if ($subject ne ''){
  64. ($count,@results)=&CatSearch(\$blah,'subject',\%search,$num,$offset);
  65. } else {
  66. if ($keyword ne ''){
  67. # print "hey";
  68. ($count,@results)=&KeywordSearch(\$blah,'intra',\%search,$num,$offset);
  69. } else {
  70. ($count,@results)=&CatSearch(\$blah,'loose',\%search,$num,$offset);
  71. # print "hey";
  72. }
  73. }
  74. }
  75. print "You searched on ";
  76. while ( my ($key, $value) = each %search) {
  77. if ($value ne ''){
  78. print bold("$key $value,");
  79. }
  80. }
  81. print " $count results found";
  82. my $offset2=$num+$offset;
  83. print "<br> Results $offset to $offset2 displayed";
  84. print mktablehdr;
  85. if ($type ne 'opac'){
  86. if ($subject ne ''){
  87. print mktablerow(1,$main,'<b>SUBJECT</b>','/images/background-mem.gif');
  88. } else {
  89. print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'','/images/background-mem.gif');
  90. }
  91. } else {
  92. if ($subject ne ''){
  93. print mktablerow(1,$main,'<b>SUBJECT</b>');
  94. } else {
  95. print mktablerow(6,$main,'<b>TITLE</b>','<b>AUTHOR</b>',bold('&copy;'),'<b>COUNT</b>',bold('LOCATION'),'');
  96. }
  97. }
  98. my $count2=@results;
  99. #print $count2;
  100. my $i=0;
  101. my $colour=1;
  102. while ($i < $count2){
  103. # print $results[$i]."\n";
  104. my @stuff=split('\t',$results[$i]);
  105. my $title2=$stuff[1];
  106. $title2=~ s/ /%20/g;
  107. if ($subject eq ''){
  108. # print $stuff[0];
  109. $stuff[1]=mklink("/cgi-bin/koha/detail.pl?type=$type&bib=$stuff[2]&title=$title2",$stuff[1]);
  110. my $word=$stuff[0];
  111. # print $word;
  112. $word=~ s/([a-z]) +([a-z])/$1%20$2/ig;
  113. $word=~ s/ //g;
  114. $word=~ s/\,/\,%20/g;
  115. $word=~ s/\n//g;
  116. my $url="/cgi-bin/koha/search.pl?author=$word&type=$type";
  117. $stuff[0]=mklink($url,$stuff[0]);
  118. my ($count,$lcount,$nacount,$fcount,$scount)=itemcount($env,$stuff[2]);
  119. $stuff[4]=$count;
  120. if ($nacount > 0){
  121. $stuff[5]=$stuff[5]."On Loan 1";
  122. }
  123. if ($lcount > 0){
  124. $stuff[5]=$stuff[5]." L$lcount";
  125. }
  126. if ($fcount > 0){
  127. $stuff[5]=$stuff[5]." F$fcount";
  128. }
  129. if ($scount > 0){
  130. $stuff[5]=$stuff[5]." S$scount";
  131. }
  132. if ($type ne 'opac'){
  133. $stuff[6]=mklink("/cgi-bin/koha/request.pl?bib=$stuff[2]","Request");
  134. }
  135. } else {
  136. my $word=$stuff[1];
  137. $word=~ s/ /%20/g;
  138. $stuff[1]=mklink("/cgi-bin/koha/subjectsearch.pl?subject=$word&type=$type",$stuff[1]);
  139. }
  140. if ($colour == 1){
  141. print mktablerow(6,$secondary,$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
  142. $colour=0;
  143. } else{
  144. print mktablerow(6,'white',$stuff[1],$stuff[0],$stuff[3],$stuff[4],$stuff[5],$stuff[6]);
  145. $colour=1;
  146. }
  147. $i++;
  148. }
  149. $offset=$num+$offset;
  150. if ($type ne 'opac'){
  151. print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp;','','','/images/background-mem.gif');
  152. } else {
  153. print mktablerow(6,$main,' &nbsp; ',' &nbsp; ',' &nbsp;',' &nbsp; ','','');
  154. }
  155. print mktableft();
  156. if ($offset < $count){
  157. my $search="num=$num&offset=$offset&type=$type";
  158. if ($subject ne ''){
  159. $subject=~ s/ /%20/g;
  160. $search=$search."&subject=$subject";
  161. }
  162. if ($title ne ''){
  163. $title=~ s/ /%20/g;
  164. $search=$search."&title=$title";
  165. }
  166. if ($author ne ''){
  167. $author=~ s/ /%20/g;
  168. $search=$search."&author=$author";
  169. }
  170. if ($keyword ne ''){
  171. $keyword=~ s/ /%20/g;
  172. $search=$search."&keyword=$keyword";
  173. }
  174. my $stuff=mklink("/cgi-bin/koha/search.pl?$search",'Next');
  175. print $stuff;
  176. }
  177. print endcenter();
  178. print endmenu($type);
  179. print endpage();