correct path to 404.pl in opac-details.pl
[koha.git] / opac / opac-user.pl
blobf9aeb0c008a9386a814e2ea20ff46587e354170b
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
19 use strict;
20 require Exporter;
21 use CGI;
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Circulation;
26 use C4::Reserves;
27 use C4::Members;
28 use C4::Output;
29 use C4::Biblio;
30 use C4::Items;
31 use C4::Dates qw/format_date/;
32 use C4::Letters;
33 use C4::Branch; # GetBranches
35 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "opac-user.tmpl",
39 query => $query,
40 type => "opac",
41 authnotrequired => 0,
42 flagsrequired => { borrow => 1 },
43 debug => 1,
47 my $patronupdate = $query->param('patronupdate');
49 # get borrower information ....
50 my ( $borr, $flags ) = GetMemberDetails( $borrowernumber );
52 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
53 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
54 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
55 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
57 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
58 $borr->{'flagged'} = 1;
60 # $make flagged available everywhere in the template
61 my $patron_flagged = $borr->{'flagged'};
62 if ( $borr->{'amountoutstanding'} > 5 ) {
63 $borr->{'amountoverfive'} = 1;
65 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
66 $borr->{'amountoverzero'} = 1;
68 if ( $borr->{'amountoutstanding'} < 0 ) {
69 $borr->{'amountlessthanzero'} = 1;
70 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
73 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
75 my @bordat;
76 $bordat[0] = $borr;
78 $template->param( BORROWER_INFO => \@bordat,
79 borrowernumber => $borrowernumber,
80 patron_flagged => $patron_flagged,
83 #get issued items ....
84 my ($countissues,$issues) = GetPendingIssues($borrowernumber);
86 my $count = 0;
87 my $toggle = 0;
88 my $overdues_count = 0;
89 my @overdues;
90 my @issuedat;
91 my $imgdir = getitemtypeimagesrc();
92 my $itemtypes = GetItemTypes();
93 foreach my $issue ( @$issues ) {
94 if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
95 # check for reserves
96 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
97 if ( $restype ) {
98 $issue->{'reserved'} = 1;
101 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
102 my $charges = 0;
103 foreach my $ac (@$accts) {
104 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
105 $charges += $ac->{'amountoutstanding'}
106 if $ac->{'accounttype'} eq 'F';
107 $charges += $ac->{'amountoutstanding'}
108 if $ac->{'accounttype'} eq 'L';
111 $issue->{'charges'} = $charges;
113 # get publictype for icon
115 my $publictype = $issue->{'publictype'};
116 $issue->{$publictype} = 1;
118 # check if item is renewable
119 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
120 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
122 $issue->{'status'} = $status;
124 if ( $issue->{'overdue'} ) {
125 push @overdues, $issue;
126 $overdues_count++;
127 $issue->{'overdue'} = 1;
129 else {
130 $issue->{'issued'} = 1;
132 # imageurl:
133 my $itemtype = $issue->{'itemtype'};
134 if ( $itemtype ) {
135 $issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
136 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
138 $issue->{date_due} = format_date($issue->{date_due});
139 push @issuedat, $issue;
140 $count++;
143 $template->param( ISSUES => \@issuedat );
144 $template->param( issues_count => $count );
146 $template->param( OVERDUES => \@overdues );
147 $template->param( overdues_count => $overdues_count );
149 # load the branches
150 my $branches = GetBranches();
151 my @branch_loop;
152 for my $branch_hash (sort keys %$branches ) {
153 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
154 push @branch_loop,
156 value => "branch: $branch_hash",
157 branchname => $branches->{$branch_hash}->{'branchname'},
158 selected => $selected
161 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
163 # now the reserved items....
164 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
165 foreach my $res (@reserves) {
166 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
167 my $publictype = $res->{'publictype'};
168 $res->{$publictype} = 1;
169 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
170 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
171 my $biblioData = GetBiblioData($res->{'biblionumber'});
172 $res->{'reserves_title'} = $biblioData->{'title'};
175 # use Data::Dumper;
176 # warn Dumper(@reserves);
178 $template->param( RESERVES => \@reserves );
179 $template->param( reserves_count => $#reserves+1 );
181 my @waiting;
182 my $wcount = 0;
183 foreach my $res (@reserves) {
184 if ( $res->{'itemnumber'} ) {
185 my $item = GetItem( $res->{'itemnumber'});
186 $res->{'holdingbranch'} =
187 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
188 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
189 # get document reserve status
190 my $biblioData = GetBiblioData($res->{'biblionumber'});
191 $res->{'waiting_title'} = $biblioData->{'title'};
192 if ( ( $res->{'found'} eq 'W' ) ) {
193 my $item = $res->{'itemnumber'};
194 $item = GetBiblioFromItemNumber($item,undef);
195 $res->{'wait'}= 1;
196 $res->{'holdingbranch'}=$item->{'holdingbranch'};
197 $res->{'biblionumber'}=$item->{'biblionumber'};
198 $res->{'barcodenumber'} = $item->{'barcode'};
199 $res->{'wbrcode'} = $res->{'branchcode'};
200 $res->{'itemnumber'} = $res->{'itemnumber'};
201 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
202 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
203 $res->{'atdestination'} = 1;
205 # set found to 1 if reserve is waiting for patron pickup
206 $res->{'found'} = 1 if $res->{'found'} eq 'W';
208 push @waiting, $res;
209 $wcount++;
213 $template->param( WAITING => \@waiting );
215 # current alert subscriptions
216 my $alerts = getalert($borrowernumber);
217 foreach ( @$alerts ) {
218 $_->{ $_->{type} } = 1;
219 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
222 $template->param(
223 waiting_count => $wcount,
224 textmessaging => $borr->{textmessaging},
225 patronupdate => $patronupdate,
226 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
227 userview => 1,
228 dateformat => C4::Context->preference("dateformat"),
231 output_html_with_http_headers $query, $cookie, $template->output;