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