Started work on a web-based circulation interface.
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 use CGI qw/:standard/;
4 use C4::Circulation::Circ2;
5 use C4::Output;
6 use DBI;
7
8
9 my %env;
10 my $query=new CGI;
11 print $query->header;
12 print startpage();
13 print startmenu('catalogue');
14
15 print << "EOF";
16 <center>
17 <a href=circulation.pl?module=issues>Issues</a> |
18 <a href=circulation.pl?module=returns>Returns</a>
19 <hr>
20 EOF
21
22 SWITCH: {
23     if ($query->param('module') eq 'issues') { issues(); last SWITCH; }
24     if ($query->param('module') eq 'returns') { returns(); last SWITCH; }
25     issues();
26 }
27
28
29 print endmenu();
30 print endpage();
31 sub default {
32 print << "EOF";
33 <a href=circulation.pl?module=issues>Issues</a>
34 <a href=circulation.pl?module=returns>Returns</a>
35 EOF
36 }
37
38 sub issues {
39     if (my $borrnumber=$query->param('borrnumber')) {
40         my ($borrower, $flags) = getpatroninformation(\%env,$borrnumber,0);
41         if (my $barcode=$query->param('barcode')) {
42             my %responses;
43             foreach (sort $query->param) {
44                 if ($_ =~ /response-(\d*)/) {
45                     $responses{$1}=$query->param($_);
46                 }
47             }
48             if (my $qnumber=$query->param('questionnumber')) {
49                 $responses{$qnumber}=$query->param('answer');
50             }
51             my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer) = issuebook(\%env, $borrower, $barcode, \%responses);
52             if ($rejected) {
53                 if ($rejected == -1) {
54                 } else {
55                     print "Error issuing book: $rejected<br>\n";
56                 }
57             }
58             if ($question) {
59                 print << "EOF";
60                 <table border=1 bgcolor=#dddddd>
61                 <tr><th bgcolor=black><font color=white><b>Issuing Question</b></font></td></tr>
62                 <tr><td>
63                 Attempting to issue $iteminformation->{'title'} by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
64                 <br>
65                 $question
66                 </td></tr>
67
68                 <tr><td align=center>
69                 <table border=0>
70                 <tr><td>
71                 <form method=get>
72                 <input type=hidden name=module value=issues>
73                 <input type=hidden name=borrnumber value=$borrnumber>
74                 <input type=hidden name=barcode value=$barcode>
75                 <input type=hidden name=questionnumber value=$questionnumber>
76                 <input type=hidden name=answer value=Y>
77                 <input type=submit value=Yes>
78                 </form>
79                 </td>
80                 <td>
81                 <form method=get>
82                 <input type=hidden name=module value=issues>
83                 <input type=hidden name=borrnumber value=$borrnumber>
84                 <input type=hidden name=barcode value=$barcode>
85                 <input type=hidden name=questionnumber value=$questionnumber>
86                 <input type=hidden name=answer value=N>
87                 <input type=submit value=No>
88                 </form>
89                 </td>
90                 </tr>
91                 </table>
92                 </td></tr>
93                 </table>
94 EOF
95                 return;
96             }
97         }
98         my $issueid=$query->param('issueid');
99         ($issueid) || ($issueid=int(rand()*1000000000));
100         my $flag='';
101         my $flagtext='';
102         foreach $flag (sort keys %$flags) {
103             $flagtext.="$flag ";
104         }
105         $env{'nottodaysissues'}=1;
106         my ($borrowerissues) = currentissues(\%env, $borrower);
107         $env{'nottodaysissues'}=0;
108         $env{'todaysissues'}=1;
109         my ($today) = currentissues(\%env, $borrower);
110         $env{'todaysissues'}=0;
111         my $previssues='';
112         my @datearr = localtime(time());
113         my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", $datearr[3]);
114         foreach (sort keys %$borrowerissues) {
115             my $bookissue=$borrowerissues->{$_};
116             my $bgcolor='';
117             my $datedue=$bookissue->{'date_due'};
118             $datedue=~s/-//g;
119             if ($datedue < $todaysdate) {
120                 $bgcolor="bgcolor=red";
121             }
122             $previssues.="<tr $bgcolor><td>$bookissue->{'date_due'}</td><td>$bookissue->{'barcode'}</td><td>$bookissue->{'title'}</td><td>$bookissue->{'author'}</td><td>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>\n";
123         }
124         my $todaysissues='';
125         foreach (sort keys %$today) {
126             my $bookissue=$today->{$_};
127             $todaysissues.="<tr><td>$bookissue->{'date_due'}</td><td>$bookissue->{'barcode'}</td><td>$bookissue->{'title'}</td><td>$bookissue->{'author'}</td><td>$bookissue->{'dewey'} $bookissue->{'subclass'}</td></tr>\n";
128         }
129         print << "EOF";
130         <form method=get>
131         <input type=hidden name=module value=issues>
132         <input type=hidden name=borrnumber value=$borrnumber>
133     <table border=0 cellpadding=5>
134     <tr>
135         <td align=left>
136             <table border=3 bgcolor=#dddddd>
137                 <tr><td colspan=2 bgcolor=black><font color=white><b>Enter Book Barcode</b></font></td></tr>
138                 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
139             </table>
140         </td>
141         <td align=right>
142         <table border=1 bgcolor=#dddddd>
143         <tr><th bgcolor=black><font color=white><b>Patron Information</b></font></td></tr>
144         <tr><td>
145         $borrower->{'cardnumber'} $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>
146         $borrower->{'streetaddress'} $borrower->{'city'}<br>
147         $borrower->{'categorycode'} $flagtext
148         </td></tr>
149         </table>
150         </td>
151     </tr>
152     <tr>
153         <td colspan=2 align=center>
154         <table border=1 width=100% bgcolor=#dddddd>
155             <tr><th colspan=5 bgcolor=black><font color=white><b>Today's Issues</b></font></th></tr>
156             <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
157             $todaysissues
158         </table>
159         </td>
160     </tr>
161     <tr>
162         <td colspan=2 align=center>
163         <table border=1 width=100% bgcolor=#dddddd>
164             <tr><th colspan=5 bgcolor=black><font color=white><b>Previous Issues</b></font></th></tr>
165             <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
166             $previssues
167         </table>
168         </td>
169     </tr>
170 </table>
171 EOF
172     } else {
173         if (my $findborrower=$query->param('findborrower')) {
174             my ($borrowers, $flags) = findborrower(\%env, $findborrower);
175             print "<form method=get>\n";
176             print "<input type=hidden name=module value=issues>\n";
177             my @borrowers=@$borrowers;
178             if ($#borrowers == 0) {
179                 $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
180                 issues();
181                 return;
182             } else {
183                 print "<table border=1 cellpadding=5 bgcolor=#dddddd>";
184                 print "<tr><th bgcolor=black><font color=white><b>Select a borrower</b></font></th></tr>\n";
185                 print "<tr><td align=center>\n";
186                 print "<select name=borrnumber size=7>\n";
187                 foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowers) {
188                     print "<option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})\n";
189                 }
190                 print "</select><br>";
191                 print "<input type=submit>\n";
192                 print "</td></tr></table>\n";
193             }
194         } else {
195             print << "EOF";
196             <h1>Issues Module</h1>
197 <form method=get>
198 <input type=hidden name=module value=issues>
199 <table border=1 bgcolor=#dddddd>
200 <tr><th bgcolor=black><font color=white><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
201 <tr><td><input name=findborrower></td></tr>
202 </table>
203 </form>
204 EOF
205         }
206     }
207 }