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

(-)a/admin/clone-rules.pl (-69 lines)
Lines 1-69 Link Here
1
#!/usr/bin/perl
2
# vim: et ts=4 sw=4
3
# Copyright BibLibre 
4
#
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
21
# This script clones issuing rules from a library to another
22
# parameters : 
23
#  - frombranch : the branch we want to clone issuing rules from
24
#  - tobranch   : the branch we want to clone issuing rules to
25
#
26
# The script can be called with one of the parameters, both or none
27
28
use Modern::Perl;
29
use CGI qw ( -utf8 );
30
use C4::Context;
31
use C4::Output;
32
use C4::Auth;
33
use C4::Koha;
34
use C4::Debug;
35
use Koha::CirculationRules;
36
37
my $input = CGI->new;
38
39
my ($template, $loggedinuser, $cookie)
40
    = get_template_and_user({template_name => "admin/clone-rules.tt",
41
                            query => $input,
42
                            type => "intranet",
43
                            flagsrequired => {parameters => 'manage_circ_rules'},
44
                            debug => 1,
45
                            });
46
47
my $frombranch = $input->param("frombranch");
48
my $tobranch   = $input->param("tobranch");
49
50
$template->param(frombranch     => $frombranch)                if ($frombranch);
51
$template->param(tobranch       => $tobranch)                  if ($tobranch);
52
53
if ($frombranch && $tobranch && $frombranch ne $tobranch) {
54
    $frombranch = ( $frombranch ne '*' ? $frombranch : undef );
55
    $tobranch = ( $tobranch ne '*' ? $tobranch : undef );
56
57
    Koha::CirculationRules->search({branchcode => $tobranch})->delete;
58
59
    my $rules = Koha::CirculationRules->search({ branchcode => $frombranch });
60
    $rules->clone($tobranch);
61
} else {
62
    $template->param(error => 1);
63
}
64
65
$template->param(result => 1);
66
67
68
output_html_with_http_headers $input, $cookie, $template->output;
69
(-)a/admin/smart-rules.pl (-617 lines)
Lines 1-617 Link Here
1
#!/usr/bin/perl
2
# Copyright 2000-2002 Katipo Communications
3
# copyright 2010 BibLibre
4
#
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
use C4::Context;
23
use C4::Output;
24
use C4::Auth;
25
use C4::Koha;
26
use C4::Debug;
27
use Koha::DateUtils;
28
use Koha::Database;
29
use Koha::Logger;
30
use Koha::Libraries;
31
use Koha::CirculationRules;
32
use Koha::Patron::Categories;
33
use Koha::Caches;
34
use Koha::Patrons;
35
36
my $input = CGI->new;
37
my $dbh = C4::Context->dbh;
38
39
# my $flagsrequired;
40
# $flagsrequired->{circulation}=1;
41
my ($template, $loggedinuser, $cookie)
42
    = get_template_and_user({template_name => "admin/smart-rules.tt",
43
                            query => $input,
44
                            type => "intranet",
45
                            flagsrequired => {parameters => 'manage_circ_rules'},
46
                            debug => 1,
47
                            });
48
49
my $type=$input->param('type');
50
51
my $branch = $input->param('branch');
52
unless ( $branch ) {
53
    if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
54
        $branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch();
55
    }
56
    else {
57
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
58
    }
