3 # Copyright 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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);
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 AddClassSource
($source_code, $description, $used, $sort_rule);
122 $template->param(added_source
=> $source_code);
125 sub edit_class_source_form
{
126 my ($template, $source_code) = @_;
128 my $source = GetClassSource
($source_code);
130 class_source_form
=> 1,
131 edit_class_source
=> 1,
132 class_source
=> $source_code,
133 confirm_op
=> "edit_source_confirmed",
134 description
=> $source->{'description'},
135 used
=> $source->{'used'},
138 get_sort_rule_codes
($template, $source->{'class_sort_rule'});
141 sub edit_class_source
{
142 my ($template, $source_code, $description, $used, $sort_rule) = @_;
143 ModClassSource
($source_code, $description, $used, $sort_rule);
144 $template->param(edited_source
=> $source_code);
148 sub delete_class_source_form
{
151 delete_class_source_form
=> 1,
152 confirm_op
=> "delete_source_confirmed",
153 class_source
=> $source_code,
157 sub delete_class_source
{
158 my ($template, $source_code) = @_;
159 DelClassSource
($source_code);
160 $template->param(deleted_source
=> $source_code);
163 sub get_sort_rule_codes
{
164 my ($template, $current_rule) = @_;
166 my $sort_rules = GetClassSortRules
();
169 foreach my $sort_rule (sort keys %$sort_rules) {
170 my $sort_rule = $sort_rules->{$sort_rule};
172 rule
=> $sort_rule->{'class_sort_rule'},
173 description
=> $sort_rule->{'description'},
174 selected
=> $sort_rule->{'class_sort_rule'} eq $current_rule ?
1 : 0
177 $template->param(rules_dropdown
=> \
@sort_rules);
181 sub add_class_sort_rule_form
{
185 confirm_op
=> "add_sort_rule_confirmed"
187 get_class_sort_routines
($template, "");
190 sub add_class_sort_rule
{
191 my ($template, $rule_code, $description, $sort_routine) = @_;
192 AddClassSortRule
($rule_code, $description, $sort_routine);
193 $template->param(added_rule
=> $rule_code);
196 sub delete_sort_rule_form
{
197 my ($template, $rule_code) = @_;
199 my @sources = GetSourcesForSortRule
($rule_code);
200 if ($#sources == -1) {
202 delete_sort_rule_form
=> 1,
203 confirm_op
=> "delete_sort_rule_confirmed",
204 sort_rule
=> $rule_code,
208 delete_sort_rule_impossible
=> 1,
209 sort_rule
=> $rule_code
214 sub delete_sort_rule
{
215 my ($template, $rule_code) = @_;
216 DelClassSortRule
($rule_code);
217 $template->param(deleted_rule
=> $rule_code);
220 sub edit_class_sort_rule_form
{
221 my ($template, $rule_code) = @_;
223 my $rule = GetClassSortRule
($rule_code);
227 confirm_op
=> "edit_sort_rule_confirmed",
228 sort_rule
=> $rule_code,
229 description
=> $rule->{'description'},
230 sort_routine
=> $rule->{'sort_routine'}
233 get_class_sort_routines
($template, $rule->{'sort_routine'});
237 sub get_class_sort_routines
{
238 my ($template, $current_routine) = @_;
240 my @sort_routines = GetSortRoutineNames
();
243 foreach my $sort_routine (sort @sort_routines) {
245 routine
=> $sort_routine,
246 selected
=> $sort_routine eq $current_routine ?
1 : 0
249 $template->param(routines_dropdown
=> \
@sort_form);
253 sub edit_class_sort_rule
{
254 my ($template, $rule_code, $description, $sort_routine) = @_;
255 ModClassSortRule
($rule_code, $description, $sort_routine);
256 $template->param(edited_rule
=> $rule_code);
259 sub class_source_list
{
261 my $sources = GetClassSources
();
264 foreach my $cn_source (sort keys %$sources) {
265 my $source = $sources->{$cn_source};
267 code
=> $source->{'cn_source'},
268 description
=> $source->{'description'},
269 used
=> $source->{'used'},
270 sortrule
=> $source->{'class_sort_rule'}
273 $template->param(class_sources
=> \
@sources);
276 sub class_sort_rule_list
{
279 my $sort_rules = GetClassSortRules
();
282 foreach my $sort_rule (sort keys %$sort_rules) {
283 my $sort_rule = $sort_rules->{$sort_rule};
285 rule
=> $sort_rule->{'class_sort_rule'},
286 description
=> $sort_rule->{'description'},
287 sort_routine
=> $sort_rule->{'sort_routine'}
290 $template->param(class_sort_rules
=> \
@sort_rules);