Adding 'Mark and Continue' buttons to inventory interface. Buttons are added via...
[koha.git] / members / moremember.pl
index 361692e..4ca67a8 100755 (executable)
@@ -47,6 +47,7 @@ use C4::Reserves;
 use C4::Branch; # GetBranchName
 
 #use Smart::Comments;
+#use Data::Dumper;
 
 use vars qw($debug);
 
@@ -57,11 +58,15 @@ BEGIN {
 my $dbh = C4::Context->dbh;
 
 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;
 
@@ -87,6 +92,7 @@ my $reregistration = $input->param('reregistration');
 
 if ( not defined $data ) {
     $template->param (unknowuser => 1);
+       output_html_with_http_headers $input, $cookie, $template->output;
     exit;
 }
 
@@ -103,6 +109,7 @@ my $category_type = $borrowercategory->{'category_type'};
 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children) 
 $template->param( $data->{'categorycode'} => 1 ); 
 
+$debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
                my $userdate = $data->{$_};
                unless ($userdate) {
@@ -110,9 +117,9 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) {
                        $data->{$_} = '';
                        next;
                }
-               my $tempdate = C4::Dates->new($userdate,'iso')->output('syspref')
-                       or warn ("Invalid $_ = '$userdate'");
-               $data->{$_} = $tempdate || '';
+               $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
+               $data->{$_} = $userdate || '';
+               $template->param( $_ => $userdate );
 }
 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
 
@@ -121,22 +128,25 @@ for (qw(debarred gonenoaddress lost borrowernotes)) {
 }
 
 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
-
 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
 
+my $catcode;
 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
-
     my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
-    foreach (qw(address city B_address B_city phone mobilezipcode)) {
+    foreach (qw(address city B_address B_city phone mobile zipcode)) {
         $data->{$_} = $data2->{$_};
     }
     my  ( $catcodes, $labels ) = 
         GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
     my $cnt = scalar(@$catcodes);
-    $template->param( 'CATCODE_MULTI' => 1)    if  $cnt > 1;
-    $template->param( 'IS_CHILD' => 1 );
+
+#     $cnt  =  1;
+    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
+       
+    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
 }
 
+
 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
     $template->param( printethnicityline => 1 );
 }
@@ -170,6 +180,9 @@ else {
                          $template->param("guarantor$_" => $guarantor->{$_});
         }
     }
+       if ($category_type eq 'C'){
+               $template->param('C' => 1);
+       }
 }
 
 #Independant branches management
@@ -211,6 +224,7 @@ 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'};
@@ -229,14 +243,15 @@ 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;
        $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];               
+       $row{'return_failed'} = $return_failed[$issue->[$i]{'barcode'}];   
     push( @issuedata, \%row );
 }
 
-##################################################################################
+### ###############################################################################
 # BUILD HTML
 # show all reserves of this borrower, and the position of the reservation ....
 if ($borrowernumber) {
@@ -310,18 +325,19 @@ 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 );
-}
+
+# grab patron's image if available
+my $picture = GetPatronImage($data->{'cardnumber'});
+$template->param( picture => $picture );
+
+
 my $branch=C4::Context->userenv->{'branch'};
 
 $template->param($data);
 
 $template->param(
        detailview => 1,
+  DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(), 
     roaddetails      => $roaddetails,
     borrowernumber   => $borrowernumber,
     reregistration   => $reregistration,
@@ -333,6 +349,7 @@ $template->param(
        error            => $error,
        $error                  => 1,
     StaffMember                => ($category_type eq 'S'),
+       is_child        => ($category_type eq 'C'),
        #                reserveloop     => \@reservedata,
 );