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