Added the possiblity of deleting waiting reservesm or setting them back to not waiting.
[koha.git] / groups.pl
1 #!/usr/bin/perl
2
3 #written 14/1/2000
4 #script to display reports
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use CGI qw/:standard/;
25 use C4::Output;
26 use C4::Groups;
27 use C4::Circulation::Circ2;
28 use C4::Print;
29 use DBI;
30
31 my $input=new CGI;
32 my $time=$input->param('time');
33 #print $input->header;
34
35
36 my $branches=getbranches(\%env);
37 my $printers=getprinters(\%env);
38 my $branch=$input->param('branch');
39 my $printer=$input->param('printer');
40 ($branch) || ($branch=$input->cookie('branch'));
41 ($printer) || ($printer=$input->cookie('printer'));
42 my ($oldbranch, $oldprinter);
43 if ($input->param('selectnewbranchprinter')) {
44     $oldbranch=$branch;
45     $oldprinter=$printer;
46     $branch='';
47     $printer='';
48 }
49 $env{'branchcode'}=$branch;
50 $env{'printer'}=$printer;
51 #$env{'queue'}=$printer;
52 my $branchcount=0;
53 my $printercount=0;
54 my $branchoptions;
55 my $printeroptions;
56 foreach (keys %$branches) {
57     (next) unless ($_);
58     (next) if (/^TR$/);
59     $branchcount++;
60     my $selected='';
61     ($selected='selected') if ($_ eq $oldbranch);
62     ($selected='selected') if ($_ eq $branch);
63     $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
64 }
65 foreach (keys %$printers) {
66     (next) unless ($_);
67     $printercount++;
68     my $selected='';
69     ($selected='selected') if ($_ eq $oldprinter || $_ eq $printer);
70     $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
71 }
72 if ($printercount==1) {
73     ($printer)=keys %$printers;
74 }
75 if ($branchcount==1) {
76     ($branch)=keys %$branches;
77 }
78
79
80 my $branchname='';
81 my $printername='';
82 if ($branch && $printer) {
83     $branchname=$branches->{$branch}->{'branchname'};
84     $printername=$printers->{$printer}->{'printername'};
85 }
86
87
88 my $branchcookie=$input->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y', -path=>'/cgi-bin/koha/');
89 my $printercookie=$input->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y', -path=>'/cgi-bin/koha/');
90
91 print $input->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
92 print startpage;
93 unless ($input->param('printable')) {
94     print startmenu('report');
95 }
96 print center;
97
98
99
100 my $type=$input->param('type');
101 my $groups=getgroups();
102 if ($input->param('print')) {
103     if ($input->param('groupsselected')) {
104         foreach ($input->param()) {
105             if (/print_(.*)/) {
106                 my $group=$1;
107                 printgroup($group,$input->param('type'));
108             }
109         }
110     } else {
111         print "<h2>Select the groups to print</h2>\n";
112         print "<form method=post>\n";
113         print "<input type=hidden name=print value=1>\n";
114         print "<input type=hidden name=groupsselected value=1>\n";
115         print "<table border=0><tr><td bgcolor=#dddddd>\n";
116         print "<table border=1 cellspacing=5 cellpadding=10><tr>\n";
117         my $counter=0;
118         foreach (sort {$groups->{$a} cmp $groups->{$b}} keys %$groups) {
119             (next) unless ($groups->{$_});
120             if ($counter>3) {
121                 $counter=0;
122                 print "</tr><tr>\n";
123             } else {
124             }
125             print << "EOF";
126 <td><input type=checkbox name=print_$_ value=0> $groups->{$_}
127 </td>
128 EOF
129             $counter++;
130         }
131         print << "EOF";
132 </tr></table>
133 </td></tr></table>
134 <p>
135 Printer: 
136 <select name=printer>
137 $printeroptions
138 </select>
139 <p>
140 <input type=radio name=type value=issues> Issues <input type=radio name=type value=overdues checked> Overdues
141 <p>
142 <input type=submit value=Print>
143 </body></html>
144 EOF
145         exit;
146     }
147 }
148 if (my $group=$input->param('group')) {
149     print "<a href=groups.pl?type=$type>Back to group list</a><p>\n";
150     if ($input->param('printable')) {
151         print "<head><title>Overdue list for $groups->{$group}</title></head><body>\n";
152     }
153     my $members=groupmembers($env, $group);
154     print "<table border=0><tr><td bgcolor=#dddddd>\n";
155     print "<table border=1 cellspacing=5 cellpadding=10>\n";
156     my $typetext='';
157     ($type eq 'overdues') ? ($typetext="Overdues") : ($typetext="Issues");
158     print "<thead><tr><th>Card #</th><th>Name</th><th>IS/OD</th><th>$typetext</th></tr></thead>\n";
159     foreach (sort { $a->{'surname'}." ".$a->{'firstname'} cmp $b->{'surname'}." ".$b->{'firstname'} }  @$members) {
160         my $fullname=$_->{'firstname'}." ".$_->{'surname'};
161         my $userid=$_->{'userid'};
162         my $cardnumber=$_->{'cardnumber'};
163         my $currentissues=$_->{'currentissues'};
164         my $counter=0;
165         my $overduecounter=0;
166         my $overduelist='';
167         foreach (keys %$currentissues) {
168             $counter++;
169             if ($currentissues->{$_}->{'overdue'}) {
170                 $overduecounter++;
171                 $title=$currentissues->{$_}->{'title'};
172                 $author=$currentissues->{$_}->{'author'};
173                 $date_due=$currentissues->{$_}->{'date_due'};
174                 $overduelist.="<u>$title</u> by $author (<font color=red>$date_due</font>)<br>\n";
175             } else {
176                 if ($type eq 'issues') {
177                     $title=$currentissues->{$_}->{'title'};
178                     $author=$currentissues->{$_}->{'author'};
179                     $date_due=$currentissues->{$_}->{'date_due'};
180                     $overduelist.="<u>$title</u> by $author due on $date_due<br>\n";
181                 }
182             }
183         }
184         my $overduetext="0";
185         if ($overduecounter) {
186             $overduetext="<font color=red>$overduecounter</font>";
187         }
188         (next) unless ($overduecounter || $counter);
189         if ($overduecounter==0 && $type eq 'overdues') {
190             next;
191         }
192         print "<tr><td align=center>$cardnumber</td><td>$fullname</td><td align=center>$counter/$overduetext</td><td>$overduelist</td></tr>\n";
193     }
194     print "</table>\n";
195     print "</td></tr></table>\n";
196 } else {
197     print "<a href=groups.pl?print=1>Print Reports</a><p>\n";
198     print "<h2>Pick a group</h2>\n";
199     print "<table border=0><tr><td bgcolor=#dddddd>\n";
200     print "<table border=1 cellspacing=5 cellpadding=10><tr>\n";
201     my $counter=0;
202     foreach (sort {$groups->{$a} cmp $groups->{$b}} keys %$groups) {
203         (next) unless ($groups->{$_});
204         if ($counter>3) {
205             $counter=0;
206             print "</tr><tr>\n";
207         } else {
208         }
209         print << "EOF";
210 <td align=center>$groups->{$_}
211 <br>
212 <a href=groups.pl?type=issues&group=$_>Issues</a> | <a href=groups.pl?type=overdues&group=$_>Overdues</a>
213 </td>
214 EOF
215         $counter++;
216     }
217     print "</tr></table>\n";
218     print "</td></tr></table>\n";
219 }
220
221
222 unless ($input->param('printable')) {
223     print endmenu('report');
224 }
225 print endpage;
226
227
228
229 sub printgroup {
230     my $group=shift;
231     my $type=shift;
232     $output= "<head><title>Overdue list for $groups->{$group}</title></head><body><center>\n";
233     my $members=groupmembers($env, $group);
234     ($type eq 'overdues') && ($output.="<img src=/usr/local/koha/librarian/htdocs/images/overdues.jpg><br>\n");
235     $output.= "<table border=1 cellspacing=5 cellpadding=10>\n";
236     my $typetext='';
237     ($type eq 'overdues') ? ($typetext="Overdues") : ($typetext="Issues");
238     $output.= "<thead><tr><th>Card #</th><th>Name</th><th>IS/OD</th><th>$typetext</th></tr></thead>\n";
239     foreach (sort { $a->{'surname'}." ".$a->{'firstname'} cmp $b->{'surname'}." ".$b->{'firstname'} }  @$members) {
240         my $fullname=$_->{'firstname'}." ".$_->{'surname'};
241         my $userid=$_->{'userid'};
242         my $cardnumber=$_->{'cardnumber'};
243         my $currentissues=$_->{'currentissues'};
244         my $counter=0;
245         my $overduecounter=0;
246         my $overduelist='';
247         foreach (keys %$currentissues) {
248             $counter++;
249             if ($currentissues->{$_}->{'overdue'}) {
250                 $overduecounter++;
251                 $title=$currentissues->{$_}->{'title'};
252                 $author=$currentissues->{$_}->{'author'};
253                 $date_due=$currentissues->{$_}->{'date_due'};
254                 $overduelist.="<u>$title</u> by $author (<font color=red>$date_due</font>)<br>\n";
255             } else {
256                 if ($type eq 'issues') {
257                     $title=$currentissues->{$_}->{'title'};
258                     $author=$currentissues->{$_}->{'author'};
259                     $date_due=$currentissues->{$_}->{'date_due'};
260                     $overduelist.="<u>$title</u> by $author due on $date_due<br>\n";
261                 }
262             }
263         }
264         my $overduetext="0";
265         if ($overduecounter) {
266             $overduetext="<font color=red>$overduecounter</font>";
267         }
268         (next) unless ($overduecounter || $counter);
269         if ($overduecounter==0 && $type eq 'overdues') {
270             next;
271         }
272         $output.= "<tr><td align=center>$cardnumber</td><td>$fullname</td><td align=center>$counter/$overduetext</td><td>$overduelist</td></tr>\n";
273     }
274     $output.= "</table>\n";
275     $output.= "</td></tr></table>\n";
276     open (P, "|html2ps | lpr -P$printer");
277     print P $output;
278     close P;
279 }