Bug 17428: [REST] Cities swagger specification
[koha.git] / members / readingrec.pl
index 62e653e..ed58f1c 100755 (executable)
@@ -28,12 +28,12 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Output;
 use C4::Members;
-use C4::Branch qw(GetBranches);
 use List::MoreUtils qw/any uniq/;
 use Koha::DateUtils;
-
-use C4::Dates qw/format_date/;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
+use Koha::Patron::Images;
+
+use Koha::Patron::Categories;
 
 my $input = CGI->new;
 
@@ -73,33 +73,32 @@ if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
     $issues = GetAllIssues($borrowernumber,$order,$limit);
 }
 
-my $branches = GetBranches();
-
 #   barcode export
 if ( $op eq 'export_barcodes' ) {
-    my $today = C4::Dates->new();
-    $today = $today->output('iso');
-    my @barcodes =
-      map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
-    my $borrowercardnumber =
-      GetMember( borrowernumber => $borrowernumber )->{'cardnumber'};
-    my $delimiter = "\n";
-    binmode( STDOUT, ":encoding(UTF-8)" );
-    print $input->header(
-        -type       => 'application/octet-stream',
-        -charset    => 'utf-8',
-        -attachment => "$today-$borrowercardnumber-checkinexport.txt"
-    );
-    my $content = join $delimiter, uniq(@barcodes);
-    print $content;
-    exit;
+    if ( $data->{'privacy'} < 2) {
+        my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
+        my @barcodes =
+          map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
+        my $borrowercardnumber =
+          GetMember( borrowernumber => $borrowernumber )->{'cardnumber'};
+        my $delimiter = "\n";
+        binmode( STDOUT, ":encoding(UTF-8)" );
+        print $input->header(
+            -type       => 'application/octet-stream',
+            -charset    => 'utf-8',
+            -attachment => "$today-$borrowercardnumber-checkinexport.txt"
+        );
+
+        my $content = join $delimiter, uniq(@barcodes);
+        print $content;
+        exit;
+    }
 }
 
 if ( $data->{'category_type'} eq 'C') {
-    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
-    my $cnt = scalar(@$catcodes);
-    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
-    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
+    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 )  if $patron_categories->count == 1;
 }
 
 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
@@ -107,9 +106,8 @@ if (! $limit){
        $limit = 'full';
 }
 
-
-my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
-$template->param( picture => 1 ) if $picture;
+my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
+$template->param( picture => 1 ) if $patron_image;
 
 if (C4::Context->preference('ExtendedPatronAttributes')) {
     my $attributes = GetBorrowerAttributes($borrowernumber);
@@ -119,17 +117,14 @@ if (C4::Context->preference('ExtendedPatronAttributes')) {
     );
 }
 
-
-my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
 $template->param(%$data);
 
 $template->param(
     readingrecordview => 1,
     borrowernumber    => $borrowernumber,
+    privacy           => $data->{'privacy'},
     categoryname      => $data->{description},
-    roadtype          => $roadtype,
     is_child          => ( $data->{category_type} eq 'C' ),
-    branchname        => $branches->{ $data->{branchcode} }->{branchname},
     loop_reading      => $issues,
     activeBorrowerRelationship =>
       ( C4::Context->preference('borrowerRelationship') ne '' ),