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');
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;
50 my $display_lists = 0;
51 if ($op eq "add_source") {
52 add_class_source_form
($template);
53 } elsif ($op eq "add_source_confirmed") {
54 add_class_source
($template,
56 $input->param('description'),
57 $input->param('used') eq "used" ?
1 : 0,
60 } elsif ($op eq "delete_source") {
61 delete_class_source_form
($template, $source_code);
62 } elsif ($op eq "delete_source_confirmed") {
63 delete_class_source
($template, $source_code);
65 } elsif ($op eq "edit_source") {
66 edit_class_source_form
($template, $source_code);
67 } elsif ($op eq "edit_source_confirmed") {
68 edit_class_source
($template,
70 $input->param('description'),
71 $input->param('used') eq "used" ?
1 : 0,
74 } elsif ($op eq "add_sort_rule") {
75 add_class_sort_rule_form
($template);
76 } elsif ($op eq "add_sort_rule_confirmed") {
77 add_class_sort_rule
($template,
79 $input->param('description'),
80 $input->param('sort_routine'));
82 } elsif ($op eq "delete_sort_rule") {
83 delete_sort_rule_form
($template, $rule_code);
84 } elsif ($op eq "delete_sort_rule_confirmed") {
85 delete_sort_rule
($template, $rule_code);
87 } elsif ($op eq "edit_sort_rule") {
88 edit_class_sort_rule_form
($template, $rule_code);
89 } elsif ($op eq "edit_sort_rule_confirmed") {
90 edit_class_sort_rule
($template,
92 $input->param('description'),
93 $input->param('sort_routine'));
100 $template->param(display_lists
=> 1);
101 class_source_list
($template);
102 class_sort_rule_list
($template);
105 output_html_with_http_headers
$input, $cookie, $template->output;
109 sub add_class_source_form
{
112 class_source_form
=> 1,
113 confirm_op
=> "add_source_confirmed",
116 get_sort_rule_codes
($template, '');
119 sub add_class_source
{
120 my ($template, $source_code, $description, $used, $sort_rule) = @_;
121 my $success = AddClassSource
($source_code, $description, $used, $sort_rule);
123 $template->param(added_source
=> $source_code);
125 $template->param(failed_add_source
=> $source_code);
129 sub edit_class_source_form
{
130 my ($template, $source_code) = @_;
132 my $source = GetClassSource
($source_code);
134 class_source_form
=> 1,
135 edit_class_source
=> 1,
136 class_source
=> $source_code,
137 confirm_op
=> "edit_source_confirmed",
138 description
=> $source->{'description'},
139 used
=> $source->{'used'},
142 get_sort_rule_codes
($template, $source->{'class_sort_rule'});
145 sub edit_class_source
{
146 my ($template, $source_code, $description, $used, $sort_rule) = @_;
147 ModClassSource
($source_code, $description, $used, $sort_rule);
148 $template->param(edited_source
=> $source_code);
152 sub delete_class_source_form
{
153 my ($template, $source_code) = @_;
155 delete_class_source_form
=> 1,
156 confirm_op
=> "delete_source_confirmed",
157 class_source
=> $source_code,
161 sub delete_class_source
{
162 my ($template, $source_code) = @_;
163 DelClassSource
($source_code);
164 $template->param(deleted_source
=> $source_code);
167 sub get_sort_rule_codes
{
168 my ($template, $current_rule) = @_;
170 my $sort_rules = GetClassSortRules
();
173 foreach my $sort_rule (sort keys %$sort_rules) {
174 my $sort_rule = $sort_rules->{$sort_rule};
176 rule
=> $sort_rule->{'class_sort_rule'},
177 description
=> $sort_rule->{'description'},
178 selected
=> $sort_rule->{'class_sort_rule'} eq $current_rule ?
1 : 0
181 $template->param(rules_dropdown
=> \
@sort_rules);
185 sub add_class_sort_rule_form
{
189 confirm_op
=> "add_sort_rule_confirmed"
191 get_class_sort_routines
($template, "");
194 sub add_class_sort_rule
{
195 my ($template, $rule_code, $description, $sort_routine) = @_;
196 my $success = AddClassSortRule
($rule_code, $description, $sort_routine);
198 $template->param(added_rule
=> $rule_code);
200 $template->param(failed_add_rule
=> $rule_code);
204 sub delete_sort_rule_form
{
205 my ($template, $rule_code) = @_;
207 my @sources = GetSourcesForSortRule
($rule_code);
208 if ($#sources == -1) {
210 delete_sort_rule_form
=> 1,
211 confirm_op
=> "delete_sort_rule_confirmed",
212 sort_rule
=> $rule_code,
216 delete_sort_rule_impossible
=> 1,
217 sort_rule
=> $rule_code
222 sub delete_sort_rule
{
223 my ($template, $rule_code) = @_;
224 DelClassSortRule
($rule_code);
225 $template->param(deleted_rule
=> $rule_code);
228 sub edit_class_sort_rule_form
{
229 my ($template, $rule_code) = @_;
231 my $rule = GetClassSortRule
($rule_code);
235 confirm_op
=> "edit_sort_rule_confirmed",
236 sort_rule
=> $rule_code,
237 description
=> $rule->{'description'},
238 sort_routine
=> $rule->{'sort_routine'}
241 get_class_sort_routines
($template, $rule->{'sort_routine'});
245 sub get_class_sort_routines
{
246 my ($template, $current_routine) = @_;
248 my @sort_routines = GetSortRoutineNames
();
251 foreach my $sort_routine (sort @sort_routines) {
253 routine
=> $sort_routine,
254 selected
=> $sort_routine eq $current_routine ?
1 : 0
257 $template->param(routines_dropdown
=> \
@sort_form);
261 sub edit_class_sort_rule
{
262 my ($template, $rule_code, $description, $sort_routine) = @_;
263 ModClassSortRule
($rule_code, $description, $sort_routine);
264 $template->param(edited_rule
=> $rule_code);
267 sub class_source_list
{
269 my $sources = GetClassSources
();
272 foreach my $cn_source (sort keys %$sources) {
273 my $source = $sources->{$cn_source};
275 code
=> $source->{'cn_source'},
276 description
=> $source->{'description'},
277 used
=> $source->{'used'},
278 sortrule
=> $source->{'class_sort_rule'}
281 $template->param(class_sources
=> \
@sources);
284 sub class_sort_rule_list
{
287 my $sort_rules = GetClassSortRules
();
290 foreach my $sort_rule (sort keys %$sort_rules) {
291 my $sort_rule = $sort_rules->{$sort_rule};
293 rule
=> $sort_rule->{'class_sort_rule'},
294 description
=> $sort_rule->{'description'},
295 sort_routine
=> $sort_rule->{'sort_routine'}
298 $template->param(class_sort_rules
=> \
@sort_rules);