3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
6 # Copyright 2021 Catalyst IT
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 automatic_item_modification_by_age.pl: Update new status for items.
29 This script allows a user to update the new status for items.
36 use JSON qw( to_json );
38 use C4::Auth qw( get_template_and_user );
40 use C4::Output qw( output_html_with_http_headers );
44 use Koha::Biblioitems;
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51 template_name => "tools/automatic_item_modification_by_age.tt",
54 flagsrequired => { tools => 'items_batchmod' },
58 my $op = $cgi->param('op') // 'show';
60 my $syspref_name = q|automatic_item_modification_by_age_configuration|;
61 if ( $op eq 'update' ) {
63 my @unique_ids = $cgi->multi_param('unique_id');
64 for my $unique_id ( @unique_ids ) {
65 my @substitution_fields = $cgi->multi_param("substitution_field_$unique_id");
66 my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
67 my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
68 my @condition_values = $cgi->multi_param("condition_value_$unique_id");
69 my @age_fields = $cgi->multi_param("agefield_$unique_id");
74 for my $value ( @substitution_values ) {
75 my $field = shift @substitution_fields;
77 push @{ $rule->{substitutions} }, { field => $field, value => $value };
79 push @{ $rule->{substitutions} }, {}
80 unless @{ $rule->{substitutions} };
81 for my $value ( @condition_values ) {
82 my $field = shift @condition_fields;
84 push @{ $rule->{conditions} }, { field => $field, value => $value };
86 push @{ $rule->{conditions} }, {}
87 unless @{ $rule->{conditions} };
88 $rule->{age} = $cgi->param("age_$unique_id");
90 for my $age_field ( @age_fields ) {
91 $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned";
95 my $syspref_content = to_json( \@rules );
96 C4::Context->set_preference($syspref_name, $syspref_content);
102 my $syspref_content = C4::Context->preference($syspref_name);
104 $rules = eval { JSON::from_json( $syspref_content ) }
109 code => 'unable_to_load_configuration'
111 $template->param( messages => \@messages );
112 output_html_with_http_headers $cgi, $cookie, $template->output;
116 my @item_fields = map { "items.$_" } Koha::Items->columns;
117 my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
118 my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on');
121 messages => \@messages,
122 agefields => [ @age_fields ],
123 condition_fields => [ @item_fields, @biblioitem_fields ],
124 substitution_fields => \@item_fields,
128 output_html_with_http_headers $cgi, $cookie, $template->output;