--- loncom/interface/lonhelper.pm 2003/04/30 15:18:36 1.13 +++ loncom/interface/lonhelper.pm 2003/04/30 18:40:49 1.14 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.13 2003/04/30 15:18:36 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.14 2003/04/30 18:40:49 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -202,8 +202,6 @@ sub handler { my $file; read $fh, $file, 100000000; - Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - # Send header, don't cache this page if ($r->header_only) { if ($ENV{'browser.mathml'}) { @@ -324,6 +322,8 @@ sub new { $self->{STATE} = "START"; } + Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); + $self->{TOKEN} = $ENV{'form.TOKEN'}; # If a token was passed, we load that in. Otherwise, we need to create a # new storage file @@ -506,7 +506,7 @@ sub display { $bodytag HEADER - if (!$state->overrideForm()) { $result.="
"; } + if (!$state->overrideForm()) { $result.=""; } $result .= <

$stateTitle

@@ -740,22 +740,19 @@ sub process_multiple_choices { my $formname = shift; my $var = shift; - my $formvalue = $ENV{'form.' . $formname}; - if ($formvalue) { - # Must extract values from querystring directly, as there - # may be more then one. - my @values; - for my $formparam (split (/&/, $ENV{QUERY_STRING})) { - my ($name, $value) = split(/=/, $formparam); - if ($name ne $formname) { - next; - } - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; - push @values, $value; + # Must extract values from data directly, as there + # may be more then one. + my @values; + for my $formparam (split (/&/, $ENV{QUERY_STRING})) { + my ($name, $value) = split(/=/, $formparam); + if ($name ne $formname) { + next; } - $helper->{VARS}->{$var} = join('|||', @values); + $value =~ tr/+/ /; + $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; + push @values, $value; } + $helper->{VARS}->{$var} = join('|||', @values); return; } @@ -1005,7 +1002,7 @@ SCRIPT BUTTONS } - if (defined $self->{ERROR_MSG}) { + if (defined $self->{ERRO_MSG}) { $result .= '
' . $self->{ERROR_MSG} . '
'; } @@ -1358,6 +1355,7 @@ sub start_resource { $paramHash->{'variable'} = $token->[2]{'variable'}; $helper->declareVar($paramHash->{'variable'}); + $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; return ''; } @@ -1434,7 +1432,7 @@ sub start_mapurl { my $contents = Apache::lonxml::get_all_text('/mapurl', $parser); - $paramHash->{MAP_URL} = eval $contents; + $paramHash->{MAP_URL} = $contents; } sub end_mapurl { return ''; } @@ -1458,13 +1456,14 @@ sub render { my $curVal = $helper->{VARS}->{$var}; if (defined $self->{ERROR_MSG}) { - $result .= '' . $self->{ERROR_MSG} . '

'; + $result .= '
' . $self->{ERROR_MSG} . '

'; } my $filterFunc = $self->{FILTER_FUNC}; my $choiceFunc = $self->{CHOICE_FUNC}; my $valueFunc = $self->{VALUE_FUNC}; my $mapUrl = $self->{MAP_URL}; + my $multichoice = $self->{'multichoice'}; # Create the composite function that renders the column on the nav map # have to admit any language that lets me do this can't be all bad @@ -1472,12 +1471,16 @@ sub render { my $checked = 0; my $renderColFunc = sub { my ($resource, $part, $params) = @_; - + + my $inputType; + if ($multichoice) { $inputType = 'checkbox'; } + else {$inputType = 'radio'; } + if (!&$choiceFunc($resource)) { return ' '; } else { - my $col = "{'multichoice'}) { + $self->process_multiple_choices($self->{'variable'}.'.forminput', + $self->{'variable'}); + } + + if ($self->{'multichoice'} && !$helper->{VARS}->{$self->{'variable'}}) { + $self->{ERROR_MSG} = 'You must choose at least one resource to continue.'; + return 0; + } + if (defined($self->{NEXTSTATE})) { $helper->changeState($self->{NEXTSTATE}); } @@ -2130,7 +2144,7 @@ sub render { 'due_date' => "0_duedate", 'answer_date' => "0_answerdate"); - my $result = "\n"; + my $result = "\n"; $result .= '

Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.