3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 automatic_item_modification_by_age.pl: Update new status for items.
28 This script allows a user to update the new status for items.
35 use JSON qw( to_json );
37 use C4::Auth qw( get_template_and_user );
39 use C4::Output qw( output_html_with_http_headers );
43 use Koha::Biblioitems;
48 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50 template_name => "tools/automatic_item_modification_by_age.tt",
53 flagsrequired => { tools => 'items_batchmod' },
57 my $op = $cgi->param('op') // 'show';
59 my $syspref_name = q|automatic_item_modification_by_age_configuration|;
60 if ( $op eq 'update' ) {
62 my @unique_ids = $cgi->multi_param('unique_id');
63 for my $unique_id ( @unique_ids ) {
64 my @substitution_fields = $cgi->multi_param("substitution_field_$unique_id");
65 my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
66 my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
67 my @condition_values = $cgi->multi_param("condition_value_$unique_id");
72 for my $value ( @substitution_values ) {
73 my $field = shift @substitution_fields;
75 push @{ $rule->{substitutions} }, { field => $field, value => $value };
77 push @{ $rule->{substitutions} }, {}
78 unless @{ $rule->{substitutions} };
79 for my $value ( @condition_values ) {
80 my $field = shift @condition_fields;
82 push @{ $rule->{conditions} }, { field => $field, value => $value };
84 push @{ $rule->{conditions} }, {}
85 unless @{ $rule->{conditions} };
86 $rule->{age} = $cgi->param("age_$unique_id");
89 my $syspref_content = to_json( \@rules );
90 C4::Context->set_preference($syspref_name, $syspref_content);
96 my $syspref_content = C4::Context->preference($syspref_name);
98 $rules = eval { JSON::from_json( $syspref_content ) }
103 code => 'unable_to_load_configuration'
105 $template->param( messages => \@messages );
106 output_html_with_http_headers $cgi, $cookie, $template->output;
110 my @item_fields = map { "items.$_" } Koha::Items->columns;
111 my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
114 messages => \@messages,
115 condition_fields => [ @item_fields, @biblioitem_fields ],
116 substitution_fields => \@item_fields,
120 output_html_with_http_headers $cgi, $cookie, $template->output;