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
32 use C4
::ItemCirculationAlertPreference
;
35 # shortcut for long package name
36 our $preferences = 'C4::ItemCirculationAlertPreference';
40 my ($data, @keys) = @_;
42 $data->{$_} = decode
('utf8', $data->{$_});
47 # prepend "br_" to column name and replace spaces with "<br/>"
49 my ($data, @keys) = @_;
52 $br =~ s{\s+}{<br/>}g;
53 $data->{'br_'.$_} = $br;
58 # display item circulation alerts
61 my $dbh = C4
::Context
->dbh;
62 my ($template, $user, $cookie) = get_template_and_user
(
64 template_name
=> "admin/item_circulation_alerts.tt",
68 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
69 debug
=> defined($input->param('debug')),
74 my $branch = $input->param('branch') || '*';
78 branchname
=> 'Default',
80 sort { $a->{branchname
} cmp $b->{branchname
} } values %$br,
83 $_->{selected
} = "selected" if ($branch eq $_->{branchcode
});
85 my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname
};
90 my @item_types = map { br
($_, 'description') } (
93 my $grid_checkout = $preferences->grid({ branchcode
=> $branch, notification
=> 'CHECKOUT' });
94 my $grid_checkin = $preferences->grid({ branchcode
=> $branch, notification
=> 'CHECKIN' });
96 $template->param(branch
=> $branch);
97 $template->param(branch_name
=> $branch_name || 'Default');
98 $template->param(branches
=> \
@branches);
99 $template->param(categories
=> \
@categories);
100 $template->param(item_types
=> \
@item_types);
101 $template->param(grid_checkout
=> $grid_checkout);
102 $template->param(grid_checkin
=> $grid_checkin);
104 output_html_with_http_headers
$input, $cookie, $template->output;
107 # toggle a preference via ajax
110 my $id = $input->param('id');
111 my $branch = $input->param('branch');
112 my ($category, $item_type, $notification) = split('-', $id);
114 $item_type =~ s/_/*/;
117 branchcode
=> $branch,
118 categorycode
=> $category,
119 item_type
=> $item_type,
120 notification
=> $notification,
123 my $restrictions = $preferences; # all the same thing...
124 my $notifications = $preferences; #
125 if ($notifications->is_enabled_for($settings)) {
126 # toggle by adding a restriction
127 $restrictions->create($settings);
129 # toggle by removing the restriction
130 $restrictions->delete($settings);
133 my $response = { success
=> 1 };
134 my @reasons = $notifications->is_disabled_for($settings);
136 $response->{classes
} = '';
138 my $default_exists = grep { $_->{branchcode
} eq '*' } @reasons;
139 my $non_default_also = grep { $_->{branchcode
} ne '*' } @reasons;
141 push @classes, 'default' if $default_exists;
142 push @classes, 'disabled' if $non_default_also;
143 $response->{classes
} = join(' ', @classes);
145 print $input->header;
146 print encode_json
($response);
149 # dispatch to various actions based on CGI parameter 'action'
156 my $action = $input->param('action') || 'show';
157 if (not exists $handler{$action}) {
159 print $input->header(-status
=> $status);
162 $input->p("$action is not supported.")
165 $handler{$action}->($input);
170 dispatch
if $ENV{REQUEST_URI
};
176 admin/item_circulation_alerts.pl - per-branch configuration for messaging
180 L<http://intranet.mydomain.com:8080/cgi-bin/koha/admin/item_circulation_alerts.pl>
184 This CGI script drives an interface for configuring item circulation alerts.
185 If you want to prevent alerts from going out for any combination of branch,
186 patron category, and item type, this is where that policy would be set.
193 Display a branches item circulation alert preferences.
201 What branch are we looking at. If none is specified, the virtual default
208 =head3 ?action=toggle
210 Toggle a preference via AJAX
218 The id should be string that can be split on "-" which contains:
219 "$categorycode-$item_type-$notification".
223 Branch code to apply this preference to