3 # Copyright 2007 LibLime
5 # This file is part of Koha.
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 #use warnings; FIXME - Bug 2505
29 use C4
::ClassSortRoutine
;
31 my $script_name = "/cgi-bin/koha/admin/classsources.pl";
34 my $op = $input->param('op') || '';
35 my $source_code = $input->param('class_source');
36 my $rule_code = $input->param('sort_rule');
37 my $sort_routine = $input->param('sort_routine');
38 my ($template, $loggedinuser, $cookie)
39 = get_template_and_user
({template_name
=> "admin/classsources.tt",
43 flagsrequired
=> {parameters
=> 'parameters_remaining_permissions'},
47 $template->param(script_name
=> $script_name);
48 $template->param($op => 1) if $op;
49 my $description = $input->param('description');
50 my $used = $input->param('used');
51 my $display_lists = 0;
52 if ($op eq "add_source") {
53 add_class_source_form
($template);
54 } elsif ($op eq "add_source_confirmed") {
55 add_class_source
($template,
58 $used eq "used" ?
1 : 0,
61 } elsif ($op eq "delete_source") {
62 delete_class_source_form
($template, $source_code);
63 } elsif ($op eq "delete_source_confirmed") {
64 delete_class_source
($template, $source_code);
66 } elsif ($op eq "edit_source") {
67 edit_class_source_form
($template, $source_code);
68 } elsif ($op eq "edit_source_confirmed") {
69 edit_class_source
($template,
72 $used eq "used" ?
1 : 0,
75 } elsif ($op eq "add_sort_rule") {
76 add_class_sort_rule_form
($template);
77 } elsif ($op eq "add_sort_rule_confirmed") {
78 add_class_sort_rule
($template,
83 } elsif ($op eq "delete_sort_rule") {
84 delete_sort_rule_form
($template, $rule_code);
85 } elsif ($op eq "delete_sort_rule_confirmed") {
86 delete_sort_rule
($template, $rule_code);
88 } elsif ($op eq "edit_sort_rule") {
89 edit_class_sort_rule_form
($template, $rule_code);
90 } elsif ($op eq "edit_sort_rule_confirmed") {
91 edit_class_sort_rule
($template,
100 if ($display_lists) {
101 $template->param(display_lists
=> 1);
102 class_source_list
($template);
103 class_sort_rule_list
($template);
106 output_html_with_http_headers
$input, $cookie, $template->output;
110 sub add_class_source_form
{
113 class_source_form
=> 1,
114 confirm_op
=> "add_source_confirmed",
117 get_sort_rule_codes
($template, '');
120 sub add_class_source
{
121 my ($template, $source_code, $description, $used, $sort_rule) = @_;
122 my $success = AddClassSource
($source_code, $description, $used, $sort_rule);
124 $template->param(added_source
=> $source_code);
126 $template->param(failed_add_source
=> $source_code);
130 sub edit_class_source_form
{
131 my ($template, $source_code) = @_;
133 my $source = GetClassSource
($source_code);
135 class_source_form
=> 1,
136 edit_class_source
=> 1,
137 class_source
=> $source_code,
138 confirm_op
=> "edit_source_confirmed",
139 description
=> $source->{'description'},
140 used
=> $source->{'used'},
143 get_sort_rule_codes
($template, $source->{'class_sort_rule'});
146 sub edit_class_source
{
147 my ($template, $source_code, $description, $used, $sort_rule) = @_;
148 ModClassSource
($source_code, $description, $used, $sort_rule);
149 $template->param(edited_source
=> $source_code);
153 sub delete_class_source_form
{
154 my ($template, $source_code) = @_;
156 delete_class_source_form
=> 1,
157 confirm_op
=> "delete_source_confirmed",
158 class_source
=> $source_code,
162 sub delete_class_source
{
163 my ($template, $source_code) = @_;
164 DelClassSource
($source_code);
165 $template->param(deleted_source
=> $source_code);
168 sub get_sort_rule_codes
{
169 my ($template, $current_rule) = @_;
171 my $sort_rules = GetClassSortRules
();
174 foreach my $sort_rule (sort keys %$sort_rules) {
175 my $sort_rule = $sort_rules->{$sort_rule};
177 rule
=> $sort_rule->{'class_sort_rule'},
178 description
=> $sort_rule->{'description'},
179 selected
=> $sort_rule->{'class_sort_rule'} eq $current_rule ?
1 : 0
182 $template->param(rules_dropdown
=> \
@sort_rules);
186 sub add_class_sort_rule_form
{
190 confirm_op
=> "add_sort_rule_confirmed"
192 get_class_sort_routines
($template, "");
195 sub add_class_sort_rule
{
196 my ($template, $rule_code, $description, $sort_routine) = @_;
197 my $success = AddClassSortRule
($rule_code, $description, $sort_routine);
199 $template->param(added_rule
=> $rule_code);
201 $template->param(failed_add_rule
=> $rule_code);
205 sub delete_sort_rule_form
{
206 my ($template, $rule_code) = @_;
208 my @sources = GetSourcesForSortRule
($rule_code);
209 if ($#sources == -1) {
211 delete_sort_rule_form
=> 1,
212 confirm_op
=> "delete_sort_rule_confirmed",
213 sort_rule
=> $rule_code,
217 delete_sort_rule_impossible
=> 1,
218 sort_rule
=> $rule_code
223 sub delete_sort_rule
{
224 my ($template, $rule_code) = @_;
225 DelClassSortRule
($rule_code);
226 $template->param(deleted_rule
=> $rule_code);
229 sub edit_class_sort_rule_form
{
230 my ($template, $rule_code) = @_;
232 my $rule = GetClassSortRule
($rule_code);
236 confirm_op
=> "edit_sort_rule_confirmed",
237 sort_rule
=> $rule_code,
238 description
=> $rule->{'description'},
239 sort_routine
=> $rule->{'sort_routine'}
242 get_class_sort_routines
($template, $rule->{'sort_routine'});
246 sub get_class_sort_routines
{
247 my ($template, $current_routine) = @_;
249 my @sort_routines = GetSortRoutineNames
();
252 foreach my $sort_routine (sort @sort_routines) {
254 routine
=> $sort_routine,
255 selected
=> $sort_routine eq $current_routine ?
1 : 0
258 $template->param(routines_dropdown
=> \
@sort_form);
262 sub edit_class_sort_rule
{
263 my ($template, $rule_code, $description, $sort_routine) = @_;
264 ModClassSortRule
($rule_code, $description, $sort_routine);
265 $template->param(edited_rule
=> $rule_code);
268 sub class_source_list
{
270 my $sources = GetClassSources
();
273 foreach my $cn_source (sort keys %$sources) {
274 my $source = $sources->{$cn_source};
276 code
=> $source->{'cn_source'},
277 description
=> $source->{'description'},
278 used
=> $source->{'used'},
279 sortrule
=> $source->{'class_sort_rule'}
282 $template->param(class_sources
=> \
@sources);
285 sub class_sort_rule_list
{
288 my $sort_rules = GetClassSortRules
();
291 foreach my $sort_rule (sort keys %$sort_rules) {
292 my $sort_rule = $sort_rules->{$sort_rule};
294 rule
=> $sort_rule->{'class_sort_rule'},
295 description
=> $sort_rule->{'description'},
296 sort_routine
=> $sort_rule->{'sort_routine'}
299 $template->param(class_sort_rules
=> \
@sort_rules);