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