Bug 19673: Allow to set patron attributes to 0 with batch patron modification
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / modborrowers.tt
1 [% USE Koha %]
2 [% USE KohaDates %]
3 [% USE Branches %]
4 [% INCLUDE 'doc-head-open.inc'%]
5 <title>Koha &rsaquo; Tools &rsaquo; Batch patron modification</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 [% INCLUDE 'calendar.inc' %]
8 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
9 [% INCLUDE 'datatables.inc' %]
10 <script type="text/javascript">
11 //<![CDATA[
12         var patron_attributes_lib = new Array();
13         var patron_attributes_values = new Array();
14         $(document).ready(function() {
15             [% IF borrowers %]
16                 $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
17                     "sDom": 't',
18                     [% IF ( op == 'show_results' ) %]
19                         "aoColumnDefs": [
20                             { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
21                         ],
22                     [% ELSE %]
23                         "aoColumnDefs": [
24                             { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
25                             { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
26                         ],
27                     [% END %]
28                     "bPaginate": false
29                 }));
30                 $("#selectallbutton").click(function() {
31                     $("#borrowerst").find("input:checkbox").each(function() {
32                         $(this).prop("checked", true);
33                     });
34                     return false;
35                 });
36                 $("#clearallbutton").click(function() {
37                     $("#borrowerst").find("input:checkbox").each(function() {
38                         $(this).prop("checked", false);
39                     });
40                     return false;
41                 });
42             [% END %]
43
44             var values = new Array();
45             var lib = new Array();
46             [% FOREACH pav IN patron_attributes_values %]
47                 values = new Array();
48                 lib = new Array();
49                 [% FOREACH option IN pav.options %]
50                     values.push("[% option.lib %]");
51                     lib.push("[% option.authorised_value %]");
52                 [% END %]
53                 patron_attributes_lib["[% pav.attribute_code %]"] = values;
54                 patron_attributes_values["[% pav.attribute_code %]"] = lib;
55             [% END %]
56
57             $('select[name="patron_attributes"]').change(function() {
58                 updateAttrValues(this);
59             } );
60
61             $('select[name="patron_attributes"]').change();
62
63             $(".clear-date").on("click",function(e){
64                 e.preventDefault();
65                 var fieldID = this.id.replace("clear-date-","");
66                 $("#" + fieldID).val("");
67             });
68             $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
69                 e.preventDefault();
70                 add_attributes();
71             });
72             $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
73                 e.preventDefault();
74                 del_attributes(this);
75             });
76         });
77
78         function updateAttrValues (select_attr) {
79             var attr_code = $(select_attr).val();
80             var selected_option = $(select_attr).find("option:selected");
81             var type = $(selected_option).attr('data-type');
82             var category = $(selected_option).attr('data-category');
83             var li_node = $(select_attr).parent().parent();
84             var span = $(li_node).find('span.patron_attributes_value');
85             var information_category_node = $(li_node).find('span.information_category');
86             information_category_node.html("");
87             if ( category && category.length > 0 ) {
88                 information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
89             }
90             var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
91             if ( type == 'select' ) {
92                 var options = '<option value = ""></option>';
93                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
94                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
95                 }
96                 span.html('<select name="patron_attributes_value">' + options + '</select>');
97                 $(disable_input_node).show();
98             } else if ( $(selected_option).val() != "" ) {
99                 span.html('<input type="text" name="patron_attributes_value"/>');
100                 $(disable_input_node).show();
101             } else {
102                 span.html('');
103                 $(disable_input_node).hide();
104             }
105         }
106
107         function add_attributes() {
108             var li_node = $("li.attributes:last");
109             var li_clone = $(li_node).clone();
110             if ( $(li_clone).find("a.del_attributes").length == 0 ) {
111                 $(li_clone).append('<a href="#" title="Delete" class="del_attributes"><i class="fa fa-fw fa-trash"></i> ' + _("Delete") + '</a>');
112             }
113             $(li_clone).find('select[name="patron_attributes"]').change(function() {
114                 updateAttrValues(this);
115             } );
116
117             $(li_clone).find('select[name="patron_attributes"]').change();
118
119             $("#fields_list>ol").append(li_clone);
120             update_attr_values();
121         }
122
123         function del_attributes(a_node) {
124             $(a_node).parent('li').remove();
125             update_attr_values();
126         }
127
128         function update_attr_values() {
129             $("li.attributes").each(function(i) {
130                 $(this).find("input:checkbox").val("attr"+i+"_value");
131             });
132         }
133         function clearDate(nodeid) {
134             $("#"+nodeid).val("");
135         }
136
137 //]]>
138 </script>
139 </head>
140 <body id="tools_modborrowers" class="tools">
141 [% INCLUDE 'header.inc' %]
142 [% INCLUDE 'cat-search.inc' %]
143
144 <div id="breadcrumbs">
145     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
146     <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
147     <a href="/cgi-bin/koha/tools/modborrowers.pl">Batch patron modification</a>
148 </div>
149
150 <div id="doc3" class="yui-t2">
151     <div id="bd">
152         <div id="yui-main">
153             <div class="yui-b">
154                 [% IF ( op == 'show_form' ) %]
155                 <h1>Batch patron modification</h1>
156                 <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
157                     <fieldset class="rows">
158                         <legend>Use a file</legend>
159                         <ol>
160                             <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
161                         </ol>
162                     </fieldset>
163
164                     [% IF patron_lists %]
165                     <fieldset class="rows">
166                         <legend>Or use a patron list</legend>
167                         <ol>
168                             <li>
169                                 <label for="patron_list_id">Patron list: </label>
170                                 <select id="patron_list_id" name="patron_list_id">
171                                     <option value=""></option>
172                                     [% FOREACH pl IN patron_lists %]
173                                         <option value="[% pl.patron_list_id %]">[% pl.name %]</option>
174                                     [% END %]
175                                 </select>
176                             </li>
177                         </ol>
178                     </fieldset>
179                     [% END %]
180
181                     <fieldset class="rows">
182                         <legend>Or list cardnumbers one by one</legend>
183                         <ol>
184                             <li>
185                               <label for="cardnumberlist">Card number list (one cardnumber per line): </label>
186                               <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist %]</textarea>
187                             </li>
188                         </ol>
189                     </fieldset>
190                     <input type="hidden" name="op" value="show" />
191                     <fieldset class="action">
192                         <input type="submit" value="Continue" class="button" />
193                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
194                     </fieldset>
195                 </form>
196                 [% END %]
197
198                 [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) # Alert if no patrons given%]
199                     [% op = 'noshow' # Change op to prevent display in code below %]
200                     <h1>Batch patrons modification</h1>
201                     <div class="dialog alert">
202                         <p>No patron card numbers given.</p>
203                         <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
204                          <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
205                         </form>
206                     </div>
207                 [% END #Alert if no patrons %]
208
209                 [% IF ( op == 'show' or op == 'show_results' ) %]
210                     [% IF ( op == 'show' ) %]
211                         <h1>Batch patrons modification</h1>
212                     [% ELSE %]
213                         <h1>Batch patrons results</h1>
214                     [% END %]
215                     [% IF ( notfoundcardnumbers ) %]
216                         <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
217                         <table style="margin:auto;">
218                             <thead>
219                                 <tr><th>Cardnumbers not found</th></tr>
220                             </thead>
221                             <tbody>
222                                 [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
223                                     <tr><td>[% notfoundcardnumber.cardnumber %]</td></tr>
224                                 [% END %]
225                             </tbody>
226                         </table>
227                     [% END %]
228
229                     [% IF ( op == 'show_results' ) %]
230                         [% IF ( errors ) %]
231                             <div class="dialog alert">
232                             <h4>Errors occurred:</h4>
233                             <ul class="warnings">
234                             [% FOREACH error IN errors %]
235                                 [% IF ( error.error == 'can_not_update' ) %]
236                                     <li>Can not update patron.
237                                     [% IF ( error.cardnumber ) %] Cardnumber:  [% error.cardnumber %] [% END %]
238                                     (Borrowernumber: [% error.borrowernumber %])
239                                     </li>
240                                 [% ELSE %]
241                                     <li>[% error.error %]</li>
242                                 [% END %]
243                             [% END %]
244                             </ul>
245                             </div>
246                         [% END %]
247                     [% END %]
248
249                     [% IF ( op == 'show' ) %]
250                     <form name="f" action="modborrowers.pl" method="post">
251                         <input type="hidden" name="op" value="do" />
252                         [% IF ( borrowers ) %]
253                             <div id="toolbar"><a id="selectallbutton" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="clearallbutton" href="#"><i class="fa fa-remove"></i> Clear all</a></div>
254                         [% END %]
255                     [% END %]
256                         [% IF borrowers %]
257                             <div id="cataloguing_additem_itemlist">
258                                 <div style="overflow:auto">
259                                     <table id="borrowerst">
260                                         <thead>
261                                             <tr>
262                                                 [% IF ( op == 'show' ) %]
263                                                     <th>&nbsp;</th>
264                                                 [% END %]
265                                                 <th>Card number</th>
266                                                 <th>Surname</th>
267                                                 <th>First name</th>
268                                                 <th>Library</th>
269                                                 <th>Category</th>
270                                                 <th>City</th>
271                                                 <th>State</th>
272                                                 <th>ZIP/Postal code</th>
273                                                 <th>Country</th>
274                                                 <th class="title-string">Registration date</th>
275                                                 <th class="title-string">Expiry date</th>
276                                                 <th>Circulation note</th>
277                                                 <th>Opac Note</th>
278                                                 [% FOREACH attrh IN attributes_header %]
279                                                     <th>[% attrh.attribute %]</th>
280                                                 [% END %]
281                                             </tr>
282                                         </thead>
283                                         <tbody>
284                                             [% FOREACH borrower IN borrowers %]
285                                                 <tr>
286                                                     [% IF ( op == 'show' ) %]
287                                                         <td><input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td>
288                                                     [% END %]
289                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td>
290                                                     <td>[% borrower.surname %]</td>
291                                                     <td>[% borrower.firstname %]</td>
292                                                     <td>[% Branches.GetName( borrower.branchcode ) %]</td>
293                                                     <td>[% borrower.category_description %]</td>
294                                                     <td>[% borrower.city %]</td>
295                                                     <td>[% borrower.state %]</td>
296                                                     <td>[% borrower.zipcode %]</td>
297                                                     <td>[% borrower.country %]</td>
298                                                     <td><span title="[% borrower.dateenrolled %]">[% borrower.dateenrolled | $KohaDates %]</span></td>
299                                                     <td><span title="[% borrower.dateexpiry %]">[% borrower.dateexpiry | $KohaDates %]</span></td>
300                                                     <td>[% borrower.borrowernotes %]</td>
301                                                     <td>[% borrower.opacnote %]</td>
302                                                     [% FOREACH pa IN borrower.patron_attributes %]
303                                                         [% IF ( pa.code ) %]
304                                                             <td>[% pa.code %]=[% pa.value %]</td>
305                                                         [% ELSE %]
306                                                             <td></td>
307                                                         [% END %]
308                                                     [% END %]
309                                                 </tr>
310                                             [% END %]
311                                         </tbody>
312                                     </table>
313                                 </div>
314                             </div>
315
316                             [% IF ( op == 'show' ) %]
317                             <div id="cataloguing_additem_newitem">
318                                 <h2>Edit patrons</h2>
319                                 <div class="hint">Checking the box right next to the label will disable the entry and delete the values of that field on all selected patrons</div>
320                                 <fieldset class="rows" id="fields_list">
321                                     <ol>
322                                         [% FOREACH field IN fields %]
323                                         <li>
324                                             [% IF ( field.mandatory ) %]
325                                             <label for="[% field.name %]" class="required">
326                                             [% ELSE %]
327                                             <label for="[% field.name %]">
328                                             [% END %]
329                                             [% SWITCH ( field.name ) %]
330                                                 [% CASE 'surname' %]
331                                                 Surname:
332                                                 [% CASE 'firstname' %]
333                                                 First name:
334                                                 [% CASE 'branchcode' %]
335                                                 Library:
336                                                 [% CASE 'categorycode' %]
337                                                 Category
338                                                 [% CASE 'city' %]
339                                                 City
340                                                 [% CASE 'state' %]
341                                                 State
342                                                 [% CASE 'zipcode' %]
343                                                 ZIP/Postal code
344                                                 [% CASE 'country' %]
345                                                 Country
346                                                 [% CASE 'sort1' %]
347                                                 Sort 1:
348                                                 [% CASE 'sort2' %]
349                                                 Sort 2:
350                                                 [% CASE 'dateenrolled' %]
351                                                 Registration date:
352                                                 [% CASE 'dateexpiry' %]
353                                                 Expiry date:
354                                                 [% CASE 'borrowernotes' %]
355                                                 Circulation note:
356                                                 [% CASE 'opacnote' %]
357                                                 OPAC note:
358                                             [% END %]
359                                             </label>
360                                             [% IF ( field.type == 'text' ) %]
361                                                 <input type="text" name="[% field.name %]" value="" />
362                                             [% END %]
363                                             [% IF ( field.type == 'select' ) %]
364                                                 [% IF field.option.size %]
365                                                     <select name="[% field.name %]" >
366                                                         [% FOREACH opt IN field.option %]
367                                                             <option value="[% opt.value %]">[% opt.lib %]</option>
368                                                         [% END %]
369                                                     </select>
370                                                 [% ELSE %]
371                                                     There is no value defined for [% field.name %]
372                                                 [% END %]
373                                             [% END %]
374                                             [% IF ( field.type == 'date' ) %]
375                                                 <input type="text" name="[% field.name %]" id="[% field.name %]" value="" size="10" maxlength="10" class="datepicker" />
376                                                 <a href="#"  class="clear-date" id="clear-date-[% field.name %]" ><i class="fa fa-fw fa-trash"></i> Clear</a>
377                                             [% END %]
378                                             [% IF field.mandatory %]
379                                                 <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name %]" disabled="disabled" readonly="readonly" />
380                                                 <span class="required">Required fields cannot be cleared</span>
381                                             [% ELSE %]
382                                                 <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name %]" />
383                                             [% END %]
384                                         </li>
385                                         [% END %]
386                                         [% IF ( patron_attributes_codes ) %]
387                                             <li class="attributes">
388                                                 <label style="width:auto;">Attribute:
389                                                     <select name="patron_attributes">
390                                                         <option value=""></option>
391                                                         [% FOREACH pac IN patron_attributes_codes %]
392                                                             <option value="[% pac.attribute_code %]" data-type="[% pac.type %]" data-category="[% pac.category_lib %]">[% pac.attribute_lib %]</option>
393                                                         [% END %]
394                                                     </select>
395                                                 </label>
396                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
397                                                 <span class="patron_attributes_value"></span>
398                                                 <a href="#" class="add_attributes" title="Add an attribute"><i class="fa fa-fw fa-plus"></i> New</a>
399                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
400                                             </li>
401                                         [% END %]
402                                     </ol>
403                                 </fieldset>
404                                 <fieldset class="action">
405                                     <input type="submit" name="mainformsubmit" value="Save" />
406                                     <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
407                                 </fieldset>
408                             </div>
409                         </form>
410                         [% END %]
411                     [% END %]
412                 [% END %]
413                 [% IF ( op == 'show_results' ) %]
414                 <p>
415                     <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
416                 </p>
417                 [% END %]
418             </div>
419             </div>
420             <div class="yui-b">
421                 [% INCLUDE 'tools-menu.inc' %]
422             </div>
423         </div>
424 [% INCLUDE 'intranet-bottom.inc' %]