Bug 14686: Add two granular permission for upload under tools
[koha.git] / tools / automatic_item_modification_by_age.pl
blob82895d25dd918b51dc89bbc31f48c3507a6485a2
1 #!/usr/bin/perl
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>.
20 =head1 NAME
22 automatic_item_modification_by_age.pl: Update new status for items.
24 =cut
26 =head1 DESCRIPTION
28 This script allows a user to update the new status for items.
30 =cut
32 use Modern::Perl;
34 use CGI;
35 use JSON qw( to_json from_json );
37 use C4::Auth;
38 use C4::Context;
39 use C4::Items;
40 use C4::Output;
41 use C4::Koha;
43 my $cgi = new CGI;
45 # open template
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48 template_name => "tools/automatic_item_modification_by_age.tt",
49 query => $cgi,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { tools => 'items_batchmod' },
56 my $op = $cgi->param('op') // 'show';
58 my $syspref_name = q|automatic_item_modification_by_age_configuration|;
59 if ( $op eq 'update' ) {
60 my @rules;
61 my @unique_ids = $cgi->multi_param('unique_id');
62 for my $unique_id ( @unique_ids ) {
63 my @substitution_fields = $cgi->multi_param("substitution_field_$unique_id");
64 my @substitution_values = $cgi->multi_param("substitution_value_$unique_id");
65 my @condition_fields = $cgi->multi_param("condition_field_$unique_id");
66 my @condition_values = $cgi->multi_param("condition_value_$unique_id");
67 my $rule = {
68 substitutions => [],
69 conditions => [],
71 for my $value ( @substitution_values ) {
72 my $field = shift @substitution_fields;
73 last unless $field;
74 push @{ $rule->{substitutions} }, { field => $field, value => $value };
76 push @{ $rule->{substitutions} }, {}
77 unless @{ $rule->{substitutions} };
78 for my $value ( @condition_values ) {
79 my $field = shift @condition_fields;
80 last unless $field;
81 push @{ $rule->{conditions} }, { field => $field, value => $value };
83 push @{ $rule->{conditions} }, {}
84 unless @{ $rule->{conditions} };
85 $rule->{age} = $cgi->param("age_$unique_id");
86 push @rules, $rule;
88 my $syspref_content = to_json( \@rules );
89 C4::Context->set_preference($syspref_name, $syspref_content);
91 $op = 'show';
94 my @messages;
95 my $syspref_content = C4::Context->preference($syspref_name);
96 my $rules;
97 $rules = eval { JSON::from_json( $syspref_content ) }
98 if $syspref_content;
99 if ( $@ ) {
100 push @messages, {
101 type => 'error',
102 code => 'unable_to_load_configuration'
104 $template->param( messages => \@messages );
105 output_html_with_http_headers $cgi, $cookie, $template->output;
106 exit;
109 my @item_fields = map { "items.$_" } C4::Items::columns;
110 my @biblioitem_fields = map { "biblioitems.$_" } C4::Items::biblioitems_columns;
111 $template->param(
112 op => $op,
113 messages => \@messages,
114 condition_fields => [ @item_fields, @biblioitem_fields ],
115 substitution_fields => \@item_fields,
116 rules => $rules,
119 output_html_with_http_headers $cgi, $cookie, $template->output;