View | Details | Raw Unified | Return to bug 15836
Collapse All | Expand All

(-)a/admin/classsources.pl (-230 / +214 lines)
Lines 1-6 Link Here
1
#! /usr/bin/perl
1
#! /usr/bin/perl
2
#
2
#
3
# Copyright 2007 LibLime
3
# Copyright 2007 LibLime
4
# Copyright 2018 Koha Development Team
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 26-299 use C4::Output; Link Here
26
use C4::Koha;
27
use C4::Koha;
27
use C4::ClassSource;
28
use C4::ClassSource;
28
use C4::ClassSortRoutine;
29
use C4::ClassSortRoutine;
30
use Koha::ClassSources;
31
use Koha::ClassSortRules;
32
use Koha::ClassSplitRules;
29
33
30
my $script_name = "/cgi-bin/koha/admin/classsources.pl";
34
my $script_name = "/cgi-bin/koha/admin/classsources.pl";
31
35
32
my $input = new CGI;
36
my $input            = new CGI;
33
my $op          = $input->param('op') || '';
37
my $op               = $input->param('op') || 'list';
34
my $source_code = $input->param('class_source');
38
my $cn_source        = $input->param('cn_source');
35
my $rule_code   = $input->param('sort_rule');
39
my $class_sort_rule  = $input->param('class_sort_rule');
36
my $sort_routine = $input->param('sort_routine');
40
my $class_split_rule = $input->param('class_split_rule');
37
my ($template, $loggedinuser, $cookie)
41
my $sort_routine     = $input->param('sort_routine');
38
    = get_template_and_user({template_name => "admin/classsources.tt",
42
my $split_routine    = $input->param('split_routine');
39
                 query => $input,
43
my $split_regex      = $input->param('split_regex');
40
                 type => "intranet",
44
my $description      = $input->param('description');
41
                 authnotrequired => 0,
45
my $used             = $input->param('used');
42
                 flagsrequired => {parameters => 'manage_classifications'},
46
43
                 debug => 1,
47
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44
                 });
48
    {
45
49
        template_name   => "admin/classsources.tt",
46
$template->param(script_name => $script_name);
50
        query           => $input,
47
$template->param($op => 1) if $op;
51
        type            => "intranet",
48
my $description = $input->param('description');
52
        authnotrequired => 0,
49
my $used = $input->param('used');
53
        flagsrequired   => { parameters => 'manage_classifications' },
50
my $display_lists = 0;
54
        debug           => 1,
51
if ($op eq "add_source") {
55
    }
52
    add_class_source_form($template);
56
);
53
} elsif ($op eq "add_source_confirmed") {
54
    add_class_source($template,
55
                     $source_code,
56
                     $description,
57
                     $used eq "used" ? 1 : 0,
58
                     $rule_code);
59
    $display_lists = 1;
60
} elsif ($op eq "delete_source") {
61
    delete_class_source_form($template, $source_code);
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
                     $description,
71
                     $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
                        $description,
80
                        $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
                         $description,
93
                         $sort_routine);
94
    $display_lists = 1;
95
} else {
96
    $display_lists = 1;
97
}
98
99
if ($display_lists) {
100
    $template->param(display_lists => 1);
101
    class_source_list($template);
102
    class_sort_rule_list($template);
103
}
104
105
output_html_with_http_headers $input, $cookie, $template->output;
106
57
107
exit 0;
58
my @messages;
59
$template->param( script_name => $script_name );
108
60
109
sub add_class_source_form {
61
if ( $op eq "add_source" ) {
110
    my ($template) = @_;
62
    my $class_source =
63
      $cn_source ? Koha::ClassSources->find($cn_source) : undef;
111
    $template->param(
64
    $template->param(
112
        class_source_form => 1,
65
        class_source => $class_source,
113
        confirm_op => "add_source_confirmed",
66
        sort_rules   => scalar Koha::ClassSortRules->search,
114
        used => 0
67
        split_rules  => scalar Koha::ClassSplitRules->search,
115
    );
68
    );
116
    get_sort_rule_codes($template, '');
117
}
69
}
70
elsif ( $op eq "add_source_validate" ) {
71
    my $class_source = Koha::ClassSources->find($cn_source);
72
    if ($class_source) {
73
        $class_source->set(
74
            {
75
                description      => $description,
76
                used             => ( $used eq 'used' ? 1 : 0 ),
77
                class_sort_rule  => $class_sort_rule,
78
                class_split_rule => $class_split_rule,
79
            }
80
        );
81
        eval { $class_source->store; };
82
        if ($@) {
83
            push @messages,
84
              { type => 'error', code => 'error_on_update_source' };
85
        }
86
        else {
87
            push @messages,
88
              { type => 'message', code => 'success_on_update_source' };
89
        }
118
90
119
sub add_class_source {
120
    my ($template, $source_code, $description, $used, $sort_rule) = @_;
121
    my $success = AddClassSource($source_code, $description, $used, $sort_rule);
122
    if ($success > 0) {
123
        $template->param(added_source => $source_code);
124
    } else {
125
        $template->param(failed_add_source => $source_code);
126
    }
91
    }
127
}
92
    else {
128
93
        $class_source = Koha::ClassSource->new(
129
sub edit_class_source_form {
94
            {
130
    my ($template, $source_code) = @_;
95
                cn_source        => $cn_source,
131
96
                description      => $description,
132
    my $source = GetClassSource($source_code);
97
                used             => ( $used eq 'used' ? 1 : 0 ),
133
    $template->param(
98
                class_sort_rule  => $class_sort_rule,
134
        class_source_form => 1,
99
                class_split_rule => $class_split_rule,
135
        edit_class_source => 1,
100
            }
136
        class_source => $source_code,
101
        );
137
        confirm_op => "edit_source_confirmed",
102
        eval { $class_source->store; };
138
        description => $source->{'description'},
103
        if ($@) {
139
        used => $source->{'used'},
104
            push @messages,
140
    );
105
              { type => 'error', code => 'error_on_insert_source' };
106
        }
107
        else {
108
            push @messages,
109
              { type => 'message', code => 'success_on_insert_source' };
110
        }
111
    }
141
112
142
    get_sort_rule_codes($template, $source->{'class_sort_rule'});
113
    $op = 'list';
143
}
114
}
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' };
120
    }
