3 # Copyright 2007 Liblime ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
19 use CGI
::Carp
qw(fatalsToBrowser warningsToBrowser);
28 Script to control the guided report creation
38 my $referer = $input->referer();
40 my $phase = $input->param('phase');
41 my $no_html = 0; # this will be set if we dont want to print out an html::template
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
44 template_name
=> "reports/dictionary.tmpl",
48 flagsrequired
=> { editcatalogue
=> 1 },
53 if ($phase eq 'View Dictionary'){
54 # view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town
55 my $areas = C4
::Reports
::get_report_areas
();
56 my $definitions = get_from_dictionary
();
57 $template->param( 'areas' => $areas ,
58 'start_dictionary' => 1,
59 'definitions' => $definitions,
62 elsif ($phase eq 'Add New Definition'){
63 # display form allowing them to add a new definition
64 $template->param( 'new_dictionary' => 1,
68 elsif ($phase eq 'New Term step 2'){
70 my $areas = C4
::Reports
::get_report_areas
();
71 my $definition_name=$input->param('definition_name');
72 my $definition_description=$input->param('definition_description');
73 $template->param( 'step_2' => 1,
75 'definition_name' => $definition_name,
76 'definition_description' => $definition_description,
80 elsif ($phase eq 'New Term step 3'){
81 # Choosing the columns
82 my $area = $input->param('areas');
83 my $columns = get_columns
($area);
84 my $definition_name=$input->param('definition_name');
85 my $definition_description=$input->param('definition_description');
86 $template->param( 'step_3' => 1,
88 'columns' => $columns,
89 'definition_name' => $definition_name,
90 'definition_description' => $definition_description,
94 elsif ($phase eq 'New Term step 4'){
96 my $area=$input->param('area');
97 my $definition_name=$input->param('definition_name');
98 my $definition_description=$input->param('definition_description');
99 my @columns = $input->param('columns');
100 my $columnstring = join (',',@columns);
102 foreach my $column (@columns){
104 $tmp_hash{'name'}=$column;
105 my $type =get_column_type
($column);
106 if ($type eq 'distinct'){
107 my $values = get_distinct_values
($column);
108 $tmp_hash{'values'} = $values;
109 $tmp_hash{'distinct'} = 1;
112 if ($type eq 'DATE' || $type eq 'DATETIME'){
115 if ($type eq 'TEXT'){
121 push @column_loop,\
%tmp_hash;
124 $template->param( 'step_4' => 1,
126 'definition_name' => $definition_name,
127 'definition_description' => $definition_description,
128 'columns' => \
@column_loop,
129 'columnstring' => $columnstring,
134 elsif ($phase eq 'New Term step 5'){
135 # Confirmation screen
136 my $area = $input->param('area');
137 my $columnstring = $input->param('columnstring');
138 my $definition_name=$input->param('definition_name');
139 my $definition_description=$input->param('definition_description');
140 my @criteria = $input->param('criteria_column');
143 foreach my $crit (@criteria) {
144 my $value = $input->param( $crit . "_value" );
146 $query_criteria .= " AND $crit='$value'";
148 $tmp_hash{'name'}=$crit;
149 $tmp_hash{'value'} = $value;
150 push @criteria_loop,\
%tmp_hash;
153 $value = $input->param( $crit . "_start_value" );
155 $query_criteria .= " AND $crit > '$value'";
157 $tmp_hash{'name'}="$crit Start";
158 $tmp_hash{'value'} = $value;
159 push @criteria_loop,\
%tmp_hash;
161 $value = $input->param( $crit . "_end_value" );
163 $query_criteria .= " AND $crit <= '$value'";
165 $tmp_hash{'name'}="$crit End";
166 $tmp_hash{'value'} = $value;
167 push @criteria_loop,\
%tmp_hash;
170 $template->param( 'step_5' => 1,
172 'definition_name' => $definition_name,
173 'definition_description' => $definition_description,
174 'query' => $query_criteria,
175 'columnstring' => $columnstring,
176 'criteria_loop' => \
@criteria_loop,
180 elsif ($phase eq 'New Term step 6'){
182 my $area = $input->param('area');
183 my $definition_name=$input->param('definition_name');
184 my $definition_description=$input->param('definition_description');
185 my $sql=$input->param('sql');
186 save_dictionary
($definition_name,$definition_description,$sql,$area);
188 print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=View%20Dictionary");
191 elsif ($phase eq 'Delete Definition'){
193 my $id = $input->param('id');
194 delete_definition
($id);
195 print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=View%20Dictionary");
198 $template->param( 'referer' => $referer );
202 output_html_with_http_headers
$input, $cookie, $template->output;