Bug 3150: (follow-up) Make subs to get host/related parts for notices
[koha-ffzg.git] / members / members-update-do.pl
index d07acdb..a42c1ff 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use C4::Auth;
+use C4::Auth qw( checkauth );
 use C4::Output;
 use C4::Context;
-use C4::Members;
-use C4::Branch;
+use Koha::Patrons;
 use Koha::Patron::Modifications;
 
-my $query = new CGI;
+my $query = CGI->new;
 
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
-    {
-        template_name   => "about.tt",
-        query           => $query,
-        type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { borrowers => 1 },
-        debug           => 1,
-    }
-);
+my ( $userid, $cookie, $sessionID, $flags ) = checkauth($query, 0, { borrowers => 'edit_borrowers' }, 'intranet');
+
+my $logged_in_user = Koha::Patrons->find({ userid => $userid });
 
 my @params = $query->param;
 
@@ -46,10 +37,21 @@ foreach my $param (@params) {
     if ( $param =~ "^modify_" ) {
         my (undef, $borrowernumber) = split( /_/, $param );
 
+        my $patron = Koha::Patrons->find($borrowernumber);
+        next unless $logged_in_user->can_see_patron_infos( $patron );
+
         my $action = $query->param($param);
 
         if ( $action eq 'approve' ) {
             my $m = Koha::Patron::Modifications->find( { borrowernumber => $borrowernumber } );
+
+            if ($query->param("unset_gna_$borrowernumber")) {
+                # Unset gone no address
+                # FIXME Looks like this could go to $m->approve
+                my $patron = Koha::Patrons->find( $borrowernumber );
+                $patron->gonenoaddress(undef)->store;
+            }
+
             $m->approve() if $m;
         }
         elsif ( $action eq 'deny' ) {