121
    else {
122
        push @messages,
123
          { type => 'message', code => 'success_on_delete_source' };
124
    }
144
125
145
sub edit_class_source {
126
    $op = 'list';
146
    my ($template, $source_code, $description, $used, $sort_rule) = @_;
147
    ModClassSource($source_code, $description, $used, $sort_rule);
148
    $template->param(edited_source => $source_code);
149
}
127
}
150
128
elsif ( $op eq "add_sort_rule" ) {
151
129
    my $sort_rule =
152
sub delete_class_source_form {
130
      $class_sort_rule ? Koha::ClassSortRules->find($class_sort_rule) : undef;
153
    my ($template, $source_code) = @_;
154
    $template->param(
131
    $template->param(
155
        delete_class_source_form => 1,
132
        sort_rule     => $sort_rule,
156
        confirm_op   => "delete_source_confirmed",
133
        sort_routines => get_class_sort_routines(),
157
        class_source => $source_code,
158
    );
134
    );
159
}
135
}
136
elsif ( $op eq "add_sort_rule_validate" ) {
137
    my $sort_rule = Koha::ClassSortRules->find($class_sort_rule);
138
    if ($sort_rule) {
139
        $sort_rule->set(
140
            { description => $description, sort_routine => $sort_routine } );
141
        eval { $sort_rule->store; };
142
        if ($@) {
143
            push @messages,
144
              { type => 'error', code => 'error_on_update_sort_rule' };
145
        }
146
        else {
147
            push @messages,
148
              { type => 'message', code => 'success_on_update_sort_rule' };
149
        }
160
150
161
sub delete_class_source { 
151
    }
162
    my ($template, $source_code) = @_;
152
    else {
163
    DelClassSource($source_code);
153
        $sort_rule = Koha::ClassSortRule->new(
164
    $template->param(deleted_source => $source_code);
154
            {
155
                class_sort_rule => $class_sort_rule,
156
                description     => $description,
157
                sort_routine    => $sort_routine,
158
            }
159
        );
160
        eval { $sort_rule->store; };
161
        if ($@) {
162
            push @messages,
163
              { type => 'error', code => 'error_on_insert_sort_rule' };
164
        }
165
        else {
166
            push @messages,
167
              { type => 'message', code => 'success_on_insert_sort_rule' };
168
        }
169
    }
170
    $op = 'list';
165
}
171
}
166
172
elsif ( $op eq "delete_sort_rule" ) {
167
sub get_sort_rule_codes {
173
    my $sort_rule = Koha::ClassSortRules->find($class_sort_rule);
168
    my ($template, $current_rule) = @_;
174
    my $deleted = eval { $sort_rule->delete };
169
175
    if ( $@ or not $deleted ) {
170
    my $sort_rules = GetClassSortRules();
176
        push @messages,
171
177
          { type => 'error', code => 'error_on_delete_sort_rule' };
172
    my @sort_rules = ();
178
    }
173
    foreach my $sort_rule (sort keys %$sort_rules) {
179
    else {
174
        my $sort_rule = $sort_rules->{$sort_rule};
180
        push @messages,
175
        push @sort_rules, {
181
          { type => 'message', code => 'success_on_delete_sort_rule' };
176
            rule        => $sort_rule->{'class_sort_rule'},
177
            description => $sort_rule->{'description'},
178
            selected    => $sort_rule->{'class_sort_rule'} eq $current_rule ? 1 : 0
179
        };
180
    }
182
    }
181
    $template->param(rules_dropdown => \@sort_rules);
183
    $op = 'list';
182
 
183
}
184
}
184
185
elsif ( $op eq "add_split_rule" ) {
185
sub add_class_sort_rule_form {
186
    my $split_rule =
186
    my ($template) = @_;
187
      $class_split_rule
188
      ? Koha::ClassSplitRules->find($class_split_rule)
189
      : undef;
187
    $template->param(
190
    $template->param(
188
        sort_rule_form => 1,
191
        split_rule     => $split_rule,
189
        confirm_op => "add_sort_rule_confirmed"
192
        split_routines => get_class_split_routines(),
190
    );
193
    );
191
    get_class_sort_routines($template, "");
192
}
194
}
195
elsif ( $op eq "add_split_rule_validate" ) {
196
    my $split_rule = Koha::ClassSplitRules->find($class_split_rule);
197
    if ($split_rule) {
198
        $split_rule->set(
199
            {
200
                description   => $description,
201
                split_routine => $split_routine,
202
                split_regex =>
203
                  ( $split_routine eq 'RegEx' ? $split_regex : '' ),
204
            }
205
        );
206
        eval { $split_rule->store; };
207
        if ($@) {
208
            push @messages,
209
              { type => 'error', code => 'error_on_update_split_rule' };
210
        }
211
        else {
212
            push @messages,
213
              { type => 'message', code => 'success_on_update_split_rule' };
214
        }
193
215
194
sub add_class_sort_rule {
195
    my ($template, $rule_code, $description, $sort_routine) = @_;
196
    my $success = AddClassSortRule($rule_code, $description, $sort_routine);
197
    if ($success > 0) {
198
        $template->param(added_rule => $rule_code);
199
    } else {
200
        $template->param(failed_add_rule => $rule_code);
201
    }
216
    }
202
}
217
    else {
203
218
        $split_rule = Koha::ClassSplitRule->new(
204
sub delete_sort_rule_form {
219
            {
205
    my ($template, $rule_code) = @_;
220
                class_split_rule => $class_split_rule,
206
221
                description      => $description,
207
    my @sources = GetSourcesForSortRule($rule_code);
222
                split_routine    => $split_routine,
208
    if ($#sources == -1) {
223
                split_regex =>
209
        $template->param(
224
                  ( $split_routine eq 'RegEx' ? $split_regex : '' ),
210
            delete_sort_rule_form => 1,
225
            }
211
            confirm_op => "delete_sort_rule_confirmed",
212
            sort_rule  => $rule_code,
213
        );
214
    } else {
215
        $template->param(
216
            delete_sort_rule_impossible => 1,
217
            sort_rule => $rule_code
218
        );
226
        );
227
        eval { $split_rule->store; };
228
        if ($@) {
229
            warn $@;
230
            push @messages,
231
              { type => 'error', code => 'error_on_insert_split_rule' };
232
        }
233
        else {
234
            push @messages,
235
              { type => 'message', code => 'success_on_insert_split_rule' };
236
        }
219
    }
237
    }
238
    $op = 'list';
220
}
239
}
221
240
elsif ( $op eq "delete_split_rule" ) {
222
sub delete_sort_rule { 
241
    my $split_rule = Koha::ClassSplitRules->find($class_split_rule);
223
    my ($template, $rule_code) = @_;
242
    my $deleted = eval { $split_rule->delete };
224
    DelClassSortRule($rule_code);
243
    if ( $@ or not $deleted ) {
225
    $template->param(deleted_rule => $rule_code);
244
        push @messages,
245
          { type => 'error', code => 'error_on_delete_split_rule' };
246
    }
247
    else {
248
        push @messages,
249
          { type => 'message', code => 'success_on_delete_split_rule' };
250
    }
251
    $op = 'list';
226
}
252
}
227
253
228
sub edit_class_sort_rule_form {
254
if ( $op eq 'list' ) {
229
    my ($template, $rule_code) = @_;
255
    my $class_sources = Koha::ClassSources->search;
230
256
    my $sort_rules    = Koha::ClassSortRules->search;
231
    my $rule = GetClassSortRule($rule_code);
257
    my $split_rules   = Koha::ClassSplitRules->search;
232
    $template->param(
258
    $template->param(
233
        sort_rule_form => 1,
259
        class_sources => $class_sources,
234
        edit_sort_rule => 1,
260
        sort_rules    => $sort_rules,
235
        confirm_op   => "edit_sort_rule_confirmed",
261
        split_rules   => $split_rules,
236
        sort_rule    => $rule_code,
237
        description  => $rule->{'description'},
238
        sort_routine => $rule->{'sort_routine'}
239
    );
262
    );
263
}
240
264
241
    get_class_sort_routines($template, $rule->{'sort_routine'});
265
$template->param( op => $op, messages => \@messages, );
266
output_html_with_http_headers $input, $cookie, $template->output;
242
267
243
}
268
exit 0;
244
269
245
sub get_class_sort_routines {
270
sub get_class_sort_routines {
246
    my ($template, $current_routine) = @_;
247
248
    my @sort_routines = GetSortRoutineNames();
271
    my @sort_routines = GetSortRoutineNames();
249
    my @sort_form = ();
272
    return \@sort_routines;
250
251
    foreach my $sort_routine (sort @sort_routines) {    
252
        push @sort_form, {
253
            routine  => $sort_routine,
254
            selected => $sort_routine eq $current_routine ? 1 : 0
255
        };
256
    }
257
    $template->param(routines_dropdown => \@sort_form);
258
259
}
273
}
260
274
261
sub edit_class_sort_rule {
275
sub get_class_split_routines {
262
    my ($template, $rule_code, $description, $sort_routine) = @_;
276
    my @split_routines = qw(
263
    ModClassSortRule($rule_code, $description, $sort_routine);
277
      Dewey
264
    $template->param(edited_rule => $rule_code);
278
      Generic
265
} 
279
      LCC
266
280
      RegEx
267
sub class_source_list {
281
    );
268
    my ($template) = @_;
282
    return \@split_routines;
269
    my $sources = GetClassSources();
270
271
    my @sources = ();
272
    foreach my $cn_source (sort keys %$sources) {
273
        my $source = $sources->{$cn_source};
274
        push @sources, {
275
            code        => $source->{'cn_source'},
276
            description => $source->{'description'},
277
            used        => $source->{'used'},
278
            sortrule    => $source->{'class_sort_rule'}
279
        };
280
    }
281
    $template->param(class_sources => \@sources);
282
}
283
284
sub class_sort_rule_list {
285
286
    my ($template) = @_;
287
    my $sort_rules = GetClassSortRules();
288
289
    my @sort_rules = ();
290
    foreach my $sort_rule (sort keys %$sort_rules) {
291
        my $sort_rule = $sort_rules->{$sort_rule};
292
        push @sort_rules, {
293
            rule        => $sort_rule->{'class_sort_rule'},
294
            description => $sort_rule->{'description'},
295
            sort_routine    => $sort_rule->{'sort_routine'}
296
        }; 
297
    }
298
    $template->param(class_sort_rules => \@sort_rules);
299
}
283
}
(-)a/installer/data/mysql/atomicupdate/bug_15836.perl (-1 / +1 lines)
Lines 25-31 if( CheckVersion( $DBversion ) ) { Link Here
25
        $dbh->do(q|
25
        $dbh->do(q|
26
            INSERT INTO class_split_rules(class_split_rule, description, split_routine)
26
            INSERT INTO class_split_rules(class_split_rule, description, split_routine)
27
            VALUES
27
            VALUES
28
            ('dewey', 'Default sorting rules for DDC', 'dewey'),
28
            ('dewey', 'Default sorting rules for DDC', 'Dewey'),
29
            ('lcc', 'Default sorting rules for LCC', 'LCC'),
29
            ('lcc', 'Default sorting rules for LCC', 'LCC'),
30
            ('generic', 'Generic call number sorting rules', 'Generic')
30
            ('generic', 'Generic call number sorting rules', 'Generic')
31
        |);
31
        |);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/classsources.tt (-132 / +224 lines)
Lines 3-23 Link Here
3
[% SET footerjs = 1 %]
3
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Administration &rsaquo; Classification sources
5
<title>Koha &rsaquo; Administration &rsaquo; Classification sources
6
[% IF ( class_source_form ) %]
6
[% IF op == 'add_source' %]
7
&rsaquo; 
8
    [% IF ( edit_class_source ) %]Modify classification source[% ELSE %]Add classification source[% END %]
9
[% END %]
10
[% IF ( sort_rule_form ) %]
11
&rsaquo;
7
&rsaquo;
12
    [% IF ( edit_sort_rule ) %]Modify filing rule[% ELSE %]Add filing rule[% END %]
8
    [% IF class_source %]Modify classification source[% ELSE %]Add classification source[% END %]
13
[% END %]
9
[% ELSIF op == 'add_sort_rule' %]
14
[% IF ( delete_class_source_form ) %]
10
&rsaquo;
15
  &rsaquo; Confirm deletion of classification source [% class_source | html %]
11
    [% IF sort_rule %]Modify filing rule[% ELSE %]Add filing rule[% END %]
16
[% ELSIF ( delete_sort_rule_form ) %]
12
[% ELSIF op == 'add_split_rule' %]
17
  &rsaquo; Confirm deletion of filing rule [% sort_rule | html %]
13
&rsaquo;
18
[% ELSIF ( delete_sort_rule_impossible ) %]
14
    [% IF split_rule %]Modify splitting rule[% ELSE %]Add splitting rule[% END %]
19
  &rsaquo; Cannot delete filing rule [% sort_rule | html %]
20
[% END %]
15
[% END %]
16
21
</title>
17
</title>
22
[% INCLUDE 'doc-head-close.inc' %]
18
[% INCLUDE 'doc-head-close.inc' %]
23
</head>
19
</head>
Lines 30-47 Link Here
30
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
26
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
31
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
27
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
32
&rsaquo; <a href="/cgi-bin/koha/admin/classsources.pl">Classification sources</a>
28
&rsaquo; <a href="/cgi-bin/koha/admin/classsources.pl">Classification sources</a>
33
[% IF ( class_source_form ) %]
29
[% IF op == 'add_source' %]
34
&rsaquo; [% IF ( edit_class_source ) %]Modify classification source[% ELSE %]Add classification source[% END %]
30
&rsaquo; [% IF class_source %]Modify classification source[% ELSE %]Add classification source[% END %]
35
[% END %]
31
[% ELSIF op == 'add_sort_rule' %]
36
[% IF ( sort_rule_form ) %]
32
&rsaquo; [% IF sort_rule %]Modify filing rule[% ELSE %]Add filing rule[% END %]
37
&rsaquo; [% IF ( edit_sort_rule ) %]Modify filing rule[% ELSE %]Add filing rule[% END %]
33
[% ELSIF op == 'add_split_rule' %]
38
[% END %]
34
&rsaquo; [% IF split_rule %]Modify splitting rule[% ELSE %]Add splitting rule[% END %]
39
[% IF ( delete_class_source_form ) %]
40
&rsaquo; Confirm deletion of classification source <span class="ex">'[% class_source | html %]'</span>
41
[% ELSIF ( delete_sort_rule_form ) %]
42
&rsaquo; Confirm deletion of filing rule <span class="ex">'[% sort_rule | html %]'</span>
43
[% ELSIF ( delete_sort_rule_impossible ) %]
44
&rsaquo; Cannot delete filing rule <span class="ex">'[% sort_rule | html %]'</span>
45
[% END %]
35
[% END %]
46
</div>
36
</div>
47
37
Lines 50-96 Link Here
50
        <div class="col-sm-10 col-sm-push-2">
40
        <div class="col-sm-10 col-sm-push-2">
51
            <main>
41
            <main>
52
42
53
[% IF ( class_source_form ) %]
43
[% FOR m IN messages %]
54
  [% IF ( edit_class_source ) %]
44
    <div class="dialog [% m.type %]">
45
        [% SWITCH m.code %]
46
        [% CASE 'error_on_update_source' %]
47
            An error occurred when updating this classification source.
48
        [% CASE 'success_on_update_source' %]
49
            Classification source updated successfully.
50
        [% CASE 'error_on_insert_source' %]
51
            An error occurred when adding this classification source. Perhaps the code already exists?
52
        [% CASE 'success_on_insert_source' %]
53
            Classification source added successfully.
54
        [% CASE 'error_on_delete_source' %]
55
            An error occurred when deleting this classification source.
56
        [% CASE 'success_on_delete_source' %]
57
            Classification source deleted successfully.
58
        [% CASE 'error_on_update_sort_rule' %]
59
            An error occurred when adding this filing rule. Perhaps the code already exists?
60
        [% CASE 'success_on_update_sort_rule' %]
61
            Filing rule updated successfully.
62
        [% CASE 'error_on_insert_sort_rule' %]
63
            An error occurred when adding this filing rule. Perhaps the code already exists?
64
        [% CASE 'success_on_insert_sort_rule' %]
65
            Filing rule added successfully.
66
        [% CASE 'error_on_delete_sort_rule' %]
67
            An error occurred when deleting this filing rule. Perhaps it is used by at least one classification source?
68
        [% CASE 'success_on_delete_sort_rule' %]
69
            Filing rule deleted successfully.
70
        [% CASE 'error_on_update_split_rule' %]
71
            An error occurred when adding this splitting rule. Perhaps the code already exists?
72
        [% CASE 'success_on_update_split_rule' %]
73
            Splitting rule updated successfully.
74
        [% CASE 'error_on_insert_split_rule' %]
75
            An error occurred when adding this splitting rule. Perhaps the code already exists?
76
        [% CASE 'success_on_insert_split_rule' %]
77
            Splitting rule added successfully.
78
        [% CASE 'error_on_delete_split_rule' %]
79
            An error occurred when deleting this splitting rule. Perhaps it is used by at least one classification source?
80
        [% CASE 'success_on_delete_split_rule' %]
81
            Splitting rule deleted successfully.
82
        [% CASE %]
83
            [% m.code %]
84
        [% END %]
85
    </div>
86
[% END %]
87
88
89
[% IF op == 'add_source' %]
90
  [% IF class_source %]
55
<h2>Modify classification source</h2>
91
<h2>Modify classification source</h2>
56
  [% ELSE %]
92
  [% ELSE %]
57
<h2>Add classification source</h2>
93
<h2>Add classification source</h2>
58
  [% END %]
94
  [% END %]
59
<form action="[% script_name | html %]" name="Aform" class="validated" method="post">
95
<form action="[% script_name | html %]" name="Aform" class="validated" method="post">
60
  <input type="hidden" name="op" value="[% confirm_op | html %]" />
96
  <input type="hidden" name="op" value="add_source_validate" />
61
  <fieldset class="rows">
97
  <fieldset class="rows">
62
    <ol>
98
    <ol>
63
      <li>
99
      <li>
64
          [% IF ( edit_class_source ) %]
100
          [% IF class_source %]
65
		  <span class="label">Classification source code: </span>
101
		  <span class="label">Classification source code: </span>
66
            <input type="hidden" name="class_source" value="[% class_source | html %]" />
102
            <input type="hidden" name="cn_source" value="[% class_source.cn_source | html %]" />
67
            [% class_source | html %]
103
            [% class_source.cn_source | html %]
68
          [% ELSE %]
104
          [% ELSE %]
69
              <label class="required" for="class_source">Classification source code: </label>
105
              <label class="required" for="class_source">Classification source code: </label>
70
              <input class="required" required="required" type="text" id="class_source" name="class_source"  size="10" maxlength="10" />
106
              <input class="required" required="required" type="text" id="class_source" name="cn_source"  size="10" maxlength="10" />
71
              <span class="required">Required</span>
107
              <span class="required">Required</span>
72
          [% END %]
108
          [% END %]
73
       </li>
109
       </li>
74
       <li><label class="required" for="description">Description: </label>
110
       <li><label class="required" for="description">Description: </label>
75
           <input class="required" required="required" type="text" id="description" name="description" size="50" maxlength="250" value="[% description | html %]" />
111
           <input class="required" required="required" type="text" id="description" name="description" size="50" maxlength="250" value="[% class_source.description | html %]" />
76
           <span class="required">Required</span>
112
           <span class="required">Required</span>
77
       </li>
113
       </li>
78
       <li><label for="used">Source in use?</label>
114
       <li><label for="used">Source in use?</label>
79
           [% IF ( used ) %]<input type="checkbox" id="used" name="used" value="used" checked="checked" />[% ELSE %]
115
           [% IF ( class_source.used ) %]<input type="checkbox" id="used" name="used" value="used" checked="checked" />[% ELSE %]
80
		  <input type="checkbox" id="used" name="used" value="used" />[% END %]
116
		  <input type="checkbox" id="used" name="used" value="used" />[% END %]
81
       </li>
117
       </li>
82
       <li><label class="required" for="sort_rule">Filing rule: </label>
118
        <li>
83
           <select class="required" required="required" id="sort_rule" name="sort_rule">
119
            <label class="required" for="class_sort_rule">Filing rule: </label>
84
           [% FOREACH rules_dropdow IN rules_dropdown %]
120
            <select class="required" required="required" id="class_sort_rule" name="class_sort_rule">
85
             [% IF ( rules_dropdow.selected ) %]
121
                [% FOREACH r IN sort_rules %]
86
             <option value="[% rules_dropdow.rule | html %]" selected="selected">[% rules_dropdow.description | html %] ([% rules_dropdow.rule | html %])</option>
122
                    [% IF class_source.class_sort_rule == r.class_sort_rule %]
87
             [% ELSE %]
123
                        <option value="[% r.class_sort_rule | html %]" selected="selected">[% r.description | html %] ([% r.class_sort_rule | html %])</option>
88
             <option value="[% rules_dropdow.rule | html %]">[% rules_dropdow.description | html %] ([% rules_dropdow.rule | html %])</option>
124
                    [% ELSE %]
89
             [% END %]
125
                        <option value="[% r.class_sort_rule | html %]">[% r.description | html %] ([% r.class_sort_rule | html %])</option>
90
           [% END %]
126
                    [% END %]
91
           </select>
127
                [% END %]
92
           <span class="required">Required</span>
128
            </select>
93
       </li>    
129
            <span class="required">Required</span>
130
        </li>
131
        <li>
132
            <label class="required" for="class_split_rule">Splitting rule: </label>
133
            <select class="required" required="required" id="split_rule" name="class_split_rule">
134
                [% FOREACH r IN split_rules %]
135
                    [% IF class_source.class_split_rule == r.class_split_rule %]
136
                        <option value="[% r.class_split_rule | html %]" selected="selected">[% r.description | html %] ([% r.class_split_rule | html %])</option>
137
                    [% ELSE %]
138
                        <option value="[% r.class_split_rule | html %]">[% r.description | html %] ([% r.class_split_rule | html %])</option>
139
                    [% END %]
140
                [% END %]
141
            </select>
142
            <span class="required">Required</span>
143
        </li>
94
    </ol>
144
    </ol>
95
  </fieldset>
145
  </fieldset>
96
  <fieldset class="action">
146
  <fieldset class="action">
Lines 100-137 Link Here
100
</form>
150
</form>
101
[% END %]
151
[% END %]
102
152
103
[% IF ( sort_rule_form ) %]
153
[% IF op == 'add_sort_rule' %]
104
  [% IF ( edit_sort_rule ) %]
154
  [% IF sort_rule %]
105
<h2>Modify filing rule</h2>
155
<h2>Modify filing rule</h2>
106
  [% ELSE %]
156
  [% ELSE %]
107
<h2>Add filing rule</h2>
157
<h2>Add filing rule</h2>
108
  [% END %]
158
  [% END %]
109
<form action="[% script_name | html %]" name="Aform" class="validated" method="post">
159
<form action="[% script_name | html %]" name="Aform" class="validated" method="post">
110
  <input type="hidden" name="op" value="[% confirm_op | html %]" />
160
  <input type="hidden" name="op" value="add_sort_rule_validate" />
111
  <fieldset class="rows">
161
  <fieldset class="rows">
112
    <ol>
162
    <ol>
113
      <li>
163
      <li>
114
          [% IF ( edit_sort_rule ) %]
164
          [% IF sort_rule %]
115
		  <span class="label">Filing rule code: </span>
165
		  <span class="label">Filing rule code: </span>
116
            <input type="hidden" name="sort_rule" value="[% sort_rule | html %]" />
166
            <input type="hidden" name="class_sort_rule" value="[% sort_rule.class_sort_rule | html %]" />
117
            [% sort_rule | html %]
167
            [% sort_rule.class_sort_rule | html %]
118
          [% ELSE %]
168
          [% ELSE %]
119
              <label for="sort_rule" class="required">Filing rule code: </label>
169
              <label for="class_sort_rule" class="required">Filing rule code: </label>
120
              <input class="required" required="required" type="text" id="sort_rule" name="sort_rule"  size="10" maxlength="10" />
170
              <input class="required" required="required" type="text" id="class_sort_rule" name="class_sort_rule"  size="10" maxlength="10" />
121
              <span class="required">Required</span>
171
              <span class="required">Required</span>
122
          [% END %]
172
          [% END %]
123
       </li>
173
       </li>
124
       <li><label for="description" class="required">Description: </label>
174
       <li><label for="description" class="required">Description: </label>
125
           <input class="required" required="required" type="text" id="description" name="description" size="50" maxlength="250" value="[% description | html %]" />
175
           <input class="required" required="required" type="text" id="description" name="description" size="50" maxlength="250" value="[% sort_rule.description | html %]" />
126
           <span class="required">Required</span>
176
           <span class="required">Required</span>
127
       </li>
177
       </li>
128
       <li><label for="sort_routine" class="required">Filing routine: </label>
178
       <li><label for="sort_routine" class="required">Filing routine: </label>
129
           <select class="required" required="required" id="sort_routine" name="sort_routine">
179
           <select class="required" required="required" id="sort_routine" name="sort_routine">
130
           [% FOREACH routines_dropdow IN routines_dropdown %]
180
           [% FOREACH routine_name IN sort_routines %]
131
             [% IF ( routines_dropdow.selected ) %]
181
             [% IF routine_name == sort_rule.sort_routine %]
132
             <option value="[% routines_dropdow.routine | html %]" selected="selected">[% routines_dropdow.routine | html %]</option>
182
                 <option value="[% routine_name | html %]" selected="selected">[% routine_name | html %]</option>
133
             [% ELSE %]
183
             [% ELSE %]
134
             <option value="[% routines_dropdow.routine | html %]">[% routines_dropdow.routine | html %]</option>
184
                 <option value="[% routine_name | html %]">[% routine_name %]</option>
135
             [% END %]
185
             [% END %]
136
           [% END %]
186
           [% END %]
137
           </select>
187
           </select>
Lines 146-245 Link Here
146
</form>
196
</form>
147
[% END %]
197
[% END %]
148
198
149
[% IF ( delete_class_source_form ) %]
199
[% IF op == 'add_split_rule' %]
150
    <div class="dialog alert">
200
  [% IF split_rule %]
151
        <h3>Confirm deletion of classification source <span class="ex">'[% class_source | html %]'</span>?</h3>
201
<h2>Modify splitting rule</h2>
152
        <form action="[% script_name | html %]" name="Aform" method="post">
202
  [% ELSE %]
153
            <input type="hidden" name="op" value="[% confirm_op | html %]" />
203
<h2>Add splitting rule</h2>
154
            <input type="hidden" name="class_source" value="[% class_source | html %]" />
204
  [% END %]
155
            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete classification source</button>
205
<form action="[% script_name | html %]" name="Aform" class="validated" method="post">
156
        </form>
206
  <input type="hidden" name="op" value="add_split_rule_validate" />
157
        <form action="[% script_name | html %]" method="get">
207
  <fieldset class="rows">
158
            <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
208
    <ol>
159
        </form>
209
      <li>
160
    </div>
210
          [% IF split_rule %]
161
[% END %]
211
            <span class="label">Splitting rule code: </span>
162
212
            <input type="hidden" name="class_split_rule" value="[% split_rule.class_split_rule | html %]" />
163
[% IF ( delete_sort_rule_form ) %]
213
            [% split_rule.class_split_rule | html %]
164
    <div class="dialog alert">
214
          [% ELSE %]
165
        <h3>Confirm deletion of filing rule <span class="ex">'[% sort_rule | html %]'</span>?</h3>
215
              <label for="class_split_rule" class="required">Splitting rule code: </label>
166
        <form action="[% script_name | html %]" name="Aform" method="post">
216
              <input class="required" required="required" type="text" id="class_split_rule" name="class_split_rule"  size="10" maxlength="10" />
167
            <input type="hidden" name="op" value="[% confirm_op | html %]" />
217
              <span class="required">Required</span>
168
            <input type="hidden" name="sort_rule" value="[% sort_rule | html %]" />
218
          [% END %]
169
            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete filing rule</button>
219
       </li>
170
        </form>
220
       <li><label for="description" class="required">Description: </label>
171
        <form action="[% script_name | html %]" method="get">
221
           <input class="required" required="required" type="text" id="description" name="description" size="50" maxlength="250" value="[% split_rule.description | html %]" />
172
            <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
222
           <span class="required">Required</span>
173
        </form>
223
       </li>
174
    </div>
224
       <li><label for="split_routine" class="required">Splitting routine: </label>
175
[% END %]
225
           <select class="required" required="required" id="split_routine" name="split_routine">
226
            [% FOREACH routine_name IN split_routines %]
227
                [% IF routine_name == split_rule.split_routine %]
228
                    <option value="[% routine_name | html %]" selected="selected">[% routine_name | html %]</option>
229
                [% ELSE %]
230
                    <option value="[% routine_name | html %]">[% routine_name | html %]</option>
231
                [% END %]
232
            [% END %]
233
           </select>
234
           <span class="required">Required</span>
235
       </li>
236
       <li id="regex_block">
237
           <label for="split_regex" class="required">Regular expression: </label>
238
           <input type="text" name="split_regex" id="split_regex" value="[% split_rule.split_regex | html %]" />
239
           <span class="required">Required</span>
240
       </li>
176
241
177
[% IF ( delete_sort_rule_impossible ) %]
242
    </ol>
178
<div class="dialog alert"><h3>Cannot delete filing rule <span class="ex">'[% sort_rule | html %]'</span></h3>
243
  </fieldset>
179
    <p>The filing rule [% sort_rule | html %] is used by at least one classification source.  Please
244
    <fieldset class="action">
180
    remove it from all classification source definitions before trying again.
245
        <input type="submit" value="Save" />
181
    </p>
246
        <a class="cancel" href="/cgi-bin/koha/admin/classsources.pl">Cancel</a>
182
    <form action="[% script_name | html %]" method="get">
247
    </fieldset>
183
          <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
248
</form>
184
    </form>
185
</div>
186
[% END %]
249
[% END %]
187
250
188
[% IF ( display_lists ) %]
251
[% IF op == 'list' %]
189
252
190
<div id="toolbar" class="btn-toolbar">
253
<div id="toolbar" class="btn-toolbar">
191
    <a class="btn btn-default btn-sm" id="newsource" href="[% script_name | url %]?op=add_source"><i class="fa fa-plus"></i> New classification source</a>
254
    <a class="btn btn-default btn-sm" id="newsource" href="[% script_name | url %]?op=add_source"><i class="fa fa-plus"></i> New classification source</a>
192
    <a class="btn btn-default btn-sm" id="newrule" href="[% script_name | url %]?op=add_sort_rule"><i class="fa fa-plus"></i> New filing rule</a>
255
    <a class="btn btn-default btn-sm" id="newrule" href="[% script_name | url %]?op=add_sort_rule"><i class="fa fa-plus"></i> New filing rule</a>
256
    <a class="btn btn-default btn-sm" id="newrule" href="[% script_name | url %]?op=add_split_rule"><i class="fa fa-plus"></i> New splitting rule</a>
193
</div>
257
</div>
194
258
195
<h2>Classification sources</h2>
259
<h2>Classification sources</h2>
196
[% IF ( added_source ) %]
197
<div class="dialog message">Added classification source [% added_source | html %]</div>
198
[% END %]
199
[% IF ( edited_source ) %]
200
<div class="dialog message">Modified classification source [% edited_source | html %]</div>
201
[% END %]
202
[% IF ( deleted_source ) %]
203
<div class="dialog message">Deleted classification source [% deleted_source | html %]</div>
204
[% END %]
205
[% IF ( failed_add_source ) %]
206
<div class="dialog message">Failed to add classification source [% failed_add_source | html %]. Perhaps the code already exists?</div>
207
[% END %]
208
<table>
260
<table>
209
  <tr>
261
  <tr>
210
    <th>Code</th>
262
    <th>Code</th>
211
    <th>Description</th>
263
    <th>Description</th>
212
    <th>In use</th>
264
    <th>In use</th>
213
    <th>Filing rule</th>
265
    <th>Filing rule</th>
266
    <th>Splitting rule</th>
214
    <th>Actions</th>
267
    <th>Actions</th>
215
  </tr>
268
  </tr>
216
  [% FOREACH class_source IN class_sources %]
269
  [% FOREACH class_source IN class_sources %]
217
  <tr>
270
  <tr>
218
    <td>[% class_source.code | html %]</td>
271
    <td>[% class_source.cn_source | html %]</td>
219
    <td>[% class_source.description | html %]</td>
272
    <td>[% class_source.description |html | html %]</td>
220
    <td>[% IF ( class_source.used ) %]Yes[% ELSE %]No[% END %]</td>
273
    <td>[% IF ( class_source.used ) %]Yes[% ELSE %]No[% END %]</td>
221
    <td>[% class_source.sortrule | html %]</td>
274
    <td>[% class_source.class_sort_rule | html %]</td>
275
    <td>[% class_source.class_split_rule | html %]</td>
222
    <td class="actions">
276
    <td class="actions">
223
      <a class="btn btn-default btn-xs" href="[% class_source.script_name | url %]?op=edit_source&amp;class_source=[% class_source.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
277
      <a class="btn btn-default btn-xs" href="[% script_name | url %]?op=add_source&amp;cn_source=[% class_source.cn_source | uri %]"><i class="fa fa-pencil"></i> Edit</a>
224
      <a class="btn btn-default btn-xs" href="[% class_source.script_name | url %]?op=delete_source&amp;class_source=[% class_source.code | uri %]"><i class="fa fa-trash"></i> Delete</a>
278
      <a class="btn btn-default btn-xs delete_class_source" href="[% script_name | url %]?op=delete_source&amp;cn_source=[% class_source.cn_source | uri%]"><i class="fa fa-trash"></i> Delete</a>
225
    </td>
279
    </td>
226
  </tr>
280
  </tr>
227
  [% END %]
281
  [% END %]
228
</table>
282
</table>
229
283
230
<h2>Classification filing rules</h2>
284
<h2>Classification filing rules</h2>
231
[% IF ( added_rule ) %]
232
<div class="dialog message">Added filing rule [% added_rule | html %]</div>
233
[% END %]
234
[% IF ( edited_rule ) %]
235
<div class="dialog message">Modified filing rule [% edited_rule | html %]</div>
236
[% END %]
237
[% IF ( deleted_rule ) %]
238
<div class="dialog message">Deleted filing rule [% deleted_rule | html %]</div>
239
[% END %]
240
[% IF ( failed_add_rule ) %]
241
<div class="dialog message">Failed to add filing rule [% failed_add_rule | html %]. Perhaps the code already exists?</div>
242
[% END %]
243
<table>
285
<table>
244
  <tr>
286
  <tr>
245
    <th>Code</th>
287
    <th>Code</th>
Lines 247-265 Link Here
247
    <th>Sorting routine</th>
289
    <th>Sorting routine</th>
248
    <th>Actions</th>
290
    <th>Actions</th>
249
  </tr>
291
  </tr>
250
  [% FOREACH class_sort_rule IN class_sort_rules %]
292
  [% FOREACH rule IN sort_rules %]
293
  <tr>
294
    <td>[% rule.class_sort_rule | html %]</td>
295
    <td>[% rule.description |html | html %]</td>
296
    <td>[% rule.sort_routine | html %]</td>
297
    <td class="actions">
298
      <a class="btn btn-default btn-xs" href="[% script_name | html %]?op=add_sort_rule&amp;class_sort_rule=[% rule.class_sort_rule |url %]"><i class="fa fa-pencil"></i> Edit</a>
299
      <a class="btn btn-default btn-xs delete_sort_rule" href="[% script_name | html %]?op=delete_sort_rule&amp;class_sort_rule=[% rule.class_sort_rule |url %]"><i class="fa fa-trash"></i> Delete</a>
300
    </td>
301
  </tr>
302
  [% END %]
303
</table>
304
305
<h2>Classification splitting rules</h2>
306
<table>
307
  <tr>
308
    <th>Code</th>
309
    <th>Description</th>
310
    <th>Splitting routine</th>
311
    <th>Actions</th>
312
  </tr>
313
  [% FOREACH rule IN split_rules %]
251
  <tr>
314
  <tr>
252
    <td>[% class_sort_rule.rule | html %]</td>
315
    <td>[% rule.class_split_rule | html %]</td>
253
    <td>[% class_sort_rule.description | html %]</td>
316
    <td>[% rule.description | html %]</td>
254
    <td>[% class_sort_rule.sort_routine | html %]</td>
317
    <td>[% rule.split_routine | html %]</td>
255
    <td class="actions">
318
    <td class="actions">
256
      <a class="btn btn-default btn-xs" href="[% class_sort_rule.script_name | url %]?op=edit_sort_rule&amp;sort_rule=[% class_sort_rule.rule | uri %]"><i class="fa fa-pencil"></i> Edit</a>
319
      <a class="btn btn-default btn-xs" href="[% script_name | url %]?op=add_split_rule&amp;class_split_rule=[% rule.class_split_rule | uri %]"><i class="fa fa-pencil"></i> Edit</a>
257
      <a class="btn btn-default btn-xs" href="[% class_sort_rule.script_name | url %]?op=delete_sort_rule&amp;sort_rule=[% class_sort_rule.rule | uri %]"><i class="fa fa-trash"></i> Delete</a>
320
      <a class="btn btn-default btn-xs delete_split_rule" href="[% script_name | url %]?op=delete_split_rule&amp;class_split_rule=[% rule.class_split_rule | uri %]"><i class="fa fa-trash"></i> Delete</a>
258
    </td>
321
    </td>
259
  </tr>
322
  </tr>
260
  [% END %]
323
  [% END %]
261
</table>
324
</table>
262
325
326
263
[% END %]
327
[% END %]
264
328
265
            </main>
329
            </main>
Lines 274-278 Link Here
274
338
275
[% MACRO jsinclude BLOCK %]
339
[% MACRO jsinclude BLOCK %]
276
    [% Asset.js("js/admin-menu.js") | $raw %]
340
    [% Asset.js("js/admin-menu.js") | $raw %]
341
342
    <script>
343
        function update_regex_block(){
344
            if ( $("#split_routine option:selected").val() == 'RegEx' ) {
345
                $("#regex_block").show();
346
                $("#split_regex").attr('required', 'required');
347
            } else {
348
                $("#regex_block").hide();
349
                $("#split_regex").removeAttr('required');
350
            }
351
        };
352
        $(document).ready(function(){
353
            update_regex_block();
354
            $("#split_routine").on("change", function(){
355
                update_regex_block();
356
            });
357
358
            $(".delete_class_source").on("click", function(e){
359
                return confirm(_("Are you sure you want to delete this class source?"));
360
            });
361
            $(".delete_sort_rule").on("click", function(e){
362
                return confirm(_("Are you sure you want to delete this filing rule?"));
363
            });
364
            $(".delete_split_rule").on("click", function(e){
365
                return confirm(_("Are you sure you want to delete this splitting rule?"));
366
            });
367
        });
368
369
    </script>
277
[% END %]
370
[% END %]
278
[% INCLUDE 'intranet-bottom.inc' %]
371
[% INCLUDE 'intranet-bottom.inc' %]
279
- 

Return to bug 15836