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';
32 use C4::ItemCirculationAlertPreference;
35 # shortcut for long package name
36 my $preferences = 'C4::ItemCirculationAlertPreference';
38 # common redirect code
41 my $path = defined($input->param('redirect_to'))
42 ? $input->param('redirect_to')
44 print $input->redirect($path);
49 my ($data, @keys) = @_;
51 $data->{$_} = decode('utf8', $data->{$_});
56 # add long category and itemtype descriptions to preferences
57 sub category_and_itemtype {
58 my ($categories, $item_types, @prefs) = @_;
59 my %c = map { $_->{categorycode} => $_->{description} } @$categories;
60 my %i = map { $_->{itemtype} => $_->{description} } @$item_types;
62 $_->{category_description} = $c{$_->{categorycode}} || 'Default';
63 $_->{item_type_description} = $i{$_->{item_type}} || 'Default';
67 # display item circulation alerts
70 my $dbh = C4::Context->dbh;
71 my ($template, $user, $cookie) = get_template_and_user(
73 template_name => "admin/item_circulation_alerts.tmpl",
77 flagsrequired => { admin => 1 },
78 debug => defined($input->param('debug')),
83 my $branch = $input->param('branch') || '*';
84 my @branches = map { utf8($_, 'branchname') } (
87 branchname => 'Default',
89 sort { $a->{branchname} cmp $b->{branchname} } values %$br,
92 $_->{selected} = "selected" if ($branch eq $_->{branchcode});
94 my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
96 my @categories = map { utf8($_, 'description') } (
97 C4::Category->new({ categorycode => '*', description => 'Default' }),
100 my @item_types = map { utf8($_, 'description') } (
101 C4::ItemType->new({ itemtype => '*', description => 'Default' }),
104 my @default_prefs = $preferences->find({ branchcode => '*' });
106 my $redirect_to = "?branch=$branch";
108 $template->param(redirect_to => $redirect_to);
109 $template->param(redirect_to_x => uri_escape_utf8($redirect_to));
110 $template->param(branch => $branch);
111 $template->param(branch_name => $branch_name);
112 $template->param(branches => \@branches);
113 $template->param(categories => \@categories);
114 $template->param(item_types => \@item_types);
115 $template->param(default_prefs => \@default_prefs);
116 if ($branch ne '*') {
117 @branch_prefs = $preferences->find({ branchcode => $branch });
118 $template->param(branch_prefs => \@branch_prefs);
120 category_and_itemtype(\@categories, \@item_types, (@default_prefs, @branch_prefs));
121 output_html_with_http_headers $input, $cookie, $template->output;
124 # create item circulation alert preference and redirect
127 my $branchcode = $input->param('branchcode');
128 my $categorycode = $input->param('categorycode');
129 my $item_type = $input->param('item_type');
130 $preferences->create({
131 branchcode => $branchcode,
132 categorycode => $categorycode,
133 item_type => $item_type,
138 # delete preference and redirect
141 my $id = $input->param('id');
142 $preferences->delete({ id => $id });
146 # dispatch to various actions based on CGI parameter 'action'
154 my $action = $input->param('action') || 'show';
155 if (not exists $handler{$action}) {
157 print $input->header(-status => $status);
160 $input->p("$action is not supported.")
163 $handler{$action}->($input);
168 dispatch if $ENV{REQUEST_URI};
174 admin/item_circulation_alerts.pl - per-branch configuration for messaging
178 L<http://intranet.mydomain.com:8080/cgi-bin/koha/admin/item_circulation_alerts.pl>
182 This CGI script drives an interface for configuring item circulation alerts.
183 If you want to prevent alerts from going out for any combination of branch,
184 patron category, and item type, this is where that policy would be set.
191 Display a branches item circulation alert preferences.
199 What branch are we looking at. If none is specified, the virtual default
207 =head3 ?action=create
209 Create an item circulation alert preference.
232 =head3 ?action=delete
234 Delete an item circulation alert preference.
242 The id of the preference to delete.
251 # Local Variables: ***
253 # indent-tabs-mode: nil ***
254 # cperl-close-paren-offset: -4 ***
255 # cperl-continued-statement-offset: 4 ***
256 # cperl-indent-level: 4 ***
257 # cperl-indent-parens-as-block: t ***
258 # cperl-tab-always-indent: nil ***
260 # vim:tabstop=8 softtabstop=4 shiftwidth=4 shiftround expandtab