Lines 40-45
Script to control the guided report creation
Link Here
|
40 |
=cut |
40 |
=cut |
41 |
|
41 |
|
42 |
my $input = new CGI; |
42 |
my $input = new CGI; |
|
|
43 |
my $usecache = C4::Context->ismemcached; |
43 |
|
44 |
|
44 |
my $phase = $input->param('phase'); |
45 |
my $phase = $input->param('phase'); |
45 |
my $flagsrequired; |
46 |
my $flagsrequired; |
Lines 84-90
if ( !$phase ) {
Link Here
|
84 |
elsif ( $phase eq 'Build new' ) { |
85 |
elsif ( $phase eq 'Build new' ) { |
85 |
# build a new report |
86 |
# build a new report |
86 |
$template->param( 'build1' => 1 ); |
87 |
$template->param( 'build1' => 1 ); |
87 |
$template->param( 'areas' => get_report_areas() ); |
88 |
$template->param( 'areas' => get_report_areas(), 'usecache' => $usecache, 'cache_expiry' => 300, 'public' => '0' ); |
88 |
} |
89 |
} |
89 |
elsif ( $phase eq 'Use saved' ) { |
90 |
elsif ( $phase eq 'Use saved' ) { |
90 |
# use a saved report |
91 |
# use a saved report |
Lines 92-97
elsif ( $phase eq 'Use saved' ) {
Link Here
|
92 |
$template->param( |
93 |
$template->param( |
93 |
'saved1' => 1, |
94 |
'saved1' => 1, |
94 |
'savedreports' => get_saved_reports($filter), |
95 |
'savedreports' => get_saved_reports($filter), |
|
|
96 |
'usecache' => $usecache, |
95 |
); |
97 |
); |
96 |
if ($filter) { |
98 |
if ($filter) { |
97 |
while ( my ($k, $v) = each %$filter ) { |
99 |
while ( my ($k, $v) = each %$filter ) { |
Lines 125-136
elsif ( $phase eq 'Show SQL'){
Link Here
|
125 |
elsif ( $phase eq 'Edit SQL'){ |
127 |
elsif ( $phase eq 'Edit SQL'){ |
126 |
|
128 |
|
127 |
my $id = $input->param('reports'); |
129 |
my $id = $input->param('reports'); |
128 |
my ($sql,$type,$reportname,$notes) = get_saved_report($id); |
130 |
my ($sql,$type,$reportname,$notes, $cache_expiry, $public) = get_saved_report($id); |
129 |
$template->param( |
131 |
$template->param( |
130 |
'sql' => $sql, |
132 |
'sql' => $sql, |
131 |
'reportname' => $reportname, |
133 |
'reportname' => $reportname, |
132 |
'notes' => $notes, |
134 |
'notes' => $notes, |
133 |
'id' => $id, |
135 |
'id' => $id, |
|
|
136 |
'cache_expiry' => $cache_expiry, |
137 |
'public' => $public, |
138 |
'usecache' => $usecache, |
134 |
'editsql' => 1, |
139 |
'editsql' => 1, |
135 |
); |
140 |
); |
136 |
} |
141 |
} |
Lines 140-146
elsif ( $phase eq 'Update SQL'){
Link Here
|
140 |
my $sql = $input->param('sql'); |
145 |
my $sql = $input->param('sql'); |
141 |
my $reportname = $input->param('reportname'); |
146 |
my $reportname = $input->param('reportname'); |
142 |
my $notes = $input->param('notes'); |
147 |
my $notes = $input->param('notes'); |
|
|
148 |
my $cache_expiry = $input->param('cache_expiry'); |
149 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
150 |
my $public = $input->param('public'); |
151 |
|
143 |
my @errors; |
152 |
my @errors; |
|
|
153 |
|
154 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
155 |
if( $cache_expiry_units ){ |
156 |
if( $cache_expiry_units eq "minutes" ){ |
157 |
$cache_expiry *= 60; |
158 |
} elsif( $cache_expiry_units eq "hours" ){ |
159 |
$cache_expiry *= 3600; # 60 * 60 |
160 |
} elsif( $cache_expiry_units eq "days" ){ |
161 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
162 |
} |
163 |
} |
164 |
# check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp |
165 |
if( $cache_expiry >= 2592000 ){ |
166 |
push @errors, {cache_expiry => $cache_expiry}; |
167 |
} |
168 |
|
144 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
169 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
145 |
push @errors, {sqlerr => $1}; |
170 |
push @errors, {sqlerr => $1}; |
146 |
} |
171 |
} |
Lines 154-160
elsif ( $phase eq 'Update SQL'){
Link Here
|
154 |
); |
179 |
); |
155 |
} |
180 |
} |
156 |
else { |
181 |
else { |
157 |
update_sql( $id, $sql, $reportname, $notes ); |
182 |
update_sql( $id, $sql, $reportname, $notes, $cache_expiry, $public ); |
158 |
$template->param( |
183 |
$template->param( |
159 |
'save_successful' => 1, |
184 |
'save_successful' => 1, |
160 |
'reportname' => $reportname, |
185 |
'reportname' => $reportname, |
Lines 177-193
elsif ($phase eq 'retrieve results') {
Link Here
|
177 |
} |
202 |
} |
178 |
|
203 |
|
179 |
elsif ( $phase eq 'Report on this Area' ) { |
204 |
elsif ( $phase eq 'Report on this Area' ) { |
180 |
|
205 |
my $cache_expiry_units = $input->param('cache_expiry_units'), |
181 |
# they have choosen a new report and the area to report on |
206 |
my $cache_expiry = $input->param('cache_expiry'); |
182 |
$template->param( |
207 |
|
183 |
'build2' => 1, |
208 |
# we need to handle converting units |
184 |
'area' => $input->param('areas'), |
209 |
if( $cache_expiry_units eq "minutes" ){ |
185 |
'types' => get_report_types(), |
210 |
$cache_expiry *= 60; |
186 |
); |
211 |
} elsif( $cache_expiry_units eq "hours" ){ |
|
|
212 |
$cache_expiry *= 3600; # 60 * 60 |
213 |
} elsif( $cache_expiry_units eq "days" ){ |
214 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
215 |
} |
216 |
# check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp |
217 |
if( $cache_expiry >= 2592000 ){ # oops, over the limit of 30 days |
218 |
# report error to user |
219 |
$template->param( |
220 |
'cache_error' => 1, |
221 |
'build1' => 1, |
222 |
'areas' => get_report_areas(), |
223 |
'cache_expiry' => $cache_expiry, |
224 |
'usecache' => $usecache, |
225 |
'public' => $input->param('public'), |
226 |
); |
227 |
} else { |
228 |
# they have choosen a new report and the area to report on |
229 |
$template->param( |
230 |
'build2' => 1, |
231 |
'area' => $input->param('areas'), |
232 |
'types' => get_report_types(), |
233 |
'cache_expiry' => $cache_expiry, |
234 |
'public' => $input->param('public'), |
235 |
); |
236 |
} |
187 |
} |
237 |
} |
188 |
|
238 |
|
189 |
elsif ( $phase eq 'Choose this type' ) { |
239 |
elsif ( $phase eq 'Choose this type' ) { |
190 |
|
|
|
191 |
# they have chosen type and area |
240 |
# they have chosen type and area |
192 |
# get area and type and pass them to the template |
241 |
# get area and type and pass them to the template |
193 |
my $area = $input->param('area'); |
242 |
my $area = $input->param('area'); |
Lines 197-207
elsif ( $phase eq 'Choose this type' ) {
Link Here
|
197 |
'area' => $area, |
246 |
'area' => $area, |
198 |
'type' => $type, |
247 |
'type' => $type, |
199 |
columns => get_columns($area,$input), |
248 |
columns => get_columns($area,$input), |
|
|
249 |
'cache_expiry' => $input->param('cache_expiry'), |
250 |
'public' => $input->param('public'), |
200 |
); |
251 |
); |
201 |
} |
252 |
} |
202 |
|
253 |
|
203 |
elsif ( $phase eq 'Choose these columns' ) { |
254 |
elsif ( $phase eq 'Choose these columns' ) { |
204 |
|
|
|
205 |
# we now know type, area, and columns |
255 |
# we now know type, area, and columns |
206 |
# next step is the constraints |
256 |
# next step is the constraints |
207 |
my $area = $input->param('area'); |
257 |
my $area = $input->param('area'); |
Lines 215-220
elsif ( $phase eq 'Choose these columns' ) {
Link Here
|
215 |
'column' => $column, |
265 |
'column' => $column, |
216 |
definitions => get_from_dictionary($area), |
266 |
definitions => get_from_dictionary($area), |
217 |
criteria => get_criteria($area,$input), |
267 |
criteria => get_criteria($area,$input), |
|
|
268 |
'cache_expiry' => $input->param('cache_expiry'), |
269 |
'cache_expiry_units' => $input->param('cache_expiry_units'), |
270 |
'public' => $input->param('public'), |
218 |
); |
271 |
); |
219 |
} |
272 |
} |
220 |
|
273 |
|
Lines 259-265
elsif ( $phase eq 'Choose these criteria' ) {
Link Here
|
259 |
} |
312 |
} |
260 |
} |
313 |
} |
261 |
} |
314 |
} |
262 |
|
|
|
263 |
$template->param( |
315 |
$template->param( |
264 |
'build5' => 1, |
316 |
'build5' => 1, |
265 |
'area' => $area, |
317 |
'area' => $area, |
Lines 267-272
elsif ( $phase eq 'Choose these criteria' ) {
Link Here
|
267 |
'column' => $column, |
319 |
'column' => $column, |
268 |
'definition' => $definition, |
320 |
'definition' => $definition, |
269 |
'criteriastring' => $query_criteria, |
321 |
'criteriastring' => $query_criteria, |
|
|
322 |
'cache_expiry' => $input->param('cache_expiry'), |
323 |
'cache_expiry_units' => $input->param('cache_expiry_units'), |
324 |
'public' => $input->param('public'), |
270 |
); |
325 |
); |
271 |
|
326 |
|
272 |
# get columns |
327 |
# get columns |
Lines 307-312
elsif ( $phase eq 'Choose These Operations' ) {
Link Here
|
307 |
'criteriastring' => $criteria, |
362 |
'criteriastring' => $criteria, |
308 |
'totals' => $totals, |
363 |
'totals' => $totals, |
309 |
'definition' => $definition, |
364 |
'definition' => $definition, |
|
|
365 |
'cache_expiry' => $input->param('cache_expiry'), |
366 |
'public' => $input->param('public'), |
310 |
); |
367 |
); |
311 |
|
368 |
|
312 |
# get columns |
369 |
# get columns |
Lines 356-362
elsif ( $phase eq 'Build Report' ) {
Link Here
|
356 |
$template->param( |
413 |
$template->param( |
357 |
'showreport' => 1, |
414 |
'showreport' => 1, |
358 |
'sql' => $sql, |
415 |
'sql' => $sql, |
359 |
'type' => $type |
416 |
'type' => $type, |
|
|
417 |
'cache_expiry' => $input->param('cache_expiry'), |
418 |
'public' => $input->param('public'), |
360 |
); |
419 |
); |
361 |
} |
420 |
} |
362 |
|
421 |
|
Lines 367-373
elsif ( $phase eq 'Save' ) {
Link Here
|
367 |
$template->param( |
426 |
$template->param( |
368 |
'save' => 1, |
427 |
'save' => 1, |
369 |
'sql' => $sql, |
428 |
'sql' => $sql, |
370 |
'type' => $type |
429 |
'type' => $type, |
|
|
430 |
'cache_expiry' => $input->param('cache_expiry'), |
431 |
'public' => $input->param('public'), |
371 |
); |
432 |
); |
372 |
} |
433 |
} |
373 |
|
434 |
|
Lines 377-382
elsif ( $phase eq 'Save Report' ) {
Link Here
|
377 |
my $name = $input->param('reportname'); |
438 |
my $name = $input->param('reportname'); |
378 |
my $type = $input->param('types'); |
439 |
my $type = $input->param('types'); |
379 |
my $notes = $input->param('notes'); |
440 |
my $notes = $input->param('notes'); |
|
|
441 |
my $cache_expiry = $input->param('cache_expiry'); |
442 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
443 |
my $public = $input->param('public'); |
444 |
|
445 |
|
446 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
447 |
if( $cache_expiry_units ){ |
448 |
if( $cache_expiry_units eq "minutes" ){ |
449 |
$cache_expiry *= 60; |
450 |
} elsif( $cache_expiry_units eq "hours" ){ |
451 |
$cache_expiry *= 3600; # 60 * 60 |
452 |
} elsif( $cache_expiry_units eq "days" ){ |
453 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
454 |
} |
455 |
} |
456 |
# check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp |
457 |
if( $cache_expiry >= 2592000 ){ |
458 |
push @errors, {cache_expiry => $cache_expiry}; |
459 |
} |
460 |
## FIXME this is AFTER entering a name to save the report under |
380 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
461 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
381 |
push @errors, {sqlerr => $1}; |
462 |
push @errors, {sqlerr => $1}; |
382 |
} |
463 |
} |
Lines 390-399
elsif ( $phase eq 'Save Report' ) {
Link Here
|
390 |
'reportname'=> $name, |
471 |
'reportname'=> $name, |
391 |
'type' => $type, |
472 |
'type' => $type, |
392 |
'notes' => $notes, |
473 |
'notes' => $notes, |
|
|
474 |
'cache_expiry' => $cache_expiry, |
475 |
'public' => $public, |
393 |
); |
476 |
); |
394 |
} |
477 |
} |
395 |
else { |
478 |
else { |
396 |
my $id = save_report( $borrowernumber, $sql, $name, $type, $notes ); |
479 |
my $id = save_report( $borrowernumber, $sql, $name, $type, $notes, $cache_expiry, $public ); |
397 |
$template->param( |
480 |
$template->param( |
398 |
'save_successful' => 1, |
481 |
'save_successful' => 1, |
399 |
'reportname' => $name, |
482 |
'reportname' => $name, |
Lines 602-608
elsif ($phase eq 'Create report from SQL') {
Link Here
|
602 |
'notes' => $input->param('notes'), |
685 |
'notes' => $input->param('notes'), |
603 |
); |
686 |
); |
604 |
} |
687 |
} |
605 |
$template->param('create' => 1); |
688 |
$template->param('create' => 1, 'public' => '0', 'cache_expiry' => 300, 'usecache' => $usecache); |
606 |
} |
689 |
} |
607 |
|
690 |
|
608 |
elsif ($phase eq 'Create Compound Report'){ |
691 |
elsif ($phase eq 'Create Compound Report'){ |