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

version 1.10, 2003/02/20 22:10:06 version 1.12, 2003/02/21 21:27:28
Line 30  use Apache::loncommon; Line 30  use Apache::loncommon;
   
 =head1 Class: lonwizard  =head1 Class: lonwizard
   
   FIXME: Doc the parameters of the wizard well: Title, Data (Query string), URL.
   
 =head2 lonwizard Attributes  =head2 lonwizard Attributes
   
 =over 4  =over 4
Line 59  sub new { Line 61  sub new {
   
     $self->{TITLE} = shift;      $self->{TITLE} = shift;
     $self->{DATA} = shift;      $self->{DATA} = shift;
       $self->{URL} = shift;
     &Apache::loncommon::get_unprocessed_cgi($self->{DATA});      &Apache::loncommon::get_unprocessed_cgi($self->{DATA});
   
   
Line 132  sub declareVars { Line 135  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 215  sub display { Line 217  sub display {
     if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->")      if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->")
     {      {
  my $prevState = $self->{STATES}{$self->{STATE}};   my $prevState = $self->{STATES}{$self->{STATE}};
  $prevState->postprocess();              $prevState->postprocess();
     }      }
           
     # Note, to handle errors in a state's input that a user must correct,      # Note, to handle errors in a state's input that a user must correct,
Line 470  These methods should be overridden in de Line 472  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 508  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 1243  sub render { Line 1277  sub render {
                                                   Apache::lonnavmaps::resource()],                                                    Apache::lonnavmaps::resource()],
                                        'showParts' => 0,                                         'showParts' => 0,
                                        'queryString' => $wizard->queryStringVars() . '&folderManip=1',                                         'queryString' => $wizard->queryStringVars() . '&folderManip=1',
                                        'url' => '/adm/wizard',                                         'url' => $wizard->{URL},
                                        'filterFunc' => $filterFunc } );                                         'filterFunc' => $filterFunc } );
                                                                                                   
     $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER});      $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER});
Line 1304  sub postprocess { Line 1338  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 1596  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.12


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