Bug 15344: Remove some other calls of GetMemberDetails from pl scripts
[koha.git] / circ / waitingreserves.pl
index c9c9f0e..67afdcc 100755 (executable)
@@ -5,32 +5,31 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Output;
 use C4::Branch; # GetBranchName
 use C4::Auth;
-use C4::Dates qw/format_date/;
 use C4::Circulation;
 use C4::Members;
 use C4::Biblio;
 use C4::Items;
-
+use Koha::DateUtils;
 use Date::Calc qw(
   Today
   Add_Delta_Days
@@ -47,12 +46,13 @@ my $fbr            = $input->param('fbr') || '';
 my $tbr            = $input->param('tbr') || '';
 my $all_branches   = $input->param('allbranches') || '';
 my $cancelall      = $input->param('cancelall');
+my $tab            = $input->param('tab');
 
 my $cancel;
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => "circ/waitingreserves.tmpl",
+        template_name   => "circ/waitingreserves.tt",
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
@@ -73,10 +73,10 @@ if ($item) {
     push @cancel_result, $res if $res;
 }
 
-if ( C4::Context->preference('IndependantBranches') ) {
+if ( C4::Context->preference('IndependentBranches') ) {
     undef $all_branches;
 } else {
-    $template->param( all_branches_link => $input->url . '?allbranches=1' )
+    $template->param( all_branches_link => '/cgi-bin/koha/circ/waitingreserves.pl' . '?allbranches=1' )
       unless $all_branches;
 }
 $template->param( all_branches => 1 ) if $all_branches;
@@ -96,12 +96,6 @@ foreach my $num (@getreserves) {
     my $holdingbranch = $gettitle->{'holdingbranch'};
     my $homebranch = $gettitle->{'homebranch'};
 
-    if ($cancelall) {
-        my $res = cancel( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
-        push @cancel_result, $res if $res;
-        next;
-    }
-
     my %getreserv = (
         itemnumber => $itemnumber,
         borrowernum => $borrowernum,
@@ -111,7 +105,7 @@ foreach my $num (@getreserves) {
     $gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'};
     my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'});
     my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );  # using the fixed up itype/itemtype
-    $getreserv{'waitingdate'} = format_date( $num->{'waitingdate'} );
+    $getreserv{'waitingdate'} = $num->{'waitingdate'};
     my ( $waiting_year, $waiting_month, $waiting_day ) = split (/-/, $num->{'waitingdate'});
     ( $waiting_year, $waiting_month, $waiting_day ) =
       Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
@@ -120,6 +114,7 @@ foreach my $num (@getreserves) {
 
     $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
     $getreserv{'title'}          = $gettitle->{'title'};
+    $getreserv{'subtitle'}       = GetRecordValue('subtitle', GetMarcBiblio($gettitle->{'biblionumber'}), GetFrameworkCode($gettitle->{'biblionumber'}));
     $getreserv{'biblionumber'}   = $gettitle->{'biblionumber'};
     $getreserv{'barcode'}        = $gettitle->{'barcode'};
     $getreserv{'branchname'}     = GetBranchName($gettitle->{'homebranch'});
@@ -134,13 +129,22 @@ foreach my $num (@getreserves) {
     $getreserv{'borrowername'}      = $getborrower->{'surname'};
     $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
     $getreserv{'borrowerphone'}     = $getborrower->{'phone'};
-    if ( $getborrower->{'emailaddress'} ) {
-        $getreserv{'borrowermail'}  = $getborrower->{'emailaddress'};
+
+    my $borEmail = GetFirstValidEmailAddress( $borrowernum );
+
+    if ( $borEmail ) {
+        $getreserv{'borrowermail'}  = $borEmail;
     }
+
     if ($today > $calcDate) {
-        push @overloop,   \%getreserv;
-        $overcount++;
+        if ($cancelall) {
+            my $res = cancel( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
+            push @cancel_result, $res if $res;
+            next;
+        } else {
+            push @overloop,   \%getreserv;
+            $overcount++;
+        }
     }else{
         push @reservloop, \%getreserv;
         $reservcount++;
@@ -154,12 +158,13 @@ $template->param(
     reservecount => $reservcount,
     overloop    => \@overloop,
     overcount   => $overcount,
-    show_date   => format_date(C4::Dates->today('iso')),
-    dateformat  => C4::Context->preference("dateformat"),
+    show_date   => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
     ReservesMaxPickUpDelay => C4::Context->preference('ReservesMaxPickUpDelay')
 );
 
-if ($cancelall) {
+if ($item && $tab eq 'holdsover') {
+    print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
+} elsif ($cancelall) {
     print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
 } else {
     output_html_with_http_headers $input, $cookie, $template->output;
@@ -183,7 +188,7 @@ sub cancel {
     # if we have a result
     if ($nextreservinfo) {
         my %res;
-        my $borrowerinfo = GetMemberDetails( $nextreservinfo );
+        my $borrowerinfo = C4::Members::GetMember( borrowernumber => $nextreservinfo );
         my $iteminfo = GetBiblioFromItemNumber($item);
         if ( $messages->{'transfert'} ) {
             $res{messagetransfert} = $messages->{'transfert'};