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