Bug 24154: Get rules rather than values to determine if set or not
[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="datepicker" />
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="datepicker"/>
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', 1, 1 ) %]
547                 [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty', 1, 1 ) %]
548                 [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds', 1, 1 ) %]
549                 [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed', 1 ) %]
550                 [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy', 1 ) %]
551                 [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch', 1 ) %]
552                 [% SET dcharp = ( patron_maxissueqty || patron_maxonsiteissueqty || rule_value || holdallowed || hold_fulfillment_policy || returnbranch ) %]
553                 <tr>
554                     <td>
555                         [% IF ( dcharp ) %]
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 (dcharp) %]
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     <div id="refund-lost-item-fee-on-return" class="container">
791         [% IF current_branch == '*' %]
792             <h3>Default lost item fee refund on return policy</h3>
793         [% ELSE %]
794             <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) | html %]</h3>
795         [% END %]
796         <p>Specify the default policy for lost item fees on return.
797         </p>
798         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
799             <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
800             <input type="hidden" name="branch" value="[% current_branch | html %]" />
801             <table>
802                 <tr>
803                     <th>Refund lost item fee</th>
804                     <th>&nbsp;</th>
805                 </tr>
806                 <tr>
807                     <td>
808                         <select name="lostreturn">
809                           [%# Default branch %]
810                           [% IF ( current_branch == '*' ) %]
811                             [% IF ( defaultRefundRule == 'refund' ) %]
812                             <option value="refund" selected="selected">Refund lost item charge</option>
813                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
814                             <option value="restore">Refund lost item charge and restore overdue fine</option>
815                             <option value="0">Leave lost item charge</option>
816                             [% ELSIF ( defaultRefundRule == 'charge' ) %]
817                             <option value="refund">Refund lost item charge</option>
818                             <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
819                             <option value="restore">Refund lost item charge and restore overdue fine</option>
820                             <option value="0">Leave lost item charge</option>
821                             [% ELSIF ( defaultRefundRule == 'restore' ) %]
822                             <option value="refund">Refund lost item charge</option>
823                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
824                             <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
825                             <option value="0">Leave lost item charge</option>
826                             [% ELSIF ( defaultRefundRule == 0 ) %]
827                             <option value="refund">Refund lost item charge</option>
828                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
829                             <option value="restore">Refund lost item charge and restore overdue fine</option>
830                             <option value="0" selected="selected">Leave lost item charge</option>
831                             [% ELSE %]
832                             <option value="refund">Refund lost item charge</option>
833                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
834                             <option value="restore">Refund lost item charge and restore overdue fine</option>
835                             <option value="0">Leave lost item charge</option>
836                             [% END %]
837                           [% ELSE %]
838                           [%# Branch-specific %]
839                             [% IF ( not refundLostItemFeeRule ) %]
840                                 <option value="*" selected="selected">
841                             [% ELSE %]
842                                 <option value="*">
843                             [% END %]
844                               [% IF defaultRefundRule == 'refund' %]
845                                 Use default (Refund lost item charge)
846                               [% ELSIF defaultRefundRule == 'charge' %]
847                                 Use default (Refund lost item charge and restore overdue fine)
848                               [% ELSIF defaultRefundRule == 'restore' %]
849                                 Use default (Refund lost item charge and charge new overdue fine)
850                               [% ELSE %]
851                                 Use default (Leave lost item charge)
852                               [% END %]
853                                 </option>
854                             [% IF ( not refundLostItemFeeRule ) %]
855                                 <option value="refund">Refund lost item charge</option>
856                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
857                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
858                                 <option value="0">Leave lost item charge</option>
859                             [% ELSE %]
860                                 [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %]
861                                 <option value="refund" selected="selected">Refund lost item charge</option>
862                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
863                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
864                                 <option value="0">Leave lost item charge</option>
865                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %]
866                                 <option value="refund">Refund lost item charge</option>
867                                 <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
868                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
869                                 <option value="0">Leave lost item charge</option>
870                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %]
871                                 <option value="refund">Refund lost item charge</option>
872                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
873                                 <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
874                                 <option value="0">Leave lost item charge</option>
875                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %]
876                                 <option value="refund">Refund lost item charge</option>
877                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
878                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
879                                 <option value="0" selected="selected">Leave lost item charge</option>
880                                 [% END %]
881                             [% END %]
882                           [% END %]
883                         </select>
884                     </td>
885                     <td class="actions">
886                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
887                     </td>
888                     </td>
889                 </tr>
890             </table>
891         </form>
892     </div>
893
894     <div id="holds-policy-by-item-type" class="container">
895     <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default holds policy by item type[% END %]</h3>
896         <p>
897             For this library, you can edit rules for given itemtypes, regardless
898             of the patron's category.
899         </p>
900         <p>
901             Currently, this means hold policies.
902             The various policies have the following effects:
903         </p>
904         <ul>
905             <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
906             <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>
907             <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
908             <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
909         </ul>
910         <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
911             <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>.
912         </p>
913
914         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
915             <input type="hidden" name="op" value="add-branch-item" />
916             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
917             <table>
918                 <tr>
919                     <th>Item type</th>
920                     <th>Hold policy</th>
921                     <th>Hold pickup library match</th>
922                     <th>Return policy</th>
923                     <th>&nbsp;</th>
924                 </tr>
925                 [% FOREACH i IN itemtypeloop %]
926                     [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %]
927                     [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
928                     [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %]
929
930                     [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
931                         <tr>
932                             <td>
933                                 [% i.translated_description | html %]
934                             </td>
935                             <td>
936                                 [% IF holdallowed == 'from_any_library' %]
937                                     <span>From any library</span>
938                                 [% ELSIF holdallowed == 'from_local_hold_group' %]
939                                     <span>From local hold group</span>
940                                 [% ELSIF holdallowed == 'from_home_library' %]
941                                     <span>From home library</span>
942                                 [% ELSE %]
943                                     <span>No holds allowed</span>
944                                 [% END %]
945                             </td>
946                             <td>
947                                 [% IF hold_fulfillment_policy == 'any' %]
948                                     <span>any library</span>
949                                 [% ELSIF hold_fulfillment_policy == 'homebranch' %]
950                                     <span>item's home library</span>
951                                 [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
952                                     <span>item's hold group</span>
953                                 [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
954                                     <span>patron's hold group</span>
955                                 [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
956                                     <span>item's holding library</span>
957                                 [% END %]
958                             </td>
959                             <td>
960                                 [% IF returnbranch == 'homebranch' %]
961                                     <span>Item returns home</span>
962                                 [% ELSIF returnbranch == 'holdingbranch' %]
963                                     <span>Item returns to issuing branch</span>
964                                 [% ELSIF returnbranch == 'noreturn' %]
965                                     <span>Item floats</span>
966                                 [% END %]
967                             </td>
968                             <td class="actions">
969                                 <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>
970                             </td>
971                         </tr>
972                     [% END %]
973                 [% END %]
974                 <tr>
975                     <td>
976                         <select name="itemtype">
977                         [% FOREACH itemtypeloo IN itemtypeloop %]
978                             <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
979                         [% END %]
980                         </select>
981                     </td>
982                     <td>
983                         <select name="holdallowed">
984                             <option value="from_any_library">From any library</option>
985                             <option value="from_local_hold_group">From local hold group</option>
986                             <option value="from_home_library">From home library</option>
987                             <option value="not_allowed">No holds allowed</option>
988                         </select>
989                     </td>
990                     <td>
991                         <select name="hold_fulfillment_policy">
992                             <option value="any">
993                                 any library
994                             </option>
995
996                             <option value="holdgroup">
997                                 item's hold group
998                             </option>
999
1000                             <option value="patrongroup">
1001                                 patron's hold group
1002                             </option>
1003
1004                             <option value="homebranch">
1005                                 item's home library
1006                             </option>
1007
1008                             <option value="holdingbranch">
1009                                 item's holding library
1010                             </option>
1011                         </select>
1012                     </td>
1013                     <td>
1014                         <select name="returnbranch">
1015                             <option value="homebranch">Item returns home</option>
1016                             <option value="holdingbranch">Item returns to issuing library</option>
1017                             <option value="noreturn">Item floats</option>
1018                         </select>
1019                     </td>
1020                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
1021                 </tr>
1022             </table>
1023         </form>
1024     </div>
1025             </main>
1026         </div> <!-- /.col-sm-10.col-sm-push-2 -->
1027
1028         <div class="col-sm-2 col-sm-pull-10">
1029             <aside>
1030                 [% INCLUDE 'admin-menu.inc' %]
1031             </aside>
1032         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1033      </div> <!-- /.row -->
1034
1035 [% MACRO jsinclude BLOCK %]
1036     [% Asset.js("js/admin-menu.js") | $raw %]
1037     [% INCLUDE 'datatables.inc' %]
1038     [% INCLUDE 'calendar.inc' %]
1039     <script>
1040          $(document).ready(function() {
1041             $("#default-circulation-rules").dataTable($.extend(true,{},dataTablesDefaults, {
1042                 "aoColumnDefs": [
1043                     { "bVisible": false, "aTargets": [ 0,2 ] },
1044                     { "bSortable": false, "aTargets": ["_all"] }
1045                 ],
1046                 "aaSortingFixed": [ [0,'asc'], [1,'asc'], [2,'asc'], [3,'asc'] ],
1047                 "bPaginate": false,
1048                 "bAutoWidth": false
1049             }));
1050         });
1051
1052         function clear_edit(){
1053             var cancel = confirm(_("Are you sure you want to cancel your changes?"));
1054             if ( !cancel ) return;
1055             $('#default-circulation-rules td').removeClass('highlighted-row');
1056             var edit_row = $("#edit_row");
1057             $(edit_row).find("input").each(function(){
1058                 var type = $(this).attr("type");
1059                 if (type != "button" && type != "submit" ) {
1060                     $(this).val("");
1061                     $(this).prop('disabled', false);
1062                 }
1063                 if ( type == "checkbox" ) {
1064                     $(this).prop('checked', false);
1065                 }
1066             });
1067             $(edit_row).find("select").prop('disabled', false);
1068             $(edit_row).find("select option:first-child").attr("selected", "selected");
1069             $(edit_row).find("td:last input[name='clear']").remove();
1070         }
1071
1072         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
1073
1074         $(document).ready(function() {
1075             $('[data-toggle="popover"]').popover();
1076
1077             $(".delete").on("click",function(){
1078                 return confirmDelete(MSG_CONFIRM_DELETE);
1079             });
1080
1081             $("#clone_rules").on("click",function(){
1082                 var library_dropdown = document.getElementById("branch");
1083                 var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
1084                 var selected_library_text = $("#branch option:selected").text();
1085                 var to_library = $("#tobranch option:selected").text();
1086                 var MSG_CONFIRM_CLONE;
1087                 if (selected_library === "*") {
1088                     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);
1089                     return confirmClone(MSG_CONFIRM_CLONE);
1090                 } else {
1091                     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);
1092                     return confirmClone(MSG_CONFIRM_CLONE);
1093                 }
1094             });
1095
1096             $('#selectlibrary').find("input:submit").hide();
1097             $('#branch').change(function() {
1098                     $('#selectlibrary').submit();
1099             });
1100             $(".editrule").click(function(){
1101                 if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
1102                     var edit = confirm(_("Are you sure you want to edit another rule?"));
1103                     if (!edit) return false;
1104                 }
1105                 $('#default-circulation-rules td').removeClass('highlighted-row');
1106                 $(this).parent().parent().find("td").each(function (i) {
1107                     $(this).addClass('highlighted-row');
1108                     itm = $(this).text();
1109                     itm = itm.replace(/^\s*|\s*$/g,'');
1110                     var current_column = $("#edit_row td:eq("+i+")");
1111                     if ( i == 3 ) {
1112                         // specific processing for the Note column
1113                         var note = $(this).find("a[name='viewnote']").data("content");
1114                         $(current_column).find("input[type='text']").val(note);
1115                     } else if ( i == 9 ) {
1116                         // specific processing for the Hard due date column
1117                         var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
1118                         var input_value = '';
1119                         if (typeof select_value === 'undefined'){
1120                             select_value = '-1';
1121                         }else {
1122                             input_value = itm.split(' ')[1];
1123                         }
1124                         $(current_column).find("input[type='text']").val(input_value);
1125                         $(current_column).find("select").val(select_value);
1126                     } else if ( i == 15 ) {
1127                         // specific processing for cap_fine_to_replacement_price
1128                         var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
1129                         $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
1130                         $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
1131                     } else {
1132                         $(current_column).find("input[type='text']").val(itm);
1133                         // select the corresponding option
1134                         $(current_column).find("select option").each(function(){
1135                             opt = $(this).text().toLowerCase();
1136                             itm = itm.replace(/.*->(.*)/,"$1"); //If item type is part of a group we need to clear the parent description
1137                             opt = opt.replace(/^\s*|\s*$/g,'');
1138                             if ( opt == itm.toLowerCase() ) {
1139                                 $(this).attr('selected', 'selected');
1140                             }
1141                         });
1142                         if ( i == 0 || i == 1 ) {
1143                             // Disable the 2 first columns, we cannot update them.
1144                             var val = $(current_column).find("select option:selected").val();
1145                             var name = "categorycode";
1146                             if ( i == 1 ) {
1147                                 name="itemtype";
1148                             }
1149                             // Remove potential previous input added
1150                             $(current_column).find("input").remove();
1151                             $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
1152                         } else if ( i == 5 || i == 6 || i == 26 || i == 27 || i == 28 ) {
1153                             // If the value is not an integer for
1154                             //     - "Current checkouts allowed"
1155                             //     - "Current on-site checkouts allowed"
1156                             //     - "Holds allowed (total)"
1157                             //     - "Holds allowed (daily)"
1158                             //     - "Holds per record (count)"
1159                             // The value is "Unlimited" (or an equivalent translated string)
1160                             // an it should be set to an empty string
1161                             if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
1162                                 $(current_column).find("input[type='text']").val("");
1163                             }
1164                         }
1165                     }
1166                 });
1167                 $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
1168                 $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
1169                 return false;
1170             });
1171             $(".clear_edit").on("click",function(e){
1172                 e.preventDefault();
1173                 clear_edit();
1174             });
1175         });
1176     </script>
1177 [% END %]
1178 [% INCLUDE 'intranet-bottom.inc' %]