Adding superlibrarian rights when IndependantBranches is set.
[koha.git] / members / moremember.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # script to do a borrower enquiry/bring up borrower details etc
6 # Displays all the details about a borrower
7 # written 20/12/99 by chris@katipo.co.nz
8 # last modified 21/1/2000 by chris@katipo.co.nz
9 # modified 31/1/2001 by chris@katipo.co.nz
10 #   to not allow items on request to be renewed
11 #
12 # needs html removed and to use the C4::Output more, but its tricky
13 #
14
15
16 # Copyright 2000-2002 Katipo Communications
17 #
18 # This file is part of Koha.
19 #
20 # Koha is free software; you can redistribute it and/or modify it under the
21 # terms of the GNU General Public License as published by the Free Software
22 # Foundation; either version 2 of the License, or (at your option) any later
23 # version.
24 #
25 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
26 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
27 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License along with
30 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
31 # Suite 330, Boston, MA  02111-1307 USA
32
33 use strict;
34 use C4::Auth;
35 use C4::Context;
36 use C4::Output;
37 use C4::Interface::CGI::Output;
38 use C4::Interface::CGI::Template;
39 use CGI;
40 use C4::Search;
41 use Date::Manip;
42 use C4::Date;
43 use C4::Reserves2;
44 use C4::Circulation::Circ2;
45 use C4::Koha;
46 use HTML::Template;
47
48 my $dbh = C4::Context->dbh;
49
50 my $input = new CGI;
51 my $print = $input->param('print');
52 my $template_name;
53
54 if($print eq "page"){
55         $template_name = "members/moremember-print.tmpl";
56 } elsif($print eq "slip"){
57         $template_name = "members/moremember-receipt.tmpl";
58 } else {
59         $template_name = "members/moremember.tmpl";
60 }
61
62 my ($template, $loggedinuser, $cookie)
63     = get_template_and_user({template_name => $template_name,
64                              query => $input,
65                              type => "intranet",
66                              authnotrequired => 0,
67                              flagsrequired => {borrowers => 1},
68                              debug => 1,
69                              });
70
71 my $bornum=$input->param('bornum');
72
73 #start the page and read in includes
74
75 my $data=borrdata('',$bornum);
76
77 $template->param($data->{'categorycode'} => 1); # in template <TMPL_IF name="I"> => instutitional (A for Adult & C for children)
78
79 $data->{'dateenrolled'} = format_date($data->{'dateenrolled'});
80 $data->{'expiry'} = format_date($data->{'expiry'});
81 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
82 $data->{'IS_ADULT'} = ($data->{'categorycode'} ne 'I');
83
84 if($data->{'debarred'} || $data->{'gonenoaddress'} || $data->{'lost'} || $data->{'borrowernotes'}){
85         $template->param(flagged =>1);
86 }
87
88 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
89
90 $data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
91
92 if ($data->{'categorycode'} eq 'C'){
93         my $data2=borrdata('',$data->{'guarantor'});
94         $data->{'streetaddress'}=$data2->{'streetaddress'};
95         $data->{'city'}=$data2->{'city'};
96         $data->{'physstreet'}=$data2->{'physstreet'};
97         $data->{'streetcity'}=$data2->{'streetcity'};
98         $data->{'phone'}=$data2->{'phone'};
99         $data->{'phoneday'}=$data2->{'phoneday'};
100         $data->{'zipcode'} = $data2->{'zipcode'};
101 }
102
103
104 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
105         $template->param(printethnicityline => 1);
106 }
107
108 if ($data->{'categorycode'} ne 'C'){
109         $template->param(isguarantee => 1);
110         # FIXME
111         # It looks like the $i is only being returned to handle walking through
112         # the array, which is probably better done as a foreach loop.
113         #
114         my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
115         my @guaranteedata;
116         for (my $i=0;$i<$count;$i++){
117                 push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
118                                         cardnumber => $guarantees->[$i]->{'cardnumber'},
119                                         name => $guarantees->[$i]->{'firstname'} . " " . $guarantees->[$i]->{'surname'}});
120         }
121         $template->param(guaranteeloop => \@guaranteedata);
122
123 } else {
124         my ($guarantor)=findguarantor($data->{'borrowernumber'});
125         unless ($guarantor->{'borrowernumber'} == 0){
126                 $template->param(guarantorborrowernumber => $guarantor->{'borrowernumber'}, guarantorcardnumber => $guarantor->{'cardnumber'});
127         }
128 }
129
130 my %bor;
131 $bor{'borrowernumber'}=$bornum;
132
133 # Converts the branchcode to the branch name
134 my $samebranch;
135 if (C4::Context->preference("IndependantBranches")) {
136         my $userenv = C4::Context->userenv;
137         unless ($userenv->{flags} == 1){
138                 $samebranch = ($data->{'branchcode'} eq $userenv->{branch});
139         }
140         $samebranch =1 if ($userenv->{flags} == 1);
141 }
142
143 $data->{'branchcode'} = &getbranchname($data->{'branchcode'});
144
145 # Converts the categorycode to the description
146 $data->{'categorycode'} = &getborrowercategory($data->{'categorycode'});
147
148 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
149
150 my ($count,$issue)=borrissues($bornum);
151 my $today=ParseDate('today');
152 my @issuedata;
153 my $totalprice = 0;
154 for (my $i=0;$i<$count;$i++){
155         my $datedue=ParseDate($issue->[$i]{'date_due'});
156         $issue->[$i]{'date_due'} = format_date($issue->[$i]{'date_due'});
157         my %row = %{$issue->[$i]};
158         $totalprice += $issue->[$i]{'replacementprice'};
159         $row{'replacementprice'}=$issue->[$i]{'replacementprice'};
160         if ($datedue < $today){
161                 $row{'red'}=1; #print "<font color=red>";
162         }
163         #find the charge for an item
164         # FIXME - This is expecting
165         # &C4::Circulation::Renewals2::calc_charges, but it's getting
166         # &C4::Circulation::Circ2::calc_charges, which only returns one
167         # element, so itemtype isn't being set.
168         # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
169         # return the correct item type either (or a properly-formatted
170         # charge, for that matter).
171         my ($charge,$itemtype)=calc_charges($dbh,$issue->[$i]{'itemnumber'},$bornum);
172         $row{'itemtype'}=&ItemType($itemtype);
173         $row{'charge'}=$charge;
174
175         #check item is not reserved
176         my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
177         if ($restype){
178 #               print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
179                 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
180                 #      print "<TD>Previously Renewed - no renewals</td></tr>";
181                         $row{'norenew'}=1;
182         } else {
183                 $row{'norenew'}=0;
184         }
185         push (@issuedata, \%row);
186 }
187
188 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
189
190 my @reservedata;
191 foreach my $reserveline (@$reserves) {
192         $reserveline->{'reservedate2'} = format_date($reserveline->{'reservedate'});
193         my $restitle;
194         my %row = %$reserveline;
195         if ($reserveline->{'constrainttype'} eq 'o'){
196                 $restitle=getreservetitle($reserveline->{'biblionumber'},$reserveline->{'borrowernumber'},$reserveline->{'reservedate'},$reserveline->{'rtimestamp'});
197                 %row =  (%row , %$restitle) if $restitle;
198         }
199         push (@reservedata, \%row);
200 }
201
202 $template->param($data);
203 $template->param(
204                  bornum          => $bornum,
205                  totalprice =>$totalprice,
206                  totaldue =>$total,
207                  issueloop       => \@issuedata,
208                  reserveloop     => \@reservedata
209                  );
210 $template->param(
211                  independantbranches => C4::Context->preference("IndependantBranches"),
212                  samebranch              => $samebranch) if (C4::Context->preference("IndependantBranches"));
213
214 output_html_with_http_headers $input, $cookie, $template->output;