bug-2149, added new block to C4::Letters::SendAlerts() to email 'account creation...
[koha_fer] / members / moremember.pl
index 8128d50..723bb74 100755 (executable)
@@ -37,6 +37,7 @@ use C4::Context;
 use C4::Auth;
 use C4::Output;
 use C4::Members;
+use C4::Members::Attributes;
 use C4::Dates;
 use C4::Reserves;
 use C4::Circulation;
@@ -61,9 +62,12 @@ my $input = new CGI;
 $debug or $debug = $input->param('debug') || 0;
 my $print = $input->param('print');
 my @failedrenews = $input->param('failedrenew');
+my @failedreturns = $input->param('failedreturn');
 my $error = $input->param('error');
 my @renew_failed;
-for (@failedrenews) { $renew_failed[$_] = 1; }
+for my $renew (@failedrenews) { $renew_failed[$renew] = 1; }
+my @return_failed;
+for my $failedret (@failedreturns) { $return_failed[$failedret] = 1; }
 
 my $template_name;
 
@@ -98,8 +102,7 @@ if ( $reregistration eq 'y' ) {
        $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
 }
 
-my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
-my $category_type = $borrowercategory->{'category_type'};
+my $category_type = $data->{'category_type'};
 
 ### $category_type
 
@@ -139,6 +142,7 @@ if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
 
 #     $cnt  =  1;
     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
+       
     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
 }
 
@@ -176,6 +180,9 @@ else {
                          $template->param("guarantor$_" => $guarantor->{$_});
         }
     }
+       if ($category_type eq 'C'){
+               $template->param('C' => 1);
+       }
 }
 
 #Independant branches management
@@ -210,19 +217,20 @@ my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
 #
 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
-my $today       = POSIX::strftime("%Y%m%d", localtime);        # iso format
+my $today       = POSIX::strftime("%Y-%m-%d", localtime);      # iso format
 my @issuedata;
 my $totalprice = 0;
 my $toggle     = 0;
 for ( my $i = 0 ; $i < $count ; $i++ ) {
     my $datedue = $issue->[$i]{'date_due'};
     $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
+    $issue->[$i]{'issuedate'} = C4::Dates->new($issue->[$i]{'issuedate'},'iso')->output('syspref');
     my %row = %{ $issue->[$i] };
     $totalprice += $issue->[$i]{'replacementprice'};
     $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
-    if ( $datedue < $today ) {
+    if ( $datedue lt $today ) {
         $row{'red'} = 1;    #print "<font color=red>";
-    }
+       }
     $row{toggle} = $toggle++ % 2;
 
     #find the charge for an item
@@ -235,10 +243,11 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
 
     $row{'charge'} = sprintf( "%.2f", $charge );
 
-    #check item is not reserved
-    my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
-    $row{'norenew'} = ($restype) ? 1 : 0;
+       my ( $renewokay,$renewerror ) = CanBookBeRenewed( $borrowernumber, $issue->[$i]{'itemnumber'});
+       $row{'norenew'} = !$renewokay;
+       $row{"norenew_reason_$renewerror"} = 1 if $renewerror;
        $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];               
+       $row{'return_failed'} = $return_failed[$issue->[$i]{'barcode'}];   
     push( @issuedata, \%row );
 }
 
@@ -299,7 +308,6 @@ if ($borrowernumber) {
             $getreserv{nottransfered}   = 0;
             $getreserv{itemtype}        = $getbibtype->{'description'};
             $getreserv{author}          = $getbibinfo->{'author'};
-            $getreserv{itemcallnumber}  = '----------';
             $getreserv{biblionumber}  = $num_res->{'biblionumber'};    
         }
 
@@ -316,20 +324,28 @@ foreach (@$alerts) {
     $_->{ $_->{type} } = 1;
     $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
 }
-my $picture;
-my $htdocs = C4::Context->config('intrahtdocs');
-$picture = "/borrowerimages/" . $borrowernumber . ".jpg";
-if ( -e $htdocs . "$picture" ) {
-    $template->param( picture => $picture );
-}
+
+# check to see if patron's image exists in the database
+# basically this gives us a template var to condition the display of
+# patronimage related interface on
+my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
+$template->param( picture => 1 ) if $picture;
+
 my $branch=C4::Context->userenv->{'branch'};
 
 $template->param($data);
 
+if (C4::Context->preference('ExtendedPatronAttributes')) {
+    $template->param(ExtendedPatronAttributes => 1);
+    $template->param(patron_attributes => C4::Members::Attributes::GetBorrowerAttributes($borrowernumber));
+}
+
 $template->param(
        detailview => 1,
+  DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(), 
     roaddetails      => $roaddetails,
     borrowernumber   => $borrowernumber,
+    categoryname       => $data->{'description'},
     reregistration   => $reregistration,
     branch          => $branch,        
     totalprice       => sprintf( "%.2f", $totalprice ),
@@ -341,6 +357,7 @@ $template->param(
     StaffMember                => ($category_type eq 'S'),
        is_child        => ($category_type eq 'C'),
        #                reserveloop     => \@reservedata,
+       dateformat    => C4::Context->preference("dateformat"),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;