Bug 27631: (follow-up) Various corrections
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / modborrowers.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% USE TablesSettings %]
8 [% SET footerjs = 1 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Batch patron modification &rsaquo; Tools &rsaquo; Koha</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 </head>
13
14 <body id="tools_modborrowers" class="tools">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'cat-search.inc' %]
17
18 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
19     <ol>
20         <li>
21             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
22         </li>
23         <li>
24             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
25         </li>
26         <li>
27             <a href="#" aria-current="page">Batch patron modification</a>
28         </li>
29     </ol>
30 </nav>
31
32 <div class="main container-fluid">
33     <div class="row">
34         <div class="col-sm-10 col-sm-push-2">
35             <main>
36
37                 [% IF ( op == 'show_form' ) %]
38                 <h1>Batch patron modification</h1>
39                 <form id="patron_batchmod_form" method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
40                     <input type="hidden" name="op" value="show" />
41                     <div id="batch_patron_options" class="toptabs">
42                         <ul>
43                             <li>
44                                 <a href="#usecardnumber">By card number</a>
45                             </li>
46                             <li>
47                                 <a href="#useborrowernumber">By borrowernumber</a>
48                             </li>
49                             [% IF patron_lists %]
50                                 <li>
51                                     <a href="#uselist">By patron list</a>
52                                 </li>
53                             [% END %]
54                         </ul>
55                         <div id="usecardnumber">
56                             <fieldset class="rows">
57                                 <legend>Use a file of card numbers</legend>
58                                 <ol>
59                                     <li>
60                                         <label for="cardnumberuploadfile">File: </label> <input type="file" id="cardnumberuploadfile" name="cardnumberuploadfile" />
61                                         <div class="hint">File must contain one card number per line.</div>
62                                     </li>
63                                 </ol>
64                             </fieldset>
65                             <fieldset class="rows">
66                                 <legend>Or list card numbers one by one</legend>
67                                 <ol>
68                                     <li>
69                                     <label for="cardnumberlist">Card number list (one card number per line): </label>
70                                     <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist | html %]</textarea>
71                                     </li>
72                                 </ol>
73                             </fieldset>
74                     <fieldset class="action">
75                         <input type="submit" value="Continue" class="button" />
76                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
77                     </fieldset>
78                         </div>
79                         <div id="useborrowernumber">
80                             <fieldset class="rows">
81                                 <legend>Use a file of borrowernumbers</legend>
82                                 <ol>
83                                     <li>
84                                         <label for="borrowernumberuploadfile">File: </label> <input type="file" id="borrowernumberuploadfile" name="borrowernumberuploadfile" />
85                                         <div class="hint">File must contain one borrowernumber per line.</div>
86                                     </li>
87                                 </ol>
88                             </fieldset>
89                             <fieldset class="rows">
90                                 <legend>List borrowernumbers one by one</legend>
91                                 <ol>
92                                     <li>
93                                     <label for="borrowernumberlist">Borrowernumber list (one number per line): </label>
94                                     <textarea rows="10" cols="30" id="borrowernumberlist" name="borrowernumberlist">[% borrowernumberlist | html %]</textarea>
95                                     </li>
96                                 </ol>
97                             </fieldset>
98                     <fieldset class="action">
99                         <input type="submit" value="Continue" class="button" />
100                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
101                     </fieldset>
102                         </div>
103                         [% IF patron_lists %]
104                             <div id="uselist">
105                                 <fieldset class="rows">
106                                     <legend>Use a patron list</legend>
107                                     <ol>
108                                         <li>
109                                             <label for="patron_list_id">Patron list: </label>
110                                             <select id="patron_list_id" name="patron_list_id">
111                                                 <option value=""> -- Choose a patron list -- </option>
112                                                 [% FOREACH pl IN patron_lists %]
113                                                     <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
114                                                 [% END %]
115                                             </select>
116                                         </li>
117                                     </ol>
118                                 </fieldset>
119                     <fieldset class="action">
120                         <input type="submit" value="Continue" class="button" />
121                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
122                     </fieldset>
123                             </div>
124                         [% END %]
125                     </div><!-- /#batch_patron_options -->
126                 </form>
127                 [% END %]
128
129                 [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) # Alert if no patrons given%]
130                     [% op = 'noshow' # Change op to prevent display in code below %]
131                     <h1>Batch patrons modification</h1>
132                     <div class="dialog alert">
133                         <p>No patron card numbers or borrowernumbers given.</p>
134                         <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
135                          <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
136                         </form>
137                     </div>
138                 [% END #Alert if no patrons %]
139
140                 [% IF ( op == 'show' or op == 'show_results' ) %]
141                     [% IF ( op == 'show' ) %]
142                         <h1>Batch patrons modification</h1>
143                     [% ELSE %]
144                         <h1>Batch patrons results</h1>
145                     [% END %]
146                     [% IF ( notfoundcardnumbers ) %]
147                         [% IF ( useborrowernumbers ) -%]
148                             <div class="dialog alert"><p>Warning, the following borrowernumbers were not found:</p></div>
149                         [% ELSE -%]
150                             <div class="dialog alert"><p>Warning, the following card numbers were not found:</p></div>
151                         [% END %]
152
153                         <table style="margin:auto;">
154                             <thead>
155                                 [% IF ( useborrowernumbers ) -%]
156                                     <tr><th>Borrowernumbers not found</th></tr>
157                                 [% ELSE -%]
158                                     <tr><th>Card numbers not found</th></tr>
159                                 [% END %]
160                             </thead>
161                             <tbody>
162                                 [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
163                                     <tr><td>[% notfoundcardnumber.cardnumber | html %]</td></tr>
164                                 [% END %]
165                             </tbody>
166                         </table>
167                     [% END %]
168
169                     [% IF ( op == 'show_results' ) %]
170                         [% IF ( errors ) %]
171                             <div class="dialog alert">
172                             <h4>Errors occurred:</h4>
173                             <ul class="warnings">
174                             [% FOREACH error IN errors %]
175                                 [% IF ( error.error == 'can_not_update' ) %]
176                                     <li>Can not update patron.
177                                     [% IF ( error.cardnumber ) %] Card number:  [% error.cardnumber | html %] [% END %]
178                                     (Borrowernumber: [% error.borrowernumber | html %])
179                                     </li>
180                                 [% ELSE %]
181                                     <li>[% error.error | html %]</li>
182                                 [% END %]
183                             [% END %]
184                             </ul>
185                             </div>
186                         [% END %]
187                     [% END %]
188
189                     [% IF ( op == 'show' ) %]
190                     <form name="f" action="modborrowers.pl" method="post">
191                         <input type="hidden" name="op" value="do" />
192                         [% IF ( borrowers ) %]
193                             <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>
194                         [% END %]
195                     [% END %]
196                         [% IF borrowers %]
197                             <div id="cataloguing_additem_itemlist">
198                                 <div style="overflow:auto">
199                                     <table id="borrowerst">
200                                         <thead>
201                                             <tr>
202                                                 [% IF ( op == 'show' ) %]
203                                                     <th class="NoSort">&nbsp;</th>
204                                                 [% ELSE %]
205                                                     <th class="NoVisible">&nbsp;</th>
206                                                 [% END %]
207                                                 <th>Card number</th>
208                                                 <th>Surname</th>
209                                                 <th>First name</th>
210                                                 <th>Library</th>
211                                                 <th>Patron category</th>
212                                                 <th>Street number</th>
213                                                 <th>Address</th>
214                                                 <th>Address 2</th>
215                                                 <th>City</th>
216                                                 <th>State</th>
217                                                 <th>ZIP/Postal code</th>
218                                                 <th>Country</th>
219                                                 <th>Primary email</th>
220                                                 <th>Phone</th>
221                                                 <th>Mobile</th>
222                                                 <th>Registration date</th>
223                                                 <th>Expiry date</th>
224                                                 <th>Circulation note</th>
225                                                 <th>OPAC note</th>
226                                                 <th>Restriction expiration</th>
227                                                 <th>Restriction comment</th>
228                                                 [% FOREACH attrh IN attributes_header %]
229                                                     <th>[% attrh.attribute | html %]</th>
230                                                 [% END %]
231                                             </tr>
232                                         </thead>
233                                         <tbody>
234                                             [% FOREACH borrower IN borrowers %]
235                                                 <tr>
236                                                     [% IF ( op == 'show' ) %]
237                                                         <td>
238                                                     [% ELSE %]
239                                                         <td class="NoVisible">
240                                                     [% END %]
241                                                         <input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber | html %]" checked="checked" />
242                                                     </td>
243                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber | uri %]">[% borrower.cardnumber | html %]</a></td>
244                                                     <td>[% borrower.surname | html %]</td>
245                                                     <td>[% borrower.firstname | html %]</td>
246                                                     <td>[% Branches.GetName( borrower.branchcode ) | html %]</td>
247                                                     <td>[% Categories.GetName(borrower.categorycode) | html %]</td>
248                                                     <td>[% borrower.streetnumber | html %]</td>
249                                                     <td>[% borrower.address | html %]</td>
250                                                     <td>[% borrower.address2 | html %]</td>
251                                                     <td>[% borrower.city | html %]</td>
252                                                     <td>[% borrower.state | html %]</td>
253                                                     <td>[% borrower.zipcode | html %]</td>
254                                                     <td>[% borrower.country | html %]</td>
255                                                     <td>[% borrower.email | html %]</td>
256                                                     <td>[% borrower.phone | html %]</td>
257                                                     <td>[% borrower.mobile | html %]</td>
258                                                     <td data-order="[% borrower.dateenrolled | html %]">[% borrower.dateenrolled | $KohaDates %]</td>
259                                                     <td data-order="[% borrower.dateexpiry | html %]">[% borrower.dateexpiry | $KohaDates %]</td>
260                                                     <td>[% borrower.borrowernotes | html %]</td>
261                                                     <td>[% borrower.opacnote | html %]</td>
262                                                     <td data-order="[% borrower.debarred | html %]">[% borrower.debarred | $KohaDates %]</td>
263                                                     <td>[% borrower.debarredcomment | html %]</td>
264                                                     [% FOREACH pa IN borrower.patron_attributes %]
265                                                         [% IF ( pa.code ) %]
266                                                         [%# Replace pa.attribute with pa.description if we prefer to display the description %]
267                                                             <td>[% pa.code | html %]=[% pa.attribute | html %]</td>
268                                                         [% ELSE %]
269                                                             <td></td>
270                                                         [% END %]
271                                                     [% END %]
272                                                 </tr>
273                                             [% END %]
274                                         </tbody>
275                                     </table>
276                                 </div>
277                             </div>
278
279                             [% IF ( op == 'show' ) %]
280                             <div id="cataloguing_additem_newitem">
281                                 <h2>Edit patrons</h2>
282                                 <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>
283                                 <fieldset class="rows" id="fields_list">
284                                     <ol>
285                                         [% FOREACH field IN fields %]
286                                         <li>
287                                             [% IF ( field.mandatory ) %]
288                                             <label for="[% field.name | html %]" class="required">
289                                             [% ELSE %]
290                                             <label for="[% field.name | html %]">
291                                             [% END %]
292                                             [% SWITCH ( field.name ) %]
293                                                 [% CASE 'surname' %]<span>Surname:</span>
294                                                 [% CASE 'firstname' %]<span>First name:</span>
295                                                 [% CASE 'branchcode' %]<span>Library:</span>
296                                                 [% CASE 'categorycode' %]<span>Patron category:</span>
297                                                 [% CASE 'streetnumber' %]<span>Street number:</span>
298                                                 [% CASE 'address' %]<span>Address:</span>
299                                                 [% CASE 'address2' %]<span>Address 2:</span>
300                                                 [% CASE 'city' %]<span>City:</span>
301                                                 [% CASE 'state' %]<span>State:</span>
302                                                 [% CASE 'zipcode' %]<span>ZIP/Postal code:</span>
303                                                 [% CASE 'country' %]<span>Country:</span>
304                                                 [% CASE 'email' %]<span>Primary email:</span>
305                                                 [% CASE 'phone' %]<span>Phone:</span>
306                                                 [% CASE 'mobile' %]<span>Mobile:</span>
307                                                 [% CASE 'sort1' %]<span>Sort 1:</span>
308                                                 [% CASE 'sort2' %]<span>Sort 2:</span>
309                                                 [% CASE 'dateenrolled' %]<span>Registration date:</span>
310                                                 [% CASE 'dateexpiry' %]<span>Expiry date:</span>
311                                                 [% CASE 'borrowernotes' %]<span>Circulation note:</span>
312                                                 [% CASE 'opacnote' %]<span>OPAC note:</span>
313                                                 [% CASE 'debarred' %]<span>Restriction expiration:</span>
314                                                 [% CASE 'debarredcomment' %]<span>Restriction comment:</span>
315                                             [% END %]
316                                             </label>
317                                             [% IF ( field.type == 'text' ) %]
318                                                 <input type="text" name="[% field.name | html %]" value="" />
319                                             [% END %]
320                                             [% IF ( field.type == 'select' ) %]
321                                                 [% IF field.option.size %]
322                                                     <select name="[% field.name | html %]" >
323                                                         [% FOREACH opt IN field.option %]
324                                                             <option value="[% opt.value | html %]">[% opt.lib | html %]</option>
325                                                         [% END %]
326                                                     </select>
327                                                 [% ELSE %]
328                                                     There is no value defined for [% field.name | html %]
329                                                 [% END %]
330                                             [% END %]
331                                             [% IF ( field.type == 'date' ) %]
332                                                 <input type="text" name="[% field.name | html %]" id="[% field.name | html %]" value="" size="10" maxlength="10" class="flatpickr" />
333                                                 <a href="#"  class="clear-date" id="clear-date-[% field.name | html %]" ><i class="fa fa-fw fa-trash"></i> Clear</a>
334                                             [% END %]
335                                             [% IF field.mandatory %]
336                                                 <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name | html %]" disabled="disabled" readonly="readonly" />
337                                                 <span class="required">Required fields cannot be cleared</span>
338                                             [% ELSE %]
339                                                 <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name | html %]" />
340                                             [% END %]
341                                         </li>
342                                         [% END %]
343                                         [% IF ( patron_attributes_codes ) %]
344                                             <li class="attributes">
345                                                 <label style="width:auto;">Patron attribute:
346                                                     <select name="patron_attributes">
347                                                         <option value=""></option>
348                                                         [% FOREACH pac IN patron_attributes_codes %]
349                                                             <option value="[% pac.attribute_code | html %]" data-type="[% pac.type | html %]" data-category="[% pac.category_lib | html %]">[% pac.attribute_lib | html %]</option>
350                                                         [% END %]
351                                                     </select>
352                                                 </label>
353                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
354                                                 <span class="patron_attributes_value"><input type"hidden" name="patron_attributes_value" /></span>
355                                                 <a href="#" class="add_attributes" title="Add an attribute"><i class="fa fa-fw fa-plus"></i> New</a>
356                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
357                                             </li>
358                                         [% END %]
359                                     </ol>
360                                 </fieldset>
361                                 <fieldset class="action">
362                                     <input type="submit" name="mainformsubmit" value="Save" />
363                                     <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
364                                 </fieldset>
365                             </div>
366                         </form>
367                         [% END %]
368                     [% END %]
369                 [% END %]
370                 [% IF ( op == 'show_results' ) %]
371                 <p>
372                     <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
373                 </p>
374                 [% END %]
375
376             </main>
377         </div> <!-- /.col-sm-10.col-sm-push-2 -->
378
379         <div class="col-sm-2 col-sm-pull-10">
380             <aside>
381                 [% INCLUDE 'tools-menu.inc' %]
382             </aside>
383         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
384      </div> <!-- /.row -->
385
386 [% MACRO jsinclude BLOCK %]
387     [% INCLUDE 'calendar.inc' %]
388     [% INCLUDE 'datatables.inc' %]
389     [% INCLUDE 'columns_settings.inc' %]
390     [% Asset.js("js/tools-menu.js") | $raw %]
391     <script>
392         var patron_attributes_lib = new Array();
393         var patron_attributes_values = new Array();
394         var table_settings = [% TablesSettings.GetColumns( 'tools', 'batch_patron_modification', 'borrowerst', 'json' ) | $raw %];
395         [% FOREACH attrh IN attributes_header %]
396             table_settings.push({
397                 columname: "[% attrh.attribute | html %]",
398                 cannot_be_modified: 0,
399                 cannot_be_toggled: 0,
400                 is_hidden: 0
401             });
402         [% END %]
403         $(document).ready(function() {
404             [% IF borrowers %]
405                 KohaTable("borrowerst", {
406                     "order": [[ 1, "asc" ]],
407                     "autoWidth": false,
408                 }, table_settings);
409
410                 $("#selectallbutton").click(function() {
411                     $("#borrowerst").find("input:checkbox").each(function() {
412                         $(this).prop("checked", true);
413                     });
414                     return false;
415                 });
416                 $("#clearallbutton").click(function() {
417                     $("#borrowerst").find("input:checkbox").each(function() {
418                         $(this).prop("checked", false);
419                     });
420                     return false;
421                 });
422             [% ELSE %]
423                 $("#batch_patron_options").tabs();
424             [% END %]
425
426             var values = new Array();
427             var lib = new Array();
428             [% FOREACH pav IN patron_attributes_values %]
429                 values = new Array();
430                 lib = new Array();
431                 [% FOREACH option IN pav.options %]
432                     values.push("[% option.lib | html %]");
433                     lib.push("[% option.authorised_value | html %]");
434                 [% END %]
435                 patron_attributes_lib["[% pav.attribute_code | html %]"] = values;
436                 patron_attributes_values["[% pav.attribute_code | html %]"] = lib;
437             [% END %]
438
439             $('select[name="patron_attributes"]').change(function() {
440                 updateAttrValues(this);
441             } );
442
443             $('select[name="patron_attributes"]').change();
444
445             $(".clear-date").on("click",function(e){
446                 e.preventDefault();
447                 var fieldID = this.id.replace("clear-date-","");
448                 $("#" + fieldID).val("");
449             });
450             $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
451                 e.preventDefault();
452                 add_attributes();
453             });
454             $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
455                 e.preventDefault();
456                 del_attributes(this);
457             });
458             $("#patron_batchmod_form").on("submit", function(){
459                 /* Reset form fields on inactive tabs */
460                 var tab = $(this).find('.ui-tabs-active:first a').attr('href');
461                 if ( tab == '#usecardnumber' ) {
462                     $("#borrowernumberuploadfile, #patron_list_id, #borrowernumberlist").val("");
463                 } else if ( tab == '#useborrowernumber' ) {
464                     $("#cardnumberuploadfile, #cardnumberlist, #patron_list_id").val("");
465                 } else { // uselist
466                     $("#borrowernumberuploadfile, #cardnumberuploadfile, #borrowernumberlist, #cardnumberlist").val("");
467                 }
468             });
469         });
470
471         function updateAttrValues (select_attr) {
472             var attr_code = $(select_attr).val();
473             var selected_option = $(select_attr).find("option:selected");
474             var type = $(selected_option).attr('data-type');
475             var category = $(selected_option).attr('data-category');
476             var li_node = $(select_attr).parent().parent();
477             var span = $(li_node).find('span.patron_attributes_value');
478             var information_category_node = $(li_node).find('span.information_category');
479             information_category_node.html("");
480
481             if ( category && category.length > 0 ) {
482                 information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
483             }
484             var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
485             if ( type == 'select' ) {
486                 var options = '<option value = ""></option>';
487                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
488                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
489                 }
490                 span.html('<select name="patron_attributes_value">' + options + '</select>');
491                 $(disable_input_node).show();
492             } else if ( $(selected_option).val() != "" ) {
493                 span.html('<input type="text" name="patron_attributes_value"/>');
494                 $(disable_input_node).show();
495             } else {
496                 span.html('<input type="hidden" name="patron_attributes_value" />');
497                 $(disable_input_node).hide();
498             }
499         }
500
501         function add_attributes() {
502             var li_node = $("li.attributes:last");
503             var li_clone = $(li_node).clone();
504             if ( $(li_clone).find("a.del_attributes").length == 0 ) {
505                 $(li_clone).append('<a href="#" title="' + _("Delete") + '" class="del_attributes"><i class="fa fa-fw fa-trash"></i> ' + _("Delete") + '</a>');
506             }
507             $(li_clone).find('select[name="patron_attributes"]').change(function() {
508                 updateAttrValues(this);
509             } );
510
511             $(li_clone).find('select[name="patron_attributes"]').change();
512
513             $("#fields_list>ol").append(li_clone);
514             update_attr_values();
515         }
516
517         function del_attributes(a_node) {
518             $(a_node).parent('li').remove();
519             update_attr_values();
520         }
521
522         function update_attr_values() {
523             $("li.attributes").each(function(i) {
524                 $(this).find("input:checkbox").val("attr"+i+"_value");
525             });
526         }
527         function clearDate(nodeid) {
528             $("#"+nodeid).val("");
529         }
530     </script>
531 [% END %]
532
533 [% INCLUDE 'intranet-bottom.inc' %]