Bug 24865: (QA follow-up) Remove hardcoded notice name from protected_letters
[srvgit] / tools / automatic_item_modification_by_age.pl
index 12a1c00..a313809 100755 (executable)
@@ -3,6 +3,7 @@
 # This file is part of Koha.
 #
 # Copyright 2013 BibLibre
+# Copyright 2021 Catalyst IT
 #
 # Koha is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -32,18 +33,17 @@ This script allows a user to update the new status for items.
 use Modern::Perl;
 
 use CGI;
-use JSON qw( to_json from_json );
+use JSON qw( to_json );
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Items;
-use C4::Output;
+use C4::Output qw( output_html_with_http_headers );
 use C4::Koha;
 
 use Koha::Items;
 use Koha::Biblioitems;
 
-my $cgi = new CGI;
+my $cgi = CGI->new;
 
 # open template
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -51,7 +51,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         template_name   => "tools/automatic_item_modification_by_age.tt",
         query           => $cgi,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { tools => 'items_batchmod' },
     }
 );
@@ -67,6 +66,7 @@ if ( $op eq 'update' ) {
         my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
         my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
         my @condition_values = $cgi->multi_param("condition_value_$unique_id");
+        my @age_fields = $cgi->multi_param("agefield_$unique_id");
         my $rule = {
             substitutions => [],
             conditions => [],
@@ -86,6 +86,10 @@ if ( $op eq 'update' ) {
         push @{ $rule->{conditions} }, {}
             unless @{ $rule->{conditions} };
         $rule->{age} = $cgi->param("age_$unique_id");
+
+        for my $age_field ( @age_fields ) {
+            $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned";
+        }
         push @rules, $rule;
     }
     my $syspref_content = to_json( \@rules );
@@ -111,9 +115,11 @@ if ( $@ ) {
 
 my @item_fields = map { "items.$_" } Koha::Items->columns;
 my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
+my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on');
 $template->param(
     op => $op,
     messages => \@messages,
+    agefields => [ @age_fields ],
     condition_fields => [ @item_fields, @biblioitem_fields ],
     substitution_fields => \@item_fields,
     rules => $rules,