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