59
}
60
61
my $logged_in_patron = Koha::Patrons->find( $loggedinuser );
62
63
my $can_edit_from_any_library = $logged_in_patron->has_permission( {parameters => 'manage_circ_rules_from_any_libraries' } );
64
$template->param( restricted_to_own_library => not $can_edit_from_any_library );
65
$branch = C4::Context::mybranch() unless $can_edit_from_any_library;
66
67
my $op = $input->param('op') || q{};
68
my $language = C4::Languages::getlanguage();
69
70
my $cache = Koha::Caches->get_instance;
71
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
72
73
if ($op eq 'delete') {
74
    my $itemtype     = $input->param('itemtype');
75
    my $categorycode = $input->param('categorycode');
76
    $debug and warn "deleting $1 $2 $branch";
77
78
    Koha::CirculationRules->set_rules(
79
        {
80
            categorycode => $categorycode eq '*' ? undef : $categorycode,
81
            branchcode   => $branch eq '*' ? undef : $branch,
82
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
83
            rules        => {
84
                maxissueqty                      => undef,
85
                maxonsiteissueqty                => undef,
86
                rentaldiscount                   => undef,
87
                fine                             => undef,
88
                finedays                         => undef,
89
                maxsuspensiondays                => undef,
90
                suspension_chargeperiod          => undef,
91
                firstremind                      => undef,
92
                chargeperiod                     => undef,
93
                chargeperiod_charge_at           => undef,
94
                issuelength                      => undef,
95
                daysmode                         => undef,
96
                lengthunit                       => undef,
97
                hardduedate                      => undef,
98
                hardduedatecompare               => undef,
99
                renewalsallowed                  => undef,
100
                renewalperiod                    => undef,
101
                norenewalbefore                  => undef,
102
                auto_renew                       => undef,
103
                no_auto_renewal_after            => undef,
104
                no_auto_renewal_after_hard_limit => undef,
105
                reservesallowed                  => undef,
106
                holds_per_record                 => undef,
107
                holds_per_day                    => undef,
108
                onshelfholds                     => undef,
109
                opacitemholds                    => undef,
110
                overduefinescap                  => undef,
111
                cap_fine_to_replacement_price    => undef,
112
                article_requests                 => undef,
113
                note                             => undef,
114
            }
115
        }
116
    );
117
}
118
elsif ($op eq 'delete-branch-cat') {
119
    my $categorycode  = $input->param('categorycode');
120
    if ($branch eq "*") {
121
        if ($categorycode eq "*") {
122
            Koha::CirculationRules->set_rules(
123
                {
124
                    branchcode   => undef,
125
                    categorycode => undef,
126
                    rules        => {
127
                        max_holds                      => undef,
128
                        patron_maxissueqty             => undef,
129
                        patron_maxonsiteissueqty       => undef,
130
                    }
131
                }
132
            );
133
            Koha::CirculationRules->set_rules(
134
                {
135
                    branchcode   => undef,
136
                    itemtype     => undef,
137
                    rules        => {
138
                        holdallowed             => undef,
139
                        hold_fulfillment_policy => undef,
140
                        returnbranch            => undef,
141
                    }
142
                }
143
            );
144
        } else {
145
            Koha::CirculationRules->set_rules(
146
                {
147
                    categorycode => $categorycode,
148
                    branchcode   => undef,
149
                    rules        => {
150
                        max_holds                => undef,
151
                        patron_maxissueqty       => undef,
152
                        patron_maxonsiteissueqty => undef,
153
                    }
154
                }
155
            );
156
        }
157
    } elsif ($categorycode eq "*") {
158
        Koha::CirculationRules->set_rules(
159
            {
160
                branchcode   => $branch,
161
                categorycode => undef,
162
                rules        => {
163
                    max_holds                => undef,
164
                    patron_maxissueqty       => undef,
165
                    patron_maxonsiteissueqty => undef,
166
                }
167
            }
168
        );
169
        Koha::CirculationRules->set_rules(
170
            {
171
                branchcode   => $branch,
172
                itemtype     => undef,
173
                rules        => {
174
                    holdallowed             => undef,
175
                    hold_fulfillment_policy => undef,
176
                    returnbranch            => undef,
177
                }
178
            }
179
        );
180
    } else {
181
        Koha::CirculationRules->set_rules(
182
            {
183
                categorycode => $categorycode,
184
                branchcode   => $branch,
185
                rules        => {
186
                    max_holds         => undef,
187
                    patron_maxissueqty       => undef,
188
                    patron_maxonsiteissueqty => undef,
189
                }
190
            }
191
        );
192
    }
193
}
194
elsif ($op eq 'delete-branch-item') {
195
    my $itemtype  = $input->param('itemtype');
196
    if ($branch eq "*") {
197
        if ($itemtype eq "*") {
198
            Koha::CirculationRules->set_rules(
199
                {
200
                    branchcode   => undef,
201
                    itemtype     => undef,
202
                    rules        => {
203
                        holdallowed             => undef,
204
                        hold_fulfillment_policy => undef,
205
                        returnbranch            => undef,
206
                    }
207
                }
208
            );
209
        } else {
210
            Koha::CirculationRules->set_rules(
211
                {
212
                    branchcode   => undef,
213
                    itemtype     => $itemtype,
214
                    rules        => {
215
                        holdallowed             => undef,
216
                        hold_fulfillment_policy => undef,
217
                        returnbranch            => undef,
218
                    }
219
                }
220
            );
221
        }
222
    } elsif ($itemtype eq "*") {
223
        Koha::CirculationRules->set_rules(
224
            {
225
                branchcode   => $branch,
226
                itemtype     => undef,
227
                rules        => {
228
                    holdallowed             => undef,
229
                    hold_fulfillment_policy => undef,
230
                    returnbranch            => undef,
231
                }
232
            }
233
        );
234
    } else {
235
        Koha::CirculationRules->set_rules(
236
            {
237
                branchcode   => $branch,
238
                itemtype     => $itemtype,
239
                rules        => {
240
                    holdallowed             => undef,
241
                    hold_fulfillment_policy => undef,
242
                    returnbranch            => undef,
243
                }
244
            }
245
        );
246
    }
247
}
248
# save the values entered
249
elsif ($op eq 'add') {
250
    my $br = $branch; # branch
251
    my $bor  = $input->param('categorycode'); # borrower category
252
    my $itemtype  = $input->param('itemtype');     # item type
253
    my $fine = $input->param('fine');
254
    my $finedays     = $input->param('finedays');
255
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
256
    my $suspension_chargeperiod = $input->param('suspension_chargeperiod') || 1;
257
    my $firstremind  = $input->param('firstremind');
258
    my $chargeperiod = $input->param('chargeperiod');
259
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
260
    my $maxissueqty = strip_non_numeric( scalar $input->param('maxissueqty') );
261
    my $maxonsiteissueqty = strip_non_numeric( scalar $input->param('maxonsiteissueqty') );
262
    my $renewalsallowed  = $input->param('renewalsallowed');
263
    my $renewalperiod    = $input->param('renewalperiod');
264
    my $norenewalbefore  = $input->param('norenewalbefore');
265
    $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/;
266
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
267
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
268
    $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/;
269
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || '';
270
    $no_auto_renewal_after_hard_limit = eval { dt_from_string( scalar $no_auto_renewal_after_hard_limit ) } if ( $no_auto_renewal_after_hard_limit );
271
    $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
272
    my $reservesallowed  = strip_non_numeric( scalar $input->param('reservesallowed') );
273
    my $holds_per_record = strip_non_numeric( scalar $input->param('holds_per_record') );
274
    my $holds_per_day    = strip_non_numeric( scalar $input->param('holds_per_day') );
275
    my $onshelfholds     = $input->param('onshelfholds') || 0;
276
    my $issuelength  = $input->param('issuelength');
277
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
278
    my $daysmode = $input->param('daysmode');
279
    my $lengthunit  = $input->param('lengthunit');
280
    my $hardduedate = $input->param('hardduedate') || undef;
281
    $hardduedate = eval { dt_from_string( scalar $hardduedate ) } if ( $hardduedate );
282
    $hardduedate = output_pref( { dt => $hardduedate, dateonly => 1, dateformat => 'iso' } ) if ( $hardduedate );
283
    my $hardduedatecompare = $input->param('hardduedatecompare');
284
    my $rentaldiscount = $input->param('rentaldiscount');
285
    my $opacitemholds = $input->param('opacitemholds') || 0;
286
    my $article_requests = $input->param('article_requests') || 'no';
287
    my $overduefinescap = $input->param('overduefinescap') || '';
288
    my $cap_fine_to_replacement_price = ($input->param('cap_fine_to_replacement_price') || '') eq 'on';
289
    my $note = $input->param('note');
290
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
291
292
    my $rules = {
293
        maxissueqty                   => $maxissueqty,
294
        maxonsiteissueqty             => $maxonsiteissueqty,
295
        rentaldiscount                => $rentaldiscount,
296
        fine                          => $fine,
297
        finedays                      => $finedays,
298
        maxsuspensiondays             => $maxsuspensiondays,
299
        suspension_chargeperiod       => $suspension_chargeperiod,
300
        firstremind                   => $firstremind,
301
        chargeperiod                  => $chargeperiod,
302
        chargeperiod_charge_at        => $chargeperiod_charge_at,
303
        issuelength                   => $issuelength,
304
        daysmode                      => $daysmode,
305
        lengthunit                    => $lengthunit,
306
        hardduedate                   => $hardduedate,
307
        hardduedatecompare            => $hardduedatecompare,
308
        renewalsallowed               => $renewalsallowed,
309
        renewalperiod                 => $renewalperiod,
310
        norenewalbefore               => $norenewalbefore,
311
        auto_renew                    => $auto_renew,
312
        no_auto_renewal_after         => $no_auto_renewal_after,
313
        no_auto_renewal_after_hard_limit => $no_auto_renewal_after_hard_limit,
314
        reservesallowed               => $reservesallowed,
315
        holds_per_record              => $holds_per_record,
316
        holds_per_day                 => $holds_per_day,
317
        onshelfholds                  => $onshelfholds,
318
        opacitemholds                 => $opacitemholds,
319
        overduefinescap               => $overduefinescap,
320
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
321
        article_requests              => $article_requests,
322
        note                          => $note,
323
    };
324
325
    Koha::CirculationRules->set_rules(
326
        {
327
            categorycode => $bor eq '*' ? undef : $bor,
328
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
329
            branchcode   => $br eq '*' ? undef : $br,
330
            rules        => $rules,
331
        }
332
    );
333
334
}
335
elsif ($op eq "set-branch-defaults") {
336
    my $categorycode  = $input->param('categorycode');
337
    my $patron_maxissueqty = strip_non_numeric( scalar $input->param('patron_maxissueqty') );
338
    my $patron_maxonsiteissueqty = $input->param('patron_maxonsiteissueqty');
339
    $patron_maxonsiteissueqty = strip_non_numeric($patron_maxonsiteissueqty);
340
    my $holdallowed   = $input->param('holdallowed');
341
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
342
    my $returnbranch  = $input->param('returnbranch');
343
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
344
345
    if ($branch eq "*") {
346
        Koha::CirculationRules->set_rules(
347
            {
348
                itemtype     => undef,
349
                branchcode   => undef,
350
                rules        => {
351
                    holdallowed             => $holdallowed,
352
                    hold_fulfillment_policy => $hold_fulfillment_policy,
353
                    returnbranch            => $returnbranch,
354
                }
355
            }
356
        );
357
        Koha::CirculationRules->set_rules(
358
            {
359
                categorycode => undef,
360
                branchcode   => undef,
361
                rules        => {
362
                    patron_maxissueqty             => $patron_maxissueqty,
363
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
364
                }
365
            }
366
        );
367
    } else {
368
        Koha::CirculationRules->set_rules(
369
            {
370
                itemtype     => undef,
371
                branchcode   => $branch,
372
                rules        => {
373
                    holdallowed             => $holdallowed,
374
                    hold_fulfillment_policy => $hold_fulfillment_policy,
375
                    returnbranch            => $returnbranch,
376
                }
377
            }
378
        );
379
        Koha::CirculationRules->set_rules(
380
            {
381
                categorycode => undef,
382
                branchcode   => $branch,
383
                rules        => {
384
                    patron_maxissueqty             => $patron_maxissueqty,
385
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
386
                }
387
            }
388
        );
389
    }
390
    Koha::CirculationRules->set_rule(
391
        {
392
            branchcode   => $branch,
393
            categorycode => undef,
394
            rule_name    => 'max_holds',
395
            rule_value   => $max_holds,
396
        }
397
    );
398
}
399
elsif ($op eq "add-branch-cat") {
400
    my $categorycode  = $input->param('categorycode');
401
    my $patron_maxissueqty = strip_non_numeric( scalar $input->param('patron_maxissueqty') );
402
    my $patron_maxonsiteissueqty = $input->param('patron_maxonsiteissueqty');
403
    $patron_maxonsiteissueqty = strip_non_numeric($patron_maxonsiteissueqty);
404
    my $max_holds = $input->param('max_holds');
405
    $max_holds =~ s/\s//g;
406
    $max_holds = undef if $max_holds !~ /^\d+/;
407
408
    if ($branch eq "*") {
409
        if ($categorycode eq "*") {
410
            Koha::CirculationRules->set_rules(
411
                {
412
                    categorycode => undef,
413
                    branchcode   => undef,
414
                    rules        => {
415
                        max_holds         => $max_holds,
416
                        patron_maxissueqty       => $patron_maxissueqty,
417
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
418
                    }
419
                }
420
            );
421
        } else {
422
            Koha::CirculationRules->set_rules(
423
                {
424
                    categorycode => $categorycode,
425
                    branchcode   => undef,
426
                    rules        => {
427
                        max_holds         => $max_holds,
428
                        patron_maxissueqty       => $patron_maxissueqty,
429
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
430
                    }
431
                }
432
            );
433
        }
434
    } elsif ($categorycode eq "*") {
435
        Koha::CirculationRules->set_rules(
436
            {
437
                categorycode => undef,
438
                branchcode   => $branch,
439
                rules        => {
440
                    max_holds         => $max_holds,
441
                    patron_maxissueqty       => $patron_maxissueqty,
442
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
443
                }
444
            }
445
        );
446
    } else {
447
        Koha::CirculationRules->set_rules(
448
            {
449
                categorycode => $categorycode,
450
                branchcode   => $branch,
451
                rules        => {
452
                    max_holds         => $max_holds,
453
                    patron_maxissueqty       => $patron_maxissueqty,
454
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
455
                }
456
            }
457
        );
458
    }
459
}
460
elsif ($op eq "add-branch-item") {
461
    my $itemtype                = $input->param('itemtype');
462
    my $holdallowed             = $input->param('holdallowed');
463
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
464
    my $returnbranch            = $input->param('returnbranch');
465
466
    if ($branch eq "*") {
467
        if ($itemtype eq "*") {
468
            Koha::CirculationRules->set_rules(
469
                {
470
                    itemtype     => undef,
471
                    branchcode   => undef,
472
                    rules        => {
473
                        holdallowed             => $holdallowed,
474
                        hold_fulfillment_policy => $hold_fulfillment_policy,
475
                        returnbranch            => $returnbranch,
476
                    }
477
                }
478
            );
479
        } else {
480
            Koha::CirculationRules->set_rules(
481
                {
482
                    itemtype     => $itemtype,
483
                    branchcode   => undef,
484
                    rules        => {
485
                        holdallowed             => $holdallowed,
486
                        hold_fulfillment_policy => $hold_fulfillment_policy,
487
                        returnbranch            => $returnbranch,
488
                    }
489
                }
490
            );
491
        }
492
    } elsif ($itemtype eq "*") {
493
            Koha::CirculationRules->set_rules(
494
                {
495
                    itemtype     => undef,
496
                    branchcode   => $branch,
497
                    rules        => {
498
                        holdallowed             => $holdallowed,
499
                        hold_fulfillment_policy => $hold_fulfillment_policy,
500
                        returnbranch            => $returnbranch,
501
                    }
502
                }
503
            );
504
    } else {
505
        Koha::CirculationRules->set_rules(
506
            {
507
                itemtype     => $itemtype,
508
                branchcode   => $branch,
509
                rules        => {
510
                    holdallowed             => $holdallowed,
511
                    hold_fulfillment_policy => $hold_fulfillment_policy,
512
                    returnbranch            => $returnbranch,
513
                }
514
            }
515
        );
516
    }
517
}
518
elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
519
520
    my $refund = $input->param('refund');
