Bug fixing stack underflow on results.tmpl
[koha.git] / members / moremember.pl
index 03d3323..286a811 100755 (executable)
@@ -202,7 +202,9 @@ if ( C4::Context->preference("IndependantBranches") ) {
     unless ( $userenv->{flags} == 1 ) {
         $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
     }
-    $samebranch = 1 if ( $userenv->{flags} == 1 );
+    $samebranch = 1 if ( $userenv->{flags} % 2 == 1 );
+}else{
+    $samebranch = 1;
 }
 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
 $data->{'branchname'} = $branchdetail->{branchname};
@@ -216,7 +218,8 @@ my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
 
 # current issues
 #
-my ( $count, $issue ) = GetPendingIssues($borrowernumber);
+my $issue = GetPendingIssues($borrowernumber);
+my $count = scalar(@$issue);
 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
 my $today       = POSIX::strftime("%Y-%m-%d", localtime);      # iso format
 my @issuedata;
@@ -227,15 +230,38 @@ 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 $biblionumber = $issue->[$i]{'biblionumber'};
     my %row = %{ $issue->[$i] };
     $totalprice += $issue->[$i]{'replacementprice'};
     $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
+    # item lost, damaged loops
+    if ($row{'itemlost'}) {
+        my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'});
+        my $category = GetAuthValCode('items.itemlost',$fw);
+        my $lostdbh = C4::Context->dbh;
+        my $sth = $lostdbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
+        $sth->execute($category, $row{'itemlost'});
+        my $loststat = $sth->fetchrow;
+        if ($loststat) {
+           $row{'itemlost'} = $loststat;
+        }
+    }
+    if ($row{'damaged'}) {
+        my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'});
+        my $category = GetAuthValCode('items.damaged',$fw);
+        my $damageddbh = C4::Context->dbh;
+        my $sth = $damageddbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
+        $sth->execute($category, $row{'damaged'});
+        my $damagedstat = $sth->fetchrow;
+        if ($damagedstat) {
+           $row{'itemdamaged'} = $damagedstat;
+        }
+    }
+    # end lost, damaged
     if ( $datedue lt $today ) {
         $overdues_exist = 1;
         $row{'red'} = 1;    #print "<font color=red>";
        }
-    $row{toggle} = $toggle++ % 2;
-
     #find the charge for an item
     my ( $charge, $itemtype ) =
       GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
@@ -350,9 +376,9 @@ if (C4::Context->preference('ExtendedPatronAttributes')) {
 }
 
 $template->param(
-       detailview => 1,
+    detailview => 1,
     AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
-  DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(), 
+    DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(),
     roaddetails      => $roaddetails,
     borrowernumber   => $borrowernumber,
     categoryname       => $data->{'description'},