Bug 15062: Holds queue with Transport Cost Matrix will transfer item even if transfer...
[koha.git] / admin / classsources.pl
blob0b7ee31776bb870103762241956053110eb2dcda
1 #! /usr/bin/perl
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>.
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use CGI qw ( -utf8 );
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Koha;
28 use C4::ClassSource;
29 use C4::ClassSortRoutine;
31 my $script_name = "/cgi-bin/koha/admin/classsources.pl";
33 my $input = new CGI;
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",
40 query => $input,
41 type => "intranet",
42 authnotrequired => 0,
43 flagsrequired => {parameters => 'parameters_remaining_permissions'},
44 debug => 1,
45 });
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,
55 $source_code,
56 $input->param('description'),
57 $input->param('used') eq "used" ? 1 : 0,
58 $rule_code);
59 $display_lists = 1;
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);
64 $display_lists = 1;
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,
69 $source_code,
70 $input->param('description'),
71 $input->param('used') eq "used" ? 1 : 0,
72 $rule_code);
73 $display_lists = 1;
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,
78 $rule_code,
79 $input->param('description'),
80 $input->param('sort_routine'));
81 $display_lists = 1;
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);
86 $display_lists = 1;
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,
91 $rule_code,
92 $input->param('description'),
93 $input->param('sort_routine'));
94 $display_lists = 1;
95 } else {
96 $display_lists = 1;
99 if ($display_lists) {
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;
107 exit 0;
109 sub add_class_source_form {
110 my ($template) = @_;
111 $template->param(
112 class_source_form => 1,
113 confirm_op => "add_source_confirmed",
114 used => 0
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);
129 $template->param(
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 {
149 my ($template) = @_;
150 $template->param(
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();
168 my @sort_rules = ();
169 foreach my $sort_rule (sort keys %$sort_rules) {
170 my $sort_rule = $sort_rules->{$sort_rule};
171 push @sort_rules, {
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 {
182 my ($template) = @_;
183 $template->param(
184 sort_rule_form => 1,
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) {
201 $template->param(
202 delete_sort_rule_form => 1,
203 confirm_op => "delete_sort_rule_confirmed",
204 sort_rule => $rule_code,
206 } else {
207 $template->param(
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);
224 $template->param(
225 sort_rule_form => 1,
226 edit_sort_rule => 1,
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();
241 my @sort_form = ();
243 foreach my $sort_routine (sort @sort_routines) {
244 push @sort_form, {
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 {
260 my ($template) = @_;
261 my $sources = GetClassSources();
263 my @sources = ();
264 foreach my $cn_source (sort keys %$sources) {
265 my $source = $sources->{$cn_source};
266 push @sources, {
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 {
278 my ($template) = @_;
279 my $sort_rules = GetClassSortRules();
281 my @sort_rules = ();
282 foreach my $sort_rule (sort keys %$sort_rules) {
283 my $sort_rule = $sort_rules->{$sort_rule};
284 push @sort_rules, {
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);