3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
24 use URI::Escape 'uri_escape_utf8';
33 use C4::ItemCirculationAlertPreference;
36 # shortcut for long package name
37 my $preferences = 'C4::ItemCirculationAlertPreference';
41 my ($data, @keys) = @_;
43 $data->{$_} = decode('utf8', $data->{$_});
48 # prepend "br_" to column name and replace spaces with "<br/>"
50 my ($data, @keys) = @_;
53 $br =~ s{\s+}{<br/>}g;
54 $data->{'br_'.$_} = $br;
59 # display item circulation alerts
62 my $dbh = C4::Context->dbh;
63 my ($template, $user, $cookie) = get_template_and_user(
65 template_name => "admin/item_circulation_alerts.tmpl",
69 flagsrequired => { admin => 1 },
70 debug => defined($input->param('debug')),
75 my $branch = $input->param('branch') || '*';
76 my @branches = map { utf8($_, 'branchname') } (
79 branchname => 'Default',
81 sort { $a->{branchname} cmp $b->{branchname} } values %$br,
84 $_->{selected} = "selected" if ($branch eq $_->{branchcode});
86 my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
88 my @categories = map { utf8($_, 'description') } (
91 my @item_types = map { utf8($_, 'description'); br($_, 'description') } (
94 my $grid_checkout = $preferences->grid({ branchcode => $branch, notification => 'CHECKOUT' });
95 my $grid_checkin = $preferences->grid({ branchcode => $branch, notification => 'CHECKIN' });
97 $template->param(branch => $branch);
98 $template->param(branch_name => $branch_name || 'Default');
99 $template->param(branches => \@branches);
100 $template->param(categories => \@categories);
101 $template->param(item_types => \@item_types);
102 $template->param(grid_checkout => $grid_checkout);
103 $template->param(grid_checkin => $grid_checkin);
105 output_html_with_http_headers $input, $cookie, $template->output;
108 # toggle a preference via ajax
111 my $id = $input->param('id');
112 my $branch = $input->param('branch');
113 my ($category, $item_type, $notification) = split('-', $id);
115 $item_type =~ s/_/*/;
118 branchcode => $branch,
119 categorycode => $category,
120 item_type => $item_type,
121 notification => $notification,
124 my $restrictions = $preferences; # all the same thing...
125 my $notifications = $preferences; #
126 if ($notifications->is_enabled_for($settings)) {
127 # toggle by adding a restriction
128 $restrictions->create($settings);
130 # toggle by removing the restriction
131 $restrictions->delete($settings);
134 my $response = { success => 1 };
135 my @reasons = $notifications->is_disabled_for($settings);
137 $response->{class} = '';
139 my $default_exists = grep { $_->{branchcode} eq '*' } @reasons;
140 my $non_default_also = grep { $_->{branchcode} ne '*' } @reasons;
142 push @classes, 'default' if $default_exists;
143 push @classes, 'disabled' if $non_default_also;
144 $response->{class} = join(' ', @classes);
146 print $input->header;
147 print encode_json($response);
150 # dispatch to various actions based on CGI parameter 'action'
157 my $action = $input->param('action') || 'show';
158 if (not exists $handler{$action}) {
160 print $input->header(-status => $status);
163 $input->p("$action is not supported.")
166 $handler{$action}->($input);
171 dispatch if $ENV{REQUEST_URI};
177 admin/item_circulation_alerts.pl - per-branch configuration for messaging
181 L<http://intranet.mydomain.com:8080/cgi-bin/koha/admin/item_circulation_alerts.pl>
185 This CGI script drives an interface for configuring item circulation alerts.
186 If you want to prevent alerts from going out for any combination of branch,
187 patron category, and item type, this is where that policy would be set.
194 Display a branches item circulation alert preferences.
202 What branch are we looking at. If none is specified, the virtual default
209 =head3 ?action=toggle
211 Toggle a preference via AJAX
219 "$categorycode-$item_type-$notification"
223 Branch code to apply this preference to
229 # Local Variables: ***
231 # indent-tabs-mode: nil ***
232 # cperl-close-paren-offset: -4 ***
233 # cperl-continued-statement-offset: 4 ***
234 # cperl-indent-level: 4 ***
235 # cperl-indent-parens-as-block: t ***
236 # cperl-tab-always-indent: nil ***
238 # vim:tabstop=8 softtabstop=4 shiftwidth=4 shiftround expandtab