Diff for /loncom/interface/Attic/lonwizard.pm between versions 1.10 and 1.11

version 1.10, 2003/02/20 22:10:06 version 1.11, 2003/02/21 18:50:09
Line 132  sub declareVars { Line 132  sub declareVars {
   
  # if there's a form in the env, use that instead   # if there's a form in the env, use that instead
  my $envname = "form." . $element;   my $envname = "form." . $element;
  if (defined ($ENV{$envname}))   if (defined ($ENV{$envname})) {
  {  
     $self->{VARS}->{$element} = $ENV{$envname};      $self->{VARS}->{$element} = $ENV{$envname};
  }   }
                   
Line 470  These methods should be overridden in de Line 469  These methods should be overridden in de
   
 =item B<render>(): render returns a string of itself to be rendered to the screen, which the wizard will display.  =item B<render>(): render returns a string of itself to be rendered to the screen, which the wizard will display.
   
 =back  
   
 =cut   =cut 
   
 package Apache::lonwizard::state;  package Apache::lonwizard::state;
Line 508  sub preprocess { Line 505  sub preprocess {
     return 1;      return 1;
 }  }
   
   =pod
   
   =item * B<process_multiple_choices>(formname, var_name): A service function that correctly handles resources with multiple selections, such as checkboxes. It delimits the selections with triple pipes and stores them in the given wizard variable. 'formname' is the name of the form element to process.
   
   =back
   
   =cut 
   
   sub process_multiple_choices {
       my $self = shift;
       my $formname = shift;
       my $var = shift;
       my $wizard = $self->{WIZARD};
   
       my $formvalue = $ENV{'form.' . $var};
       if ($formvalue) {
           # Must extract values from $wizard->{DATA} directly, as there
           # may be more then one.
           my @values;
           for my $formparam (split (/&/, $wizard->{DATA})) {
               my ($name, $value) = split(/=/, $formparam);
               if ($name ne $var) {
                   next;
               }
               $value =~ tr/+/ /;
               $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
               push @values, $value;
           }
           $wizard->setVar($var, join('|||', @values));
       }
       
       return;
   }
   
 sub render {  sub render {
     return "This is the empty state. If you can see this, it's a bug.\n"      return "This is the empty state. If you can see this, it's a bug.\n"
 }  }
Line 1304  sub postprocess { Line 1335  sub postprocess {
     my $self = shift;      my $self = shift;
     my $wizard = $self->{WIZARD};      my $wizard = $self->{WIZARD};
   
     my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'};      $self->process_multiple_choices($self->{VAR_NAME}.'.forminput',
     if ($formvalue) {                                      $self->{VAR_NAME});
         # Must extract values from $wizard->{DATA} directly, as there  
         # may be more then one.  
         my @values;  
         for my $formparam (split (/&/, $wizard->{DATA})) {  
             my ($name, $value) = split(/=/, $formparam);  
             if ($name ne $self->{VAR_NAME} . '.forminput') {  
                 next;  
             }  
             $value =~ tr/+/ /;  
             $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;  
             push @values, $value;  
         }  
         $wizard->setVar($self->{VAR_NAME}, join('|||', @values));  
     }      
   
     # If nothing was selected...      # If nothing was selected...
     if (!$wizard->{VARS}->{$self->{VAR_NAME}}) {      if (!$wizard->{VARS}->{$self->{VAR_NAME}}) {
Line 1576  sub postprocess { Line 1593  sub postprocess {
     my $self = shift;      my $self = shift;
     print $self->{NEXT_STATE};      print $self->{NEXT_STATE};
     my $wizard = $self->{WIZARD};      my $wizard = $self->{WIZARD};
     my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'};  
   
     if ($formvalue) {      $self->process_multiple_choices($self->{VAR_NAME}.'.forminput',
         # Must extract values from $wizard->{DATA} directly, as there                                      $self->{VAR_NAME});
         # may be more then one.      
         my @values;      if (!$wizard->{VARS}->{$self->{VAR_NAME}}) {
         for my $formparam (split (/&/, $wizard->{DATA})) {  
             my ($name, $value) = split(/=/, $formparam);  
             if ($name ne $self->{VAR_NAME} . '.forminput') {  
                 next;  
             }  
             $value =~ tr/+/ /;  
             $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;  
             push @values, $value;  
         }  
         $wizard->setVar($self->{VAR_NAME}, join('|||', @values));  
         $wizard->changeState($self->{NEXT_STATE});  
     } else {  
         $self->{ERROR_MSG} = "Can't continue the wizard because you ".          $self->{ERROR_MSG} = "Can't continue the wizard because you ".
             "must make a selection to continue.";              "must make a selection to continue.";
     }      }

Removed from v.1.10  
changed lines
  Added in v.1.11


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>