521
522
    if ( $refund eq '*' ) {
523
        if ( $branch ne '*' ) {
524
            # only do something for $refund eq '*' if branch-specific
525
            Koha::CirculationRules->set_rules(
526
                {
527
                    branchcode   => $branch,
528
                    rules        => {
529
                        refund => undef
530
                    }
531
                }
532
            );
533
        }
534
    } else {
535
        Koha::CirculationRules->set_rules(
536
            {
537
                branchcode   => $branch,
538
                rules        => {
539
                    refund => $refund
540
                }
541
            }
542
        );
543
    }
544
}
545
546
my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'refund' });
547
my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'refund' });
548
$template->param(
549
    refundLostItemFeeRule => $refundLostItemFeeRule,
550
    defaultRefundRule     => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 1
551
);
552
553
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
554
555
my $itemtypes = Koha::ItemTypes->search_with_localization;
556
557
my $humanbranch = ( $branch ne '*' ? $branch : undef );
558
559
my $all_rules = Koha::CirculationRules->search({ branchcode => $humanbranch });
560
my $definedbranch = $all_rules->count ? 1 : 0;
561
562
my $rules = {};
563
while ( my $r = $all_rules->next ) {
564
    $r = $r->unblessed;
565
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
566
}
567
568
$template->param(show_branch_cat_rule_form => 1);
569
570
$template->param(
571
    patron_categories => $patron_categories,
572
    itemtypeloop      => $itemtypes,
573
    humanbranch       => $humanbranch,
574
    current_branch    => $branch,
575
    definedbranch     => $definedbranch,
576
    all_rules         => $rules,
577
);
578
output_html_with_http_headers $input, $cookie, $template->output;
579
580
exit 0;
581
582
# sort by patron category, then item type, putting
583
# default entries at the bottom
584
sub by_category_and_itemtype {
585
    unless (by_category($a, $b)) {
586
        return by_itemtype($a, $b);
587
    }
588
}
589
590
sub by_category {
591
    my ($a, $b) = @_;
592
    if ($a->{'default_humancategorycode'}) {
593
        return ($b->{'default_humancategorycode'} ? 0 : 1);
594
    } elsif ($b->{'default_humancategorycode'}) {
595
        return -1;
596
    } else {
597
        return $a->{'humancategorycode'} cmp $b->{'humancategorycode'};
598
    }
599
}
600
601
sub by_itemtype {
602
    my ($a, $b) = @_;
603
    if ($a->{default_translated_description}) {
604
        return ($b->{'default_translated_description'} ? 0 : 1);
605
    } elsif ($b->{'default_translated_description'}) {
606
        return -1;
607
    } else {
608
        return lc $a->{'translated_description'} cmp lc $b->{'translated_description'};
609
    }
610
}
611
612
sub strip_non_numeric {
613
    my $string = shift;
614
    $string =~ s/\s//g;
615
    $string = '' if $string !~ /^\d+/;
616
    return $string;
617
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/clone-rules.tt (-77 lines)
Lines 1-77 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Branches %]
4
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules &rsaquo; Clone circulation and fine rules</title>
7
[% INCLUDE 'doc-head-close.inc' %]
8
</head>
9
<body id="admin_clone-rules" class="admin">
10
[% INCLUDE 'header.inc' %]
11
[% INCLUDE 'prefs-admin-search.inc' %]
12
13
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fine rules</a> &rsaquo; Clone circulation and fine rules</div>
14
15
<div class="main container-fluid">
16
    <div class="row">
17
        <div class="col-sm-10 col-sm-push-2">
18
            <main>
19
20
    <h2>Cloning circulation and fine rules
21
        [% IF frombranch %] from "[% Branches.GetName( frombranch ) | html %]"[% END %]
22
        [% IF tobranch %] to "[% Branches.GetName( tobranch ) | html %]"[% END %]
23
    </h2>
24
25
    [% IF ( result ) %]
26
	[% IF ( error ) %]
27
        <div class="dialog alert">Cloning of circulation and fine rules failed!</div>
28
	[% ELSE %]
29
	    <div class="dialog message"><p>The rules have been cloned.</p></div>
30
	[% END %]
31
    <a href="/cgi-bin/koha/admin/smart-rules.pl">Return to circulation and fine rules</a>
32
    [% ELSE %]
33
34
    <p class="help">Use carefully! If the destination library already has circulation and fine rules, they will be deleted without warning!</p>
35
    <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
36
        [% UNLESS ( frombranch ) %]
37
            <fieldset>
38
                <legend>Please choose a library to clone rules from:</legend>
39
                <label for="frombranch">Source library:</label>
40
                <select name="frombranch" id="frombranch">
41
                    <option value="">Default</option>
42
                    [% PROCESS options_for_libraries libraries => Branches.all() %]
43
                </select>
44
                [% IF ( tobranch ) %]<input type="hidden" name="tobranch" value="[% tobranch | html %]" />[% END %]
45
            </fieldset>
46
        [% END %]
47
48
        [% UNLESS ( tobranch ) %]
49
            <fieldset>
50
            <legend>Please choose the library to clone the rules to:</legend>
51
            <label for="tobranch">Destination library:</label>
52
            <select name="tobranch" id="tobranch">
53
                <option value="">Default</option>
54
                [% PROCESS options_for_libraries libraries => Branches.all() %]
55
            </select>
56
            [% IF ( frombranch ) %]<input type="hidden" name="frombranch" value="[% frombranch | html %]" />[% END %]
57
            </fieldset>
58
        [% END %]
