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