Bug 33966: (bug 23824 follow-up) Fix submit buttons for translated templates
[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-remove"></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 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 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 fa-pencil"></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 fa-clock-o"></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"></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-remove"></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 fa-fw fa-pencil"></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 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 fa 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 fa-eye autolink" style="display:none"></i>
1085                                                 <i class="fa 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 fa-fw fa-pencil"></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 fa-pencil"></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 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 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 fa-pencil"></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     [% END %]
1481     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
1482     [% Asset.js( "lib/codemirror/overlay.min.js" ) | $raw %]
1483     [% Asset.js( "lib/codemirror/sql.js" ) | $raw %]
1484     [% Asset.js( "lib/codemirror/show-hint.js" ) | $raw %]
1485     [% Asset.css("lib/codemirror/show-hint.css") | $raw %]
1486     [% Asset.js( "lib/codemirror/sql-hint.js" ) | $raw %]
1487     [% Asset.js( "lib/codemirror/highlight.js" ) | $raw %]
1488     [% Asset.css("lib/codemirror/highlight.css") | $raw %]
1489     [% Asset.js( "js/mana.js" ) | $raw %]
1490
1491     <script>
1492
1493         function hide_bar_element() {
1494             $('#chart-column-horizontal').hide()
1495             $('.chart-column-group').each(function( index ) {
1496                 $( this ).hide();
1497             });
1498             $('.chart-column-line').each(function( index ) {
1499                 $( this ).hide()
1500             });
1501         }
1502
1503         function show_bar_element() {
1504             $('#chart-column-horizontal').show()
1505             $('.chart-column-group').each(function( index ) {
1506                 $( this ).show()
1507             });
1508             $('.chart-column-line').each(function( index ) {
1509                 $( this ).show()
1510             });
1511         }
1512
1513         function removeColumn(id) {
1514             $('#'+id).remove();
1515
1516             if ( $('.chart-column-conf').length == 1 ) {
1517                 $('.chart-column-delete').remove();
1518             }
1519         }
1520
1521         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1522         var group_subgroups = {};
1523         [% FOREACH group IN groups_with_subgroups %]
1524             var gid = "[% group.id | html %]"
1525             group_subgroups[gid] = new Array();
1526             [% FOREACH subgroup IN group.subgroups %]
1527                 var sgid = "[% subgroup.id | html %]";
1528                 var sgname = "[% subgroup.name | html %]";
1529                 group_subgroups[gid].push([sgid, sgname]);
1530             [% END %]
1531         [% END %]
1532
1533         [% IF ( create || editsql || save ) %]
1534
1535             var editor = CodeMirror.fromTextArea(sql, {
1536                 lineNumbers: true,
1537                 mode: "text/x-sql",
1538                 lineWrapping: true,
1539                 smartIndent: false,
1540                 keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1541                     "\\[\\[(.*?)\\]\\]":"style1",
1542                     "<<(.*?)>>":"style1"
1543                 },
1544                 extraKeys: {"Tab": "autocomplete"}, //enable tab to accept auto-complete
1545                 hint: CodeMirror.hint.sql,
1546                 hintOptions: {
1547                     tables: [% To.json(tables) | $raw %]
1548                 }
1549             });
1550             var ExcludedTriggerKeys = { //key-code combinations of keys that will not fire the auto-complete script
1551                 "8": "backspace",
1552                 "9": "tab",
1553                 "13": "enter",
1554                 "16": "shift",
1555                 "17": "ctrl",
1556                 "18": "alt",
1557                 "19": "pause",
1558                 "20": "capslock",
1559                 "27": "escape",
1560                 "33": "pageup",
1561                 "32": "spacebar",
1562                 "34": "pagedown",
1563                 "35": "end",
1564                 "36": "home",
1565                 "37": "left",
1566                 "38": "up",
1567                 "39": "right",
1568                 "40": "down",
1569                 "45": "insert",
1570                 "46": "delete",
1571                 "56": "asterisk",
1572                 "59": "semicolon",
1573                 "91": "left window key",
1574                 "92": "right window key",
1575                 "93": "select",
1576                 "106": "asterisk",
1577                 "107": "add",
1578                 "109": "subtract",
1579                 "110": "decimal point",
1580                 "111": "divide",
1581                 "112": "f1",
1582                 "113": "f2",
1583                 "114": "f3",
1584                 "115": "f4",
1585                 "116": "f5",
1586                 "117": "f6",
1587                 "118": "f7",
1588                 "119": "f8",
1589                 "120": "f9",
1590                 "121": "f10",
1591                 "122": "f11",
1592                 "123": "f12",
1593                 "144": "numlock",
1594                 "145": "scrolllock",
1595                 "186": "semicolon",
1596                 "187": "equalsign",
1597                 "188": "comma",
1598                 "189": "dash",
1599                 "191": "slash",
1600                 "192": "graveaccent",
1601                 "220": "backslash",
1602                 "222": "quote"
1603             }
1604             //Trigger auto-complete on all keys not in dictionary of exclusions above.
1605             editor.on("keyup", function(cm, e) {
1606                 if (ExcludedTriggerKeys[e.keyCode] == undefined) {
1607                          CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
1608                 }
1609             })
1610
1611            // https://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages#answer-16025232
1612             function clearValidation( formElement ){
1613                 // formElement should be a jQuery object
1614                 var validator = formElement.validate();
1615                 // Iterate through named elements inside of the form, and mark them as error free
1616                 $('[name]',formElement).each(function(){
1617                     validator.successList.push(this);//mark as error free
1618                     validator.showErrors();//remove error messages if present
1619                 });
1620                 validator.resetForm();//remove error class on name elements and clear history
1621                 validator.reset();//remove all error and success data
1622             }
1623         [% END %]
1624
1625         [% IF ( showsql ) %]
1626
1627             var editor = CodeMirror.fromTextArea(sql, {
1628                 lineNumbers: false,
1629                 mode: "text/x-sql",
1630                 lineWrapping: true,
1631                 readOnly: true,
1632                 keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1633                     "\\[\\[(.*?)\\]\\]":"style2",
1634                     "<<(.*?)>>":"style1"
1635                },
1636             });
1637         [% END %]
1638
1639         function showParamModal( category ){
1640             var modal = $("#runtime_parameters");
1641             var modalTitle = $("#runtime_parametersLabel");
1642             switch ( category ){
1643                 case "insertAuthVal":
1644                     modalTitle.text( _("Insert authorized value parameter") );
1645                     $("#paramLabel").val( _("Authorized value") );
1646                     $("#authorised_value_category").show();
1647                     $("label[for='authorised_value']").addClass("required");
1648                     $("#authorised_value").prop("required", true ).attr("required", "required").addClass("required");
1649                     break;
1650                 case "insertCnSource":
1651                     modalTitle.text( _("Insert classification source parameter") );
1652                     $("#paramLabel").val( _("Source of classification or shelving scheme") );
1653                     $("#param_category").val("cn_source");
1654                     break;
1655                 case "insertFramework":
1656                     modalTitle.text( _("Insert bibliographic framework parameter") );
1657                     $("#paramLabel").val( _("Framework") );
1658                     $("#param_category").val("biblio_framework");
1659                     break;
1660                 case "insertDate":
1661                     modalTitle.text( _("Insert date parameter") );
1662                     $("#paramLabel").val( _("Date") );
1663                     $("#param_category").val("date");
1664                     break;
1665                 case "insertItemtypes":
1666                     modalTitle.text( _("Insert item types parameter") );
1667                     $("#paramLabel").val( _("Item type") );
1668                     $("#param_category").val("itemtypes");
1669                     break;
1670                 case "insertBranches":
1671                     modalTitle.text( _("Insert libraries parameter") );
1672                     $("#paramLabel").val( _("Library") );
1673                     $("#param_category").val("branches");
1674                     break;
1675                 case "insertCategorycode":
1676                     modalTitle.text( _("Insert patron category parameter") );
1677                     $("#paramLabel").val( _("Patron category") );
1678                     $("#param_category").val("categorycode");
1679                     break;
1680                 case "insertCashregister":
1681                     modalTitle.text( _("Insert cash register parameter") );
1682                     $("#paramLabel").val( _("Cash register") );
1683                     $("#param_category").val("cash_registers");
1684                     break;
1685                 case "insertDebittypes":
1686                     modalTitle.text( _("Insert debit type parameter") );
1687                     $("#paramLabel").val( _("Debit type") );
1688                     $("#param_category").val("debit_types");
1689                     break;
1690                 case "insertCredittypes":
1691                     modalTitle.text( _("Insert credit type parameter") );
1692                     $("#paramLabel").val( _("Credit type") );
1693                     $("#param_category").val("credit_types");
1694                     break;
1695                 case "insertList":
1696                     modalTitle.text( _("Insert list parameter") );
1697                     $("#paramLabel").val( _("List of values") );
1698                     $("#param_category").val("list");
1699                     break;
1700                 case "insertText":
1701                     modalTitle.text( _("Insert text parameter") );
1702                     $("#paramLabel").val( _("Text") );
1703                     $("#param_category").val("");
1704                     break;
1705             }
1706             $("#paramLabel").select();
1707             modal.modal("show");
1708         }
1709
1710         function load_group_subgroups () {
1711             var group = $("#group_select").val();
1712             var subgroup = $("#subgroup_select").val();
1713             var sg = $("#subgroup");
1714             $(sg).find('option[value!=""]').each(function() {
1715                 $(this).remove();
1716             });
1717             $(sg).hide();
1718             if (group) {
1719                 var select = $(sg).find('select')[0];
1720                 $.each( group_subgroups[group], function(index, value) {
1721                     if ( value[0] == subgroup ) {
1722                         $('<option selected="selected" value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1723                     } else {
1724                         $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1725                     }
1726                 } );
1727                 $("#subgroup, #subgroup *").show();
1728             }
1729         }
1730
1731         $(document).ready(function(){
1732
1733             var activeTab = localStorage.getItem("sql_reports_activetab");
1734
1735             $("body").on('click',".fetch_chart_data",function(){
1736                 if( [% unlimited_total || 0 | $raw %] > 1000 ){
1737                     if( confirm( _("Fetching full chart data for reports with many rows can cause performance issues. Are you sure you want to chart this report?") ) ){
1738                         return true;
1739                     } else {
1740                         return false;
1741                     }
1742                 }
1743             });
1744
1745             var showsql;
1746             hide_bar_element();
1747
1748             if ( $('.chart-column-conf').length == 1 ) {
1749                 $('.chart-column-delete').remove();
1750             }
1751
1752             $(".chart-column-delete").on('click', function(e){
1753                 e.preventDefault();
1754                 removeColumn('column_' + $(this).data('column'));
1755             })
1756
1757             $('#download-chart').click(function() {
1758                 var svg = '<svg>' + $('#chart svg').html() + '</svg>';
1759                 this.href = 'data:application/octet-stream;base64,' + btoa(svg);
1760                 this.setAttribute('download', 'chart.svg');
1761             });
1762
1763             $('#chart-type').change(function() {
1764                 if ($(this).val() == 'bar') {
1765                     show_bar_element();
1766                 }
1767                 else {
1768                     hide_bar_element();
1769                 }
1770             });
1771
1772             $('#download-chart').hide();
1773             var chart;
1774
1775             [% IF results && !errors %]
1776                 $('#draw-chart').click(function() {
1777
1778                     var x_elements = $('select[name="x"]').val();
1779                     var y_elements = [];
1780                     var groups = [];
1781                     var lines = [];
1782                     var options = {};
1783
1784                     headers = [% header_row.json | $raw %];
1785
1786                     var results;
1787                     [% IF allresults.size %]
1788                         if ($('input[name="chart-include-all"]').prop('checked')) {
1789                             results = [% allresults.json | $raw %]
1790                         }
1791                         else {
1792                             results = [% results.json | $raw %]
1793                         }
1794                     [% ELSE %]
1795                         results = [% results.json | $raw %];
1796                     [% END %]
1797
1798                     if ($('input[name="chart-exclude-last"]').prop('checked')) {
1799                         results.splice(-1, 1);
1800                     }
1801
1802                     $('select[name="y"]').each(function( index ) {
1803                         y_elements.push( $(this).val() );
1804                     });
1805                     $('select[name="group"]').each(function( index ) {
1806                         groups.push( $(this).val() );
1807                     });
1808                     $('.column-line').each(function( index ) {
1809                         if ($(this).prop('checked')) {
1810                             lines.push( $(this).attr('name') );
1811                         }
1812                     });
1813
1814                     // Remove deleted columns from headers and results.
1815                     var deleted_indexes = [];
1816                     var kept_headers = [];
1817                     $.each(headers, function(index, value) {
1818                         if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
1819                             // This header is neither a x element nor in y elements. Don't need it.
1820                             deleted_indexes.push(index);
1821                         }
1822                         else {
1823                             kept_headers.push({cell: value.cell});
1824                         }
1825                     });
1826
1827                     // Remove coresponding cells.
1828                     var kept_results = [];
1829                     $.each(results, function(index, value) {
1830                         var line = {};
1831                         line['cells'] = [];
1832                         $.each(value.cells, function(i, val) {
1833                             if ($.inArray(i, deleted_indexes) === -1) {
1834                                 line['cells'].push({cell: val.cell});
1835                             }
1836                         });
1837                         kept_results.push(line);
1838                     });
1839
1840                     options.type = $('select[name="chart-type"]').val();
1841                     options.horizontal = $('input[name="column-horizontal"]').prop('checked');
1842                     options.lines = lines;
1843
1844                     chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
1845                     $("#download-chart,#toggle_chart_settings_hid,#chart").show();
1846                     $("#toggle_chart_settings_vis").hide();
1847                     $("#chartModal").modal("hide");
1848                 });
1849             [% END %]
1850             [% IF ( create ) %]
1851                 load_group_subgroups();
1852             [% END %]
1853
1854             $('[data-toggle="tooltip"]').tooltip();
1855
1856             $('#limit').change(function() {
1857                 $('#limitselect').submit();
1858             });
1859
1860             $(document).click(function() {
1861                 $('#report_updated').hide();
1862             });
1863
1864             $(".goback").on("click",function(e){
1865                 e.preventDefault();
1866                 window.history.back();
1867             });
1868
1869             $("body").on("click", ".mana_search_button", function(){
1870                 $("#mana-loading").show();
1871                 mana_search($("#mana_search_field").val());
1872             });
1873
1874             $(".ShareButton").on("click", function(){
1875                 $("#note-error").hide();
1876                 if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){
1877                     $(".shared_infos").hide();
1878                     $("#note-error").show();
1879                 }
1880                 else{
1881                     $("#reportid").val($(this).closest("tr").find(".report_id").text());
1882                     $("#shared_id").html($(this).closest("tr").find(".report_id").text());
1883                     $("#shared_name").html($(this).closest("tr").find(".report_name").text());
1884                     $("#shared_sql").html($(this).closest("tr").find(".report_sql").val());
1885                     $("#shared_type").html($(this).closest("tr").find(".report_type").text());
1886                     $("#shared_group").html($(this).closest("tr").find(".report_group").text());
1887                     $("#shared_notes").html($(this).closest("tr").find(".report_notes").text());
1888                 }
1889             });
1890
1891             $("#ManaCloseButton").on("click", function() {
1892                 $(".shared_infos").show();
1893             });
1894
1895             $("#addColumn").on("click",function(){
1896                 addColumn();
1897             });
1898
1899             $("#delColumn").on("click",function(){
1900                 delColumn();
1901             });
1902
1903             [% IF (saved1) %]
1904                 var table_settings = [% TablesSettings.GetTableSettings( 'reports', 'saved-sql', 'table_reports', 'json' ) | $raw %];
1905                 var rtable = KohaTable("table_reports", {
1906                     'bAutoWidth': false,
1907                     'sPaginationType': 'full',
1908                     'aaSorting': [[ 1, "asc" ]],
1909                     'oLanguage': {
1910                         'sZeroRecords': _("No matching reports found")
1911                     }
1912                 }, table_settings);
1913
1914                 $("#tabs a[data-toggle='tab']").on("shown.bs.tab", function (e) {
1915                     tabsInit( $(e.target).parent(), rtable );
1916                 });
1917
1918                 if( activeTab ){
1919                     $("#tabs li:eq(" + activeTab + ") a").tab("show");
1920                 }
1921
1922                 $("#subgroup_filter").change(function() {
1923                     var selected = $(this).find('option:selected');
1924                     var sg_id = $(selected).val();
1925                     var sg_name = $(selected).text();
1926                     if (sg_id.length > 0) {
1927                         rtable.fnFilter('^' + sg_name + '$', 5, true, true, true, false);
1928                         rtable.fnSetColumnVis(5, false);
1929                     } else {
1930                         rtable.fnFilter('', 5);
1931                         rtable.fnSetColumnVis(5, true);
1932                     }
1933                 });
1934
1935                 $("#reports_form").submit(function(){
1936                     var checkedItems = $("input[name=ids]:checked");
1937                     if ($(checkedItems).size() == 0) {
1938                         alert(_("You must select one or more reports to delete"));
1939                         return false;
1940                     }
1941                     $(checkedItems).parents('tr').addClass("warn");
1942                     if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
1943                         return true;
1944                     } else {
1945                         $(checkedItems).parents('tr').removeClass("warn");
1946                         return false;
1947                     }
1948                 });
1949
1950                 $("body").on("click", ".update_sql", function(e){
1951                     e.preventDefault();
1952                     var ltitle = $(this).text();
1953                     var report_id = $(this).data("report_id");
1954                     var page = $(this).attr("href");
1955                     $("#update_sql .modal-body").load(page + " div", function(){
1956                         var diff1 = $("#col1 .show_sql").text();
1957                         var diff2 = $("#col2 .show_sql").text();
1958                         var diffs = diffString( escape(diff1), escape(diff2) );
1959                         $("#col1 .show_sql,#col2 .show_sql").html(diffs);
1960                     });
1961                     $('#update_sql').modal('show');
1962                     $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id);
1963                 });
1964
1965                 $("#update_sql").on("hidden.bs.modal", function(){
1966                     $("#update_sql_label").html("");
1967                     $("#update_sql .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
1968                 });
1969             [% END %]
1970
1971             [% IF ( showsql ) %]
1972                 $("#sql").focus(function() {
1973                     $(this).select();
1974                 });
1975             [% END %]
1976
1977             $("#toggle_sql").click(function(){
1978                 var sql_output = $("#sql_output");
1979                 sql_output.toggle();
1980                 if( sql_output.is(":visible") ){
1981                     $(this).button('complete');
1982                 } else {
1983                     $(this).button('reset');
1984                 }
1985                 if( !showsql ){
1986                     showsql = CodeMirror.fromTextArea(sql, {
1987                         lineNumbers: false,
1988                         mode: "text/x-sql",
1989                         lineWrapping: true,
1990                         readOnly: true
1991                     });
1992                 }
1993             });
1994
1995             $(".toggle_chart_settings").click(function(){
1996                 $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
1997             });
1998
1999             $("#table_reports").delegate(".confirmdelete", 'click', function(){
2000                 $(this).parents('tr').attr("class","warn");
2001                 if(confirm(_("Are you sure you want to delete this saved report?"))){
2002                     return true;
2003                 } else {
2004                     $(this).parents('tr').attr("class","");
2005                     return false;
2006                 }
2007             });
2008
2009             [% IF (create || editsql || save) %]
2010
2011                 var validated_form = $("#sql_report_form").validate({
2012                     reportname: "required",
2013                     group_input: {
2014                         required: {
2015                             depends: function(element) {
2016                                 return $("#create_group").prop("checked") && $("#groupdesc_input").val() != '';
2017                             }
2018                         }
2019                     },
2020                     groupdesc_input: {
2021                         required: {
2022                             depends: function(element) {
2023                                 return $("#create_group").prop("checked") && $("#group_input").val() != '';
2024                             }
2025                         }
2026                     }
2027                 });
2028
2029                 $("#select_group").change(function() {
2030                     if($(this).prop('checked')) {
2031                         $("#group_input").attr("class","").prop('disabled', true).prop("required", false);
2032                         $("#groupdesc_input").attr("class","").prop('disabled', true).prop("required", false);
2033                         $("#group_select").prop('disabled', false);
2034                         clearValidation( $("#sql_report_form") );
2035                         if ($("#group_select").val().length > 0) {
2036                             $("#select_subgroup").prop('checked', true);
2037                             $("#select_subgroup").change();
2038                             $("#subgroup, #subgroup *").show();
2039                         } else {
2040                             $("#subgroup").hide();
2041                         }
2042                     }
2043                 });
2044                 $("#create_group").change(function() {
2045                     if($(this).prop('checked')) {
2046                         $("#group_input").prop('disabled', false).prop("required", true );
2047                         $("#groupdesc_input").prop('disabled', false).prop("required", true );
2048                         $("#group_select").prop('disabled', true);
2049                         // $("#create_subgroup").prop('checked', true).change();
2050                         $("#subgroup_select").hide();
2051                         $("#subgroup input[type='radio']").hide();
2052                         $("#subgroup label[for]").hide();
2053                         $("#subgroup_input").prop("required", false ).prop("disabled", false).show();
2054                         $("#subgroupdesc_input").prop("required", false ).prop("disabled", false).show();
2055                         $("#subgroup").show();
2056                         // Add validation rules for fields which were previously hidden
2057                         $("#subgroup_input").rules("add", {
2058                             required: {
2059                                 depends: function(element) {
2060                                     return $("#create_group").prop("checked") &&  $("#subgroupdesc_input").val() != '';
2061                                 }
2062                             }
2063                         });
2064                         $("#subgroupdesc_input").rules("add", {
2065                             required: {
2066                                 depends: function(element) {
2067                                     return $("#create_group").prop("checked") &&  $("#subgroup_input").val() != '';
2068                                 }
2069                             }
2070                         });
2071                     }
2072                 });
2073                 $("#select_subgroup").change(function() {
2074                     if($(this).prop('checked')) {
2075                         $("#subgroup_select").prop('disabled', false);
2076                         $("#subgroup_input").prop('disabled', true).prop("required", false );
2077                         $("#subgroupdesc_input").prop('disabled', true).prop("required", false );
2078                         clearValidation( $("#sql_report_form") );
2079                     }
2080                 });
2081                 $("#create_subgroup").change(function() {
2082                     if($(this).prop('checked')) {
2083                         $("#subgroup_input").prop('disabled', false).prop("required", true );
2084                         $("#subgroupdesc_input").prop('disabled', false).prop("required", true );
2085                         $("#subgroup_select").val("").prop('disabled', true);
2086                     }
2087                 });
2088                 $("#select_group").change();
2089                 $("#select_subgroup").change();
2090                 $("#group_select").on("change",function(){
2091                     load_group_subgroups();
2092                 });
2093
2094                 $(".insertParam").on("click", function(e){
2095                     e.preventDefault();
2096                     var category = this.id;
2097                     showParamModal( category );
2098                 });
2099
2100                 $("#runtime_parameters").on("shown.bs.modal", function(){
2101                     $("#paramLabel").focus();
2102                 });
2103
2104                 $("#runtime_parameters").on("hide.bs.modal", function(){
2105                     $("#send_runtime_parameter")[0].reset();
2106                     $("#authorised_value_category").val("").hide();
2107                     $("label[for='authorised_value']").removeClass("required");
2108                     $("#authorised_value").prop("required", false ).removeAttr("required").removeClass("required");
2109                 });
2110
2111                 $("#send_runtime_parameter").on("submit", function(e){
2112                     e.preventDefault();
2113                     /* Get form values */
2114                     var paramLabel = $("#paramLabel").val();
2115                     var param_category = $("#param_category").val();
2116                     var categoryLabel = $("#authorised_value").val();
2117                     // Get CodeMirror environment variables
2118                     var selection = editor.getSelection();
2119                     var doc = editor.getDoc();
2120                     var cursor = doc.getCursor();
2121                     var pos = {
2122                         line: cursor.line,
2123                         ch: cursor.ch
2124                     }
2125                     /* Build runtime parameter text string */
2126                     var text = "";
2127                     if( paramLabel && param_category ){
2128                         text += paramLabel + "|" + param_category;
2129                     } else if( paramLabel ) {
2130                         text += paramLabel;
2131                     } else if( param_category ){
2132                         text += param_category;
2133                     }
2134                     if( text != "" ){
2135                         text = " <<" + text + ">> ";
2136                         if( selection.length > 0){
2137                             editor.replaceSelection(text);
2138                         } else {
2139                             doc.replaceRange(text, pos);
2140                         }
2141                     }
2142                     $("#runtime_parameters").modal("hide");
2143                 });
2144
2145                 $("#authorised_value").on("change", function(){
2146                     $("#param_category").val( $(this).val() );
2147                 });
2148
2149             [% END %]
2150
2151             $(".delete").on("click",function(){
2152                 return confirmDelete(MSG_CONFIRM_DELETE);
2153             });
2154
2155             $("#mana_search_form").submit(function(e){
2156                 e.preventDefault();
2157             });
2158
2159             $("#column_submit").submit(function() {
2160                 if ($("#selectedColumns option").size() < 1) {
2161                     alert(_("No columns selected!"));
2162                     return false;
2163                 }
2164                 $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
2165                 return true;
2166             });
2167
2168             // Mana KB
2169             $("body").on("click", ".mana-use", function(e) {
2170                 e.preventDefault();
2171                 $(this).find("i").attr("class","fa fa-refresh fa-spin");
2172                 mana_use( $(this).data("report_id") );
2173             });
2174
2175             $("#mana_search_result").on("shown.bs.modal", function(){
2176                 $("#mana_search_field").focus();
2177             });
2178
2179             $("#mana_search_result").on("hide.bs.modal", function(){
2180                 $("#mana_result_content").html("");
2181                 $("#mana_search_field").val("");
2182             });
2183
2184             $(".batch_op").on("click", function(e){
2185                 e.preventDefault();
2186                 var target_form = $(this).data("submit");
2187                 $("#" + target_form ).submit();
2188             });
2189
2190             $("#batch_add_to_list").on("submit", function(e){
2191                 e.preventDefault();
2192                 addToList();
2193             });
2194
2195             $("body").on("click", ".preview_sql", function(e){
2196                 e.preventDefault();
2197                 var reportid = $(this).data("reportid");
2198                 previewSql( reportid );
2199             });
2200             $(".limitselect").on("click", function(){
2201                 var limit = $(this).data("limit");
2202                 $("#limit").val( limit );
2203                 $("#limitselect").submit();
2204             });
2205
2206         });
2207
2208         $("#toggle_auto_links").on("click", function(e){
2209             e.preventDefault();
2210             if( $(".data-plain").is(":visible") ){
2211                 /* if a data-plain element is visible, this click hides it and shows auto-links */
2212                 localStorage.removeItem("reports_auto_link_off");
2213             } else {
2214                 /* if a data-plain element is hidden, this click shows it  and hides auto-links */
2215                 localStorage.setItem("reports_auto_link_off", 1);
2216             }
2217             $(".data-plain,.autolink").toggle();
2218         });
2219         if ( localStorage.getItem("reports_auto_link_off") == 1 ){
2220             $("#toggle_auto_links").click();
2221         }
2222
2223         function tabsInit( tab, rtable ){
2224             var activeTab = tab.index();
2225             localStorage.setItem("sql_reports_activetab", activeTab );
2226
2227             $("#subgroup_filter option").each(function() {
2228                 if($(this).val().length > 0) {
2229                     $(this).remove();
2230                 }
2231             });
2232             rtable.fnFilter('', 4);
2233             rtable.fnFilter('', 5);
2234             rtable.fnSetColumnVis(4, true);
2235             rtable.fnSetColumnVis(5, true);
2236
2237             var g_id = tab.find("a").data("tabname");
2238             var g_name = tab.find("a").text().trim();
2239
2240             if ( g_name == _("All") ) {
2241                 g_id = "";
2242                 g_name = "";
2243             }
2244
2245             if (g_id && g_id.length > 0) {
2246                 rtable.fnFilter('^' + g_name + '$', 4, true, true, true, false);
2247                 rtable.fnSetColumnVis(4, false);
2248                 for(var i in group_subgroups[g_id]) {
2249                     $("#subgroup_filter").append(
2250                         '<option value="' + group_subgroups[g_id][i][0] + '">'
2251                         + group_subgroups[g_id][i][1] + '</option>'
2252                     );
2253                 }
2254                 $("#subgroup_filter_block").show();
2255             } else {
2256                 $("#subgroup_filter_block").hide();
2257             }
2258         }
2259
2260         function addColumn() {
2261             $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
2262         }
2263         function delColumn() {
2264             $("#selectedColumns option:selected").remove();
2265         }
2266
2267         // Mana KB
2268         function mana_use( mana_id ){
2269             $.ajax( {
2270                 type:"POST",
2271                 url: "/cgi-bin/koha/svc/mana/use",
2272                 data: {id:mana_id, resource: 'report', saveinbase: 1},
2273                 dataType: "json",
2274             })
2275             .done( function (result){
2276                 if ( result.errmsg ){
2277                     alert( result.errmsg );
2278                 }
2279                 else{
2280                     window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL&mana_success=1");
2281                 }
2282             })
2283             .fail(function( error ) {
2284                 $(".mana_use_status").hide();
2285                 $("#mana_use_errortext").html( error.status + " " + error.statusText );
2286                 $("#mana_use_failed").show();
2287                 $(".mana-use i").attr("class","fa fa-download");
2288             });
2289         }
2290
2291         function mana_search( textquery ){
2292             $(".mana_search_status").hide();
2293             $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", { resource: 'report', id: textquery, usecomments: 1 }, function( response, status, xhr ) {
2294
2295                     if ( status == "error" ) {
2296                         $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
2297                         $("#mana_search_failed").show();
2298                         $("#mana-loading").hide();
2299                     } else {
2300                         $(".mana_search_status").hide();
2301                         $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2302                         $("#mana-loading").hide();
2303                         $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
2304                             "sPaginationType":"full",
2305                             "autoWidth": false,
2306                             "columnDefs": [
2307                                 { "width": "35%", "targets": 1 }
2308                             ],
2309                             "aoColumnDefs": [
2310                                 { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
2311                                 { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
2312                             ]
2313                         }));
2314
2315                         $(".showbutton").on("click", function(e){
2316                             e.preventDefault();
2317                             $(this).parent().hide();
2318                             $(this).parent().next().show();
2319                         });
2320
2321                         $(".hidebutton").on("click", function(e){
2322                             e.preventDefault();
2323                             $(this).parent().hide();
2324                             $(this).parent().prev().show();
2325                         });
2326
2327                         if($("td.dataTables_empty").length == 0){
2328                             $("#mana_search_message").show();
2329                         }
2330                     }
2331                 });
2332         }
2333
2334         function addToList() {
2335             var biblionumbers = [];
2336             $(".bib_to_list").each(function() {
2337                 var biblionumber = Number( $(this).val() );
2338                 if( biblionumbers.indexOf( biblionumber ) < 0 ){
2339                     biblionumbers.push( biblionumber );
2340                 }
2341             });
2342             bibs = biblionumbers.join("/");
2343             var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
2344             window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
2345             return false;
2346         }
2347
2348         // Adapted from https://gist.github.com/jnormore/7418776
2349         function previewSql(reportid) {
2350             var yes_label = "";
2351             var no_label = "";
2352             var message = $("#previewSql" + reportid ).val();
2353             var title = $("#previewSql" + reportid ).data("title");
2354             if( $("#preview-sql-modal").length > 0) {
2355                 $("#preview-sql-modal").remove();
2356             }
2357             $("body").append('<div id="preview-sql-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal">\
2358                 <div class="modal-dialog">\
2359                     <div class="modal-content">\
2360                         <div class="modal-header" style="min-height:40px;">\
2361                             <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">\
2362                                 <span aria-hidden="true">×</span>\
2363                             </button>\
2364                             <h4 class="modal-title">' + title + '</h4>\
2365                         </div>\
2366                         <div class="modal-body"><textarea id="code' + reportid + '">' + message + '</textarea>\
2367                         </div>\
2368                         <div class="modal-footer">\
2369                             <a id="preview-modal-editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> ' + _("Edit") + '</a>\
2370                             <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>\
2371                             <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=' + reportid + '"><i class="fa fa-clock-o"></i> ' + _("Schedule") + '</a>\
2372                             <a id="preview-modal-delete" class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Delete%20Saved"><i class="fa fa-trash"></i> ' + _("Delete") + '</a>\
2373                             <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>\
2374                             <a href="#" id="preview-sql-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-remove" aria-hidden="true"></i> ' + _("Close") + '</a>\
2375                         </div>\
2376                     </div>\
2377                 </div>\
2378             </div>');
2379
2380             $("#preview-sql-modal").modal('show');
2381             CodeMirror.fromTextArea( document.getElementById("code" + reportid ), {
2382                 lineNumbers: false,
2383                 mode: "text/x-sql",
2384                 lineWrapping: true,
2385                 readOnly: true
2386             });
2387         }
2388     </script>
2389 [% END %]
2390
2391 [% INCLUDE 'intranet-bottom.inc' %]
2392
2393 [% BLOCK group_and_subgroup_selection %]
2394     <li id="group">
2395         <label>Report group:</label>
2396         <input type="radio" name="select_or_create_group"
2397             id="select_group" checked="checked" />
2398         <label for="select_group" class="radio">Select</label>
2399         <select name="group" id="group_select">
2400             <option value="">(None)</option>
2401             [% FOREACH group IN groups_with_subgroups %]
2402                 [% IF (group.selected) %]
2403                     <option value="[% group.id | html %]" selected="selected">
2404                 [% ELSE %]
2405                     <option value="[% group.id | html %]">
2406                 [% END %]
2407                     [% group.name | html %]
2408                 </option>
2409             [% END %]
2410         </select>
2411         <input type="radio" name="select_or_create_group" id="create_group" />
2412         <label for="create_group" class="radio">or create:</label>
2413         <input type="text" name="group" id="group_input" title="Group code" placeholder="Code" />
2414         <input type="text" name="groupdesc" id="groupdesc_input" title="Group name" placeholder="Name" />
2415     </li>
2416     <li id="subgroup">
2417         <label>Report subgroup:</label>
2418         <input type="radio" name="select_or_create_subgroup"
2419             id="select_subgroup" checked="checked" />
2420         <label for="select_subgroup" style="float:none">Select</label>
2421         <select name="subgroup" id="subgroup_select">
2422             <option value="">(None)</option>
2423             [% FOREACH group IN groups_with_subgroups %]
2424                 [% IF (group.selected) %]
2425                     [% FOREACH subgroup IN group.subgroups %]
2426                         [% IF (subgroup.selected) %]
2427                             <option value="[% subgroup.id | html %]" selected="selected">
2428                         [% ELSE %]
2429                             <option value="[% subgroup.id | html %]">
2430                         [% END %]
2431                             [% subgroup.name | html %]
2432                         </option>
2433                     [% END %]
2434                 [% END %]
2435             [% END %]
2436         </select>
2437         <input type="radio" name="select_or_create_subgroup"
2438             id="create_subgroup" />
2439         <label for="create_subgroup" style="float:none">or create</label>
2440         <input type="text" name="subgroup" id="subgroup_input" title="Subgroup code" placeholder="Code" />
2441         <input type="text" name="subgroupdesc" id="subgroupdesc_input" title="Subgroup name" placeholder="Name" />
2442     </li>
2443 [% END %]
2444
2445 [% BLOCK insert_runtime_parameter %]
2446     <div class="btn-group"  style="margin-left:30px;">
2447         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2448             Insert runtime parameter <span class="caret"></span>
2449         </button>
2450         <ul class="dropdown-menu">
2451             <li><a href="#" class="insertParam" id="insertAuthVal">Authorized values</a></li>
2452             <li><a href="#" class="insertParam" id="insertFramework">Bibliographic framework</a></li>
2453             <li><a href="#" class="insertParam" id="insertCnSource">Classification sources</a></li>
2454             <li><a href="#" class="insertParam" id="insertDate">Date</a></li>
2455             <li><a href="#" class="insertParam" id="insertItemtypes">Item types</a></li>
2456             <li><a href="#" class="insertParam" id="insertBranches">Libraries</a></li>
2457             <li><a href="#" class="insertParam" id="insertList">List</a></li>
2458             <li><a href="#" class="insertParam" id="insertCategorycode">Patron categories</a></li>
2459             <li><a href="#" class="insertParam" id="insertCashregister">Cash registers</a></li>
2460             <li><a href="#" class="insertParam" id="insertDebittypes">Debit types</a></li>
2461             <li><a href="#" class="insertParam" id="insertCredittypes">Credit types</a></li>
2462             <li><a href="#" class="insertParam" id="insertText">Text field</a></li>
2463         </ul>
2464     </div>
2465 [% END %]