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->preference('usecache'); |
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 122-133
elsif ( $phase eq 'Show SQL'){
Link Here
|
122 |
elsif ( $phase eq 'Edit SQL'){ |
124 |
elsif ( $phase eq 'Edit SQL'){ |
123 |
|
125 |
|
124 |
my $id = $input->param('reports'); |
126 |
my $id = $input->param('reports'); |
125 |
my ($sql,$type,$reportname,$notes) = get_saved_report($id); |
127 |
my ($sql,$type,$reportname,$notes, $cache_expiry, $public) = get_saved_report($id); |
126 |
$template->param( |
128 |
$template->param( |
127 |
'sql' => $sql, |
129 |
'sql' => $sql, |
128 |
'reportname' => $reportname, |
130 |
'reportname' => $reportname, |
129 |
'notes' => $notes, |
131 |
'notes' => $notes, |
130 |
'id' => $id, |
132 |
'id' => $id, |
|
|
133 |
'cache_expiry' => $cache_expiry, |
134 |
'public' => $public, |
135 |
'usecache' => $usecache, |
131 |
'editsql' => 1, |
136 |
'editsql' => 1, |
132 |
); |
137 |
); |
133 |
} |
138 |
} |
Lines 137-143
elsif ( $phase eq 'Update SQL'){
Link Here
|
137 |
my $sql = $input->param('sql'); |
142 |
my $sql = $input->param('sql'); |
138 |
my $reportname = $input->param('reportname'); |
143 |
my $reportname = $input->param('reportname'); |
139 |
my $notes = $input->param('notes'); |
144 |
my $notes = $input->param('notes'); |
|
|
145 |
my $cache_expiry = $input->param('cache_expiry'); |
146 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
147 |
my $public = $input->param('public'); |
148 |
|
140 |
my @errors; |
149 |
my @errors; |
|
|
150 |
|
151 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
152 |
if( $cache_expiry_units ){ |
153 |
if( $cache_expiry_units eq "minutes" ){ |
154 |
$cache_expiry *= 60; |
155 |
} elsif( $cache_expiry_units eq "hours" ){ |
156 |
$cache_expiry *= 3600; # 60 * 60 |
157 |
} elsif( $cache_expiry_units eq "days" ){ |
158 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
159 |
} |
160 |
} |
161 |
# 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 |
162 |
if( $cache_expiry >= 2592000 ){ |
163 |
push @errors, {cache_expiry => $cache_expiry}; |
164 |
} |
165 |
|
141 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
166 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
142 |
push @errors, {sqlerr => $1}; |
167 |
push @errors, {sqlerr => $1}; |
143 |
} |
168 |
} |
Lines 151-157
elsif ( $phase eq 'Update SQL'){
Link Here
|
151 |
); |
176 |
); |
152 |
} |
177 |
} |
153 |
else { |
178 |
else { |
154 |
update_sql( $id, $sql, $reportname, $notes ); |
179 |
update_sql( $id, $sql, $reportname, $notes, $cache_expiry, $public ); |
155 |
$template->param( |
180 |
$template->param( |
156 |
'save_successful' => 1, |
181 |
'save_successful' => 1, |
157 |
'id' => $id, |
182 |
'id' => $id, |
Lines 173-189
elsif ($phase eq 'retrieve results') {
Link Here
|
173 |
} |
198 |
} |
174 |
|
199 |
|
175 |
elsif ( $phase eq 'Report on this Area' ) { |
200 |
elsif ( $phase eq 'Report on this Area' ) { |
176 |
|
201 |
my $cache_expiry_units = $input->param('cache_expiry_units'), |
177 |
# they have choosen a new report and the area to report on |
202 |
my $cache_expiry = $input->param('cache_expiry'); |
178 |
$template->param( |
203 |
|
179 |
'build2' => 1, |
204 |
# we need to handle converting units |
180 |
'area' => $input->param('areas'), |
205 |
if( $cache_expiry_units eq "minutes" ){ |
181 |
'types' => get_report_types(), |
206 |
$cache_expiry *= 60; |
182 |
); |
207 |
} elsif( $cache_expiry_units eq "hours" ){ |
|
|
208 |
$cache_expiry *= 3600; # 60 * 60 |
209 |
} elsif( $cache_expiry_units eq "days" ){ |
210 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
211 |
} |
212 |
# 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 |
213 |
if( $cache_expiry >= 2592000 ){ # oops, over the limit of 30 days |
214 |
# report error to user |
215 |
$template->param( |
216 |
'cache_error' => 1, |
217 |
'build1' => 1, |
218 |
'areas' => get_report_areas(), |
219 |
'cache_expiry' => $cache_expiry, |
220 |
'usecache' => $usecache, |
221 |
'public' => $input->param('public'), |
222 |
); |
223 |
} else { |
224 |
# they have choosen a new report and the area to report on |
225 |
$template->param( |
226 |
'build2' => 1, |
227 |
'area' => $input->param('areas'), |
228 |
'types' => get_report_types(), |
229 |
'cache_expiry' => $cache_expiry, |
230 |
'public' => $input->param('public'), |
231 |
); |
232 |
} |
183 |
} |
233 |
} |
184 |
|
234 |
|
185 |
elsif ( $phase eq 'Choose this type' ) { |
235 |
elsif ( $phase eq 'Choose this type' ) { |
186 |
|
|
|
187 |
# they have chosen type and area |
236 |
# they have chosen type and area |
188 |
# get area and type and pass them to the template |
237 |
# get area and type and pass them to the template |
189 |
my $area = $input->param('area'); |
238 |
my $area = $input->param('area'); |
Lines 193-203
elsif ( $phase eq 'Choose this type' ) {
Link Here
|
193 |
'area' => $area, |
242 |
'area' => $area, |
194 |
'type' => $type, |
243 |
'type' => $type, |
195 |
columns => get_columns($area,$input), |
244 |
columns => get_columns($area,$input), |
|
|
245 |
'cache_expiry' => $input->param('cache_expiry'), |
246 |
'public' => $input->param('public'), |
196 |
); |
247 |
); |
197 |
} |
248 |
} |
198 |
|
249 |
|
199 |
elsif ( $phase eq 'Choose these columns' ) { |
250 |
elsif ( $phase eq 'Choose these columns' ) { |
200 |
|
|
|
201 |
# we now know type, area, and columns |
251 |
# we now know type, area, and columns |
202 |
# next step is the constraints |
252 |
# next step is the constraints |
203 |
my $area = $input->param('area'); |
253 |
my $area = $input->param('area'); |
Lines 211-216
elsif ( $phase eq 'Choose these columns' ) {
Link Here
|
211 |
'column' => $column, |
261 |
'column' => $column, |
212 |
definitions => get_from_dictionary($area), |
262 |
definitions => get_from_dictionary($area), |
213 |
criteria => get_criteria($area,$input), |
263 |
criteria => get_criteria($area,$input), |
|
|
264 |
'cache_expiry' => $input->param('cache_expiry'), |
265 |
'cache_expiry_units' => $input->param('cache_expiry_units'), |
266 |
'public' => $input->param('public'), |
214 |
); |
267 |
); |
215 |
} |
268 |
} |
216 |
|
269 |
|
Lines 255-261
elsif ( $phase eq 'Choose these criteria' ) {
Link Here
|
255 |
} |
308 |
} |
256 |
} |
309 |
} |
257 |
} |
310 |
} |
258 |
|
|
|
259 |
$template->param( |
311 |
$template->param( |
260 |
'build5' => 1, |
312 |
'build5' => 1, |
261 |
'area' => $area, |
313 |
'area' => $area, |
Lines 263-268
elsif ( $phase eq 'Choose these criteria' ) {
Link Here
|
263 |
'column' => $column, |
315 |
'column' => $column, |
264 |
'definition' => $definition, |
316 |
'definition' => $definition, |
265 |
'criteriastring' => $query_criteria, |
317 |
'criteriastring' => $query_criteria, |
|
|
318 |
'cache_expiry' => $input->param('cache_expiry'), |
319 |
'cache_expiry_units' => $input->param('cache_expiry_units'), |
320 |
'public' => $input->param('public'), |
266 |
); |
321 |
); |
267 |
|
322 |
|
268 |
# get columns |
323 |
# get columns |
Lines 303-308
elsif ( $phase eq 'Choose These Operations' ) {
Link Here
|
303 |
'criteriastring' => $criteria, |
358 |
'criteriastring' => $criteria, |
304 |
'totals' => $totals, |
359 |
'totals' => $totals, |
305 |
'definition' => $definition, |
360 |
'definition' => $definition, |
|
|
361 |
'cache_expiry' => $input->param('cache_expiry'), |
362 |
'public' => $input->param('public'), |
306 |
); |
363 |
); |
307 |
|
364 |
|
308 |
# get columns |
365 |
# get columns |
Lines 352-358
elsif ( $phase eq 'Build Report' ) {
Link Here
|
352 |
$template->param( |
409 |
$template->param( |
353 |
'showreport' => 1, |
410 |
'showreport' => 1, |
354 |
'sql' => $sql, |
411 |
'sql' => $sql, |
355 |
'type' => $type |
412 |
'type' => $type, |
|
|
413 |
'cache_expiry' => $input->param('cache_expiry'), |
414 |
'public' => $input->param('public'), |
356 |
); |
415 |
); |
357 |
} |
416 |
} |
358 |
|
417 |
|
Lines 363-369
elsif ( $phase eq 'Save' ) {
Link Here
|
363 |
$template->param( |
422 |
$template->param( |
364 |
'save' => 1, |
423 |
'save' => 1, |
365 |
'sql' => $sql, |
424 |
'sql' => $sql, |
366 |
'type' => $type |
425 |
'type' => $type, |
|
|
426 |
'cache_expiry' => $input->param('cache_expiry'), |
427 |
'public' => $input->param('public'), |
367 |
); |
428 |
); |
368 |
} |
429 |
} |
369 |
|
430 |
|
Lines 373-378
elsif ( $phase eq 'Save Report' ) {
Link Here
|
373 |
my $name = $input->param('reportname'); |
434 |
my $name = $input->param('reportname'); |
374 |
my $type = $input->param('types'); |
435 |
my $type = $input->param('types'); |
375 |
my $notes = $input->param('notes'); |
436 |
my $notes = $input->param('notes'); |
|
|
437 |
my $cache_expiry = $input->param('cache_expiry'); |
438 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
439 |
my $public = $input->param('public'); |
440 |
|
441 |
|
442 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
443 |
if( $cache_expiry_units ){ |
444 |
if( $cache_expiry_units eq "minutes" ){ |
445 |
$cache_expiry *= 60; |
446 |
} elsif( $cache_expiry_units eq "hours" ){ |
447 |
$cache_expiry *= 3600; # 60 * 60 |
448 |
} elsif( $cache_expiry_units eq "days" ){ |
449 |
$cache_expiry *= 86400; # 60 * 60 * 24 |
450 |
} |
451 |
} |
452 |
# 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 |
453 |
if( $cache_expiry >= 2592000 ){ |
454 |
push @errors, {cache_expiry => $cache_expiry}; |
455 |
} |
456 |
## FIXME this is AFTER entering a name to save the report under |
376 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
457 |
if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) { |
377 |
push @errors, {sqlerr => $1}; |
458 |
push @errors, {sqlerr => $1}; |
378 |
} |
459 |
} |
Lines 386-395
elsif ( $phase eq 'Save Report' ) {
Link Here
|
386 |
'reportname'=> $name, |
467 |
'reportname'=> $name, |
387 |
'type' => $type, |
468 |
'type' => $type, |
388 |
'notes' => $notes, |
469 |
'notes' => $notes, |
|
|
470 |
'cache_expiry' => $cache_expiry, |
471 |
'public' => $public, |
389 |
); |
472 |
); |
390 |
} |
473 |
} |
391 |
else { |
474 |
else { |
392 |
my $id = save_report( $borrowernumber, $sql, $name, $type, $notes ); |
475 |
my $id = save_report( $borrowernumber, $sql, $name, $type, $notes, $cache_expiry, $public ); |
393 |
$template->param( |
476 |
$template->param( |
394 |
'save_successful' => 1, |
477 |
'save_successful' => 1, |
395 |
'id' => $id, |
478 |
'id' => $id, |
Lines 593-599
elsif ($phase eq 'Create report from SQL') {
Link Here
|
593 |
'notes' => $input->param('notes'), |
676 |
'notes' => $input->param('notes'), |
594 |
); |
677 |
); |
595 |
} |
678 |
} |
596 |
$template->param('create' => 1); |
679 |
$template->param('create' => 1, 'public' => '0', 'cache_expiry' => 300, 'usecache' => $usecache); |
597 |
} |
680 |
} |
598 |
|
681 |
|
599 |
elsif ($phase eq 'Create Compound Report'){ |
682 |
elsif ($phase eq 'Create Compound Report'){ |