MT 1816: Granular permissions for the serials module
[koha.git] / members / memberentry.pl
index 57b520d..3b62849 100755 (executable)
@@ -19,7 +19,7 @@
 
 # pragma
 use strict;
-use warnings;  # FIXME: really.
+use warnings;
 
 # external modules
 use CGI;
@@ -69,7 +69,7 @@ my $destination    = $input->param('destination');
 my $cardnumber     = $input->param('cardnumber');
 my $check_member   = $input->param('check_member');
 my $name_city      = $input->param('name_city');
-my $nodouble       = $input->param('nodouble');
+my $nodouble       = $input->param('nodouble')||$op eq 'modify';
 my $select_city    = $input->param('select_city');
 my $nok            = $input->param('nok');
 my $guarantorinfo  = $input->param('guarantorinfo');
@@ -115,8 +115,10 @@ my %newdata;       # comes from $input->param()
 if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') {
     my @names= ($borrower_data && $op ne 'save') ? keys %$borrower_data : $input->param();
     foreach my $key (@names) {
-        $newdata{$key} = $input->param($key) if (defined $input->param($key));
-        $newdata{$key} =~ s/\"/"/gg unless $key eq 'borrowernotes' or $key eq 'opacnote';
+        if (defined $input->param($key)) {
+            $newdata{$key} = $input->param($key);
+            $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
+        }
     }
     my $dateobject = C4::Dates->new();
     my $syspref = $dateobject->regexp();               # same syspref format for all 3 dates
@@ -134,7 +136,7 @@ if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') {
         }
     }
   # check permission to modify login info.
-    if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($dbh,$userenv->{'id'},{'staffaccess'=>1})) )  {
+    if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) )  {
         $NoUpdateLogin = 1;
     }
 }
@@ -161,21 +163,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'}) {
-    $data{'contactfirstname'}= $guarantordata->{'firstname'};
-    $data{'contactname'}     = $guarantordata->{'surname'};
-    $data{'contacttitle'}    = $guarantordata->{'title'};
-         foreach (qw(streetnumber address streettype address2 zipcode city phone phonepro mobile fax email emailpro branchcode)) {
-               $data{$_} = $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'));
@@ -376,7 +384,7 @@ foreach (qw(C A S P I X)) {
 $template->param('typeloop' => \@typeloop);
 
 # test in city
-$select_city=getidcity($data{'city'}) if ($guarantorid ne '0');
+$select_city=getidcity($data{'city'}) if defined $guarantorid and ($guarantorid ne '0');
 ($default_city=$select_city) if ($step eq 0);
 if (!defined($select_city) or $select_city eq '' ){
        $default_city = &getidcity($data{'city'});