[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Wed, 30 Apr 2003 18:40:49 -0000
bowersj2 Wed Apr 30 14:40:49 2003 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
Add multiple selection capability to the resource object.
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.13 loncom/interface/lonhelper.pm:1.14
--- loncom/interface/lonhelper.pm:1.13 Wed Apr 30 11:18:36 2003
+++ loncom/interface/lonhelper.pm Wed Apr 30 14:40:49 2003
@@ -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 @@
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 @@
$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 @@
</head>
$bodytag
HEADER
- if (!$state->overrideForm()) { $result.="<form name='wizform' method='GET'>"; }
+ if (!$state->overrideForm()) { $result.="<form name='helpform' method='GET'>"; }
$result .= <<HEADER;
<table border="0"><tr><td>
<h2><i>$stateTitle</i></h2>
@@ -740,22 +740,19 @@
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 @@
BUTTONS
}
- if (defined $self->{ERROR_MSG}) {
+ if (defined $self->{ERRO_MSG}) {
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
}
@@ -1358,6 +1355,7 @@
$paramHash->{'variable'} = $token->[2]{'variable'};
$helper->declareVar($paramHash->{'variable'});
+ $paramHash->{'multichoice'} = $token->[2]{'multichoice'};
return '';
}
@@ -1434,7 +1432,7 @@
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 @@
my $curVal = $helper->{VARS}->{$var};
if (defined $self->{ERROR_MSG}) {
- $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
+ $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
}
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 @@
my $checked = 0;
my $renderColFunc = sub {
my ($resource, $part, $params) = @_;
-
+
+ my $inputType;
+ if ($multichoice) { $inputType = 'checkbox'; }
+ else {$inputType = 'radio'; }
+
if (!&$choiceFunc($resource)) {
return '<td> </td>';
} else {
- my $col = "<td><input type='radio' name='${var}.forminput' ";
- if (!$checked) {
+ my $col = "<td><input type='$inputType' name='${var}.forminput' ";
+ if (!$checked && !$multichoice) {
$col .= "checked ";
$checked = 1;
}
@@ -1503,6 +1506,17 @@
sub postprocess {
my $self = shift;
+
+ if ($self->{'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 @@
'due_date' => "0_duedate",
'answer_date' => "0_answerdate");
- my $result = "<form name='wizform' method='get' action='/adm/parmset'>\n";
+ my $result = "<form name='helpform' method='get' action='/adm/parmset'>\n";
$result .= '<p>Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.<ul>';
my $affectedResourceId = "";
my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}};