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