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