Skip to main content.
home | support | download

Back to List Archive

Configuration of the example CGI (swish.cgi)

From: Tajoli Zeno <tajoli(at)not-real.cilea.it>
Date: Thu Mar 27 2003 - 10:59:53 GMT
At 10.01 26/03/03 -0800, you wrote:
Hi,

that code comes from version 2.3.4

>Look at example/modules/SWISH/DateRanges.pm  That's where is should be
>changed.
>
>     my %Num_to_label;
>     my %Label_to_num;
>     my $i = 1;
>     for ( @TIME_PERIODS ) {
>         my $label = $_;
>         $label =~ s/ /&nbsp;/g;
>         $Num_to_label{$i} = $label;
>         $Label_to_num{$_} = $i++;
>     }

but in fact I'm working on 2.2.3. It's the 2.3.4 so stable to be used in 
production ?

In found a way to have a good results in version 2.2.3 .

In fact in 2.2.3 the module DateRanges.pm uses the 'values' in the second 
radio button group
  also as 'labels'.
The code in version 2.2.3 is so:

sub DateRangeForm {
..
      $fields->{buttons} =
           $CGI->radio_group(
             -name       => 'DateRanges_date_option',
             -values     => \@time_periods,
             -default    => ($params->{default} || $time_periods[0]),
             -linebreak  => (exists $params->{line_break} ? 
$params->{line_break} : 1),
             #-columns=>2,
           ) if @time_periods;
..

You can see that the code defines 'name', 'values', 'default', 'linebreak' 
but not 'labels'.
So 'label' are the same of 'values'.

Because I want to change the labels, but not the values, I modified so the 
DateRanges.pm for the version 2.2.3


1) after the definition of @TIME_PERIODS (lines 79-92) I add an hash with 
all possible keys/values:

  my %LABEL_TIME_PERIODS =(
         'All' => 'Tutto',
         'Yesterday' => 'Ieri',
         'Today' => 'Oggi',
         'Yesterday onward' => 'Ieri avanti',
         'This Week' => 'Questa settimana',
         'Last Week' => 'Ultima settimana',
         'Last 90 Days'=> 'Ultimi 90 giorni',
         'This Month' => 'Questo mese',
         'Last Month'=> 'Ultimo mese',
         'Past' => 'Passato',
         'Future' => 'Futuro',
         'Next 30 Days',
     );

2) In the sub DateRangeForm I add a line

     $fields->{buttons} =
           $CGI->radio_group(
             -name       => 'DateRanges_date_option',
             -values     => \@time_periods,
             -default    => ($params->{default} || $time_periods[0]),
             -linebreak  => (exists $params->{line_break} ? 
$params->{line_break} : 1),
             #-columns=>2,
             -labels      => \%LABEL_TIME_PERIODS, #Line that I have add
           ) if @time_periods;

3) I found that I need to list the values in the same order:

..
     my %hash = (
         date_ranges     => {

             # Define what buttons to include
             time_periods    => [
                 'All',
                 'Today',
                 'Yesterday',
                 #'Yesterday onward',
                 'This Week',
                 'Last Week',
                 'Last 90 Days',
                 'This Month',
                 'Last Month',
                 #'Past',
                 #'Future',
                 #'Next 30 Days',
             ],
..

     # what to pick from
     my @TIME_PERIODS = (
         'All',
         'Today',
         'Yesterday',
         #'Yesterday onward',
         'This Week',
         'Last Week',
         'Last 90 Days',
         'This Month',
         'Last Month',
         #'Past',
         #'Future',
         #'Next 30 Days',
     );


Thanks for all.

Bye

Zeno Tajoli
tajoli@cilea.it
CILEA - Segrate (MI)
02 / 26995321
Received on Thu Mar 27 11:01:01 2003