Bug 13552: Add debar option to batch patron modification
[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>Category</th>
144                                                 <th>City</th>
145                                                 <th>State</th>
146                                                 <th>ZIP/Postal code</th>
147                                                 <th>Country</th>
148                                                 <th class="title-string">Registration date</th>
149                                                 <th class="title-string">Expiry date</th>
150                                                 <th>Circulation note</th>
151                                                 <th>Opac Note</th>
152                                                 <th>Debarred till</th>
153                                                 <th>Debarred comment</th>
154                                                 [% FOREACH attrh IN attributes_header %]
155                                                     <th>[% attrh.attribute | html %]</th>
156                                                 [% END %]
157                                             </tr>
158                                         </thead>
159                                         <tbody>
160                                             [% FOREACH borrower IN borrowers %]
161                                                 <tr>
162                                                     [% IF ( op == 'show' ) %]
163                                                         <td><input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber | html %]" checked="checked" /></td>
164                                                     [% END %]
165                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber | uri %]">[% borrower.cardnumber | html %]</a></td>
166                                                     <td>[% borrower.surname | html %]</td>
167                                                     <td>[% borrower.firstname | html %]</td>
168                                                     <td>[% Branches.GetName( borrower.branchcode ) | html %]</td>
169                                                     <td>[% Categories.GetName(borrower.categorycode) | html %]</td>
170                                                     <td>[% borrower.city | html %]</td>
171                                                     <td>[% borrower.state | html %]</td>
172                                                     <td>[% borrower.zipcode | html %]</td>
173                                                     <td>[% borrower.country | html %]</td>
174                                                     <td><span title="[% borrower.dateenrolled | html %]">[% borrower.dateenrolled | $KohaDates %]</span></td>
175                                                     <td><span title="[% borrower.dateexpiry | html %]">[% borrower.dateexpiry | $KohaDates %]</span></td>
176                                                     <td>[% borrower.borrowernotes | html %]</td>
177                                                     <td>[% borrower.opacnote | html %]</td>
178                                                     <td><span title="[% borrower.debarred | html %]">[% borrower.debarred | $KohaDates %]</span></td>
179                                                     <td>[% borrower.debarredcomment | html %]</td>
180                                                     [% FOREACH pa IN borrower.patron_attributes %]
181                                                         [% IF ( pa.code ) %]
182                                                             <td>[% pa.code | html %]=[% pa.value | html %]</td>
183                                                         [% ELSE %]
184                                                             <td></td>
185                                                         [% END %]
186                                                     [% END %]
187                                                 </tr>
188                                             [% END %]
189                                         </tbody>
190                                     </table>
191                                 </div>
192                             </div>
193
194                             [% IF ( op == 'show' ) %]
195                             <div id="cataloguing_additem_newitem">
196                                 <h2>Edit patrons</h2>
197                                 <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>
198                                 <fieldset class="rows" id="fields_list">
199                                     <ol>
200                                         [% FOREACH field IN fields %]
201                                         <li>
202                                             [% IF ( field.mandatory ) %]
203                                             <label for="[% field.name | html %]" class="required">
204                                             [% ELSE %]
205                                             <label for="[% field.name | html %]">
206                                             [% END %]
207                                             [% SWITCH ( field.name ) %]
208                                                 [% CASE 'surname' %]
209                                                 Surname:
210                                                 [% CASE 'firstname' %]
211                                                 First name:
212                                                 [% CASE 'branchcode' %]
213                                                 Library:
214                                                 [% CASE 'categorycode' %]
215                                                 Category
216                                                 [% CASE 'city' %]
217                                                 City
218                                                 [% CASE 'state' %]
219                                                 State
220                                                 [% CASE 'zipcode' %]
221                                                 ZIP/Postal code
222                                                 [% CASE 'country' %]
223                                                 Country
224                                                 [% CASE 'sort1' %]
225                                                 Sort 1:
226                                                 [% CASE 'sort2' %]
227                                                 Sort 2:
228                                                 [% CASE 'dateenrolled' %]
229                                                 Registration date:
230                                                 [% CASE 'dateexpiry' %]
231                                                 Expiry date:
232                                                 [% CASE 'borrowernotes' %]
233                                                 Circulation note:
234                                                 [% CASE 'opacnote' %]
235                                                 OPAC note:
236                                                 [% CASE 'debarred' %]
237                                                 Debarred till:
238                                                 [% CASE 'debarredcomment' %]
239                                                 Debarred comment:
240                                             [% END %]
241                                             </label>
242                                             [% IF ( field.type == 'text' ) %]
243                                                 <input type="text" name="[% field.name | html %]" value="" />
244                                             [% END %]
245                                             [% IF ( field.type == 'select' ) %]
246                                                 [% IF field.option.size %]
247                                                     <select name="[% field.name | html %]" >
248                                                         [% FOREACH opt IN field.option %]
249                                                             <option value="[% opt.value | html %]">[% opt.lib | html %]</option>
250                                                         [% END %]
251                                                     </select>
252                                                 [% ELSE %]
253                                                     There is no value defined for [% field.name | html %]
254                                                 [% END %]
255                                             [% END %]
256                                             [% IF ( field.type == 'date' ) %]
257                                                 <input type="text" name="[% field.name | html %]" id="[% field.name | html %]" value="" size="10" maxlength="10" class="datepicker" />
258                                                 <a href="#"  class="clear-date" id="clear-date-[% field.name | html %]" ><i class="fa fa-fw fa-trash"></i> Clear</a>
259                                             [% END %]
260                                             [% IF field.mandatory %]
261                                                 <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name | html %]" disabled="disabled" readonly="readonly" />
262                                                 <span class="required">Required fields cannot be cleared</span>
263                                             [% ELSE %]
264                                                 <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name | html %]" />
265                                             [% END %]
266                                         </li>
267                                         [% END %]
268                                         [% IF ( patron_attributes_codes ) %]
269                                             <li class="attributes">
270                                                 <label style="width:auto;">Attribute:
271                                                     <select name="patron_attributes">
272                                                         <option value=""></option>
273                                                         [% FOREACH pac IN patron_attributes_codes %]
274                                                             <option value="[% pac.attribute_code | html %]" data-type="[% pac.type | html %]" data-category="[% pac.category_lib | html %]">[% pac.attribute_lib | html %]</option>
275                                                         [% END %]
276                                                     </select>
277                                                 </label>
278                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
279                                                 <span class="patron_attributes_value"><input type"hidden" name="patron_attributes_value" /></span>
280                                                 <a href="#" class="add_attributes" title="Add an attribute"><i class="fa fa-fw fa-plus"></i> New</a>
281                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
282                                             </li>
283                                         [% END %]
284                                     </ol>
285                                 </fieldset>
286                                 <fieldset class="action">
287                                     <input type="submit" name="mainformsubmit" value="Save" />
288                                     <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
289                                 </fieldset>
290                             </div>
291                         </form>
292                         [% END %]
293                     [% END %]
294                 [% END %]
295                 [% IF ( op == 'show_results' ) %]
296                 <p>
297                     <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
298                 </p>
299                 [% END %]
300
301             </main>
302         </div> <!-- /.col-sm-10.col-sm-push-2 -->
303
304         <div class="col-sm-2 col-sm-pull-10">
305             <aside>
306                 [% INCLUDE 'tools-menu.inc' %]
307             </aside>
308         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
309      </div> <!-- /.row -->
310
311 [% MACRO jsinclude BLOCK %]
312     [% INCLUDE 'calendar.inc' %]
313     [% INCLUDE 'datatables.inc' %]
314     [% Asset.js("js/tools-menu.js") | $raw %]
315     <script>
316         var patron_attributes_lib = new Array();
317         var patron_attributes_values = new Array();
318         $(document).ready(function() {
319             [% IF borrowers %]
320                 $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
321                     "sDom": 't',
322                     [% IF ( op == 'show_results' ) %]
323                         "aoColumnDefs": [
324                             { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
325                         ],
326                     [% ELSE %]
327                         "aoColumnDefs": [
328                             { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
329                             { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
330                         ],
331                     [% END %]
332                     "bPaginate": false
333                 }));
334                 $("#selectallbutton").click(function() {
335                     $("#borrowerst").find("input:checkbox").each(function() {
336                         $(this).prop("checked", true);
337                     });
338                     return false;
339                 });
340                 $("#clearallbutton").click(function() {
341                     $("#borrowerst").find("input:checkbox").each(function() {
342                         $(this).prop("checked", false);
343                     });
344                     return false;
345                 });
346             [% END %]
347
348             var values = new Array();
349             var lib = new Array();
350             [% FOREACH pav IN patron_attributes_values %]
351                 values = new Array();
352                 lib = new Array();
353                 [% FOREACH option IN pav.options %]
354                     values.push("[% option.lib | html %]");
355                     lib.push("[% option.authorised_value | html %]");
356                 [% END %]
357                 patron_attributes_lib["[% pav.attribute_code | html %]"] = values;
358                 patron_attributes_values["[% pav.attribute_code | html %]"] = lib;
359             [% END %]
360
361             $('select[name="patron_attributes"]').change(function() {
362                 updateAttrValues(this);
363             } );
364
365             $('select[name="patron_attributes"]').change();
366
367             $(".clear-date").on("click",function(e){
368                 e.preventDefault();
369                 var fieldID = this.id.replace("clear-date-","");
370                 $("#" + fieldID).val("");
371             });
372             $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
373                 e.preventDefault();
374                 add_attributes();
375             });
376             $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
377                 e.preventDefault();
378                 del_attributes(this);
379             });
380         });
381
382         function updateAttrValues (select_attr) {
383             var attr_code = $(select_attr).val();
384             var selected_option = $(select_attr).find("option:selected");
385             var type = $(selected_option).attr('data-type');
386             var category = $(selected_option).attr('data-category');
387             var li_node = $(select_attr).parent().parent();
388             var span = $(li_node).find('span.patron_attributes_value');
389             var information_category_node = $(li_node).find('span.information_category');
390             information_category_node.html("");
391
392             if ( category && category.length > 0 ) {
393                 information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
394             }
395             var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
396             if ( type == 'select' ) {
397                 var options = '<option value = ""></option>';
398                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
399                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
400                 }
401                 span.html('<select name="patron_attributes_value">' + options + '</select>');
402                 $(disable_input_node).show();
403             } else if ( $(selected_option).val() != "" ) {
404                 span.html('<input type="text" name="patron_attributes_value"/>');
405                 $(disable_input_node).show();
406             } else {
407                 span.html('<input type="hidden" name="patron_attributes_value" />');
408                 $(disable_input_node).hide();
409             }
410         }
411
412         function add_attributes() {
413             var li_node = $("li.attributes:last");
414             var li_clone = $(li_node).clone();
415             if ( $(li_clone).find("a.del_attributes").length == 0 ) {
416                 $(li_clone).append('<a href="#" title="' + _("Delete") + '" class="del_attributes"><i class="fa fa-fw fa-trash"></i> ' + _("Delete") + '</a>');
417             }
418             $(li_clone).find('select[name="patron_attributes"]').change(function() {
419                 updateAttrValues(this);
420             } );
421
422             $(li_clone).find('select[name="patron_attributes"]').change();
423
424             $("#fields_list>ol").append(li_clone);
425             update_attr_values();
426         }
427
428         function del_attributes(a_node) {
429             $(a_node).parent('li').remove();
430             update_attr_values();
431         }
432
433         function update_attr_values() {
434             $("li.attributes").each(function(i) {
435                 $(this).find("input:checkbox").val("attr"+i+"_value");
436             });
437         }
438         function clearDate(nodeid) {
439             $("#"+nodeid).val("");
440         }
441     </script>
442 [% END %]
443
444 [% INCLUDE 'intranet-bottom.inc' %]