Bug 24588: Prevent e-mails from Koha to be flagged as spam
[koha-ffzg.git] / svc / holds
index 5aefb6b..55aa3a6 100755 (executable)
--- a/svc/holds
+++ b/svc/holds
@@ -23,13 +23,14 @@ use CGI;
 use JSON qw(to_json);
 
 use C4::Auth qw(check_cookie_auth);
-use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
 use C4::Charset;
 use C4::Circulation qw(GetTransfers);
 use C4::Context;
 
 use Koha::DateUtils;
 use Koha::Holds;
+use Koha::ItemTypes;
+use Koha::Libraries;
 
 my $input = new CGI;
 
@@ -52,8 +53,8 @@ my $borrowernumber    = $input->param('borrowernumber');
 my $offset            = $input->param('iDisplayStart');
 my $results_per_page  = $input->param('iDisplayLength');
 my $sorting_direction = $input->param('sSortDir_0') || 'desc';
-my $sorting_column    = $sort_columns[ $input->param('iSortCol_0') ]
-  || 'reservedate';
+my $iSortCol          = $input->param('iSortCol_0') // 0;
+my $sorting_column    = $sort_columns[$iSortCol] // 'reservedate';
 
 binmode STDOUT, ":encoding(UTF-8)";
 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
@@ -74,17 +75,29 @@ while ( my $h = $holds_rs->next() ) {
 
     my $itemtype_limit;
     if ( $h->itemtype ) {
-        my $itemtype = C4::Koha::getitemtypeinfo( $h->itemtype );
-        $itemtype_limit = $itemtype->{translated_description};
+        my $itemtype = Koha::ItemTypes->find( $h->itemtype );
+        $itemtype_limit = $itemtype->translated_description;
     }
 
+    my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
+    for my $library ( @$libraries ) {
+        $library->{selected} = 1 if $library->{branchcode} eq $h->branchcode();
+    }
+
+    my $biblio = $h->biblio();
+    my @subtitles = split(/ \| /, $biblio->subtitle() // '');
     my $hold = {
         DT_RowId       => $h->reserve_id(),
         biblionumber   => $biblionumber,
-        title          => $h->biblio()->title(),
-        author         => $h->biblio()->author(),
+        title          => $biblio->title(),
+        subtitle       => \@subtitles,
+        medium         => $biblio->medium() // '',
+        part_number    => $biblio->part_number() // '',
+        part_name      => $biblio->part_name() // '',
+        author         => $biblio->author(),
         reserve_id     => $h->reserve_id(),
         branchcode     => $h->branch()->branchname(),
+        branches       => $libraries,
         reservedate    => $h->reservedate(),
         expirationdate => $h->expirationdate(),
         suspend        => $h->suspend(),
@@ -95,10 +108,6 @@ while ( my $h = $holds_rs->next() ) {
         waiting_here   => $h->branch()->branchcode() eq $branch,
         priority       => $h->priority(),
         itemtype_limit => $itemtype_limit,
-        subtitle       => GetRecordValue(
-            'subtitle', GetMarcBiblio($biblionumber),
-            GetFrameworkCode($biblionumber)
-        ),
         reservedate_formatted => $h->reservedate() ? output_pref(
             { dt => dt_from_string( $h->reservedate() ), dateonly => 1 }
           )
@@ -113,11 +122,6 @@ while ( my $h = $holds_rs->next() ) {
         : q{},
     };
 
-    if ( my $e = $h->waiting_expires_on() ) {
-        $hold->{expirationdate} = $e->ymd();
-        $hold->{expirationdate_formatted} = output_pref( { dt => $e, dateonly => 1 });
-    }
-
     $hold->{transfered}     = 0;
     $hold->{not_transfered} = 0;
 
@@ -125,6 +129,7 @@ while ( my $h = $holds_rs->next() ) {
         $hold->{itemnumber}     = $item->itemnumber();
         $hold->{barcode}        = $item->barcode();
         $hold->{itemtype}       = $item->effective_itemtype();
+        $hold->{enumchron}      = $item->enumchron();
         $hold->{itemcallnumber} = $item->itemcallnumber() || q{};
 
         my ( $transferred_when, $transferred_from, $transferred_to ) =