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