View | Details | Raw Unified | Return to bug 9659
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-16 / +32 lines)
Lines 551-576 canned reports and writing custom SQL reports.</p> Link Here
551
551
552
[% IF ( enter_params ) %]
552
[% IF ( enter_params ) %]
553
    <form action='/cgi-bin/koha/reports/guided_reports.pl'>
553
    <form action='/cgi-bin/koha/reports/guided_reports.pl'>
554
        <input type='hidden' name='phase' value='Run this report' />
555
        <input type='hidden' name='reports' value="[% reports %]" />
554
        <input type='hidden' name='reports' value="[% reports %]" />
556
        <h1>Enter parameters for report [% name %]:</h1>
555
        [% IF ( auth_val_error ) %]
557
        [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
556
            <input type='hidden' name='phase' value='Edit SQL' />
558
        <fieldset class="rows">
557
            <h1>Errors found when processing parameters for report: [% name %]</h1>
558
            <fieldset class="rows">
559
                <div class="dialog alert">
560
                [% FOREACH auth_val_error IN auth_val_errors %]
561
                  <p>   
562
                    <strong>[% auth_val_error.entry %]:</strong> The authorised value category (<strong>[% auth_val_error.auth_val %]</strong>)
563
                    you selected does not exist.
564
                  </p>
565
                [% END %]
566
                </div>
567
            </fieldset>
568
            <fieldset class="action"><input type="submit" value="Edit SQL" /></fieldset>
569
        [% ELSE %]
570
            <input type='hidden' name='phase' value='Run this report' />
571
            <h1>Enter parameters for report [% name %]:</h1>
572
            [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
573
            <fieldset class="rows">
559
            <ol>
574
            <ol>
560
        [% FOREACH sql_param IN sql_params %]
575
            [% FOREACH sql_param IN sql_params %]
561
            [% IF sql_param.input == 'date' %]
576
                [% IF sql_param.input == 'date' %]
562
                <li>
577
                    <li>
563
                <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
578
                    <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
564
                </li>
579
                    </li>
565
            [% ELSIF ( sql_param.input == 'text' ) %]
580
                [% ELSIF ( sql_param.input == 'text' ) %]
566
                <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li>
581
                    <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li>
567
            [% ELSE %]
582
                [% ELSE %]
568
                <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li>
583
                    <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li>
584
                [% END %]
569
            [% END %]
585
            [% END %]
570
        [% END %]
571
            </ol>
586
            </ol>
572
        </fieldset>
587
            </fieldset>
573
        <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
588
            <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
589
        [% END %]
574
    </form>
590
    </form>
575
[% END %]
591
[% END %]
576
592
(-)a/reports/guided_reports.pl (-17 / +39 lines)
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/GetAuthorisedValueCategories/;
32
33
33
=head1 NAME
34
=head1 NAME
34
35
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
550
            # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
550
            my @split = split /<<|>>/,$sql;
551
            my @split = split /<<|>>/,$sql;
551
            my @tmpl_parameters;
552
            my @tmpl_parameters;
553
            my @authval_errors;
552
            for(my $i=0;$i<($#split/2);$i++) {
554
            for(my $i=0;$i<($#split/2);$i++) {
553
                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
555
                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
554
                my $input;
556
                my $input;
555
                my $labelid;
557
                my $labelid;
556
                if ($authorised_value eq "date") {
558
                if ( not defined $authorised_value ) {
557
                   $input = 'date';
559
                    # no authorised value input, provide a text box
558
                }
560
                    $input = "text";
559
                elsif ($authorised_value) {
561
                } elsif ( $authorised_value eq "date" ) {
562
                    # require a date, provide a date picker
563
                    $input = 'date';
564
                } else {
565
                    # defined $authorised_value, and not 'date'
560
                    my $dbh=C4::Context->dbh;
566
                    my $dbh=C4::Context->dbh;
561
                    my @authorised_values;
567
                    my @authorised_values;
562
                    my %authorised_lib;
568
                    my %authorised_lib;
Lines 596-611 elsif ($phase eq 'Run this report'){ Link Here
596
602
597
                        #---- "true" authorised value
603
                        #---- "true" authorised value
598
                    }
604
                    }
599
                    else {
605
                    else {  
600
                        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
606
                        # Build a hash of authorised value categories
601
607
                        my %authorised_value_categories = map { $_ => 1 } (GetAuthorisedValueCategories());
602
                        $authorised_values_sth->execute( $authorised_value);
608
                        if ( exists $authorised_value_categories{$authorised_value}) {
603
609
                            my $query = '
604
                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
610
                            SELECT authorised_value,lib
605
                            push @authorised_values, $value;
611
                            FROM authorised_values
606
                            $authorised_lib{$value} = $lib;
612
                            WHERE category=?
607
                            # For item location, we show the code and the libelle
613
                            ORDER BY lib
608
                            $authorised_lib{$value} = $lib;
614
                            ';
615
                            my $authorised_values_sth = $dbh->prepare($query);
616
                            $authorised_values_sth->execute( $authorised_value);
617
618
                            while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
619
                                push @authorised_values, $value;
620
                                $authorised_lib{$value} = $lib;
621
                                # For item location, we show the code and the libelle
622
                                $authorised_lib{$value} = $lib;
623
                            }
624
                        } else {
625
                            # not exists $authorised_value_categories{$authorised_value})
626
                            push @authval_errors, {'entry' => $text,
627
                                                   'auth_val' => $authorised_value };
628
                            # tell the template there's an error
629
                            $template->param( auth_val_error => 1 );
630
                            # skip scrolling list creation and params push
631
                            next; 
609
                        }
632
                        }
610
                    }
633
                    }
611
                    $labelid = $text;
634
                    $labelid = $text;
Lines 621-634 elsif ($phase eq 'Run this report'){ Link Here
621
                        -multiple => 0,
644
                        -multiple => 0,
622
                        -tabindex => 1,
645
                        -tabindex => 1,
623
                    );
646
                    );
624
                } else {
625
                    $input = "text";
626
                }
647
                }
648
627
                push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
649
                push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
628
            }
650
            }
629
            $template->param('sql'         => $sql,
651
            $template->param('sql'         => $sql,
630
                            'name'         => $name,
652
                            'name'         => $name,
631
                            'sql_params'   => \@tmpl_parameters,
653
                            'sql_params'   => \@tmpl_parameters,
654
                            'auth_val_errors'  => \@authval_errors,
632
                            'enter_params' => 1,
655
                            'enter_params' => 1,
633
                            'reports'      => $report_id,
656
                            'reports'      => $report_id,
634
                            );
657
                            );
635
- 

Return to bug 9659