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