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