Bug 27142: Don't interpolate batch_type variable
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / reports / guided_reports_start.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% USE Koha %]
5 [% USE TablesSettings %]
6 [% USE JSON.Escape %]
7 [% SET footerjs = 1 %]
8
9 [%- BLOCK area_name -%]
10     [%- SWITCH area -%]
11         [%- CASE 'CIRC' -%]Circulation
12         [%- CASE 'CAT'  -%]Catalog
13         [%- CASE 'PAT'  -%]Patrons
14         [%- CASE 'ACQ'  -%]Acquisitions
15         [%- CASE 'ACC'  -%]Accounts
16         [%- CASE 'SER'  -%]Serials
17     [%- END -%]
18 [%- END -%]
19
20 [% INCLUDE 'doc-head-open.inc' %]
21
22 <title>
23     Koha &rsaquo; Reports &rsaquo; Guided reports wizard
24     [%- IF ( saved1 ) -%]
25         &rsaquo; Saved reports
26     [%- ELSIF ( create ) -%]
27         &rsaquo; Create from SQL
28     [%- ELSIF ( showsql ) -%]
29         &rsaquo; Saved reports &rsaquo; SQL view
30     [%- ELSIF ( execute ) -%]
31         &rsaquo; Saved reports &rsaquo; Report [% name | html %] ([% id | html %])
32     [%- ELSIF ( editsql ) -%]
33         &rsaquo; Saved reports &rsaquo; Edit report [% reportname | html %] ([% id | html %])
34     [%- END -%]
35     [%- IF ( build1 ) -%]
36         &rsaquo; Build a report, step 1 of 6: Choose a module
37     [%- ELSIF ( build2 ) -%]
38         &rsaquo; Build a report, step 2 of 6: Pick a report type
39     [%- ELSIF ( build3 ) -%]
40         &rsaquo; Build a report, step 3 of 6: Select columns for display
41     [%- ELSIF ( build4 ) -%]
42         &rsaquo; Build a report, step 4 of 6: Select criteria to limit on
43     [%- ELSIF ( build5 ) -%]
44         &rsaquo; Build a report, step 5 of 6: Pick which columns to total
45     [%- ELSIF ( build6 ) -%]
46         &rsaquo; Build a report, step 6 of 6: Select how you want the report ordered
47     [%- END -%]
48 </title>
49
50 [% INCLUDE 'doc-head-close.inc' %]
51 [% Asset.css("lib/codemirror/codemirror.min.css") | $raw %]
52 <style>
53     .CodeMirror {
54         resize:  vertical;
55     }
56     #mana_search_errortext { font-family: monospace; font-weight: bold; }
57 </style>
58 [% Asset.css("css/reports.css") | $raw %]
59 [% Asset.css("lib/d3c3/c3.min.css") | $raw %]
60 </head>
61
62 <body id="rep_guided_reports_start" class="rep">
63 [% INCLUDE 'header.inc' %]
64 [% INCLUDE 'circ-search.inc' %]
65
66 <div id="breadcrumbs">
67     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
68     &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
69     &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
70
71     [% IF ( saved1 ) %]
72         &rsaquo; Saved reports
73     [% ELSIF ( create ) %]
74         &rsaquo; Create from SQL
75     [% ELSIF ( showsql ) %]
76         &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; [% reportname | html %] ([% id | html %])
77     [% ELSIF ( editsql ) %]
78         &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% reportname | html %] ([% id | html %])</a> &rsaquo; Edit
79     [% ELSIF ( execute ) %]
80         &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% name | html %] ([% id | html %])</a> &rsaquo; Run
81     [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]
82         &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
83         [% IF ( build1 ) %]
84             &rsaquo; Step 1 of 6: Choose a module
85         [% ELSIF ( build2 ) %]
86             &rsaquo; Step 2 of 6: Pick a report type
87         [% ELSIF ( build3 ) %]
88             &rsaquo; Step 3 of 6: Select columns for display
89         [% ELSIF ( build4 ) %]
90             &rsaquo; Step 4 of 6: Select criteria to limit on
91         [% ELSIF ( build5 ) %]
92             &rsaquo; Step 5 of 6: Pick which columns to total
93         [% ELSIF ( build6 ) %]
94             &rsaquo; Step 6 of 6: Select how you want the report ordered
95         [% END %]
96     [% END %]
97 </div> <!-- /#breadcrumbs -->
98
99 <div id="update_sql" class="modal" tabindex="-1" role="dialog" aria-labelledby="update_sql_label" aria-hidden="true">
100     <div class="modal-dialog">
101         <div class="modal-content">
102             <div class="modal-header">
103                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
104                 <h3 id="update_sql_label">Update SQL</h3>
105             </div>
106             <div class="modal-body">
107                 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
108             </div>
109             <div class="modal-footer">
110                 <a href="#" class="btn btn-default" id="update_sql_button" role="button" data-toggle="modal">Update</a>
111                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
112             </div>
113         </div> <!-- /.modal-content -->
114     </div> <!-- /.modal-dialog -->
115 </div> <!-- #update_sql -->
116
117 <div class="main container-fluid">
118     <div class="row">
119         <div class="col-sm-10 col-sm-push-2">
120             <main>
121
122                 [% INCLUDE "reports-toolbar.inc" %]
123
124                 [% IF ( start ) %]
125                     <h2>Guided reports</h2>
126                     <p>Use the guided reports engine to create non standard reports. This feature aims to provide some middle ground between the built in canned reports and writing custom SQL reports.</p>
127
128                     <h3>Build and run reports</h3>
129
130                     [% IF ( CAN_user_reports_create_reports ) %]
131                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
132                             <input type="hidden" name="phase" value="Build new" />
133                             <input type="submit" name="submit" value="Build new"/>
134                         </form>
135                     [% END %]
136
137                     [% IF ( CAN_user_reports_execute_reports ) %]
138                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
139                             <input type="hidden" name="phase" value="Use saved"/>
140                             <input type="submit" name="submit" value="Use saved"/>
141                         </form>
142                     [% END %]
143
144                     [% IF ( CAN_user_reports_create_reports ) %]
145                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
146                             <input type="hidden" name="phase" value="Create report from SQL"/>
147                             <input type="submit" name="submit" value="Create report from SQL"/>
148                         </form>
149                     [% END %]
150
151                     <h3>Reports Dictionary</h3>
152                     <p>Use the reports dictionary to define custom criteria to use in your reports</p>
153                     <form action="/cgi-bin/koha/reports/dictionary.pl">
154                         <input type="hidden" name="phase" value="View Dictionary"/>
155                         <input type="submit" name="submit" value="View dictionary"/>
156                     </form>
157                 [% END # /IF (start) %]
158
159                 [% IF report_converted %]
160                     <div class="dialog message">
161                         The report "[% report_converted | html %]" has been converted.
162                     </div>
163                 [% END %]
164
165                 [% IF report_converted %]
166                     <div class="dialog message">
167                         The report "[% report_converted | html %]" has been converted.
168                     </div>
169                 [% END %]
170
171                 [% IF ( saved1 ) %]
172                     [% IF ( savedreports ) %]
173                         <h1>Saved reports</h1>
174
175                         [% IF ( filters.date || filters.author || filters.keyword ) %]
176                             <p>Filtered by:
177                                 <span class="filter">
178                                     [% IF ( filters.date ) %]
179                                         <span class="filter_date"><strong>Date:</strong> [% filters.date | html %]</span>
180                                     [% END %]
181                                     [% IF ( filters.author ) %]
182                                         <span class="filter_author"><strong>Author:</strong> [% filters.author | html %]</span>
183                                     [% END %]
184                                     [% IF ( filters.keyword ) %]
185                                         <span class="filter_keyword"><strong>Keyword:</strong> [% filters.keyword | html %]</span>
186                                     [% END %]
187                                     <a class="clear_filter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1"><i class="fa fa-remove"></i> Clear</a>
188                                 </span>
189                             </p>
190                         [% END %]
191
192                         <div id="tabs" class="toptabs">
193                             <ul>
194                                 <li><a href="#reports">All</a></li>
195                                 [% FOREACH group IN groups_with_subgroups %]
196                                     <li><a id="[% group.id | html %]" href="#reports">[% group.name | html %]</a></li>
197                                 [% END %]
198                             </ul>
199                             <div id="reports">
200                                 <div id="subgroup_filter_block">
201                                     <label for="subgroup_filter">Subgroup:</label>
202                                     <select id="subgroup_filter">
203                                         <option value="">All</option>
204                                     </select>
205                                 </div>
206
207                                 [% IF (Koha.Preference('Mana') == 1) %]
208                                     [% IF manamsg %]
209                                         <div id="mana_search_message" class="dialog message">
210                                             <p> [% manamsg | html %] </p>
211                                         </div>
212                                     [% END %]
213                                 [% END %]
214
215                                 <form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post">
216                                     <input type="hidden" name="phase" value="Delete Multiple" />
217                                     <table id="table_reports">
218                                         <thead>
219                                             <tr>
220                                                 <th class="NoSort">&nbsp;</th>
221                                                 <th>ID</th>
222                                                 <th>Report name</th>
223                                                 <th>Type</th>
224                                                 <th>Group</th>
225                                                 <th>Subgroup</th>
226                                                 <th>Notes</th>
227                                                 <th>Author</th>
228                                                 <th class="title-string">Creation date</th>
229                                                 <th class="title-string">Last edit</th>
230                                                 <th class="title-string">Last run</th>
231                                                 <th class="report_public">Public</th>
232                                                 <th class="report_json_url">JSON URL</th>
233                                                 [% IF (usecache) %]
234                                                     <th>Cache expiry (seconds)</th>
235                                                 [% ELSE %]
236                                                     <th class="hidden">&nbsp;</th>
237                                                 [% END %]
238                                                 <th>Saved results</th>
239                                                 [% IF has_obsolete_reports %]
240                                                     <th>Update</th>
241                                                 [% ELSE %]
242                                                     <th class="hidden">&nbsp;</th>
243                                                 [% END %]
244                                                 <th class="NoSort">Actions</th>
245                                             </tr>
246                                         </thead>
247                                         <tbody>
248                                             [% FOREACH savedreport IN savedreports %]
249                                                 [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
250                                                     <td class="report_checkbox">
251                                                         [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS -->
252                                                             <input type="checkbox" name="ids" id="ids[% savedreport.id | html %]" value="[% savedreport.id | html %]" />
253                                                         [% END %]
254                                                         <input type="hidden" class="report_sql" value="[% savedreport.savedsql |html %]">
255                                                     </td>
256                                                     <td class="report_id">
257                                                         <label for="ids[% savedreport.id | html %]">[% savedreport.id | html %]</label>
258                                                     </td>
259                                                     <td class="report_name">
260                                                         [% IF ( savedreport.report_name ) %]
261                                                             [% savedreport.report_name | html %]
262                                                         [% ELSE %]
263                                                             [ no name ]
264                                                         [% END %]
265                                                     </td>
266                                                     <td class="report_type">
267                                                         [% savedreport.type | html %]
268                                                     </td>
269                                                     <td class="report_group">
270                                                         [% savedreport.groupname | html %]
271                                                     </td>
272                                                     <td>
273                                                         [% savedreport.subgroupname | html %]
274                                                     </td>
275                                                     <td class="report_notes">
276                                                         [% savedreport.notes | html %]
277                                                     </td>
278                                                     <td>
279                                                         [% savedreport.borrowersurname | html %]
280                                                         [% IF ( savedreport.borrowerfirstname ) %]
281                                                             , [% savedreport.borrowerfirstname | html %]
282                                                         [% END %]
283                                                         ([% savedreport.borrowernumber | html %])
284                                                     </td>
285                                                     <td>
286                                                         <span title="[% savedreport.date_created | html %]">[% savedreport.date_created | $KohaDates %]</span>
287                                                     </td>
288                                                     <td>
289                                                         <span title="[% savedreport.last_modified | html %]">[% savedreport.last_modified | $KohaDates  with_hours => 1 %]</span>
290                                                     </td>
291                                                     <td>
292                                                         <span title="[% savedreport.last_run | html %]">[% savedreport.last_run | $KohaDates  with_hours => 1 %]</span>
293                                                     </td>
294                                                     <td class="report_public">
295                                                         [% IF (savedreport.public) %]
296                                                             Yes
297                                                         [% ELSE %]
298                                                             No
299                                                         [% END %]
300                                                     </td>
301                                                     <td class="report_json_url">
302                                                         [% IF (savedreport.public) %]
303                                                             <a href="[% OPACBaseURL | url %]/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% OPACBaseURL | html %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
304                                                         [% ELSE %]
305                                                             <a href="/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% Koha.Preference('staffClientBaseURL') | html %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
306                                                         [% END %]
307                                                     </td>
308                                                     <td>
309                                                         [% savedreport.cache_expiry | html %]
310                                                     </td>
311                                                     <td>
312                                                         [% FOR result IN savedreport.results %]
313                                                             <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% result.id | uri %]">[% result.date_run | html %]</a>
314                                                             <br/>
315                                                         [% END %]
316                                                     </td>
317                                                     <td>
318                                                         [% IF savedreport.seems_obsolete %]
319                                                             This report seems obsolete, it uses biblioitems.marcxml field.
320                                                             <a href="/cgi-bin/koha/svc/convert_report?report_id=[% savedreport.id | uri %]" data-report_id="[% savedreport.id | html %]" class="update_sql btn btn-default btn-xs" title="Update SQL"><i class="fa fa-eye"></i> Update SQL</a>
321                                                         [% END %]
322                                                     </td>
323                                                     <td>
324                                                         <div class="btn-group dropup">
325                                                             [%# There should be no space between these two buttons, it would render badly %]
326                                                             <a class="btn btn-default btn-xs" role="button"
327                                                                href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Run%20this%20report"><i
328                                                                class="fa fa-play"></i> Run</a><a
329                                                                class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown"
330                                                                href="#"><b class="caret"></b></a>
331                                                             <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
332                                                                 <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> Show</a></li>
333                                                                 [% IF ( CAN_user_reports_create_reports ) %]
334                                                                     <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a></li>
335                                                                     <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% savedreport.id | uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
336                                                                 [% END %]
337                                                                 [% IF (Koha.Preference('Mana') == 1) %]
338                                                                     <li><a class="ShareButton" data-toggle="modal" href="#mana_share_report" title="Share your report with Mana Knowledge Base"><i class="fa fa-share-alt"></i> Share</a></li>
339                                                                 [% END %]
340                                                                 <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | uri %]"><i class="fa fa-clock-o"></i> Schedule</a></li>
341                                                                 [% IF ( CAN_user_reports_delete_reports ) %]
342                                                                     <li><a class="confirmdelete" title="Delete this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Delete%20Saved"><i class="fa fa-trash"></i> Delete</a></li>
343                                                                 [% END %]
344                                                             </ul>
345                                                         </div>
346                                                     </td>
347                                                 </tr>
348                                             [% END %]
349                                         </tbody>
350                                     </table>
351
352                                     [% IF ( CAN_user_reports_delete_reports ) %]
353                                         <fieldset class="action">
354                                             <input type="submit" value="Delete selected" />
355                                         </fieldset>
356                                     [% END %]
357                                 </form>
358                             </div>
359                         </div>
360                     [% ELSE # IF ( savedreports ) %]
361                         <div class="dialog message">
362                             [% IF (filter_set || filters.date || filters.author || filters.keyword) %]
363                                 <h4>No saved reports match your criteria. </h4>
364                                 [% IF ( CAN_user_reports_create_reports ) %]
365                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
366                                         <input type="hidden" name="phase" value="Build new" />
367                                         <button type="submit" class="new"><i class="fa fa-plus"></i> New guided report</button>
368                                     </form>
369
370                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
371                                         <input type="hidden" name="phase" value="Create report from SQL" />
372                                         <button type="submit" class="new"><i class="fa fa-plus"></i> New SQL report</button>
373                                     </form>
374
375                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
376                                         <input type="hidden" name="phase" value="Use saved" />
377                                         <input type="hidden" name="filter_set" value="1" />
378                                         <input type="hidden" name="filter_keyword" value="" />
379                                         <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> Cancel filter</button>
380                                     </form>
381                                 [% END %]
382                             [% ELSE %]
383                                 <h4>There are no saved reports. </h4>
384                                 [% IF ( CAN_user_reports_create_reports ) %]
385                                     <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a new report?</a>
386                                 [% END %]
387                             [% END # IF (filter_set || filters.date || filters.author || filters.keyword) %]
388                         </div> <!-- /.dialog.message -->
389                     [% END # /IF ( savedreports ) %]
390                 [% END # /IF ( saved1 ) %]
391
392                 [% INCLUDE 'mana/mana-share-report.inc' %]
393
394                 [% IF ( build1 ) %]
395                     [% IF ( cache_error) %]
396                         <div class="dialog alert">
397                             <strong> Please choose a cache_expiry less than 30 days </strong>
398                         </div>
399                     [% END %]
400
401                     <h1>Build a report</h1>
402                     <form action="/cgi-bin/koha/reports/guided_reports.pl">
403                         <fieldset class="rows">
404                             <legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend>
405                             <ol>
406                                 <li>
407                                     <label for="area">Choose: </label>
408                                     <select name="area" id="area">
409                                         [%- FOREACH area IN areas -%]
410                                             <option value="[% area | html %]">[%- PROCESS area_name area=area -%]</option>
411                                         [%- END -%]
412                                     </select>
413                                 </li>
414                                 [% IF (public) %]
415                                     <li>
416                                         <label for="public">Report is public:</label>
417                                         <select id="public" name="public">
418                                             <option value="0">No (default)</option>
419                                             <option value="1" selected="selected">Yes</option>
420                                         </select>
421                                     </li>
422                                 [% ELSE %]
423                                     <li>
424                                         <label for="public">Report is public:</label>
425                                         <select id="public" name="public">
426                                             <option value="0" selected="selected">No (default)</option>
427                                             <option value="1">Yes</option>
428                                         </select>
429                                     </li>
430                                 [% END %]
431
432                                 [% IF (usecache) %]
433                                     <li>
434                                         <label for="cache_expiry">Cache expiry:</label>
435                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
436                                         <select id="cache_expiry_units" name="cache_expiry_units">
437                                             <option value="seconds">Seconds (default)</option>
438                                             <option value="minutes">Minutes</option>
439                                             <option value="hours">Hours</option>
440                                             <option value="days">Days</option>
441                                         </select>
442                                     </li>
443                                 [% END %]
444                             </ol>
445                         </fieldset> <!-- /.rows -->
446                         <fieldset class="action">
447                             <input type="hidden" name="phase" value="Report on this Area" />
448                             <input type="submit" name="submit" value="Next &gt;&gt;" />
449                         </fieldset>
450                     </form>
451                 [% END # /build1 %]
452
453                 [% IF ( build2 ) %]
454                     <h1>Build a report</h1>
455                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
456                         <input type="hidden" name="area" value="[% area | html %]" />
457                         <input type="hidden" name="public" value="[% public | html %]" />
458                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
459                         <fieldset class="rows">
460                             <legend>Step 2 of 6: Pick a report type</legend>
461                             <ol>
462                                 <li>
463                                     <label for="types">Choose: </label>
464                                     <select id="types" name="types">
465                                         <option value="1">Tabular</option>
466                                         <option value="2" disabled="disabled">Summary</option>
467                                         <option value="3" disabled="disabled">Matrix</option>
468                                     </select>
469                                 </li>
470                             </ol>
471                         </fieldset>
472
473                         <fieldset class="action">
474                             <input type="hidden" name="phase" value="Choose this type" />
475                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
476                             <input type="submit" name="submit" value="Next &gt;&gt;" />
477                         </fieldset>
478                     </form>
479                 [% END # /IF (build2 ) %]
480
481                 [% IF ( build3 ) %]
482                     <h1>Build a report</h1>
483                     <h3>Step 3 of 6: Select columns for display</h3>
484                     <p>Note: Be careful selecting when selecting columns. If your choice is too broad it could result in a very large report that will either not complete, or slow your system down.</p>
485
486                     <form id="column_submit" action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
487                         <input type="hidden" name="area" value="[% area | html %]" />
488                         <input type="hidden" name="type" value="[% type | html %]" />
489                         <input type="hidden" name="public" value="[% public | html %]" />
490                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
491                         <fieldset>
492                             <div class="row">
493                                 <div class="col-sm-6">
494                                     <div style="float: left;">
495                                         <select id="availableColumns" name="oldcolumns2" multiple="multiple" size="25" style="min-width: 200px;height:300px;">
496                                             [% FOREACH column IN columns %]
497                                                 [% IF ( column.table ) %]
498                                                     [% IF ( loop.first ) %]
499                                                     [% ELSE %]
500                                                         </optgroup>
501                                                     [% END %]
502                                                     <optgroup label="[% column.table | html %]">
503                                                 [% ELSE %]
504                                                     <option value="[% column.name | html %]">
505                                                         [% IF ( column.description ) %]
506                                                             [% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
507                                                         [% ELSE %]
508                                                             [% column.name | html %]
509                                                         [% END %]
510                                                     </option>
511                                                 [% END %]
512                                             [% END %]
513                                             </optgroup>
514                                         </select>
515                                     </div>
516                                     <div style="width: 6.3em; float: right; margin-top: 100px">
517                                         <input type="button" name="Add" value="Add" class="button" style="width:6em;" id="addColumn" /><br />
518                                         <input type="button" name="delete" value="&lt;&lt; Delete" class="button" style="width: 6em; margin: 1em 0;" id="delColumn" />
519                                     </div>
520                                 </div> <!-- /.col-sm-6 -->
521
522                                 <div class="col-sm-6">
523                                     <select id="selectedColumns" name="columns" multiple="multiple" size="25" style="width:200px; height:300px;">
524                                     </select>
525                                 </div>
526                             </div> <!-- /.row -->
527                         </fieldset>
528                         <fieldset class="action">
529                             <input type="hidden" name="phase" value="Choose these columns" />
530                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
531                             <input type="submit" name="submit" value="Next &gt;&gt;" />
532                         </fieldset>
533                     </form> <!-- /#column_submit -->
534                 [% END # /IF ( build3 ) %]
535
536                 [% IF ( build4 ) %]
537                     <h1>Build a report</h1>
538                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" >
539                         <input type="hidden" name="area" value="[% area | html %]" />
540                         <input type="hidden" name="type" value="[% type | html %]" />
541                         <input type="hidden" name="column" value="[% column | html %]" />
542                         <input type="hidden" name="public" value="[% public | html %]" />
543                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
544                         <fieldset>
545                             <legend>Step 4 of 6: Select criteria to limit on</legend>
546                             <table>
547                                 [% FOREACH criteri IN criteria %]
548                                     <tr>
549                                         <td>
550                                             <input type="checkbox" name="criteria_column" id="[% criteri.name | html %]" value="[% criteri.name | html %]" />
551                                             <label for="[% criteri.name | html %]">[% criteri.description | html %] </label>
552                                         </td>
553                                         [% IF ( criteri.date ) %]
554                                             <td>
555                                                 <input type="text" size="10" id="[% criteri.name | html %]_value" name="[% criteri.name | html %]_value" value="" class="datepicker" />
556                                                 <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
557                                             </td>
558                                         </tr>
559                                         [% ELSE %]
560                                             [% IF ( criteri.textrange ) %]
561                                                 <td>
562                                                     from
563                                                     <input type="text" size="10" id="[% criteri.from | html %]_value" name="[% criteri.from | html %]_value" value="" /> to
564                                                     <input type="text" size="10" id="[% criteri.to | html %]_value" name="[% criteri.to | html %]_value" value="" />
565                                                 </td>
566                                             </tr>
567                                             [% ELSE %]
568                                                 [% IF ( criteri.daterange ) %]
569                                                     <td>
570                                                         from
571                                                         <input type="text" size="10" id="from_[% criteri.name | html %]_value" name="from_[% criteri.name | html %]_value" value="" class="datepickerfrom" />
572                                                         to
573                                                         <input type="text" size="10" id="to_[% criteri.name | html %]_value" name="to_[% criteri.name | html %]_value" value="" class="datepickerto" />
574                                                         <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
575                                                     </td>
576                                                 </tr>
577                                                 [% ELSE %]
578                                                     <td>
579                                                         <select name="[% criteri.name | html %]_value">
580                                                            [% FOREACH value IN criteri.values %]
581                                                                 <option value="[% value.availablevalues | html %]">
582                                                                     [% IF ( value.default ) %]
583                                                                         Default
584                                                                     [% ELSE %]
585                                                                         [% value.display_value | html %]
586                                                                     [% END %]
587                                                                 </option>
588                                                             [% END %]
589                                                         </select>
590                                                     </td>
591                                                 </tr>
592                                                 [% END %]
593                                             [% END %]
594                                         [% END %]
595                                 [% END %]
596                             </table>
597                         </fieldset>
598
599                         [% IF ( definitions ) %]
600                             <fieldset>
601                                 <legend>Dictionary definitions</legend>
602                                 <table>
603                                     [% FOREACH definition IN definitions %]
604                                         <tr>
605                                             <td>
606                                                 <input type="checkbox" name="definition" value="[% definition.id | html %]" />
607                                                 [% definition.name | html %]
608                                             </td>
609                                         </tr>
610                                     [% END %]
611                                 </table>
612                             </fieldset>
613                         [% END %]
614
615                         <fieldset class="action">
616                             <input type="hidden" name="phase" value="Choose these criteria" />
617                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
618                             <input type="submit" name="submit" value="Next &gt;&gt;" />
619                         </fieldset>
620                     </form>
621                 [% END # /IF ( build4 ) %]
622
623                 [% IF ( build5 ) %]
624                     <h1>Build a report</h1>
625                     <h3>Step 5 of 6: Pick which columns to total</h3>
626                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
627                         <input type="hidden" name="area" value="[% area | html %]" />
628                         <input type="hidden" name="type" value="[% type | html %]" />
629                         <input type="hidden" name="column" value="[% column | html %]" />
630                         <input type="hidden" name="definition" value="[% definition | html %]" />
631                         <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
632                         <input type="hidden" name="public" value="[% public | html %]" />
633                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
634                         <fieldset>
635                             <table>
636                                 [% FOREACH total_b IN total_by %]
637                                     <tr>
638                                         <td>
639                                             <input type="checkbox" name="total_by" id="[% total_b.name | html %]" value="[% total_b.name | html %]" />
640                                             <label for="[% total_b.name | html %]">[% total_b.name | html %]</label>
641                                         </td>
642                                         <td>
643                                             <select name="[% total_b.name | html %]_tvalue">
644                                                 [% FOREACH selec IN total_b.select %]
645                                                     <option value="[% selec.value | html %]">[% selec.value | html %]</option>
646                                                 [% END %]
647                                             </select>
648                                         </td>
649                                     </tr>
650                                 [% END %]
651                             </table>
652                         </fieldset>
653
654                         <fieldset class="action"><input type="hidden" name="phase" value="Choose these operations" />
655                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
656                             <input type="submit" name="submit" value="Next &gt;&gt;" />
657                         </fieldset>
658                     </form>
659                 [% END # /IF ( build5 ) %]
660
661                 [% IF ( build6 ) %]
662                     <h1>Build a report</h1>
663                     <h3>Step 6 of 6: Choose how you want the report ordered</h3>
664                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
665                         <input type="hidden" name="area" value="[% area | html %]" />
666                         <input type="hidden" name="type" value="[% type | html %]" />
667                         <input type="hidden" name="column" value="[% column | html %]" />
668                         <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
669                         <input type="hidden" name="definition" value="[% definition | html %]" />
670                         <input type="hidden" name="totals" value="[% totals | html %]" />
671                         <input type="hidden" name="public" value="[% public | html %]" />
672                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
673                         <fieldset>
674                             <table>
675                                 [% FOREACH order_b IN order_by %]
676                                     <tr>
677                                         <td>
678                                             <input type="checkbox" id="[% order_b.name | html %]" name="order_by" value="[% order_b.name | html %]" />
679                                             <label for="[% order_b.name | html %]">[% order_b.name | html %]</label>
680                                         </td>
681                                         <td>
682                                             <select name="[% order_b.name | html %]_ovalue">
683                                                 [% FOREACH selec IN order_b.select %]
684                                                     <option value="[% selec.value | html %]">[% selec.value | html %]</option>
685                                                 [% END %]
686                                             </select>
687                                         </td>
688                                     </tr>
689                                 [% END %]
690                             </table>
691                         </fieldset>
692                         <fieldset class="action">
693                             <input type="hidden" name="phase" value="Build report" />
694                             <input type="submit" name="submit" value="Finish" />
695                         </fieldset>
696                     </form>
697                 [% END #/ IF ( build6 ) %]
698
699                 [% IF ( showreport ) %]
700                     <h1>Confirm custom report</h1>
701                     <p>Your report will be generated with the following SQL statement.</p>
702                     <p>
703                         [% sql | html %]
704                     </p>
705
706                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
707                         <input type="hidden" name="sql" value="[% sql | html %]" />
708                         <input type="hidden" name="type" value="[% type | html %]" />
709                         <input type="hidden" name="public" value="[% public | html %]" />
710                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
711                         <p>You will need to save the report before you can execute it</p>
712                         <fieldset class="action"><input type="hidden" name="phase" value="Save" />
713                             <input type="submit" name="submit" value="Next" />
714                         </fieldset>
715                     </form>
716                 [% END #/ IF ( showreport ) %]
717
718                 [% IF ( save ) %]
719                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
720                         <input type="hidden" name="sql" value="[% sql | html %]" />
721                         <input type="hidden" name="type" value="[% type | html %]" />
722                         <input type="hidden" name="area" value="[% area | html %]" />
723                         <input type="hidden" name="public" value="[% public | html %]" />
724                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
725                         <fieldset class="rows">
726                             <legend>Save your custom report</legend>
727                             <ol>
728                                 <li>
729                                     <label for="reportname" class="required">Report name: </label>
730                                     <input type="text" id="reportname" name="reportname" class="required" required="required" />
731                                     <span class="required">Required</span>
732                                 </li>
733                                 [% PROCESS group_and_subgroup_selection %]
734                                 <li>
735                                     <label for="notes">Notes:</label>
736                                     <textarea name="notes" id="notes"></textarea>
737                                 </li>
738                             </ol>
739                         </fieldset>
740                         <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
741                             <input type="submit" name="submit" value="Save report" />
742                         </fieldset>
743                     </form>
744                 [% END # /IF( save ) %]
745
746                 [% IF ( warn_authval_problem ) %]
747                     <div class="dialog alert">
748                         <h3>Errors found when processing parameters for report: [% name | html %]</h3>
749                         [% FOREACH problematic_authval IN problematic_authvals %]
750                             <p>
751                             <strong>[% problematic_authval.name | html %]:</strong> The authorized value category (<strong>[% problematic_authval.authval | html %]</strong>)
752                                 you selected does not exist.
753                             </p>
754                         [% END %]
755                         <!-- Save Anyway Form -->
756                         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
757                         <!--Every parameter the user issued is provided as a hidden field for recovery-->
758                             <input type='hidden' name='id' value='[% id | html %]' />
759                             <input type='hidden' name='sql' value='[% sql | html %]' />
760                             <input type='hidden' name='reportname' value='[% reportname | html %]' />
761                             <input type='hidden' name='group' value='[% group | html %]' />
762                             <input type='hidden' name='subgroup' value='[% subgroup | html %]' />
763                             <input type='hidden' name='notes' value='[% notes | html %]' />
764                             <input type='hidden' name='cache_expiry' value='[% cache_expiry | html %]' />
765                             <input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units | html %]' />
766                             <input type='hidden' name='public' value='[% public | html %]' />
767                         [% IF ( phase_update) %]
768                             <input type='hidden' name='phase' value='Update SQL' />
769                             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
770                         [% ELSIF ( phase_save) %]
771                             <input type='hidden' name='area' value='[% area | html %]' />
772                             <input type='hidden' name='phase' value='Save Report' />
773                             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
774                         [% END %]
775                         </form>
776                         <!-- Go back to editing -->
777                         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
778                             <button type="button" class="new goback"><i class="fa fa-fw fa-pencil"></i> Edit SQL</button>
779                         </form>
780                     </div>
781                 [% END # /IF ( warn_authval_problem )%]
782
783                 [% IF ( enter_params ) %]
784                     <form action='/cgi-bin/koha/reports/guided_reports.pl'>
785                         <input type='hidden' name='reports' value="[% reports | html %]" />
786                         [% IF ( auth_val_error ) %]
787                             <input type='hidden' name='phase' value='Edit SQL' />
788                             <div class="dialog alert">
789                                 <h3>Errors found when processing parameters for report: [% name | html %]</h3>
790                                 [% FOREACH auth_val_error IN auth_val_errors %]
791                                     <p>
792                                         <strong>[% auth_val_error.entry | html %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val | html %]</strong>)
793                                         you selected does not exist.
794                                     </p>
795                                 [% END %]
796                             </div>
797                             <fieldset class="action"><input type="submit" value="Edit SQL" /></fieldset>
798                         [% ELSE #  IF ( auth_val_error ) %]
799                             <input type='hidden' name='phase' value='Run this report' />
800                             <h1>Enter parameters for report [% name | html %]:</h1>
801                             [% IF ( notes ) %]
802                                 <p>[% notes | html %]</p>
803                             [% END %]
804                             <fieldset class="rows">
805                                 <ol>
806                                     [% FOREACH sql_param IN sql_params %]
807                                         <input name="param_name" value="[% sql_param.name | html %]" type="hidden" />
808                                         [% IF sql_param.input == 'date' %]
809                                             <li>
810                                                 <label for="date_[% sql_param_entry | html %][% loop.count | html %]">[% sql_param.entry | html %]:</label> <input id="date_[% sql_param_entry | html %][% loop.count | html %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
811                                             </li>
812                                         [% ELSIF ( sql_param.input == 'text' ) %]
813                                             <li>
814                                                 <label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label>
815                                                 <input id="sql_params[% loop.count | html %]" type="text" name="sql_params" />
816                                             </li>
817                                         [% ELSE %]
818                                             <li>
819                                                 <label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
820                                                 <select name="[%- sql_param.input.name | html -%]" tabindex="1"  size="1" id="[%- sql_param.input.id | html -%]">
821                                                     [% IF (sql_param.include_all) %]
822                                                         <option value="%">All</option>
823                                                     [% END %]
824                                                     [% FOREACH value IN sql_param.input.values %]
825                                                         <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
826                                                     [% END %]
827                                                 </select>
828                                             </li>
829                                         [% END # /IF sql_param.input == 'date' %]
830                                     [% END # /FOREACH sql_param %]
831                                 </ol>
832                             </fieldset> <!-- /.rows -->
833                             <fieldset class="action">
834                                 <input type="submit" value="Run the report" />
835                             </fieldset>
836                         [% END # / IF ( auth_val_error ) %]
837                     </form>
838                 [% END # /IF ( enter_params ) %]
839
840                 [% IF ( execute ) %]
841                     <h1>[% name | html %] <span id="report_id">([% id | html %])</span></h1>
842                     [% IF ( notes ) %]
843                         <p><span class="label">Notes:</span> [% notes | html %]</p>
844                     [% END %]
845                     [% IF ( unlimited_total ) %]
846                         <p>
847                             <span class="label">Total number of results:</span>
848                             [% unlimited_total | html %]
849                             [% IF unlimited_total > limit %]
850                                 ([% limit | html %] shown)
851                             [% END %].
852                         </p>
853                     [% END %]
854
855                     <div id="sql_output" style="display:none;">
856                         <span class="label">Report SQL:</span>
857                         <textarea id="sql" readonly="readonly">[% sql | html %]</textarea>
858                     </div>
859
860                     <div>
861                         <a href="#" id="toggle_chart_settings_hid" class="toggle_chart_settings" style="display:none"><i class="fa fa-eye-slash"></i> Hide chart</a>
862                         <a href="#" id="toggle_chart_settings_vis" class="toggle_chart_settings" style="display:none"><i class="fa fa fa-eye"></i> Show chart</a>
863                     </div>
864                     <div id="chart" class="clearfix"></div>
865
866                     [% IF ( execute ) %]
867                         [% UNLESS ( errors ) %]
868                             <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_record_modification.pl" id="batch_record_modification">
869                                 <input type="hidden" name="recordtype" value="biblio" />
870                                 <input type="hidden" name="op" value="list" />
871                                 [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
872                                 <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">
873                                     [%- recordnumbers = PROCESS batch_list results=results batch_type='biblionumber' | trim | html %][% IF recordnumbers %][% SET batch_biblionumbers = 1 %][% recordnumbers | html %][% END -%]
874                                 </textarea>
875                             </form>
876
877                             <form method="POST" action="/cgi-bin/koha/tools/batch_delete_records.pl" id="batch_record_deletion">
878                                 <input type="hidden" name="recordtype" value="biblio" />
879                                 <input type="hidden" name="op" value="list" />
880                                 [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
881                                 <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">
882                                     [%- recordnumbers = PROCESS batch_list results=results batch_type='biblionumber' | trim | html %][% IF recordnumbers %][% SET batch_biblionumbers = 1 %][% recordnumbers | html %][% END -%]
883                                 </textarea>
884                             </form>
885
886                             <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_modification">
887                                 <input type="hidden" name="op" value="show" />
888                                 [% FOREACH result IN results %]
889                                     [% FOREACH cells IN result.cells %]
890                                         [% place = loop.index %]
891                                         [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
892                                         [% IF header_row.$place.cell == 'itemnumber' || header_types.item(header_row.$place.cell) == 'itemnumber'  %]
893                                             [% SET batch_itemnumbers = 1 %]
894                                             [% SET header_row.$place.has_itemnumbers = 1 %]
895                                             <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
896                                         [% END %]
897                                     [% END %]
898                                 [% END %]
899                             </form>
900
901                             <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_deletion">
902                                 <input type="hidden" name="op" value="show" />
903                                 <input type="hidden" name="del" value="1" />
904                                 [% FOREACH result IN results %]
905                                     [% FOREACH cells IN result.cells %]
906                                         [% place = loop.index %]
907                                         [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
908                                         [% IF header_row.$place.cell == 'itemnumber' || header_types.item(header_row.$place.cell) == 'itemnumber'  %]
909                                             [% SET batch_itemnumbers = 1 %]
910                                             [% SET header_row.$place.has_itemnumbers = 1 %]
911                                             <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
912                                         [% END %]
913                                     [% END %]
914                                 [% END %]
915                             </form>
916
917                             <form method="get" action="/cgi-bin/koha/virtualshelves/addbybiblionumber.pl" id="batch_add_to_list">
918                                 [% FOREACH result IN results %]
919                                     [% FOREACH cells IN result.cells %]
920                                         [% place = loop.index %]
921                                         [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
922                                         [% IF header_row.$place.cell == 'biblionumber' || header_types.item(header_row.$place.cell) == 'biblionumber' %]
923                                             [% SET batch_biblionumbers = 1 %]
924                                             [% SET header_row.$place.has_biblionumbers = 1 %]
925                                             <input type="hidden" class="bib_to_list" name="biblionumber" value="[% cells.cell | html %]" />
926                                         [% END %]
927                                     [% END %]
928                                 [% END %]
929                             </form>
930
931                             <form method="POST" action="/cgi-bin/koha/tools/modborrowers.pl" id="batch_patron_modification">
932                                 <input type="hidden" name="op" value="show" />
933                                 [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
934                                 <textarea style="display:none" name="cardnumberlist" id="cardnumberlist">
935                                     [%- cardnumbers = PROCESS batch_list results=results batch_type='cardnumber' | trim | html %][% IF cardnumbers %][% SET batch_cardnumbers = 1 %][% cardnumbers | html %][% END -%]
936                                 </textarea>
937                             </form>
938
939                             [% BLOCK batch_list %]
940                                     [%- FOREACH result IN results %]
941                                         [%- FOREACH cells IN result.cells %]
942                                             [%- place = loop.index %]
943                                             [%- IF header_row.$place.cell == batch_type || header_types.item(header_row.$place.cell) == batch_type %]
944 [%# We must not add whitespace to the cardnumbers %][% cells.cell | html %]
945                                             [%- END %]
946                                         [%- END %]
947                                     [%- END -%]
948                             [% END %]
949                             [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %]
950                                 <p>
951                                     <div class="btn-group">
952                                         <button class="btn btn-default dropdown-toggle" type="button" id="batch_mod_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
953                                             Batch operations with [% IF unlimited_total > limit %][% limit | html %][% ELSE %][% unlimited_total | html %][% END %] visible records
954                                             <span class="caret"></span>
955                                         </button>
956                                         <ul class="dropdown-menu" aria-labelledby="batch_mod_menu">
957                                             [% FOREACH header_ro IN header_row %]
958                                                 [% IF header_ro.has_biblionumbers && ( header_ro.cell == 'biblionumber' || header_types.item( header_ro.cell ) == 'biblionumber' ) %]
959                                                     <li class="dropdown-header">Bibliographic records</li>
960                                                     <li>
961                                                         <a href="#" data-submit="batch_record_modification" data-toggle="tooltip" data-placement="right" title="Send visible records to batch record modification" class="batch_op send_to_record_mod">Batch record modification</a>
962                                                     </li>
963                                                     <li>
964                                                         <a href="#" data-submit="batch_record_deletion" data-toggle="tooltip" data-placement="right" title="Send visible records to batch record deletion" class="batch_op send_to_record_del">Batch record deletion</a>
965                                                     </li>
966                                                     <li>
967                                                         <a href="#" data-submit="batch_add_to_list" data-toggle="tooltip" data-placement="right" title="Send visible records to a list" class="batch_op send_to_list">Add to list</a>
968                                                     </li>
969                                                 [% END %]
970                                                 [% IF header_ro.has_itemnumbers && ( header_ro.cell == 'itemnumber' || header_types.item( header_ro.cell ) == 'itemnumber' ) %]
971                                                     [% IF ( batch_biblionumbers ) %]
972                                                         <li role="separator" class="divider"></li>
973                                                     [% END %]
974                                                     <li class="dropdown-header">Item records</li>
975                                                     <li>
976                                                         <a href="#" data-submit="batch_item_modification" data-toggle="tooltip" data-placement="right" title="Send visible items to batch item modification" class="batch_op send_to_item_mod">Batch item modification</a>
977                                                     </li>
978                                                     <li>
979                                                         <a href="#" data-submit="batch_item_deletion" data-toggle="tooltip" data-placement="right" title="Send visible items to batch item deletion" class="batch_op send_to_item_del">Batch item deletion</a>
980                                                     </li>
981                                                 [% END %]
982                                                 [% IF header_ro.cell == 'cardnumber' || header_types.item( header_ro.cell ) == 'cardnumber' %]
983                                                     [% IF ( batch_biblionumbers || batch_itemnumbers ) %]
984                                                         <li role="separator" class="divider"></li>
985                                                     [% END %]
986                                                     <li class="dropdown-header">Patron records</li>
987                                                     <li>
988                                                         <a href="#" data-submit="batch_patron_modification" data-toggle="tooltip" data-placement="right" title="Send visible results to batch patron modification" class="batch_op send_to_patron_mod">Batch patron modification</a>
989                                                     </li>
990                                                 [% END %]
991                                             [% END %]
992                                         </ul> <!-- /.dropdown-menu -->
993                                     </div> <!-- /.dropdown -->
994                                 </p>
995                             [% END # /IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %]
996                         [% END # UNLESS ( errors ) %]
997                     [% END # IF ( execute ) %]
998
999                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect">
1000                         <input type="hidden" name="phase" value="Run this report"/>
1001                         <input type="hidden" name="reports" value="[% report_id | html %]"/>
1002
1003                         [% FOREACH p IN sql_params %]
1004                             <input type="hidden" name="sql_params" value="[% p | html %]"/>
1005                         [% END %]
1006                         [% FOREACH n IN param_names %]
1007                             <input type="hidden" name="param_name" value="[% n | html %]"/>
1008                         [% END %]
1009
1010                         <label for="limit">Rows per page: </label>
1011                         <select name="limit" id="limit">
1012                             [% limits = [ 10, 20, 50, 100, 200, 300, 400, 500, 1000 ] %]
1013                             [% FOREACH l IN limits %]
1014                                 [% IF l == limit %]
1015                                     <option value="[% l | html %]" selected="selected">[% l | html %]</option>
1016                                 [% ELSE %]
1017                                     <option value="[% l | html %]">[% l | html %]</option>
1018                                 [% END %]
1019                             [% END %]
1020                         </select>
1021                     </form> <!-- /#limitselect -->
1022
1023                     <div class="pages">[% pagination_bar | $raw %]</div>
1024                     [% UNLESS ( errors ) %]
1025                         <table>
1026                             <tr>
1027                                 [% FOREACH header_ro IN header_row %]
1028                                     <th>[% header_ro.cell | html %]</th>
1029                                 [% END %]
1030                             </tr>
1031                             [% FOREACH result IN results %]
1032                                 <tr>
1033                                     [% FOREACH cells IN result.cells %]
1034                                         <td>[% cells.cell | $raw %]</td>
1035                                     [% END %]
1036                                 </tr>
1037                             [% END %]
1038                         </table>
1039                     [% END %]
1040
1041                     [% INCLUDE 'chart.inc' %]
1042
1043                 [% END #/IF ( execute ) %]
1044
1045                 [% IF ( create ) %]
1046                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
1047                         <fieldset class="rows">
1048                             <legend>Create report from SQL</legend>
1049                             <ol>
1050                                 <li>
1051                                     <label for="reportname" class="required">Report name:</label>
1052                                     [% IF ( reportname ) %]
1053                                         <input type="text" class="required" required="required" id="reportname" name="reportname" value="[% reportname | html %]" size="50"/>
1054                                     [% ELSE %]
1055                                         <input type="text" class="required" required="required" id="reportname" name="reportname" size="50" />
1056                                     [% END %]
1057                                     <span class="required">Required</span>
1058                                 </li>
1059                                 [% PROCESS group_and_subgroup_selection %]
1060
1061                                 [% IF (public) %]
1062                                     <li>
1063                                         <label for="public">Report is public:</label>
1064                                         <select id="public" name="public">
1065                                             <option value="0">No (default)</option>
1066                                             <option value="1" selected="selected">Yes</option>
1067                                         </select>
1068                                     </li>
1069                                 [% ELSE %]
1070                                     <li>
1071                                         <label for="public">Report is public:</label>
1072                                         <select id="public" name="public">
1073                                             <option value="0" selected="selected">No (default)</option>
1074                                             <option value="1">Yes</option>
1075                                         </select>
1076                                     </li>
1077                                 [% END # /IF (public) %]
1078
1079                                 [% IF (usecache) %]
1080                                     <li>
1081                                         <label for="cache_expiry">Cache expiry:</label>
1082                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
1083                                         <select id="cache_expiry_units" name="cache_expiry_units">
1084                                             <option value="seconds" selected="selected">Seconds (default)</option>
1085                                             <option value="minutes">Minutes</option>
1086                                             <option value="hours">Hours</option>
1087                                             <option value="days">Days</option>
1088                                         </select>
1089                                     </li>
1090                                 [% END # /IF (usecache) %]
1091                                 <li>
1092                                     <label for="notes">Notes:</label>
1093                                     <textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea>
1094                                 </li>
1095                             </ol>
1096                         </fieldset> <!-- /.rows -->
1097
1098                         <fieldset class="rows">
1099                             <legend>SQL:</legend>
1100                             <div style="margin:1em;">
1101                                 <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql | html %]</textarea>
1102                                 <span class="required">Required</span>
1103                             </div>
1104                         </fieldset>
1105
1106                         <fieldset class="action">
1107                             <input type="hidden" name="phase" value="Save Report" />
1108                             <input type="submit" name="submit" value="Save report" />
1109                             <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
1110                         </fieldset>
1111                     </form>
1112                 [% END #/IF ( create ) %]
1113
1114                 [% IF saved_results %]
1115                     <h1>Saved report results</h1>
1116                     <h2>[% name | html %]</h2>
1117                     <p>[% notes | html %]</p>
1118                     <table>
1119                         [% FOREACH rows IN saved_results %]
1120                             <tr>
1121                                 [% FOREACH col IN rows %]
1122                                     <td>[% col | html %]</td>
1123                                 [% END %]
1124                             </tr>
1125                         [% END %]
1126                     </table>
1127                 [% END # /IF saved_results %]
1128
1129                 [% IF ( showsql ) %]
1130                     <fieldset class="rows">
1131                         <legend>[% reportname | html %]</legend>
1132                         <ol>
1133                             [% IF ( notes ) %]
1134                                 <li>
1135                                     <span class="label">Notes:</span>
1136                                     [% notes | html %]
1137                                 </li>
1138                             [% ELSE %]
1139                             [% END %]
1140                             <li>
1141                                 <textarea id="sql">[% sql | html %]</textarea>
1142                             </li>
1143                         </ol>
1144                     </fieldset>
1145                 [% END # /IF ( showsql ) %]
1146
1147                 [% IF ( save_successful ) %]
1148                     [% UNLESS ( errors ) %]
1149                         </br>
1150                         <div id="report_updated">
1151                             <div class="dialog message">
1152                                 <p>Your report "[% reportname | html %]" has been saved</p>
1153                             </div>
1154                         </div>
1155                     [% END %]
1156                 [% END %]
1157
1158                 [% IF ( editsql ) %]
1159                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
1160                         <input type="hidden" name="phase" value="Update SQL" />
1161                         <input type="hidden" name="id" value="[% id | html %]"/>
1162                         <fieldset class="rows">
1163                             <legend>Edit SQL report</legend>
1164                             <ol>
1165                                 <li>
1166                                     <label for="reportname" class="required">Report name: </label>
1167                                     <input type="text" id="reportname" name="reportname" value="[% reportname | html %]" size="50" class="required" required="required" />
1168                                     <span class="required">Required</span>
1169                                 </li>
1170                                 [% PROCESS group_and_subgroup_selection %]
1171                                 [% IF (public) %]
1172                                     <li>
1173                                         <label for="public">Report is public:</label>
1174                                         <select id="public" name="public">
1175                                             <option value="0">No (default)</option>
1176                                             <option value="1" selected="selected">Yes</option>
1177                                         </select>
1178                                     </li>
1179                                 [% ELSE %]
1180                                     <li>
1181                                         <label for="public">Report is public:</label>
1182                                         <select id="public" name="public">
1183                                             <option value="0" selected="selected">No (default)</option>
1184                                             <option value="1">Yes</option>
1185                                         </select>
1186                                     </li>
1187                                 [% END # /IF (public) %]
1188
1189                                 [% IF (usecache) %]
1190                                     <li>
1191                                         <label for="cache_expiry">Cache expiry:</label>
1192                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]" />
1193                                         <select id="cache_expiry_units" name="cache_expiry_units">
1194                                             <option value="seconds">Seconds (default)</option>
1195                                             <option value="minutes">Minutes</option>
1196                                             <option value="hours">Hours</option>
1197                                             <option value="days">Days</option>
1198                                         </select>
1199                                     </li>
1200                                 [% END %]
1201                                 <li>
1202                                     <label for="notes">Notes:</label>
1203                                     <textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea>
1204                                 </li>
1205                             </ol>
1206                         </fieldset> <!-- /.rows -->
1207
1208                         <fieldset class="rows">
1209                             <legend>SQL:</legend>
1210                             <div style="margin:1em;">
1211                                 <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql | html %]</textarea>
1212                                 <span class="required">Required</span>
1213                             </div>
1214                         </fieldset>
1215
1216                         <fieldset class="action">
1217                             <input type="submit" name="submit" value="Update SQL" />
1218                             <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
1219                         </fieldset>
1220                     </form>
1221                 [% END # /IF ( editsql ) %]
1222
1223                 [% IF ( errors ) %]
1224                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
1225                         <div class="dialog alert">
1226                             <strong>The following error was encountered:</strong><br />
1227                             [% FOREACH error IN errors %]
1228                                 [% IF ( error.sqlerr ) %]
1229                                     This report contains the SQL keyword <strong>[% error.sqlerr | html %]</strong>.<br />
1230                                     Use of this keyword is not allowed in Koha reports due to security and data integrity risks. Only SELECT queries are allowed.<br />
1231                                     Please return to the &quot;Saved Reports&quot; screen and delete this report or retry creating a new one.
1232                                 [% ELSIF ( error.queryerr ) %]
1233                                     The database returned the following error: <br />
1234                                     [% error.queryerr | html %]<br />Please check the log for further details.
1235                                 [% ELSIF ( error.cache_expiry ) %]
1236                                     Please select a cache expiry less than 30 days.
1237                                 [% ELSE %]
1238                                 [% END %]
1239                                 <div id="onerror_actions">
1240                                     <a href="#" class="button goback">Return to previous page</a>
1241                                 </div>
1242                             [% END %]
1243                         </div>
1244                         <fieldset class="action">
1245                             <input type="hidden" name="phase" value="Use saved" />
1246                             <input type="submit" name="submit" value="Saved reports" />
1247                         </fieldset>
1248                     </form>
1249                 [% END # /IF ( errors ) %]
1250
1251             </main>
1252         </div> <!-- /.col-sm-10.col-sm-push-2 -->
1253
1254         <div class="col-sm-2 col-sm-pull-10">
1255             <aside>
1256                 [% IF ( saved1 ) %]
1257                     <div id="saved-reports-filter">
1258                         <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
1259                             <input type="hidden" name="phase" value="Use saved" />
1260                             <input type="hidden" name="filter_set" value="1" />
1261                             <fieldset class="brief">
1262                                 <h3>Filter</h3>
1263                                 <ol>
1264                                     <li>
1265                                         <label for="filter_date">Date:</label>
1266                                         <input type="text" id="filter_date" name="filter_date" size="10" value="[% filters.date | html %]" class="datepicker" />
1267                                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
1268                                     </li>
1269                                     <li>
1270                                         <label for="filter_author">Author:</label>
1271                                         <input type="text" id="filter_author" name="filter_author" value="[% filters.author | html %]" size="16" />
1272                                     </li>
1273                                     <li>
1274                                         <label for="filter_keyword">Keyword:</label>
1275                                         <input type="text" id="filter_keyword" name="filter_keyword" value="[% filters.keyword | html %]" size="16" />
1276                                     </li>
1277                                 </ol>
1278                             </fieldset> <!-- /.brief -->
1279                             <fieldset class="action">
1280                                 <input type="submit" value="Apply filter" />
1281                                 <a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1">Clear</a>
1282                             </fieldset>
1283                         </form>
1284                     </div> <!-- /#saved-reports-filter -->
1285                 [% END %]
1286                 [% INCLUDE 'guided-reports-view.inc' %]
1287             </aside>
1288         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1289      </div> <!-- /.row -->
1290
1291 [% MACRO jsinclude BLOCK %]
1292     [% Asset.js("js/charts.js") | $raw %]
1293     [% Asset.js("lib/d3c3/d3.min.js") | $raw %]
1294     [% Asset.js("lib/d3c3/c3.min.js") | $raw %]
1295     [% INCLUDE 'calendar.inc' %]
1296     [% INCLUDE 'datatables.inc' %]
1297     [% IF ( saved1 ) %]
1298         [% INCLUDE 'columns_settings.inc' %]
1299     [% END %]
1300     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
1301     [% Asset.js( "lib/codemirror/sql.min.js" ) | $raw %]
1302     [% Asset.js( "js/mana.js" ) | $raw %]
1303     <script>
1304
1305         function hide_bar_element() {
1306             $('#chart-column-horizontal').hide()
1307             $('.chart-column-group').each(function( index ) {
1308                 $( this ).hide();
1309             });
1310             $('.chart-column-line').each(function( index ) {
1311                 $( this ).hide()
1312             });
1313         }
1314
1315         function show_bar_element() {
1316             $('#chart-column-horizontal').show()
1317             $('.chart-column-group').each(function( index ) {
1318                 $( this ).show()
1319             });
1320             $('.chart-column-line').each(function( index ) {
1321                 $( this ).show()
1322             });
1323         }
1324
1325         function removeColumn(id) {
1326             $('#'+id).remove();
1327
1328             if ( $('.chart-column-conf').length == 1 ) {
1329                 $('.chart-column-delete').remove();
1330             }
1331         }
1332
1333         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1334         var group_subgroups = {};
1335         [% FOREACH group IN groups_with_subgroups %]
1336             var gid = "[% group.id | html %]"
1337             group_subgroups[gid] = new Array();
1338             [% FOREACH subgroup IN group.subgroups %]
1339                 var sgid = "[% subgroup.id | html %]";
1340                 var sgname = "[% subgroup.name | html %]";
1341                 group_subgroups[gid].push([sgid, sgname]);
1342             [% END %]
1343         [% END %]
1344
1345         [% IF ( create || editsql || save ) %]
1346             var editor = CodeMirror.fromTextArea(sql, {
1347                 lineNumbers: true,
1348                 mode: "text/x-sql",
1349                 lineWrapping: true,
1350                 smartIndent: false
1351             });
1352
1353             // https://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages#answer-16025232
1354             function clearValidation( formElement ){
1355                 // formElement should be a jQuery object
1356                 var validator = formElement.validate();
1357                 // Iterate through named elements inside of the form, and mark them as error free
1358                 $('[name]',formElement).each(function(){
1359                     validator.successList.push(this);//mark as error free
1360                     validator.showErrors();//remove error messages if present
1361                 });
1362                 validator.resetForm();//remove error class on name elements and clear history
1363                 validator.reset();//remove all error and success data
1364             }
1365         [% END %]
1366
1367         [% IF ( showsql ) %]
1368             var editor = CodeMirror.fromTextArea(sql, {
1369                 lineNumbers: false,
1370                 mode: "text/x-sql",
1371                 lineWrapping: true,
1372                 readOnly: true
1373             });
1374         [% END %]
1375
1376         function load_group_subgroups () {
1377             var group = $("#group_select").val();
1378             var sg = $("#subgroup");
1379             $(sg).find('option[value!=""]').each(function() {
1380                 $(this).remove();
1381             });
1382             $(sg).hide();
1383             if (group) {
1384                 var select = $(sg).find('select')[0];
1385                 $.each( group_subgroups[group], function(index, value) {
1386                     $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1387                 } );
1388                 $("#subgroup, #subgroup *").show();
1389             }
1390         }
1391
1392         $(document).ready(function(){
1393
1394             var activeTab = localStorage.getItem("sql_reports_activetab");
1395
1396             $("body").on('click',".fetch_chart_data",function(){
1397                 if( [% unlimited_total || 0 | $raw %] > 1000 ){
1398                     if( confirm("Fetching full chart data for reports with many rows can cause performance issues. Are you sure you with to chart this report?") ){
1399                         return true;
1400                     } else {
1401                         return false;
1402                     }
1403                 }
1404             });
1405
1406             var showsql;
1407             hide_bar_element();
1408
1409             if ( $('.chart-column-conf').length == 1 ) {
1410                 $('.chart-column-delete').remove();
1411             }
1412
1413             $(".chart-column-delete").on('click', function(e){
1414                 e.preventDefault();
1415                 removeColumn('column_' + $(this).data('column'));
1416             })
1417
1418             $('#download-chart').click(function() {
1419                 var svg = '<svg>' + $('#chart svg').html() + '</svg>';
1420                 this.href = 'data:application/octet-stream;base64,' + btoa(svg);
1421                 this.setAttribute('download', 'chart.svg');
1422             });
1423
1424             $('#chart-type').change(function() {
1425                 if ($(this).val() == 'bar') {
1426                     show_bar_element();
1427                 }
1428                 else {
1429                     hide_bar_element();
1430                 }
1431             });
1432
1433             $('#download-chart').hide();
1434             var chart;
1435
1436             [% IF results && !errors %]
1437                 $('#draw-chart').click(function() {
1438
1439                     var x_elements = $('select[name="x"]').val();
1440                     var y_elements = [];
1441                     var groups = [];
1442                     var lines = [];
1443                     var options = {};
1444
1445                     headers = [% header_row.json | $raw %];
1446
1447                     var results;
1448                     [% IF allresults.size %]
1449                         if ($('input[name="chart-include-all"]').prop('checked')) {
1450                             results = [% allresults.json | $raw %]
1451                         }
1452                         else {
1453                             results = [% results.json | $raw %]
1454                         }
1455                     [% ELSE %]
1456                         results = [% results.json | $raw %];
1457                     [% END %]
1458
1459                     if ($('input[name="chart-exclude-last"]').prop('checked')) {
1460                         results.splice(-1, 1);
1461                     }
1462
1463                     $('select[name="y"]').each(function( index ) {
1464                         y_elements.push( $(this).val() );
1465                     });
1466                     $('select[name="group"]').each(function( index ) {
1467                         groups.push( $(this).val() );
1468                     });
1469                     $('.column-line').each(function( index ) {
1470                         if ($(this).prop('checked')) {
1471                             lines.push( $(this).attr('name') );
1472                         }
1473                     });
1474
1475                     // Remove deleted columns from headers and results.
1476                     var deleted_indexes = [];
1477                     var kept_headers = [];
1478                     $.each(headers, function(index, value) {
1479                         if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
1480                             // This header is neither a x element nor in y elements. Don't need it.
1481                             deleted_indexes.push(index);
1482                         }
1483                         else {
1484                             kept_headers.push({cell: value.cell});
1485                         }
1486                     });
1487
1488                     // Remove coresponding cells.
1489                     var kept_results = [];
1490                     $.each(results, function(index, value) {
1491                         var line = {};
1492                         line['cells'] = [];
1493                         $.each(value.cells, function(i, val) {
1494                             if ($.inArray(i, deleted_indexes) === -1) {
1495                                 line['cells'].push({cell: val.cell});
1496                             }
1497                         });
1498                         kept_results.push(line);
1499                     });
1500
1501                     options.type = $('select[name="chart-type"]').val();
1502                     options.horizontal = $('input[name="column-horizontal"]').prop('checked');
1503                     options.lines = lines;
1504
1505                     chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
1506                     $("#download-chart,#toggle_chart_settings_hid,#chart").show();
1507                     $("#toggle_chart_settings_vis").hide();
1508                     $("#chartModal").modal("hide");
1509                 });
1510             [% END %]
1511             [% IF ( create ) %]
1512                 load_group_subgroups();
1513             [% END %]
1514
1515             $('[data-toggle="tooltip"]').tooltip();
1516             var columns_settings = [% TablesSettings.GetColumns( 'reports', 'saved-sql', 'table_reports', 'json' ) | $raw %];
1517
1518             $('#limit').change(function() {
1519                 $('#limitselect').submit();
1520             });
1521
1522             $(document).click(function() {
1523                 $('#report_updated').hide();
1524             });
1525
1526             $(".goback").on("click",function(e){
1527                 e.preventDefault();
1528                 window.history.back();
1529             });
1530
1531             $("body").on("click", ".mana_search_button", function(){
1532                 $("#mana-loading").show();
1533                 mana_search($("#mana_search_field").val());
1534             });
1535
1536             $(".ShareButton").on("click", function(){
1537                 $("#note-error").hide();
1538                 if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){
1539                     $(".shared_infos").hide();
1540                     $("#note-error").show();
1541                 }
1542                 else{
1543                     $("#reportid").val($(this).closest("tr").find(".report_id").text());
1544                     $("#shared_id").html($(this).closest("tr").find(".report_id").text());
1545                     $("#shared_name").html($(this).closest("tr").find(".report_name").text());
1546                     $("#shared_sql").html($(this).closest("tr").find(".report_sql").val());
1547                     $("#shared_type").html($(this).closest("tr").find(".report_type").text());
1548                     $("#shared_group").html($(this).closest("tr").find(".report_group").text());
1549                     $("#shared_notes").html($(this).closest("tr").find(".report_notes").text());
1550                 }
1551             });
1552
1553             $("#ManaCloseButton").on("click", function() {
1554                 $(".shared_infos").show();
1555             });
1556
1557             $("#addColumn").on("click",function(){
1558                 addColumn();
1559             });
1560
1561             $("#delColumn").on("click",function(){
1562                 delColumn();
1563             });
1564
1565             [% IF (saved1) %]
1566                 var rtable = KohaTable("table_reports", {
1567                     'iDisplayLength': [% Koha.Preference('NumSavedReports') | html %],
1568                     'bAutoWidth': false,
1569                     'sPaginationType': 'full',
1570                     'aaSorting': [[ 1, "asc" ]],
1571                     'aoColumnDefs': [
1572                         { 'bSearchable': false, 'aTargets': [3] },
1573                         { "aTargets": [ 1, 2 ], "sType": "natural"  },
1574                         { "visible": false, "aTargets" : [ "hidden" ] }
1575                     ],
1576                     'oLanguage': {
1577                         'sZeroRecords': _("No matching reports found")
1578                     },
1579                 }, columns_settings);
1580
1581                 var rtabs = $("#tabs").tabs({
1582                     create: function( e, ui ){
1583                         tabsInit( ui, rtable );
1584                     },
1585                     activate: function( e, ui ){
1586                         tabsInit( ui, rtable );
1587                     }
1588                 });
1589                 if( activeTab ){
1590                     $("#tabs").tabs("option","active", activeTab );
1591                 }
1592                 $("#subgroup_filter_block").hide();
1593
1594                 $("#subgroup_filter").change(function() {
1595                     var selected = $(this).find('option:selected');
1596                     var sg_id = $(selected).val();
1597                     var sg_name = $(selected).text();
1598                     if (sg_id.length > 0) {
1599                         rtable.fnFilter('^' + sg_name + '$', 5, true, true, true, false);
1600                         rtable.fnSetColumnVis(5, false);
1601                     } else {
1602                         rtable.fnFilter('', 5);
1603                         rtable.fnSetColumnVis(5, true);
1604                     }
1605                 });
1606
1607                 $("#reports_form").submit(function(){
1608                     var checkedItems = $("input[name=ids]:checked");
1609                     if ($(checkedItems).size() == 0) {
1610                         alert(_("You must select one or more reports to delete"));
1611                         return false;
1612                     }
1613                     $(checkedItems).parents('tr').addClass("warn");
1614                     if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
1615                         return true;
1616                     } else {
1617                         $(checkedItems).parents('tr').removeClass("warn");
1618                         return false;
1619                     }
1620                 });
1621
1622                 $("body").on("click", ".update_sql", function(e){
1623                     e.preventDefault();
1624                     var ltitle = $(this).text();
1625                     var report_id = $(this).data("report_id");
1626                     var page = $(this).attr("href");
1627                     $("#update_sql .modal-body").load(page + " div", function(){
1628                         var diff1 = $("#col1 .show_sql").text();
1629                         var diff2 = $("#col2 .show_sql").text();
1630                         var diffs = diffString( escape(diff1), escape(diff2) );
1631                         $("#col1 .show_sql,#col2 .show_sql").html(diffs);
1632                     });
1633                     $('#update_sql').modal('show');
1634                     $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id);
1635                 });
1636
1637                 $("#update_sql").on("hidden.bs.modal", function(){
1638                     $("#update_sql_label").html("");
1639                     $("#update_sql .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
1640                 });
1641             [% END %]
1642
1643             [% IF ( showsql ) %]
1644                 $("#sql").focus(function() {
1645                     $(this).select();
1646                 });
1647             [% END %]
1648
1649             $(".toggle_sql").click(function(){
1650                 $("#sql_output").toggle();
1651                 $("#toggle_sql_hid").toggle();
1652                 $("#toggle_sql_vis").toggle();
1653                 if( !showsql ){
1654                     showsql = CodeMirror.fromTextArea(sql, {
1655                         lineNumbers: false,
1656                         mode: "text/x-sql",
1657                         lineWrapping: true,
1658                         readOnly: true
1659                     });
1660                 }
1661             });
1662
1663             $(".toggle_chart_settings").click(function(){
1664                 $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
1665             });
1666
1667             $("#table_reports").delegate(".confirmdelete", 'click', function(){
1668                 $(this).parents('tr').attr("class","warn");
1669                 if(confirm(_("Are you sure you want to delete this saved report?"))){
1670                     return true;
1671                 } else {
1672                     $(this).parents('tr').attr("class","");
1673                     return false;
1674                 }
1675             });
1676
1677             [% IF (create || editsql || save) %]
1678
1679                 var validated_form = $("#sql_report_form").validate({
1680                     reportname: "required",
1681                     group_input: {
1682                         required: {
1683                             depends: function(element) {
1684                                 return $("#create_group").prop("checked") && $("#groupdesc_input").val() != '';
1685                             }
1686                         }
1687                     },
1688                     groupdesc_input: {
1689                         required: {
1690                             depends: function(element) {
1691                                 return $("#create_group").prop("checked") && $("#group_input").val() != '';
1692                             }
1693                         }
1694                     }
1695                 });
1696
1697                 $("#select_group").change(function() {
1698                     if($(this).prop('checked')) {
1699                         $("#group_input").attr("class","").prop('disabled', true).prop("required", false);
1700                         $("#groupdesc_input").attr("class","").prop('disabled', true).prop("required", false);
1701                         $("#group_select").prop('disabled', false);
1702                         clearValidation( $("#sql_report_form") );
1703                         if ($("#group_select").val().length > 0) {
1704                             $("#select_subgroup").prop('checked', true);
1705                             $("#select_subgroup").change();
1706                             $("#subgroup, #subgroup *").show();
1707                         } else {
1708                             $("#subgroup").hide();
1709                         }
1710                     }
1711                 });
1712                 $("#create_group").change(function() {
1713                     if($(this).prop('checked')) {
1714                         $("#group_input").prop('disabled', false).prop("required", true );
1715                         $("#groupdesc_input").prop('disabled', false).prop("required", true );
1716                         $("#group_select").prop('disabled', true);
1717                         // $("#create_subgroup").prop('checked', true).change();
1718                         $("#subgroup_select").hide();
1719                         $("#subgroup input[type='radio']").hide();
1720                         $("#subgroup label[for]").hide();
1721                         $("#subgroup_input").prop("required", false ).prop("disabled", false).show();
1722                         $("#subgroupdesc_input").prop("required", false ).prop("disabled", false).show();
1723                         $("#subgroup").show();
1724                         // Add validation rules for fields which were previously hidden
1725                         $("#subgroup_input").rules("add", {
1726                             required: {
1727                                 depends: function(element) {
1728                                     return $("#create_group").prop("checked") &&  $("#subgroupdesc_input").val() != '';
1729                                 }
1730                             }
1731                         });
1732                         $("#subgroupdesc_input").rules("add", {
1733                             required: {
1734                                 depends: function(element) {
1735                                     return $("#create_group").prop("checked") &&  $("#subgroup_input").val() != '';
1736                                 }
1737                             }
1738                         });
1739                     }
1740                 });
1741                 $("#select_subgroup").change(function() {
1742                     if($(this).prop('checked')) {
1743                         $("#subgroup_select").prop('disabled', false);
1744                         $("#subgroup_input").prop('disabled', true).prop("required", false );
1745                         $("#subgroupdesc_input").prop('disabled', true).prop("required", false );
1746                         clearValidation( $("#sql_report_form") );
1747                     }
1748                 });
1749                 $("#create_subgroup").change(function() {
1750                     if($(this).prop('checked')) {
1751                         $("#subgroup_input").prop('disabled', false).prop("required", true );
1752                         $("#subgroupdesc_input").prop('disabled', false).prop("required", true );
1753                         $("#subgroup_select").val("").prop('disabled', true);
1754                     }
1755                 });
1756                 $("#select_group").change();
1757                 $("#select_subgroup").change();
1758                 $("#group_select").on("change",function(){
1759                     load_group_subgroups();
1760                 });
1761             [% END %]
1762
1763             $(".delete").on("click",function(){
1764                 return confirmDelete(MSG_CONFIRM_DELETE);
1765             });
1766
1767             $("#mana_search_form").submit(function(e){
1768                 e.preventDefault();
1769             });
1770
1771             $("#column_submit").submit(function() {
1772                 if ($("#selectedColumns option").size() < 1) {
1773                     alert(_("No columns selected!"));
1774                     return false;
1775                 }
1776                 $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
1777                 return true;
1778             });
1779
1780             // Mana KB
1781             $("body").on("click", ".mana-use", function(e) {
1782                 e.preventDefault();
1783                 $(this).find("i").attr("class","fa fa-refresh fa-spin");
1784                 mana_use( $(this).data("report_id") );
1785             });
1786
1787             $("#mana_search_result").on("hide.bs.modal", function(){
1788                 $("#mana_result_content").html("");
1789                 $("#mana_search_field").val("");
1790             });
1791
1792             $(".batch_op").on("click", function(e){
1793                 e.preventDefault();
1794                 var target_form = $(this).data("submit");
1795                 $("#" + target_form ).submit();
1796             });
1797
1798             $("#batch_add_to_list").on("submit", function(e){
1799                 e.preventDefault();
1800                 addToList();
1801             });
1802         });
1803
1804         function tabsInit( ui, rtable ){
1805             var thisTab = ui.newTab ? ui.newTab : ui.tab;
1806             var activeTab = thisTab.index();
1807             localStorage.setItem("sql_reports_activetab", activeTab );
1808
1809             $("#subgroup_filter option").each(function() {
1810                 if($(this).val().length > 0) {
1811                     $(this).remove();
1812                 }
1813             });
1814             rtable.fnFilter('', 4);
1815             rtable.fnFilter('', 5);
1816             rtable.fnSetColumnVis(4, true);
1817             rtable.fnSetColumnVis(5, true);
1818
1819             var g_id = $(ui.newTab).children().attr('id');
1820             var g_name = $(ui.newTab).text();
1821             if ( g_name == _("All") ) {
1822                 g_id = "";
1823                 g_name = "";
1824             }
1825
1826             if (g_id && g_id.length > 0) {
1827                 rtable.fnFilter('^' + g_name + '$', 4, true, true, true, false);
1828                 rtable.fnSetColumnVis(4, false);
1829                 for(var i in group_subgroups[g_id]) {
1830                     $("#subgroup_filter").append(
1831                         '<option value="' + group_subgroups[g_id][i][0] + '">'
1832                         + group_subgroups[g_id][i][1] + '</option>'
1833                     );
1834                 }
1835                 $("#subgroup_filter_block").show();
1836             } else {
1837                 $("#subgroup_filter_block").hide();
1838             }
1839         }
1840
1841         function addColumn() {
1842             $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
1843         }
1844         function delColumn() {
1845             $("#selectedColumns option:selected").remove();
1846         }
1847
1848         // Mana KB
1849         function mana_use( mana_id ){
1850             $.ajax( {
1851                 type:"POST",
1852                 url: "/cgi-bin/koha/svc/mana/use",
1853                 data: {id:mana_id, resource: 'report', saveinbase: 1},
1854                 dataType: "json",
1855             })
1856             .done( function (result){
1857                 if ( result.errmsg ){
1858                     alert( result.errmsg );
1859                 }
1860                 else{
1861                     window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL&mana_success=1");
1862                 }
1863             })
1864             .fail(function( error ) {
1865                 $(".mana_use_status").hide();
1866                 $("#mana_use_errortext").html( error.status + " " + error.statusText );
1867                 $("#mana_use_failed").show();
1868                 $(".mana-use i").attr("class","fa fa-download");
1869             });
1870         }
1871
1872         function mana_search( textquery ){
1873             $(".mana_search_status").hide();
1874             $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", { resource: 'report', id: textquery, usecomments: 1 }, function( response, status, xhr ) {
1875
1876                     if ( status == "error" ) {
1877                         $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
1878                         $("#mana_search_failed").show();
1879                         $("#mana-loading").hide();
1880                     } else {
1881                         $(".mana_search_status").hide();
1882                         $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
1883                         $("#mana-loading").hide();
1884                         $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
1885                             "sPaginationType":"full",
1886                             "autoWidth": false,
1887                             "columnDefs": [
1888                                 { "width": "35%", "targets": 1 }
1889                             ],
1890                             "aoColumnDefs": [
1891                                 { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
1892                                 { "sType": "title-string", "aTargets" : [ "title-string" ] },
1893                                 { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
1894                             ]
1895                         }));
1896
1897                         $(".showbutton").on("click", function(e){
1898                             e.preventDefault();
1899                             $(this).parent().hide();
1900                             $(this).parent().next().show();
1901                         });
1902
1903                         $(".hidebutton").on("click", function(e){
1904                             e.preventDefault();
1905                             $(this).parent().hide();
1906                             $(this).parent().prev().show();
1907                         });
1908
1909                         if($("td.dataTables_empty").length == 0){
1910                             $("#mana_search_message").show();
1911                         }
1912                     }
1913                 });
1914         }
1915
1916         function addToList() {
1917             var biblionumbers = [];
1918             $(".bib_to_list").each(function() {
1919                 var biblionumber = Number( $(this).val() );
1920                 if( biblionumbers.indexOf( biblionumber ) < 0 ){
1921                     biblionumbers.push( biblionumber );
1922                 }
1923             });
1924             bibs = biblionumbers.join("/");
1925             var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
1926             window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
1927             return false;
1928         }
1929     </script>
1930 [% END %]
1931
1932 [% INCLUDE 'intranet-bottom.inc' %]
1933
1934 [% BLOCK group_and_subgroup_selection %]
1935     <li id="group">
1936         <label>Report group:</label>
1937         <input type="radio" name="select_or_create_group"
1938             id="select_group" checked="checked" />
1939         <label for="select_group" style="float:none">Select</label>
1940         <select name="group" id="group_select">
1941             <option value="">(None)</option>
1942             [% FOREACH group IN groups_with_subgroups %]
1943                 [% IF (group.selected) %]
1944                     <option value="[% group.id | html %]" selected="selected">
1945                 [% ELSE %]
1946                     <option value="[% group.id | html %]">
1947                 [% END %]
1948                     [% group.name | html %]
1949                 </option>
1950             [% END %]
1951         </select>
1952         <input type="radio" name="select_or_create_group" id="create_group" />
1953         <label for="create_group" style="float:none">or create:</label>
1954         <input type="text" name="group" id="group_input" title="Group code" placeholder="Code" />
1955         <input type="text" name="groupdesc" id="groupdesc_input" title="Group name" placeholder="Name" />
1956     </li>
1957     <li id="subgroup">
1958         <label>Report subgroup:</label>
1959         <input type="radio" name="select_or_create_subgroup"
1960             id="select_subgroup" checked="checked" />
1961         <label for="select_subgroup" style="float:none">Select</label>
1962         <select name="subgroup" id="subgroup_select">
1963             <option value="">(None)</option>
1964             [% FOREACH group IN groups_with_subgroups %]
1965                 [% IF (group.selected) %]
1966                     [% FOREACH subgroup IN group.subgroups %]
1967                         [% IF (subgroup.selected) %]
1968                             <option value="[% subgroup.id | html %]" selected="selected">
1969                         [% ELSE %]
1970                             <option value="[% subgroup.id | html %]">
1971                         [% END %]
1972                             [% subgroup.name | html %]
1973                         </option>
1974                     [% END %]
1975                 [% END %]
1976             [% END %]
1977         </select>
1978         <input type="radio" name="select_or_create_subgroup"
1979             id="create_subgroup" />
1980         <label for="create_subgroup" style="float:none">or create</label>
1981         <input type="text" name="subgroup" id="subgroup_input" title="Subgroup code" placeholder="Code" />
1982         <input type="text" name="subgroupdesc" id="subgroupdesc_input" title="Subgroup name" placeholder="Name" />
1983     </li>
1984 [% END %]