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",
53 flagsrequired
=> { parameters
=> 'manage_classifications' },
59 $template->param( script_name
=> $script_name );
61 if ( $op eq "add_source" ) {
63 $cn_source ? Koha
::ClassSources
->find($cn_source) : undef;
65 class_source
=> $class_source,
66 sort_rules
=> scalar Koha
::ClassSortRules
->search,
67 split_rules
=> scalar Koha
::ClassSplitRules
->search,
70 elsif ( $op eq "add_source_validate" ) {
71 my $class_source = Koha
::ClassSources
->find($cn_source);
75 description
=> $description,
76 used
=> ( $used eq 'used' ?
1 : 0 ),
77 class_sort_rule
=> $class_sort_rule,
78 class_split_rule
=> $class_split_rule,
81 eval { $class_source->store; };
84 { type
=> 'error', code
=> 'error_on_update_source' };
88 { type
=> 'message', code
=> 'success_on_update_source' };
93 $class_source = Koha
::ClassSource
->new(
95 cn_source
=> $cn_source,
96 description
=> $description,
97 used
=> ( $used eq 'used' ?
1 : 0 ),
98 class_sort_rule
=> $class_sort_rule,
99 class_split_rule
=> $class_split_rule,
102 eval { $class_source->store; };
105 { type
=> 'error', code
=> 'error_on_insert_source' };
109 { type
=> 'message', code
=> 'success_on_insert_source' };
115 elsif ( $op eq "delete_source_confirmed" ) {
116 my $class_source = Koha
::ClassSources
->find($cn_source);
117 my $deleted = eval { $class_source->delete };
118 if ( $@
or not $deleted ) {
119 push @messages, { type
=> 'error', code
=> 'error_on_delete_source' };
123 { type
=> 'message', code
=> 'success_on_delete_source' };
128 elsif ( $op eq "add_sort_rule" ) {
130 $class_sort_rule ? Koha
::ClassSortRules
->find($class_sort_rule) : undef;
132 sort_rule
=> $sort_rule,
133 sort_routines
=> get_class_sort_routines
(),
136 elsif ( $op eq "add_sort_rule_validate" ) {
137 my $sort_rule = Koha
::ClassSortRules
->find($class_sort_rule);
140 { description
=> $description, sort_routine
=> $sort_routine } );
141 eval { $sort_rule->store; };
144 { type
=> 'error', code
=> 'error_on_update_sort_rule' };
148 { type
=> 'message', code
=> 'success_on_update_sort_rule' };
153 $sort_rule = Koha
::ClassSortRule
->new(
155 class_sort_rule
=> $class_sort_rule,
156 description
=> $description,
157 sort_routine
=> $sort_routine,
160 eval { $sort_rule->store; };
163 { type
=> 'error', code
=> 'error_on_insert_sort_rule' };
167 { type
=> 'message', code
=> 'success_on_insert_sort_rule' };
172 elsif ( $op eq "delete_sort_rule" ) {
173 my $sort_rule = Koha
::ClassSortRules
->find($class_sort_rule);
174 my $deleted = eval { $sort_rule->delete };
175 if ( $@
or not $deleted ) {
177 { type
=> 'error', code
=> 'error_on_delete_sort_rule' };
181 { type
=> 'message', code
=> 'success_on_delete_sort_rule' };
185 elsif ( $op eq "add_split_rule" ) {
188 ? Koha
::ClassSplitRules
->find($class_split_rule)
191 split_rule
=> $split_rule,
192 split_routines
=> get_class_split_routines
(),
195 elsif ( $op eq "add_split_rule_validate" ) {
196 my $split_rule = Koha
::ClassSplitRules
->find($class_split_rule);
198 @split_regex = grep {!/^$/} @split_regex; # Remove empty
202 description
=> $description,
203 split_routine
=> $split_routine,
207 $split_rule->regexs(\
@split_regex)
208 if $split_routine eq 'RegEx';
213 { type
=> 'error', code
=> 'error_on_update_split_rule' };
217 { type
=> 'message', code
=> 'success_on_update_split_rule' };
222 $split_rule = Koha
::ClassSplitRule
->new(
224 class_split_rule
=> $class_split_rule,
225 description
=> $description,
226 split_routine
=> $split_routine,
227 regexs
=> \
@split_regex,
230 eval { $split_rule->store; };
234 { type
=> 'error', code
=> 'error_on_insert_split_rule' };
238 { type
=> 'message', code
=> 'success_on_insert_split_rule' };
243 elsif ( $op eq "delete_split_rule" ) {
244 my $split_rule = Koha
::ClassSplitRules
->find($class_split_rule);
245 my $deleted = eval { $split_rule->delete };
246 if ( $@
or not $deleted ) {
248 { type
=> 'error', code
=> 'error_on_delete_split_rule' };
252 { type
=> 'message', code
=> 'success_on_delete_split_rule' };
257 if ( $op eq 'list' ) {
258 my $class_sources = Koha
::ClassSources
->search;
259 my $sort_rules = Koha
::ClassSortRules
->search;
260 my $split_rules = Koha
::ClassSplitRules
->search;
262 class_sources
=> $class_sources,
263 sort_rules
=> $sort_rules,
264 split_rules
=> $split_rules,
268 $template->param( op
=> $op, messages
=> \
@messages, );
269 output_html_with_http_headers
$input, $cookie, $template->output;
273 sub get_class_sort_routines
{
274 my @sort_routines = GetSortRoutineNames
();
275 return \
@sort_routines;
278 sub get_class_split_routines
{
279 my @split_routines = GetSplitRoutineNames
();
280 return \
@split_routines;