Lines 29-34
use C4::Output;
Link Here
|
29 |
use C4::Dates qw/format_date/; |
29 |
use C4::Dates qw/format_date/; |
30 |
use C4::Debug; |
30 |
use C4::Debug; |
31 |
use C4::Branch; # XXX subfield_is_koha_internal_p |
31 |
use C4::Branch; # XXX subfield_is_koha_internal_p |
|
|
32 |
use C4::Koha qw/IsAuthorisedValueCategory/; |
32 |
|
33 |
|
33 |
=head1 NAME |
34 |
=head1 NAME |
34 |
|
35 |
|
Lines 132-138
elsif ( $phase eq 'Show SQL'){
Link Here
|
132 |
} |
133 |
} |
133 |
|
134 |
|
134 |
elsif ( $phase eq 'Edit SQL'){ |
135 |
elsif ( $phase eq 'Edit SQL'){ |
135 |
|
|
|
136 |
my $id = $input->param('reports'); |
136 |
my $id = $input->param('reports'); |
137 |
my $report = get_saved_report($id); |
137 |
my $report = get_saved_report($id); |
138 |
my $group = $report->{report_group}; |
138 |
my $group = $report->{report_group}; |
Lines 160-165
elsif ( $phase eq 'Update SQL'){
Link Here
|
160 |
my $cache_expiry = $input->param('cache_expiry'); |
160 |
my $cache_expiry = $input->param('cache_expiry'); |
161 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
161 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
162 |
my $public = $input->param('public'); |
162 |
my $public = $input->param('public'); |
|
|
163 |
my $save_anyway = $input->param('save_anyway'); |
163 |
|
164 |
|
164 |
my @errors; |
165 |
my @errors; |
165 |
|
166 |
|
Lines 184-209
elsif ( $phase eq 'Update SQL'){
Link Here
|
184 |
elsif ($sql !~ /^(SELECT)/i) { |
185 |
elsif ($sql !~ /^(SELECT)/i) { |
185 |
push @errors, {queryerr => 1}; |
186 |
push @errors, {queryerr => 1}; |
186 |
} |
187 |
} |
|
|
188 |
|
187 |
if (@errors) { |
189 |
if (@errors) { |
188 |
$template->param( |
190 |
$template->param( |
189 |
'errors' => \@errors, |
191 |
'errors' => \@errors, |
190 |
'sql' => $sql, |
192 |
'sql' => $sql, |
191 |
); |
193 |
); |
192 |
} else { |
194 |
} else { |
193 |
update_sql( $id, { |
195 |
|
194 |
sql => $sql, |
196 |
# Check defined SQL parameters for authorised value validity |
195 |
name => $reportname, |
197 |
my $problematic_authvals = ValidateSQLParameters($sql); |
196 |
group => $group, |
198 |
|
197 |
subgroup => $subgroup, |
199 |
if ( scalar @$problematic_authvals > 0 && not $save_anyway ) { |
198 |
notes => $notes, |
200 |
# There's at least one problematic parameter, report to the |
199 |
cache_expiry => $cache_expiry, |
201 |
# GUI and provide all user input for further actions |
200 |
public => $public, |
202 |
$template->param( |
201 |
} ); |
203 |
'id' => $id, |
202 |
$template->param( |
204 |
'sql' => $sql, |
203 |
'save_successful' => 1, |
205 |
'reportname' => $reportname, |
204 |
'reportname' => $reportname, |
206 |
'group' => $group, |
205 |
'id' => $id, |
207 |
'subgroup' => $subgroup, |
206 |
); |
208 |
'notes' => $notes, |
|
|
209 |
'cache_expiry' => $cache_expiry, |
210 |
'cache_expiry_units' => $cache_expiry_units, |
211 |
'public' => $public, |
212 |
'problematic_authvals' => $problematic_authvals, |
213 |
'warn_authval_problem' => 1, |
214 |
'phase_update' => 1 |
215 |
); |
216 |
|
217 |
} else { |
218 |
# No params problem found or asked to save anyway |
219 |
update_sql( $id, { |
220 |
sql => $sql, |
221 |
name => $reportname, |
222 |
group => $group, |
223 |
subgroup => $subgroup, |
224 |
notes => $notes, |
225 |
cache_expiry => $cache_expiry, |
226 |
public => $public, |
227 |
} ); |
228 |
$template->param( |
229 |
'save_successful' => 1, |
230 |
'reportname' => $reportname, |
231 |
'id' => $id, |
232 |
); |
233 |
} |
207 |
} |
234 |
} |
208 |
} |
235 |
} |
209 |
|
236 |
|
Lines 466-471
elsif ( $phase eq 'Save Report' ) {
Link Here
|
466 |
my $cache_expiry = $input->param('cache_expiry'); |
493 |
my $cache_expiry = $input->param('cache_expiry'); |
467 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
494 |
my $cache_expiry_units = $input->param('cache_expiry_units'); |
468 |
my $public = $input->param('public'); |
495 |
my $public = $input->param('public'); |
|
|
496 |
my $save_anyway = $input->param('save_anyway'); |
469 |
|
497 |
|
470 |
|
498 |
|
471 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
499 |
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units |
Lines 489-494
elsif ( $phase eq 'Save Report' ) {
Link Here
|
489 |
elsif ($sql !~ /^(SELECT)/i) { |
517 |
elsif ($sql !~ /^(SELECT)/i) { |
490 |
push @errors, {queryerr => "No SELECT"}; |
518 |
push @errors, {queryerr => "No SELECT"}; |
491 |
} |
519 |
} |
|
|
520 |
|
492 |
if (@errors) { |
521 |
if (@errors) { |
493 |
$template->param( |
522 |
$template->param( |
494 |
'errors' => \@errors, |
523 |
'errors' => \@errors, |
Lines 499-523
elsif ( $phase eq 'Save Report' ) {
Link Here
|
499 |
'cache_expiry' => $cache_expiry, |
528 |
'cache_expiry' => $cache_expiry, |
500 |
'public' => $public, |
529 |
'public' => $public, |
501 |
); |
530 |
); |
502 |
} |
531 |
} else { |
503 |
else { |
532 |
# Check defined SQL parameters for authorised value validity |
504 |
my $id = save_report( { |
533 |
my $problematic_authvals = ValidateSQLParameters($sql); |
505 |
borrowernumber => $borrowernumber, |
534 |
|
506 |
sql => $sql, |
535 |
if ( scalar @$problematic_authvals > 0 && not $save_anyway ) { |
507 |
name => $name, |
536 |
# There's at least one problematic parameter, report to the |
508 |
area => $area, |
537 |
# GUI and provide all user input for further actions |
509 |
group => $group, |
538 |
$template->param( |
510 |
subgroup => $subgroup, |
539 |
'area' => $area, |
511 |
type => $type, |
540 |
'group' => $group, |
512 |
notes => $notes, |
541 |
'subgroup' => $subgroup, |
513 |
cache_expiry => $cache_expiry, |
542 |
'sql' => $sql, |
514 |
public => $public, |
543 |
'reportname' => $name, |
515 |
} ); |
544 |
'type' => $type, |
516 |
$template->param( |
545 |
'notes' => $notes, |
517 |
'save_successful' => 1, |
546 |
'cache_expiry' => $cache_expiry, |
518 |
'reportname' => $name, |
547 |
'cache_expiry_units' => $cache_expiry_units, |
519 |
'id' => $id, |
548 |
'public' => $public, |
520 |
); |
549 |
'problematic_authvals' => $problematic_authvals, |
|
|
550 |
'warn_authval_problem' => 1, |
551 |
'phase_save' => 1 |
552 |
); |
553 |
} else { |
554 |
# No params problem found or asked to save anyway |
555 |
my $id = save_report( { |
556 |
borrowernumber => $borrowernumber, |
557 |
sql => $sql, |
558 |
name => $name, |
559 |
area => $area, |
560 |
group => $group, |
561 |
subgroup => $subgroup, |
562 |
type => $type, |
563 |
notes => $notes, |
564 |
cache_expiry => $cache_expiry, |
565 |
public => $public, |
566 |
} ); |
567 |
$template->param( |
568 |
'save_successful' => 1, |
569 |
'reportname' => $name, |
570 |
'id' => $id, |
571 |
); |
572 |
} |
521 |
} |
573 |
} |
522 |
} |
574 |
} |
523 |
|
575 |
|
Lines 549-562
elsif ($phase eq 'Run this report'){
Link Here
|
549 |
# split on ??. Each odd (2,4,6,...) entry should be a parameter to fill |
601 |
# split on ??. Each odd (2,4,6,...) entry should be a parameter to fill |
550 |
my @split = split /<<|>>/,$sql; |
602 |
my @split = split /<<|>>/,$sql; |
551 |
my @tmpl_parameters; |
603 |
my @tmpl_parameters; |
|
|
604 |
my @authval_errors; |
552 |
for(my $i=0;$i<($#split/2);$i++) { |
605 |
for(my $i=0;$i<($#split/2);$i++) { |
553 |
my ($text,$authorised_value) = split /\|/,$split[$i*2+1]; |
606 |
my ($text,$authorised_value) = split /\|/,$split[$i*2+1]; |
554 |
my $input; |
607 |
my $input; |
555 |
my $labelid; |
608 |
my $labelid; |
556 |
if ($authorised_value eq "date") { |
609 |
if ( not defined $authorised_value ) { |
557 |
$input = 'date'; |
610 |
# no authorised value input, provide a text box |
558 |
} |
611 |
$input = "text"; |
559 |
elsif ($authorised_value) { |
612 |
} elsif ( $authorised_value eq "date" ) { |
|
|
613 |
# require a date, provide a date picker |
614 |
$input = 'date'; |
615 |
} else { |
616 |
# defined $authorised_value, and not 'date' |
560 |
my $dbh=C4::Context->dbh; |
617 |
my $dbh=C4::Context->dbh; |
561 |
my @authorised_values; |
618 |
my @authorised_values; |
562 |
my %authorised_lib; |
619 |
my %authorised_lib; |
Lines 597-611
elsif ($phase eq 'Run this report'){
Link Here
|
597 |
#---- "true" authorised value |
654 |
#---- "true" authorised value |
598 |
} |
655 |
} |
599 |
else { |
656 |
else { |
600 |
my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"); |
657 |
if ( IsAuthorisedValueCategory($authorised_value) ) { |
601 |
|
658 |
my $query = ' |
602 |
$authorised_values_sth->execute( $authorised_value); |
659 |
SELECT authorised_value,lib |
603 |
|
660 |
FROM authorised_values |
604 |
while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { |
661 |
WHERE category=? |
605 |
push @authorised_values, $value; |
662 |
ORDER BY lib |
606 |
$authorised_lib{$value} = $lib; |
663 |
'; |
607 |
# For item location, we show the code and the libelle |
664 |
my $authorised_values_sth = $dbh->prepare($query); |
608 |
$authorised_lib{$value} = $lib; |
665 |
$authorised_values_sth->execute( $authorised_value); |
|
|
666 |
|
667 |
while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { |
668 |
push @authorised_values, $value; |
669 |
$authorised_lib{$value} = $lib; |
670 |
# For item location, we show the code and the libelle |
671 |
$authorised_lib{$value} = $lib; |
672 |
} |
673 |
} else { |
674 |
# not exists $authorised_value_categories{$authorised_value}) |
675 |
push @authval_errors, {'entry' => $text, |
676 |
'auth_val' => $authorised_value }; |
677 |
# tell the template there's an error |
678 |
$template->param( auth_val_error => 1 ); |
679 |
# skip scrolling list creation and params push |
680 |
next; |
609 |
} |
681 |
} |
610 |
} |
682 |
} |
611 |
$labelid = $text; |
683 |
$labelid = $text; |
Lines 621-634
elsif ($phase eq 'Run this report'){
Link Here
|
621 |
-multiple => 0, |
693 |
-multiple => 0, |
622 |
-tabindex => 1, |
694 |
-tabindex => 1, |
623 |
); |
695 |
); |
624 |
} else { |
|
|
625 |
$input = "text"; |
626 |
} |
696 |
} |
|
|
697 |
|
627 |
push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid }; |
698 |
push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid }; |
628 |
} |
699 |
} |
629 |
$template->param('sql' => $sql, |
700 |
$template->param('sql' => $sql, |
630 |
'name' => $name, |
701 |
'name' => $name, |
631 |
'sql_params' => \@tmpl_parameters, |
702 |
'sql_params' => \@tmpl_parameters, |
|
|
703 |
'auth_val_errors' => \@authval_errors, |
632 |
'enter_params' => 1, |
704 |
'enter_params' => 1, |
633 |
'reports' => $report_id, |
705 |
'reports' => $report_id, |
634 |
); |
706 |
); |
635 |
- |
|
|