Bug 17282: Ability to create charts for SQL reports
[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 ColumnsSettings %]
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>Koha &rsaquo; Reports &rsaquo; Guided reports wizard [%- IF ( saved1 ) -%]&rsaquo; Saved reports
23 [%- ELSIF ( create ) -%]&rsaquo; Create from SQL
24 [%- ELSIF ( showsql ) -%]&rsaquo; Saved reports &rsaquo; SQL view
25 [%- ELSIF ( execute ) -%]&rsaquo; Saved reports &rsaquo; [% name | html %] Report
26 [%- ELSIF ( editsql ) -%]&rsaquo; Saved reports &rsaquo; Edit SQL report
27 [%- END -%]
28 [%- IF ( build1 ) -%]&rsaquo; Build a report, step 1 of 6: Choose a module
29 [%- ELSIF ( build2 ) -%]&rsaquo; Build a report, step 2 of 6: Pick a report type
30 [%- ELSIF ( build3 ) -%]&rsaquo; Build a report, step 3 of 6: Select columns for display
31 [%- ELSIF ( build4 ) -%]&rsaquo; Build a report, step 4 of 6: Select criteria to limit on
32 [%- ELSIF ( build5 ) -%]&rsaquo; Build a report, step 5 of 6: Pick which columns to total
33 [%- ELSIF ( build6 ) -%]&rsaquo; Build a report, step 6 of 6: Select how you want the report ordered
34 [%- END -%]</title>
35
36 [% INCLUDE 'doc-head-close.inc' %]
37 [% IF ( saved1 ) %]
38     [% Asset.css("css/reports.css") | $raw %]
39     [% Asset.css("css/datatables.css") | $raw %]
40 [% END %]
41 [% Asset.css("../lib/d3c3/c3.min.css") | $raw %]
42 </head>
43
44 <body id="rep_guided_reports_start" class="rep">
45 [% INCLUDE 'header.inc' %]
46 [% INCLUDE 'circ-search.inc' %]
47
48 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
49 &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
50 &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
51
52 [% IF ( saved1 ) %]&rsaquo; Saved reports
53 [% ELSIF ( create ) %]&rsaquo; Create from SQL
54 [% ELSIF ( showsql ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; SQL view
55 [% ELSIF ( editsql ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; Edit SQL report
56 [% ELSIF ( execute ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <em>[% name | html %]</em> Report
57 [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
58     [% IF ( build1 ) %]&rsaquo; Step 1 of 6: Choose a module
59     [% ELSIF ( build2 ) %]&rsaquo; Step 2 of 6: Pick a report type
60     [% ELSIF ( build3 ) %]&rsaquo; Step 3 of 6: Select columns for display
61     [% ELSIF ( build4 ) %]&rsaquo; Step 4 of 6: Select criteria to limit on
62     [% ELSIF ( build5 ) %]&rsaquo; Step 5 of 6: Pick which columns to total
63     [% ELSIF ( build6 ) %]&rsaquo; Step 6 of 6: Select how you want the report ordered
64     [% END %]
65 [% END %]
66 </div>
67
68 <div id="update_sql" class="modal" tabindex="-1" role="dialog" aria-labelledby="update_sql_label" aria-hidden="true">
69     <div class="modal-dialog">
70     <div class="modal-content">
71     <div class="modal-header">
72         <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
73         <h3 id="update_sql_label">Update SQL</h3>
74     </div>
75     <div class="modal-body">
76         <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
77     </div>
78     <div class="modal-footer">
79         <a href="#" class="btn btn-default" id="update_sql_button" role="button" data-toggle="modal">Update</a>
80         <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
81     </div>
82     </div>
83     </div>
84 </div>
85
86 <div id="doc3" class="yui-t1">
87 <div id="bd">
88 <div id="yui-main">
89     <div class="yui-b">
90     [% INCLUDE "reports-toolbar.inc" %]
91
92 [% IF ( start ) %]
93     <h2>Guided reports</h2>
94     <p>Use the guided reports engine to create non standard reports.
95 This feature aims to provide some middle ground between the built in
96 canned reports and writing custom SQL reports.</p>
97
98     <h3>Build and run reports</h3>
99         [% IF ( CAN_user_reports_create_reports ) %]
100         <form action="/cgi-bin/koha/reports/guided_reports.pl">
101             <input type="hidden" name="phase" value="Build new" />
102             <input type="submit" name="submit" value="Build new"/>
103         </form>
104         [% END %]
105         [% IF ( CAN_user_reports_execute_reports ) %]
106         <form action="/cgi-bin/koha/reports/guided_reports.pl">
107             <input type="hidden" name="phase" value="Use saved"/>
108             <input type="submit" name="submit" value="Use saved"/>
109         </form>
110         [% END %]
111         [% IF ( CAN_user_reports_create_reports ) %]
112         <form action="/cgi-bin/koha/reports/guided_reports.pl">
113             <input type="hidden" name="phase" value="Create report from SQL"/>
114             <input type="submit" name="submit" value="Create report from SQL"/>
115         </form>
116         [% END %]
117 <h3>Reports Dictionary</h3>
118 <p>Use the reports dictionary to define custom criteria to use in your reports</p>
119 <form action="/cgi-bin/koha/reports/dictionary.pl">
120 <input type="hidden" name="phase" value="View Dictionary"/>
121 <input type="submit" name="submit" value="View dictionary"/>
122 </form>
123 [% END %]
124
125 [% IF report_converted %]
126     <div class="dialog message">
127         The report "[% report_converted | html %]" has been converted.
128     </div>
129 [% END %]
130
131 [% IF ( saved1 ) %]
132 [% IF ( savedreports ) %]<h1>Saved reports</h1>
133
134 [% IF ( filters.date || filters.author || filters.keyword ) %]
135     <p>Filtered by:
136         <span class="filter">
137             [% IF ( filters.date ) %]
138                 <span class="filter_date"><strong>Date:</strong> [% filters.date | html %]</span>
139             [% END %]
140             [% IF ( filters.author ) %]
141                 <span class="filter_author"><strong>Author:</strong> [% filters.author | html %]</span>
142             [% END %]
143             [% IF ( filters.keyword ) %]
144                 <span class="filter_keyword"><strong>Keyword:</strong> [% filters.keyword | html %]</span>
145             [% END %]
146             <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>
147         </span>
148     </p>
149 [% END %]
150
151 <div id="tabs" class="toptabs">
152     <ul>
153         <li><a href="#reports">All</a></li>
154         [% FOREACH group IN groups_with_subgroups %]
155             <li><a id="[% group.id | html %]" href="#reports">[% group.name | html %]</a></li>
156         [% END %]
157     </ul>
158     <div id="reports">
159         <div id="subgroup_filter_block">
160             <label for="subgroup_filter">Subgroup:</label>
161             <select id="subgroup_filter">
162                 <option value="">All</option>
163             </select>
164         </div>
165 <form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post">
166 <input type="hidden" name="phase" value="Delete Multiple" />
167         <table id="table_reports">
168             <thead>
169                 <tr>
170                     <th>&nbsp;</th>
171                     <th>ID</th>
172                     <th>Report name</th>
173                     <th>Type</th>
174                     <th>Group</th>
175                     <th>Subgroup</th>
176                     <th>Notes</th>
177                     <th>Author</th>
178                     <th class="title-string">Creation date</th>
179                     <th class="title-string">Last edit</th>
180                     <th class="title-string">Last run</th>
181                     <th class="report_public">Public</th>
182                     <th class="report_json_url">JSON URL</th>
183                     [% IF (usecache) %]
184                         <th>Cache expiry (seconds)</th>
185                     [% ELSE %]
186                         <th class="hidden">&nbsp;</th>
187                     [% END %]
188                     <th>Saved results</th>
189                     [% IF has_obsolete_reports %]
190                         <th>Update</th>
191                     [% ELSE %]
192                         <th class="hidden">&nbsp;</th>
193                     [% END %]
194                     <th>Actions</th>
195                 </tr>
196             </thead>
197             <tbody>
198                 [% FOREACH savedreport IN savedreports %]
199                     [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
200                         <td>
201                             [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS -->
202                                 <input type="checkbox" name="ids" value="[% savedreport.id | html %]" />
203                             [% END %]
204                         </td>
205                         <td><label for="ids">[% savedreport.id | html %]</label></td>
206                         <td>
207                             [% IF ( savedreport.report_name ) %]
208                                 [% savedreport.report_name | html %]
209                             [% ELSE %]
210                                 [ no name ]
211                             [% END %]
212                         </td>
213                         <td>[% savedreport.type | html %]</td>
214                         <td>[% savedreport.groupname | html %]</td>
215                         <td>[% savedreport.subgroupname | html %]</td>
216                         <td>[% savedreport.notes | html %]</td>
217                         <td>[% savedreport.borrowersurname | html %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname | html %][% END %] ([% savedreport.borrowernumber | html %])</td>
218                         <td><span title="[% savedreport.date_created | html %]">[% savedreport.date_created | $KohaDates %]</span></td>
219                         <td><span title="[% savedreport.last_modified | html %]">[% savedreport.last_modified | $KohaDates with_hours => 1 | html %]</span></td>
220                         <td><span title="[% savedreport.last_run | html %]">[% savedreport.last_run | $KohaDates with_hours => 1 | html %]</span></td>
221                         <td class="report_public">
222                         [% IF (savedreport.public) %]
223                             Yes
224                         [% ELSE %]
225                             No
226                         [% END %]
227                         </td>
228                         <td class="report_json_url">
229                         [% IF (savedreport.public) %]
230                             <a href="[% OPACBaseURL | html %]/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% OPACBaseURL | html %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
231                         [% ELSE %]
232                             <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>
233                         [% END %]
234                         </td>
235                         <td>[% savedreport.cache_expiry | html %]</td>
236                         <td>
237                             [% FOR result IN savedreport.results %]
238                                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% result.id | html %]">[% result.date_run | html %]</a>
239                                 <br/>
240                             [% END %]
241                         </td>
242                         <td>
243                             [% IF savedreport.seems_obsolete %]
244                                 This report seems obsolete, it uses biblioitems.marcxml field.
245                                 <a href="/cgi-bin/koha/svc/convert_report?report_id=[% savedreport.id | html %]" 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>
246                             [% END %]
247                         </td>
248                         <td>
249                             <div class="dropup">
250                                 <div class="btn-group">
251                                     [%# There should be no space between these two buttons, it would render badly %]
252                                     <a class="btn btn-default btn-xs" role="button"
253                                        href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Run%20this%20report"><i
254                                        class="fa fa-play"></i> Run</a><a
255                                        class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown"
256                                        href="#"><b class="caret"></b></a>
257                                     <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
258                                         <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> Show</a></li>
259                                         [% IF ( CAN_user_reports_create_reports ) %]
260                                             <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a></li>
261                                             <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from SQL&amp;sql=[% savedreport.savedsql |uri %]&amp;reportname=[% savedreport.report_name |uri %]&amp;notes=[% savedreport.notes |uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
262                                         [% END %]
263                                         <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | html %]"><i class="fa fa-clock-o"></i> Schedule</a></li>
264                                         [% IF ( CAN_user_reports_delete_reports ) %]
265                                             <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>
266                                         [% END %]
267                                     </ul>
268                                 </div>
269                             </div>
270                         </td>
271                     </tr>
272                 [% END %]
273             </tbody>
274         </table>
275         [% IF ( CAN_user_reports_delete_reports ) %]
276         <fieldset class="action">
277             <input type="submit" value="Delete selected" />
278         </fieldset>
279         [% END %]
280     </form>
281     </div>
282 </div>
283 [% ELSE %]<div class="dialog message">
284     [% IF (filter_set || filters.date || filters.author || filters.keyword) %]
285     <h4>No saved reports match your criteria. </h4>
286     [% IF ( CAN_user_reports_create_reports ) %]
287     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
288     <input type="hidden" name="phase" value="Build new" />
289         <button type="submit" class="new"><i class="fa fa-plus"></i> New guided report</button>
290     </form>
291
292     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
293         <input type="hidden" name="phase" value="Create report from SQL" />
294         <button type="submit" class="new"><i class="fa fa-plus"></i> New SQL report</button>
295     </form>
296
297     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
298     <input type="hidden" name="phase" value="Use saved" />
299     <input type="hidden" name="filter_set" value="1" />
300     <input type="hidden" name="filter_keyword" value="" />
301         <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> Cancel filter</button>
302     </form>
303
304     [% END %]
305     [% ELSE %]
306     <h4>There are no saved reports. </h4>
307     [% IF ( CAN_user_reports_create_reports ) %]
308         <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a new report?</a>
309     [% END %]
310     [% END %]
311     </div>
312 [% END %]
313 [% END %]
314
315
316 [% IF ( build1 ) %]
317 [% IF ( cache_error) %]
318 <div class="dialog alert">
319 <b> Please choose a cache_expiry less than 30 days </b>
320 </div>
321 [% END %]
322 <h1>Build a report</h1>
323 <form action="/cgi-bin/koha/reports/guided_reports.pl">
324 <fieldset class="rows">
325 <legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend>
326 <ol>
327   <li>
328     <label for="area">Choose: </label>
329       <select name="area" id="area">
330     [%- FOREACH area IN areas -%]
331       <option value="[% area | html %]">[%- PROCESS area_name area=area -%]</option>
332     [%- END -%]
333       </select>
334   </li>
335 [% IF (public) %]
336   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
337 [% ELSE %]
338   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
339 [% END %]
340 [% IF (usecache) %] <li>
341 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
342 <select id="cache_expiry_units" name="cache_expiry_units">
343 <option value="seconds">Seconds (default)</option>
344 <option value="minutes">Minutes</option>
345 <option value="hours">Hours</option>
346 <option value="days">Days</option>
347 </select>
348 </li>[% END %]
349 </ol>
350 </fieldset>
351 <fieldset class="action">
352 <input type="hidden" name="phase" value="Report on this Area" />
353 <input type="submit" name="submit" value="Next &gt;&gt;" />
354
355 </fieldset>
356 </form>
357 [% END %]
358
359
360 [% IF ( build2 ) %]
361 <h1>Build a report</h1>
362 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
363 <input type="hidden" name="area" value="[% area | html %]" />
364 <input type="hidden" name="public" value="[% public | html %]" />
365 <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
366 <fieldset class="rows"><legend>Step 2 of 6: Pick a report type</legend>
367 <ol><li><label for="types">Choose: </label>
368     <select id="types" name="types">
369         <option value="1">Tabular</option>
370         <option value="2" disabled="disabled">Summary</option>
371         <option value="3" disabled="disabled">Matrix</option>
372     </select>
373 </li></ol></fieldset>
374
375 <fieldset class="action">
376     <input type="hidden" name="phase" value="Choose this type" />
377     <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
378     <input type="submit" name="submit" value="Next &gt;&gt;" />
379 </fieldset>
380 </form>
381 </div>
382 <div class="yui-gb"><div class="yui-u first"></div>
383
384 <!--- Summary and Matrix reports have not yet been implemented-->
385 <!--<div class="yui-u">Summary:
386 <img src="[% interface | html %]/[% theme | html %]/img/reports-summary-graphic.gif" /></div>
387 <div class="yui-u">Matrix:
388 <img src="[% interface | html %]/[% theme | html %]/img/reports-matrix-graphic.gif" /></div>-->
389
390 [% END %]
391
392 [% IF ( build3 ) %]
393 <h1>Build a report</h1>
394 <h3>Step 3 of 6: Select columns for display</h3>
395 <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>
396
397 <form id="column_submit" action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
398     <input type="hidden" name="area" value="[% area | html %]" />
399     <input type="hidden" name="type" value="[% type | html %]" />
400     <input type="hidden" name="public" value="[% public | html %]" />
401     <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
402     <fieldset>
403 <div class="yui-g">
404 <div class="yui-u first">       <div style="float: left;"><select id="availableColumns" name="oldcolumns2" multiple="multiple" size="25" style="min-width: 200px;height:300px;">
405 [% FOREACH column IN columns %]
406 [% IF ( column.table ) %]
407
408 [% IF ( loop.first ) %]
409 [% ELSE %]
410 </optgroup>
411 [% END %]
412
413 <optgroup label="[% column.table | html %]">
414 [% ELSE %]
415 <option value="[% column.name | html %]">
416 [% IF ( column.description ) %][% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
417 [% ELSE %]
418 [% column.name | html %]
419 [% END %]
420 </option>
421 [% END %]
422 [% END %]
423 </optgroup>
424 </select></div>
425 <div style="width: 6.3em; float: right; margin-top: 100px"><input type="button" name="Add" value="Add" class="button" style="width:6em;" id="addColumn" /><br />
426 <input type="button" name="delete" value="&lt;&lt; Delete" class="button" style="width: 6em; margin: 1em 0;" id="delColumn" /></div>
427 </div>
428
429 <div class="yui-u">
430 <select id="selectedColumns" name="columns" multiple="multiple" size="25" style="width:200px; height:300px;"></select>
431 </div>
432 </div>
433 </fieldset>
434 <div class="yui-g">
435 <fieldset class="action">
436     <input type="hidden" name="phase" value="Choose these columns" />
437     <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
438     <input type="submit" name="submit" value="Next &gt;&gt;" />
439 </fieldset>
440 </div>
441 </form>
442
443 [% END %]
444
445 [% IF ( build4 ) %]
446 <h1>Build a report</h1>
447 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" >
448     <input type="hidden" name="area" value="[% area | html %]" />
449     <input type="hidden" name="type" value="[% type | html %]" />
450     <input type="hidden" name="column" value="[% column | html %]" />
451     <input type="hidden" name="public" value="[% public | html %]" />
452     <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
453     <fieldset><legend>Step 4 of 6: Select criteria to limit on</legend>
454     <table>
455         [% FOREACH criteri IN criteria %]
456         <tr>
457         <td>
458             <input type="checkbox" name="criteria_column" id="[% criteri.name | html %]" value="[% criteri.name | html %]" /> 
459             <label for="[% criteri.name | html %]">[% criteri.description | html %] </label>
460         </td>
461         [% IF ( criteri.date ) %]
462         <td>
463             <input type="text" size="10" id="[% criteri.name | html %]_value" name="[% criteri.name | html %]_value" value="" class="datepicker" />
464                 <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
465         </td>
466         </tr>
467         [% ELSE %]
468         [% IF ( criteri.textrange ) %]
469             <td>from
470             <input type="text" size="10" id="[% criteri.from | html %]_value" name="[% criteri.from | html %]_value" value="" /> to 
471             <input type="text" size="10" id="[% criteri.to | html %]_value" name="[% criteri.to | html %]_value" value="" />
472             </td>
473             </tr>
474         [% ELSE %]
475             [% IF ( criteri.daterange ) %]
476             <td>from 
477             <input type="text" size="10" id="from_[% criteri.name | html %]_value" name="from_[% criteri.name | html %]_value" value="" class="datepickerfrom" />
478             to
479             <input type="text" size="10" id="to_[% criteri.name | html %]_value" name="to_[% criteri.name | html %]_value" value="" class="datepickerto" />
480                         <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
481             </td>
482         </tr>
483             [% ELSE %]
484             <td>
485                 <select name="[% criteri.name | html %]_value">
486                 [% FOREACH value IN criteri.values %]
487                 <option value="[% value.availablevalues | html %]">[% IF ( value.default ) %]Default[% ELSE %][% value.display_value | html %][% END %]</option>
488                 [% END %]
489                 </select>
490             </td>
491             </tr>
492             [% END %]
493         [% END %]
494         [% END %]
495     [% END %]
496     </table>
497     </fieldset>
498
499 [% IF ( definitions ) %]
500 <fieldset><legend>Dictionary definitions</legend>
501 <table>
502 [% FOREACH definition IN definitions %]
503     <tr><td><input type="checkbox" name="definition" value="[% definition.id | html %]" /> [% definition.name | html %]</td></tr>
504 [% END %]
505 </table>
506 </fieldset>
507 [% END %]
508
509 <fieldset class="action"><input type="hidden" name="phase" value="Choose these criteria" />
510     <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
511     <input type="submit" name="submit" value="Next &gt;&gt;" /> </fieldset>
512 </form>
513 [% END %]
514
515
516 [% IF ( build5 ) %]
517 <h1>Build a report</h1>
518 <h3>Step 5 of 6: Pick which columns to total</h3>
519 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
520 <input type="hidden" name="area" value="[% area | html %]" />
521 <input type="hidden" name="type" value="[% type | html %]" />
522 <input type="hidden" name="column" value="[% column | html %]" />
523 <input type="hidden" name="definition" value="[% definition | html %]" />
524 <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
525 <input type="hidden" name="public" value="[% public | html %]" />
526 <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
527 <fieldset><table>
528 [% FOREACH total_b IN total_by %]
529 <tr><td><input type="checkbox" name="total_by" id="[% total_b.name | html %]" value="[% total_b.name | html %]" /> <label for="[% total_b.name | html %]">[% total_b.name | html %]</label></td>
530 <td><select name="[% total_b.name | html %]_tvalue">
531
532 [% FOREACH selec IN total_b.select %]
533 <option value="[% selec.value | html %]">[% selec.value | html %]</option>
534 [% END %]
535 </select>
536
537 </td></tr>
538 [% END %]
539 </table></fieldset>
540
541 <fieldset class="action"><input type="hidden" name="phase" value="Choose these operations" />
542     <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
543     <input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
544 </form>
545 [% END %]
546
547
548 [% IF ( build6 ) %]
549 <h1>Build a report</h1>
550 <h3>Step 6 of 6: Choose how you want the report ordered</h3>
551 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
552 <input type="hidden" name="area" value="[% area | html %]" />
553 <input type="hidden" name="type" value="[% type | html %]" />
554 <input type="hidden" name="column" value="[% column | html %]" />
555 <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
556 <input type="hidden" name="definition" value="[% definition | html %]" />
557 <input type="hidden" name="totals" value="[% totals | html %]" />
558 <input type="hidden" name="public" value="[% public | html %]" />
559 <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
560 <fieldset><table>[% FOREACH order_b IN order_by %]
561 <tr><td><input type="checkbox" id="[% order_b.name | html %]" name="order_by" value="[% order_b.name | html %]" /> <label for="[% order_b.name | html %]">[% order_b.name | html %]</label></td><td>
562 <select name="[% order_b.name | html %]_ovalue">
563
564 [% FOREACH selec IN order_b.select %]
565 <option value="[% selec.value | html %]">[% selec.value | html %]</option>
566 [% END %]
567 </select>
568 </td></tr>
569
570 [% END %]
571 </table></fieldset>
572
573 <fieldset class="action">
574 <input type="hidden" name="phase" value="Build report" />
575 <input type="submit" name="submit" value="Finish" /></fieldset>
576 </form>
577 [% END %]
578
579
580 [% IF ( showreport ) %]
581 <h1>Confirm custom report</h1>
582 <p>Your report will be generated with the following SQL statement.</p>
583 <p> 
584 [% sql | html %]
585 </p>
586
587 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
588 <input type="hidden" name="sql" value="[% sql | html %]" />
589 <input type="hidden" name="type" value="[% type | html %]" />
590 <input type="hidden" name="public" value="[% public | html %]" />
591 <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
592 <p>You will need to save the report before you can execute it</p>
593 <fieldset class="action"><input type="hidden" name="phase" value="Save" />  
594 <input type="submit" name="submit" value="Save" />  </fieldset>
595 </form>
596 [% END %]
597
598 [% IF ( save ) %]
599 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
600 <input type="hidden" name="sql" value="[% sql | html %]" />
601 <input type="hidden" name="type" value="[% type | html %]" />
602 <input type="hidden" name="area" value="[% area | html %]" />
603 <input type="hidden" name="public" value="[% public | html %]" />
604 <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
605 <fieldset class="rows">
606 <legend>Save your custom report</legend>
607 <ol>
608     <li><label for="reportname" class="required">Report name: </label><input type="text" id="reportname" name="reportname" class="required" required="required" /> <span class="required">Required</span></li>
609     [% PROCESS group_and_subgroup_selection %]
610     <li><label for="notes">Notes:</label> <textarea name="notes" id="notes"></textarea></li>
611 </ol></fieldset>
612 <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
613 <input type="submit" name="submit" value="Save report" /></fieldset>
614 </form>
615 [% END %]
616
617 [% IF ( warn_authval_problem ) %]
618     <div class="dialog alert">
619         <h3>Errors found when processing parameters for report: [% name | html %]</h3>
620         [% FOREACH problematic_authval IN problematic_authvals %]
621             <p>
622             <strong>[% problematic_authval.name | html %]:</strong> The authorized value category (<strong>[% problematic_authval.authval | html %]</strong>)
623                 you selected does not exist.
624             </p>
625         [% END %]
626         <!-- Save Anyway Form -->
627         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
628         <!--Every parameter the user issued is provided as a hidden field for recovery-->
629             <input type='hidden' name='id' value='[% id | html %]' />
630             <input type='hidden' name='sql' value='[% sql | html %]' />
631             <input type='hidden' name='reportname' value='[% reportname | html %]' />
632             <input type='hidden' name='group' value='[% group | html %]' />
633             <input type='hidden' name='subgroup' value='[% subgroup | html %]' />
634             <input type='hidden' name='notes' value='[% notes | html %]' />
635             <input type='hidden' name='cache_expiry' value='[% cache_expiry | html %]' />
636             <input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units | html %]' />
637             <input type='hidden' name='public' value='[% public | html %]' />
638         [% IF ( phase_update) %]
639             <input type='hidden' name='phase' value='Update SQL' />
640             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
641         [% ELSIF ( phase_save) %]
642             <input type='hidden' name='area' value='[% area | html %]' />
643             <input type='hidden' name='phase' value='Save Report' />
644             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
645         [% END %]
646         </form>
647         <!-- Go back to editing -->
648         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
649             <button type="button" class="new goback"><i class="fa fa-fw fa-pencil"></i> Edit SQL</button>
650         </form>
651     </div>
652 [% END %]
653
654 [% IF ( enter_params ) %]
655     <form action='/cgi-bin/koha/reports/guided_reports.pl'>
656         <input type='hidden' name='reports' value="[% reports | html %]" />
657     [% IF ( auth_val_error ) %]
658         <input type='hidden' name='phase' value='Edit SQL' />
659         <div class="dialog alert">
660             <h3>Errors found when processing parameters for report: [% name | html %]</h3>
661             [% FOREACH auth_val_error IN auth_val_errors %]
662                 <p>
663                     <strong>[% auth_val_error.entry | html %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val | html %]</strong>)
664                     you selected does not exist.
665                 </p>
666             [% END %]
667         </div>
668         <fieldset class="action"><input type="submit" value="Edit SQL" /></fieldset>
669     [% ELSE %]
670         <input type='hidden' name='phase' value='Run this report' />
671         <h1>Enter parameters for report [% name | html %]:</h1>
672         [% IF ( notes ) %]<p>[% notes | html %]</p>[% END %]
673         <fieldset class="rows">
674             <ol>
675             [% FOREACH sql_param IN sql_params %]
676                 <input name="param_name" value="[% sql_param.name | html %]" type="hidden" />
677                 [% IF sql_param.input == 'date' %]
678                     <li>
679                     <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" />
680                     </li>
681                 [% ELSIF ( sql_param.input == 'text' ) %]
682                     <li><label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label><input id="sql_params[% loop.count | html %]" type="text" name="sql_params" /></li>
683                 [% ELSE %]
684                     <li><label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
685                         <select name="[%- sql_param.input.name | html -%]" tabindex="1"  size="1" id="[%- sql_param.input.id | html -%]">
686                         [% FOREACH value IN sql_param.input.values %]
687                             <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
688                         [% END %]
689                         </select>
690                     </li>
691                 [% END %]
692             [% END %]
693             </ol>
694         </fieldset>
695         <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
696     [% END %]
697     </form>
698 [% END %]
699
700 [% IF ( execute ) %]
701 <h1>[% name | html %]</h1>
702 [% INCLUDE 'chart.inc' %]
703 [% IF ( notes ) %]<p><span class="label">Notes:</span> [% notes | html %]</p>[% END %]
704 [% IF ( unlimited_total ) %]<p><span class="label">Total number of results:</span> [% unlimited_total | html %][% IF unlimited_total > limit %] ([% limit | html %] shown)[% END %].</p>[% END %]
705 <div id="sql_output" style="display:none;"><span class="label">Report SQL:</span><pre>[% sql | html %]</pre></div>
706 </br>
707
708 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect">
709     <input type="hidden" name="phase" value="Run this report"/>
710     <input type="hidden" name="reports" value="[% report_id | html %]"/>
711
712     [% FOREACH p IN sql_params %]
713         <input type="hidden" name="sql_params" value="[% p | html %]"/>
714     [% END %]
715
716     <label for="limit">Rows per page: </label>
717     <select name="limit" id="limit">
718         [% limits = [ 10, 20, 50, 100, 200, 300, 400, 500, 1000 ] %]
719         [% FOREACH l IN limits %]
720                 [% IF l == limit %]
721                     <option value="[% l | html %]" selected="selected">[% l | html %]</option>
722                 [% ELSE %]
723                     <option value="[% l | html %]">[% l | html %]</option>
724                 [% END %]
725         [% END %]
726     </select>
727 </form>
728
729 <div class="pages">[% pagination_bar | $raw %]</div>
730 [% UNLESS ( errors ) %]
731     <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="report_results">
732         <input type="hidden" name="op" value="show" />
733         <table>
734             <tr>
735                 [% FOREACH header_ro IN header_row %]
736                     [% IF header_ro.cell == 'itemnumber' %]
737                         <th>
738                             [% header_ro.cell | html %] <button type="submit" data-toggle="tooltip" title="Send visible items to batch modification" class="btn btn-xs btn-default send_to_item_mod"><i class="fa fa-pencil"></i> Batch modify</button>
739                         </th>
740                     [% ELSE %]
741                         <th>[% header_ro.cell | html %]</th>
742                     [% END %]
743                 [% END %]
744             </tr>
745             [% FOREACH result IN results %]
746                 <tr>
747                     [% FOREACH cells IN result.cells %]
748                         [% place = loop.index | html %]
749                         [% IF header_row.$place.cell == 'itemnumber' %]
750                             <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
751                         [% END %]
752                         <td>[% cells.cell | html %]</td>
753                     [% END %]
754                 </tr>
755             [% END %]
756         </table>
757     </form>
758
759 [% END %]
760 [% END %]
761
762 [% IF ( create ) %]
763 <script type="text/javascript">
764 $(document).ready(function() {
765     load_group_subgroups();
766 });
767 </script>
768 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
769 <fieldset class="rows">
770 <legend>Create report from SQL</legend>
771 <ol>
772     <li><label for="reportname" class="required">Report name:</label>
773         [% IF ( reportname ) %]<input type="text" class="required" required="required" id="reportname" name="reportname" value="[% reportname | html %]" size="50"/>
774         [% ELSE %]<input type="text" class="required" required="required" id="reportname" name="reportname" size="50" />[% END %] <span class="required">Required</span>
775     </li>
776     [% PROCESS group_and_subgroup_selection %]
777
778 [% IF (public) %]
779   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
780 [% ELSE %]
781   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
782 [% END %]
783 [% IF (usecache) %] <li>
784 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
785 <select id="cache_expiry_units" name="cache_expiry_units">
786 <option value="seconds" selected="selected">Seconds (default)</option>
787 <option value="minutes">Minutes</option>
788 <option value="hours">Hours</option>
789 <option value="days">Days</option>
790 </select>
791 </li>[% END %]
792     <li><label for="notes">Notes:</label> <textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea></li>
793 </ol>
794 </fieldset>
795 <fieldset class="rows">
796 <legend>SQL:</legend>
797 <div style="margin:1em;">
798 <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql | html %]</textarea> <span class="required">Required</span>
799 </div>
800 </fieldset>
801
802 <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
803 <input type="submit" name="submit" value="Save report" /> <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
804 </fieldset>
805 </form>
806 [% END %]
807
808 [% IF saved_results %]
809 <h1>Saved report results</h1>
810 <h2>[% name | html %]</h2>
811 <p>[% notes | html %]</p>
812 <table>
813 [% FOREACH rows IN saved_results %]
814 <tr>
815 [% FOREACH col IN rows %]
816 <td>[% col | html %]</td>
817 [% END %]
818 <tr>
819 [% END %]
820 </table>
821 [% END %]
822
823 [% IF ( showsql ) %]
824 <fieldset class="rows">
825     <legend>[% reportname | html %]</legend>
826     <ol>
827         [% IF ( notes ) %]<li><span class="label">Notes:</span> [% notes | html %]</li>[% ELSE %][% END %]
828         <li><textarea id="sql">[% sql | html %]</textarea></li>
829     </ol>
830 </fieldset>
831 [% END %]
832
833 [% IF ( save_successful ) %]
834 [% UNLESS ( errors ) %]
835 </br>
836 <div id="report_updated">
837     <div class="dialog message">
838         <p>Your report "[% reportname | html %]" has been saved</p>
839     </div>
840 </div>
841 [% END %]
842 [% END %]
843
844 [% IF ( editsql ) %]
845 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
846 <input type="hidden" name="phase" value="Update SQL" />
847 <input type="hidden" name="id" value="[% id | html %]"/>
848 <fieldset class="rows">
849 <legend>Edit SQL report</legend>
850 <ol>
851 <li><label for="reportname" class="required">Report name: </label><input type="text" id="reportname" name="reportname" value="[% reportname | html %]" size="50" class="required" required="required" /> <span class="required">Required</span></li>
852 [% PROCESS group_and_subgroup_selection %]
853 [% IF (public) %]
854   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
855 [% ELSE %]
856   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
857 [% END %]
858 [% IF (usecache) %] <li>
859 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
860 <select id="cache_expiry_units" name="cache_expiry_units">
861 <option value="seconds">Seconds (default)</option>
862 <option value="minutes">Minutes</option>
863 <option value="hours">Hours</option>
864 <option value="days">Days</option>
865 </select>
866 </li>[% END %]
867 <li><label for="notes">Notes:</label><textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea></li>
868 </ol>
869 </fieldset>
870
871 <fieldset class="rows">
872     <legend>SQL:</legend>
873     <div style="margin:1em;">
874         <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql | html %]</textarea> <span class="required">Required</span>
875     </div>
876 </fieldset>
877
878 <fieldset class="action">
879 <input type="submit" name="submit" value="Update SQL" /> <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
880 </fieldset>
881 </form>
882
883
884 [% END %]
885
886 [% IF ( errors ) %]
887 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
888 <div class="dialog alert">
889 <b>The following error was encountered:</b><br />
890 [% FOREACH error IN errors %]
891     [% IF ( error.sqlerr ) %]This report contains the SQL keyword <b>[% error.sqlerr | html %]</b>.
892     <br />Use of this keyword is not allowed in Koha reports due to security and data integrity risks. Only SELECT queries are allowed.
893     <br />Please return to the &quot;Saved Reports&quot; screen and delete this report or retry creating a new one.
894     [% ELSIF ( error.queryerr ) %]The database returned the following error: <br />[% error.queryerr | html %]<br />Please check the log for further details.
895     [% ELSIF ( error.cache_expiry ) %]Please select a cache expiry less than 30 days.
896     [% ELSE %]
897     [% END %]
898     <div id="onerror_actions">
899         <a href="#" class="button goback">Return to previous page</a>
900     </div>
901 [% END %]
902 </div>
903 <fieldset class="action"><input type="hidden" name="phase" value="Use saved" />
904 <input type="submit" name="submit" value="Saved reports" /></fieldset>
905 </form>
906 [% END %]
907
908 </div>
909 </div>
910 <div class="yui-b">
911
912 [% IF ( saved1 ) %]
913 <div id="saved-reports-filter">
914 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
915   <input type="hidden" name="phase" value="Use saved" />
916   <input type="hidden" name="filter_set" value="1" />
917   <fieldset class="brief">
918   <h3>Filter</h3>
919   <ol>
920     <li><label for="filter_date">Date:</label> <input type="text" id="filter_date" name="filter_date" size="10" value="[% filters.date | html %]" class="datepicker" />
921     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
922
923     </li>
924     <li><label for="filter_author">Author:</label> <input type="text" id="filter_author" name="filter_author" value="[% filters.author | html %]" size="16" /></li>
925     <li><label for="filter_keyword">Keyword:</label> <input type="text" id="filter_keyword" name="filter_keyword" value="[% filters.keyword | html %]" size="16" /></li>
926   </ol>
927   </fieldset>
928   <fieldset class="action">
929     <input type="submit" value="Apply filter" />
930     <a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1">Clear</a>
931   </fieldset>
932 </form>
933 </div>
934 [% END %]
935
936
937 [% INCLUDE 'guided-reports-view.inc' %]
938 </div>
939 </div>
940
941 [% MACRO jsinclude BLOCK %]
942     [% Asset.js("js/charts.js") | $raw %]
943     [% Asset.js("../lib/d3c3/d3.min.js") | $raw %]
944     [% Asset.js("../lib/d3c3/c3.min.js") | $raw %]
945     [% INCLUDE 'calendar.inc' %]
946     [% IF ( saved1 ) %]
947         [% INCLUDE 'datatables.inc' %]
948         [% INCLUDE 'columns_settings.inc' %]
949     [% END %]
950     <script>
951
952         function hide_bar_element() {
953             $('#chart-column-horizontal').hide()
954             $('.chart-column-group').each(function( index ) {
955                 $( this ).hide();
956             });
957             $('.chart-column-line').each(function( index ) {
958                 $( this ).hide()
959             });
960         }
961
962         function show_bar_element() {
963             $('#chart-column-horizontal').show()
964             $('.chart-column-group').each(function( index ) {
965                 $( this ).show()
966             });
967             $('.chart-column-line').each(function( index ) {
968                 $( this ).show()
969             });
970         }
971
972         function removeColumn(id) {
973             $('#'+id).remove();
974
975             if ( $('.chart-column-conf').length == 1 ) {
976                 $('.chart-column-delete').remove();
977             }
978         }
979
980         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
981         var group_subgroups = {};
982         [% FOREACH group IN groups_with_subgroups %]
983             var gid = "[% group.id | html %]"
984             group_subgroups[gid] = new Array();
985             [% FOREACH subgroup IN group.subgroups %]
986                 var sgid = "[% subgroup.id | html %]";
987                 var sgname = "[% subgroup.name | html %]";
988                 group_subgroups[gid].push([sgid, sgname]);
989             [% END %]
990         [% END %]
991
992         function load_group_subgroups () {
993             var group = $("#group_select").val();
994             var sg = $("#subgroup");
995             $(sg).find('option[value!=""]').each(function() {
996                 $(this).remove();
997             });
998             $(sg).hide();
999             if (group) {
1000                 var select = $(sg).find('select')[0];
1001                 $.each( group_subgroups[group], function(index, value) {
1002                     $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1003                 } );
1004                 $("#subgroup, #subgroup *").show();
1005             }
1006         }
1007
1008         $(document).ready(function(){
1009
1010             hide_bar_element();
1011
1012             if ( $('.chart-column-conf').length == 1 ) {
1013                 $('.chart-column-delete').remove();
1014             }
1015
1016             $(".chart-column-delete").on('click', function(e){
1017                 e.preventDefault();
1018                 removeColumn('column_' + $(this).data('column'));
1019             })
1020
1021             $('#download-chart').click(function() {
1022                 var svg = '<svg>' + $('#chart svg').html() + '</svg>';
1023                 this.href = 'data:application/octet-stream;base64,' + btoa(svg);
1024                 this.setAttribute('download', 'chart.svg');
1025             });
1026
1027             $('#chart-type').change(function() {
1028                 if ($(this).val() == 'bar') {
1029                     show_bar_element();
1030                 }
1031                 else {
1032                     hide_bar_element();
1033                 }
1034             });
1035
1036             $('#download-chart').hide();
1037             var chart;
1038
1039             [% IF results && !errors %]
1040                 $('#draw-chart').click(function() {
1041
1042                     var btn_text = $("#draw-chart").html();
1043                     $("#draw-chart").html(_("Loading..."));
1044
1045                     var x_elements = $('select[name="x"]').val();
1046                     var y_elements = [];
1047                     var groups = [];
1048                     var lines = [];
1049                     var options = {};
1050
1051                     headers = [% header_row.json %];
1052
1053                     var results;
1054                     if ($('input[name="chart-include-all"]').prop('checked')) {
1055                         results = [% allresults.json %]
1056                     }
1057                     else {
1058                         results = [% results.json %]
1059                     }
1060
1061                     if ($('input[name="chart-exclude-last"]').prop('checked')) {
1062                         results.splice(-1, 1);
1063                     }
1064
1065                     $('select[name="y"]').each(function( index ) {
1066                         y_elements.push( $(this).val() );
1067                     });
1068                     $('select[name="group"]').each(function( index ) {
1069                         groups.push( $(this).val() );
1070                     });
1071                     $('.column-line').each(function( index ) {
1072                         if ($(this).prop('checked')) {
1073                             lines.push( $(this).attr('name') );
1074                         }
1075                     });
1076
1077                     // Remove deleted columns from headers and results.
1078                     var deleted_indexes = [];
1079                     var kept_headers = [];
1080                     $.each(headers, function(index, value) {
1081                         if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
1082                             // This header is neither a x element nor in y elements. Don't need it.
1083                             deleted_indexes.push(index);
1084                         }
1085                         else {
1086                             kept_headers.push({cell: value.cell});
1087                         }
1088                     });
1089
1090                     // Remove coresponding cells.
1091                     var kept_results = [];
1092                     $.each(results, function(index, value) {
1093                         var line = {};
1094                         line['cells'] = [];
1095                         $.each(value.cells, function(i, val) {
1096                             if ($.inArray(i, deleted_indexes) === -1) {
1097                                 line['cells'].push({cell: val.cell});
1098                             }
1099                         });
1100                         kept_results.push(line);
1101                     });
1102
1103                     options.type = $('select[name="chart-type"]').val();
1104                     options.horizontal = $('input[name="column-horizontal"]').prop('checked');
1105                     options.lines = lines;
1106
1107                     chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
1108                     $('#chart').prepend('<div style="font-size: 1rem; text-align: center;">' + "[% name %]" + '</div>');
1109                     $('#download-chart').show();
1110                     $("#draw-chart").html(_(btn_text));
1111                     $("html, body").animate({ scrollTop: $(document).height() }, "slow");
1112                 });
1113             [% END %]
1114
1115             $('[data-toggle="tooltip"]').tooltip();
1116             var columns_settings = [% ColumnsSettings.GetColumns( 'reports', 'saved-sql', 'table_reports', 'json' ) | $raw %];
1117
1118             $('#limit').change(function() {
1119                 $('#limitselect').submit();
1120             });
1121
1122             $(document).click(function() {
1123                 $('#report_updated').hide();
1124             });
1125
1126             $(".goback").on("click",function(e){
1127                 e.preventDefault();
1128                 window.history.back();
1129             });
1130
1131             $("#addColumn").on("click",function(){
1132                 addColumn();
1133             });
1134
1135             $("#delColumn").on("click",function(){
1136                 delColumn();
1137             });
1138
1139             [% IF (saved1) %]
1140                 var rtable = KohaTable("table_reports", {
1141                     'iDisplayLength': [% Koha.Preference('NumSavedReports') | html %],
1142                     'bAutoWidth': false,
1143                     'sPaginationType': 'four_button',
1144                     'aaSorting': [[ 1, "asc" ]],
1145                     'aoColumnDefs': [
1146                         { 'bSortable': false, 'bSearchable':false, 'aTargets': [0, -1] },
1147                         { 'bSearchable': false, 'aTargets': [3] },
1148                         { "aTargets": [ 1, 2 ], "sType": "natural"  },
1149                         { "sType": "title-string", "aTargets" : [ "title-string" ] },
1150                         { "visible": false, "aTargets" : [ "hidden" ] }
1151                     ],
1152                     'oLanguage': {
1153                         'sZeroRecords': _("No matching reports found")
1154                     },
1155                 }, columns_settings);
1156
1157                 var rtabs = $("#tabs").tabs();
1158                 rtabs.on("tabsactivate", function(e, ui) {
1159                     $("#subgroup_filter option").each(function() {
1160                         if($(this).val().length > 0) {
1161                             $(this).remove();
1162                         }
1163                     });
1164                     rtable.fnFilter('', 4);
1165                     rtable.fnFilter('', 5);
1166                     rtable.fnSetColumnVis(4, true);
1167                     rtable.fnSetColumnVis(5, true);
1168
1169                     var g_id = $(ui.newTab).children().attr('id');
1170                     var g_name = $(ui.newTab).text();
1171                     if ( g_name == _("All") ) {
1172                         g_id = "";
1173                         g_name = "";
1174                     }
1175
1176                     if (g_id && g_id.length > 0) {
1177                         rtable.fnFilter('^' + g_name + '$', 4, true, true, true, false);
1178                         rtable.fnSetColumnVis(4, false);
1179                         for(var i in group_subgroups[g_id]) {
1180                             $("#subgroup_filter").append(
1181                                 '<option value="' + group_subgroups[g_id][i][0] + '">'
1182                                 + group_subgroups[g_id][i][1] + '</option>'
1183                             );
1184                         }
1185                         $("#subgroup_filter_block").show();
1186                     } else {
1187                         $("#subgroup_filter_block").hide();
1188                     }
1189                 });
1190                 $("#subgroup_filter_block").hide();
1191
1192                 $("#subgroup_filter").change(function() {
1193                     var selected = $(this).find('option:selected');
1194                     var sg_id = $(selected).val();
1195                     var sg_name = $(selected).text();
1196                     if (sg_id.length > 0) {
1197                         rtable.fnFilter('^' + sg_name + '$', 5, true, true, true, false);
1198                         rtable.fnSetColumnVis(5, false);
1199                     } else {
1200                         rtable.fnFilter('', 5);
1201                         rtable.fnSetColumnVis(5, true);
1202                     }
1203                 });
1204
1205                 $("#reports_form").submit(function(){
1206                     var checkedItems = $("input[name=ids]:checked");
1207                     if ($(checkedItems).size() == 0) {
1208                         alert(_("You must select one or more reports to delete"));
1209                         return false;
1210                     }
1211                     $(checkedItems).parents('tr').addClass("warn");
1212                     if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
1213                         return true;
1214                     } else {
1215                         $(checkedItems).parents('tr').removeClass("warn");
1216                         return false;
1217                     }
1218                 });
1219
1220                 $("body").on("click", ".update_sql", function(e){
1221                     e.preventDefault();
1222                     var ltitle = $(this).text();
1223                     var report_id = $(this).data("report_id");
1224                     var page = $(this).attr("href");
1225                     $("#update_sql .modal-body").load(page + " div", function(){
1226                         var diff1 = $("#col1 .show_sql").text();
1227                         var diff2 = $("#col2 .show_sql").text();
1228                         var diffs = diffString( escape(diff1), escape(diff2) );
1229                         $("#col1 .show_sql,#col2 .show_sql").html(diffs);
1230                     });
1231                     $('#update_sql').modal('show');
1232                     $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id);
1233                 });
1234
1235                 $("#update_sql").on("hidden.bs.modal", function(){
1236                     $("#update_sql_label").html("");
1237                     $("#update_sql .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
1238                 });
1239             [% END %]
1240
1241             [% IF ( showsql ) %]
1242                 $("#sql").focus(function() {
1243                     $(this).select();
1244                 });
1245             [% END %]
1246
1247                 $(".toggle_sql").click(function(){
1248                     $("#sql_output").toggle();
1249                     $("#toggle_sql_hid").toggle();
1250                     $("#toggle_sql_vis").toggle();
1251                 });
1252
1253                 $(".toggle_chart_settings").click(function(){
1254                     $("#makechart").toggle();
1255                     $("#toggle_chart_settings_hid").toggle();
1256                     $("#toggle_chart_settings_vis").toggle();
1257                 });
1258
1259                 $("#table_reports").delegate(".confirmdelete", 'click', function(){
1260                     $(this).parents('tr').attr("class","warn");
1261                     if(confirm(_("Are you sure you want to delete this saved report?"))){
1262                         return true;
1263                     } else {
1264                         $(this).parents('tr').attr("class","");
1265                         return false;
1266                     }
1267                 });
1268
1269             [% IF (create || editsql || save) %]
1270                 $("#select_group").change(function() {
1271                     if($(this).prop('checked')) {
1272                         $("#group_input").prop('disabled', true);
1273                         $("#groupdesc_input").prop('disabled', true);
1274                         $("#group_select").prop('disabled', false);
1275                         if ($("#group_select").val().length > 0) {
1276                             $("#select_subgroup").prop('checked', true);
1277                             $("#select_subgroup").change();
1278                             $("#subgroup, #subgroup *").show();
1279                         } else {
1280                             $("#subgroup").hide();
1281                         }
1282                     }
1283                 });
1284                 $("#create_group").change(function() {
1285                     if($(this).prop('checked')) {
1286                         $("#group_input").prop('disabled', false);
1287                         $("#groupdesc_input").prop('disabled', false);
1288                         $("#group_select").prop('disabled', true);
1289                         $("#create_subgroup").prop('checked', true).change();
1290                         $("#subgroup_select").hide();
1291                         $("#subgroup input[type='radio']").hide();
1292                         $("#subgroup label[for]").hide();
1293                         $("#subgroup_input").show();
1294                         $("#subgroupdesc_input").show();
1295                         $("#subgroup").show();
1296                     }
1297                 });
1298                 $("#select_subgroup").change(function() {
1299                     if($(this).prop('checked')) {
1300                         $("#subgroup_select").prop('disabled', false);
1301                         $("#subgroup_input").prop('disabled', true);
1302                         $("#subgroupdesc_input").prop('disabled', true);
1303                     }
1304                 });
1305                 $("#create_subgroup").change(function() {
1306                     if($(this).prop('checked')) {
1307                         $("#subgroup_input").prop('disabled', false);
1308                         $("#subgroupdesc_input").prop('disabled', false);
1309                         $("#subgroup_select").prop('disabled', true);
1310                     }
1311                 });
1312                 $("#select_group").change();
1313                 $("#select_subgroup").change();
1314                 $("#group_select").on("change",function(){
1315                     load_group_subgroups();
1316                 });
1317             [% END %]
1318             $(".delete").on("click",function(){
1319                 return confirmDelete(MSG_CONFIRM_DELETE);
1320             });
1321         });
1322         function addColumn() {
1323             $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
1324         }
1325         function delColumn() {
1326             $("#selectedColumns option:selected").remove();
1327         }
1328         $("#column_submit").submit(function() {
1329             if ($("#selectedColumns option").size() < 1) {
1330                 alert(_("No columns selected!"));
1331                 return false;
1332             }
1333             $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
1334             return true;
1335         });
1336     </script>
1337 [% END %]
1338
1339 [% INCLUDE 'intranet-bottom.inc' %]
1340
1341 [% BLOCK group_and_subgroup_selection %]
1342     <li id="group">
1343         <label>Report group:</label>
1344         <input type="radio" name="select_or_create_group"
1345             id="select_group" checked="checked" />
1346         <label for="select_group" style="float:none">Select</label>
1347         <select name="group" id="group_select">
1348             <option value="">(None)</option>
1349             [% FOREACH group IN groups_with_subgroups %]
1350                 [% IF (group.selected) %]
1351                     <option value="[% group.id | html %]" selected="selected">
1352                 [% ELSE %]
1353                     <option value="[% group.id | html %]">
1354                 [% END %]
1355                     [% group.name | html %]
1356                 </option>
1357             [% END %]
1358         </select>
1359         <input type="radio" name="select_or_create_group" id="create_group" />
1360         <label for="create_group" style="float:none">or create:</label>
1361         <input type="text" name="group" id="group_input" title="Group code" placeholder="Code" />
1362         <input type="text" name="groupdesc" id="groupdesc_input" title="Group name" placeholder="Name" />
1363     </li>
1364     <li id="subgroup">
1365         <label>Report subgroup:</label>
1366         <input type="radio" name="select_or_create_subgroup"
1367             id="select_subgroup" checked="checked" />
1368         <label for="select_subgroup" style="float:none">Select</label>
1369         <select name="subgroup" id="subgroup_select">
1370             <option value="">(None)</option>
1371             [% FOREACH group IN groups_with_subgroups %]
1372                 [% IF (group.selected) %]
1373                     [% FOREACH subgroup IN group.subgroups %]
1374                         [% IF (subgroup.selected) %]
1375                             <option value="[% subgroup.id | html %]" selected="selected">
1376                         [% ELSE %]
1377                             <option value="[% subgroup.id | html %]">
1378                         [% END %]
1379                             [% subgroup.name | html %]
1380                         </option>
1381                     [% END %]
1382                 [% END %]
1383             [% END %]
1384         </select>
1385         <input type="radio" name="select_or_create_subgroup"
1386             id="create_subgroup" />
1387         <label for="create_subgroup" style="float:none">or create</label>
1388         <input type="text" name="subgroup" id="subgroup_input" title="Subgroup code" placeholder="Code" />
1389         <input type="text" name="subgroupdesc" id="subgroupdesc_input" title="Subgroup name" placeholder="Name" />
1390     </li>
1391 [% END %]