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