Kumara - predecessor to Koha
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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