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