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