Bug 14919: Add Koha::Patron->old_holds subroutine
[koha.git] / admin / classsources.pl
blob539095f457d958ff54e9861eee3d6d34d5e724de
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');
37 my $sort_routine = $input->param('sort_routine');
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;
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,
56 $source_code,
57 $description,
58 $used eq "used" ? 1 : 0,
59 $rule_code);
60 $display_lists = 1;
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);
65 $display_lists = 1;
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,
70 $source_code,
71 $description,
72 $used eq "used" ? 1 : 0,
73 $rule_code);
74 $display_lists = 1;
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,
79 $rule_code,
80 $description,
81 $sort_routine);
82 $display_lists = 1;
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);
87 $display_lists = 1;
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,
92 $rule_code,
93 $description,
94 $sort_routine);
95 $display_lists = 1;
96 } else {
97 $display_lists = 1;
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;
108 exit 0;
110 sub add_class_source_form {
111 my ($template) = @_;
112 $template->param(
113 class_source_form => 1,
114 confirm_op => "add_source_confirmed",
115 used => 0
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);
123 if ($success > 0) {
124 $template->param(added_source => $source_code);
125 } else {
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);
134 $template->param(
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) = @_;
155 $template->param(
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();
173 my @sort_rules = ();
174 foreach my $sort_rule (sort keys %$sort_rules) {
175 my $sort_rule = $sort_rules->{$sort_rule};
176 push @sort_rules, {
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 {
187 my ($template) = @_;
188 $template->param(
189 sort_rule_form => 1,
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);
198 if ($success > 0) {
199 $template->param(added_rule => $rule_code);
200 } else {
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) {
210 $template->param(
211 delete_sort_rule_form => 1,
212 confirm_op => "delete_sort_rule_confirmed",
213 sort_rule => $rule_code,
215 } else {
216 $template->param(
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);
233 $template->param(
234 sort_rule_form => 1,
235 edit_sort_rule => 1,
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();
250 my @sort_form = ();
252 foreach my $sort_routine (sort @sort_routines) {
253 push @sort_form, {
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 {
269 my ($template) = @_;
270 my $sources = GetClassSources();
272 my @sources = ();
273 foreach my $cn_source (sort keys %$sources) {
274 my $source = $sources->{$cn_source};
275 push @sources, {
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 {
287 my ($template) = @_;
288 my $sort_rules = GetClassSortRules();
290 my @sort_rules = ();
291 foreach my $sort_rule (sort keys %$sort_rules) {
292 my $sort_rule = $sort_rules->{$sort_rule};
293 push @sort_rules, {
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);