Koha/reports/dictionary.pl
Srdjan 42acfbf75b Bug 7993: Save reports with Group/Subgroup hierarchy
This should make saved reports more manageable.
Group/Subgroup hierarchy is stored in authorised_values,
categories REPORT_GROUP and REPORT_SUBGROUP, connected by
REPORT_SUBGROUP.lib_opac -> REPORT_GROUP.authorised_value

Database changes:
* authorised_values: expanded category to 16 chars
* created default set of REPORT_GROUP authorised values to match
  hardcoded report areas
* reports_dictionary: replaced area int with report_area text, converted
  values
* saved_sql: added report_area, report_group and report_subgroup;
  report_area is not currently used, saved for the record

C4/Reports/Guided.pm:
* Replaced Area numeric values with the mnemonic codes
* get_report_areas(): returns hardcoded areas list
* created get_report_areas(): returns full hierarchy (groups with belonging
  subgroups)
* save_report(): changed iterface, accepts fields hashref as input
* update_sql(): changed iterface, accepts id and fields hashref as input
* get_saved_reports():]
- join to authorised_values to pick group and subgroup name
- accept group and subgroup filter params
* get_saved_report():
- changed iterface, return record hashref
- join to authorised_values to pick group and subgroup name
* build_authorised_value_list(): new sub, moved code from
  reports/guided_reports.pl
* Updated interfaces in:
cronjobs/runreport.pl, svc/report, opac/svc/report: get_saved_report()
reports/dictionary.pl: get_report_areas()
reports/guided_reports.pl

reports/guided_reports_start.tt:
* Reports list:
- added group/subgroup filter
- display area/group/subgroup for the reports
* Create report wizard:
- carry area to the end
- select group and subgroup when saving the report; group defaults to area,
  useful when report groups match areas
* Update report and Create from SQL: added group/subgroup
* Amended reports/guided_reports.pl accordingly

Conflicts:

    C4/Reports/Guided.pm
    admin/authorised_values.pl
    installer/data/mysql/kohastructure.sql
    installer/data/mysql/updatedatabase.pl
    koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl
    koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
    misc/cronjobs/runreport.pl
    reports/dictionary.pl
    reports/guided_reports.pl

Signed-off-by: Delaye Stephane <stephane.delaye@biblibre.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
2012-09-18 17:49:08 +02:00

222 lines
7.1 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2007 Liblime ltd
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use strict;
use warnings;
use C4::Auth;
use CGI;
use C4::Output;
use C4::Reports::Guided;
use C4::Dates;
=head1 NAME
Script to control the guided report creation
=head1 DESCRIPTION
=cut
my $input = new CGI;
my $referer = $input->referer();
my $phase = $input->param('phase') || 'View Dictionary';
my $definition_name = $input->param('definition_name');
my $definition_description = $input->param('definition_description');
my $area = $input->param('area') || '';
my $no_html = 0; # this will be set if we dont want to print out an html::template
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{ template_name => "reports/dictionary.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { reports => '*' },
debug => 1,
}
);
if ($phase eq 'View Dictionary'){
# view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town
my $definitions = get_from_dictionary($area);
$template->param(
'areas'=> areas(),
'start_dictionary' => 1,
'definitions' => $definitions,
);
} elsif ( $phase eq 'Add New Definition' ) {
# display form allowing them to add a new definition
$template->param( 'new_dictionary' => 1, );
}
elsif ( $phase eq 'New Term step 2' ) {
# Choosing the area
$template->param(
'step_2' => 1,
'areas' => areas(),
'definition_name' => $definition_name,
'definition_description' => $definition_description,
);
}
elsif ( $phase eq 'New Term step 3' ) {
# Choosing the columns
my $columns = get_columns( $area, $input );
$template->param(
'step_3' => 1,
'area' => $area,
'columns' => $columns,
'definition_name' => $definition_name,
'definition_description' => $definition_description,
);
}
elsif ( $phase eq 'New Term step 4' ) {
# Choosing the values
my @columns = $input->param('columns');
my $columnstring = join( ',', @columns );
my @column_loop;
foreach my $column (@columns) {
my %tmp_hash;
$tmp_hash{'name'} = $column;
my $type = get_column_type($column);
if ( $type eq 'distinct' ) {
my $values = get_distinct_values($column);
$tmp_hash{'values'} = $values;
$tmp_hash{'distinct'} = 1;
}
if ( $type eq 'DATE' || $type eq 'DATETIME' ) {
$tmp_hash{'date'} = 1;
}
if ( $type eq 'TEXT' ) {
$tmp_hash{'text'} = 1;
}
# else {
# warn $type;#
# }
push @column_loop, \%tmp_hash;
}
$template->param( 'step_4' => 1,
'area' => $area,
'definition_name' => $definition_name,
'definition_description' => $definition_description,
'columns' => \@column_loop,
'columnstring' => $columnstring,
'DHTMLcalendar_dateformat' => C4::Dates->DHTMLcalendar(),
);
}
elsif ( $phase eq 'New Term step 5' ) {
# Confirmation screen
my $columnstring = $input->param('columnstring');
my @criteria = $input->param('criteria_column');
my $query_criteria;
my @criteria_loop;
foreach my $crit (@criteria) {
my $value = $input->param( $crit . "_value" );
if ($value) {
my %tmp_hash;
$tmp_hash{'name'} = $crit;
$tmp_hash{'value'} = $value;
push @criteria_loop, \%tmp_hash;
if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
my $date = C4::Dates->new($value);
$value = $date->output("iso");
}
$query_criteria .= " AND $crit='$value'";
}
$value = $input->param( $crit . "_start_value" );
if ($value) {
my %tmp_hash;
$tmp_hash{'name'} = "$crit Start";
$tmp_hash{'value'} = $value;
push @criteria_loop, \%tmp_hash;
if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
my $date = C4::Dates->new($value);
$value = $date->output("iso");
}
$query_criteria .= " AND $crit >= '$value'";
}
$value = $input->param( $crit . "_end_value" );
if ($value) {
my %tmp_hash;
$tmp_hash{'name'} = "$crit End";
$tmp_hash{'value'} = $value;
push @criteria_loop, \%tmp_hash;
if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
my $date = C4::Dates->new($value);
$value = $date->output("iso");
}
$query_criteria .= " AND $crit <= '$value'";
}
}
my %report_areas = map @$_, get_report_areas();
$template->param(
'step_5' => 1,
'area' => $area,
'areaname' => $report_areas{$area},
'definition_name' => $definition_name,
'definition_description' => $definition_description,
'query' => $query_criteria,
'columnstring' => $columnstring,
'criteria_loop' => \@criteria_loop,
);
}
elsif ( $phase eq 'New Term step 6' ) {
# Saving
my $area = $input->param('area');
my $sql = $input->param('sql');
save_dictionary( $definition_name, $definition_description, $sql, $area );
$no_html = 1;
print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
} elsif ( $phase eq 'Delete Definition' ) {
$no_html = 1;
my $id = $input->param('id');
delete_definition($id);
print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
}
$template->param( 'referer' => $referer );
if (!$no_html){
output_html_with_http_headers $input, $cookie, $template->output;
}
sub areas {
my $areas = get_report_areas();
my @a;
foreach (@$areas) {
push @a, {
id => $_->[0],
name => $_->[1],
selected => ($_->[0] eq $area),
};
}
return \@a;
}