From 1e92b9c15e525442bd147c0f44586640c8f38c85 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 2 Aug 2012 16:03:32 +0200 Subject: [PATCH] Bug 9117: Reports hierarchies management improvements - Filter by groups using tabs - Filter by subgroups using a dropdown list under each tab - Allow to create new group and subgroups when building a new report or editing an existing report (no need to go through admin AV interface) + Possibility to duplicate a report (new link in the table) Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Jared Camins-Esakov --- C4/Koha.pm | 21 + .../modules/reports/guided_reports_start.tt | 445 ++++++++++-------- reports/guided_reports.pl | 42 +- 3 files changed, 314 insertions(+), 194 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 4c01309263..13ab94a978 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -63,6 +63,7 @@ BEGIN { &GetAuthorisedValueByCode &GetKohaImageurlFromAuthorisedValues &GetAuthValCode + &AddAuthorisedValue &GetNormalizedUPC &GetNormalizedISBN &GetNormalizedEAN @@ -1226,6 +1227,26 @@ sub GetKohaAuthorisedValueLib { return $value; } +=head2 AddAuthorisedValue + + AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac); + +Create a new authorised value. + +=cut + +sub AddAuthorisedValue { + my ($category, $authorised_value, $lib, $lib_opac) = @_; + + my $dbh = C4::Context->dbh; + my $query = qq{ + INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) + VALUES (?,?,?,?) + }; + my $sth = $dbh->prepare($query); + $sth->execute($category, $authorised_value, $lib, $lib_opac); +} + =head2 display_marc_indicators my $display_form = C4::Koha::display_marc_indicators($field); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index e1f4593e7d..e2a5a19177 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -32,25 +32,98 @@ dt_add_type_uk_date(); [% END %] var group_subgroups = {}; -var no_subgroup_label = _( "(None)" ); +[% 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").val(); + var group = $("#group_select").val(); var sg = $("#subgroup"); - var has_subgroups = false; - $(sg).empty().append(''); + $(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) { - has_subgroups = true; - $('').appendTo(sg); + $('').appendTo(select); } ); - } - if (has_subgroups) { - $(sg).show(); - } else { - $(sg).hide(); + $("#subgroup, #subgroup *").show(); } } + $(document).ready(function(){ + +[% IF (saved1) %] + [% IF (dateformat == "metric") %] + dt_add_type_uk_date(); + [% END %] + var rtable = $("#table_reports").dataTable($.extend(true, {}, dataTablesDefaults, { + 'bAutoWidth': false, + 'sDom': 't<"bottom pager"ilpf>', + 'sPaginationType': 'four_button', + 'aLengthMenu': [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]], + 'iDisplayLength': 20, + 'aaSorting': [[ 1, "asc" ]], + 'aoColumnDefs': [ + { 'bSortable': false, 'bSearchable':false, 'aTargets': [-1, -2, -3, -4] }, + { 'bSearchable': false, 'aTargets': [3, 4] } + ], + 'oLanguage': { + 'sZeroRecords': _('No matching reports found') + } + })); + + var rtabs = $("#tabs").tabs(); + rtabs.bind("tabsshow", function(e, ui) { + $("#subgroup_filter option").each(function() { + if($(this).val().length > 0) { + $(this).remove(); + } + }); + rtable.fnFilter('', 3); + rtable.fnFilter('', 4); + rtable.fnSetColumnVis(3, true); + rtable.fnSetColumnVis(4, true); + + var g_id = $(ui.tab).attr('id') + var g_name = $(ui.tab).text(); + if (g_id && g_id.length > 0) { + rtable.fnFilter(g_name, 3); + rtable.fnSetColumnVis(3, false); + for(var i in group_subgroups[g_id]) { + $("#subgroup_filter").append( + '' + ); + } + $("#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, 4); + rtable.fnSetColumnVis(4, false); + } else { + rtable.fnFilter('', 4); + rtable.fnSetColumnVis(4, true); + } + }); +[% END %] + [% IF ( showsql ) %] $("#sql").focus(function() { $(this).select(); @@ -66,20 +139,57 @@ $(document).ready(function(){ return false; } }); - // call the datatables plugin - $("#table_reports").dataTable($.extend(true, {}, dataTablesDefaults, { - "aoColumnDefs": [ - { "aTargets": [ -1, -2, -3, -4 ], "bSortable": false, "bSearchable": false }, - ], - "aaSorting": [[ 1, "asc" ]], - "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]], - "iDisplayLength": 20, - "sPaginationType": "four_button" - })); [% END %] // redefine the datepicker's default because reports require ISO // http://jqueryui.com/demos/datepicker/#option-dateFormat $( ".datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" ); + +[% IF (create || editsql || save) %] + $("#select_group").change(function() { + if($(this).attr('checked')) { + $("#group_input").attr('disabled', 'disabled'); + $("#groupdesc_input").attr('disabled', 'disabled'); + $("#group_select").attr('disabled', false); + if ($("#group_select").val().length > 0) { + $("#select_subgroup").attr('checked', 'checked'); + $("#select_subgroup").change(); + $("#subgroup, #subgroup *").show(); + } else { + $("#subgroup").hide(); + } + } + }); + $("#create_group").change(function() { + if($(this).attr('checked')) { + $("#group_input").attr('disabled', false); + $("#groupdesc_input").attr('disabled', false); + $("#group_select").attr('disabled', 'disabled'); + $("#create_subgroup").attr('checked', 'checked').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).attr('checked')) { + $("#subgroup_select").attr('disabled', false); + $("#subgroup_input").attr('disabled', 'disabled'); + $("#subgroupdesc_input").attr('disabled', 'disabled'); + } + }); + $("#create_subgroup").change(function() { + if($(this).attr('checked')) { + $("#subgroup_input").attr('disabled', false); + $("#subgroupdesc_input").attr('disabled', false); + $("#subgroup_select").attr('disabled', 'disabled'); + } + }); + $("#select_group").change(); + $("#select_subgroup").change(); +[% END %] }); //]]> @@ -149,61 +259,78 @@ canned reports and writing custom SQL reports.

[% IF ( saved1 ) %] [% IF ( savedreports ) %]

Saved reports

- - - - - - - - - - - - - - [% IF (usecache) %] [% END %] - - - - - - - -[% FOREACH savedreport IN savedreports %] -[% UNLESS ( loop.odd ) %][% ELSE %][% END %] - - - - - - - - - -[% IF (savedreport.public) %] - -[% ELSE %] - -[% END %] -[% IF (usecache) %] [% END %] - - - - [% IF ( CAN_user_reports_create_reports ) %] - - [% END %] - -[% END %] - -
IDReport nameTypeAreaGroupSubgroupNotesAuthorCreation datePublicCache expiry (seconds)Saved resultsSaved SQL  
[% savedreport.id %][% savedreport.report_name %][% savedreport.type %][% savedreport.areaname %][% savedreport.groupname %][% savedreport.subgroupname %][% savedreport.notes %][% savedreport.borrowersurname %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname %][% END %] ([% savedreport.borrowernumber %])[% savedreport.date_created %]YesNo[% savedreport.cache_expiry %][% IF ( savedreport.date_run ) %][% savedreport.date_run %][% END %] - - Show - [% IF ( CAN_user_reports_create_reports ) %] -   Edit +
+
Run -ScheduleDelete
+ +
+
+ + +
+ + + + + + + + + + + + + [% IF (usecache) %] [% END %] + + + + + + + + [% FOREACH savedreport IN savedreports %] + [% UNLESS ( loop.odd ) %][% ELSE %][% END %] + + + + + + + + + [% IF (savedreport.public) %] + + [% ELSE %] + + [% END %] + [% IF (usecache) %] [% END %] + + + + [% IF ( CAN_user_reports_create_reports ) %] + + [% END %] + + [% END %] + +
IDReport nameTypeGroupSubgroupNotesAuthorCreation datePublicCache expiry (seconds)Saved resultsSaved SQL  
[% savedreport.id %][% savedreport.report_name %][% savedreport.type %][% savedreport.groupname %][% savedreport.subgroupname %][% savedreport.notes %][% savedreport.borrowersurname %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname %][% END %] ([% savedreport.borrowernumber %])[% savedreport.date_created %]YesNo[% savedreport.cache_expiry %][% IF ( savedreport.date_run ) %][% savedreport.date_run %][% END %] + + Show + [% IF ( CAN_user_reports_create_reports ) %] + Edit + Duplicate + [% END %] + + Run + Schedule + Delete
+
+ [% ELSE %]
[% IF (filter_set) %]

No saved reports match your criteria.

@@ -515,31 +642,7 @@ canned reports and writing custom SQL reports.

Save your custom report
  1. - [% IF groups_with_subgroups %] -
  2. -
  3. - [% END %] + [% PROCESS group_and_subgroup_selection %]
@@ -635,31 +738,8 @@ $(document).ready(function() { [% IF ( reportname ) %] [% ELSE %][% END %] - [% IF groups_with_subgroups %] -
  • -
  • - [% END %] + [% PROCESS group_and_subgroup_selection %] + [% IF (public) %]
  • [% ELSE %] @@ -744,11 +824,6 @@ Sub report: @@ -756,31 +831,7 @@ $(document).ready(function() { Edit SQL report
    1. - [% IF groups_with_subgroups %] -
    2. -
    3. - [% END %] +[% PROCESS group_and_subgroup_selection %] [% IF (public) %]
    4. [% ELSE %] @@ -848,43 +899,12 @@ $(document).ready(function() { [% IF ( saved1 ) %]
      -

      Filter

        -
      1. - - -
      2. [% INCLUDE 'date-format.inc' %]
        @@ -920,3 +940,56 @@ $("#column_submit").submit(function() { //]]> [% INCLUDE 'intranet-bottom.inc' %] + + +[% BLOCK group_and_subgroup_selection %] +
      3. + + + + + + + + +
      4. +
      5. + + + + + + + + +
      6. +[% END %] diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 23d85a9e2c..0171cb46a0 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -17,8 +17,6 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; use CGI; use Text::CSV; @@ -106,6 +104,7 @@ elsif ( $phase eq 'Build new' ) { 'savedreports' => get_saved_reports($filter), 'usecache' => $usecache, 'groups_with_subgroups'=> groups_with_subgroups($group, $subgroup), + dateformat => C4::Context->preference('dateformat'), ); } @@ -178,6 +177,8 @@ elsif ( $phase eq 'Update SQL'){ push @errors, {cache_expiry => $cache_expiry}; } + create_non_existing_group_and_subgroup($input, $group, $subgroup); + if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { push @errors, {sqlerr => $1}; } @@ -482,6 +483,9 @@ elsif ( $phase eq 'Save Report' ) { if( $cache_expiry && $cache_expiry >= 2592000 ){ push @errors, {cache_expiry => $cache_expiry}; } + + create_non_existing_group_and_subgroup($input, $group, $subgroup); + ## FIXME this is AFTER entering a name to save the report under if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { push @errors, {sqlerr => $1}; @@ -735,9 +739,9 @@ elsif ( $phase eq 'Create report from SQL' ) { $group = $input->param('report_group'); $subgroup = $input->param('report_subgroup'); $template->param( - 'sql' => $input->param('sql'), - 'reportname' => $input->param('reportname'), - 'notes' => $input->param('notes'), + 'sql' => $input->param('sql') // '', + 'reportname' => $input->param('reportname') // '', + 'notes' => $input->param('notes') // '', ); } $template->param( @@ -790,13 +794,17 @@ sub groups_with_subgroups { my $groups_with_subgroups = get_report_groups(); my @g_sg; - while (my ($g_id, $v) = each %$groups_with_subgroups) { + my @sorted_keys = sort { + $groups_with_subgroups->{$a}->{name} cmp $groups_with_subgroups->{$b}->{name} + } keys %$groups_with_subgroups; + foreach my $g_id (@sorted_keys) { + my $v = $groups_with_subgroups->{$g_id}; my @subgroups; if (my $sg = $v->{subgroups}) { - while (my ($sg_id, $n) = each %$sg) { + foreach my $sg_id (sort { $sg->{$a} cmp $sg->{$b} } keys %$sg) { push @subgroups, { id => $sg_id, - name => $n, + name => $sg->{$sg_id}, selected => ($group && $g_id eq $group && $subgroup && $sg_id eq $subgroup ), }; } @@ -810,3 +818,21 @@ sub groups_with_subgroups { } return \@g_sg; } + +sub create_non_existing_group_and_subgroup { + my ($input, $group, $subgroup) = @_; + + if (defined $group and $group ne '') { + my $report_groups = C4::Reports::Guided::get_report_groups; + if (not exists $report_groups->{$group}) { + my $groupdesc = $input->param('groupdesc') // $group; + C4::Koha::AddAuthorisedValue('REPORT_GROUP', $group, $groupdesc); + } + if (defined $subgroup and $subgroup ne '') { + if (not exists $report_groups->{$group}->{subgroups}->{$subgroup}) { + my $subgroupdesc = $input->param('subgroupdesc') // $subgroup; + C4::Koha::AddAuthorisedValue('REPORT_SUBGROUP', $subgroup, $subgroupdesc, $group); + } + } + } +} -- 2.39.5