Bug 20805: Update child to adult patron process broken on several patron-related...
[koha.git] / members / files.pl
index 73a486a..2e38c0d 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::Branch;
 use C4::Output;
 use C4::Members;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
 use C4::Debug;
 
 use Koha::DateUtils;
+use Koha::Patrons;
 use Koha::Patron::Files;
-use Koha::Patron::Images;
+use Koha::Patron::Categories;
 
 my $cgi = CGI->new;
 
@@ -41,14 +40,19 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         query           => $cgi,
         type            => "intranet",
         authnotrequired => 0,
-        flagsrequired   => { borrowers => 1 },
+        flagsrequired   => { borrowers => 'edit_borrowers' },
         debug           => 1,
     }
 );
 $template->param( 'borrower_files' => 1 );
 
 my $borrowernumber = $cgi->param('borrowernumber');
-my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
+
+my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
+my $patron         = Koha::Patrons->find($borrowernumber);
+output_and_exit_if_error( $cgi, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
+
+my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber ); # FIXME Should be $patron->get_files. Koha::Patron::Files needs to be Koha::Objects based first
 
 my $op = $cgi->param('op') || '';
 
@@ -64,8 +68,9 @@ if ( $op eq 'download' ) {
     print $file->{'file_content'};
 }
 else {
-    my $data = GetMember( borrowernumber => $borrowernumber );
-    $template->param(%$data);
+
+    my $patron_category = $patron->category;
+    $template->param( patron => $patron );
 
     my %errors;
 
@@ -91,7 +96,7 @@ else {
                     name    => $filename,
                     type    => $mimetype,
                     content => $file_content,
-                    description => $cgi->param('description'),
+                    description => scalar $cgi->param('description'),
                 );
             }
         }
@@ -99,15 +104,9 @@ else {
             $errors{'no_file'} = 1;
         }
     } elsif ( $op eq 'delete' ) {
-        $bf->DelFile( id => $cgi->param('file_id') );
+        $bf->DelFile( id => scalar $cgi->param('file_id') );
     }
 
-    $template->param(
-        categoryname    => $data->{'description'},
-        branchname      => GetBranchName($data->{'branchcode'}),
-        RoutingSerials => C4::Context->preference('RoutingSerials'),
-    );
-
     if (C4::Context->preference('ExtendedPatronAttributes')) {
         my $attributes = GetBorrowerAttributes($borrowernumber);
         $template->param(
@@ -116,8 +115,11 @@ else {
         );
     }
 
-    my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
-    $template->param( picture => 1 ) if $patron_image;
+    if ( $patron->is_child ) {
+        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
+        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
+    }
 
     $template->param(
         files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )