fix for bug 1892: When checking in item on hold...
[koha.git] / reports / dictionary.pl
blob56949aa5b637e6532c8822c82639859d673df4a2
1 #!/usr/bin/perl
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
10 # version.
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);
20 use strict;
21 use C4::Auth;
22 use CGI;
23 use C4::Output;
24 use C4::Reports;
26 =head1 NAME
28 Script to control the guided report creation
30 =head1 DESCRIPTION
33 =over2
35 =cut
37 my $input = new CGI;
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",
45 query => $input,
46 type => "intranet",
47 authnotrequired => 0,
48 flagsrequired => { editcatalogue => 1 },
49 debug => 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'){
69 # Choosing the area
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,
74 'areas' => $areas,
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,$input);
84 my $definition_name=$input->param('definition_name');
85 my $definition_description=$input->param('definition_description');
86 $template->param( 'step_3' => 1,
87 'area' => $area,
88 'columns' => $columns,
89 'definition_name' => $definition_name,
90 'definition_description' => $definition_description,
94 elsif ($phase eq 'New Term step 4'){
95 # Choosing the values
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);
101 my @column_loop;
102 foreach my $column (@columns){
103 my %tmp_hash;
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'){
113 $tmp_hash{'date'}=1;
115 if ($type eq 'TEXT'){
116 $tmp_hash{'text'}=1;
118 # else {
119 # warn $type;#
121 push @column_loop,\%tmp_hash;
124 $template->param( 'step_4' => 1,
125 'area' => $area,
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 $areas = C4::Reports::get_report_areas();
137 my $area = $input->param('area');
138 my $areaname = $areas->[$area - 1]->{'name'};
139 my $columnstring = $input->param('columnstring');
140 my $definition_name=$input->param('definition_name');
141 my $definition_description=$input->param('definition_description');
142 my @criteria = $input->param('criteria_column');
143 my $query_criteria;
144 my @criteria_loop;
145 foreach my $crit (@criteria) {
146 my $value = $input->param( $crit . "_value" );
147 if ($value) {
148 $query_criteria .= " AND $crit='$value'";
149 my %tmp_hash;
150 $tmp_hash{'name'}=$crit;
151 $tmp_hash{'value'} = $value;
152 push @criteria_loop,\%tmp_hash;
155 $value = $input->param( $crit . "_start_value" );
156 if ($value) {
157 $query_criteria .= " AND $crit > '$value'";
158 my %tmp_hash;
159 $tmp_hash{'name'}="$crit Start";
160 $tmp_hash{'value'} = $value;
161 push @criteria_loop,\%tmp_hash;
163 $value = $input->param( $crit . "_end_value" );
164 if ($value) {
165 $query_criteria .= " AND $crit <= '$value'";
166 my %tmp_hash;
167 $tmp_hash{'name'}="$crit End";
168 $tmp_hash{'value'} = $value;
169 push @criteria_loop,\%tmp_hash;
172 $template->param( 'step_5' => 1,
173 'area' => $area,
174 'areaname' => $areaname,
175 'definition_name' => $definition_name,
176 'definition_description' => $definition_description,
177 'query' => $query_criteria,
178 'columnstring' => $columnstring,
179 'criteria_loop' => \@criteria_loop,
183 elsif ($phase eq 'New Term step 6'){
184 # Saving
185 my $area = $input->param('area');
186 my $definition_name=$input->param('definition_name');
187 my $definition_description=$input->param('definition_description');
188 my $sql=$input->param('sql');
189 save_dictionary($definition_name,$definition_description,$sql,$area);
190 $no_html=1;
191 print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
194 elsif ($phase eq 'Delete Definition'){
195 $no_html=1;
196 my $id = $input->param('id');
197 delete_definition($id);
198 print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=View%20Dictionary");
201 $template->param( 'referer' => $referer );
204 if (!$no_html){
205 output_html_with_http_headers $input, $cookie, $template->output;