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