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