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