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