Bug 20350: Add column configuration to table of saved reports
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / reports / guided_reports_start.tt
index 7f109d9..7f5d368 100644 (file)
@@ -1,87 +1,59 @@
+[% USE KohaDates %]
+[% USE Koha %]
+[% USE ColumnsSettings %]
+[% SET footerjs = 1 %]
+[%- BLOCK area_name -%]
+    [%- SWITCH area -%]
+        [%- CASE 'CIRC' -%]Circulation
+        [%- CASE 'CAT'  -%]Catalog
+        [%- CASE 'PAT'  -%]Patrons
+        [%- CASE 'ACQ'  -%]Acquisitions
+        [%- CASE 'ACC'  -%]Accounts
+        [%- CASE 'SER'  -%]Serials
+    [%- END -%]
+[%- END -%]
+
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Reports &rsaquo; Guided reports wizard
-[% IF ( saved1 ) %]&rsaquo; Saved Reports
-[% ELSIF ( create ) %]&rsaquo; Create from SQL
-[% ELSIF ( showsql ) %]&rsaquo; Saved reports &rsaquo; SQL view
-[% ELSIF ( execute ) %]&rsaquo; Saved reports &rsaquo; [% name %] Report
-[% ELSIF ( buildx ) %]&rsaquo; Build a report, step [% buildx %] of 6:
-[% IF ( build1 ) %]Choose a module
-[% ELSIF ( build2 ) %]Pick a report type
-[% ELSIF ( build3 ) %]Select columns for display
-[% ELSIF ( build4 ) %]Select criteria to limit on
-[% ELSIF ( build5 ) %]Pick which columns to total
-[% ELSIF ( build6 ) %]Select how you want the report ordered
-[% END %]
-[% END %]
-</title>
+
+<title>Koha &rsaquo; Reports &rsaquo; Guided reports wizard [%- IF ( saved1 ) -%]&rsaquo; Saved reports
+[%- ELSIF ( create ) -%]&rsaquo; Create from SQL
+[%- ELSIF ( showsql ) -%]&rsaquo; Saved reports &rsaquo; SQL view
+[%- ELSIF ( execute ) -%]&rsaquo; Saved reports &rsaquo; [% name %] Report
+[%- ELSIF ( editsql ) -%]&rsaquo; Saved reports &rsaquo; Edit SQL report
+[%- END -%]
+[%- IF ( build1 ) -%]&rsaquo; Build a report, step 1 of 6: Choose a module
+[%- ELSIF ( build2 ) -%]&rsaquo; Build a report, step 2 of 6: Pick a report type
+[%- ELSIF ( build3 ) -%]&rsaquo; Build a report, step 3 of 6: Select columns for display
+[%- ELSIF ( build4 ) -%]&rsaquo; Build a report, step 4 of 6: Select criteria to limit on
+[%- ELSIF ( build5 ) -%]&rsaquo; Build a report, step 5 of 6: Pick which columns to total
+[%- ELSIF ( build6 ) -%]&rsaquo; Build a report, step 6 of 6: Select how you want the report ordered
+[%- END -%]</title>
+
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <style type="text/css">
     #sql { width: 90%; height: 9em;}
