--- loncom/interface/lonhelper.pm 2005/07/12 16:03:12 1.111
+++ loncom/interface/lonhelper.pm 2005/10/11 20:57:54 1.118
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.111 2005/07/12 16:03:12 albertel Exp $
+# $Id: lonhelper.pm,v 1.118 2005/10/11 20:57:54 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1188,7 +1188,8 @@ sub render {
if ($self->{'multichoice'}) {
$result .= <
SCRIPT
}
@@ -1436,7 +1438,7 @@ sub render {
$choiceLabel = eval($choiceLabel);
$choiceLabel = &$choiceLabel($helper, $self);
}
- $result .= ">" . &mtn($choiceLabel) . "\n";
+ $result .= ">" . &mtn($choiceLabel) . "\n";
}
$result .= "\n";
@@ -1534,6 +1536,7 @@ sub start_date {
$paramHash->{'variable'} = $token->[2]{'variable'};
$helper->declareVar($paramHash->{'variable'});
$paramHash->{'hoursminutes'} = $token->[2]{'hoursminutes'};
+ $paramHash->{'anytime'} = $token->[2]{'anytime'};
}
sub end_date {
@@ -1552,9 +1555,19 @@ sub render {
my $var = $self->{'variable'};
my $date;
-
+
+ my $time=time;
+ my $anytime;
+
+ if (defined($self->{DEFAULT_VALUE})) {
+ my $valueFunc = eval($self->{DEFAULT_VALUE});
+ die('Error in default value code for variable ' .
+ $self->{'variable'} . ', Perl said: ' . $@) if $@;
+ $time = &$valueFunc($helper, $self);
+ if (lc($time) eq 'anytime') { $time=time; $anytime=1; }
+ }
# Default date: The current hour.
- $date = localtime();
+ $date = localtime($time);
$date->min(0);
if (defined $self->{ERROR_MSG}) {
@@ -1628,9 +1641,9 @@ sub render {
$result .= " :\n";
$result .= "\n";
}
-
+ if ($self->{'anytime'}) {
+ $result.=" or '
+ }
return $result;
}
@@ -1650,41 +1669,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 +1952,8 @@ sub render {
if ($self->{'multichoice'}) {
$result = <
SCRIPT
my %lt=&Apache::lonlocal::texthash(
@@ -2057,6 +2081,7 @@ BUTTONS
};
$result.=(<
+//
@@ -2203,7 +2229,8 @@ sub render {
if ($self->{'multichoice'}) {
$result = <
SCRIPT
@@ -2250,23 +2315,12 @@ SCRIPT
$buttons = <
-
-
-
-
-
-
-
-
-
-
-
-
+
BUTTONS
@@ -2364,8 +2418,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 =<
+