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