If a patron with a child patron category is not linked
to a guarantor (or a valid one), it was not possible to edit
the child patron's record.  When attempt, no changes were saved
and the following error is recorded in the Apache error log:

memberentry.pl: DBD::mysql::st execute failed: Cannot add or
update a child row: a foreign key constraint
fails (`gmc_koha/borrowers`, CONSTRAINT `borrowers_ibfk_2`
FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)) ...

This patch fixes this bug, allowing a child patron record to be
edited even if it has no guarantor.
---
 members/memberentry.pl |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/members/memberentry.pl b/members/memberentry.pl
index bf20434..e142e74 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -186,21 +186,27 @@ if (($op eq 'insert') and !$nodouble){
 }
 
   #recover all data from guarantor address phone ,fax... 
-if (defined($guarantorid) and ($category_type eq 'C' || $category_type eq 'P') 
and $guarantorid ne '' ){
-  my $guarantordata=GetMember($guarantorid);
-  $guarantorinfo=$guarantordata->{'surname'}." , 
".$guarantordata->{'firstname'};
-  if (!defined($data{'contactname'}) or $data{'contactname'} eq '' or 
$data{'contactname'} ne $guarantordata->{'surname'}) {
-    $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
-    $newdata{'contactname'}     = $guarantordata->{'surname'};
-    $newdata{'contacttitle'}    = $guarantordata->{'title'};
-         foreach (qw(streetnumber address streettype address2 zipcode city 
phone phonepro mobile fax email emailpro branchcode)) {
-               $newdata{$_} = $guarantordata->{$_};
-       }
-  }
+if ( defined($guarantorid) and
+     ( $category_type eq 'C' || $category_type eq 'P' ) and
+     $guarantorid ne ''  and
+     $guarantorid ne '0' ) {
+    if (my $guarantordata=GetMember($guarantorid)) {
+        $guarantorinfo=$guarantordata->{'surname'}." , 
".$guarantordata->{'firstname'};
+        if ( !defined($data{'contactname'}) or $data{'contactname'} eq '' or
+             $data{'contactname'} ne $guarantordata->{'surname'} ) {
+            $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
+            $newdata{'contactname'}     = $guarantordata->{'surname'};
+            $newdata{'contacttitle'}    = $guarantordata->{'title'};
+               foreach (qw(streetnumber address streettype address2
+                        zipcode city phone phonepro mobile fax email emailpro 
branchcode)) {
+                       $newdata{$_} = $guarantordata->{$_};
+               }
+        }
+    }
 }
 
 ###############test to take the right zipcode and city name ##############
-if (!defined($guarantorid) or $guarantorid eq '') {
+if (!defined($guarantorid) or $guarantorid eq '' or $guarantorid eq '0') {
     # set only if parameter was passed from the form
     $newdata{'city'}    = $input->param('city')    if 
defined($input->param('city'));
     $newdata{'zipcode'} = $input->param('zipcode') if 
defined($input->param('zipcode'));
-- 
1.5.6.5

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to