59
        <input type="submit" value="Submit" />
60
    </form>
61
62
    [% END %]
63
            </main>
64
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
65
66
        <div class="col-sm-2 col-sm-pull-10">
67
            <aside>
68
                [% INCLUDE 'admin-menu.inc' %]
69
            </aside>
70
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
71
     </div> <!-- /.row -->
72
73
[% MACRO jsinclude BLOCK %]
74
    [% Asset.js("js/admin-menu.js") | $raw %]
75
[% END %]
76
77
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1111 lines)
Lines 1-1110 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Koha %]
4
[% USE KohaDates %]
5
[% USE Branches %]
6
[% USE Categories %]
7
[% USE ItemTypes %]
8
[% USE CirculationRules %]
9
[% SET footerjs = 1 %]
10
11
[% SET branchcode = humanbranch || undef %]
12
13
[% SET categorycodes = [] %]
14
[% FOREACH pc IN patron_categories %]
15
    [% categorycodes.push( pc.id ) %]
16
[% END %]
17
[% categorycodes.push(undef) %]
18
19
[% SET itemtypes = [] %]
20
[% FOREACH i IN itemtypeloop %]
21
    [% itemtypes.push( i.itemtype ) %]
22
[% END %]
23
[% itemtypes.push(undef) %]
24
25
[% INCLUDE 'doc-head-open.inc' %]
26
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
27
[% INCLUDE 'doc-head-close.inc' %]
28
</head>
29
30
<body id="admin_smart-rules" class="admin">
31
[% INCLUDE 'header.inc' %]
32
[% INCLUDE 'prefs-admin-search.inc' %]
33
34
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Circulation and fine rules</div>
35
36
<div class="main container-fluid">
37
    <div class="row">
38
        <div class="col-sm-10 col-sm-push-2">
39
            <main>
40
41
    <h1 class="parameters">
42
        [% IF humanbranch %]
43
            Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) | html %]"
44
        [% ELSE %]
45
            Defining circulation and fine rules for all libraries
46
        [% END %]
47
    </h1>
48
    <div class="help">
49
        <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
50
        <ul>
51
            <li>same library, same patron category, same item type</li>
52
            <li>same library, same patron category, all item types</li>
53
            <li>same library, all patron categories, same item type</li>
54
            <li>same library, all patron categories, all item types</li>
55
            <li>default (all libraries), same patron category, same item type</li>
56
            <li>default (all libraries), same patron category, all item types</li>
57
            <li>default (all libraries), all patron categories, same item type</li>
58
            <li>default (all libraries), all patron categories, all item types</li>
59
        </ul>
60
61
        <p>Where an itemtype has a parent, the rule will display as "Parent->Child" and the number of
62
        current checkouts allowed will be limited to either the maximum for the parent (counting sibling types)
63
        or the specific rule's type, whichever is less.</p>
64
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
65
    </div>
66
    <div>
67
        [% UNLESS restricted_to_own_library %]
68
            <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
69
            Select a library :
70
                <select name="branch" id="branch" style="width:20em;">
71
                    <option value="*">Standard rules for all libraries</option>
