--- loncom/interface/Attic/lonwizard.pm 2003/02/27 19:42:59 1.13 +++ loncom/interface/Attic/lonwizard.pm 2003/02/27 21:01:09 1.14 @@ -522,14 +522,14 @@ sub process_multiple_choices { my $var = shift; my $wizard = $self->{WIZARD}; - my $formvalue = $ENV{'form.' . $var}; + my $formvalue = $ENV{'form.' . $formname}; 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) { + if ($name ne $formname) { next; } $value =~ tr/+/ /; @@ -719,15 +719,9 @@ BUTTONS my $choices = $self->{CHOICE_HASH}; my @keys = keys (%$choices); - my $multichoice = ''; - if ($self->{MULTICHOICE}) { - $multichoice = 'multichoice="true" '; - } - my $type = "radio"; if ($self->{MULTICHOICE}) { $type = 'checkbox'; } - foreach (@keys) - { + foreach (@keys) { $result .= " " . HTML::Entities::encode($_) . "
\n"; } - if (defined $self->{MESSAGE_AFTER}) - { + if (defined $self->{MESSAGE_AFTER}) { $result .= '

' . $self->{MESSAGE_AFTER}; } @@ -749,7 +742,11 @@ sub postprocess { my $wizard = $self->{WIZARD}; my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; if ($formvalue) { - # Value already stored by Wizard + if ($self->{MULTICHOICE}) { + $self->process_multiple_choices($self->{VAR_NAME}.'.forminput', + $self->{VAR_NAME}); + } + # For non-multichoice, value already stored by Wizard $wizard->changeState($self->{NEXT_STATE}); } else { $self->{ERROR_MSG} = "Can't continue the wizard because you must make" @@ -1450,28 +1447,107 @@ BUTTONS package Apache::lonwizard::choose_student; no strict; -@ISA = ("Apache::lonwizard::choice_state"); +@ISA = ("Apache::lonwizard::state"); use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; - my $self = bless $proto->SUPER::new(shift, shift, shift, shift, - shift, shift, shift, undef, shift); + my $self = bless $proto->SUPER::new(shift, shift, shift); + + $self->{MESSAGE_BEFORE} = shift; + $self->{NEXT_STATE} = shift; + $self->{VAR_NAME} = shift; + $self->{MULTICHOICE} = shift; + return $self; } -sub determineChoices { - my %choices; +sub render { + my $self = shift; + my $result = ''; + my $var = $self->{VAR_NAME}; + my $buttons = ''; - my $classlist = Apache::loncoursedata::get_classlist(); - foreach (keys %$classlist) { - $choices{$classlist->{$_}->[6]} = $_; + if ($self->{MULTICHOICE}) { + $result = < + function checkall(value) { + for (i=0; i +SCRIPT + $buttons = < + +
+BUTTONS + } + + if (defined $self->{ERROR_MSG}) { + $result .= '' . $self->{ERROR_MSG} . '

'; + } + + if (defined $self->{MESSAGE_BEFORE}) { + $result .= $self->{MESSAGE_BEFORE} . '

'; + } + + $result .= $buttons; + + my $choices = &Apache::loncoursedata::get_classlist(); + + my @keys = keys %{$choices}; + # Sort by: Section, name + + @keys = sort { + if ($choices->{$a}->[3] ne $choices->{$b}->[3]) { + return $choices->{$a}->[3] cmp $choices->{$b}->[3]; + } + return $choices->{$a}->[6] cmp $choices->{$b}->[6]; + } @keys; + + my $type = 'radio'; + if ($self->{MULTICHOICE}) { $type = 'checkbox'; } + $result .= "\n"; + $result .= "". + ""; + + foreach (@keys) { + $result .= "\n"; + } + + $result .= "
Student NameSection
" . HTML::Entities::encode($choices->{$_}->[6]) + . "" + . HTML::Entities::encode($choices->{$_}->[5]) + . "
\n\n"; + $result .= $buttons; + + return $result; } +sub postprocess { + my $self = shift; + my $wizard = $self->{WIZARD}; + my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; + if ($formvalue) { + if ($self->{MULTICHOICE}) { + $self->process_multiple_choices($self->{VAR_NAME}.'.forminput', + $self->{VAR_NAME}); + } + $wizard->changeState($self->{NEXT_STATE}); + } else { + $self->{ERROR_MSG} = "Can't continue the wizard because you must make" + . ' a selection to continue.'; + } + return 1; +} + + 1; package Apache::lonwizard::choose_section;