Some code cleanup. Created subroutines for ISBN checksum,
[koha.git] / acqui.simple / keywordsearch.pl
1 #!/usr/bin/perl
2
3 use CGI;
4 use strict;
5 use C4::Acquisitions;
6 use C4::Search;
7 use C4::Output;
8
9 my $input    = new CGI;
10 my $keywords = $input->param('keyword');
11 my $offset   = $input->param('offset');
12 my $num      = $input->param('num');
13 my $total;
14 my $count;
15 my @results;
16
17 if (! $keywords) {
18     print $input->redirect('addbooks.pl');
19 } else {
20     if (! $offset) { $offset = 0 };
21     if (! $num) { $num = 10 };
22     my %search;
23     $search{'keyword'}=$keywords;
24     ($count, @results) = KeywordSearch(undef,'intra',\%search,$num,$offset);
25
26     if ($count < ($offset + $num)) {
27         $total = $count;
28     } else {
29         $total = $offset + $num;
30     } # else
31
32     print $input->header;
33     print startpage();
34     print startmenu('acquisitions');
35
36     print << "EOF";
37 <font size="6"><em>Biblio Search Results</em></font><br />
38 <CENTER>
39 You searched on <b>keywords $keywords,</b> $count results found <br />
40 Results $offset to $total displayed
41 <div align="right">
42 <h2><a href="addbiblio.pl">Add New Biblio</a></h2>
43 </div>
44 <p />
45 <table border="0" cellspacing="0" cellpadding="5">
46 <tr valign=top bgcolor=#cccc99>
47 <td background="/images/background-mem.gif"><b>TITLE</b></td>
48 <td background="/images/background-mem.gif"><b>AUTHOR</b></td>
49 <td background="/images/background-mem.gif"><b>&copy;</b></td>
50 </tr>
51 EOF
52
53     for (my $i = $offset; $i < $total; $i++) {
54         if ($i % 2) {
55             print << "EOF";
56 <tr valign="top" bgcolor="#ffffcc">
57 EOF
58         } else {
59             print << "EOF";
60 <tr valign="top" bgcolor="#ffffff">
61 EOF
62         } # else
63
64         print << "EOF";
65 <td><a href="addbiblioitem.pl?biblionumber=$results[$i]->{'biblionumber'}">$results[$i]->{'title'}</a></td>
66 <td><a href="addbiblioitem.pl?biblionumber=$results[$i]->{'biblionumber'}">$results[$i]->{'author'}</a></td>
67 <td>$results[$i]->{'copyrightdate'}</td>
68 </tr>
69 EOF
70     } # for
71     print << "EOF";
72 <tr valign=top bgcolor=#cccc99>
73 <td background="/images/background-mem.gif">&nbsp;</td>
74 <td background="/images/background-mem.gif">&nbsp;</td>
75 <td background="/images/background-mem.gif">&nbsp;</td>
76 </tr>
77 </table>
78 <br />
79 EOF
80
81     for (my $i = 0; ($i * $num) < $count; $i++) {
82         my $newoffset = $i * $num;
83         print << "EOF";
84 <a href="keywordsearch.pl?keyword=$keywords&offset=$newoffset&num=$num">$i</a>
85 EOF
86     } # for
87
88     print << "EOF";
89 <p />
90 Results per page:
91 <a href="keywordsearch.pl?keyword=$keywords&offset=$offset&num=5">5</a>
92 <a href="keywordsearch.pl?keyword=$keywords&offset=$offset&num=10">10</a>
93 <a href="keywordsearch.pl?keyword=$keywords&offset=$offset&num=20">20</a>
94 <a href="keywordsearch.pl?keyword=$keywords&offset=$offset&num=50">50</a>
95 </CENTER>
96 <br clear="all" />
97 <p>&nbsp;</p>
98 EOF
99
100     print endmenu();
101     print endpage();
102 } # else