Bug 31051: Fix test
[koha-ffzg.git] / labels / label-item-search.pl
index d93c922..4dba302 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 vars qw($debug $cgi_debug);
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use List::Util qw( max min );
-use POSIX qw(ceil);
+use POSIX qw( ceil );
 
-use C4::Auth qw(get_template_and_user);
-use C4::Output qw(output_html_with_http_headers);
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
 use C4::Context;
-use C4::Search qw(SimpleSearch);
-use C4::Biblio qw(TransformMarcToKoha);
-use C4::Creators::Lib qw(html_table);
-use C4::Debug;
+use C4::Search qw( new_record_from_zebra );
+use C4::Biblio qw( TransformMarcToKoha );
+use C4::Creators::Lib qw( html_table );
 
-use Koha::DateUtils;
+use Koha::Logger;
 use Koha::Items;
 use Koha::ItemTypes;
 use Koha::SearchEngine::Search;
 
-BEGIN {
-    $debug = $debug || $cgi_debug;
-    if ($debug) {
-        require Data::Dumper;
-        import Data::Dumper qw(Dumper);
-    }
-}
-
-my $query = new CGI;
+my $query = CGI->new;
 
 my $type      = $query->param('type');
 my $op        = $query->param('op') || '';
@@ -68,8 +56,6 @@ my $display_columns = [ {_add                   => {label => "Add Item", link_fi
                       ];
 
 if ( $op eq "do_search" ) {
-    my $QParser;
-    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
     $idx         = $query->param('idx');
     $ccl_textbox = $query->param('ccl_textbox');
     if ( $ccl_textbox && $idx ) {
@@ -80,32 +66,13 @@ if ( $op eq "do_search" ) {
     $dateto   = $query->param('dateto');
 
     if ($datefrom) {
-        $datefrom = eval { dt_from_string ( $datefrom ) };
-        if ($datefrom) {
-            $datefrom = output_pref( { dt => $datefrom, dateonly => 1, dateformat => 'iso' } );
-            if ($QParser) {
-                $ccl_query .= ' && ' if $ccl_textbox;
-                $ccl_query .=
-                    "acqdate(" . $datefrom . '-)';
-            } else {
-                $ccl_query .= ' and ' if $ccl_textbox;
-                $ccl_query .= "acqdate,st-date-normalized,ge=" . $datefrom;
-            }
-        }
+        $ccl_query .= ' AND ' if $ccl_textbox;
+        $ccl_query .= "acqdate,ge,st-date-normalized=" . $datefrom;
     }
 
     if ($dateto) {
-        $dateto = eval { dt_from_string ( $dateto ) };
-        if ($dateto) {
-           $dateto = output_pref( { dt => $dateto, dateonly => 1, dateformat => 'iso' } );
-            if ($QParser) {
-                $ccl_query .= ' && ' if ( $ccl_textbox || $datefrom );
-                $ccl_query .= "acqdate(-" . $dateto . ')';
-            } else {
-                $ccl_query .= ' and ' if ( $ccl_textbox || $datefrom );
-                $ccl_query .= "acqdate,st-date-normalized,le=" . $dateto;
-            }
-        }
+        $ccl_query .= ' AND ' if ( $ccl_textbox || $datefrom );
+        $ccl_query .= "acqdate,le,st-date-normalized=" . $dateto;
     }
 
     my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
@@ -116,7 +83,7 @@ if ( $op eq "do_search" ) {
         $show_results = @{$marcresults};
     }
     else {
-        $debug and warn "ERROR label-item-search: no results from simple_search_compat";
+        Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat");
 
         # leave $show_results undef
     }
@@ -126,14 +93,12 @@ if ($show_results) {
     my $hits = $show_results;
     my @results_set = ();
     my @items =();
-    # This code needs to be refactored using these subs...
-    #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
     for ( my $i = 0 ; $i < $hits ; $i++ ) {
         my @row_data= ();
         #DEBUG Notes: Decode the MARC record from each resulting MARC record...
         my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcresults->[$i] );
         #DEBUG Notes: Transform it to Koha form...
-        my $biblio = TransformMarcToKoha( $marcrecord, '' );
+        my $biblio = TransformMarcToKoha({ record => $marcrecord });
         #DEBUG Notes: Stuff the bib into @biblio_data...
         push (@results_set, $biblio);
         my $biblionumber = $biblio->{'biblionumber'};
@@ -160,10 +125,8 @@ if ($show_results) {
             template_name   => "labels/result.tt",
             query           => $query,
             type            => "intranet",
-            authnotrequired => 0,
-            flagsrequired   => { borrowers => 1 },
+            flagsrequired   => { borrowers => 'edit_borrowers' },
             flagsrequired   => { catalogue => 1 },
-            debug           => 1,
         }
     );
 
@@ -240,9 +203,7 @@ else {
             template_name   => "labels/search.tt",
             query           => $query,
             type            => "intranet",
-            authnotrequired => 0,
             flagsrequired   => { catalogue => 1 },
-            debug           => 1,
         }
     );
     my $itemtypes = Koha::ItemTypes->search;