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