From d758212ac6c555f0a7bc17dd667b45ea3f830f55 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 29 Oct 2007 13:21:40 -0500 Subject: [PATCH] Splitting reports dictionary out into its own script. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- .../prog/en/modules/reports/dictionary.tmpl | 14 +- .../modules/reports/guided_reports_start.tmpl | 4 +- reports/dictionary.pl | 203 +++++++++++++++++ reports/guided_reports.pl | 205 ------------------ 4 files changed, 213 insertions(+), 213 deletions(-) create mode 100755 reports/dictionary.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl index b36568f916..56917396d0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl @@ -22,7 +22,7 @@

Use the dictionary to define custom criteria for reporting.

Current Terms

-
+ Filter By Area - + ">
@@ -56,7 +56,7 @@ Filter By Area

Add New Definition

1 Name | 2 Area | 3 Columns | 4 Values

-
+ "> "> @@ -97,7 +97,7 @@ Select table "> "> "> @@ -136,7 +136,7 @@ Select table "> "> "> @@ -205,7 +205,7 @@ align : "Tl" - + "> "> "> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl index 8908c08234..11a24bc1bd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl @@ -30,11 +30,13 @@ canned reports and writing custom SQL reports.

+

Reports Dictionary

Use the reports dictionary to define custom criteria to use in your reports

+
-
+ diff --git a/reports/dictionary.pl b/reports/dictionary.pl new file mode 100755 index 0000000000..addb01a565 --- /dev/null +++ b/reports/dictionary.pl @@ -0,0 +1,203 @@ +#!/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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA +use CGI::Carp qw(fatalsToBrowser warningsToBrowser); +use strict; +use C4::Auth; +use CGI; +use C4::Output; +use C4::Reports; + +=head1 NAME + +Script to control the guided report creation + +=head1 DESCRIPTION + + +=over2 + +=cut + +my $input = new CGI; +my $referer = $input->referer(); + +my $phase = $input->param('phase'); +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 => { editcatalogue => 1 }, + 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 $areas = C4::Reports::get_report_areas(); + my $definitions = get_from_dictionary(); + $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 + my $areas = C4::Reports::get_report_areas(); + my $definition_name=$input->param('definition_name'); + my $definition_description=$input->param('definition_description'); + $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 $area = $input->param('areas'); + my $columns = get_columns($area); + my $definition_name=$input->param('definition_name'); + my $definition_description=$input->param('definition_description'); + $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 $area=$input->param('area'); + my $definition_name=$input->param('definition_name'); + my $definition_description=$input->param('definition_description'); + 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'){ + $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, + + ); +} + +elsif ($phase eq 'New Term step 5'){ + # Confirmation screen + my $area = $input->param('area'); + my $columnstring = $input->param('columnstring'); + my $definition_name=$input->param('definition_name'); + my $definition_description=$input->param('definition_description'); + my @criteria = $input->param('criteria_column'); + my $query_criteria; + my @criteria_loop; + foreach my $crit (@criteria) { + my $value = $input->param( $crit . "_value" ); + if ($value) { + $query_criteria .= " AND $crit='$value'"; + my %tmp_hash; + $tmp_hash{'name'}=$crit; + $tmp_hash{'value'} = $value; + push @criteria_loop,\%tmp_hash; + } + + $value = $input->param( $crit . "_start_value" ); + if ($value) { + $query_criteria .= " AND $crit > '$value'"; + my %tmp_hash; + $tmp_hash{'name'}="$crit Start"; + $tmp_hash{'value'} = $value; + push @criteria_loop,\%tmp_hash; + } + $value = $input->param( $crit . "_end_value" ); + if ($value) { + $query_criteria .= " AND $crit <= '$value'"; + my %tmp_hash; + $tmp_hash{'name'}="$crit End"; + $tmp_hash{'value'} = $value; + push @criteria_loop,\%tmp_hash; + } + } + $template->param( 'step_5' => 1, + 'area' => $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 $definition_name=$input->param('definition_name'); + my $definition_description=$input->param('definition_description'); + my $sql=$input->param('sql'); + save_dictionary($definition_name,$definition_description,$sql,$area); + $no_html=1; + print $input->redirect("/cgi-bin/koha/reports/guided_reports.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/guided_reports.pl?phase=View%20Dictionary"); + } + +$template->param( 'referer' => $referer ); + + +if (!$no_html){ + output_html_with_http_headers $input, $cookie, $template->output; +} diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 1b3e825c7d..5eac92cd23 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -350,211 +350,6 @@ elsif ($phase eq 'Save Compound'){ ); } -elsif ($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 - ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - my $areas = C4::Reports::get_report_areas(); - my $definitions = get_from_dictionary(); - $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, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - - $template->param( 'new_dictionary' => 1, - ); -} - -elsif ($phase eq 'New Term step 2'){ - # Choosing the area - ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - my $areas = C4::Reports::get_report_areas(); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - $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 - ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - my $area = $input->param('areas'); - my $columns = get_columns($area); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - $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 - ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - my $area=$input->param('area'); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - 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'){ - $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, - - ); -} - -elsif ($phase eq 'New Term step 5'){ - # Confirmation screen - ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - my $area = $input->param('area'); - my $columnstring = $input->param('columnstring'); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - my @criteria = $input->param('criteria_column'); - my $query_criteria; - my @criteria_loop; - foreach my $crit (@criteria) { - my $value = $input->param( $crit . "_value" ); - if ($value) { - $query_criteria .= " AND $crit='$value'"; - my %tmp_hash; - $tmp_hash{'name'}=$crit; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - } - - $value = $input->param( $crit . "_start_value" ); - if ($value) { - $query_criteria .= " AND $crit > '$value'"; - my %tmp_hash; - $tmp_hash{'name'}="$crit Start"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - } - $value = $input->param( $crit . "_end_value" ); - if ($value) { - $query_criteria .= " AND $crit <= '$value'"; - my %tmp_hash; - $tmp_hash{'name'}="$crit End"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - } - } - $template->param( 'step_5' => 1, - 'area' => $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 $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - my $sql=$input->param('sql'); - save_dictionary($definition_name,$definition_description,$sql,$area); - $no_html=1; - print $input->redirect("/cgi-bin/koha/reports/guided_reports.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/guided_reports.pl?phase=View%20Dictionary"); - } $template->param( 'referer' => $referer ); -- 2.39.5