+//
+
+CHECK
+ $result.=" or '
+ }
return $result;
}
@@ -1650,41 +1684,44 @@ sub render {
sub postprocess {
my $self = shift;
my $var = $self->{'variable'};
- my $month = $env{'form.' . $var . 'month'};
- my $day = $env{'form.' . $var . 'day'};
- my $year = $env{'form.' . $var . 'year'};
- my $min = 0;
- my $hour = 0;
- if ($self->{'hoursminutes'}) {
- $min = $env{'form.' . $var . 'minute'};
- $hour = $env{'form.' . $var . 'hour'};
- }
+ if ($env{'form.' . $var . 'anytime'}) {
+ $helper->{VARS}->{$var} = undef;
+ } else {
+ my $month = $env{'form.' . $var . 'month'};
+ my $day = $env{'form.' . $var . 'day'};
+ my $year = $env{'form.' . $var . 'year'};
+ my $min = 0;
+ my $hour = 0;
+ if ($self->{'hoursminutes'}) {
+ $min = $env{'form.' . $var . 'minute'};
+ $hour = $env{'form.' . $var . 'hour'};
+ }
+
+ my $chosenDate;
+ eval {$chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year);};
+ my $error = $@;
+
+ # Check to make sure that the date was not automatically co-erced into a
+ # valid date, as we want to flag that as an error
+ # This happens for "Feb. 31", for instance, which is coerced to March 2 or
+ # 3, depending on if it's a leap year
+ my $checkDate = localtime($chosenDate);
+
+ if ($error || $checkDate->mon != $month || $checkDate->mday != $day ||
+ $checkDate->year + 1900 != $year) {
+ unless (Apache::lonlocal::current_language()== ~/^en/) {
+ $self->{ERROR_MSG} = &mt("Invalid date entry");
+ return 0;
+ }
+ # LOCALIZATION FIXME: Needs to be parameterized
+ $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "
+ . "date because it doesn't exist. Please enter a valid date.";
- my $chosenDate;
- eval {$chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year);};
- my $error = $@;
-
- # Check to make sure that the date was not automatically co-erced into a
- # valid date, as we want to flag that as an error
- # This happens for "Feb. 31", for instance, which is coerced to March 2 or
- # 3, depending on if it's a leap year
- my $checkDate = localtime($chosenDate);
-
- if ($error || $checkDate->mon != $month || $checkDate->mday != $day ||
- $checkDate->year + 1900 != $year) {
- unless (Apache::lonlocal::current_language()== ~/^en/) {
- $self->{ERROR_MSG} = &mt("Invalid date entry");
return 0;
}
- # LOCALIZATION FIXME: Needs to be parameterized
- $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "
- . "date because it doesn't exist. Please enter a valid date.";
-
- return 0;
+ $helper->{VARS}->{$var} = $chosenDate;
}
- $helper->{VARS}->{$var} = $chosenDate;
-
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
@@ -1930,7 +1967,8 @@ sub render {
if ($self->{'multichoice'}) {
$result = <
SCRIPT
my %lt=&Apache::lonlocal::texthash(
@@ -1978,6 +2017,17 @@ BUTTONS
$mapUrl = $self->{MAP_URL};
}
+ my @defaultSymbs;
+ if (defined($self->{DEFAULT_VALUE})) {
+ my $valueFunc = eval($self->{DEFAULT_VALUE});
+ die 'Error in default value code for variable ' .
+ $self->{'variable'} . ', Perl said: ' . $@ if $@;
+ @defaultSymbs = &$valueFunc($helper, $self);
+ if (!$multichoice) { # only allowed 1
+ @defaultSymbs = ($defaultSymbs[0]);
+ }
+ }
+
# 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
@@ -2026,13 +2076,21 @@ BUTTONS
}
$col .= "symb();
+ if (grep(/\Q$symb\E/,@defaultSymbs)) {
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
+ } else {
+ if (!$checked && !$multichoice) {
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
+ if ($multichoice) { # all resources start checked; see bug 1174
+ $col .= "checked='checked' ";
+ $checked = 1;
+ }
}
$col .= "value='" . $resource_name . "' /> | ";
@@ -2057,6 +2115,7 @@ BUTTONS
};
$result.=(<
+//
@@ -2148,6 +2208,10 @@ selection. Defaults to false.
If true, only active students and course personnel will be
shown. Defaults to false.
+=item * B:
+
+If true, the selection of no users is allowed. Defaults to false.
+
=back
=cut
@@ -2183,6 +2247,7 @@ sub start_student {
if (defined($token->[2]{'nextstate'})) {
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};
}
+ $paramHash->{'emptyallowed'} = $token->[2]{'emptyallowed'};
}
@@ -2203,7 +2268,8 @@ sub render {
if ($self->{'multichoice'}) {
$result = <
SCRIPT
@@ -2250,23 +2354,12 @@ SCRIPT
$buttons = <
BUTTONS
@@ -2364,8 +2457,51 @@ BUTTONS
}
$result .= "\n\n";
- $result .= $buttons;
-
+ $result .= $buttons;
+ #
+ # now add the fancy section choice... first enumerate the sections:
+ if ($self->{'multichoice'}) {
+ my %sections;
+ for my $key (@keys) {
+ my $section_name = $classlist->{$key}->[$section];
+ if ($section_name ne "") {
+ $sections{$section_name} = 1;
+ }
+ }
+ # The variable $choice_widget will have the html to make the choice
+ # selector.
+ my $size=5;
+ if (scalar(keys(%sections)) < 5) {
+ $size=scalar(keys(%sections));
+ }
+ my $choice_widget = '\n";
+
+ # Build a table without any borders to contain the section based
+ # selection:
+
+ my $section_selectors =<
+
+ For Sections: | $choice_widget |
+ |
+ |
+ |
+
+
+ |
+ |
+
+
+SECTIONSELECT
+ $result .= $section_selectors;
+ }
return $result;
}
@@ -2373,9 +2509,14 @@ sub postprocess {
my $self = shift;
my $result = $env{'form.' . $self->{'variable'} . '.forminput'};
- if (!$result) {
- $self->{ERROR_MSG} =
- &mt('You must choose at least one student to continue.');
+ if (!$result && !$self->{'emptyallowed'}) {
+ if ($self->{'coursepersonnel'}) {
+ $self->{ERROR_MSG} =
+ &mt('You must choose at least one user to continue.');
+ } else {
+ $self->{ERROR_MSG} =
+ &mt('You must choose at least one student to continue.');
+ }
return 0;
}
@@ -2547,7 +2688,8 @@ sub render {
if ($self->{'multichoice'}) {
$result = <
SCRIPT
my %lt=&Apache::lonlocal::texthash(