72
                    [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
73
                </select>
74
            </form>
75
            [% IF ( definedbranch ) %]
76
                <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
77
                    <label for="tobranch"><strong>Clone these rules to:</strong></label>
78
                    <input type="hidden" name="frombranch" value="[% current_branch | html %]" />
79
                    <select name="tobranch" id="tobranch">
80
                        [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
81
                    </select>
82
                    <input type="submit" id="clone_rules" value="Clone" />
83
                </form>
84
            [% END %]
85
        [% END %]
86
87
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
88
            <input type="hidden" name="op" value="add" />
89
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
90
            <table id="default-circulation-rules">
91
            <thead>
92
            <tr>
93
                <th>&nbsp;</th>
94
                <th>Patron category</th>
95
                <th>&nbsp;</th>
96
                <th>Item type</th>
97
                <th>Actions</th>
98
                <th>Note</th>
99
                <th>Current checkouts allowed</th>
100
                <th>Current on-site checkouts allowed</th>
101
                <th>Loan period</th>
102
                <th>Days mode</th>
103
                <th>Unit</th>
104
                <th>Hard due date</th>
105
                <th>Fine amount</th>
106
                <th>Fine charging interval</th>
107
                <th>When to charge</th>
108
                <th>Fine grace period</th>
109
                <th>Overdue fines cap (amount)</th>
110
                <th>Cap fine at replacement price</th>
111
                <th>Suspension in days (day)</th>
112
                <th>Max. suspension duration (day)</th>
113
                <th>Suspension charging interval</th>
114
                <th>Renewals allowed (count)</th>
115
                <th>Renewal period</th>
116
                <th>No renewal before</th>
117
                <th>Automatic renewal</th>
118
                <th>No automatic renewal after</th>
119
                <th>No automatic renewal after (hard limit)</th>
120
                <th>Holds allowed (total)</th>
121
                <th>Holds allowed (daily)</th>
122
                <th>Holds per record (count)</th>
123
                <th>On shelf holds allowed</th>
124
                <th>OPAC item level holds</th>
125
                <th>Article requests</th>
126
                <th>Rental discount (%)</th>
127
                <th>Actions</th>
128
            </tr>
129
            </thead>
130
            <tbody>
131
                [% SET row_count = 0 %]
132
                [% FOREACH c IN categorycodes %]
133
                    [% SET c = '' UNLESS c.defined %]
134
                    [% FOREACH i IN itemtypes %]
135
                        [% SET i = '' UNLESS i.defined %]
136
                        [% SET note = all_rules.$c.$i.note %]
137
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
138
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
139
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
140
                        [% SET daysmode = all_rules.$c.$i.daysmode %]
141
                        [% SET lengthunit = all_rules.$c.$i.lengthunit %]
142
                        [% SET hardduedate = all_rules.$c.$i.hardduedate %]
143
                        [% SET hardduedatecompare = all_rules.$c.$i.hardduedatecompare %]
144
                        [% SET fine = all_rules.$c.$i.fine %]
145
                        [% SET chargeperiod = all_rules.$c.$i.chargeperiod %]
146
                        [% SET chargeperiod_charge_at = all_rules.$c.$i.chargeperiod_charge_at %]
147
                        [% SET firstremind = all_rules.$c.$i.firstremind %]
148
                        [% SET overduefinescap = all_rules.$c.$i.overduefinescap %]
149
                        [% SET cap_fine_to_replacement_price = all_rules.$c.$i.cap_fine_to_replacement_price %]
150
                        [% SET finedays = all_rules.$c.$i.finedays %]
151
                        [% SET maxsuspensiondays = all_rules.$c.$i.maxsuspensiondays %]
152
                        [% SET suspension_chargeperiod = all_rules.$c.$i.suspension_chargeperiod %]
153
                        [% SET renewalsallowed = all_rules.$c.$i.renewalsallowed %]
154
                        [% SET renewalperiod = all_rules.$c.$i.renewalperiod %]
155
                        [% SET norenewalbefore = all_rules.$c.$i.norenewalbefore %]
156
                        [% SET auto_renew = all_rules.$c.$i.auto_renew %]
157
                        [% SET no_auto_renewal_after = all_rules.$c.$i.no_auto_renewal_after %]
158
                        [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.no_auto_renewal_after_hard_limit %]
159
                        [% SET reservesallowed = all_rules.$c.$i.reservesallowed %]
160
                        [% SET holds_per_day = all_rules.$c.$i.holds_per_day %]
161
                        [% SET holds_per_record = all_rules.$c.$i.holds_per_record %]
162
                        [% SET onshelfholds = all_rules.$c.$i.onshelfholds %]
163
                        [% SET opacitemholds = all_rules.$c.$i.opacitemholds %]
164
                        [% SET article_requests = all_rules.$c.$i.article_requests %]
165
                        [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %]
166
167
                        [% SET show_rule = note || maxissueqty || maxonsiteissueqty || issuelength || daysmode || lengthunit || hardduedate || hardduedatecompare || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalperiod || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || rentaldiscount %]
168
                        [% IF show_rule %]
169
                            [% SET row_count = row_count + 1 %]
170
                            <tr row_countd="row_[% row_count | html %]">
171
                                    <td>[% IF ( c == undef ) %]1[% ELSE %]0[% END %]</td>
172
                                    <td>
173
                                        [% IF c == undef %]
174
                                            <em>All</em>
175
                                        [% ELSE %]
176
                                            [% Categories.GetName(c) | html %]
177
                                        [% END %]
178
                                    </td>
179
                                    <td>[% IF ( i == undef ) %]1[% ELSE %]0[% END %]</td>
180
                                    <td>
181
                                        [% IF i == undef %]
182
                                            <em>All</em>
183
                                        [% ELSE %]
184
                                            [% ItemTypes.GetDescription(i,1) | html %]
185
                                        [% END %]
186
                                    </td>
187
                                    <td class="actions">
188
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
189
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | html %]&amp;categorycode=[% c || '*' | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
190
                                    </td>
191
                                    <td>
192
                                        [% IF note.defined && note != '' %]
193
                                            <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
194
                                        [% ELSE %]<span>&nbsp;</span>[% END %]
195
                                    </td>
196
                                    <td>
197
                                        [% IF maxissueqty.defined && maxissueqty != '' %]
198
                                            [% maxissueqty | html %]
199
                                        [% ELSE %]
200
                                            <span>Unlimited</span>
201
                                        [% END %]
202
                                    </td>
203
                                    <td>
204
                                        [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
205
                                            [% maxonsiteissueqty | html %]
206
                                        [% ELSE %]
207
                                            <span>Unlimited</span>
208
                                        [% END %]
209
                                    </td>
210
                                    <td>[% issuelength | html %]</td>
211
                                    <td>
212
                                        [% SWITCH daysmode %]
213
                                        [% CASE 'Calendar' %]<span title="Use the calendar to skip days the library is closed">Calendar</span>
214
                                        [% CASE 'Datedue' %]<span title="Use the calendar to push the due date to the next open day">Datedue</span>
215
                                        [% CASE 'Days' %]<span title="Ignore the calendar">Days</span>
216
                                        [% CASE 'Dayweek' %]<span title="Use the calendar to push the due date to the next open matching weekday for weekly loan periods, or the next open day otherwise">Dayweek</span>
217
                                        [% CASE %]<span title="Use the system preference 'useDaysMode' as a default value">Default</span>
218
                                        [% END %]
219
                                    </td>
220
                                    <td>
221
                                        [% IF ( lengthunit == 'days' ) %]
222
                                            Days
223
                                        [% ELSIF ( lengthunit == 'hours') %]
224
                                            Hours
225
                                        [% ELSE %]
226
                                            Undefined
227
                                        [% END %]
228
                                    </td>
229
                                    <td>
230
                                      [% IF ( hardduedate ) %]
231
                                        [% IF ( hardduedatecompare == '-1' ) %]
232
                                          before [% hardduedate | $KohaDates %]
233
                                          <input type="hidden" name="hardduedatecomparebackup" value="-1" />
234
                                        [% ELSIF ( hardduedatecompare == '0' ) %]
235
                                          on [% hardduedate | $KohaDates %]
236
                                          <input type="hidden" name="hardduedatecomparebackup" value="0" />
237
                                        [% ELSIF ( hardduedatecompare == '1' ) %]
238
                                          after [% hardduedate | $KohaDates %]
239
                                          <input type="hidden" name="hardduedatecomparebackup" value="1" />
240
                                        [% END %]
241
                                      [% ELSE %]
242
                                        <span>None defined</span>
243
                                      [% END %]
244
                                    </td>
245
                                    <td>[% fine | html %]</td>
246
                                    <td>[% chargeperiod | html %]</td>
247
                                    <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
248
                                    <td>[% firstremind | html %]</td>
249
                                    <td>[% overduefinescap FILTER format("%.2f") %]</td>
250
                                    <td>
251
                                        [% IF cap_fine_to_replacement_price %]
252
                                            <input type="checkbox" checked="checked" disabled="disabled" />
253
                                        [% ELSE %]
254
                                            <input type="checkbox" disabled="disabled" />
255
                                        [% END %]
256
                                    </td>
257
                                    <td>[% finedays | html %]</td>
258
                                    <td>[% maxsuspensiondays | html %]</td>
259
                                    <td>[% suspension_chargeperiod | html %]</td>
260
                                    <td>[% renewalsallowed | html %]</td>
261
                                    <td>[% renewalperiod | html %]</td>
262
                                    <td>[% norenewalbefore | html %]</td>
263
                                    <td>
264
                                        [% IF auto_renew %]
265
                                            <span>Yes</span>
266
                                        [% ELSE %]
267
                                            <span>No</span>
268
                                        [% END %]
269
                                    </td>
270
                                    <td>[% no_auto_renewal_after | html %]</td>
271
                                    <td>[% no_auto_renewal_after_hard_limit | $KohaDates %]</td>
272
                                    <td>
273
                                        [% IF reservesallowed.defined && reservesallowed != '' %]
274
                                            [% reservesallowed | html %]
275
                                        [% ELSE %]
276
                                            <span>Unlimited</span>
277
                                        [% END %]
278
                                    </td>
279
                                    <td>
280
                                        [% IF holds_per_day.defined && holds_per_day != '' %]
281
                                            [% holds_per_day | html %]
282
                                        [% ELSE %]
283
                                            <span>Unlimited</span>
284
                                        [% END %]
285
                                    </td>
286
                                    <td>
287
                                        [% IF holds_per_record.defined && holds_per_record != '' %]
288
                                            [% holds_per_record | html %]
289
                                        [% ELSE %]
290
                                            <span>Unlimited</span>
291
                                        [% END %]
292
                                    </td>
293
                                    <td>
294
                                        [% IF onshelfholds == 1 %]
295
                                            <span>Yes</span>
296
                                        [% ELSIF onshelfholds == 2 %]
297
                                            <span>If all unavailable</span>
298
                                        [% ELSE %]
299
                                            <span>If any unavailable</span>
300
                                        [% END %]
301
                                    </td>
302
                                    <td>
303
                                        [% IF opacitemholds == 'F'%]
304
                                            <span>Force</span>
305
                                        [% ELSIF opacitemholds == 'Y'%]
306
                                            <span>Allow</span>
307
                                        [% ELSE %]
308
                                            <span>Don't allow</span>
309
                                        [% END %]
310
                                    </td>
311
                                    <td>
312
                                        [% IF article_requests == 'no' %]
313
                                            <span>No</span>
314
                                        [% ELSIF article_requests == 'yes' %]
315
                                            <span>Yes</span>
316
                                        [% ELSIF article_requests == 'bib_only' %]
317
                                            <span>Record only</span>
318
                                        [% ELSIF article_requests == 'item_only' %]
319
                                            <span>Item only</span>
320
                                        [% END %]
321
                                    </td>
322
                                    <td>[% rentaldiscount | html %]</td>
323
                                    <td class="actions">
324
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
325
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | uri %]&amp;categorycode=[% c || '*' | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
326
                                    </td>
327
                            </tr>
328
                        [% END %]
329
                    [% END %]
330
                [% END %]
331
                <tr id="edit_row">
332
                    <td>2</td>
333
                    <td>
334
                        <select name="categorycode" id="categorycode">
335
                            <option value="*">All</option>
336
                        [% FOREACH patron_category IN patron_categories%]
337
                            <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
338
                        [% END %]
339
                        </select>
340
                    </td>
341
                    <td>0</td>
342
                    <td>
343
                        <select name="itemtype" id="matrixitemtype" style="width:13em;">
344
                            <option value="*">All</option>
345
                            [% FOREACH itemtypeloo IN itemtypeloop %]
346
                                [% NEXT IF itemtypeloo.parent_type %]
347
                                [% SET children = itemtypeloo.children_with_localization %]
348
                                [% IF children %]
349
                                    <optgroup label="[% itemtypeloo.translated_description | html %]">
350
                                        <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %] (All)</option>
351
                                        [% FOREACH child IN children %]
352
                                            <option value="[% child.itemtype | html %]">[% child.translated_description | html %]</option>
353
                                        [% END %]
354
                                    </optgroup>
355
                                [% ELSE %]
356
                                    <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
357
                                [% END %]
358
                            [% END %]
359
                        </select>
360
                    </td>
361
                    <td class="actions">
362
                        <input type="hidden" name="branch" value="[% current_branch | html %]"/>
363
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
364
                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
365
                    </td>
366
                    <td><input type="text" name="note" id="note" size="15" value="" maxlength="100"></td>
367
                    <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
368
                    <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
369
                    <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
370
                    <td>
371
                        <select name="daysmode" id="daysmode">
372
                            <option value="">Default</option>
373
                            <option value="Calendar">Calendar</option>
374
                            <option value="Datedue">Datedue</option>
375
                            <option value="Days">Days</option>
376
                            <option value="Dayweek">Dayweek</option>
377
                        </select>
378
                    </td>
379
                    <td>
380
                      <select name="lengthunit" id="lengthunit">
381
                        <option value="days" selected="selected">Days</option>
382
                        <option value="hours">Hours</option>
383
                      </select>
384
                    </td>
385
                    <td>
386
                        <select name="hardduedatecompare" id="hardduedatecompare">
387
                           <option value="-1">Before</option>
388
                           <option value="0">Exactly on</option>
389
                           <option value="1">After</option>
390
                        </select>
391
                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="datepicker" />
392
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
393
                    </td>
394
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
395
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
396
                    <td>
397
                        <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
398
                           <option value="0">End of interval</option>
399
                           <option value="1">Start of interval</option>
400
                        </select>
401
                    </td>
402
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
403
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
404
                    <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
405
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
406
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
407
                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
408
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
409
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
410
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
411
                    <td>
412
                        <select name="auto_renew" id="auto_renew">
413
                            <option value="no" selected>No</option>
414
                            <option value="yes">Yes</option>
415
                        </select>
416
                    </td>
417
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
418
                    <td>
419
                        <input type="text" size="10" name="no_auto_renewal_after_hard_limit" id="no_auto_renewal_after_hard_limit" value="[% no_auto_renewal_after_hard_limit | html %]" class="datepicker"/>
420
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
421
                    </td>
422
                    <td><input type="text" name="reservesallowed"  id="reservesallowed"  size="2" /></td>
423
                    <td><input type="text" name="holds_per_day"    id="holds_per_day"    size="2" /></td>
424
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
425
                    <td>
426
                        <select name="onshelfholds" id="onshelfholds">
427
                            <option value="1">Yes</option>
428
                            <option value="0">If any unavailable</option>
429
                            <option value="2">If all unavailable</option>
430
                        </select>
431
                    </td>
432
                    <td>
433
                        <select id="opacitemholds" name="opacitemholds">
434
                            <option value="N">Don't allow</option>
435
                            <option value="Y">Allow</option>
436
                            <option value="F">Force</option>
437
                        </select>
438
                    </td>
439
                    <td>
440
                        <select id="article_requests" name="article_requests">
441
                            <option value="no">No</option>
442
                            <option value="yes">Yes</option>
443
                            <option value="bib_only">Record only</option>
444
                            <option value="item_only">Item only</option>
445
                        </select>
446
                    </td>
447
                    <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
448
                    <td class="actions">
449
                        <input type="hidden" name="branch" value="[% current_branch | html %]"/>
450
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
451
                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
452
                    </td>
453
                </tr>
454
                <tfoot>
455
                    <tr>
456
                      <th>&nbsp;</th>
457
                      <th>Patron category</th>
458
                      <th>&nbsp;</th>
459
                      <th>Item type</th>
460
                      <th>&nbsp;</th>
461
                      <th>Note</th>
462
                      <th>Current checkouts allowed</th>
463
                      <th>Current on-site checkouts allowed</th>
464
                      <th>Loan period</th>
465
                      <th>Days mode</th>
466
                      <th>Unit</th>
467
                      <th>Hard due date</th>
468
                      <th>Fine amount</th>
469
                      <th>Fine charging interval</th>
470
                      <th>Charge when?</th>
471
                      <th>Fine grace period</th>
472
                      <th>Overdue fines cap (amount)</th>
473
                      <th>Cap fine at replacement price</th>
474
                      <th>Suspension in days (day)</th>
475
                      <th>Max. suspension duration (day)</th>
476
                      <th>Suspension charging interval</th>
477
                      <th>Renewals allowed (count)</th>
478
                      <th>Renewal period</th>
479
                      <th>No renewal before</th>
480
                      <th>Automatic renewal</th>
481
                      <th>No automatic renewal after</th>
482
                      <th>No automatic renewal after (hard limit)</th>
483
                      <th>Holds allowed (total)</th>
484
                      <th>Holds allowed (daily)</th>
485
                      <th>Holds per record (count)</th>
486
                      <th>On shelf holds allowed</th>
487
                      <th>OPAC item level holds</th>
488
                      <th>Article requests</th>
489
                      <th>Rental discount (%)</th>
490
                      <th>&nbsp;</th>
491
                    </tr>
492
                  </tfoot>
493
                </tbody>
494
            </table>
495
        </form>
496
    </div>
497
    <div id="defaults-for-this-library" class="container">
498
    <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) | html %][% END %]</h3>
