Bug 27631: (follow-up) Various corrections
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / smart-rules.tt
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>Circulation and fine rules &rsaquo; Administration &rsaquo; Koha</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 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
35     <ol>
36         <li>
37             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
38         </li>
39         <li>
40             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
41         </li>
42         <li>
43             <a href="#" aria-current="page">
44                 Circulation and fine rules
45             </a>
46         </li>
47     </ol>
48 </nav>
49
50 <div class="main container-fluid">
51     <div class="row">
52         <div class="col-sm-10 col-sm-push-2">
53             <main>
54
55     <h1 class="parameters">
56         [% IF humanbranch %]
57             Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) | html %]"
58         [% ELSE %]
59             Defining circulation and fine rules for all libraries
60         [% END %]
61     </h1>
62     <div class="help">
63         <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
64         <ul>
65             <li>same library, same patron category, same item type</li>
66             <li>same library, same patron category, all item types</li>
67             <li>same library, all patron categories, same item type</li>
68             <li>same library, all patron categories, all item types</li>
69             <li>default (all libraries), same patron category, same item type</li>
70             <li>default (all libraries), same patron category, all item types</li>
71             <li>default (all libraries), all patron categories, same item type</li>
72             <li>default (all libraries), all patron categories, all item types</li>
73         </ul>
74
75         <p>Where an itemtype has a parent, the rule will display as "Parent->Child" and the number of
76         current checkouts allowed will be limited to either the maximum for the parent (counting sibling types)
77         or the specific rule's type, whichever is less.</p>
78         <p>To modify a rule, create a new one with the same patron category and item type.</p>
79     </div>
80     <div>
81         [% UNLESS restricted_to_own_library %]
82             <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
83             Select a library :
84                 <select name="branch" id="branch" style="width:20em;">
85                     <option value="*">Standard rules for all libraries</option>
86                     [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
87                 </select>
88             </form>
89             [% IF ( definedbranch ) %]
90                 <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
91                     <label for="tobranch"><strong>Clone these rules to:</strong></label>
92                     <input type="hidden" name="frombranch" value="[% current_branch | html %]" />
93                     <select name="tobranch" id="tobranch">
94                         [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
95                     </select>
96                     <input type="submit" id="clone_rules" value="Clone" />
97                 </form>
98             [% END %]
99         [% END %]
100
101         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
102             <input type="hidden" name="op" value="add" />
103             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
104             <table id="default-circulation-rules">
105             <thead>
106             <tr>
107                 <th>&nbsp;</th>
108                 <th class="fixed_sort">Patron category</th>
109                 <th>&nbsp;</th>
110                 <th class="fixed_sort">Item type</th>
111                 <th class="noExport">Actions</th>
112                 <th>Note</th>
113                 <th>Current checkouts allowed</th>
114                 <th>Current on-site checkouts allowed</th>
115                 <th>Loan period</th>
116                 <th>Days mode</th>
117                 <th>Unit</th>
118                 <th>Hard due date</th>
119                 <th>Decreased loan period for high holds (day)</th>
120                 <th>Fine amount</th>
121                 <th>Fine charging interval</th>
122                 <th>When to charge</th>
123                 <th>Fine grace period</th>
124                 <th>Overdue fines cap (amount)</th>
125                 <th>Cap fine at replacement price</th>
126                 <th>Suspension in days (day)</th>
127                 <th>Max. suspension duration (day)</th>
128                 <th>Suspension charging interval</th>
129                 <th>Renewals allowed (count)</th>
130                 [% IF Koha.Preference('UnseenRenewals') %]
131                 <th>Unseen renewals allowed (count)</th>
132                 [% END %]
133                 <th>Renewal period</th>
134                 <th>No renewal before</th>
135                 <th>Automatic renewal</th>
136                 <th>No automatic renewal after</th>
137                 <th>No automatic renewal after (hard limit)</th>
138                 <th>Holds allowed (total)</th>
139                 <th>Holds allowed (daily)</th>
140                 <th>Holds per record (count)</th>
141                 <th>On shelf holds allowed</th>
142                 <th>OPAC item level holds</th>
143                 <th>Article requests</th>
144                 <th>Rental discount (%)</th>
145                 [% IF Koha.Preference('UseRecalls') %]
146                     <th>Recalls allowed (total)</th>
147                     <th>Recalls per record (count)</th>
148                     <th>On shelf recalls allowed</th>
149                     <th>Recall due date interval (day)</th>
150                     <th>Recall overdue fine amount</th>
151                     <th>Recall pickup period (day)</th>
152                 [% END %]
153                 <th class="noExport">Actions</th>
154             </tr>
155             </thead>
156             <tbody>
157                 [% SET row_count = 0 %]
158                 [% FOREACH c IN categorycodes %]
159                     [% SET c = '' UNLESS c.defined %]
160                     [% FOREACH i IN itemtypes %]
161                         [% SET i = '' UNLESS i.defined %]
162                         [% SET note = all_rules.$c.$i.note %]
163                         [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
164                         [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
165                         [% SET issuelength = all_rules.$c.$i.issuelength %]
166                         [% SET daysmode = all_rules.$c.$i.daysmode %]
167                         [% SET lengthunit = all_rules.$c.$i.lengthunit %]
168                         [% SET hardduedate = all_rules.$c.$i.hardduedate %]
169                         [% SET hardduedatecompare = all_rules.$c.$i.hardduedatecompare %]
170                         [% SET fine = all_rules.$c.$i.fine %]
171                         [% SET chargeperiod = all_rules.$c.$i.chargeperiod %]
172                         [% SET chargeperiod_charge_at = all_rules.$c.$i.chargeperiod_charge_at %]
173                         [% SET firstremind = all_rules.$c.$i.firstremind %]
174                         [% SET overduefinescap = all_rules.$c.$i.overduefinescap %]
175                         [% SET cap_fine_to_replacement_price = all_rules.$c.$i.cap_fine_to_replacement_price %]
176                         [% SET finedays = all_rules.$c.$i.finedays %]
177                         [% SET maxsuspensiondays = all_rules.$c.$i.maxsuspensiondays %]
178                         [% SET suspension_chargeperiod = all_rules.$c.$i.suspension_chargeperiod %]
179                         [% SET renewalsallowed = all_rules.$c.$i.renewalsallowed %]
180                         [% SET unseenrenewalsallowed = all_rules.$c.$i.unseen_renewals_allowed %]
181                         [% SET renewalperiod = all_rules.$c.$i.renewalperiod %]
182                         [% SET norenewalbefore = all_rules.$c.$i.norenewalbefore %]
183                         [% SET auto_renew = all_rules.$c.$i.auto_renew %]
184                         [% SET no_auto_renewal_after = all_rules.$c.$i.no_auto_renewal_after %]
185                         [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.no_auto_renewal_after_hard_limit %]
186                         [% SET reservesallowed = all_rules.$c.$i.reservesallowed %]
187                         [% SET holds_per_day = all_rules.$c.$i.holds_per_day %]
188                         [% SET holds_per_record = all_rules.$c.$i.holds_per_record %]
189                         [% SET onshelfholds = all_rules.$c.$i.onshelfholds %]
190                         [% SET opacitemholds = all_rules.$c.$i.opacitemholds %]
191                         [% SET article_requests = all_rules.$c.$i.article_requests %]
192                         [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %]
193                         [% SET decreaseloanholds = all_rules.$c.$i.decreaseloanholds %]
194                         [% SET recalls_allowed = all_rules.$c.$i.recalls_allowed %]
195                         [% SET recalls_per_record = all_rules.$c.$i.recalls_per_record %]
196                         [% SET on_shelf_recalls = all_rules.$c.$i.on_shelf_recalls %]
197                         [% SET recall_due_date_interval = all_rules.$c.$i.recall_due_date_interval %]
198                         [% SET recall_overdue_fine = all_rules.$c.$i.recall_overdue_fine %]
199                         [% SET recall_shelf_time = all_rules.$c.$i.recall_shelf_time %]
200
201                         [% 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 || unseenrenewalsallowed || 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 || decreaseloanholds || recalls_allowed || recalls_per_record || on_shelf_recalls || recall_due_date_interval || recall_overdue_fine || recall_shelf_time %]
202                         [% IF show_rule %]
203                             [% SET row_count = row_count + 1 %]
204                             <tr row_countd="row_[% row_count | html %]">
205                                     <td>[% IF ( c == undef ) %]1[% ELSE %]0[% END %]</td>
206                                     <td>
207                                         [% IF c == undef %]
208                                             <em>All</em>
209                                         [% ELSE %]
210                                             [% Categories.GetName(c) | html %]
211                                         [% END %]
212                                     </td>
213                                     <td>[% IF ( i == undef ) %]1[% ELSE %]0[% END %]</td>
214                                     <td>
215                                         [% IF i == undef %]
216                                             <em>All</em>
217                                         [% ELSE %]
218                                             [% ItemTypes.GetDescription(i,1) | html %]
219                                         [% END %]
220                                     </td>
221                                     <td class="actions">
222                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
223                                       <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>
224                                     </td>
225                                     <td>
226                                         [% IF note.defined && note != '' %]
227                                             <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
228                                         [% ELSE %]<span>&nbsp;</span>[% END %]
229                                     </td>
230                                     <td>
231                                         [% IF maxissueqty.defined && maxissueqty != '' %]
232                                             [% maxissueqty | html %]
233                                         [% ELSE %]
234                                             <span>Unlimited</span>
235                                         [% END %]
236                                     </td>
237                                     <td>
238                                         [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
239                                             [% maxonsiteissueqty | html %]
240                                         [% ELSE %]
241                                             <span>Unlimited</span>
242                                         [% END %]
243                                     </td>
244                                     <td>[% issuelength | html %]</td>
245                                     <td>
246                                         [% SWITCH daysmode %]
247                                         [% CASE 'Calendar' %]<span title="Use the calendar to skip days the library is closed">Skip closed days</span>
248                                         [% CASE 'Datedue' %]<span title="Use the calendar to push the due date to the next open day">Next open day</span>
249                                         [% CASE 'Days' %]<span title="Ignore the calendar">Ignore the calendar</span>
250                                         [% 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">Same week day</span>
251                                         [% CASE %]<span title="Use the system preference 'useDaysMode' as a default value">Default</span>
252                                         [% END %]
253                                     </td>
254                                     <td>
255                                         [% IF ( lengthunit == 'days' ) %]
256                                             Days
257                                         [% ELSIF ( lengthunit == 'hours') %]
258                                             Hours
259                                         [% ELSE %]
260                                             Undefined
261                                         [% END %]
262                                     </td>
263                                     <td>
264                                       [% IF ( hardduedate ) %]
265                                         [% IF ( hardduedatecompare == '-1' ) %]
266                                           before [% hardduedate | $KohaDates %]
267                                           <input type="hidden" name="hardduedatecomparebackup" value="-1" />
268                                         [% ELSIF ( hardduedatecompare == '0' ) %]
269                                           on [% hardduedate | $KohaDates %]
270                                           <input type="hidden" name="hardduedatecomparebackup" value="0" />
271                                         [% ELSIF ( hardduedatecompare == '1' ) %]
272                                           after [% hardduedate | $KohaDates %]
273                                           <input type="hidden" name="hardduedatecomparebackup" value="1" />
274                                         [% END %]
275                                       [% ELSE %]
276                                         <span>None defined</span>
277                                       [% END %]
278                                     </td>
279                                     <td>[% decreaseloanholds | html %]</td>
280                                     <td>[% fine | html %]</td>
281                                     <td>[% chargeperiod | html %]</td>
282                                     <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
283                                     <td>[% firstremind | html %]</td>
284                                     <td>[% overduefinescap FILTER format("%.2f") %]</td>
285                                     <td>
286                                         [% IF cap_fine_to_replacement_price %]
287                                             <input type="checkbox" checked="checked" disabled="disabled" />
288                                         [% ELSE %]
289                                             <input type="checkbox" disabled="disabled" />
290                                         [% END %]
291                                     </td>
292                                     <td>[% finedays | html %]</td>
293                                     <td>[% maxsuspensiondays | html %]</td>
294                                     <td>[% suspension_chargeperiod | html %]</td>
295                                     <td>[% renewalsallowed | html %]</td>
296                                     [% IF Koha.Preference('UnseenRenewals') %]
297                                         <td>[% unseenrenewalsallowed | html %]</td>
298                                     [% END %]
299                                     <td>[% renewalperiod | html %]</td>
300                                     <td>[% norenewalbefore | html %]</td>
301                                     <td>
302                                         [% IF auto_renew %]
303                                             <span>Yes</span>
304                                         [% ELSE %]
305                                             <span>No</span>
306                                         [% END %]
307                                     </td>
308                                     <td>[% no_auto_renewal_after | html %]</td>
309                                     <td>[% no_auto_renewal_after_hard_limit | $KohaDates %]</td>
310                                     <td>
311                                         [% IF reservesallowed.defined && reservesallowed != '' %]
312                                             [% reservesallowed | html %]
313                                         [% ELSE %]
314                                             <span>Unlimited</span>
315                                         [% END %]
316                                     </td>
317                                     <td>
318                                         [% IF holds_per_day.defined && holds_per_day != '' %]
319                                             [% holds_per_day | html %]
320                                         [% ELSE %]
321                                             <span>Unlimited</span>
322                                         [% END %]
323                                     </td>
324                                     <td>
325                                         [% IF holds_per_record.defined && holds_per_record != '' %]
326                                             [% holds_per_record | html %]
327                                         [% ELSE %]
328                                             <span>Unlimited</span>
329                                         [% END %]
330                                     </td>
331                                     <td>
332                                         [% IF onshelfholds == 1 %]
333                                             <span>Yes</span>
334                                         [% ELSIF onshelfholds == 2 %]
335                                             <span>If all unavailable</span>
336                                         [% ELSE %]
337                                             <span>If any unavailable</span>
338                                         [% END %]
339                                     </td>
340                                     <td>
341                                         [% IF opacitemholds == 'F'%]
342                                             <span>Force</span>
343                                         [% ELSIF opacitemholds == 'Y'%]
344                                             <span>Allow</span>
345                                         [% ELSE %]
346                                             <span>Don't allow</span>
347                                         [% END %]
348                                     </td>
349                                     <td>
350                                         [% IF article_requests == 'no' %]
351                                             <span>No</span>
352                                         [% ELSIF article_requests == 'yes' %]
353                                             <span>Yes</span>
354                                         [% ELSIF article_requests == 'bib_only' %]
355                                             <span>Record only</span>
356                                         [% ELSIF article_requests == 'item_only' %]
357                                             <span>Item only</span>
358                                         [% END %]
359                                     </td>
360                                     <td>[% rentaldiscount | html %]</td>
361                                     [% IF Koha.Preference('UseRecalls') %]
362                                         <td>[% recalls_allowed | html %]</td>
363                                         <td>[% recalls_per_record | html %]</td>
364                                         <td>
365                                             [% IF on_shelf_recalls == 'all' %]
366                                                 <span>If all unavailable</span>
367                                             [% ELSE %]
368                                                 <span>If any unavailable</span>
369                                             [% END %]
370                                         </td>
371                                         <td>[% recall_due_date_interval | html %]</td>
372                                         <td>[% recall_overdue_fine FILTER format("%.2f") %]</td>
373                                         <td>[% recall_shelf_time | html %]</td>
374                                     [% END %]
375                                     <td class="actions">
376                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
377                                       <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>
378                                     </td>
379                             </tr>
380                         [% END %]
381                     [% END %]
382                 [% END %]
383                 <tr id="edit_row">
384                     <td>2</td>
385                     <td>
386                         <select name="categorycode" id="categorycode">
387                             <option value="*">All</option>
388                         [% FOREACH patron_category IN patron_categories%]
389                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
390                         [% END %]
391                         </select>
392                     </td>
393                     <td>0</td>
394                     <td>
395                         <select name="itemtype" id="matrixitemtype" style="width:13em;">
396                             <option value="*">All</option>
397                             [% FOREACH itemtypeloo IN itemtypeloop %]
398                                 [% NEXT IF itemtypeloo.parent_type %]
399                                 [% SET children = itemtypeloo.children_with_localization %]
400                                 [% IF children.count %]
401                                     <optgroup label="[% itemtypeloo.translated_description | html %]">
402                                         <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %] (All)</option>
403                                         [% FOREACH child IN children %]
404                                             <option value="[% child.itemtype | html %]">[% child.translated_description | html %]</option>
405                                         [% END %]
406                                     </optgroup>
407                                 [% ELSE %]
408                                     <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
409                                 [% END %]
410                             [% END %]
411                         </select>
412                     </td>
413                     <td class="actions">
414                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
415                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
416                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
417                     </td>
418                     <td><input type="text" name="note" id="note" size="15" value="" maxlength="100"></td>
419                     <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
420                     <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
421                     <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
422                     <td>
423                         <select name="daysmode" id="daysmode">
424                             <option value="" title="Use the system preference 'useDaysMode' as a default value">Default</option>
425                             <option value="Calendar" title="Use the calendar to skip days the library is closed">Skip closed days</option>
426                             <option value="Datedue" title="Use the calendar to push the due date to the next open day">Next open day</option>
427                             <option value="Days" title="Ignore the calendar">Ignore the calendar</option>
428                             <option value="Dayweek" 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">Same week day</option>
429                         </select>
430                     </td>
431                     <td>
432                       <select name="lengthunit" id="lengthunit">
433                         <option value="days" selected="selected">Days</option>
434                         <option value="hours">Hours</option>
435                       </select>
436                     </td>
437                     <td>
438                         <select name="hardduedatecompare" id="hardduedatecompare">
439                            <option value="-1">Before</option>
440                            <option value="0">Exactly on</option>
441                            <option value="1">After</option>
442                         </select>
443                         <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="flatpickr" />
444                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
445                     </td>
446                     <td><input type="text" name="decreaseloanholds" id="decreaseloanholds" size="2" /></td>
447                     <td><input type="text" name="fine" id="fine" size="4" /></td>
448                     <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
449                     <td>
450                         <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
451                            <option value="0">End of interval</option>
452                            <option value="1">Start of interval</option>
453                         </select>
454                     </td>
455                     <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
456                     <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
457                     <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
458                     <td><input type="text" name="finedays" id="fined" size="3" /> </td>
459                     <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
460                     <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
461                     <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
462                     [% IF Koha.Preference('UnseenRenewals') %]
463                         <td><input type="text" name="unseen_renewals_allowed" id="unseen_renewals_allowed" size="2" /></td>
464                     [% END %]
465                     <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
466                     <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
467                     <td>
468                         <select name="auto_renew" id="auto_renew">
469                             <option value="no" selected>No</option>
470                             <option value="yes">Yes</option>
471                         </select>
472                     </td>
473                     <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
474                     <td>
475                         <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="flatpickr"/>
476                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
477                     </td>
478                     <td><input type="text" name="reservesallowed"  id="reservesallowed"  size="2" /></td>
479                     <td><input type="text" name="holds_per_day"    id="holds_per_day"    size="2" /></td>
480                     <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
481                     <td>
482                         <select name="onshelfholds" id="onshelfholds">
483                             <option value="1">Yes</option>
484                             <option value="0">If any unavailable</option>
485                             <option value="2">If all unavailable</option>
486                         </select>
487                     </td>
488                     <td>
489                         <select id="opacitemholds" name="opacitemholds">
490                             <option value="N">Don't allow</option>
491                             <option value="Y">Allow</option>
492                             <option value="F">Force</option>
493                         </select>
494                     </td>
495                     <td>
496                         <select id="article_requests" name="article_requests">
497                             <option value="no">No</option>
498                             <option value="yes">Yes</option>
499                             <option value="bib_only">Record only</option>
500                             <option value="item_only">Item only</option>
501                         </select>
502                     </td>
503                     <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
504                     [% IF Koha.Preference('UseRecalls') %]
505                         <td><input type="text" name="recalls_allowed" id="recalls_allowed" size="3"></td>
506                         <td><input type="text" name="recalls_per_record" id="recalls_per_record" size="3"></td>
507                         <td>
508                             <select name="on_shelf_recalls" id="on_shelf_recalls">
509                                 <option value="any">If any unavailable</option>
510                                 <option value="all">If all unavailable</option>
511                             </select>
512                         </td>
513                         <td><input type="text" name="recall_due_date_interval" id="recall_due_date_interval" size="3"></td>
514                         <td><input type="text" name="recall_overdue_fine" id="recall_overdue_fine" size="6"></td>
515                         <td><input type="text" name="recall_shelf_time" id="recall_shelf_time" size="3"></td>
516                     [% END %]
517                     <td class="actions">
518                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
519                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
520                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
521                     </td>
522                 </tr>
523                 <tfoot>
524                     <tr>
525                       <th>&nbsp;</th>
526                       <th>Patron category</th>
527                       <th>&nbsp;</th>
528                       <th>Item type</th>
529                       <th>&nbsp;</th>
530                       <th>Note</th>
531                       <th>Current checkouts allowed</th>
532                       <th>Current on-site checkouts allowed</th>
533                       <th>Loan period</th>
534                       <th>Days mode</th>
535                       <th>Unit</th>
536                       <th>Hard due date</th>
537                       <th>Decreased loan period for high holds (day)</th>
538                       <th>Fine amount</th>
539                       <th>Fine charging interval</th>
540                       <th>Charge when?</th>
541                       <th>Fine grace period</th>
542                       <th>Overdue fines cap (amount)</th>
543                       <th>Cap fine at replacement price</th>
544                       <th>Suspension in days (day)</th>
545                       <th>Max. suspension duration (day)</th>
546                       <th>Suspension charging interval</th>
547                       <th>Renewals allowed (count)</th>
548                       [% IF Koha.Preference('UnseenRenewals') %]
549                       <th>Unseen renewals allowed (count)</th>
550                       [% END %]
551                       <th>Renewal period</th>
552                       <th>No renewal before</th>
553                       <th>Automatic renewal</th>
554                       <th>No automatic renewal after</th>
555                       <th>No automatic renewal after (hard limit)</th>
556                       <th>Holds allowed (total)</th>
557                       <th>Holds allowed (daily)</th>
558                       <th>Holds per record (count)</th>
559                       <th>On shelf holds allowed</th>
560                       <th>OPAC item level holds</th>
561                       <th>Article requests</th>
562                       <th>Rental discount (%)</th>
563                       [% IF Koha.Preference('UseRecalls') %]
564                         <th>Recalls allowed (total)</th>
565                         <th>Recalls per record (count)</th>
566                         <th>On shelf recalls allowed</th>
567                         <th>Recall due date interval (day)</th>
568                         <th>Recall overdue fine amount</th>
569                         <th>Recall pickup period (day)</th>
570                       [% END %]
571                       <th>&nbsp;</th>
572                     </tr>
573                   </tfoot>
574                 </tbody>
575             </table>
576         </form>
577     </div>
578     <div id="defaults-for-this-library" class="container">
579     <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) | html %][% END %]</h3>
580         <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>
581         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
582             <input type="hidden" name="op" value="set-branch-defaults" />
583             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
584             <table>
585                 <tr>
586                     <th>&nbsp;</th>
587                     <th>Total current checkouts allowed</th>
588                     <th>Total current on-site checkouts allowed</th>
589                     <th>Maximum total holds allowed (count)</th>
590                     <th>Hold policy</th>
591                     <th>Hold pickup library match</th>
592                     <th>Return policy</th>
593                     <th class="noExport">Actions</th>
594                 </tr>
595                 [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty', { want_rule => 1 } ) %]
596                 [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty', { want_rule => 1 } ) %]
597                 [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds', { want_rule => 1 } ) %]
598                 [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed', { want_rule => 1 } ) %]
599                 [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy', { want_rule => 1 }) %]
600                 [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch', { want_rule => 1 }) %]
601                 [% SET default_checkout_hold_and_return_policy = ( patron_maxissueqty || patron_maxonsiteissueqty || rule_value || holdallowed || hold_fulfillment_policy || returnbranch ) %]
602                 <tr>
603                     <td>
604                         [% IF ( default_checkout_hold_and_return_policy ) %]
605                             <em>
606                             Defaults
607                             </em>
608                         [% ELSE %]
609                             Not set
610                         [% END %]
611                     </td>
612                     <td>
613                         <input type="text" name="patron_maxissueqty" size="9" value="[% patron_maxissueqty.rule_value | html %]" placeholder="Unlimited"/>
614                     </td>
615                     <td>
616                         <input type="text" name="patron_maxonsiteissueqty" size="9" value="[% patron_maxonsiteissueqty.rule_value | html %]" placeholder="Unlimited"/>
617                     </td>
618                     <td>
619                         <input name="max_holds" size="9" value="[% rule_value.rule_value | html %]" placeholder="Unlimited"/>
620                     </td>
621                     <td>
622                         <select name="holdallowed">
623                             <option value="">
624                                 Not set
625                             </option>
626
627                             [% IF holdallowed.rule_value == 'from_any_library' %]
628                                 <option value="from_any_library" selected="selected">
629                             [% ELSE %]
630                                 <option value="from_any_library">
631                             [% END %]
632                                 From any library
633                             </option>
634
635                             [% IF holdallowed.rule_value == 'from_local_hold_group' %]
636                             <option value="from_local_hold_group" selected="selected">
637                             [% ELSE %]
638                             <option value="from_local_hold_group">
639                             [% END %]
640                                 From local hold group
641                             </option>
642
643                             [% IF holdallowed.rule_value == 'from_home_library' %]
644                                 <option value="from_home_library" selected="selected">
645                             [% ELSE %]
646                                 <option value="from_home_library">
647                             [% END %]
648                                 From home library
649                             </option>
650
651                             [% IF holdallowed.rule_value == 'not_allowed' %]
652                                 <option value="not_allowed" selected="selected">
653                             [% ELSE %]
654                                 <option value="not_allowed">
655                             [% END %]
656                                 No holds allowed
657                             </option>
658                         </select>
659                     </td>
660                     <td>
661                         <select name="hold_fulfillment_policy">
662
663                             <option value="">
664                                 Not set
665                             </option>
666
667                             [% IF hold_fulfillment_policy.rule_value == 'any' %]
668                                 <option value="any" selected="selected">
669                                     any library
670                                 </option>
671                             [% ELSE %]
672                                 <option value="any">
673                                     any library
674                                 </option>
675                             [% END %]
676
677                             [% IF hold_fulfillment_policy.rule_value == 'holdgroup' %]
678                                 <option value="holdgroup" selected="selected">
679                                     item's hold group
680                                 </option>
681                             [% ELSE %]
682                                 <option value="holdgroup">
683                                     item's hold group
684                                 </option>
685                             [% END %]
686
687                             [% IF hold_fulfillment_policy.rule_value == 'patrongroup' %]
688                                 <option value="patrongroup" selected="selected">
689                                     patron's hold group
690                                 </option>
691                             [% ELSE %]
692                                 <option value="patrongroup">
693                                     patron's hold group
694                                 </option>
695                             [% END %]
696
697                             [% IF hold_fulfillment_policy.rule_value == 'homebranch' %]
698                                 <option value="homebranch" selected="selected">
699                                     item's home library
700                                 </option>
701                             [% ELSE %]
702                                 <option value="homebranch">
703                                     item's home library
704                                 </option>
705                             [% END %]
706
707                             [% IF hold_fulfillment_policy.rule_value == 'holdingbranch' %]
708                                 <option value="holdingbranch" selected="selected">
709                                     item's holding library
710                                 </option>
711                             [% ELSE %]
712                                 <option value="holdingbranch">
713                                     item's holding library
714                                 </option>
715                             [% END %]
716                         </select>
717                     </td>
718                     <td>
719                         <select name="returnbranch">
720
721                             <option value="">
722                                 Not set
723                             </option>
724
725                             [% IF returnbranch.rule_value == 'homebranch' %]
726                             <option value="homebranch" selected="selected">
727                             [% ELSE %]
728                             <option value="homebranch">
729                             [% END %]
730                                 Item returns home
731                             </option>
732                             [% IF returnbranch.rule_value == 'holdingbranch' %]
733                             <option value="holdingbranch" selected="selected">
734                             [% ELSE %]
735                             <option value="holdingbranch">
736                             [% END %]
737                                 Item returns to issuing library
738                             </option>
739                             [% IF returnbranch.rule_value == 'noreturn' %]
740                             <option value="noreturn" selected="selected">
741                             [% ELSE %]
742                             <option value="noreturn">
743                             [% END %]
744                                 Item floats
745                             </option>
746                         </select>
747                     </td>
748                     <td class="actions">
749                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
750                         [% IF ( default_checkout_hold_and_return_policy ) %]
751                             <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>
752                         [% END %]
753                     </td>
754                 </tr>
755             </table>
756         </form>
757     </div>
758     [% IF ( show_branch_cat_rule_form ) %]
759     <div id="holds-policy-by-patron-category" class="container">
760     <h3>[% IF humanbranch %]Checkout, hold policy by patron category for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default checkout, hold policy by patron category[% END %]</h3>
761         <p>For this library, you can specify the maximum number of loans that
762             a patron of a given category can make, regardless of the item type.
763         </p>
764         <p>If the total amount loanable for a given patron category is left blank,
765            no limit applies, except possibly for a limit you define for a specific item type.
766         </p>
767         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
768             <input type="hidden" name="op" value="add-branch-cat" />
769             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
770             <table>
771                 <tr>
772                     <th>Patron category</th>
773                     <th>Total current checkouts allowed</th>
774                     <th>Total current on-site checkouts allowed</th>
775                     <th>Total holds allowed</th>
776                     <th>&nbsp;</th>
777                 </tr>
778                 [% FOREACH c IN categorycodes %]
779                     [% NEXT UNLESS c %]
780                     [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
781                     [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
782                     [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
783
784                     [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
785                     <tr>
786                         <td>
787                             [% IF c == undef %]
788                                 <em>Default</em>
789                             [% ELSE %]
790                                 [% Categories.GetName(c) | html %]
791                             [% END %]
792                         </td>
793                         <td>
794                             [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
795                                 [% patron_maxissueqty | html %]
796                             [% ELSE %]
797                                 <span>Unlimited</span>
798                             [% END %]
799                         </td>
800                         <td>
801                             [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
802                                 [% patron_maxonsiteissueqty | html %]
803                             [% ELSE %]
804                                 <span>Unlimited</span>
805                             [% END %]
806                         </td>
807                         <td>
808                             [% IF max_holds.defined && max_holds != '' %]
809                                 [% max_holds | html %]
810                             [% ELSE %]
811                                 <span>Unlimited</span>
812                             [% END %]
813                         </td>
814
815                         <td class="actions">
816                             <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>
817                         </td>
818                     </tr>
819                     [% END %]
820                 [% END %]
821                 <tr>
822                     <td>
823                         <select name="categorycode">
824                         [% FOREACH patron_category IN patron_categories%]
825                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
826                         [% END %]
827                         </select>
828                     </td>
829                     <td><input name="patron_maxissueqty" size="3" type="text" /></td>
830                     <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
831                     <td><input name="max_holds" size="3" type="text" /></td>
832                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
833                 </tr>
834             </table>
835         </form>
836     </div>
837     [% END %]
838
839 [% IF Koha.Preference('ArticleRequests') %]
840     <div id="open-article-requests-limit-patron-category" class="container">
841     [% IF humanbranch %]
842         <h3>Daily open article requests limit for [% Branches.GetName( humanbranch ) | html %]</h3>
843     [% ELSE %]
844         <h3>Default open article requests limit</h3>
845     [% END %]
846         <p>Specify the maximum number simultaneous current article requests a patron of a given category can have.</p>
847         <form id="set-article-requests-daily-limit" method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
848             <input type="hidden" name="op" value="add-open-article-requests-limit" />
849             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
850             <table>
851                 <tr>
852                     <th>Patron category</th>
853                     <th>Total article requests</th>
854                     <th>&nbsp;</th>
855                 </tr>
856                 [% FOREACH c IN categorycodes %]
857                     [% NEXT UNLESS c %]
858                     [% SET open_article_requests_limit = CirculationRules.Search( branchcode, c, undef, 'open_article_requests_limit' ) %]
859
860                     [% IF ( open_article_requests_limit.defined && open_article_requests_limit != '' ) %]
861                     <tr>
862                         <td>
863                             [% Categories.GetName(c) | html %]
864                         </td>
865                         <td>
866                             [% IF open_article_requests_limit.defined && open_article_requests_limit != '' %]
867                                 [% open_article_requests_limit | html %]
868                             [% ELSE %]
869                                 <span>Unlimited</span>
870                             [% END %]
871                         </td>
872
873                         <td class="actions">
874                             <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=del-open-article-requests-limit&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
875                         </td>
876                     </tr>
877                     [% END %]
878                 [% END %]
879                 <tr>
880                     <td>
881                         <select name="categorycode">
882                         [% FOREACH patron_category IN patron_categories %]
883                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
884                         [% END %]
885                         </select>
886                     </td>
887                     <td><input name="open_article_requests_limit" size="3" type="text" /></td>
888                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
889                 </tr>
890             </table>
891         </form>
892     </div>
893     <div id="article-request-fee-category" class="container">
894     [% IF humanbranch %]
895         <h3>Article request fees for [% Branches.GetName( humanbranch ) | html %]</h3>
896     [% ELSE %]
897         <h3>Default article request fees</h3>
898     [% END %]
899         <p>Specify the article request fee for a given patron category.</p>
900         <form id="set-article-request-fee" method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
901             <input type="hidden" name="op" value="set-article-request-fee" />
902             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
903             <table>
904                 <tr>
905                     <th>Patron category</th>
906                     <th>Fee</th>
907                     <th>&nbsp;</th>
908                 </tr>
909                 [% FOREACH c IN categorycodes %]
910                     [% SET c = '*' UNLESS c.defined AND c != '' %]
911
912                     [% SET article_request_fee = CirculationRules.Search( current_branch, c, undef, 'article_request_fee' ) %]
913
914                     [% IF ( article_request_fee.defined && article_request_fee != '' ) %]
915                     <tr>
916                         <td>
917                             [% IF c == '*' %]
918                                 <em>All</em>
919                             [% ELSE %]
920                                 [% Categories.GetName(c) | html %]
921                             [% END %]
922                         </td>
923                         <td>
924                             [% IF article_request_fee.defined && article_request_fee != '' %]
925                                 [% article_request_fee | html %]
926                             [% ELSE %]
927                                 <span>0</span>
928                             [% END %]
929                         </td>
930                         <td class="actions">
931                             <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=del-article-request-fee&amp;article_request_fee_category=[% c | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
932                         </td>
933                     </tr>
934                     [% END %]
935                 [% END %]
936                 <tr>
937                     <td>
938                         <select name="article_request_fee_category" id="article_request_fee_category">
939                             <option value="*">All</option>
940                         [% FOREACH patron_category IN patron_categories%]
941                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
942                         [% END %]
943                         </select>
944                     </td>
945                     <td><input name="article_request_fee" size="3" type="text" /></td>
946                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
947                 </tr>
948             </table>
949         </form>
950     </div>
951
952 [% END %]
953
954     <div id="refund-lost-item-fee-on-return" class="container">
955         [% IF current_branch == '*' %]
956             <h3>Default lost item fee refund on return policy</h3>
957         [% ELSE %]
958             <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) | html %]</h3>
959         [% END %]
960         <p>Specify the default policy for lost item fees on return.
961         </p>
962         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
963             <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
964             <input type="hidden" name="branch" value="[% current_branch | html %]" />
965             <table>
966                 <tr>
967                     <th>Refund lost item fee</th>
968                     <th>&nbsp;</th>
969                 </tr>
970                 <tr>
971                     <td>
972                         <select name="lostreturn">
973                           [%# Default branch %]
974                           [% IF ( current_branch == '*' ) %]
975                             [% IF ( defaultRefundRule == 'refund' ) %]
976                             <option value="refund" selected="selected">Refund lost item charge</option>
977                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
978                             <option value="restore">Refund lost item charge and restore overdue fine</option>
979                             <option value="0">Leave lost item charge</option>
980                             [% ELSIF ( defaultRefundRule == 'charge' ) %]
981                             <option value="refund">Refund lost item charge</option>
982                             <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
983                             <option value="restore">Refund lost item charge and restore overdue fine</option>
984                             <option value="0">Leave lost item charge</option>
985                             [% ELSIF ( defaultRefundRule == 'restore' ) %]
986                             <option value="refund">Refund lost item charge</option>
987                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
988                             <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
989                             <option value="0">Leave lost item charge</option>
990                             [% ELSIF ( defaultRefundRule == 0 ) %]
991                             <option value="refund">Refund lost item charge</option>
992                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
993                             <option value="restore">Refund lost item charge and restore overdue fine</option>
994                             <option value="0" selected="selected">Leave lost item charge</option>
995                             [% ELSE %]
996                             <option value="refund">Refund lost item charge</option>
997                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
998                             <option value="restore">Refund lost item charge and restore overdue fine</option>
999                             <option value="0">Leave lost item charge</option>
1000                             [% END %]
1001                           [% ELSE %]
1002                           [%# Branch-specific %]
1003                             [% IF ( not refundLostItemFeeRule ) %]
1004                                 <option value="*" selected="selected">
1005                             [% ELSE %]
1006                                 <option value="*">
1007                             [% END %]
1008                               [% IF defaultRefundRule == 'refund' %]
1009                                 Use default (Refund lost item charge)
1010                               [% ELSIF defaultRefundRule == 'charge' %]
1011                                 Use default (Refund lost item charge and restore overdue fine)
1012                               [% ELSIF defaultRefundRule == 'restore' %]
1013                                 Use default (Refund lost item charge and charge new overdue fine)
1014                               [% ELSE %]
1015                                 Use default (Leave lost item charge)
1016                               [% END %]
1017                                 </option>
1018                             [% IF ( not refundLostItemFeeRule ) %]
1019                                 <option value="refund">Refund lost item charge</option>
1020                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
1021                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
1022                                 <option value="0">Leave lost item charge</option>
1023                             [% ELSE %]
1024                                 [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %]
1025                                 <option value="refund" selected="selected">Refund lost item charge</option>
1026                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
1027                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
1028                                 <option value="0">Leave lost item charge</option>
1029                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %]
1030                                 <option value="refund">Refund lost item charge</option>
1031                                 <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
1032                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
1033                                 <option value="0">Leave lost item charge</option>
1034                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %]
1035                                 <option value="refund">Refund lost item charge</option>
1036                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
1037                                 <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
1038                                 <option value="0">Leave lost item charge</option>
1039                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %]
1040                                 <option value="refund">Refund lost item charge</option>
1041                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
1042                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
1043                                 <option value="0" selected="selected">Leave lost item charge</option>
1044                                 [% END %]
1045                             [% END %]
1046                           [% END %]
1047                         </select>
1048                     </td>
1049                     <td class="actions">
1050                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
1051                     </td>
1052                     </td>
1053                 </tr>
1054             </table>
1055         </form>
1056     </div>
1057
1058     <div id="holds-policy-by-item-type" class="container">
1059     <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default holds policy by item type[% END %]</h3>
1060         <p>
1061             For this library, you can edit rules for given itemtypes, regardless
1062             of the patron's category.
1063         </p>
1064         <p>
1065             Currently, this means hold policies.
1066             The various policies have the following effects:
1067         </p>
1068         <ul>
1069             <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
1070             <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>
1071             <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
1072             <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
1073         </ul>
1074         <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
1075             <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>.
1076         </p>
1077
1078         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
1079             <input type="hidden" name="op" value="add-branch-item" />
1080             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
1081             <table>
1082                 <tr>
1083                     <th>Item type</th>
1084                     <th>Hold policy</th>
1085                     <th>Hold pickup library match</th>
1086                     <th>Return policy</th>
1087                     <th>&nbsp;</th>
1088                 </tr>
1089                 [% FOREACH i IN itemtypeloop %]
1090                     [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %]
1091                     [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
1092                     [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %]
1093
1094                     [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
1095                         <tr>
1096                             <td>
1097                                 [% i.translated_description | html %]
1098                             </td>
1099                             <td>
1100                                 [% IF holdallowed == 'from_any_library' %]
1101                                     <span>From any library</span>
1102                                 [% ELSIF holdallowed == 'from_local_hold_group' %]
1103                                     <span>From local hold group</span>
1104                                 [% ELSIF holdallowed == 'from_home_library' %]
1105                                     <span>From home library</span>
1106                                 [% ELSE %]
1107                                     <span>No holds allowed</span>
1108                                 [% END %]
1109                             </td>
1110                             <td>
1111                                 [% IF hold_fulfillment_policy == 'any' %]
1112                                     <span>any library</span>
1113                                 [% ELSIF hold_fulfillment_policy == 'homebranch' %]
1114                                     <span>item's home library</span>
1115                                 [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
1116                                     <span>item's hold group</span>
1117                                 [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
1118                                     <span>patron's hold group</span>
1119                                 [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
1120                                     <span>item's holding library</span>
1121                                 [% END %]
1122                             </td>
1123                             <td>
1124                                 [% IF returnbranch == 'homebranch' %]
1125                                     <span>Item returns home</span>
1126                                 [% ELSIF returnbranch == 'holdingbranch' %]
1127                                     <span>Item returns to issuing branch</span>
1128                                 [% ELSIF returnbranch == 'noreturn' %]
1129                                     <span>Item floats</span>
1130                                 [% END %]
1131                             </td>
1132                             <td class="actions">
1133                                 <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>
1134                             </td>
1135                         </tr>
1136                     [% END %]
1137                 [% END %]
1138                 <tr>
1139                     <td>
1140                         <select name="itemtype">
1141                         [% FOREACH itemtypeloo IN itemtypeloop %]
1142                             <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
1143                         [% END %]
1144                         </select>
1145                     </td>
1146                     <td>
1147                         <select name="holdallowed">
1148                             <option value="from_any_library">From any library</option>
1149                             <option value="from_local_hold_group">From local hold group</option>
1150                             <option value="from_home_library">From home library</option>
1151                             <option value="not_allowed">No holds allowed</option>
1152                         </select>
1153                     </td>
1154                     <td>
1155                         <select name="hold_fulfillment_policy">
1156                             <option value="any">
1157                                 any library
1158                             </option>
1159
1160                             <option value="holdgroup">
1161                                 item's hold group
1162                             </option>
1163
1164                             <option value="patrongroup">
1165                                 patron's hold group
1166                             </option>
1167
1168                             <option value="homebranch">
1169                                 item's home library
1170                             </option>
1171
1172                             <option value="holdingbranch">
1173                                 item's holding library
1174                             </option>
1175                         </select>
1176                     </td>
1177                     <td>
1178                         <select name="returnbranch">
1179                             <option value="homebranch">Item returns home</option>
1180                             <option value="holdingbranch">Item returns to issuing library</option>
1181                             <option value="noreturn">Item floats</option>
1182                         </select>
1183                     </td>
1184                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1185                 </tr>
1186             </table>
1187         </form>
1188     </div>
1189             </main>
1190         </div> <!-- /.col-sm-10.col-sm-push-2 -->
1191
1192         <div class="col-sm-2 col-sm-pull-10">
1193             <aside>
1194                 [% INCLUDE 'admin-menu.inc' %]
1195             </aside>
1196         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1197      </div> <!-- /.row -->
1198
1199 [% MACRO jsinclude BLOCK %]
1200     [% Asset.js("js/admin-menu.js") | $raw %]
1201     [% INCLUDE 'datatables.inc' %]
1202     [% INCLUDE 'calendar.inc' %]
1203     <script>
1204          $(document).ready(function() {
1205             $("#default-circulation-rules").dataTable($.extend(true,{},dataTablesDefaults, {
1206                 "aoColumnDefs": [
1207                     { "bVisible": false, "aTargets": [ 0,2 ] },
1208                     { "bSortable": false, "aTargets": ["_all"] }
1209                 ],
1210                 "aaSortingFixed": [ [0,'asc'], [1,'asc'], [2,'asc'], [3,'asc'] ],
1211                 "bPaginate": false,
1212                 "bAutoWidth": false
1213             }));
1214         });
1215
1216         function clear_edit(){
1217             var cancel = confirm(_("Are you sure you want to cancel your changes?"));
1218             if ( !cancel ) return;
1219             $('#default-circulation-rules td').removeClass('highlighted-row');
1220             var edit_row = $("#edit_row");
1221             $(edit_row).find("input").each(function(){
1222                 var type = $(this).attr("type");
1223                 if (type != "button" && type != "submit" ) {
1224                     $(this).val("");
1225                     $(this).prop('disabled', false);
1226                 }
1227                 if ( type == "checkbox" ) {
1228                     $(this).prop('checked', false);
1229                 }
1230             });
1231             $(edit_row).find("select").prop('disabled', false);
1232             $(edit_row).find("select option:first-child").attr("selected", "selected");
1233             $(edit_row).find("td:last input[name='clear']").remove();
1234         }
1235
1236         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
1237
1238         $(document).ready(function() {
1239             $('[data-toggle="popover"]').popover();
1240
1241             $(".delete").on("click",function(){
1242                 return confirmDelete(MSG_CONFIRM_DELETE);
1243             });
1244
1245             $("#clone_rules").on("click",function(){
1246                 var library_dropdown = document.getElementById("branch");
1247                 var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
1248                 var selected_library_text = $("#branch option:selected").text();
1249                 var to_library = $("#tobranch option:selected").text();
1250                 var MSG_CONFIRM_CLONE;
1251                 if (selected_library === "*") {
1252                     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);
1253                     return confirmClone(MSG_CONFIRM_CLONE);
1254                 } else {
1255                     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);
1256                     return confirmClone(MSG_CONFIRM_CLONE);
1257                 }
1258             });
1259
1260             $('#selectlibrary').find("input:submit").hide();
1261             $('#branch').change(function() {
1262                     $('#selectlibrary').submit();
1263             });
1264             $(".editrule").click(function(){
1265                 if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
1266                     var edit = confirm(_("Are you sure you want to edit another rule?"));
1267                     if (!edit) return false;
1268                 }
1269                 $('#default-circulation-rules td').removeClass('highlighted-row');
1270                 $(this).parent().parent().find("td").each(function (i) {
1271                     $(this).addClass('highlighted-row');
1272                     itm = $(this).text();
1273                     itm = itm.replace(/^\s*|\s*$/g,'');
1274                     var current_column = $("#edit_row td:eq("+i+")");
1275                     if ( i == 3 ) {
1276                         // specific processing for the Note column
1277                         var note = $(this).find("a[name='viewnote']").data("content");
1278                         $(current_column).find("input[type='text']").val(note);
1279                     } else if ( i == 9 ) {
1280                         // specific processing for the Hard due date column
1281                         var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
1282                         var input_value = '';
1283                         if (typeof select_value === 'undefined'){
1284                             select_value = '-1';
1285                         }else {
1286                             input_value = itm.split(' ')[1];
1287                         }
1288                         $(current_column).find("input[type='text']").val(input_value);
1289                         $(current_column).find("select").val(select_value);
1290                     } else if ( i == 15 ) {
1291                         // specific processing for cap_fine_to_replacement_price
1292                         var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
1293                         $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
1294                         $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
1295                     } else {
1296                         $(current_column).find("input[type='text']").val(itm);
1297                         // select the corresponding option
1298                         $(current_column).find("select option").each(function(){
1299                             opt = $(this).text().toLowerCase();
1300                             opt = opt.replace(/ \(all\)$/,""); //If option is a parent, compare without (All)
1301                             itm = itm.replace(/.*->(.*)/,"$1"); //If item type is part of a group we need to clear the parent description
1302                             opt = opt.replace(/^\s*|\s*$/g,'');
1303                             if ( opt == itm.toLowerCase() ) {
1304                                 $(this).attr('selected', 'selected');
1305                             }
1306                         });
1307                         if ( i == 0 || i == 1 ) {
1308                             // Disable the 2 first columns, we cannot update them.
1309                             var val = $(current_column).find("select option:selected").val();
1310                             var name = "categorycode";
1311                             if ( i == 1 ) {
1312                                 name="itemtype";
1313                             }
1314                             // Remove potential previous input added
1315                             $(current_column).find("input").remove();
1316                             $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
1317                         } else if ( i == 5 || i == 6 || i == 26 || i == 27 || i == 28 ) {
1318                             // If the value is not an integer for
1319                             //     - "Current checkouts allowed"
1320                             //     - "Current on-site checkouts allowed"
1321                             //     - "Holds allowed (total)"
1322                             //     - "Holds allowed (daily)"
1323                             //     - "Holds per record (count)"
1324                             // The value is "Unlimited" (or an equivalent translated string)
1325                             // an it should be set to an empty string
1326                             if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
1327                                 $(current_column).find("input[type='text']").val("");
1328                             }
1329                         }
1330                     }
1331                 });
1332                 $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
1333                 $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
1334                 return false;
1335             });
1336             $(".clear_edit").on("click",function(e){
1337                 e.preventDefault();
1338                 clear_edit();
1339             });
1340
1341             $("#set-article-requests-daily-limit").on("submit", function(){
1342                 if (! $("input[name='open_article_requests_limit'").val().length){
1343                     alert("Please set a daily limit for this patron's category");
1344                     return false;
1345                 }
1346                 return true;
1347             });
1348
1349             $("#set-article-request-fee").on("submit", function(){
1350                 if (! $("input[name='article_request_fee'").val().length){
1351                     alert("Please set a valid value for the fee");
1352                     return false;
1353                 }
1354                 return true;
1355             });
1356         });
1357     </script>
1358 [% END %]
1359 [% INCLUDE 'intranet-bottom.inc' %]