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