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