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