Bug 33063: Make sure correct subgroup is pre-selected when duplicating reports
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / reports / guided_reports_start.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AuthorisedValues %]
4 [% USE KohaDates %]
5 [% USE Koha %]
6 [% USE TablesSettings %]
7 [% USE JSON.Escape %]
8 [% PROCESS 'i18n.inc' %]
9 [% SET footerjs = 1 %]
10 [% USE To %]
11
12 [%- BLOCK area_name -%]
13     [%- SWITCH area -%]
14         [%- CASE 'CIRC' -%]<span>Circulation</span>
15         [%- CASE 'CAT'  -%]<span>Catalog</span>
16         [%- CASE 'PAT'  -%]<span>Patrons</span>
17         [%- CASE 'ACQ'  -%]<span>Acquisitions</span>
18         [%- CASE 'ACC'  -%]<span>Accounts</span>
19         [%- CASE 'SER'  -%]<span>Serials</span>
20     [%- END -%]
21 [%- END -%]
22
23 [% INCLUDE 'doc-head-open.inc' %]
24
25 <title>
26     [%- IF ( saved1 ) -%]
27         Saved reports &rsaquo; [%- ELSIF ( create ) -%]
28         Create from SQL &rsaquo; [%- ELSIF ( showsql ) -%]
29         SQL view &rsaquo; Saved reports &rsaquo; [%- ELSIF ( execute ) -%]
30         Report [% name | html %] ([% id | html %]) &rsaquo; Saved reports &rsaquo; [%- ELSIF ( editsql ) -%]
31         Edit report [% reportname | html %] ([% id | html %]) &rsaquo; Saved reports &rsaquo; [%- END -%]
32
33     [%- IF ( build1 ) -%]
34         Build a report, step 1 of 6: Choose a module &rsaquo; [%- ELSIF ( build2 ) -%]
35         Build a report, step 2 of 6: Pick a report type &rsaquo; [%- ELSIF ( build3 ) -%]
36         Build a report, step 3 of 6: Select columns for display &rsaquo; [%- ELSIF ( build4 ) -%]
37         Build a report, step 4 of 6: Select criteria to limit on &rsaquo; [%- ELSIF ( build5 ) -%]
38         Build a report, step 5 of 6: Pick which columns to total &rsaquo; [%- ELSIF ( build6 ) -%]
39         Build a report, step 6 of 6: Select how you want the report ordered &rsaquo; [%- END -%]
40     Guided reports wizard &rsaquo; Reports &rsaquo; Koha
41 </title>
42
43 [% INCLUDE 'doc-head-close.inc' %]
44 [% Asset.css("lib/codemirror/codemirror.min.css") | $raw %]
45 <style>
46     .CodeMirror {
47         resize:  vertical;
48     }
49     .cm-sqlParams {
50         color: #11917B;
51     }
52     .cm-columnPlaceholder {
53         color: #BF2D5D;
54     }
55     #mana_search_errortext {
56         font-family: monospace; font-weight: bold;
57     }
58     .data-plain {
59         display: none;
60     }
61 </style>
62 [% Asset.css("css/reports.css") | $raw %]
63 [% Asset.css("lib/d3c3/c3.min.css") | $raw %]
64 </head>
65
66 <body id="rep_guided_reports_start" class="rep">
67 [% WRAPPER 'header.inc' %]
68     [% INCLUDE 'circ-search.inc' %]
69 [% END %]
70
71 [% WRAPPER 'sub-header.inc' %]
72 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
73     <ol>
74         <li>
75             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
76         </li>
77         <li>
78             <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
79         </li>
80         <li>
81             <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
82         </li>
83
84         [% IF ( saved1 ) %]
85             <li>
86                 <a href="#" aria-current="page">
87                     Saved reports
88                 </a>
89             </li>
90         [% ELSIF ( create ) %]
91             <li>
92                 <a href="#" aria-current="page">
93                     Create from SQL
94                 </a>
95             </li>
96         [% ELSIF ( showsql ) %]
97             <li>
98                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
99             </li>
100             <li>
101                 <a href="#" aria-current="page">
102                     [% reportname | html %] ([% id | html %])
103                 </a>
104             </li>
105         [% ELSIF ( editsql ) %]
106             <li>
107                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
108             </li>
109             <li>
110                 <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% reportname | html %] ([% id | html %])</a>
111             </li>
112             <li>
113                 <a href="#" aria-current="page">
114                     Edit
115                 </a>
116             </li>
117         [% ELSIF ( execute ) %]
118             <li>
119                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
120             </li>
121             <li>
122                 <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% name | html %] ([% id | html %])</a>
123             </li>
124             <li>
125                 <a href="#" aria-current="page">
126                     Run
127                 </a>
128             </li>
129         [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]
130             <li>
131                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
132             </li>
133             <li>
134                 <a href="#" aria-current="page">
135                     [% IF ( build1 ) %]
136                         <span>Step 1 of 6: Choose a module</span>
137                     [% ELSIF ( build2 ) %]
138                         <span>Step 2 of 6: Pick a report type</span>
139                     [% ELSIF ( build3 ) %]
140                         <span>Step 3 of 6: Select columns for display</span>
141                     [% ELSIF ( build4 ) %]
142                         <span>Step 4 of 6: Select criteria to limit on</span>
143                     [% ELSIF ( build5 ) %]
144                         <span>Step 5 of 6: Pick which columns to total</span>
145                     [% ELSIF ( build6 ) %]
146                         <span>Step 6 of 6: Select how you want the report ordered</span>
147                     [% END %]
148                 </a>
149         [% END %]
150     </ol>
151 </nav> <!-- /#breadcrumbs -->
152 [% END %]
153
154 <div id="update_sql" class="modal" tabindex="-1" role="dialog" aria-labelledby="update_sql_label" aria-hidden="true">
155     <div class="modal-dialog">
156         <div class="modal-content">
157             <div class="modal-header">
158                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
159                 <h3 id="update_sql_label">Update SQL</h3>
160             </div>
161             <div class="modal-body">
162                 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
163             </div>
164             <div class="modal-footer">
165                 <a href="#" class="btn btn-default" id="update_sql_button" role="button" data-toggle="modal">Update</a>
166                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
167             </div>
168         </div> <!-- /.modal-content -->
169     </div> <!-- /.modal-dialog -->
170 </div> <!-- #update_sql -->
171
172 <div class="main container-fluid">
173     <div class="row">
174         <div class="col-sm-10 col-sm-push-2">
175             <main>
176
177                 [% INCLUDE "reports-toolbar.inc" %]
178
179                 [% IF ( start ) %]
180                     <h1>Guided reports</h1>
181                     <p>Use the guided reports engine to create non standard reports. This feature aims to provide some middle ground between the built in canned reports and writing custom SQL reports.</p>
182
183                     <h3>Build and run reports</h3>
184
185                     [% IF ( CAN_user_reports_create_reports ) %]
186                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
187                             <input type="hidden" name="phase" value="Build new" />
188                             <input type="submit" name="submit" class="btn btn-primary" value="Build new" />
189                         </form>
190                     [% END %]
191
192                     [% IF ( CAN_user_reports_execute_reports ) %]
193                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
194                             <input type="hidden" name="phase" value="Use saved"/>
195                             <input type="submit" name="submit" class="btn btn-primary" value="Use saved" />
196                         </form>
197                     [% END %]
198
199                     [% IF ( CAN_user_reports_create_reports ) %]
200                         <form action="/cgi-bin/koha/reports/guided_reports.pl">
201                             <input type="hidden" name="phase" value="Create report from SQL"/>
202                             <input type="submit" name="submit" class="btn btn-primary" value="Create report from SQL" />
203                         </form>
204                     [% END %]
205
206                     <h3>Reports Dictionary</h3>
207                     <p>Use the reports dictionary to define custom criteria to use in your reports</p>
208                     <form action="/cgi-bin/koha/reports/dictionary.pl">
209                         <input type="hidden" name="phase" value="View Dictionary"/>
210                         <input type="submit" name="submit" class="btn btn-primary" value="View dictionary" />
211                     </form>
212                 [% END # /IF (start) %]
213
214                 [% IF report_converted %]
215                     <div class="dialog message">
216                         The report "[% report_converted | html %]" has been converted.
217                     </div>
218                 [% END %]
219
220                 [% IF report_converted %]
221                     <div class="dialog message">
222                         The report "[% report_converted | html %]" has been converted.
223                     </div>
224                 [% END %]
225
226                 [% IF ( saved1 ) %]
227                         <h1>Saved reports</h1>
228                     [% IF ( savedreports ) %]
229
230                         [% IF ( filters.date || filters.author || filters.keyword ) %]
231                             <p>Filtered by:
232                                 <span class="filter">
233                                     [% IF ( filters.date ) %]
234                                         <span class="filter_date"><strong>Date:</strong> [% filters.date | html %]</span>
235                                     [% END %]
236                                     [% IF ( filters.author ) %]
237                                         <span class="filter_author"><strong>Author:</strong> [% filters.author | html %]</span>
238                                     [% END %]
239                                     [% IF ( filters.keyword ) %]
240                                         <span class="filter_keyword"><strong>Keyword:</strong> [% filters.keyword | html %]</span>
241                                     [% END %]
242                                     <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>
243                                 </span>
244                             </p>
245                         [% END %]
246
247                         <div id="tabs" class="toptabs">
248                             <ul class="nav nav-tabs" role="tablist">
249                                 <li role="presentation" class="active">
250                                     <a href="#reports" aria-controls="reports" role="tab" data-toggle="tab">All</a>
251                                 </li>
252                                 [% FOREACH group IN groups_with_subgroups %]
253                                     <li role="presentation">
254                                         <a id="[% group.id | html %]" href="#reports" aria-controls="reports" role="tab" data-toggle="tab">[% group.name | html %]</a>
255                                     </li>
256                                 [% END %]
257                             </ul>
258
259                             <div class="tab-content">
260                                 <div id="reports" role="tabpanel" class="tab-pane active">
261                                     <div id="subgroup_filter_block">
262                                         <label for="subgroup_filter">Subgroup:</label>
263                                         <select id="subgroup_filter">
264                                             <option value="">All</option>
265                                         </select>
266                                     </div>
267
268                                     [% IF (Koha.Preference('Mana') == 1) %]
269                                         [% IF manamsg %]
270                                             <div id="mana_search_message" class="dialog message">
271                                                 <p> [% manamsg | html %] </p>
272                                             </div>
273                                         [% END %]
274                                     [% END %]
275
276                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post">
277                                         <input type="hidden" name="phase" value="Delete Multiple" />
278                                         <table id="table_reports">
279                                             <thead>
280                                                 <tr>
281                                                     <th class="NoSort">&nbsp;</th>
282                                                     <th>ID</th>
283                                                     <th>Report name</th>
284                                                     <th>Type</th>
285                                                     <th>Group</th>
286                                                     <th>Subgroup</th>
287                                                     <th>Notes</th>
288                                                     <th>Author</th>
289                                                     <th>Creation date</th>
290                                                     <th>Last edit</th>
291                                                     <th>Last run</th>
292                                                     <th class="report_public">Public</th>
293                                                     <th class="report_json_url">JSON URL</th>
294                                                     [% IF (usecache) %]
295                                                         <th>Cache expiry (seconds)</th>
296                                                     [% ELSE %]
297                                                         <th class="NoVisible">Cache expiry (seconds)</th>
298                                                     [% END %]
299                                                     <th>Saved results</th>
300                                                     [% IF has_obsolete_reports %]
301                                                         <th>Update</th>
302                                                     [% ELSE %]
303                                                         <th class="NoVisible">Update</th>
304                                                     [% END %]
305                                                     <th class="NoSort noExport">Actions</th>
306                                                 </tr>
307                                             </thead>
308                                             <tbody>
309                                                 [% FOREACH savedreport IN savedreports %]
310                                                     [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
311                                                         <td class="report_checkbox">
312                                                             [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS -->
313                                                                 <input type="checkbox" name="ids" id="ids[% savedreport.id | html %]" value="[% savedreport.id | html %]" />
314                                                             [% END %]
315                                                             <input type="hidden" class="report_sql" value="[% savedreport.savedsql |html %]">
316                                                         </td>
317                                                         <td class="report_id">
318                                                             <label for="ids[% savedreport.id | html %]">[% savedreport.id | html %]</label>
319                                                         </td>
320                                                         <td class="report_name">
321                                                             [% IF ( savedreport.report_name ) %]
322                                                                 [% savedreport.report_name | html %]
323                                                             [% ELSE %]
324                                                                 [ no name ]
325                                                             [% END %]
326                                                         </td>
327                                                         <td class="report_type">
328                                                             [% savedreport.type | html %]
329                                                         </td>
330                                                         <td class="report_group">
331                                                             [% savedreport.groupname | html %]
332                                                         </td>
333                                                         <td>
334                                                             [% savedreport.subgroupname | html %]
335                                                         </td>
336                                                         <td class="report_notes">
337                                                             [% savedreport.notes | html %]
338                                                         </td>
339                                                         <td>
340                                                             [%- savedreport.borrowersurname | html -%][%- IF ( savedreport.borrowerfirstname ) -%], [%- savedreport.borrowerfirstname | html -%][%- END -%]
341                                                             ([% savedreport.borrowernumber | html %])
342                                                         </td>
343                                                         <td data-order="[% savedreport.date_created | html %]">
344                                                             [% savedreport.date_created | $KohaDates %]
345                                                         </td>
346                                                         <td data-order="[% savedreport.last_modified | html %]">
347                                                             [% savedreport.last_modified | $KohaDates  with_hours => 1 %]
348                                                         </td>
349                                                         <td data-order="[% savedreport.last_run | html %]">
350                                                             [% savedreport.last_run | $KohaDates  with_hours => 1 %]
351                                                         </td>
352                                                         <td class="report_public">
353                                                             [% IF (savedreport.public) %]
354                                                                 Yes
355                                                             [% ELSE %]
356                                                                 No
357                                                             [% END %]
358                                                         </td>
359                                                         <td class="report_json_url">
360                                                             [% IF (savedreport.public) %]
361                                                                 <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>
362                                                             [% ELSE %]
363                                                                 <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>
364                                                             [% END %]
365                                                         </td>
366                                                         <td>
367                                                             [% savedreport.cache_expiry | html %]
368                                                         </td>
369                                                         <td>
370                                                             [% FOR result IN savedreport.results %]
371                                                                 <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% result.id | uri %]">[% result.date_run | html %]</a>
372                                                                 <br/>
373                                                             [% END %]
374                                                         </td>
375                                                         <td>
376                                                             [% IF savedreport.seems_obsolete %]
377                                                                 This report seems obsolete, it uses biblioitems.marcxml field.
378                                                                 <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>
379                                                             [% END %]
380                                                         </td>
381                                                         <td>
382                                                             <div class="btn-group dropup">
383                                                                 [%# There should be no space between these two buttons, it would render badly %]
384                                                                 <a class="btn btn-default btn-xs" role="button"
385                                                                 href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Run%20this%20report"><i
386                                                                 class="fa fa-play"></i> Run</a><a
387                                                                 class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown"
388                                                                 href="#"><b class="caret"></b></a>
389                                                                 <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
390                                                                     <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> View</a></li>
391                                                                     <li>
392                                                                         <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&phase=Show%20SQL" class="preview_sql" data-reportid="[% savedreport.id | html %]">
393                                                                             <i class="fa fa-eye"></i> Preview SQL
394                                                                         </a>
395                                                                     </li>
396                                                                     [% IF ( CAN_user_reports_create_reports ) %]
397                                                                         <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>
398                                                                         <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% savedreport.id | uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
399                                                                     [% END %]
400                                                                     [% IF (Koha.Preference('Mana') == 1) %]
401                                                                         <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>
402                                                                     [% END %]
403                                                                     <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | uri %]"><i class="fa fa-clock-o"></i> Schedule</a></li>
404                                                                     [% IF ( CAN_user_reports_delete_reports ) %]
405                                                                         <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>
406                                                                     [% END %]
407                                                                 </ul>
408                                                             </div>
409                                                             <input type="hidden" id="previewSql[% savedreport.id | html %]" value="[% savedreport.savedsql | html %]" data-title="[% savedreport.report_name | html %]" />
410                                                         </td>
411                                                     </tr>
412                                                 [% END %]
413                                             </tbody>
414                                         </table>
415
416                                         [% IF ( CAN_user_reports_delete_reports ) %]
417                                             <fieldset class="action">
418                                                 <input type="submit" class="btn btn-primary" value="Delete selected" />
419                                             </fieldset>
420                                         [% END %]
421                                     </form>
422                                 </div> <!-- /#reports -->
423                             </div> <!-- /.tab-content -->
424                         </div>
425                     [% ELSE # IF ( savedreports ) %]
426                         <div class="dialog message">
427                             [% IF (filter_set || filters.date || filters.author || filters.keyword) %]
428                                 <h4>No saved reports match your criteria. </h4>
429                                 [% IF ( CAN_user_reports_create_reports ) %]
430                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
431                                         <input type="hidden" name="phase" value="Build new" />
432                                         <button type="submit" class="new"><i class="fa fa-plus"></i> New guided report</button>
433                                     </form>
434
435                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
436                                         <input type="hidden" name="phase" value="Create report from SQL" />
437                                         <button type="submit" class="new"><i class="fa fa-plus"></i> New SQL report</button>
438                                     </form>
439
440                                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
441                                         <input type="hidden" name="phase" value="Use saved" />
442                                         <input type="hidden" name="filter_set" value="1" />
443                                         <input type="hidden" name="filter_keyword" value="" />
444                                         <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> Cancel filter</button>
445                                     </form>
446                                 [% END %]
447                             [% ELSE %]
448                                 <h4>There are no saved reports. </h4>
449                                 [% IF ( CAN_user_reports_create_reports ) %]
450                                     <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a new report?</a>
451                                 [% END %]
452                             [% END # IF (filter_set || filters.date || filters.author || filters.keyword) %]
453                         </div> <!-- /.dialog.message -->
454                     [% END # /IF ( savedreports ) %]
455                 [% END # /IF ( saved1 ) %]
456
457                 [% INCLUDE 'mana/mana-share-report.inc' %]
458
459                 [% IF ( build1 ) %]
460                     [% IF ( cache_error) %]
461                         <div class="dialog alert">
462                             <strong> Please choose a cache_expiry less than 30 days </strong>
463                         </div>
464                     [% END %]
465
466                     <h1>Build a report</h1>
467                     <form action="/cgi-bin/koha/reports/guided_reports.pl">
468                         <fieldset class="rows">
469                             <legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend>
470                             <ol>
471                                 <li>
472                                     <label for="area">Choose: </label>
473                                     <select name="area" id="area">
474                                         [%- FOREACH area IN areas -%]
475                                             <option value="[% area | html %]">[%- PROCESS area_name area=area -%]</option>
476                                         [%- END -%]
477                                     </select>
478                                 </li>
479                                 [% IF (public) %]
480                                     <li>
481                                         <label for="public">Report is public:</label>
482                                         <select id="public" name="public">
483                                             <option value="0">No (default)</option>
484                                             <option value="1" selected="selected">Yes</option>
485                                         </select>
486                                     </li>
487                                 [% ELSE %]
488                                     <li>
489                                         <label for="public">Report is public:</label>
490                                         <select id="public" name="public">
491                                             <option value="0" selected="selected">No (default)</option>
492                                             <option value="1">Yes</option>
493                                         </select>
494                                     </li>
495                                 [% END %]
496
497                                 [% IF (usecache) %]
498                                     <li>
499                                         <label for="cache_expiry">Cache expiry:</label>
500                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
501                                         <select id="cache_expiry_units" name="cache_expiry_units">
502                                             <option value="seconds">Seconds (default)</option>
503                                             <option value="minutes">Minutes</option>
504                                             <option value="hours">Hours</option>
505                                             <option value="days">Days</option>
506                                         </select>
507                                     </li>
508                                 [% END %]
509                             </ol>
510                         </fieldset> <!-- /.rows -->
511                         <fieldset class="action">
512                             <input type="hidden" name="phase" value="Report on this Area" />
513                             <input type="submit" name="submit" value="Next &gt;&gt;" />
514                         </fieldset>
515                     </form>
516                 [% END # /build1 %]
517
518                 [% IF ( build2 ) %]
519                     <h1>Build a report</h1>
520                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
521                         <input type="hidden" name="area" value="[% area | html %]" />
522                         <input type="hidden" name="public" value="[% public | html %]" />
523                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
524                         <fieldset class="rows">
525                             <legend>Step 2 of 6: Pick a report type</legend>
526                             <ol>
527                                 <li>
528                                     <label for="types">Choose: </label>
529                                     <select id="types" name="types">
530                                         <option value="1">Tabular</option>
531                                         <option value="2" disabled="disabled">Summary</option>
532                                         <option value="3" disabled="disabled">Matrix</option>
533                                     </select>
534                                 </li>
535                             </ol>
536                         </fieldset>
537
538                         <fieldset class="action">
539                             <input type="hidden" name="phase" value="Choose this type" />
540                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
541                             <input type="submit" name="submit" value="Next &gt;&gt;" />
542                         </fieldset>
543                     </form>
544                 [% END # /IF (build2 ) %]
545
546                 [% IF ( build3 ) %]
547                     <h1>Build a report</h1>
548                     <h3>Step 3 of 6: Select columns for display</h3>
549                     <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>
550
551                     <form id="column_submit" action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
552                         <input type="hidden" name="area" value="[% area | html %]" />
553                         <input type="hidden" name="type" value="[% type | html %]" />
554                         <input type="hidden" name="public" value="[% public | html %]" />
555                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
556                         <fieldset>
557                             <div class="row">
558                                 <div class="col-sm-6">
559                                     <div style="float: left;">
560                                         <select id="availableColumns" name="oldcolumns2" multiple="multiple" size="25" style="min-width: 200px;height:300px;">
561                                             [% FOREACH column IN columns %]
562                                                 [% IF ( column.table ) %]
563                                                     [% IF ( loop.first ) %]
564                                                     [% ELSE %]
565                                                         </optgroup>
566                                                     [% END %]
567                                                     <optgroup label="[% column.table | html %]">
568                                                 [% ELSE %]
569                                                     <option value="[% column.name | html %]">
570                                                         [% IF ( column.description ) %]
571                                                             [% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
572                                                         [% ELSE %]
573                                                             [% column.name | html %]
574                                                         [% END %]
575                                                     </option>
576                                                 [% END %]
577                                             [% END %]
578                                             </optgroup>
579                                         </select>
580                                     </div>
581                                     <div style="width: 6.3em; float: right; margin-top: 100px">
582                                         <input type="button" name="Add" value="Add" class="button" style="width:6em;" id="addColumn" /><br />
583                                         <input type="button" name="delete" value="&lt;&lt; Delete" class="button" style="width: 6em; margin: 1em 0;" id="delColumn" />
584                                     </div>
585                                 </div> <!-- /.col-sm-6 -->
586
587                                 <div class="col-sm-6">
588                                     <select id="selectedColumns" name="columns" multiple="multiple" size="25" style="width:200px; height:300px;">
589                                     </select>
590                                 </div>
591                             </div> <!-- /.row -->
592                         </fieldset>
593                         <fieldset class="action">
594                             <input type="hidden" name="phase" value="Choose these columns" />
595                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
596                             <input type="submit" name="submit" value="Next &gt;&gt;" />
597                         </fieldset>
598                     </form> <!-- /#column_submit -->
599                 [% END # /IF ( build3 ) %]
600
601                 [% IF ( build4 ) %]
602                     <h1>Build a report</h1>
603                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" >
604                         <input type="hidden" name="area" value="[% area | html %]" />
605                         <input type="hidden" name="type" value="[% type | html %]" />
606                         <input type="hidden" name="column" value="[% column | html %]" />
607                         <input type="hidden" name="public" value="[% public | html %]" />
608                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
609                         <fieldset>
610                             <legend>Step 4 of 6: Select criteria to limit on</legend>
611                             <table>
612                                 [% FOREACH criteri IN criteria %]
613                                     <tr>
614                                         <td>
615                                             <input type="checkbox" name="criteria_column" id="[% criteri.name | html %]" value="[% criteri.name | html %]" />
616                                             <label for="[% criteri.name | html %]">[% criteri.description | html %] </label>
617                                         </td>
618                                         [% IF ( criteri.date ) %]
619                                             <td>
620                                                 <input type="text" size="10" id="[% criteri.name | html %]_value" name="[% criteri.name | html %]_value" value="" class="flatpickr" />
621                                                 <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
622                                             </td>
623                                         </tr>
624                                         [% ELSE %]
625                                             [% IF ( criteri.textrange ) %]
626                                                 <td>
627                                                     from
628                                                     <input type="text" size="10" id="[% criteri.from | html %]_value" name="[% criteri.from | html %]_value" value="" /> to
629                                                     <input type="text" size="10" id="[% criteri.to | html %]_value" name="[% criteri.to | html %]_value" value="" />
630                                                 </td>
631                                             </tr>
632                                             [% ELSE %]
633                                                 [% IF ( criteri.daterange ) %]
634                                                     <td>
635                                                         from
636                                                         <input type="text" size="10" id="from_[% criteri.name.remove('\.') | html %]_value" name="from_[% criteri.name | html %]_value" value="" data-date_to="to_[% criteri.name.remove('\.') | html %]_value" class="flatpickr" />
637                                                         to
638                                                         <input type="text" size="10" id="to_[% criteri.name.remove('\.') | html %]_value" name="to_[% criteri.name | html %]_value" value="" class="flatpickr" />
639                                                         <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
640                                                     </td>
641                                                 </tr>
642                                                 [% ELSE %]
643                                                     <td>
644                                                         <select name="[% criteri.name | html %]_value">
645                                                            [% FOREACH value IN criteri.values %]
646                                                                 <option value="[% value.availablevalues | html %]">
647                                                                     [% IF ( value.default ) %]
648                                                                         Default
649                                                                     [% ELSE %]
650                                                                         [% value.display_value | html %]
651                                                                     [% END %]
652                                                                 </option>
653                                                             [% END %]
654                                                         </select>
655                                                     </td>
656                                                 </tr>
657                                                 [% END %]
658                                             [% END %]
659                                         [% END %]
660                                 [% END %]
661                             </table>
662                         </fieldset>
663
664                         [% IF ( definitions ) %]
665                             <fieldset>
666                                 <legend>Dictionary definitions</legend>
667                                 <table>
668                                     [% FOREACH definition IN definitions %]
669                                         <tr>
670                                             <td>
671                                                 <input type="checkbox" name="definition" value="[% definition.id | html %]" />
672                                                 [% definition.name | html %]
673                                             </td>
674                                         </tr>
675                                     [% END %]
676                                 </table>
677                             </fieldset>
678                         [% END %]
679
680                         <fieldset class="action">
681                             <input type="hidden" name="phase" value="Choose these criteria" />
682                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
683                             <input type="submit" name="submit" value="Next &gt;&gt;" />
684                         </fieldset>
685                     </form>
686                 [% END # /IF ( build4 ) %]
687
688                 [% IF ( build5 ) %]
689                     <h1>Build a report</h1>
690                     <h3>Step 5 of 6: Pick which columns to total</h3>
691                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
692                         <input type="hidden" name="area" value="[% area | html %]" />
693                         <input type="hidden" name="type" value="[% type | html %]" />
694                         <input type="hidden" name="column" value="[% column | html %]" />
695                         <input type="hidden" name="definition" value="[% definition | html %]" />
696                         <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
697                         <input type="hidden" name="public" value="[% public | html %]" />
698                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
699                         <fieldset>
700                             <table>
701                                 [% FOREACH total_b IN total_by %]
702                                     <tr>
703                                         <td>
704                                             <input type="checkbox" name="total_by" id="[% total_b.name | html %]" value="[% total_b.name | html %]" />
705                                             <label for="[% total_b.name | html %]">[% total_b.name | html %]</label>
706                                         </td>
707                                         <td>
708                                             <select name="[% total_b.name | html %]_tvalue">
709                                                 [% FOREACH selec IN total_b.select %]
710                                                     <option value="[% selec.value | html %]">[% selec.value | html %]</option>
711                                                 [% END %]
712                                             </select>
713                                         </td>
714                                     </tr>
715                                 [% END %]
716                             </table>
717                         </fieldset>
718
719                         <fieldset class="action"><input type="hidden" name="phase" value="Choose these operations" />
720                             <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
721                             <input type="submit" name="submit" value="Next &gt;&gt;" />
722                         </fieldset>
723                     </form>
724                 [% END # /IF ( build5 ) %]
725
726                 [% IF ( build6 ) %]
727                     <h1>Build a report</h1>
728                     <h3>Step 6 of 6: Choose how you want the report ordered</h3>
729                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
730                         <input type="hidden" name="area" value="[% area | html %]" />
731                         <input type="hidden" name="type" value="[% type | html %]" />
732                         <input type="hidden" name="column" value="[% column | html %]" />
733                         <input type="hidden" name="criteria" value="[% criteriastring | html %]" />
734                         <input type="hidden" name="definition" value="[% definition | html %]" />
735                         <input type="hidden" name="totals" value="[% totals | html %]" />
736                         <input type="hidden" name="public" value="[% public | html %]" />
737                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
738                         <fieldset>
739                             <table>
740                                 [% FOREACH order_b IN order_by %]
741                                     <tr>
742                                         <td>
743                                             <input type="checkbox" id="[% order_b.name | html %]" name="order_by" value="[% order_b.name | html %]" />
744                                             <label for="[% order_b.name | html %]">[% order_b.name | html %]</label>
745                                         </td>
746                                         <td>
747                                             <select name="[% order_b.name | html %]_ovalue">
748                                                 [% FOREACH selec IN order_b.select %]
749                                                     <option value="[% selec.value | html %]">[% selec.value | html %]</option>
750                                                 [% END %]
751                                             </select>
752                                         </td>
753                                     </tr>
754                                 [% END %]
755                             </table>
756                         </fieldset>
757                         <fieldset class="action">
758                             <input type="hidden" name="phase" value="Build report" />
759                             <input type="submit" name="submit" class="btn btn-primary" value="Finish" />
760                         </fieldset>
761                     </form>
762                 [% END #/ IF ( build6 ) %]
763
764                 [% IF ( showreport ) %]
765                     <h1>Confirm custom report</h1>
766                     <p>Your report will be generated with the following SQL statement.</p>
767                     <p>
768                         [% sql | html %]
769                     </p>
770
771                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
772                         <input type="hidden" name="sql" value="[% sql | html %]" />
773                         <input type="hidden" name="type" value="[% type | html %]" />
774                         <input type="hidden" name="public" value="[% public | html %]" />
775                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
776                         <p>You will need to save the report before you can execute it</p>
777                         <fieldset class="action"><input type="hidden" name="phase" value="Save" />
778                             <input type="submit" name="submit" class="btn btn-primary" value="Next" />
779                         </fieldset>
780                     </form>
781                 [% END #/ IF ( showreport ) %]
782
783                 [% IF ( save ) %]
784                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
785                         <input type="hidden" name="sql" value="[% sql | html %]" />
786                         <input type="hidden" name="type" value="[% type | html %]" />
787                         <input type="hidden" name="area" value="[% area | html %]" />
788                         <input type="hidden" name="public" value="[% public | html %]" />
789                         <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
790                         <fieldset class="rows">
791                             <legend><h1>Save your custom report</h1></legend>
792                             <ol>
793                                 <li>
794                                     <label for="reportname" class="required">Report name: </label>
795                                     <input type="text" id="reportname" name="reportname" class="required" required="required" />
796                                     <span class="required">Required</span>
797                                 </li>
798                                 [% PROCESS group_and_subgroup_selection %]
799                                 <li>
800                                     <label for="notes">Notes:</label>
801                                     <textarea name="notes" id="notes"></textarea>
802                                 </li>
803                             </ol>
804                         </fieldset>
805                         <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
806                             <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
807                         </fieldset>
808                     </form>
809                 [% END # /IF( save ) %]
810
811                 [% IF ( warn_authval_problem ) %]
812                     <div class="dialog alert">
813                         <h3>Errors found when processing parameters for report: [% name | html %]</h3>
814                         [% FOREACH problematic_authval IN problematic_authvals %]
815                             <p>
816                             <strong>[% problematic_authval.name | html %]:</strong> The authorized value category (<strong>[% problematic_authval.authval | html %]</strong>)
817                                 you selected does not exist.
818                             </p>
819                         [% END %]
820                         <!-- Save Anyway Form -->
821                         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
822                         <!--Every parameter the user issued is provided as a hidden field for recovery-->
823                             <input type='hidden' name='id' value='[% id | html %]' />
824                             <input type='hidden' name='sql' value='[% sql | html %]' />
825                             <input type='hidden' name='reportname' value='[% reportname | html %]' />
826                             <input type='hidden' name='group' value='[% group | html %]' />
827                             <input type='hidden' name='subgroup' value='[% subgroup | html %]' />
828                             <input type='hidden' name='notes' value='[% notes | html %]' />
829                             <input type='hidden' name='cache_expiry' value='[% cache_expiry | html %]' />
830                             <input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units | html %]' />
831                             <input type='hidden' name='public' value='[% public | html %]' />
832                         [% IF ( phase_update) %]
833                             <input type='hidden' name='phase' value='Update SQL' />
834                             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
835                         [% ELSIF ( phase_save) %]
836                             <input type='hidden' name='area' value='[% area | html %]' />
837                             <input type='hidden' name='phase' value='Save Report' />
838                             <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
839                         [% END %]
840                         </form>
841                         <!-- Go back to editing -->
842                         <form action='/cgi-bin/koha/reports/guided_reports.pl'>
843                             <button type="button" class="new goback"><i class="fa fa-fw fa-pencil"></i> Edit SQL</button>
844                         </form>
845                     </div>
846                 [% END # /IF ( warn_authval_problem )%]
847
848                 [% IF ( enter_params ) %]
849                     <form action='/cgi-bin/koha/reports/guided_reports.pl'>
850                         <input type='hidden' name='reports' value="[% reports | html %]" />
851                         [% IF ( auth_val_error ) %]
852                             <input type='hidden' name='phase' value='Edit SQL' />
853                             <div class="dialog alert">
854                                 <h3>Errors found when processing parameters for report: [% name | html %]</h3>
855                                 [% FOREACH auth_val_error IN auth_val_errors %]
856                                     <p>
857                                         <strong>[% auth_val_error.entry | html %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val | html %]</strong>)
858                                         you selected does not exist.
859                                     </p>
860                                 [% END %]
861                             </div>
862                             <fieldset class="action"><input type="submit" class="btn btn-primary" value="Edit SQL" /></fieldset>
863                         [% ELSE #  IF ( auth_val_error ) %]
864                             <input type='hidden' name='phase' value='Run this report' />
865                             <h1>Enter parameters for report [% name | html %]:</h1>
866                             [% IF ( notes ) %]
867                                 <p>[% notes | html %]</p>
868                             [% END %]
869                             <fieldset class="rows">
870                                 <ol>
871                                     [% FOREACH sql_param IN sql_params %]
872                                         <input name="param_name" value="[% sql_param.name | html %]" type="hidden" />
873                                         [% IF sql_param.input == 'date' %]
874                                             <li>
875                                                 <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="flatpickr" />
876                                             </li>
877                                         [% ELSIF ( sql_param.input == 'text' ) %]
878                                             <li>
879                                                 <label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label>
880                                                 <input id="sql_params[% loop.count | html %]" type="text" name="sql_params" />
881                                             </li>
882                                         [% ELSIF ( sql_param.input == 'textarea' ) %]
883                                             <li>
884                                                 <label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label>
885                                                 <textarea id="sql_params[% loop.count | html %]" name="sql_params" rows="5"></textarea>
886                                             </li>
887                                         [% ELSE %]
888                                             <li>
889                                                 <label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
890                                                 <select name="[%- sql_param.input.name | html -%]" tabindex="1"  id="[%- sql_param.input.id | html -%]">
891                                                     [% IF (sql_param.include_all) %]
892                                                         <option value="%">All</option>
893                                                     [% END %]
894                                                     [% FOREACH value IN sql_param.input.values %]
895                                                         <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
896                                                     [% END %]
897                                                 </select>
898                                             </li>
899                                         [% END # /IF sql_param.input == 'date' %]
900                                     [% END # /FOREACH sql_param %]
901                                 </ol>
902                             </fieldset> <!-- /.rows -->
903                             <fieldset class="action">
904                                 <input type="submit" class="btn btn-primary" value="Run the report" />
905                             </fieldset>
906                         [% END # / IF ( auth_val_error ) %]
907                     </form>
908                 [% END # /IF ( enter_params ) %]
909
910                 [% IF ( execute ) %]
911                     <h1>[% name | html %] <span class="report_heading_id"><span class="report_label">Report ID:</span> <span class="report_number">[% id | html %]</span></span></h1>
912                     <div class="page-section">
913                         [% IF ( notes ) %]
914                             <p><span class="label">Notes:</span> [% notes | html %]</p>
915                         [% END %]
916                         [% IF ( unlimited_total ) %]
917                             <p>
918                                 <span class="label">Total number of results:</span>
919                                 [% unlimited_total | html %]
920                                 [% IF unlimited_total >= limit %]
921                                     ([% results.size | html %] shown)
922                                 [% END %]
923                             </p>
924                         [% END %]
925
926                         <div id="sql_output" style="display:none;">
927                             <span class="label">Report SQL:</span>
928                             <textarea id="sql" readonly="readonly">[% sql | html %]</textarea>
929                         </div>
930
931                         <div>
932                             <a href="#" id="toggle_chart_settings_hid" class="toggle_chart_settings" style="display:none"><i class="fa fa-eye-slash"></i> Hide chart</a>
933                             <a href="#" id="toggle_chart_settings_vis" class="toggle_chart_settings" style="display:none"><i class="fa fa fa-eye"></i> Show chart</a>
934                         </div>
935                         <div id="chart" class="clearfix"></div>
936
937                         [% IF ( execute ) %]
938                             [% UNLESS ( errors ) %]
939                                 <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_record_modification.pl" id="batch_record_modification">
940                                     <input type="hidden" name="recordtype" value="biblio" />
941                                     <input type="hidden" name="op" value="list" />
942                                     [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
943                                     <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">
944                                         [%- recordnumbers = PROCESS batch_list results=results batch_type='biblionumber' | trim | html %][% IF recordnumbers %][% SET batch_biblionumbers = 1 %][% recordnumbers | html %][% END -%]
945                                     </textarea>
946                                 </form>
947
948                                 <form method="POST" action="/cgi-bin/koha/tools/batch_delete_records.pl" id="batch_record_deletion">
949                                     <input type="hidden" name="recordtype" value="biblio" />
950                                     <input type="hidden" name="op" value="list" />
951                                     [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
952                                     <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">
953                                         [%- recordnumbers = PROCESS batch_list results=results batch_type='biblionumber' | trim | html %][% IF recordnumbers %][% SET batch_biblionumbers = 1 %][% recordnumbers | html %][% END -%]
954                                     </textarea>
955                                 </form>
956
957                                 <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_modification">
958                                     <input type="hidden" name="op" value="show" />
959                                     [% FOREACH result IN results %]
960                                         [% FOREACH cells IN result.cells %]
961                                             [% place = loop.index %]
962                                             [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
963                                             [% IF header_row.$place.cell == 'itemnumber' || header_types.item(header_row.$place.cell) == 'itemnumber'  %]
964                                                 [% SET batch_itemnumbers = 1 %]
965                                                 [% SET header_row.$place.has_itemnumbers = 1 %]
966                                                 <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
967                                             [% END %]
968                                         [% END %]
969                                     [% END %]
970                                 </form>
971
972                                 <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_deletion">
973                                     <input type="hidden" name="op" value="show" />
974                                     <input type="hidden" name="del" value="1" />
975                                     [% FOREACH result IN results %]
976                                         [% FOREACH cells IN result.cells %]
977                                             [% place = loop.index %]
978                                             [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
979                                             [% IF header_row.$place.cell == 'itemnumber' || header_types.item(header_row.$place.cell) == 'itemnumber'  %]
980                                                 [% SET batch_itemnumbers = 1 %]
981                                                 [% SET header_row.$place.has_itemnumbers = 1 %]
982                                                 <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
983                                             [% END %]
984                                         [% END %]
985                                     [% END %]
986                                 </form>
987
988                                 <form method="get" action="/cgi-bin/koha/virtualshelves/addbybiblionumber.pl" id="batch_add_to_list">
989                                     [% FOREACH result IN results %]
990                                         [% FOREACH cells IN result.cells %]
991                                             [% place = loop.index %]
992                                             [% NEXT UNLESS cells.cell.match('^(\d+)$') %]
993                                             [% IF header_row.$place.cell == 'biblionumber' || header_types.item(header_row.$place.cell) == 'biblionumber' %]
994                                                 [% SET batch_biblionumbers = 1 %]
995                                                 [% SET header_row.$place.has_biblionumbers = 1 %]
996                                                 <input type="hidden" class="bib_to_list" name="biblionumber" value="[% cells.cell | html %]" />
997                                             [% END %]
998                                         [% END %]
999                                     [% END %]
1000                                 </form>
1001
1002                                 <form method="POST" action="/cgi-bin/koha/tools/modborrowers.pl" id="batch_patron_modification">
1003                                     <input type="hidden" name="op" value="show" />
1004                                     [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
1005                                     <textarea style="display:none" name="cardnumberlist" id="cardnumberlist">
1006                                         [%- cardnumbers = PROCESS batch_list results=results batch_type='cardnumber' | trim | html %][% IF cardnumbers %][% SET batch_cardnumbers = 1 %][% cardnumbers | html %][% END -%]
1007                                     </textarea>
1008                                 </form>
1009
1010                                 [% BLOCK batch_list %]
1011                                         [%- FOREACH result IN results %]
1012                                             [%- FOREACH cells IN result.cells %]
1013                                                 [%- place = loop.index %]
1014                                                 [%- IF header_row.$place.cell == batch_type || header_types.item(header_row.$place.cell) == batch_type %]
1015     [%# We must not add whitespace to the cardnumbers %][% cells.cell | html %]
1016                                                 [%- END %]
1017                                             [%- END %]
1018                                         [%- END -%]
1019                                 [% END %]
1020
1021                                 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect">
1022                                     <input type="hidden" name="phase" value="Run this report"/>
1023                                     <input type="hidden" name="reports" value="[% report_id | html %]"/>
1024                                     [% FOREACH p IN sql_params %]
1025                                         <input type="hidden" name="sql_params" value="[% p | html %]"/>
1026                                     [% END %]
1027                                     [% FOREACH n IN param_names %]
1028                                         <input type="hidden" name="param_name" value="[% n | html %]"/>
1029                                     [% END %]
1030                                     <input type="hidden" name="limit" id="limit" value="20" />
1031                                 </form> <!-- /#limitselect -->
1032
1033                                 [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) || ( unlimited_total > 10 && limit <= 1000 ) %]
1034                                     <div id="toolbar" class="btn-toolbar">
1035                                         [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %]
1036                                             <div class="btn-group">
1037                                                 <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="batch_mod_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
1038                                                     Batch operations with [% IF unlimited_total >= limit %][% limit | html %][% ELSE %][% unlimited_total | html %][% END %] visible records
1039                                                     <span class="caret"></span>
1040                                                 </button>
1041                                                 <ul class="dropdown-menu" aria-labelledby="batch_mod_menu">
1042                                                     [% FOREACH header_ro IN header_row %]
1043                                                         [% IF header_ro.has_biblionumbers && ( header_ro.cell == 'biblionumber' || header_types.item( header_ro.cell ) == 'biblionumber' ) %]
1044                                                             <li class="dropdown-header">Bibliographic records</li>
1045                                                             <li>
1046                                                                 <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>
1047                                                             </li>
1048                                                             <li>
1049                                                                 <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>
1050                                                             </li>
1051                                                             <li>
1052                                                                 <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>
1053                                                             </li>
1054                                                         [% END %]
1055                                                         [% IF header_ro.has_itemnumbers && ( header_ro.cell == 'itemnumber' || header_types.item( header_ro.cell ) == 'itemnumber' ) %]
1056                                                             <li class="dropdown-header">Item records</li>
1057                                                             <li>
1058                                                                 <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>
1059                                                             </li>
1060                                                             <li>
1061                                                                 <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>
1062                                                             </li>
1063                                                         [% END %]
1064                                                         [% IF header_ro.cell == 'cardnumber' || header_types.item( header_ro.cell ) == 'cardnumber' %]
1065                                                             <li class="dropdown-header">Patron records</li>
1066                                                             <li>
1067                                                                 <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>
1068                                                             </li>
1069                                                         [% END %]
1070                                                     [% END # /FOREACH header_ro %]
1071                                                 </ul> <!-- /.dropdown-menu -->
1072                                             </div> <!-- /.dropdown -->
1073                                         [% END # /IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %]
1074
1075                                         [% IF ( unlimited_total > 10 && limit <= 1000 ) %]
1076                                             <div class="btn-group">
1077                                                 <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1078                                                     [% IF ( limit ) %]
1079                                                         Rows per page: <strong>[% limit | html %]</strong>
1080                                                     [% ELSE %]
1081                                                         Rows per page
1082                                                     [% END %]
1083                                                     <span class="caret"></span>
1084                                                 </button>
1085                                                 <ul class="dropdown-menu">
1086                                                     [% limits = [ 10, 20, 50, 100, 200, 300, 400, 500, 1000 ] %]
1087                                                     [% FOREACH l IN limits %]
1088                                                         [% IF l == limit %]
1089                                                             <li>
1090                                                                 <a class="limitselect" data-limit="[% l | html %]" href="#"><i class="fa fa-fw fa-check"></i> [% l | html %]</a>
1091                                                             </li>
1092                                                         [% ELSE %]
1093                                                             <li>
1094                                                                 <a class="limitselect" data-limit="[% l | html %]" href="#"><i class="fa fa-fw"></i> [% l | html %]</a>
1095                                                             </li>
1096                                                         [% END %]
1097                                                     [% END %]
1098                                                 </ul>
1099                                             </div>
1100                                         [% END # /IF ( unlimited_total > 10 && limit <= 1000 ) %]
1101
1102                                         [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %]
1103                                             <a href="#" class="btn btn-link" id="toggle_auto_links">
1104                                                 <i class="fa fa-eye autolink" style="display:none"></i>
1105                                                 <i class="fa fa-eye-slash autolink"></i>
1106                                                 <span class="autolink" style="display:none">Show data menus</span>
1107                                                 <span class="autolink">Hide data menus</span>
1108                                             </a>
1109                                         [% END %]
1110                                     </div> <!-- /#toolbar.btn-toolbar -->
1111                                 [% END # /IF batch operations || ( unlimited_total > 10 && limit <= 1000 ) %]
1112
1113                                 <div class="pages">
1114                                     [% pagination_bar | $raw %]
1115                                 </div>
1116
1117                             [% END # UNLESS ( errors ) %]
1118                         [% END # IF ( execute ) %]
1119
1120                         [% UNLESS ( errors ) %]
1121                             <table id="report_results">
1122                                 <thead>
1123                                     <tr>
1124                                         [% FOREACH header_ro IN header_row %]
1125                                             [% IF header_ro.has_itemnumbers && ( header_ro.cell == 'itemnumber' || header_types.item( header_ro.cell ) == 'itemnumber' ) %]
1126                                                 <th class="itemnumber">[% header_ro.cell | html %]</th>
1127                                             [% ELSIF header_ro.has_biblionumbers && ( header_ro.cell == 'biblionumber' || header_types.item( header_ro.cell ) == 'biblionumber' ) %]
1128                                                 <th class="biblionumber">[% header_ro.cell | html %]</th>
1129                                             [% ELSIF header_ro.cell == 'cardnumber' || header_types.item( header_ro.cell ) == 'cardnumber' %]
1130                                                 <th class="cardnumber">[% header_ro.cell | html %]</th>
1131                                             [% ELSIF header_ro.cell == 'borrowernumber' || header_types.item( header_ro.cell ) == 'borrowernumber' %]
1132                                                 <th class="borrowernumber">[% header_ro.cell | html %]</th>
1133                                             [% ELSE %]
1134                                                 <th>[% header_ro.cell | html %]</th>
1135                                             [% END %]
1136                                         [% END %]
1137                                     </tr>
1138                                 </thead>
1139                                 <tbody>
1140                                     [% FOREACH result IN results %]
1141                                         <tr>
1142                                             [% FOREACH cells IN result.cells %]
1143                                                 [% place = loop.index %]
1144                                                 [%- IF header_row.$place.cell == 'itemnumber' || header_types.item(header_row.$place.cell) == 'itemnumber' %]
1145                                                     <td class="batch-op itemnumber" data-number="itemnumber">
1146                                                         <span class="data-plain">[% cells.cell | $raw %]</span>
1147                                                         <div id="itemnumber_autolink" class="btn-group dropup autolink"><a class="btn btn-link dropdown-toggle" role="button" data-toggle="dropdown" href="#">[% cells.cell | $raw %] <b class="caret"></b></a>
1148                                                             <ul class="dropdown-menu pull-right" role="menu">
1149                                                                 <li><a target="_blank" href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&itemnumber=[% cells.cell | $raw %]"><i class="fa fa-fw fa-pencil"></i> Edit record</a></li>
1150                                                                 <li role="separator" class="divider"></li>
1151                                                                 <li><a target="_blank" href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% cells.cell | $raw %]"><i class="fa fa-fw fa-eye"></i> View record</a></li>
1152                                                             </ul>
1153                                                         </div>
1154                                                     </td>
1155                                                 [% ELSIF header_row.$place.cell == 'biblionumber' || header_types.item(header_row.$place.cell) == 'biblionumber' %]
1156                                                     <td class="batch-op biblionumber" data-number="biblionumber">
1157                                                         <span class="data-plain">[% cells.cell | $raw %]</span>
1158                                                         <div id="biblionumber_autolink" class="btn-group dropup autolink"><a class="btn btn-link dropdown-toggle" role="button" data-toggle="dropdown" href="#">[% cells.cell | $raw %] <b class="caret"></b></a>
1159                                                             <ul class="dropdown-menu pull-right" role="menu">
1160                                                                 <li><a target="_blank" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% cells.cell | $raw %]"><i class="fa fa-pencil"></i> Edit record</a></li>
1161                                                                 <li role="separator" class="divider"></li>
1162                                                                 <li><a target="_blank" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% cells.cell | $raw %]"><i class="fa fa-eye"></i> View record</a></li>
1163                                                             </ul>
1164                                                         </div>
1165                                                     </td>
1166                                                 [% ELSIF header_row.$place.cell == 'borrowernumber' || header_types.item(header_row.$place.cell) == 'borrowernumber' %]
1167                                                     <td class="batch-op borrowernumber" data-number="borrowernumber">
1168                                                         <span class="data-plain">[% cells.cell | $raw %]</span>
1169                                                         <div id="borrowernumber_autolink" class="btn-group dropup autolink"><a class="btn btn-link dropdown-toggle" role="button" data-toggle="dropdown" href="#">[% cells.cell | $raw %] <b class="caret"></b></a>
1170                                                             <ul class="dropdown-menu pull-right" role="menu">
1171                                                                 <li><a target="_blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% cells.cell | $raw %]"><i class="fa fa-eye"></i> View patron</a></li>
1172                                                                 <li role="separator" class="divider"></li>
1173                                                                 <li><a target="_blank" href="/cgi-bin/koha/members/memberentry.pl?op=modify&borrowernumber=[% cells.cell | $raw %]"><i class="fa fa-pencil"></i> Edit patron</a></li>
1174                                                                 <li role="separator" class="divider"></li>
1175                                                                 <li><a target="_blank" href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% cells.cell | $raw %]"><i class="fa fa-barcode"></i> Check out</a></li>
1176                                                             </ul>
1177                                                         </div>
1178                                                     </td>
1179                                                 [% ELSIF header_row.$place.cell == 'cardnumber' || header_types.item(header_row.$place.cell) == 'cardnumber' %]
1180                                                     <td class="batch-op cardnumber" data-number="cardnumber">
1181                                                         <span class="data-plain">[% cells.cell | $raw %]</span>
1182                                                         <div id="cardnumber_autolink" class="btn-group dropup autolink"><a class="btn btn-link dropdown-toggle" role="button" data-toggle="dropdown" href="#">[% cells.cell | $raw %] <b class="caret"></b></a>
1183                                                             <ul class="dropdown-menu pull-right" role="menu">
1184                                                                 <li><a target="_blank" href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% cells.cell | $raw %]"><i class="fa fa-barcode"></i> Check out</a></li>
1185                                                             </ul>
1186                                                         </div>
1187                                                     </td>
1188                                                 [% ELSE %]
1189                                                     <td>
1190                                                         [% cells.cell | $raw %]
1191                                                     </td>
1192                                                 [% END %]
1193                                             [% END %]
1194                                         </tr>
1195                                     [% END %]
1196                                 </tbody>
1197                             </table>
1198                         [% END %]
1199                         <div class="pages">[% pagination_bar | $raw %]</div>
1200                     </div>
1201                     [% INCLUDE 'chart.inc' %]
1202
1203                 [% END #/IF ( execute ) %]
1204
1205                 [% IF ( create ) %]
1206                     <h1>Create from SQL</h1>
1207                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
1208                         <fieldset class="rows">
1209                             <legend>Create report from SQL</legend>
1210                             <ol>
1211                                 <li>
1212                                     <label for="reportname" class="required">Report name:</label>
1213                                     [% IF ( reportname ) %]
1214                                         <input type="text" class="required" required="required" id="reportname" name="reportname" value="[% reportname | html %]" size="50"/>
1215                                     [% ELSE %]
1216                                         <input type="text" class="required focus" required="required" id="reportname" name="reportname" size="50" />
1217                                     [% END %]
1218                                     <span class="required">Required</span>
1219                                 </li>
1220                                 [% PROCESS group_and_subgroup_selection %]
1221
1222                                 [% IF (public) %]
1223                                     <li>
1224                                         <label for="public">Report is public:</label>
1225                                         <select id="public" name="public">
1226                                             <option value="0">No (default)</option>
1227                                             <option value="1" selected="selected">Yes</option>
1228                                         </select>
1229                                     </li>
1230                                 [% ELSE %]
1231                                     <li>
1232                                         <label for="public">Report is public:</label>
1233                                         <select id="public" name="public">
1234                                             <option value="0" selected="selected">No (default)</option>
1235                                             <option value="1">Yes</option>
1236                                         </select>
1237                                     </li>
1238                                 [% END # /IF (public) %]
1239
1240                                 [% IF (usecache) %]
1241                                     <li>
1242                                         <label for="cache_expiry">Cache expiry:</label>
1243                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]"></input>
1244                                         <select id="cache_expiry_units" name="cache_expiry_units">
1245                                             <option value="seconds" selected="selected">Seconds (default)</option>
1246                                             <option value="minutes">Minutes</option>
1247                                             <option value="hours">Hours</option>
1248                                             <option value="days">Days</option>
1249                                         </select>
1250                                     </li>
1251                                 [% END # /IF (usecache) %]
1252                                 <li>
1253                                     <label for="notes">Notes:</label>
1254                                     <textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea>
1255                                 </li>
1256                             </ol>
1257                         </fieldset> <!-- /.rows -->
1258
1259                         <fieldset class="rows">
1260                             <legend>SQL:</legend>
1261                             <div style="margin:1em;">
1262                                 [% PROCESS insert_runtime_parameter  %]
1263                                 <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10" >[% sql | html %]</textarea>
1264                                 <span style='color:#383838; font-style:italic'>* In order to achieve auto-complete for columns, please prepend the column name with the table name, followed by a period. For example: 'borrowers.surname'</span>
1265                                 <br/>
1266                                 <span class="required">Required</span>
1267                             </div>
1268                         </fieldset>
1269
1270                         <fieldset class="action">
1271                             <input type="hidden" name="phase" value="Save Report" />
1272                             <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
1273                             <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
1274                         </fieldset>
1275
1276                     </form>
1277                 [% END #/IF ( create ) %]
1278
1279                 [% IF saved_results %]
1280                     <h1>Saved report results</h1>
1281                     <h2>[% name | html %]</h2>
1282                     <p>[% notes | html %]</p>
1283                     <table>
1284                         [% FOREACH rows IN saved_results %]
1285                             <tr>
1286                                 [% FOREACH col IN rows %]
1287                                     <td>[% col | html %]</td>
1288                                 [% END %]
1289                             </tr>
1290                         [% END %]
1291                     </table>
1292                 [% END # /IF saved_results %]
1293
1294                 [% IF ( showsql ) %]
1295                 <h1>Saved reports - SQL</h1>
1296                     <fieldset class="rows">
1297                         <legend>[% reportname | html %]</legend>
1298                         <ol>
1299                             [% IF ( notes ) %]
1300                                 <li>
1301                                     <span class="label">Notes:</span>
1302                                     [% notes | html %]
1303                                 </li>
1304                             [% ELSE %]
1305                             [% END %]
1306                             <li>
1307                                 <textarea id="sql">[% sql | html %]</textarea>
1308                             </li>
1309                         </ol>
1310                     </fieldset>
1311                 [% END # /IF ( showsql ) %]
1312
1313                 [% IF ( save_successful ) %]
1314                     [% UNLESS ( errors ) %]
1315                         </br>
1316                         <div id="report_updated">
1317                             <div class="dialog message">
1318                                 <p>Your report "[% reportname | html %]" has been saved</p>
1319                             </div>
1320                         </div>
1321                     [% END %]
1322                 [% END %]
1323
1324                 [% IF ( editsql ) %]
1325                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="sql_report_form">
1326                         <input type="hidden" name="phase" value="Update SQL" />
1327                         <input type="hidden" name="id" value="[% id | html %]"/>
1328                         <fieldset class="rows">
1329                             <legend><h1>Edit SQL report</h1></legend>
1330                             <ol>
1331                                 <li>
1332                                     <label for="reportname" class="required">Report name: </label>
1333                                     <input type="text" id="reportname" name="reportname" value="[% reportname | html %]" size="50" class="required" required="required" />
1334                                     <span class="required">Required</span>
1335                                 </li>
1336                                 [% PROCESS group_and_subgroup_selection %]
1337                                 [% IF (public) %]
1338                                     <li>
1339                                         <label for="public">Report is public:</label>
1340                                         <select id="public" name="public">
1341                                             <option value="0">No (default)</option>
1342                                             <option value="1" selected="selected">Yes</option>
1343                                         </select>
1344                                     </li>
1345                                 [% ELSE %]
1346                                     <li>
1347                                         <label for="public">Report is public:</label>
1348                                         <select id="public" name="public">
1349                                             <option value="0" selected="selected">No (default)</option>
1350                                             <option value="1">Yes</option>
1351                                         </select>
1352                                     </li>
1353                                 [% END # /IF (public) %]
1354
1355                                 [% IF (usecache) %]
1356                                     <li>
1357                                         <label for="cache_expiry">Cache expiry:</label>
1358                                         <input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry | html %]" />
1359                                         <select id="cache_expiry_units" name="cache_expiry_units">
1360                                             <option value="seconds">Seconds (default)</option>
1361                                             <option value="minutes">Minutes</option>
1362                                             <option value="hours">Hours</option>
1363                                             <option value="days">Days</option>
1364                                         </select>
1365                                     </li>
1366                                 [% END %]
1367                                 <li>
1368                                     <label for="notes">Notes:</label>
1369                                     <textarea id="notes" name="notes" cols="50" rows="2">[% notes | html %]</textarea>
1370                                 </li>
1371                             </ol>
1372                         </fieldset> <!-- /.rows -->
1373
1374                         <fieldset class="rows">
1375                             <legend>SQL:</legend>
1376                                 [% PROCESS insert_runtime_parameter  %]
1377                                 <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql | html %]</textarea>
1378                                 <span style='color:#383838; font-style:italic'>* In order to achieve auto-complete for columns, please prepend the column name with the table name, followed by a period. For example: 'borrowers.surname'</span>
1379                                 <br/>
1380                                 <span class="required" style="margin-left:30px;">Required</span>
1381                         </fieldset>
1382
1383                         <fieldset class="action">
1384                             <input type="submit" name="submit" class="btn btn-primary" value="Update SQL" />
1385                             <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
1386                         </fieldset>
1387                     </form>
1388                 [% END # /IF ( editsql ) %]
1389
1390                 [% IF ( errors ) %]
1391                     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
1392                         <div class="dialog alert">
1393                             <strong>The following error was encountered:</strong><br />
1394                             [% FOREACH error IN errors %]
1395                                 [% IF ( error.sqlerr ) %]
1396                                     This report contains the SQL keyword <strong>[% error.sqlerr | html %]</strong>.<br />
1397                                     Use of this keyword is not allowed in Koha reports due to security and data integrity risks. Only SELECT queries are allowed.<br />
1398                                     Please return to the &quot;Saved Reports&quot; screen and delete this report or retry creating a new one.
1399                                 [% ELSIF ( error.queryerr ) %]
1400                                     <span>The database returned the following error:</span> <br />
1401                                     [% error.queryerr | html %]<br />Please check the log for further details.
1402                                 [% ELSIF ( error.cache_expiry ) %]
1403                                     Please select a cache expiry less than 30 days.
1404                                 [% ELSE %]
1405                                 [% END %]
1406                                 <div id="onerror_actions">
1407                                     <a href="#" class="button goback">Return to previous page</a>
1408                                 </div>
1409                             [% END %]
1410                         </div>
1411                         <fieldset class="action">
1412                             <input type="hidden" name="phase" value="Use saved" />
1413                             <input type="submit" name="submit" class="btn btn-primary" value="Saved reports" />
1414                         </fieldset>
1415                     </form>
1416                 [% END # /IF ( errors ) %]
1417
1418             </main>
1419         </div> <!-- /.col-sm-10.col-sm-push-2 -->
1420
1421         <div class="col-sm-2 col-sm-pull-10">
1422             <aside>
1423                 [% IF ( saved1 ) %]
1424                     <div id="saved-reports-filter">
1425                         <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
1426                             <input type="hidden" name="phase" value="Use saved" />
1427                             <input type="hidden" name="filter_set" value="1" />
1428                             <fieldset class="brief">
1429                                 <h3>Filter</h3>
1430                                 <ol>
1431                                     <li>
1432                                         <label for="filter_date">Date:</label>
1433                                         <input type="text" id="filter_date" name="filter_date" size="10" value="[% filters.date | html %]" class="flatpickr" />
1434                                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
1435                                     </li>
1436                                     <li>
1437                                         <label for="filter_author">Author:</label>
1438                                         <input type="text" id="filter_author" name="filter_author" value="[% filters.author | html %]" size="16" />
1439                                     </li>
1440                                     <li>
1441                                         <label for="filter_keyword">Keyword:</label>
1442                                         <input type="text" id="filter_keyword" name="filter_keyword" value="[% filters.keyword | html %]" size="16" />
1443                                     </li>
1444                                 </ol>
1445                             </fieldset> <!-- /.brief -->
1446                             <fieldset class="action">
1447                                 <input type="submit" class="btn btn-primary" value="Apply filter" />
1448                                 <a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1">Clear</a>
1449                             </fieldset>
1450                         </form>
1451                     </div> <!-- /#saved-reports-filter -->
1452                 [% END %]
1453                 [% INCLUDE 'guided-reports-view.inc' %]
1454             </aside>
1455         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1456     </div> <!-- /.row -->
1457
1458     <!-- Runtime Parameters Modal -->
1459     <div class="modal" id="runtime_parameters" tabindex="-1" role="dialog" aria-labelledby="runtime_parametersLabel">
1460         <div class="modal-dialog" role="document">
1461             <div class="modal-content">
1462                 <div class="modal-header">
1463                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1464                     <h4 class="modal-title" id="runtime_parametersLabel">Runtime parameter options</h4>
1465                 </div>
1466                 <form id="send_runtime_parameter">
1467                     <input type="hidden" name="param_category" id="param_category" />
1468                     <div class="modal-body">
1469                         <div class="form-group">
1470                             <label for="paramLabel" class="required">Parameter label: </label>
1471                             <input class="form-control required" type="text" name="paramLabel" id="paramLabel" required="required" />
1472                             <div class="hint">The label for the field shown when the report is run, e.g. "Select a library."</div>
1473                         </div>
1474                         <div id="authorised_value_category" class="form-group" style="display:none">
1475                             <label for="authorised_value">Authorized value category:</label>
1476                             <select class="form-control" name="authorised_value" id="authorised_value">
1477                                 <option value=""></option>
1478                                 [% PROCESS options_for_authorised_value_categories authorised_value_categories => AuthorisedValues.GetCategories() %]
1479                             </select>
1480                             <div class="hint">Select which authorized value category the user will choose from.</div>
1481                         </div>
1482                     </div> <!-- /.modal-body -->
1483                     <div class="modal-footer">
1484                         <button type="submit" id="sendParam" class="btn btn-default approve">Insert parameter</button>
1485                         <button type="button" class="btn btn-default deny" data-dismiss="modal">Cancel</button>
1486                     </div> <!-- /.modal-footer -->
1487                 </form> <!-- /#send_runtime_parameter -->
1488             </div> <!-- /.modal-content -->
1489         </div> <!-- /.modal-dialog -->
1490     </div> <!-- /#runtime_parameters -->
1491
1492 [% MACRO jsinclude BLOCK %]
1493     [% Asset.js("js/charts.js") | $raw %]
1494     [% Asset.js("lib/d3c3/d3.min.js") | $raw %]
1495     [% Asset.js("lib/d3c3/c3.min.js") | $raw %]
1496     [% INCLUDE 'calendar.inc' %]
1497     [% INCLUDE 'datatables.inc' %]
1498     [% IF ( saved1 ) %]
1499         [% INCLUDE 'columns_settings.inc' %]
1500     [% END %]
1501     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
1502     [% Asset.js( "lib/codemirror/overlay.min.js" ) | $raw %]
1503     [% Asset.js( "lib/codemirror/sql.js" ) | $raw %]
1504     [% Asset.js( "lib/codemirror/show-hint.js" ) | $raw %]
1505     [% Asset.css("lib/codemirror/show-hint.css") | $raw %]
1506     [% Asset.js( "lib/codemirror/sql-hint.js" ) | $raw %]
1507     [% Asset.js( "lib/codemirror/highlight.js" ) | $raw %]
1508     [% Asset.css("lib/codemirror/highlight.css") | $raw %]
1509     [% Asset.js( "js/mana.js" ) | $raw %]
1510
1511     <script>
1512
1513         function hide_bar_element() {
1514             $('#chart-column-horizontal').hide()
1515             $('.chart-column-group').each(function( index ) {
1516                 $( this ).hide();
1517             });
1518             $('.chart-column-line').each(function( index ) {
1519                 $( this ).hide()
1520             });
1521         }
1522
1523         function show_bar_element() {
1524             $('#chart-column-horizontal').show()
1525             $('.chart-column-group').each(function( index ) {
1526                 $( this ).show()
1527             });
1528             $('.chart-column-line').each(function( index ) {
1529                 $( this ).show()
1530             });
1531         }
1532
1533         function removeColumn(id) {
1534             $('#'+id).remove();
1535
1536             if ( $('.chart-column-conf').length == 1 ) {
1537                 $('.chart-column-delete').remove();
1538             }
1539         }
1540
1541         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1542         var group_subgroups = {};
1543         [% FOREACH group IN groups_with_subgroups %]
1544             var gid = "[% group.id | html %]"
1545             group_subgroups[gid] = new Array();
1546             [% FOREACH subgroup IN group.subgroups %]
1547                 var sgid = "[% subgroup.id | html %]";
1548                 var sgname = "[% subgroup.name | html %]";
1549                 group_subgroups[gid].push([sgid, sgname]);
1550             [% END %]
1551         [% END %]
1552
1553         [% IF ( create || editsql || save ) %]
1554
1555             var editor = CodeMirror.fromTextArea(sql, {
1556                 lineNumbers: true,
1557                 mode: "text/x-sql",
1558                 lineWrapping: true,
1559                 smartIndent: false,
1560                 keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1561                     "\\[\\[(.*?)\\]\\]":"style1",
1562                     "<<(.*?)>>":"style1"
1563                 },
1564                 extraKeys: {"Tab": "autocomplete"}, //enable tab to accept auto-complete
1565                 hint: CodeMirror.hint.sql,
1566                 hintOptions: {
1567                     tables: [% To.json(tables) | $raw %]
1568                 }
1569             });
1570             var ExcludedTriggerKeys = { //key-code combinations of keys that will not fire the auto-complete script
1571                 "8": "backspace",
1572                 "9": "tab",
1573                 "13": "enter",
1574                 "16": "shift",
1575                 "17": "ctrl",
1576                 "18": "alt",
1577                 "19": "pause",
1578                 "20": "capslock",
1579                 "27": "escape",
1580                 "33": "pageup",
1581                 "32": "spacebar",
1582                 "34": "pagedown",
1583                 "35": "end",
1584                 "36": "home",
1585                 "37": "left",
1586                 "38": "up",
1587                 "39": "right",
1588                 "40": "down",
1589                 "45": "insert",
1590                 "46": "delete",
1591                 "56": "asterisk",
1592                 "59": "semicolon",
1593                 "91": "left window key",
1594                 "92": "right window key",
1595                 "93": "select",
1596                 "106": "asterisk",
1597                 "107": "add",
1598                 "109": "subtract",
1599                 "110": "decimal point",
1600                 "111": "divide",
1601                 "112": "f1",
1602                 "113": "f2",
1603                 "114": "f3",
1604                 "115": "f4",
1605                 "116": "f5",
1606                 "117": "f6",
1607                 "118": "f7",
1608                 "119": "f8",
1609                 "120": "f9",
1610                 "121": "f10",
1611                 "122": "f11",
1612                 "123": "f12",
1613                 "144": "numlock",
1614                 "145": "scrolllock",
1615                 "186": "semicolon",
1616                 "187": "equalsign",
1617                 "188": "comma",
1618                 "189": "dash",
1619                 "191": "slash",
1620                 "192": "graveaccent",
1621                 "220": "backslash",
1622                 "222": "quote"
1623             }
1624             //Trigger auto-complete on all keys not in dictionary of exclusions above.
1625             editor.on("keyup", function(cm, e) {
1626                 if (ExcludedTriggerKeys[e.keyCode] == undefined) {
1627                          CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
1628                 }
1629             })
1630
1631            // https://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages#answer-16025232
1632             function clearValidation( formElement ){
1633                 // formElement should be a jQuery object
1634                 var validator = formElement.validate();
1635                 // Iterate through named elements inside of the form, and mark them as error free
1636                 $('[name]',formElement).each(function(){
1637                     validator.successList.push(this);//mark as error free
1638                     validator.showErrors();//remove error messages if present
1639                 });
1640                 validator.resetForm();//remove error class on name elements and clear history
1641                 validator.reset();//remove all error and success data
1642             }
1643         [% END %]
1644
1645         [% IF ( showsql ) %]
1646
1647             var editor = CodeMirror.fromTextArea(sql, {
1648                 lineNumbers: false,
1649                 mode: "text/x-sql",
1650                 lineWrapping: true,
1651                 readOnly: true,
1652                 keyword: { // Custom highlighting for items bounded in [[ ]] or << >>.
1653                     "\\[\\[(.*?)\\]\\]":"style2",
1654                     "<<(.*?)>>":"style1"
1655                },
1656             });
1657         [% END %]
1658
1659         function showParamModal( category ){
1660             var modal = $("#runtime_parameters");
1661             var modalTitle = $("#runtime_parametersLabel");
1662             switch ( category ){
1663                 case "insertAuthVal":
1664                     modalTitle.text( _("Insert authorized value parameter") );
1665                     $("#paramLabel").val( _("Authorized value") );
1666                     $("#authorised_value_category").show();
1667                     $("label[for='authorised_value']").addClass("required");
1668                     $("#authorised_value").prop("required", true ).attr("required", "required").addClass("required");
1669                     break;
1670                 case "insertCnSource":
1671                     modalTitle.text( _("Insert classification source parameter") );
1672                     $("#paramLabel").val( _("Source of classification or shelving scheme") );
1673                     $("#param_category").val("cn_source");
1674                     break;
1675                 case "insertFramework":
1676                     modalTitle.text( _("Insert bibliographic framework parameter") );
1677                     $("#paramLabel").val( _("Framework") );
1678                     $("#param_category").val("biblio_framework");
1679                     break;
1680                 case "insertDate":
1681                     modalTitle.text( _("Insert date parameter") );
1682                     $("#paramLabel").val( _("Date") );
1683                     $("#param_category").val("date");
1684                     break;
1685                 case "insertItemtypes":
1686                     modalTitle.text( _("Insert item types parameter") );
1687                     $("#paramLabel").val( _("Item type") );
1688                     $("#param_category").val("itemtypes");
1689                     break;
1690                 case "insertBranches":
1691                     modalTitle.text( _("Insert libraries parameter") );
1692                     $("#paramLabel").val( _("Library") );
1693                     $("#param_category").val("branches");
1694                     break;
1695                 case "insertCategorycode":
1696                     modalTitle.text( _("Insert patron category parameter") );
1697                     $("#paramLabel").val( _("Patron category") );
1698                     $("#param_category").val("categorycode");
1699                     break;
1700                 case "insertCashregister":
1701                     modalTitle.text( _("Insert cash register parameter") );
1702                     $("#paramLabel").val( _("Cash register") );
1703                     $("#param_category").val("cash_registers");
1704                     break;
1705                 case "insertDebittypes":
1706                     modalTitle.text( _("Insert debit type parameter") );
1707                     $("#paramLabel").val( _("Debit type") );
1708                     $("#param_category").val("debit_types");
1709                     break;
1710                 case "insertCredittypes":
1711                     modalTitle.text( _("Insert credit type parameter") );
1712                     $("#paramLabel").val( _("Credit type") );
1713                     $("#param_category").val("credit_types");
1714                     break;
1715                 case "insertList":
1716                     modalTitle.text( _("Insert list parameter") );
1717                     $("#paramLabel").val( _("List of values") );
1718                     $("#param_category").val("list");
1719                     break;
1720                 case "insertText":
1721                     modalTitle.text( _("Insert text parameter") );
1722                     $("#paramLabel").val( _("Text") );
1723                     $("#param_category").val("");
1724                     break;
1725             }
1726             $("#paramLabel").select();
1727             modal.modal("show");
1728         }
1729
1730         function load_group_subgroups () {
1731             var group = $("#group_select").val();
1732             var subgroup = $("#subgroup_select").val();
1733             var sg = $("#subgroup");
1734             $(sg).find('option[value!=""]').each(function() {
1735                 $(this).remove();
1736             });
1737             $(sg).hide();
1738             if (group) {
1739                 var select = $(sg).find('select')[0];
1740                 $.each( group_subgroups[group], function(index, value) {
1741                     if ( value[0] == subgroup ) {
1742                         $('<option selected="selected" value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1743                     } else {
1744                         $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
1745                     }
1746                 } );
1747                 $("#subgroup, #subgroup *").show();
1748             }
1749         }
1750
1751         $(document).ready(function(){
1752
1753             var activeTab = localStorage.getItem("sql_reports_activetab");
1754
1755             $("body").on('click',".fetch_chart_data",function(){
1756                 if( [% unlimited_total || 0 | $raw %] > 1000 ){
1757                     if( confirm( _("Fetching full chart data for reports with many rows can cause performance issues. Are you sure you want to chart this report?") ) ){
1758                         return true;
1759                     } else {
1760                         return false;
1761                     }
1762                 }
1763             });
1764
1765             var showsql;
1766             hide_bar_element();
1767
1768             if ( $('.chart-column-conf').length == 1 ) {
1769                 $('.chart-column-delete').remove();
1770             }
1771
1772             $(".chart-column-delete").on('click', function(e){
1773                 e.preventDefault();
1774                 removeColumn('column_' + $(this).data('column'));
1775             })
1776
1777             $('#download-chart').click(function() {
1778                 var svg = '<svg>' + $('#chart svg').html() + '</svg>';
1779                 this.href = 'data:application/octet-stream;base64,' + btoa(svg);
1780                 this.setAttribute('download', 'chart.svg');
1781             });
1782
1783             $('#chart-type').change(function() {
1784                 if ($(this).val() == 'bar') {
1785                     show_bar_element();
1786                 }
1787                 else {
1788                     hide_bar_element();
1789                 }
1790             });
1791
1792             $('#download-chart').hide();
1793             var chart;
1794
1795             [% IF results && !errors %]
1796                 $('#draw-chart').click(function() {
1797
1798                     var x_elements = $('select[name="x"]').val();
1799                     var y_elements = [];
1800                     var groups = [];
1801                     var lines = [];
1802                     var options = {};
1803
1804                     headers = [% header_row.json | $raw %];
1805
1806                     var results;
1807                     [% IF allresults.size %]
1808                         if ($('input[name="chart-include-all"]').prop('checked')) {
1809                             results = [% allresults.json | $raw %]
1810                         }
1811                         else {
1812                             results = [% results.json | $raw %]
1813                         }
1814                     [% ELSE %]
1815                         results = [% results.json | $raw %];
1816                     [% END %]
1817
1818                     if ($('input[name="chart-exclude-last"]').prop('checked')) {
1819                         results.splice(-1, 1);
1820                     }
1821
1822                     $('select[name="y"]').each(function( index ) {
1823                         y_elements.push( $(this).val() );
1824                     });
1825                     $('select[name="group"]').each(function( index ) {
1826                         groups.push( $(this).val() );
1827                     });
1828                     $('.column-line').each(function( index ) {
1829                         if ($(this).prop('checked')) {
1830                             lines.push( $(this).attr('name') );
1831                         }
1832                     });
1833
1834                     // Remove deleted columns from headers and results.
1835                     var deleted_indexes = [];
1836                     var kept_headers = [];
1837                     $.each(headers, function(index, value) {
1838                         if (value.cell != x_elements && $.inArray(value.cell, y_elements) === -1) {
1839                             // This header is neither a x element nor in y elements. Don't need it.
1840                             deleted_indexes.push(index);
1841                         }
1842                         else {
1843                             kept_headers.push({cell: value.cell});
1844                         }
1845                     });
1846
1847                     // Remove coresponding cells.
1848                     var kept_results = [];
1849                     $.each(results, function(index, value) {
1850                         var line = {};
1851                         line['cells'] = [];
1852                         $.each(value.cells, function(i, val) {
1853                             if ($.inArray(i, deleted_indexes) === -1) {
1854                                 line['cells'].push({cell: val.cell});
1855                             }
1856                         });
1857                         kept_results.push(line);
1858                     });
1859
1860                     options.type = $('select[name="chart-type"]').val();
1861                     options.horizontal = $('input[name="column-horizontal"]').prop('checked');
1862                     options.lines = lines;
1863
1864                     chart = create_chart(kept_headers, kept_results, x_elements, y_elements, groups, options);
1865                     $("#download-chart,#toggle_chart_settings_hid,#chart").show();
1866                     $("#toggle_chart_settings_vis").hide();
1867                     $("#chartModal").modal("hide");
1868                 });
1869             [% END %]
1870             [% IF ( create ) %]
1871                 load_group_subgroups();
1872             [% END %]
1873
1874             $('[data-toggle="tooltip"]').tooltip();
1875
1876             $('#limit').change(function() {
1877                 $('#limitselect').submit();
1878             });
1879
1880             $(document).click(function() {
1881                 $('#report_updated').hide();
1882             });
1883
1884             $(".goback").on("click",function(e){
1885                 e.preventDefault();
1886                 window.history.back();
1887             });
1888
1889             $("body").on("click", ".mana_search_button", function(){
1890                 $("#mana-loading").show();
1891                 mana_search($("#mana_search_field").val());
1892             });
1893
1894             $(".ShareButton").on("click", function(){
1895                 $("#note-error").hide();
1896                 if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){
1897                     $(".shared_infos").hide();
1898                     $("#note-error").show();
1899                 }
1900                 else{
1901                     $("#reportid").val($(this).closest("tr").find(".report_id").text());
1902                     $("#shared_id").html($(this).closest("tr").find(".report_id").text());
1903                     $("#shared_name").html($(this).closest("tr").find(".report_name").text());
1904                     $("#shared_sql").html($(this).closest("tr").find(".report_sql").val());
1905                     $("#shared_type").html($(this).closest("tr").find(".report_type").text());
1906                     $("#shared_group").html($(this).closest("tr").find(".report_group").text());
1907                     $("#shared_notes").html($(this).closest("tr").find(".report_notes").text());
1908                 }
1909             });
1910
1911             $("#ManaCloseButton").on("click", function() {
1912                 $(".shared_infos").show();
1913             });
1914
1915             $("#addColumn").on("click",function(){
1916                 addColumn();
1917             });
1918
1919             $("#delColumn").on("click",function(){
1920                 delColumn();
1921             });
1922
1923             [% IF (saved1) %]
1924                 var table_settings = [% TablesSettings.GetTableSettings( 'reports', 'saved-sql', 'table_reports', 'json' ) | $raw %];
1925                 var rtable = KohaTable("table_reports", {
1926                     'bAutoWidth': false,
1927                     'sPaginationType': 'full',
1928                     'aaSorting': [[ 1, "asc" ]],
1929                     'oLanguage': {
1930                         'sZeroRecords': _("No matching reports found")
1931                     }
1932                 }, table_settings);
1933
1934                 $("#tabs a[data-toggle='tab']").on("shown.bs.tab", function (e) {
1935                     tabsInit( $(e.target).parent(), rtable );
1936                 });
1937
1938                 if( activeTab ){
1939                     $("#tabs li:eq(" + activeTab + ") a").tab("show");
1940                 }
1941
1942                 $("#subgroup_filter").change(function() {
1943                     var selected = $(this).find('option:selected');
1944                     var sg_id = $(selected).val();
1945                     var sg_name = $(selected).text();
1946                     if (sg_id.length > 0) {
1947                         rtable.fnFilter('^' + sg_name + '$', 5, true, true, true, false);
1948                         rtable.fnSetColumnVis(5, false);
1949                     } else {
1950                         rtable.fnFilter('', 5);
1951                         rtable.fnSetColumnVis(5, true);
1952                     }
1953                 });
1954
1955                 $("#reports_form").submit(function(){
1956                     var checkedItems = $("input[name=ids]:checked");
1957                     if ($(checkedItems).size() == 0) {
1958                         alert(_("You must select one or more reports to delete"));
1959                         return false;
1960                     }
1961                     $(checkedItems).parents('tr').addClass("warn");
1962                     if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
1963                         return true;
1964                     } else {
1965                         $(checkedItems).parents('tr').removeClass("warn");
1966                         return false;
1967                     }
1968                 });
1969
1970                 $("body").on("click", ".update_sql", function(e){
1971                     e.preventDefault();
1972                     var ltitle = $(this).text();
1973                     var report_id = $(this).data("report_id");
1974                     var page = $(this).attr("href");
1975                     $("#update_sql .modal-body").load(page + " div", function(){
1976                         var diff1 = $("#col1 .show_sql").text();
1977                         var diff2 = $("#col2 .show_sql").text();
1978                         var diffs = diffString( escape(diff1), escape(diff2) );
1979                         $("#col1 .show_sql,#col2 .show_sql").html(diffs);
1980                     });
1981                     $('#update_sql').modal('show');
1982                     $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id);
1983                 });
1984
1985                 $("#update_sql").on("hidden.bs.modal", function(){
1986                     $("#update_sql_label").html("");
1987                     $("#update_sql .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
1988                 });
1989             [% END %]
1990
1991             [% IF ( showsql ) %]
1992                 $("#sql").focus(function() {
1993                     $(this).select();
1994                 });
1995             [% END %]
1996
1997             $("#toggle_sql").click(function(){
1998                 var sql_output = $("#sql_output");
1999                 sql_output.toggle();
2000                 if( sql_output.is(":visible") ){
2001                     $(this).button('complete');
2002                 } else {
2003                     $(this).button('reset');
2004                 }
2005                 if( !showsql ){
2006                     showsql = CodeMirror.fromTextArea(sql, {
2007                         lineNumbers: false,
2008                         mode: "text/x-sql",
2009                         lineWrapping: true,
2010                         readOnly: true
2011                     });
2012                 }
2013             });
2014
2015             $(".toggle_chart_settings").click(function(){
2016                 $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
2017             });
2018
2019             $("#table_reports").delegate(".confirmdelete", 'click', function(){
2020                 $(this).parents('tr').attr("class","warn");
2021                 if(confirm(_("Are you sure you want to delete this saved report?"))){
2022                     return true;
2023                 } else {
2024                     $(this).parents('tr').attr("class","");
2025                     return false;
2026                 }
2027             });
2028
2029             [% IF (create || editsql || save) %]
2030
2031                 var validated_form = $("#sql_report_form").validate({
2032                     reportname: "required",
2033                     group_input: {
2034                         required: {
2035                             depends: function(element) {
2036                                 return $("#create_group").prop("checked") && $("#groupdesc_input").val() != '';
2037                             }
2038                         }
2039                     },
2040                     groupdesc_input: {
2041                         required: {
2042                             depends: function(element) {
2043                                 return $("#create_group").prop("checked") && $("#group_input").val() != '';
2044                             }
2045                         }
2046                     }
2047                 });
2048
2049                 $("#select_group").change(function() {
2050                     if($(this).prop('checked')) {
2051                         $("#group_input").attr("class","").prop('disabled', true).prop("required", false);
2052                         $("#groupdesc_input").attr("class","").prop('disabled', true).prop("required", false);
2053                         $("#group_select").prop('disabled', false);
2054                         clearValidation( $("#sql_report_form") );
2055                         if ($("#group_select").val().length > 0) {
2056                             $("#select_subgroup").prop('checked', true);
2057                             $("#select_subgroup").change();
2058                             $("#subgroup, #subgroup *").show();
2059                         } else {
2060                             $("#subgroup").hide();
2061                         }
2062                     }
2063                 });
2064                 $("#create_group").change(function() {
2065                     if($(this).prop('checked')) {
2066                         $("#group_input").prop('disabled', false).prop("required", true );
2067                         $("#groupdesc_input").prop('disabled', false).prop("required", true );
2068                         $("#group_select").prop('disabled', true);
2069                         // $("#create_subgroup").prop('checked', true).change();
2070                         $("#subgroup_select").hide();
2071                         $("#subgroup input[type='radio']").hide();
2072                         $("#subgroup label[for]").hide();
2073                         $("#subgroup_input").prop("required", false ).prop("disabled", false).show();
2074                         $("#subgroupdesc_input").prop("required", false ).prop("disabled", false).show();
2075                         $("#subgroup").show();
2076                         // Add validation rules for fields which were previously hidden
2077                         $("#subgroup_input").rules("add", {
2078                             required: {
2079                                 depends: function(element) {
2080                                     return $("#create_group").prop("checked") &&  $("#subgroupdesc_input").val() != '';
2081                                 }
2082                             }
2083                         });
2084                         $("#subgroupdesc_input").rules("add", {
2085                             required: {
2086                                 depends: function(element) {
2087                                     return $("#create_group").prop("checked") &&  $("#subgroup_input").val() != '';
2088                                 }
2089                             }
2090                         });
2091                     }
2092                 });
2093                 $("#select_subgroup").change(function() {
2094                     if($(this).prop('checked')) {
2095                         $("#subgroup_select").prop('disabled', false);
2096                         $("#subgroup_input").prop('disabled', true).prop("required", false );
2097                         $("#subgroupdesc_input").prop('disabled', true).prop("required", false );
2098                         clearValidation( $("#sql_report_form") );
2099                     }
2100                 });
2101                 $("#create_subgroup").change(function() {
2102                     if($(this).prop('checked')) {
2103                         $("#subgroup_input").prop('disabled', false).prop("required", true );
2104                         $("#subgroupdesc_input").prop('disabled', false).prop("required", true );
2105                         $("#subgroup_select").val("").prop('disabled', true);
2106                     }
2107                 });
2108                 $("#select_group").change();
2109                 $("#select_subgroup").change();
2110                 $("#group_select").on("change",function(){
2111                     load_group_subgroups();
2112                 });
2113
2114                 $(".insertParam").on("click", function(e){
2115                     e.preventDefault();
2116                     var category = this.id;
2117                     showParamModal( category );
2118                 });
2119
2120                 $("#runtime_parameters").on("shown.bs.modal", function(){
2121                     $("#paramLabel").focus();
2122                 });
2123
2124                 $("#runtime_parameters").on("hide.bs.modal", function(){
2125                     $("#send_runtime_parameter")[0].reset();
2126                     $("#authorised_value_category").val("").hide();
2127                     $("label[for='authorised_value']").removeClass("required");
2128                     $("#authorised_value").prop("required", false ).removeAttr("required").removeClass("required");
2129                 });
2130
2131                 $("#send_runtime_parameter").on("submit", function(e){
2132                     e.preventDefault();
2133                     /* Get form values */
2134                     var paramLabel = $("#paramLabel").val();
2135                     var param_category = $("#param_category").val();
2136                     var categoryLabel = $("#authorised_value").val();
2137                     // Get CodeMirror environment variables
2138                     var selection = editor.getSelection();
2139                     var doc = editor.getDoc();
2140                     var cursor = doc.getCursor();
2141                     var pos = {
2142                         line: cursor.line,
2143                         ch: cursor.ch
2144                     }
2145                     /* Build runtime parameter text string */
2146                     var text = "";
2147                     if( paramLabel && param_category ){
2148                         text += paramLabel + "|" + param_category;
2149                     } else if( paramLabel ) {
2150                         text += paramLabel;
2151                     } else if( param_category ){
2152                         text += param_category;
2153                     }
2154                     if( text != "" ){
2155                         text = " <<" + text + ">> ";
2156                         if( selection.length > 0){
2157                             editor.replaceSelection(text);
2158                         } else {
2159                             doc.replaceRange(text, pos);
2160                         }
2161                     }
2162                     $("#runtime_parameters").modal("hide");
2163                 });
2164
2165                 $("#authorised_value").on("change", function(){
2166                     $("#param_category").val( $(this).val() );
2167                 });
2168
2169             [% END %]
2170
2171             $(".delete").on("click",function(){
2172                 return confirmDelete(MSG_CONFIRM_DELETE);
2173             });
2174
2175             $("#mana_search_form").submit(function(e){
2176                 e.preventDefault();
2177             });
2178
2179             $("#column_submit").submit(function() {
2180                 if ($("#selectedColumns option").size() < 1) {
2181                     alert(_("No columns selected!"));
2182                     return false;
2183                 }
2184                 $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
2185                 return true;
2186             });
2187
2188             // Mana KB
2189             $("body").on("click", ".mana-use", function(e) {
2190                 e.preventDefault();
2191                 $(this).find("i").attr("class","fa fa-refresh fa-spin");
2192                 mana_use( $(this).data("report_id") );
2193             });
2194
2195             $("#mana_search_result").on("shown.bs.modal", function(){
2196                 $("#mana_search_field").focus();
2197             });
2198
2199             $("#mana_search_result").on("hide.bs.modal", function(){
2200                 $("#mana_result_content").html("");
2201                 $("#mana_search_field").val("");
2202             });
2203
2204             $(".batch_op").on("click", function(e){
2205                 e.preventDefault();
2206                 var target_form = $(this).data("submit");
2207                 $("#" + target_form ).submit();
2208             });
2209
2210             $("#batch_add_to_list").on("submit", function(e){
2211                 e.preventDefault();
2212                 addToList();
2213             });
2214
2215             $("body").on("click", ".preview_sql", function(e){
2216                 e.preventDefault();
2217                 var reportid = $(this).data("reportid");
2218                 previewSql( reportid );
2219             });
2220             $(".limitselect").on("click", function(){
2221                 var limit = $(this).data("limit");
2222                 $("#limit").val( limit );
2223                 $("#limitselect").submit();
2224             });
2225
2226         });
2227
2228         $("#toggle_auto_links").on("click", function(e){
2229             e.preventDefault();
2230             if( $(".data-plain").is(":visible") ){
2231                 /* if a data-plain element is visible, this click hides it and shows auto-links */
2232                 localStorage.removeItem("reports_auto_link_off");
2233             } else {
2234                 /* if a data-plain element is hidden, this click shows it  and hides auto-links */
2235                 localStorage.setItem("reports_auto_link_off", 1);
2236             }
2237             $(".data-plain,.autolink").toggle();
2238         });
2239         if ( localStorage.getItem("reports_auto_link_off") == 1 ){
2240             $("#toggle_auto_links").click();
2241         }
2242
2243         function tabsInit( tab, rtable ){
2244             var thisTab = tab; // ui.newTab ? ui.newTab : ui.tab;
2245             var activeTab = thisTab.index();
2246             localStorage.setItem("sql_reports_activetab", activeTab );
2247
2248             $("#subgroup_filter option").each(function() {
2249                 if($(this).val().length > 0) {
2250                     $(this).remove();
2251                 }
2252             });
2253             rtable.fnFilter('', 4);
2254             rtable.fnFilter('', 5);
2255             rtable.fnSetColumnVis(4, true);
2256             rtable.fnSetColumnVis(5, true);
2257
2258             var g_id = $( tab ).children().attr('id');
2259             var g_name = $( tab ).children().text();
2260             if ( g_name == _("All") ) {
2261                 g_id = "";
2262                 g_name = "";
2263             }
2264
2265             if (g_id && g_id.length > 0) {
2266                 rtable.fnFilter('^' + g_name + '$', 4, true, true, true, false);
2267                 rtable.fnSetColumnVis(4, false);
2268                 for(var i in group_subgroups[g_id]) {
2269                     $("#subgroup_filter").append(
2270                         '<option value="' + group_subgroups[g_id][i][0] + '">'
2271                         + group_subgroups[g_id][i][1] + '</option>'
2272                     );
2273                 }
2274                 $("#subgroup_filter_block").show();
2275             } else {
2276                 $("#subgroup_filter_block").hide();
2277             }
2278         }
2279
2280         function addColumn() {
2281             $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
2282         }
2283         function delColumn() {
2284             $("#selectedColumns option:selected").remove();
2285         }
2286
2287         // Mana KB
2288         function mana_use( mana_id ){
2289             $.ajax( {
2290                 type:"POST",
2291                 url: "/cgi-bin/koha/svc/mana/use",
2292                 data: {id:mana_id, resource: 'report', saveinbase: 1},
2293                 dataType: "json",
2294             })
2295             .done( function (result){
2296                 if ( result.errmsg ){
2297                     alert( result.errmsg );
2298                 }
2299                 else{
2300                     window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL&mana_success=1");
2301                 }
2302             })
2303             .fail(function( error ) {
2304                 $(".mana_use_status").hide();
2305                 $("#mana_use_errortext").html( error.status + " " + error.statusText );
2306                 $("#mana_use_failed").show();
2307                 $(".mana-use i").attr("class","fa fa-download");
2308             });
2309         }
2310
2311         function mana_search( textquery ){
2312             $(".mana_search_status").hide();
2313             $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", { resource: 'report', id: textquery, usecomments: 1 }, function( response, status, xhr ) {
2314
2315                     if ( status == "error" ) {
2316                         $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
2317                         $("#mana_search_failed").show();
2318                         $("#mana-loading").hide();
2319                     } else {
2320                         $(".mana_search_status").hide();
2321                         $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2322                         $("#mana-loading").hide();
2323                         $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
2324                             "sPaginationType":"full",
2325                             "autoWidth": false,
2326                             "columnDefs": [
2327                                 { "width": "35%", "targets": 1 }
2328                             ],
2329                             "aoColumnDefs": [
2330                                 { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
2331                                 { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
2332                             ]
2333                         }));
2334
2335                         $(".showbutton").on("click", function(e){
2336                             e.preventDefault();
2337                             $(this).parent().hide();
2338                             $(this).parent().next().show();
2339                         });
2340
2341                         $(".hidebutton").on("click", function(e){
2342                             e.preventDefault();
2343                             $(this).parent().hide();
2344                             $(this).parent().prev().show();
2345                         });
2346
2347                         if($("td.dataTables_empty").length == 0){
2348                             $("#mana_search_message").show();
2349                         }
2350                     }
2351                 });
2352         }
2353
2354         function addToList() {
2355             var biblionumbers = [];
2356             $(".bib_to_list").each(function() {
2357                 var biblionumber = Number( $(this).val() );
2358                 if( biblionumbers.indexOf( biblionumber ) < 0 ){
2359                     biblionumbers.push( biblionumber );
2360                 }
2361             });
2362             bibs = biblionumbers.join("/");
2363             var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
2364             window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
2365             return false;
2366         }
2367
2368         // Adapted from https://gist.github.com/jnormore/7418776
2369         function previewSql(reportid) {
2370             var yes_label = "";
2371             var no_label = "";
2372             var message = $("#previewSql" + reportid ).val();
2373             var title = $("#previewSql" + reportid ).data("title");
2374             if( $("#preview-sql-modal").length > 0) {
2375                 $("#preview-sql-modal").remove();
2376             }
2377             $("body").append('<div id="preview-sql-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal">\
2378                 <div class="modal-dialog">\
2379                     <div class="modal-content">\
2380                         <div class="modal-header" style="min-height:40px;">\
2381                             <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">\
2382                                 <span aria-hidden="true">×</span>\
2383                             </button>\
2384                             <h4 class="modal-title">' + title + '</h4>\
2385                         </div>\
2386                         <div class="modal-body"><textarea id="code' + reportid + '">' + message + '</textarea>\
2387                         </div>\
2388                         <div class="modal-footer">\
2389                             <a id="preview-modal-editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> ' + _("Edit") + '</a>\
2390                             <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=' + reportid + '"><i class="fa fa-copy"></i> ' + _("Duplicate") + '</a>\
2391                             <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=' + reportid + '"><i class="fa fa-clock-o"></i> ' + _("Schedule") + '</a>\
2392                             <a id="preview-modal-delete" class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Delete%20Saved"><i class="fa fa-trash"></i> ' + _("Delete") + '</a>\
2393                             <a id="preview-modal-runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Run%20this%20report"><i class="fa fa-play"></i> ' + _("Run report") + '</a>\
2394                             <a href="#" id="preview-sql-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-remove" aria-hidden="true"></i> ' + _("Close") + '</a>\
2395                         </div>\
2396                     </div>\
2397                 </div>\
2398             </div>');
2399
2400             $("#preview-sql-modal").modal('show');
2401             CodeMirror.fromTextArea( document.getElementById("code" + reportid ), {
2402                 lineNumbers: false,
2403                 mode: "text/x-sql",
2404                 lineWrapping: true,
2405                 readOnly: true
2406             });
2407         }
2408     </script>
2409 [% END %]
2410
2411 [% INCLUDE 'intranet-bottom.inc' %]
2412
2413 [% BLOCK group_and_subgroup_selection %]
2414     <li id="group">
2415         <label>Report group:</label>
2416         <input type="radio" name="select_or_create_group"
2417             id="select_group" checked="checked" />
2418         <label for="select_group" class="radio">Select</label>
2419         <select name="group" id="group_select">
2420             <option value="">(None)</option>
2421             [% FOREACH group IN groups_with_subgroups %]
2422                 [% IF (group.selected) %]
2423                     <option value="[% group.id | html %]" selected="selected">
2424                 [% ELSE %]
2425                     <option value="[% group.id | html %]">
2426                 [% END %]
2427                     [% group.name | html %]
2428                 </option>
2429             [% END %]
2430         </select>
2431         <input type="radio" name="select_or_create_group" id="create_group" />
2432         <label for="create_group" class="radio">or create:</label>
2433         <input type="text" name="group" id="group_input" title="Group code" placeholder="Code" />
2434         <input type="text" name="groupdesc" id="groupdesc_input" title="Group name" placeholder="Name" />
2435     </li>
2436     <li id="subgroup">
2437         <label>Report subgroup:</label>
2438         <input type="radio" name="select_or_create_subgroup"
2439             id="select_subgroup" checked="checked" />
2440         <label for="select_subgroup" style="float:none">Select</label>
2441         <select name="subgroup" id="subgroup_select">
2442             <option value="">(None)</option>
2443             [% FOREACH group IN groups_with_subgroups %]
2444                 [% IF (group.selected) %]
2445                     [% FOREACH subgroup IN group.subgroups %]
2446                         [% IF (subgroup.selected) %]
2447                             <option value="[% subgroup.id | html %]" selected="selected">
2448                         [% ELSE %]
2449                             <option value="[% subgroup.id | html %]">
2450                         [% END %]
2451                             [% subgroup.name | html %]
2452                         </option>
2453                     [% END %]
2454                 [% END %]
2455             [% END %]
2456         </select>
2457         <input type="radio" name="select_or_create_subgroup"
2458             id="create_subgroup" />
2459         <label for="create_subgroup" style="float:none">or create</label>
2460         <input type="text" name="subgroup" id="subgroup_input" title="Subgroup code" placeholder="Code" />
2461         <input type="text" name="subgroupdesc" id="subgroupdesc_input" title="Subgroup name" placeholder="Name" />
2462     </li>
2463 [% END %]
2464
2465 [% BLOCK insert_runtime_parameter %]
2466     <div class="btn-group"  style="margin-left:30px;">
2467         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2468             Insert runtime parameter <span class="caret"></span>
2469         </button>
2470         <ul class="dropdown-menu">
2471             <li><a href="#" class="insertParam" id="insertAuthVal">Authorized values</a></li>
2472             <li><a href="#" class="insertParam" id="insertFramework">Bibliographic framework</a></li>
2473             <li><a href="#" class="insertParam" id="insertCnSource">Classification sources</a></li>
2474             <li><a href="#" class="insertParam" id="insertDate">Date</a></li>
2475             <li><a href="#" class="insertParam" id="insertItemtypes">Item types</a></li>
2476             <li><a href="#" class="insertParam" id="insertBranches">Libraries</a></li>
2477             <li><a href="#" class="insertParam" id="insertList">List</a></li>
2478             <li><a href="#" class="insertParam" id="insertCategorycode">Patron categories</a></li>
2479             <li><a href="#" class="insertParam" id="insertCashregister">Cash registers</a></li>
2480             <li><a href="#" class="insertParam" id="insertDebittypes">Debit types</a></li>
2481             <li><a href="#" class="insertParam" id="insertCredittypes">Credit types</a></li>
2482             <li><a href="#" class="insertParam" id="insertText">Text field</a></li>
2483         </ul>
2484     </div>
2485 [% END %]