3 # Copyright 2007 LibLime
4 # Copyright 2018 Koha Development Team
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use C4
::ClassSortRoutine
;
29 use C4
::ClassSplitRoutine
;
30 use Koha
::ClassSources
;
31 use Koha
::ClassSortRules
;
32 use Koha
::ClassSplitRules
;
34 my $script_name = "/cgi-bin/koha/admin/classsources.pl";
37 my $op = $input->param('op') || 'list';
38 my $cn_source = $input->param('cn_source');
39 my $class_sort_rule = $input->param('class_sort_rule');
40 my $class_split_rule = $input->param('class_split_rule');
41 my $sort_routine = $input->param('sort_routine');
42 my $split_routine = $input->param('split_routine');
43 my @split_regex = $input->multi_param('split_regex');
44 my $description = $input->param('description');
45 my $used = $input->param('used');
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
49 template_name
=> "admin/classsources.tt",
52 flagsrequired
=> { parameters
=> 'manage_classifications' },
58 $template->param( script_name
=> $script_name );
60 if ( $op eq "add_source" ) {
62 $cn_source ? Koha
::ClassSources
->find($cn_source) : undef;
64 class_source
=> $class_source,
65 sort_rules
=> scalar Koha
::ClassSortRules
->search,
66 split_rules
=> scalar Koha
::ClassSplitRules
->search,
69 elsif ( $op eq "add_source_validate" ) {
70 my $class_source = Koha
::ClassSources
->find($cn_source);
74 description
=> $description,
75 used
=> ( $used eq 'used' ?
1 : 0 ),
76 class_sort_rule
=> $class_sort_rule,
77 class_split_rule
=> $class_split_rule,
80 eval { $class_source->store; };
83 { type
=> 'error', code
=> 'error_on_update_source' };
87 { type
=> 'message', code
=> 'success_on_update_source' };
92 $class_source = Koha
::ClassSource
->new(
94 cn_source
=> $cn_source,
95 description
=> $description,
96 used
=> ( $used eq 'used' ?
1 : 0 ),
97 class_sort_rule
=> $class_sort_rule,
98 class_split_rule
=> $class_split_rule,
101 eval { $class_source->store; };
104 { type
=> 'error', code
=> 'error_on_insert_source' };
108 { type
=> 'message', code
=> 'success_on_insert_source' };
114 elsif ( $op eq "delete_source_confirmed" ) {
115 my $class_source = Koha
::ClassSources
->find($cn_source);
116 my $deleted = eval { $class_source->delete };
117 if ( $@
or not $deleted ) {
118 push @messages, { type
=> 'error', code
=> 'error_on_delete_source' };
122 { type
=> 'message', code
=> 'success_on_delete_source' };
127 elsif ( $op eq "add_sort_rule" ) {
129 $class_sort_rule ? Koha
::ClassSortRules
->find($class_sort_rule) : undef;
131 sort_rule
=> $sort_rule,
132 sort_routines
=> get_class_sort_routines
(),
135 elsif ( $op eq "add_sort_rule_validate" ) {
136 my $sort_rule = Koha
::ClassSortRules
->find($class_sort_rule);
139 { description
=> $description, sort_routine
=> $sort_routine } );
140 eval { $sort_rule->store; };
143 { type
=> 'error', code
=> 'error_on_update_sort_rule' };
147 { type
=> 'message', code
=> 'success_on_update_sort_rule' };
152 $sort_rule = Koha
::ClassSortRule
->new(
154 class_sort_rule
=> $class_sort_rule,
155 description
=> $description,
156 sort_routine
=> $sort_routine,
159 eval { $sort_rule->store; };
162 { type
=> 'error', code
=> 'error_on_insert_sort_rule' };
166 { type
=> 'message', code
=> 'success_on_insert_sort_rule' };
171 elsif ( $op eq "delete_sort_rule" ) {
172 my $sort_rule = Koha
::ClassSortRules
->find($class_sort_rule);
173 my $deleted = eval { $sort_rule->delete };
174 if ( $@
or not $deleted ) {
176 { type
=> 'error', code
=> 'error_on_delete_sort_rule' };
180 { type
=> 'message', code
=> 'success_on_delete_sort_rule' };
184 elsif ( $op eq "add_split_rule" ) {
187 ? Koha
::ClassSplitRules
->find($class_split_rule)
190 split_rule
=> $split_rule,
191 split_routines
=> get_class_split_routines
(),
194 elsif ( $op eq "add_split_rule_validate" ) {
195 my $split_rule = Koha
::ClassSplitRules
->find($class_split_rule);
197 @split_regex = grep {!/^$/} @split_regex; # Remove empty
201 description
=> $description,
202 split_routine
=> $split_routine,
206 $split_rule->regexs(\
@split_regex)
207 if $split_routine eq 'RegEx';
212 { type
=> 'error', code
=> 'error_on_update_split_rule' };
216 { type
=> 'message', code
=> 'success_on_update_split_rule' };
221 $split_rule = Koha
::ClassSplitRule
->new(
223 class_split_rule
=> $class_split_rule,
224 description
=> $description,
225 split_routine
=> $split_routine,
226 regexs
=> \
@split_regex,
229 eval { $split_rule->store; };
233 { type
=> 'error', code
=> 'error_on_insert_split_rule' };
237 { type
=> 'message', code
=> 'success_on_insert_split_rule' };
242 elsif ( $op eq "delete_split_rule" ) {
243 my $split_rule = Koha
::ClassSplitRules
->find($class_split_rule);
244 my $deleted = eval { $split_rule->delete };
245 if ( $@
or not $deleted ) {
247 { type
=> 'error', code
=> 'error_on_delete_split_rule' };
251 { type
=> 'message', code
=> 'success_on_delete_split_rule' };
256 if ( $op eq 'list' ) {
257 my $class_sources = Koha
::ClassSources
->search;
258 my $sort_rules = Koha
::ClassSortRules
->search;
259 my $split_rules = Koha
::ClassSplitRules
->search;
261 class_sources
=> $class_sources,
262 sort_rules
=> $sort_rules,
263 split_rules
=> $split_rules,
267 $template->param( op
=> $op, messages
=> \
@messages, );
268 output_html_with_http_headers
$input, $cookie, $template->output;
272 sub get_class_sort_routines
{
273 my @sort_routines = GetSortRoutineNames
();
274 return \
@sort_routines;
277 sub get_class_split_routines
{
278 my @split_routines = GetSplitRoutineNames
();
279 return \
@split_routines;