-</style>
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.pager.js"></script>
-
-<script type="text/javascript">
-//<![CDATA[
-var group_subgroups = {};
-var no_subgroup_label = _( "(None)" );
-function load_group_subgroups () {
-    var group = $("#group").val();
-    var sg = $("#subgroup");
-    var has_subgroups = false;
-    $(sg).empty().append('<option value="">' + no_subgroup_label + '</option>');
-    if (group) {
-        $.each( group_subgroups[group], function(index, value) {
-                has_subgroups = true;
-            $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(sg);
-        } );
+    #update_sql .modal-dialog { width: 80%; }
+    ins { background-color: #e6ffe6; }
+    del { background-color: #ffe6e6; }
+    #col1, #col2 { width:45%; float:left; }
+    #col1 ins, #col2 del { display: none; }
+    .show_sql { font-family: monospace; }
+    .send_to_item_mod {
+        background-color: #EBF3FF;
+        border: 1px solid #88b0e8;
+        border-radius: 5px;
+        display: inline-block;
+        font-size: 75%;
+        margin: 3px 5px;
+        padding: 3px 5px;
+        white-space: nowrap;
     }
-    if (has_subgroups) {
-        $(sg).show();
-    } else {
-        $(sg).hide();
-    }
-}
-$(document).ready(function(){
-[% IF ( showsql ) %]
-    $("#sql").focus(function() {
-        $(this).select();
-    });
-[% END %]
+</style>
 [% IF ( saved1 ) %]
-    $(".confirmdelete").click(function(){
-        $(this).parents('tr').attr("class","warn");
-        if(confirm("Are you sure you want to "+$(this).attr("title")+"?")){
-            return true;
-        } else {
-            $(this).parents('tr').attr("class","");
-            return false;
-        }
-    });
-[% END %]
-  // call the tablesorter plugin
-  $("#table_reports").tablesorter({
-    widgets : ['zebra'],
-    sortList: [[1,0]],
-    headers: {
-        10: { sorter: false},
-        11: { sorter: false},
-        12: { sorter: false},
-        13: { sorter: false}
-    }
-  }).tablesorterPager({
-    container:     $("#pagertable_reports"),
-    positionFixed: false,
-    size:          20
-  });
-  // redefine the datepicker's default because reports require ISO
-  // http://jqueryui.com/demos/datepicker/#option-dateFormat
-  $( ".datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
-});
-//]]>
-</script>
+    <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
+[% END %]
 </head>
+
 <body id="rep_guided_reports_start" class="rep">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'circ-search.inc' %]
@@ -89,22 +61,41 @@ $(document).ready(function(){
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
 &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
 &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
-&rsaquo; 
-[% IF ( saved1 ) %]Saved reports
-[% ELSIF ( create ) %]Create from SQL
-[% ELSIF ( showsql ) %]<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; SQL view
-[% ELSIF ( execute ) %]<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <em>[% name %]</em> Report
-[% ELSIF ( buildx ) %]<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a> &rsaquo; Step [% buildx %] of 6:
-    [% IF ( build1 ) %]Choose a module
-    [% ELSIF ( build2 ) %]Pick a report type
-    [% ELSIF ( build3 ) %]Select columns for display
-    [% ELSIF ( build4 ) %]Select criteria to limit on
-    [% ELSIF ( build5 ) %]Pick which columns to total
-    [% ELSIF ( build6 ) %]Select how you want the report ordered
+
+[% IF ( saved1 ) %]&rsaquo; Saved reports
+[% ELSIF ( create ) %]&rsaquo; Create from SQL
+[% ELSIF ( showsql ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; SQL view
+[% ELSIF ( editsql ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; Edit SQL report
+[% ELSIF ( execute ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <em>[% name %]</em> Report
+[% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]&rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
+    [% IF ( build1 ) %]&rsaquo; Step 1 of 6: Choose a module
+    [% ELSIF ( build2 ) %]&rsaquo; Step 2 of 6: Pick a report type
+    [% ELSIF ( build3 ) %]&rsaquo; Step 3 of 6: Select columns for display
+    [% ELSIF ( build4 ) %]&rsaquo; Step 4 of 6: Select criteria to limit on
+    [% ELSIF ( build5 ) %]&rsaquo; Step 5 of 6: Pick which columns to total
+    [% ELSIF ( build6 ) %]&rsaquo; Step 6 of 6: Select how you want the report ordered
     [% END %]
 [% END %]
 </div>
 
+<div id="update_sql" class="modal" tabindex="-1" role="dialog" aria-labelledby="update_sql_label" aria-hidden="true">
+    <div class="modal-dialog">
+    <div class="modal-content">
+    <div class="modal-header">
+        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
+        <h3 id="update_sql_label">Update SQL</h3>
+    </div>
+    <div class="modal-body">
+        <div id="loading"> <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" /> Loading </div>
+    </div>
+    <div class="modal-footer">
+        <a href="#" class="btn btn-default" id="update_sql_button" role="button" data-toggle="modal">Update</a>
+        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
+    </div>
+    </div>
+    </div>
+</div>
+
 <div id="doc3" class="yui-t1">
 <div id="bd">
 <div id="yui-main">
@@ -144,82 +135,160 @@ canned reports and writing custom SQL reports.</p>
 </form>
 [% END %]
 
+[% IF report_converted %]
+    <div class="dialog message">
+        The report "[% report_converted %]" has been converted.
+    </div>
+[% END %]
+
 [% IF ( saved1 ) %]
 [% IF ( savedreports ) %]<h1>Saved reports</h1>
 
-<div id="pagertable_reports">
-[% INCLUDE 'table-pager.inc' perpage='20' %]
-</div>
-
-<table id="table_reports" class="tablesorter">
-<thead>
- <tr>
-  <th>ID</th>
-  <th>Report name</th>
-  <th>Type</th>
-  <th>Area</th>
-  <th>Group</th>
-  <th>Subgroup</th>
-  <th>Notes</th>
-  <th>Author</th>
-  <th>Creation date</th>
-  <th>Public</th>
-  [% IF (usecache) %] <th>Cache expiry (seconds)</th> [% END %]
-  <th>Saved results</th>
-  <th>Saved SQL</th>
-  <th>&nbsp;</th>
-  <th>&nbsp;</th>
- </tr>
-</thead>
-<tbody>
-[% FOREACH savedreport IN savedreports %]
-[% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
-<td>[% savedreport.id %]</td>
-<td>[% savedreport.report_name %]</td>
-<td>[% savedreport.type %]</td>
-<td>[% savedreport.areaname %]</td>
-<td>[% savedreport.groupname %]</td>
-<td>[% savedreport.subgroupname %]</td>
-<td>[% savedreport.notes %]</td>
-<td>[% savedreport.borrowersurname %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname %][% END %] ([% savedreport.borrowernumber %])</td>
-<td>[% savedreport.date_created %]</td>
-[% IF (savedreport.public) %]
-<td>Yes</td>
-[% ELSE %]
-<td>No</td>
-[% END %]
-[% IF (usecache) %] <td>[% savedreport.cache_expiry %]</td> [% END %]
-<td>[% IF ( savedreport.date_run ) %]<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% savedreport.id %]">[% savedreport.date_run %]</a>[% END %]
-</td>
-    <td>
-        <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Show%20SQL">Show</a> 
-        [% IF ( CAN_user_reports_create_reports ) %]
-            &nbsp; <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Edit%20SQL">Edit</a>
+<div id="tabs" class="toptabs">
+    <ul>
+        <li><a href="#reports">All</a></li>
+        [% FOREACH group IN groups_with_subgroups %]
+            <li><a id="[% group.id %]" href="#reports">[% group.name %]</a></li>
         [% END %]
-    </td>
-<td><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Run%20this%20report">Run</a>
-<a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id %]">Schedule</a></td>
-    [% IF ( CAN_user_reports_create_reports ) %]
-        <td><a class="confirmdelete" title="Delete this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Delete%20Saved">Delete</a></td>
-    [% END %]
-</tr>
-[% END %]
-</tbody>
-</table>
+    </ul>
+    <div id="reports">
+        <div id="subgroup_filter_block">
+            <label for="subgroup_filter">Subgroup:</label>
+            <select id="subgroup_filter">
+                <option value="">All</option>
+            </select>
+        </div>
+<form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post">
+<input type="hidden" name="phase" value="Delete Multiple" />
+        <table id="table_reports">
+            <thead>
+                <tr>
+                    <th>&nbsp;</th>
+                    <th>ID</th>
+                    <th>Report name</th>
+                    <th>Type</th>
+                    <th>Group</th>
+                    <th>Subgroup</th>
+                    <th>Notes</th>
+                    <th>Author</th>
+                    <th class="title-string">Creation date</th>
+                    <th class="title-string">Last edit</th>
+                    <th class="title-string">Last run</th>
+                    <th class="report_public">Public</th>
+                    <th class="report_json_url">JSON URL</th>
+                    [% IF (usecache) %] <th>Cache expiry (seconds)</th> [% END %]
+                    <th>Saved results</th>
+                    [% IF has_obsolete_reports %]<th>Update</th>[% END %]
+                    <th>Actions</th>
+                </tr>
+            </thead>
+            <tbody>
+                [% FOREACH savedreport IN savedreports %]
+                    [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
+                        <td>
+                            [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS -->
+                                <input type="checkbox" name="ids" value="[% savedreport.id %]" />
+                            [% END %]
+                        </td>
+                        <td><label for="ids">[% savedreport.id %]</label></td>
+                        <td>
+                            [% IF ( savedreport.report_name ) %]
+                                [% savedreport.report_name %]
+                            [% ELSE %]
+                                [ no name ]
+                            [% END %]
+                        </td>
+                        <td>[% savedreport.type %]</td>
+                        <td>[% savedreport.groupname %]</td>
+                        <td>[% savedreport.subgroupname %]</td>
+                        <td>[% savedreport.notes %]</td>
+                        <td>[% savedreport.borrowersurname %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname %][% END %] ([% savedreport.borrowernumber %])</td>
+                        <td><span title="[% savedreport.date_created %]">[% savedreport.date_created | $KohaDates %]</span></td>
+                        <td><span title="[% savedreport.last_modified %]">[% savedreport.last_modified | $KohaDates with_hours => 1 %]</span></td>
+                        <td><span title="[% savedreport.last_run %]">[% savedreport.last_run | $KohaDates with_hours => 1 %]</span></td>
+                        <td class="report_public">
+                        [% IF (savedreport.public) %]
+                            Yes
+                        [% ELSE %]
+                            No
+                        [% END %]
+                        </td>
+                        <td class="report_json_url">
+                        [% IF (savedreport.public) %]
+                            <a href="[% OPACBaseURL %]/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% OPACBaseURL %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
+                        [% ELSE %]
+                            <a href="/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% Koha.Preference('staffClientBaseURL') %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
+                        [% END %]
+                        </td>
+                        [% IF (usecache) %] <td>[% savedreport.cache_expiry %]</td> [% END %]
+                        <td>
+                            [% FOR result IN savedreport.results %]
+                                <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% result.id %]">[% result.date_run %]</a>
+                                <br/>
+                            [% END %]
+                        </td>
+                        [% IF has_obsolete_reports %]
+                        <td>
+                            [% IF savedreport.seems_obsolete %]
+                                This report seems obsolete, it uses biblioitems.marcxml field.
+                                <a href="/cgi-bin/koha/svc/convert_report?report_id=[% savedreport.id %]" data-report_id="[% savedreport.id %]" class="update_sql btn btn-default btn-xs" title="Update SQL"><i class="fa fa-eye"></i> Update SQL</a>
+                            [% END %]
+                        </td>
+                        [% END %]
+                        <td>
+                            <div class="dropup">
+                                <div class="btn-group">
+                                    [%# There should be no space between these two buttons, it would render badly %]
+                                    <a class="btn btn-default btn-xs" role="button"
+                                       href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Run%20this%20report"><i
+                                       class="fa fa-play"></i> Run</a><a
+                                       class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id %]" role="button" data-toggle="dropdown"
+                                       href="#"><b class="caret"></b></a>
+                                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id %]">
+                                        <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> Show</a></li>
+                                        [% IF ( CAN_user_reports_create_reports ) %]
+                                            <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a></li>
+                                            <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from SQL&amp;sql=[% savedreport.savedsql |uri %]&amp;reportname=[% savedreport.report_name |uri %]&amp;notes=[% savedreport.notes |uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
+                                        [% END %]
+                                        <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id %]"><i class="fa fa-clock-o"></i> Schedule</a></li>
+                                        [% IF ( CAN_user_reports_delete_reports ) %]
+                                            <li><a class="confirmdelete" title="Delete this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id %]&amp;phase=Delete%20Saved"><i class="fa fa-trash"></i> Delete</a></li>
+                                        [% END %]
+                                    </ul>
+                                </div>
+                            </div>
+                        </td>
+                    </tr>
+                [% END %]
+            </tbody>
+        </table>
+        [% IF ( CAN_user_reports_delete_reports ) %]
+        <fieldset class="action">
+            <input type="submit" value="Delete selected" />
+        </fieldset>
+        [% END %]
+    </form>
+    </div>
+</div>
 [% ELSE %]<div class="dialog message">
-    [% IF (filter_set) %]
+    [% IF (filter_set || filters.date || filters.author || filters.keyword) %]
     <h4>No saved reports match your criteria. </h4>
     [% IF ( CAN_user_reports_create_reports ) %]
     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
     <input type="hidden" name="phase" value="Build new" />
-    <input type="submit" class="edit" value="Build a new report" accesskey="y" />
+        <button type="submit" class="new"><i class="fa fa-plus"></i> New guided report</button>
+    </form>
+
+    <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
+        <input type="hidden" name="phase" value="Create report from SQL" />
+        <button type="submit" class="new"><i class="fa fa-plus"></i> New SQL report</button>
     </form>
 
     <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
     <input type="hidden" name="phase" value="Use saved" />
     <input type="hidden" name="filter_set" value="1" />
     <input type="hidden" name="filter_keyword" value="" />
-    <input type="submit" class="deny" value="Cancel filter" accesskey="n" />
+        <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> Cancel filter</button>
     </form>
 
     [% END %]
@@ -243,16 +312,20 @@ canned reports and writing custom SQL reports.</p>
 <h1>Build a report</h1>
 <form action="/cgi-bin/koha/reports/guided_reports.pl">
 <fieldset class="rows">
-<legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and Choose report visibility </legend>
-<ol><li><label for="area">Choose: </label><select name="area" id="area">
-[% FOREACH area IN areas %]
-<option value="[% area.id %]">[% area.name %]</option>
-[% END %]
-</select></li>
+<legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend>
+<ol>
+  <li>
+    <label for="area">Choose: </label>
+      <select name="area" id="area">
+    [%- FOREACH area IN areas -%]
+      <option value="[% area %]">[%- PROCESS area_name area=area -%]</option>
+    [%- END -%]
+      </select>
+  </li>
 [% IF (public) %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
 [% ELSE %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
 [% END %]
 [% IF (usecache) %] <li>
 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
@@ -264,7 +337,7 @@ canned reports and writing custom SQL reports.</p>
 </select>
 </li>[% END %]
 </ol>
-<ofieldset>
+</fieldset>
 <fieldset class="action">
 <input type="hidden" name="phase" value="Report on this Area" />
 <input type="submit" name="submit" value="Next &gt;&gt;" />
@@ -275,7 +348,7 @@ canned reports and writing custom SQL reports.</p>
 
 
 [% IF ( build2 ) %]
-<h1>Build A Report</h1>
+<h1>Build a report</h1>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <input type="hidden" name="area" value="[% area %]" />
 <input type="hidden" name="public" value="[% public %]" />
@@ -291,7 +364,7 @@ canned reports and writing custom SQL reports.</p>
 
 <fieldset class="action">
     <input type="hidden" name="phase" value="Choose this type" />
-    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
     <input type="submit" name="submit" value="Next &gt;&gt;" />
 </fieldset>
 </form>
@@ -300,13 +373,14 @@ canned reports and writing custom SQL reports.</p>
 
 <!--- Summary and Matrix reports have not yet been implemented-->
 <!--<div class="yui-u">Summary:
-<img src="/intranet-tmpl/prog/img/reports-summary-graphic.gif" /></div>
+<img src="[% interface %]/[% theme %]/img/reports-summary-graphic.gif" /></div>
 <div class="yui-u">Matrix:
-<img src="/intranet-tmpl/prog/img/reports-matrix-graphic.gif" /></div>-->
+<img src="[% interface %]/[% theme %]/img/reports-matrix-graphic.gif" /></div>-->
 
 [% END %]
 
 [% IF ( build3 ) %]
+<h1>Build a report</h1>
 <h3>Step 3 of 6: Select columns for display</h3>
 <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>
 
@@ -338,8 +412,8 @@ canned reports and writing custom SQL reports.</p>
 [% END %]
 </optgroup>
 </select></div>
-<div style="width: 6.3em; float: right; margin-top: 100px"><input type="button" name="Add" value="Add" class="button" style="width:6em;" onclick="addColumn()" /><br />
-<input type="button" name="delete" value="&lt;&lt; Delete" class="button" style="width: 6em; margin: 1em 0;" onclick="delColumn()" /></div>
+<div style="width: 6.3em; float: right; margin-top: 100px"><input type="button" name="Add" value="Add" class="button" style="width:6em;" id="addColumn" /><br />
+<input type="button" name="delete" value="&lt;&lt; Delete" class="button" style="width: 6em; margin: 1em 0;" id="delColumn" /></div>
 </div>
 
 <div class="yui-u">
@@ -350,7 +424,7 @@ canned reports and writing custom SQL reports.</p>
 <div class="yui-g">
 <fieldset class="action">
     <input type="hidden" name="phase" value="Choose these columns" />
-    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
     <input type="submit" name="submit" value="Next &gt;&gt;" />
 </fieldset>
 </div>
@@ -359,6 +433,7 @@ canned reports and writing custom SQL reports.</p>
 [% END %]
 
 [% IF ( build4 ) %]
+<h1>Build a report</h1>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" >
     <input type="hidden" name="area" value="[% area %]" />
     <input type="hidden" name="type" value="[% type %]" />
@@ -399,7 +474,7 @@ canned reports and writing custom SQL reports.</p>
             <td>
                 <select name="[% criteri.name %]_value">
                 [% FOREACH value IN criteri.values %]
-                <option value="[% value.availablevalues %]">[% IF ( value.default ) %]Default[% ELSE %][% value.availablevalues |html %][% END %]</option>
+                <option value="[% value.availablevalues %]">[% IF ( value.default ) %]Default[% ELSE %][% value.display_value |html %][% END %]</option>
                 [% END %]
                 </select>
             </td>
@@ -412,21 +487,24 @@ canned reports and writing custom SQL reports.</p>
     </fieldset>
 
 [% IF ( definitions ) %]
-<fieldset><legend>Dictionary definitions</legend><table>
+<fieldset><legend>Dictionary definitions</legend>
+<table>
 [% FOREACH definition IN definitions %]
     <tr><td><input type="checkbox" name="definition" value="[% definition.id %]" /> [% definition.name %]</td></tr>
 [% END %]
 </table>
+</fieldset>
 [% END %]
 
 <fieldset class="action"><input type="hidden" name="phase" value="Choose these criteria" />
-    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
     <input type="submit" name="submit" value="Next &gt;&gt;" /> </fieldset>
 </form>
 [% END %]
 
 
 [% IF ( build5 ) %]
+<h1>Build a report</h1>
 <h3>Step 5 of 6: Pick which columns to total</h3>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <input type="hidden" name="area" value="[% area %]" />
@@ -451,13 +529,14 @@ canned reports and writing custom SQL reports.</p>
 </table></fieldset>
 
 <fieldset class="action"><input type="hidden" name="phase" value="Choose these operations" />
-    <input type="button" name="back" value="&lt;&lt; Back" onclick="javascript:history.back()" />
+    <input type="button" name="back" value="&lt;&lt; Back" class="goback" />
     <input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
 </form>
 [% END %]
 
 
 [% IF ( build6 ) %]
+<h1>Build a report</h1>
 <h3>Step 6 of 6: Choose how you want the report ordered</h3>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <input type="hidden" name="area" value="[% area %]" />
@@ -507,7 +586,7 @@ canned reports and writing custom SQL reports.</p>
 [% END %]
 
 [% IF ( save ) %]
-<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
+<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
 <input type="hidden" name="sql" value="[% sql |html %]" />
 <input type="hidden" name="type" value="[% type %]" />
 <input type="hidden" name="area" value="[% area %]" />
@@ -516,76 +595,114 @@ canned reports and writing custom SQL reports.</p>
 <fieldset class="rows">
 <legend>Save your custom report</legend>
 <ol>
-    <li><label for="reportname">Report name: </label><input type="text" id="reportname" name="reportname" /></li>
-    [% IF groups_with_subgroups %]
-    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
-        [% FOR g IN groups_with_subgroups %]
-            [% IF g.selected %]
-    <option value="[% g.id %]" selected>[% g.name %]</option>
-            [% ELSE %]
-    <option value="[% g.id %]">[% g.name %]</option>
-            [% END %]
-    <script type="text/javascript">
-        var g_sg = new Array();
-            [% FOR sg IN g.subgroups %]
-        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
-                [% IF sg.selected %]
-        $(document).ready(function() {
-            $("#subgroup").val("[% sg.id %]");
-        });
-                [% END %]
-            [% END %]
-        group_subgroups["[% g.id %]"] = g_sg;
-    </script>
-        [% END %]
-    </select></li>
-    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
-    </select></li>
-    [% END %]
+    <li><label for="reportname" class="required">Report name: </label><input type="text" id="reportname" name="reportname" class="required" required="required" /> <span class="required">Required</span></li>
+    [% PROCESS group_and_subgroup_selection %]
     <li><label for="notes">Notes:</label> <textarea name="notes" id="notes"></textarea></li>
 </ol></fieldset>
 <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
-<input type="submit" name="submit" value="Save Report" /></fieldset>
+<input type="submit" name="submit" value="Save report" /></fieldset>
 </form>
 [% END %]
 
+[% IF ( warn_authval_problem ) %]
+    <div class="dialog alert">
+        <h3>Errors found when processing parameters for report: [% name %]</h3>
+        [% FOREACH problematic_authval IN problematic_authvals %]
+            <p>
+            <strong>[% problematic_authval.name %]:</strong> The authorized value category (<strong>[% problematic_authval.authval %]</strong>)
+                you selected does not exist.
+            </p>
+        [% END %]
+        <!-- Save Anyway Form -->
+        <form action='/cgi-bin/koha/reports/guided_reports.pl'>
+        <!--Every parameter the user issued is provided as a hidden field for recovery-->
+            <input type='hidden' name='id' value='[% id %]' />
+            <input type='hidden' name='sql' value='[% sql %]' />
+            <input type='hidden' name='reportname' value='[% reportname %]' />
+            <input type='hidden' name='group' value='[% group %]' />
+            <input type='hidden' name='subgroup' value='[% subgroup %]' />
+            <input type='hidden' name='notes' value='[% notes %]' />
+            <input type='hidden' name='cache_expiry' value='[% cache_expiry %]' />
+            <input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units %]' />
+            <input type='hidden' name='public' value='[% public %]' />
+        [% IF ( phase_update) %]
+            <input type='hidden' name='phase' value='Update SQL' />
+            <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
+        [% ELSIF ( phase_save) %]
+            <input type='hidden' name='area' value='[% area %]' />
+            <input type='hidden' name='phase' value='Save Report' />
+            <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
+        [% END %]
+        </form>
+        <!-- Go back to editing -->
+        <form action='/cgi-bin/koha/reports/guided_reports.pl'>
+            <button type="button" class="new goback"><i class="fa fa-fw fa-pencil"></i> Edit SQL</button>
+        </form>
+    </div>
+[% END %]
+
 [% IF ( enter_params ) %]
     <form action='/cgi-bin/koha/reports/guided_reports.pl'>
-        <input type='hidden' name='phase' value='Run this report' />
         <input type='hidden' name='reports' value="[% reports %]" />
+    [% IF ( auth_val_error ) %]
+        <input type='hidden' name='phase' value='Edit SQL' />
+        <div class="dialog alert">
+            <h3>Errors found when processing parameters for report: [% name %]</h3>
+            [% FOREACH auth_val_error IN auth_val_errors %]
+                <p>
+                    <strong>[% auth_val_error.entry %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val %]</strong>)
+                    you selected does not exist.
+                </p>
+            [% END %]
+        </div>
+        <fieldset class="action"><input type="submit" value="Edit SQL" /></fieldset>
+    [% ELSE %]
+        <input type='hidden' name='phase' value='Run this report' />
         <h1>Enter parameters for report [% name %]:</h1>
         [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
         <fieldset class="rows">
             <ol>
-        [% FOREACH sql_param IN sql_params %]
-            [% IF sql_param.input == 'date' %]
-                <li>
-                <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
-                </li>
-            [% ELSIF ( sql_param.input == 'text' ) %]
-                <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li>
-            [% ELSE %]
-                <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li>
+            [% FOREACH sql_param IN sql_params %]
+                [% IF sql_param.input == 'date' %]
+                    <li>
+                    <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
+                    </li>
+                [% ELSIF ( sql_param.input == 'text' ) %]
+                    <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li>
+                [% ELSE %]
+                    <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label>
+                        <select name="[%- sql_param.input.name -%]" tabindex="1"  size="1" id="[%- sql_param.input.id -%]">
+                        [% FOREACH value IN sql_param.input.values %]
+                            <option value="[%- value -%]">[%- sql_param.input.labels.$value -%]</option>
+                        [% END %]
+                        </select>
+                    </li>
+                [% END %]
             [% END %]
-        [% END %]
             </ol>
         </fieldset>
         <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
+    [% END %]
     </form>
 [% END %]
 
 [% IF ( execute ) %]
 <h1>[% name %]</h1>
-[% IF ( notes ) %]<p>[% notes %]</p>[% END %]
-[% IF ( unlimited_total ) %]<p>Total number of rows matching the (unlimited) query is [% unlimited_total %].</p>[% END %]
-<pre id="sql_output">[% sql |html %]</pre>
+[% IF ( notes ) %]<p><span class="label">Notes:</span> [% notes %]</p>[% END %]
+[% IF ( unlimited_total ) %]<p><span class="label">Total number of results:</span> [% unlimited_total %][% IF unlimited_total > limit %] ([% limit %] shown)[% END %].</p>[% END %]
+<div id="sql_output" style="display:none;"><span class="label">Report SQL:</span><pre>[% sql |html %]</pre></div>
+</br>
 
-<form>
+<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect">
     <input type="hidden" name="phase" value="Run this report"/>
     <input type="hidden" name="reports" value="[% report_id %]"/>
 
+    [% FOREACH p IN sql_params %]
+        <input type="hidden" name="sql_params" value="[% p %]"/>
+    [% END %]
+
     <label for="limit">Rows per page: </label>
-    <select name="limit">
+    <select name="limit" id="limit">
         [% limits = [ 10, 20, 50, 100, 200, 300, 400, 500, 1000 ] %]
         [% FOREACH l IN limits %]
                 [% IF l == limit %]
@@ -595,31 +712,37 @@ canned reports and writing custom SQL reports.</p>
                 [% END %]
         [% END %]
     </select>
-
-    <input type="submit" value="Update" />
 </form>
 
 <div class="pages">[% pagination_bar %]</div>
 [% UNLESS ( errors ) %]
-<table>
-<tr>[% FOREACH header_ro IN header_row %]<th>[% header_ro.cell %]</th>[% END %]</tr>
-[% FOREACH result IN results %]
-<tr>
-    [% FOREACH cell IN result.cells %]<td>[% cell.cell %]</td>[% END %]
-</tr>
-[% END %]
-</table>
-<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
-<fieldset class="action">
-<label for="format">Download the report: </label>
-<select name="format" id="format">
-<option value="csv">Comma separated text</option>
-<option value="tab">Tab separated text</option>
-</select>
-<input type="hidden" name="sql" value="[% sql |html %]" />
-<input type="hidden" name="phase" value="Export" />
-<input type="submit" name="submit" value="Download" /></fieldset>
-</form>
+    <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="report_results">
+        <input type="hidden" name="op" value="show" />
+        <table>
+            <tr>
+                [% FOREACH header_ro IN header_row %]
+                    [% IF header_ro.cell == 'itemnumber' %]
+                        <th>
+                            [% header_ro.cell %] <button type="submit" data-toggle="tooltip" title="Send visible items to batch modification" class="btn btn-xs btn-default send_to_item_mod"><i class="fa fa-pencil"></i> Batch modify</button>
+                        </th>
+                    [% ELSE %]
+                        <th>[% header_ro.cell %]</th>
+                    [% END %]
+                [% END %]
+            </tr>
+            [% FOREACH result IN results %]
+                <tr>
+                    [% FOREACH cells IN result.cells %]
+                        [% place = loop.index %]
+                        [% IF header_row.$place.cell == 'itemnumber' %]
+                            <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
+                        [% END %]
+                        <td>[% cells.cell %]</td>
+                    [% END %]
+                </tr>
+            [% END %]
+        </table>
+    </form>
 [% END %]
 [% END %]
 
@@ -629,43 +752,20 @@ $(document).ready(function() {
     load_group_subgroups();
 });
 </script>
-<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
+<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
 <fieldset class="rows">
 <legend>Create report from SQL</legend>
 <ol>
-    <li><label for="reportname">Report name:</label>
-        [% IF ( reportname ) %]<input type="text" id="reportname" name="reportname" value="[% reportname %]" />
-        [% ELSE %]<input type="text" id="reportname" name="reportname" />[% END %] 
+    <li><label for="reportname" class="required">Report name:</label>
+        [% IF ( reportname ) %]<input type="text" class="required" required="required" id="reportname" name="reportname" value="[% reportname | html %]" size="50"/>
+        [% ELSE %]<input type="text" class="required" required="required" id="reportname" name="reportname" size="50" />[% END %] <span class="required">Required</span>
     </li>
-    [% IF groups_with_subgroups %]
-    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
-        [% FOR g IN groups_with_subgroups %]
-            [% IF g.selected %]
-    <option value="[% g.id %]" selected>[% g.name %]</option>
-            [% ELSE %]
-    <option value="[% g.id %]">[% g.name %]</option>
-            [% END %]
-    <script type="text/javascript">
-        var g_sg = new Array();
-            [% FOR sg IN g.subgroups %]
-        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
-                [% IF sg.selected %]
-        $(document).ready(function() {
-            $("#subgroup").val("[% sg.id %]");
-        });
-                [% END %]
-            [% END %]
-        group_subgroups["[% g.id %]"] = g_sg;
-    </script>
-        [% END %]
-    </select></li>
-    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
-    </select></li>
-    [% END %]
+    [% PROCESS group_and_subgroup_selection %]
+
 [% IF (public) %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
 [% ELSE %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
 [% END %]
 [% IF (usecache) %] <li>
 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
@@ -677,24 +777,17 @@ $(document).ready(function() {
 </select>
 </li>[% END %]
     <li><label for="notes">Notes:</label> <textarea id="notes" name="notes" cols="50" rows="2">[% notes %]</textarea></li>
-    <li><label for="types">Type:</label>
-        <select id="types" name="types">
-            <option value="1">Tabular</option>
-            <option value="2" disabled="disabled">Summary</option>
-            <option value="3" disabled="disabled">Matrix</option>
-        </select>
-    </li>
 </ol>
 </fieldset>
 <fieldset class="rows">
 <legend>SQL:</legend>
 <div style="margin:1em;">
-<textarea  id="sql" name="sql" cols="50" rows="10">[% sql %]</textarea>
+<textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql %]</textarea> <span class="required">Required</span>
 </div>
 </fieldset>
 
 <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
-<input type="submit" name="submit" value="Save Report" /> <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
+<input type="submit" name="submit" value="Save report" /> <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
 </fieldset>
 </form>
 [% END %]
@@ -724,13 +817,17 @@ Sub report:<select name="subreport">
 [% END %]
 
 
-[% IF ( retresults ) %]
+[% IF saved_results %]
 <h1>Saved report results</h1>
 <h2>[% name %]</h2>
 <p>[% notes %]</p>
 <table>
-[% FOREACH result IN results %]
-[% result.row %]
+[% FOREACH rows IN saved_results %]
+<tr>
+[% FOREACH col IN rows %]
+<td>[% col %]</td>
+[% END %]
+<tr>
 [% END %]
 </table>
 [% END %]
@@ -745,48 +842,30 @@ Sub report:<select name="subreport">
 </fieldset>
 [% END %]
 
+[% IF ( save_successful ) %]
+[% UNLESS ( errors ) %]
+</br>
+<div id="report_updated">
+    <div class="dialog message">
+        <p>Your report "[% reportname %]" has been saved</p>
+    </div>
+</div>
+[% END %]
+[% END %]
+
 [% IF ( editsql ) %]
-<script type="text/javascript">
-$(document).ready(function() {
-    load_group_subgroups();
-});
-</script>
-<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
+<form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" class="validated">
 <input type="hidden" name="phase" value="Update SQL" />
 <input type="hidden" name="id" value="[% id %]"/>
 <fieldset class="rows">
 <legend>Edit SQL report</legend>
 <ol>
-<li><label for="reportname">Report name:</label><input type="text" id="reportname" name="reportname" value="[% reportname %]" size="50" /></li>
-    [% IF groups_with_subgroups %]
-    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
-        [% FOR g IN groups_with_subgroups %]
-            [% IF g.selected %]
-    <option value="[% g.id %]" selected>[% g.name %]</option>
-            [% ELSE %]
-    <option value="[% g.id %]">[% g.name %]</option>
-            [% END %]
-    <script type="text/javascript">
-        var g_sg = new Array();
-            [% FOR sg IN g.subgroups %]
-        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
-                [% IF sg.selected %]
-        $(document).ready(function() {
-            $("#subgroup").val("[% sg.id %]");
-        });
-                [% END %]
-            [% END %]
-        group_subgroups["[% g.id %]"] = g_sg;
-    </script>
-        [% END %]
-    </select></li>
-    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
-    </select></li>
-    [% END %]
+<li><label for="reportname" class="required">Report name: </label><input type="text" id="reportname" name="reportname" value="[% reportname | html %]" size="50" class="required" required="required" /> <span class="required">Required</span></li>
+[% PROCESS group_and_subgroup_selection %]
 [% IF (public) %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
 [% ELSE %]
-  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selelcted">No (default)</option> <option value="1">Yes</public> </select></li>
+  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
 [% END %]
 [% IF (usecache) %] <li>
 <label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
@@ -798,10 +877,16 @@ $(document).ready(function() {
 </select>
 </li>[% END %]
 <li><label for="notes">Notes:</label><textarea id="notes" name="notes" cols="50" rows="2">[% notes %]</textarea></li>
-<li><textarea id="sql" name="sql" rows="10" cols="60">[% sql %]</textarea></li>
 </ol>
 </fieldset>
 
+<fieldset class="rows">
+    <legend>SQL:</legend>
+    <div style="margin:1em;">
+        <textarea id="sql" name="sql" class="required" required="required" cols="50" rows="10">[% sql %]</textarea> <span class="required">Required</span>
+    </div>
+</fieldset>
+
 <fieldset class="action">
 <input type="submit" name="submit" value="Update SQL" /> <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a>
 </fieldset>
@@ -810,21 +895,6 @@ $(document).ready(function() {
 
 [% END %]
 
-[% IF ( save_successful ) %]
-[% UNLESS ( errors ) %]
-<h2>Your report has been saved</h2>
-<h4>[% reportname %]</h4>
-<ul>
-    [% IF ( id ) %]
-    <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id %]&amp;phase=Run%20this%20report">Run this report</a></li>
-    [% END %]
-    <li>Access this report from the: <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports page</a></li>
-    <li>Schedule this report to run using the: <a href="/cgi-bin/koha/tools/scheduler.pl">Scheduler tool</a></li>
-    <li>Return to: <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Guided reports</a></li>
-</ul>
-[% END %]
-[% END %]
-
 [% IF ( errors ) %]
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <div class="dialog alert">
@@ -837,6 +907,9 @@ $(document).ready(function() {
     [% ELSIF ( error.cache_expiry ) %]Please select a cache expiry less than 30 days.
     [% ELSE %]
     [% END %]
+    <div id="onerror_actions">
+        <a href="#" class="button goback">Return to previous page</a>
+    </div>
 [% END %]
 </div>
 <fieldset class="action"><input type="hidden" name="phase" value="Use saved" />
@@ -850,51 +923,24 @@ $(document).ready(function() {
 
 [% IF ( saved1 ) %]
 <div id="saved-reports-filter">
-<script type="text/javascript">
-$(document).ready(function() {
-    no_subgroup_label = _( "-- All --" );
-    load_group_subgroups();
-});
-</script>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
   <input type="hidden" name="phase" value="Use saved" />
   <input type="hidden" name="filter_set" value="1" />
   <fieldset class="brief">
   <h3>Filter</h3>
   <ol>
-    <li><label for="group">Choose Group and Subgroup: </label>
-    <select name="group" id="group" onChange="load_group_subgroups();">
-        <option value="">-- All --</option>
-    [% FOR g IN groups_with_subgroups %]
-        [% IF g.selected %]
-        <option value="[% g.id %]" selected>[% g.name %]</option>
-        [% ELSE %]
-        <option value="[% g.id %]">[% g.name %]</option>
-        [% END %]
-        <script type="text/javascript">
-            var g_sg = new Array();
-        [% FOR sg IN g.subgroups %]
-            g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
-            [% IF sg.selected %]
-            $(document).ready(function() {
-                $("#subgroup").val("[% sg.id %]");
-            });
-            [% END %]
-        [% END %]
-            group_subgroups["[% g.id %]"] = g_sg;
-        </script>
-    [% END %]
-    </select>
-    <select name="subgroup" id="subgroup"></select>
-    </li>
-    <li><label for="filter_date">Date:</label> <input type="text" id="filter_date" name="filter_date" size="10" value="[% filter_date %]" class="datepicker" />
+    <li><label for="filter_date">Date:</label> <input type="text" id="filter_date" name="filter_date" size="10" value="[% filters.date %]" class="datepicker" />
     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
 
     </li>
-    <li><label for="filter_author">Author:</label> <input type="text" id="filter_author" name="filter_author" value="[% filter_author %]" /></li>
-    <li><label for="filter_keyword">Keyword:</label> <input type="text" id="filter_keyword" name="filter_keyword" value="[% filter_keyword %]" /></li>
+    <li><label for="filter_author">Author:</label> <input type="text" id="filter_author" name="filter_author" value="[% filters.author %]" size="16" /></li>
+    <li><label for="filter_keyword">Keyword:</label> <input type="text" id="filter_keyword" name="filter_keyword" value="[% filters.keyword %]" size="16" /></li>
   </ol>
-  <fieldset class="action"><input type="submit" value="Apply filter" /></fieldset>
+  </fieldset>
+  <fieldset class="action">
+    <input type="submit" value="Apply filter" />
+    <a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1">Clear</a>
+  </fieldset>
 </form>
 </div>
 [% END %]
@@ -903,22 +949,311 @@ $(document).ready(function() {
 [% INCLUDE 'guided-reports-view.inc' %]
 </div>
 </div>
-<script type="text/javascript">
-//<![CDATA[
-function addColumn() {
-    $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
-}
-function delColumn() {
-    $("#selectedColumns option:selected").remove();
-}
-$("#column_submit").submit(function() {
-    if ($("#selectedColumns option").size() < 1) {
-        alert(_("No columns selected!"));
-        return false;
-    }
-    $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
-    return true;
-});
-//]]>
-</script>
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    [% IF ( saved1 ) %]
+        [% INCLUDE 'datatables.inc' %]
+        [% INCLUDE 'columns_settings.inc' %]
+    [% END %]
+    <script>
+        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
+        var group_subgroups = {};
+        [% FOREACH group IN groups_with_subgroups %]
+            var gid = "[% group.id %]"
+            group_subgroups[gid] = new Array();
+            [% FOREACH subgroup IN group.subgroups %]
+                var sgid = "[% subgroup.id %]";
+                var sgname = "[% subgroup.name %]";
+                group_subgroups[gid].push([sgid, sgname]);
+            [% END %]
+        [% END %]
+
+        function load_group_subgroups () {
+            var group = $("#group_select").val();
+            var sg = $("#subgroup");
+            $(sg).find('option[value!=""]').each(function() {
+                $(this).remove();
+            });
+            $(sg).hide();
+            if (group) {
+                var select = $(sg).find('select')[0];
+                $.each( group_subgroups[group], function(index, value) {
+                    $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(select);
+                } );
+                $("#subgroup, #subgroup *").show();
+            }
+        }
+
+        $(document).ready(function(){
+
+            $('[data-toggle="tooltip"]').tooltip();
+            var columns_settings = [% ColumnsSettings.GetColumns( 'reports', 'saved-sql', 'table_reports', 'json' ) %];
+
+            $('#limit').change(function() {
+                $('#limitselect').submit();
+            });
+
+            $(document).click(function() {
+                $('#report_updated').hide();
+            });
+
+            $(".goback").on("click",function(e){
+                e.preventDefault();
+                window.history.back();
+            });
+
+            $("#addColumn").on("click",function(){
+                addColumn();
+            });
+
+            $("#delColumn").on("click",function(){
+                delColumn();
+            });
+
+            [% IF (saved1) %]
+                var rtable = KohaTable("table_reports", {
+                    'iDisplayLength': [% Koha.Preference('NumSavedReports') %],
+                    'bAutoWidth': false,
+                    'sPaginationType': 'four_button',
+                    'aaSorting': [[ 1, "asc" ]],
+                    'aoColumnDefs': [
+                        { 'bSortable': false, 'bSearchable':false, 'aTargets': [0, -1] },
+                        { 'bSearchable': false, 'aTargets': [3] },
+                        { "aTargets": [ 1, 2 ], "sType": "natural"  },
+                        { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                    ],
+                    'oLanguage': {
+                        'sZeroRecords': _("No matching reports found")
+                    },
+                }, columns_settings);
+
+                var rtabs = $("#tabs").tabs();
+                rtabs.on("tabsactivate", function(e, ui) {
+                    $("#subgroup_filter option").each(function() {
+                        if($(this).val().length > 0) {
+                            $(this).remove();
+                        }
+                    });
+                    rtable.fnFilter('', 4);
+                    rtable.fnFilter('', 5);
+                    rtable.fnSetColumnVis(4, true);
+                    rtable.fnSetColumnVis(5, true);
+
+                    var g_id = $(ui.newTab).children().attr('id');
+                    var g_name = $(ui.newTab).text();
+                    if ( g_name == _("All") ) {
+                        g_id = "";
+                        g_name = "";
+                    }
+
+                    if (g_id && g_id.length > 0) {
+                        rtable.fnFilter('^' + g_name + '$', 4, true, true, true, false);
+                        rtable.fnSetColumnVis(4, false);
+                        for(var i in group_subgroups[g_id]) {
+                            $("#subgroup_filter").append(
+                                '<option value="' + group_subgroups[g_id][i][0] + '">'
+                                + group_subgroups[g_id][i][1] + '</option>'
+                            );
+                        }
+                        $("#subgroup_filter_block").show();
+                    } else {
+                        $("#subgroup_filter_block").hide();
+                    }
+                });
+                $("#subgroup_filter_block").hide();
+
+                $("#subgroup_filter").change(function() {
+                    var selected = $(this).find('option:selected');
+                    var sg_id = $(selected).val();
+                    var sg_name = $(selected).text();
+                    if (sg_id.length > 0) {
+                        rtable.fnFilter('^' + sg_name + '$', 5, true, true, true, false);
+                        rtable.fnSetColumnVis(5, false);
+                    } else {
+                        rtable.fnFilter('', 5);
+                        rtable.fnSetColumnVis(5, true);
+                    }
+                });
+
+                $("#reports_form").submit(function(){
+                    var checkedItems = $("input[name=ids]:checked");
+                    if ($(checkedItems).size() == 0) {
+                        alert(_("You must select one or more reports to delete"));
+                        return false;
+                    }
+                    $(checkedItems).parents('tr').addClass("warn");
+                    if( confirm(_("Are you sure you want to delete the selected reports?")) ) {
+                        return true;
+                    } else {
+                        $(checkedItems).parents('tr').removeClass("warn");
+                        return false;
+                    }
+                });
+
+                $("body").on("click", ".update_sql", function(e){
+                    e.preventDefault();
+                    var ltitle = $(this).text();
+                    var report_id = $(this).data("report_id");
+                    var page = $(this).attr("href");
+                    $("#update_sql .modal-body").load(page + " div", function(){
+                        var diff1 = $("#col1 .show_sql").text();
+                        var diff2 = $("#col2 .show_sql").text();
+                        var diffs = diffString( escape(diff1), escape(diff2) );
+                        $("#col1 .show_sql,#col2 .show_sql").html(diffs);
+                    });
+                    $('#update_sql').modal('show');
+                    $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id);
+                });
+
+                $("#update_sql").on("hidden.bs.modal", function(){
+                    $("#update_sql_label").html("");
+                    $("#update_sql .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
+                });
+            [% END %]
+
+            [% IF ( showsql ) %]
+                $("#sql").focus(function() {
+                    $(this).select();
+                });
+            [% END %]
+
+                $(".toggle_sql").click(function(){
+                    $("#sql_output").toggle();
+                    $("#toggle_sql_hid").toggle();
+                    $("#toggle_sql_vis").toggle();
+                });
+
+                $("#table_reports").delegate(".confirmdelete", 'click', function(){
+                    $(this).parents('tr').attr("class","warn");
+                    if(confirm(_("Are you sure you want to delete this saved report?"))){
+                        return true;
+                    } else {
+                        $(this).parents('tr').attr("class","");
+                        return false;
+                    }
+                });
+
+            [% IF (create || editsql || save) %]
+                $("#select_group").change(function() {
+                    if($(this).prop('checked')) {
+                        $("#group_input").prop('disabled', true);
+                        $("#groupdesc_input").prop('disabled', true);
+                        $("#group_select").prop('disabled', false);
+                        if ($("#group_select").val().length > 0) {
+                            $("#select_subgroup").prop('checked', true);
+                            $("#select_subgroup").change();
+                            $("#subgroup, #subgroup *").show();
+                        } else {
+                            $("#subgroup").hide();
+                        }
+                    }
+                });
+                $("#create_group").change(function() {
+                    if($(this).prop('checked')) {
+                        $("#group_input").prop('disabled', false);
+                        $("#groupdesc_input").prop('disabled', false);
+                        $("#group_select").prop('disabled', true);
+                        $("#create_subgroup").prop('checked', true).change();
+                        $("#subgroup_select").hide();
+                        $("#subgroup input[type='radio']").hide();
+                        $("#subgroup label[for]").hide();
+                        $("#subgroup_input").show();
+                        $("#subgroupdesc_input").show();
+                        $("#subgroup").show();
+                    }
+                });
+                $("#select_subgroup").change(function() {
+                    if($(this).prop('checked')) {
+                        $("#subgroup_select").prop('disabled', false);
+                        $("#subgroup_input").prop('disabled', true);
+                        $("#subgroupdesc_input").prop('disabled', true);
+                    }
+                });
+                $("#create_subgroup").change(function() {
+                    if($(this).prop('checked')) {
+                        $("#subgroup_input").prop('disabled', false);
+                        $("#subgroupdesc_input").prop('disabled', false);
+                        $("#subgroup_select").prop('disabled', true);
+                    }
+                });
+                $("#select_group").change();
+                $("#select_subgroup").change();
+                $("#group_select").on("change",function(){
+                    load_group_subgroups();
+                });
+            [% END %]
+            $(".delete").on("click",function(){
+                return confirmDelete(MSG_CONFIRM_DELETE);
+            });
+        });
+        function addColumn() {
+            $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected");
+        }
+        function delColumn() {
+            $("#selectedColumns option:selected").remove();
+        }
+        $("#column_submit").submit(function() {
+            if ($("#selectedColumns option").size() < 1) {
+                alert(_("No columns selected!"));
+                return false;
+            }
+            $("#selectedColumns option").attr("selected", "selected");  // Select everything still in #selectedColumns
+            return true;
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
+
+[% BLOCK group_and_subgroup_selection %]
+    <li id="group">
+        <label>Report group:</label>
+        <input type="radio" name="select_or_create_group"
+            id="select_group" checked="checked" />
+        <label for="select_group" style="float:none">Select</label>
+        <select name="group" id="group_select">
+            <option value="">(None)</option>
+            [% FOREACH group IN groups_with_subgroups %]
+                [% IF (group.selected) %]
+                    <option value="[% group.id %]" selected="selected">
+                [% ELSE %]
+                    <option value="[% group.id %]">
+                [% END %]
+                    [% group.name %]
+                </option>
+            [% END %]
+        </select>
+        <input type="radio" name="select_or_create_group" id="create_group" />
+        <label for="create_group" style="float:none">or create:</label>
+        <input type="text" name="group" id="group_input" title="Group code" placeholder="Code" />
+        <input type="text" name="groupdesc" id="groupdesc_input" title="Group name" placeholder="Name" />
+    </li>
+    <li id="subgroup">
+        <label>Report subgroup:</label>
+        <input type="radio" name="select_or_create_subgroup"
+            id="select_subgroup" checked="checked" />
+        <label for="select_subgroup" style="float:none">Select</label>
+        <select name="subgroup" id="subgroup_select">
+            <option value="">(None)</option>
+            [% FOREACH group IN groups_with_subgroups %]
+                [% IF (group.selected) %]
+                    [% FOREACH subgroup IN group.subgroups %]
+                        [% IF (subgroup.selected) %]
+                            <option value="[% subgroup.id %]" selected="selected">
+                        [% ELSE %]
+                            <option value="[% subgroup.id %]">
+                        [% END %]
+                            [% subgroup.name %]
+                        </option>
+                    [% END %]
+                [% END %]
+            [% END %]
+        </select>
+        <input type="radio" name="select_or_create_subgroup"
+            id="create_subgroup" />
+        <label for="create_subgroup" style="float:none">or create</label>
+        <input type="text" name="subgroup" id="subgroup_input" title="Subgroup code" placeholder="Code" />
+        <input type="text" name="subgroupdesc" id="subgroupdesc_input" title="Subgroup name" placeholder="Name" />
+    </li>
+[% END %]