version 1.13, 2003/02/27 19:42:59
|
version 1.14, 2003/02/27 21:01:09
|
Line 522 sub process_multiple_choices {
|
Line 522 sub process_multiple_choices {
|
my $var = shift; |
my $var = shift; |
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
|
|
my $formvalue = $ENV{'form.' . $var}; |
my $formvalue = $ENV{'form.' . $formname}; |
if ($formvalue) { |
if ($formvalue) { |
# Must extract values from $wizard->{DATA} directly, as there |
# Must extract values from $wizard->{DATA} directly, as there |
# may be more then one. |
# may be more then one. |
my @values; |
my @values; |
for my $formparam (split (/&/, $wizard->{DATA})) { |
for my $formparam (split (/&/, $wizard->{DATA})) { |
my ($name, $value) = split(/=/, $formparam); |
my ($name, $value) = split(/=/, $formparam); |
if ($name ne $var) { |
if ($name ne $formname) { |
next; |
next; |
} |
} |
$value =~ tr/+/ /; |
$value =~ tr/+/ /; |
Line 719 BUTTONS
|
Line 719 BUTTONS
|
my $choices = $self->{CHOICE_HASH}; |
my $choices = $self->{CHOICE_HASH}; |
my @keys = keys (%$choices); |
my @keys = keys (%$choices); |
|
|
my $multichoice = ''; |
|
if ($self->{MULTICHOICE}) { |
|
$multichoice = 'multichoice="true" '; |
|
} |
|
|
|
my $type = "radio"; |
my $type = "radio"; |
if ($self->{MULTICHOICE}) { $type = 'checkbox'; } |
if ($self->{MULTICHOICE}) { $type = 'checkbox'; } |
foreach (@keys) |
foreach (@keys) { |
{ |
|
|
|
$result .= "<input type='$type' name='" . |
$result .= "<input type='$type' name='" . |
$self->{VAR_NAME} . '.forminput' . |
$self->{VAR_NAME} . '.forminput' . |
Line 736 BUTTONS
|
Line 730 BUTTONS
|
. "\"/> " . HTML::Entities::encode($_) . "<br />\n"; |
. "\"/> " . HTML::Entities::encode($_) . "<br />\n"; |
} |
} |
|
|
if (defined $self->{MESSAGE_AFTER}) |
if (defined $self->{MESSAGE_AFTER}) { |
{ |
|
$result .= '<br /><br />' . $self->{MESSAGE_AFTER}; |
$result .= '<br /><br />' . $self->{MESSAGE_AFTER}; |
} |
} |
|
|
Line 749 sub postprocess {
|
Line 742 sub postprocess {
|
my $wizard = $self->{WIZARD}; |
my $wizard = $self->{WIZARD}; |
my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; |
my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; |
if ($formvalue) { |
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}); |
$wizard->changeState($self->{NEXT_STATE}); |
} else { |
} else { |
$self->{ERROR_MSG} = "Can't continue the wizard because you must make" |
$self->{ERROR_MSG} = "Can't continue the wizard because you must make" |
Line 1450 BUTTONS
|
Line 1447 BUTTONS
|
package Apache::lonwizard::choose_student; |
package Apache::lonwizard::choose_student; |
|
|
no strict; |
no strict; |
@ISA = ("Apache::lonwizard::choice_state"); |
@ISA = ("Apache::lonwizard::state"); |
use strict; |
use strict; |
|
|
sub new { |
sub new { |
my $proto = shift; |
my $proto = shift; |
my $class = ref($proto) || $proto; |
my $class = ref($proto) || $proto; |
my $self = bless $proto->SUPER::new(shift, shift, shift, shift, |
my $self = bless $proto->SUPER::new(shift, shift, shift); |
shift, shift, shift, undef, shift); |
|
|
$self->{MESSAGE_BEFORE} = shift; |
|
$self->{NEXT_STATE} = shift; |
|
$self->{VAR_NAME} = shift; |
|
$self->{MULTICHOICE} = shift; |
|
|
return $self; |
return $self; |
} |
} |
|
|
sub determineChoices { |
sub render { |
my %choices; |
my $self = shift; |
|
my $result = ''; |
|
my $var = $self->{VAR_NAME}; |
|
my $buttons = ''; |
|
|
my $classlist = Apache::loncoursedata::get_classlist(); |
if ($self->{MULTICHOICE}) { |
foreach (keys %$classlist) { |
$result = <<SCRIPT; |
$choices{$classlist->{$_}->[6]} = $_; |
<script> |
|
function checkall(value) { |
|
for (i=0; i<document.forms.wizform.elements.length; i++) { |
|
document.forms.wizform.elements[i].checked=value; |
|
} |
} |
} |
|
</script> |
return \%choices; |
SCRIPT |
|
$buttons = <<BUTTONS; |
|
<input type="button" onclick="checkall(true)" value="Select All" /> |
|
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
|
<br /> |
|
BUTTONS |
|
} |
|
|
|
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
|
} |
|
|
|
if (defined $self->{MESSAGE_BEFORE}) { |
|
$result .= $self->{MESSAGE_BEFORE} . '<br /><br />'; |
|
} |
|
|
|
$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 .= "<table cellspacing='2' cellpadding='2' border='0'>\n"; |
|
$result .= "<tr><td></td><td align='center'><b>Student Name</b></td>". |
|
"<td align='center'><b>Section</b></td></tr>"; |
|
|
|
foreach (@keys) { |
|
$result .= "<tr><td><input type='$type' name='" . |
|
$self->{VAR_NAME} . '.forminput' . |
|
"' value='" . HTML::Entities::encode($_) |
|
. "' /></td><td>" . HTML::Entities::encode($choices->{$_}->[6]) |
|
. "</td><td align='center'>" |
|
. HTML::Entities::encode($choices->{$_}->[5]) |
|
. "</td></tr>\n"; |
|
} |
|
|
|
$result .= "</table>\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; |
1; |
|
|
package Apache::lonwizard::choose_section; |
package Apache::lonwizard::choose_section; |