499
        <p>You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.</p>
500
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
501
            <input type="hidden" name="op" value="set-branch-defaults" />
502
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
503
            <table>
504
                <tr>
505
                    <th>&nbsp;</th>
506
                    <th>Total current checkouts allowed</th>
507
                    <th>Total current on-site checkouts allowed</th>
508
                    <th>Maximum total holds allowed (count)</th>
509
                    <th>Hold policy</th>
510
                    <th>Hold pickup library match</th>
511
                    <th>Return policy</th>
512
                    <th>Actions</th>
513
                </tr>
514
                <tr>
515
                    <td><em>Defaults</em></td>
516
                    <td>
517
                        [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %]
518
                        <input type="text" name="patron_maxissueqty" size="3" value="[% patron_maxissueqty | html %]"/>
519
                    </td>
520
                    <td>
521
                        [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty' ) %]
522
                        <input type="text" name="patron_maxonsiteissueqty" size="3" value="[% patron_maxonsiteissueqty | html %]"/>
523
                    </td>
524
                    <td>
525
                        [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds' ) %]
526
                        <input name="max_holds" size="3" value="[% rule_value | html %]" />
527
                    </td>
528
                    <td>
529
                        <select name="holdallowed">
530
                            [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed' ) %]
531
                            <option value="">
532
                                Not set
533
                            </option>
534
535
                            [% IF holdallowed == 2 %]
536
                                <option value="2" selected="selected">
537
                            [% ELSE %]
538
                                <option value="2">
539
                            [% END %]
540
                                From any library
541
                            </option>
542
543
                            [% IF holdallowed == 3 %]
544
                            <option value="3" selected="selected">
545
                            [% ELSE %]
546
                            <option value="3">
547
                            [% END %]
548
                                From local hold group
549
                            </option>
550
551
                            [% IF holdallowed == 1 %]
552
                                <option value="1" selected="selected">
553
                            [% ELSE %]
554
                                <option value="1">
555
                            [% END %]
556
                                From home library
557
                            </option>
558
559
                            [% IF holdallowed == 0 %]
560
                                <option value="0" selected="selected">
561
                            [% ELSE %]
562
                                <option value="0">
563
                            [% END %]
564
                                No holds allowed
565
                            </option>
566
                        </select>
567
                    </td>
568
                    <td>
569
                        <select name="hold_fulfillment_policy">
570
                            [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy' ) %]
571
572
                            <option value="">
573
                                Not set
574
                            </option>
575
576
                            [% IF hold_fulfillment_policy == 'any' %]
577
                                <option value="any" selected="selected">
578
                                    any library
579
                                </option>
580
                            [% ELSE %]
581
                                <option value="any">
582
                                    any library
583
                                </option>
584
                            [% END %]
585
586
                            [% IF hold_fulfillment_policy == 'holdgroup' %]
587
                                <option value="holdgroup" selected="selected">
588
                                    item's hold group
589
                                </option>
590
                            [% ELSE %]
591
                                <option value="holdgroup">
592
                                    item's hold group
593
                                </option>
594
                            [% END %]
595
596
                            [% IF hold_fulfillment_policy == 'patrongroup' %]
597
                                <option value="patrongroup" selected="selected">
598
                                    patron's hold group
599
                                </option>
600
                            [% ELSE %]
601
                                <option value="patrongroup">
602
                                    patron's hold group
603
                                </option>
604
                            [% END %]
605
606
                            [% IF hold_fulfillment_policy == 'homebranch' %]
607
                                <option value="homebranch" selected="selected">
608
                                    item's home library
609
                                </option>
610
                            [% ELSE %]
611
                                <option value="homebranch">
612
                                    item's home library
613
                                </option>
614
                            [% END %]
615
616
                            [% IF hold_fulfillment_policy == 'holdingbranch' %]
617
                                <option value="holdingbranch" selected="selected">
618
                                    item's holding library
619
                                </option>
620
                            [% ELSE %]
621
                                <option value="holdingbranch">
622
                                    item's holding library
623
                                </option>
624
                            [% END %]
625
                        </select>
626
                    </td>
627
                    <td>
628
                        <select name="returnbranch">
629
                            [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch' ) %]
630
631
                            <option value="">
632
                                Not set
633
                            </option>
634
635
                            [% IF returnbranch == 'homebranch' %]
636
                            <option value="homebranch" selected="selected">
637
                            [% ELSE %]
638
                            <option value="homebranch">
639
                            [% END %]
640
                                Item returns home
641
                            </option>
642
                            [% IF returnbranch == 'holdingbranch' %]
643
                            <option value="holdingbranch" selected="selected">
644
                            [% ELSE %]
645
                            <option value="holdingbranch">
646
                            [% END %]
647
                                Item returns to issuing library
648
                            </option>
649
                            [% IF returnbranch == 'noreturn' %]
650
                            <option value="noreturn" selected="selected">
651
                            [% ELSE %]
652
                            <option value="noreturn">
653
                            [% END %]
654
                                Item floats
655
                            </option>
656
                        </select>
657
                    </td>
658
                    <td class="actions">
659
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
660
                        <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch | html %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
661
                    </td>
662
                </tr>
663
            </table>
664
        </form>
665
    </div>
666
    [% IF ( show_branch_cat_rule_form ) %]
667
    <div id="holds-policy-by-patron-category" class="container">
668
    <h3>[% IF humanbranch %]Checkout, hold policy by patron category for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default checkout, hold policy by patron category[% END %]</h3>
669
        <p>For this library, you can specify the maximum number of loans that
670
            a patron of a given category can make, regardless of the item type.
671
        </p>
672
        <p>If the total amount loanable for a given patron category is left blank,
673
           no limit applies, except possibly for a limit you define for a specific item type.
674
        </p>
675
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
676
            <input type="hidden" name="op" value="add-branch-cat" />
677
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
678
            <table>
679
                <tr>
680
                    <th>Patron category</th>
681
                    <th>Total current checkouts allowed</th>
682
                    <th>Total current on-site checkouts allowed</th>
683
                    <th>Total holds allowed</th>
684
                    <th>&nbsp;</th>
685
                </tr>
686
                [% FOREACH c IN categorycodes %]
687
                    [% NEXT UNLESS c %]
688
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
689
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
690
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
691
692
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
693
                    <tr>
694
                        <td>
695
                            [% IF c == undef %]
696
                                <em>Default</em>
697
                            [% ELSE %]
698
                                [% Categories.GetName(c) | html %]
699
                            [% END %]
700
                        </td>
701
                        <td>
702
                            [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
703
                                [% patron_maxissueqty | html %]
704
                            [% ELSE %]
705
                                <span>Unlimited</span>
706
                            [% END %]
707
                        </td>
708
                        <td>
709
                            [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
710
                                [% patron_maxonsiteissueqty | html %]
711
                            [% ELSE %]
712
                                <span>Unlimited</span>
713
                            [% END %]
714
                        </td>
715
                        <td>
716
                            [% IF max_holds.defined && max_holds != '' %]
717
                                [% max_holds | html %]
718
                            [% ELSE %]
719
                                <span>Unlimited</span>
720
                            [% END %]
721
                        </td>
722
723
                        <td class="actions">
724
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
725
                        </td>
726
                    </tr>
727
                    [% END %]
728
                [% END %]
729
                <tr>
730
                    <td>
731
                        <select name="categorycode">
732
                        [% FOREACH patron_category IN patron_categories%]
733
                            <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
734
                        [% END %]
735
                        </select>
736
                    </td>
737
                    <td><input name="patron_maxissueqty" size="3" type="text" /></td>
738
                    <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
739
                    <td><input name="max_holds" size="3" type="text" /></td>
740
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
741
                </tr>
742
            </table>
743
        </form>
744
    </div>
745
    [% END %]
746
747
    <div id="refund-lost-item-fee-on-return" class="container">
748
        [% IF current_branch == '*' %]
749
            <h3>Default lost item fee refund on return policy</h3>
750
        [% ELSE %]
751
            <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) | html %]</h3>
752
        [% END %]
753
        <p>Specify the default policy for lost item fees on return.
754
        </p>
755
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
756
            <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
757
            <input type="hidden" name="branch" value="[% current_branch | html %]" />
758
            <table>
759
                <tr>
760
                    <th>Refund lost item fee</th>
761
                    <th>&nbsp;</th>
762
                </tr>
763
                <tr>
764
                    <td>
765
                        <select name="refund">
766
                          [%# Default branch %]
767
                          [% IF ( current_branch == '*' ) %]
768
                            [% IF ( defaultRefundRule ) %]
769
                            <option value="1" selected="selected">
770
                            [% ELSE %]
771
                            <option value="1">
772
                            [% END %]
773
                                Yes
774
                            </option>
775
                            [% IF ( not defaultRefundRule ) %]
776
                            <option value="0" selected="selected">
777
                            [% ELSE %]
778
                            <option value="0">
779
                            [% END %]
780
                                No
781
                            </option>
782
                          [% ELSE %]
783
                          [%# Branch-specific %]
784
                            [% IF ( not refundLostItemFeeRule ) %]
785
                                <option value="*" selected="selected">
786
                            [% ELSE %]
787
                                <option value="*">
788
                            [% END %]
789
                              [% IF defaultRefundRule %]
790
                                Use default (Yes)
791
                              [% ELSE %]
792
                                Use default (No)
793
                              [% END %]
794
                                </option>
795
                            [% IF ( not refundLostItemFeeRule ) %]
796
                                <option value="1">Yes</option>
797
                                <option value="0">No</option>
798
                            [% ELSE %]
799
                                [% IF ( refundLostItemFeeRule.rule_value ) %]
800
                                <option value="1" selected="selected">
801
                                [% ELSE %]
802
                                <option value="1">
803
                                [% END %]
804
                                    Yes
805
                                </option>
806
                                [% IF ( not refundLostItemFeeRule.rule_value ) %]
807
                                <option value="0" selected="selected">
808
                                [% ELSE %]
809
                                <option value="0">
810
                                [% END %]
811
                                    No
812
                                </option>
813
                            [% END %]
814
                          [% END %]
815
                        </select>
816
                    </td>
817
                    <td class="actions">
818
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
819
                    </td>
820
                    </td>
821
                </tr>
822
            </table>
823
        </form>
824
    </div>
825
826
    <div id="holds-policy-by-item-type" class="container">
827
    <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default holds policy by item type[% END %]</h3>
828
        <p>
829
            For this library, you can edit rules for given itemtypes, regardless
830
            of the patron's category.
831
        </p>
832
        <p>
833
            Currently, this means hold policies.
834
            The various policies have the following effects:
835
        </p>
836
        <ul>
837
            <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
838
            <li><strong>From local hold group:</strong> Only patrons from libraries in the same item's home library hold groups may put this book on hold.</li>
839
            <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
840
            <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
841
        </ul>
842
        <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
843
            <strong>Important: </strong>The policies are applied based on the ReservesControlBranch system preference which is set to <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ReservesControlBranch">[% Koha.Preference('ReservesControlBranch') | html %]</a>.
844
        </p>
845
846
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
847
            <input type="hidden" name="op" value="add-branch-item" />
848
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
849
            <table>
850
                <tr>
851
                    <th>Item type</th>
852
                    <th>Hold policy</th>
853
                    <th>Hold pickup library match</th>
854
                    <th>Return policy</th>
855
                    <th>&nbsp;</th>
856
                </tr>
857
                [% FOREACH i IN itemtypeloop %]
858
                    [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %]
859
                    [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
860
                    [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %]
861
862
                    [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
863
                        <tr>
864
                            <td>
865
                                [% i.translated_description | html %]
866
                            </td>
867
                            <td>
868
                                [% IF holdallowed == 2 %]
869
                                    <span>From any library</span>
870
                                [% ELSIF holdallowed == 3 %]
871
                                    <span>From local hold group</span>
872
                                [% ELSIF holdallowed == 1 %]
873
                                    <span>From home library</span>
874
                                [% ELSE %]
875
                                    <span>No holds allowed</span>
876
                                [% END %]
877
                            </td>
878
                            <td>
879
                                [% IF hold_fulfillment_policy == 'any' %]
880
                                    <span>any library</span>
881
                                [% ELSIF hold_fulfillment_policy == 'homebranch' %]
882
                                    <span>item's home library</span>
883
                                [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
884
                                    <span>item's hold group</span>
885
                                [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
886
                                    <span>patron's hold group</span>
887
                                [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
888
                                    <span>item's holding library</span>
889
                                [% END %]
890
                            </td>
891
                            <td>
892
                                [% IF returnbranch == 'homebranch' %]
893
                                    <span>Item returns home</span>
894
                                [% ELSIF returnbranch == 'holdingbranch' %]
895
                                    <span>Item returns to issuing branch</span>
896
                                [% ELSIF returnbranch == 'noreturn' %]
897
                                    <span>Item floats</span>
898
                                [% END %]
899
                            </td>
900
                            <td class="actions">
901
                                <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% i.itemtype | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
902
                            </td>
903
                        </tr>
904
                    [% END %]
905
                [% END %]
906
                <tr>
907
                    <td>
908
                        <select name="itemtype">
909
                        [% FOREACH itemtypeloo IN itemtypeloop %]
910
                            <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
911
                        [% END %]
912
                        </select>
913
                    </td>
914
                    <td>
915
                        <select name="holdallowed">
916
                            <option value="2">From any library</option>
917
                            <option value="3">From local hold group</option>
918
                            <option value="1">From home library</option>
919
                            <option value="0">No holds allowed</option>
920
                        </select>
921
                    </td>
922
                    <td>
923
                        <select name="hold_fulfillment_policy">
924
                            <option value="any">
925
                                any library
926
                            </option>
927
928
                            <option value="holdgroup">
929
                                item's hold group
930
                            </option>
931
932
                            <option value="patrongroup">
933
                                patron's hold group
934
                            </option>
935
936
                            <option value="homebranch">
937
                                item's home library
938
                            </option>
939
940
                            <option value="holdingbranch">
941
                                item's holding library
942
                            </option>
943
                        </select>
944
                    </td>
945
                    <td>
946
                        <select name="returnbranch">
947
                            <option value="homebranch">Item returns home</option>
948
                            <option value="holdingbranch">Item returns to issuing library</option>
949
                            <option value="noreturn">Item floats</option>
950
                        </select>
951
                    </td>
952
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
953
                </tr>
954
            </table>
955
        </form>
956
    </div>
957
            </main>
958
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
959
960
        <div class="col-sm-2 col-sm-pull-10">
961
            <aside>
962
                [% INCLUDE 'admin-menu.inc' %]
963
            </aside>
964
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
965
     </div> <!-- /.row -->
966
967
[% MACRO jsinclude BLOCK %]
968
    [% Asset.js("js/admin-menu.js") | $raw %]
969
    [% INCLUDE 'datatables.inc' %]
970
    [% INCLUDE 'calendar.inc' %]
971
    <script>
972
        $(document).ready(function() {
973
            $("#default-circulation-rules").dataTable($.extend(true,{},dataTablesDefaults, {
974
                "aoColumnDefs": [
975
                    { "bVisible": false, "aTargets": [ 0,2 ] },
976
                    { "bSortable": false, "aTargets": ["_all"] }
977
                ],
978
                "aaSortingFixed": [ [0,'asc'], [1,'asc'], [2,'asc'], [3,'asc'] ],
979
                "bPaginate": false,
980
                "bAutoWidth": false
981
            }));
982
        });
983
984
        function clear_edit(){
985
            var cancel = confirm(_("Are you sure you want to cancel your changes?"));
986
            if ( !cancel ) return;
987
            $('#default-circulation-rules td').removeClass('highlighted-row');
988
            var edit_row = $("#edit_row");
989
            $(edit_row).find("input").each(function(){
990
                var type = $(this).attr("type");
991
                if (type != "button" && type != "submit" ) {
992
                    $(this).val("");
993
                    $(this).prop('disabled', false);
994
                }
995
                if ( type == "checkbox" ) {
996
                    $(this).prop('checked', false);
997
                }
998
            });
999
            $(edit_row).find("select").prop('disabled', false);
1000
            $(edit_row).find("select option:first-child").attr("selected", "selected");
1001
            $(edit_row).find("td:last input[name='clear']").remove();
1002
        }
1003
1004
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
1005
1006
        $(document).ready(function() {
1007
            $('[data-toggle="popover"]').popover();
1008
1009
            $(".delete").on("click",function(){
1010
                return confirmDelete(MSG_CONFIRM_DELETE);
1011
            });
1012
1013
            $("#clone_rules").on("click",function(){
1014
                var library_dropdown = document.getElementById("branch");
1015
                var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
1016
                var selected_library_text = $("#branch option:selected").text();
1017
                var to_library = $("#tobranch option:selected").text();
1018
                var MSG_CONFIRM_CLONE;
1019
                if (selected_library === "*") {
1020
                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this standard rule to %s library? This will override the existing rules in this library.").format(to_library);
1021
                    return confirmClone(MSG_CONFIRM_CLONE);
1022
                } else {
1023
                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this circulation and fine rule from %s to %s library? This will override the existing rules in this library.").format(selected_library_text, to_library);
1024
                    return confirmClone(MSG_CONFIRM_CLONE);
1025
                }
1026
            });
1027
1028
            $('#selectlibrary').find("input:submit").hide();
1029
            $('#branch').change(function() {
1030
                    $('#selectlibrary').submit();
1031
            });
1032
            $(".editrule").click(function(){
1033
                if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
1034
                    var edit = confirm(_("Are you sure you want to edit another rule?"));
1035
                    if (!edit) return false;
1036
                }
1037
                $('#default-circulation-rules td').removeClass('highlighted-row');
1038
                $(this).parent().parent().find("td").each(function (i) {
1039
                    $(this).addClass('highlighted-row');
1040
                    itm = $(this).text();
1041
                    itm = itm.replace(/^\s*|\s*$/g,'');
1042
                    var current_column = $("#edit_row td:eq("+i+")");
1043
                    if ( i == 3 ) {
1044
                        // specific processing for the Note column
1045
                        var note = $(this).find("a[name='viewnote']").data("content");
1046
                        $(current_column).find("input[type='text']").val(note);
1047
                    } else if ( i == 9 ) {
1048
                        // specific processing for the Hard due date column
1049
                        var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
1050
                        var input_value = '';
1051
                        if (typeof select_value === 'undefined'){
1052
                            select_value = '-1';
1053
                        }else {
1054
                            input_value = itm.split(' ')[1];
1055
                        }
1056
                        $(current_column).find("input[type='text']").val(input_value);
1057
                        $(current_column).find("select").val(select_value);
1058
                    } else if ( i == 15 ) {
1059
                        // specific processing for cap_fine_to_replacement_price
1060
                        var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
1061
                        $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
1062
                        $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
1063
                    } else {
1064
                        $(current_column).find("input[type='text']").val(itm);
1065
                        // select the corresponding option
1066
                        $(current_column).find("select option").each(function(){
1067
                            opt = $(this).text().toLowerCase();
1068
                            itm = itm.replace(/.*->(.*)/,"$1"); //If item type is part of a group we need to clear the parent description
1069
                            opt = opt.replace(/^\s*|\s*$/g,'');
1070
                            if ( opt == itm.toLowerCase() ) {
1071
                                $(this).attr('selected', 'selected');
1072
                            }
1073
                        });
1074
                        if ( i == 0 || i == 1 ) {
1075
                            // Disable the 2 first columns, we cannot update them.
1076
                            var val = $(current_column).find("select option:selected").val();
1077
                            var name = "categorycode";
1078
                            if ( i == 1 ) {
1079
                                name="itemtype";
1080
                            }
1081
                            // Remove potential previous input added
1082
                            $(current_column).find("input").remove();
1083
                            $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
1084
                        } else if ( i == 5 || i == 6 || i == 25 || i == 26 || i == 27 ) {
1085
                            // If the value is not an integer for
1086
                            //     - "Current checkouts allowed"
1087
                            //     - "Current on-site checkouts allowed"
1088
                            //     - "Holds allowed (total)"
1089
                            //     - "Holds allowed (daily)"
1090
                            //     - "Holds per record (count)"
1091
                            // The value is "Unlimited" (or an equivalent translated string)
1092
                            // an it should be set to an empty string
1093
                            if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
1094
                                $(current_column).find("input[type='text']").val("");
1095
                            }
1096
                        }
1097
                    }
1098
                });
1099
                $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
1100
                $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
1101
                return false;
1102
            });
1103
            $(".clear_edit").on("click",function(e){
1104
                e.preventDefault();
1105
                clear_edit();
1106
            });
1107
        });
1108
    </script>
1109
[% END %]
1110
[% INCLUDE 'intranet-bottom.inc' %]
1111
- 

Return to bug 15522