Bug 7143: Update about page for new devs
[srvgit] / members / memberentry.pl
index fd684c5..3fe2e97 100755 (executable)
@@ -55,7 +55,7 @@ BEGIN {
        $debug = $ENV{DEBUG} || 0;
 }
        
-my $input = new CGI;
+my $input = CGI->new;
 ($debug) or $debug = $input->param('debug') || 0;
 my %data;
 
@@ -65,7 +65,6 @@ my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "members/memberentrygen.tt",
            query => $input,
            type => "intranet",
-           authnotrequired => 0,
            flagsrequired => {borrowers => 'edit_borrowers'},
            debug => ($debug) ? 1 : 0,
        });
@@ -101,6 +100,7 @@ my $step          = $input->param('step') || 0;
 my @errors;
 my $borrower_data;
 my $NoUpdateLogin;
+my $NoUpdateEmail;
 my $userenv = C4::Context->userenv;
 my @messages;
 
@@ -170,6 +170,11 @@ if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) {
     my $logged_in_user = Koha::Patrons->find( $loggedinuser );
     output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
 
+    # check permission to modify email info.
+    if ( $patron->is_superlibrarian && !$logged_in_user->is_superlibrarian ) {
+        $NoUpdateEmail = 1;
+    }
+
     $borrower_data = $patron->unblessed;
     $borrower_data->{category_type} = $patron->category->category_type;
 }
@@ -210,7 +215,8 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' )
             push(@errors,"ERROR_$_");
         }
     }
-  # check permission to modify login info.
+
+    # check permission to modify login info.
     if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) )  {
         $NoUpdateLogin = 1;
     }
@@ -367,7 +373,7 @@ if ($op eq 'save' || $op eq 'insert'){
   # the edited values list when editing certain sub-forms. Get it straight
   # from the DB if absent.
   my $userid = $newdata{ userid } // $borrower_data->{ userid };
-  my $p = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : Koha::Patron->new;
+  my $p = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : Koha::Patron->new();
   $p->userid( $userid );
   unless ( $p->has_valid_userid ) {
     push @errors, "ERROR_login_exist";
@@ -378,7 +384,7 @@ if ($op eq 'save' || $op eq 'insert'){
   push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
 
   if ( $password and $password ne '****' ) {
-      my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password );
+      my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, Koha::Patron::Categories->find($categorycode) );
       unless ( $is_valid ) {
           push @errors, 'ERROR_password_too_short' if $error eq 'too_short';
           push @errors, 'ERROR_password_too_weak' if $error eq 'too_weak';
@@ -518,6 +524,13 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
         }
 
         $patron = Koha::Patrons->find( $borrowernumber );
+
+        if ($NoUpdateEmail) {
+            delete $newdata{'email'};
+            delete $newdata{'emailpro'};
+            delete $newdata{'B_email'};
+        }
+
         $newdata{debarredcomment} = $newdata{debarred_comment};
         delete $newdata{debarred_comment};
         delete $newdata{password2};
@@ -669,6 +682,8 @@ foreach my $category_type (qw(C A S P I X)) {
         push @categoryloop,
           { 'categorycode' => $patron_category->categorycode,
             'categoryname' => $patron_category->description,
+            'effective_min_password_length' => $patron_category->effective_min_password_length,
+            'effective_require_strong_password' => $patron_category->effective_require_strong_password,
             'categorycodeselected' =>
               ( defined($categorycode) && $patron_category->categorycode eq $categorycode ),
           };
@@ -832,6 +847,7 @@ $template->param(
   modify          => $modify,
   nok     => $nok,#flag to know if an error
   NoUpdateLogin =>  $NoUpdateLogin,
+  NoUpdateEmail =>  $NoUpdateEmail,
   );
 
 # Generate CSRF token
@@ -928,7 +944,7 @@ sub patron_attributes_form {
                 $i++;
                 undef $newentry->{value} if ($attr_type->unique_id() && $op eq 'duplicate');
                 $newentry->{form_id} = "patron_attr_$i";
-                push @{$items_by_class{$attr_type->{class}}}, $newentry;
+                push @{$items_by_class{$attr_type->class()}}, $newentry;
             }
         } else {
             $i++;