";
@@ -614,9 +635,9 @@ HEADER
$result .= "" . &mt("End Helper") . " ";
}
else {
- $result .= ' ';
- $result .= ' ';
+ $result .= ' ';
}
}
@@ -633,9 +654,9 @@ HEADER
$result .= "" . &mt('End Helper') . " ";
}
else {
- $result .= ' ';
- $result .= ' ';
+ $result .= ' ';
}
}
@@ -678,6 +699,7 @@ sub new {
$self->{NAME} = shift;
$self->{TITLE} = shift;
+ $self->{HELP} = shift;
$self->{ELEMENTS} = [];
bless($self, $class);
@@ -699,6 +721,11 @@ sub title {
return $self->{TITLE};
}
+sub help {
+ my $self = shift;
+ return $self->{HELP};
+}
+
sub preprocess {
my $self = shift;
for my $element (@{$self->{ELEMENTS}}) {
@@ -790,7 +817,7 @@ the element. How this value is interpret
the element itself, and possibly the settings the element has (such as
multichoice vs. single choice for tags).
-This is also intended for things like the course initialization wizard, where the
+This is also intended for things like the course initialization helper, where the
user is setting various parameters. By correctly grabbing current settings
and including them into the helper, it allows the user to come back to the
helper later and re-execute it, without needing to worry about overwriting
@@ -992,6 +1019,9 @@ sub start_message {
if (defined($token->[2]{'nextstate'})) {
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};
}
+ if (defined($token->[2]{'type'})) {
+ $paramHash->{TYPE} = $token->[2]{'type'};
+ }
return '';
}
@@ -1007,8 +1037,16 @@ sub end_message {
sub render {
my $self = shift;
-
- return &mtn($self->{MESSAGE_TEXT});
+
+ if ($self->{TYPE} =~ /^\s*warning\s*$/i) {
+ $self->{MESSAGE_TEXT} =
+ ''. $self->{MESSAGE_TEXT}.' ';
+ }
+ if ($self->{TYPE} =~ /^\s*error\s*$/i) {
+ $self->{MESSAGE_TEXT} =
+ ''. $self->{MESSAGE_TEXT}.' ';
+ }
+ return $self->{MESSAGE_TEXT};
}
# If a NEXTSTATE was given, switch to it
sub postprocess {
@@ -1021,6 +1059,175 @@ sub postprocess {
}
1;
+package Apache::lonhelper::helpicon;
+
+=pod
+
+=head1 Elements
+
+=head2 Element: helpiconX
+
+Helpicon elements add a help icon at the current location.
+Example:
+
+
+ General Help
+
+
+In this example will generate a help icon to the Help.hlp url with a
+description of 'General Help'. The description is not required and if
+left out (Example: only the icon will be
+added.)
+
+=head3 Localization
+
+The description text will be run through the normalize_string function
+and that will be used as a call to &mt.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+use Apache::lonlocal;
+
+BEGIN {
+ &Apache::lonhelper::register('Apache::lonhelper::helpicon',
+ ('helpicon'));
+}
+
+sub new {
+ my $ref = Apache::lonhelper::element->new();
+ bless($ref);
+}
+
+# CONSTRUCTION: Construct the message element from the XML
+sub start_helpicon {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ $paramHash->{HELP_TEXT} = &mtn(&Apache::lonxml::get_all_text('/helpicon',
+ $parser));
+
+ $paramHash->{HELP_TEXT} =~s/^\s+//;
+ $paramHash->{HELP_TEXT} =~s/\s+$//;
+
+ if (defined($token->[2]{'file'})) {
+ $paramHash->{HELP_FILE} = $token->[2]{'file'};
+ }
+ return '';
+}
+
+sub end_helpicon {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+ Apache::lonhelper::helpicon->new();
+ return '';
+}
+
+sub render {
+ my $self = shift;
+
+ my $text;
+ if ( $self->{HELP_TEXT} ne '') {
+ $text=&mtn($self->{HELP_TEXT});
+ }
+
+ return &Apache::loncommon::help_open_topic($self->{HELP_FILE},
+ $text);
+}
+sub postprocess {
+ my $self = shift;
+ if (defined($self->{NEXTSTATE})) {
+ $helper->changeState($self->{NEXTSTATE});
+ }
+
+ return 1;
+}
+
+1;
+
+package Apache::lonhelper::skip;
+
+=pod
+
+=head1 Elements
+
+=head2 Element: skipX
+
+The tag allows you define conditions under which the current state
+should be skipped over and define what state to skip to.
+
+
+
+
+ #some code that decides whether to skip the state or not
+
+ FINISH
+
+ A possibly skipped state
+
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+ &Apache::lonhelper::register('Apache::lonhelper::skip',
+ ('skip'));
+}
+
+sub new {
+ my $ref = Apache::lonhelper::element->new();
+ bless($ref);
+}
+
+sub start_skip {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+ # let know what text to skip to
+ $paramHash->{SKIPTAG}='/skip';
+ return '';
+}
+
+sub end_skip {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+ Apache::lonhelper::skip->new();
+ return '';
+}
+
+sub render {
+ my $self = shift;
+ return '';
+}
+# If a NEXTSTATE is set, switch to it
+sub preprocess {
+ my ($self) = @_;
+
+ if (defined($self->{NEXTSTATE})) {
+ $helper->changeState($self->{NEXTSTATE});
+ }
+
+ return 1;
+}
+
+1;
+
package Apache::lonhelper::choices;
=pod
@@ -1203,7 +1410,7 @@ sub render {
function checkall(value, checkName) {
for (i=0; i{CHOICES}}) {
my $id = &new_id();
$result .= "\n \n";
- $result .= " }.
- $choiceLabel. " ";
+ $choiceLabel. "";
if ($choice->[4]) {
$result .=' ';
}
$result .= " \n";
@@ -1310,7 +1517,8 @@ BUTTONS
# given, switch to it
sub postprocess {
my $self = shift;
- my $chosenValue = $env{'form.' . $self->{'variable'} . '.forminput'};
+ my $chosenValue = $env{'form.' . $self->{'variable'} . '_forminput'};
+
if (!defined($chosenValue) && !$self->{'allowempty'}) {
$self->{ERROR_MSG} =
@@ -1318,6 +1526,8 @@ sub postprocess {
return 0;
}
+
+
if (ref($chosenValue)) {
$helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue);
}
@@ -1334,7 +1544,7 @@ sub postprocess {
}
if ($choice->[4]) {
my $varname = $choice->[4];
- $helper->{'VARS'}->{$varname} = $env{'form.'."$varname.forminput"};
+ $helper->{'VARS'}->{$varname} = $env{'form.'."${varname}_forminput"};
}
}
return 1;
@@ -1443,7 +1653,7 @@ sub render {
$checkedChoices{$self->{CHOICES}->[0]->[1]} = 1;
}
- $result .= "\n";
+ $result .= "\n";
foreach my $choice (@{$self->{CHOICES}}) {
$result .= "{'variable'} . '.forminput'};
+ my $chosenValue = $env{'form.' . $self->{'variable'} . '_forminput'};
if (!defined($chosenValue) && !$self->{'allowempty'}) {
$self->{ERROR_MSG} = "You must choose one or more choices to" .
@@ -1529,7 +1739,7 @@ no strict;
use strict;
use Apache::lonlocal; # A localization nightmare
use Apache::lonnet;
-use Time::localtime;
+use DateTime;
BEGIN {
&Apache::lonhelper::register('Apache::lonhelper::date',
@@ -1579,14 +1789,13 @@ sub render {
my $time=time;
my ($anytime,$onclick);
-
# first check VARS for a valid new value from the user
# then check DEFAULT_VALUE for a valid default time value
# otherwise pick now as reasonably good time
if (defined($helper->{VARS}{$var})
&& $helper->{VARS}{$var} > 0) {
- $date = localtime($helper->{VARS}{$var});
+ $date = &get_date_object($helper->{VARS}{$var});
} elsif (defined($self->{DEFAULT_VALUE})) {
my $valueFunc = eval($self->{DEFAULT_VALUE});
die('Error in default value code for variable ' .
@@ -1594,22 +1803,20 @@ sub render {
$time = &$valueFunc($helper, $self);
if (lc($time) eq 'anytime') {
$anytime=1;
- $date = localtime(time);
+ $date = &get_date_object(time);
$date->min(0);
} elsif (defined($time) && $time ne 0) {
- $date = localtime($time);
+ $date = &get_date_object($time);
} else {
# leave date undefined so it'll default to now
}
}
if (!defined($date)) {
- $date = localtime(time);
+ $date = &get_date_object(time);
$date->min(0);
}
- &Apache::lonnet::logthis("date mode ");
-
if ($anytime) {
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\"";
}
@@ -1623,12 +1830,12 @@ sub render {
my $i;
$result .= "\n";
for ($i = 0; $i < 12; $i++) {
- if ($i == $date->mon) {
+ if (($i + 1) == $date->mon) {
$result .= "";
} else {
$result .= " ";
}
- $result .= &mt($months[$i]) . " \n";
+ $result .= &mt($months[$i])." \n";
}
$result .= " \n";
@@ -1647,7 +1854,7 @@ sub render {
# Year
$result .= "\n";
for ($i = 2000; $i < 2030; $i++) { # update this after 64-bit dates
- if ($date->year + 1900 == $i) {
+ if ($date->year == $i) {
$result .= "";
} else {
$result .= " ";
@@ -1702,6 +1909,7 @@ sub render {
}
$result .= " \n";
}
+ $result .= ' '.$date->time_zone_short_name().' ';
if ($self->{'anytime'}) {
$result.=(<
@@ -1729,7 +1937,8 @@ sub postprocess {
if ($env{'form.' . $var . 'anytime'}) {
$helper->{VARS}->{$var} = undef;
} else {
- my $month = $env{'form.' . $var . 'month'};
+ my $month = $env{'form.' . $var . 'month'};
+ $month ++;
my $day = $env{'form.' . $var . 'day'};
my $year = $env{'form.' . $var . 'year'};
my $min = 0;
@@ -1739,25 +1948,40 @@ sub postprocess {
$hour = $env{'form.' . $var . 'hour'};
}
- my $chosenDate;
- eval {$chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year);};
+ my ($chosenDate,$checkDate);
+ my $timezone = &Apache::lonlocal::gettimezone();
+ my $dt;
+ eval {
+ $dt = DateTime->new( year => $year,
+ month => $month,
+ day => $day,
+ hour => $hour,
+ minute => $min,
+ second => 0,
+ time_zone => $timezone,
+ );
+ };
+
my $error = $@;
+ if (!$error) {
+ $chosenDate = $dt->epoch;
+ $checkDate = &get_date_object($chosenDate);
+ }
# 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) {
+ $checkDate->year != $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.";
+ $self->{ERROR_MSG} = "Can't use ".$months[$env{'form.'.$var.'month'}]. " $day, $year as a ".
+ "date because it doesn't exist. Please enter a valid date.";
return 0;
}
@@ -1780,6 +2004,20 @@ sub postprocess {
return 1;
}
+
+sub get_date_object {
+ my ($epoch) = @_;
+ my $dt = DateTime->from_epoch(epoch => $epoch)
+ ->set_time_zone(&Apache::lonlocal::gettimezone());
+ my $lang = Apache::lonlocal::current_language();
+ if ($lang ne '') {
+ eval {
+ $dt->set_locale($lang);
+ };
+ }
+ return $dt;
+}
+
1;
package Apache::lonhelper::resource;
@@ -1806,7 +2044,8 @@ folders that have all of their contained
be filtered out. The 'addstatus' attribute, if true, will add the icon
and long status display columns to the display. The 'addparts'
attribute will add in a part selector beside problems that have more
-than 1 part.
+than 1 part. The 'includecourse' attribute if true, will include
+the toplevel default.sequence in the results.
=head3 SUB-TAGS
@@ -1879,6 +2118,7 @@ sub start_resource {
$helper->declareVar($paramHash->{'variable'}.'_part');
}
$paramHash->{'closeallpages'} = $token->[2]{'closeallpages'};
+ $paramHash->{'include_top_level_map'} = $token->[2]{'includecourse'};
return '';
}
@@ -2024,7 +2264,7 @@ sub render {
function checkall(value, checkName) {
for (i=0; i ";
}
}
- $col .= " symb();
if (exists($defaultSymbs{$symb})) {
@@ -2157,7 +2397,7 @@ BUTTONS
my $resource_name =
&HTML::Entities::encode(&$valueFunc($resource),"<>&\"'");
if ($addparts && (scalar(@{$resource->parts}) > 1)) {
- $col .= "\n";
+ $col .= "\n";
$col .= "All Parts \n";
foreach my $part (@{$resource->parts}) {
$col .= "Part: $part \n";
@@ -2179,14 +2419,14 @@ BUTTONS
}
}
function updateHidden(form,id,name) {
- var select=form['part_'+id+'.forminput'];
- var hidden=form[name+'_part.forminput'];
+ var select=form['part_'+id+'_forminput'];
+ var hidden=form[name+'_part_forminput'];
var which=select.selectedIndex;
hidden.value=select.options[which].value;
}
// -->
-
+
RADIO
$env{'form.condition'} = !$self->{'toponly'};
@@ -2204,6 +2444,7 @@ RADIO
'resource_no_folder_link' => 1,
'closeAllPages' => $self->{'closeallpages'},
'suppressEmptySequences' => $self->{'suppressEmptySequences'},
+ 'include_top_level_map' => $self->{'include_top_level_map'},
'iterator_map' => $mapUrl }
);
@@ -2219,6 +2460,21 @@ sub postprocess {
$self->{ERROR_MSG} = 'You must choose at least one resource to continue.';
return 0;
}
+ # For each of the attached options. If it's env var is undefined, set it to
+ # an empty string instead.. an undef'd env var means no choices selected.
+ #
+
+ my $option_vars = $self->{OPTION_VARS};
+ if ($option_vars) {
+ foreach my $var (@$option_vars) {
+ my $env_name = "form.".$var."_forminput";
+ if (!defined($env{$env_name})) {
+ $env{$env_name} = '';
+ $helper->{VARS}->{$var} = '';
+ }
+ }
+ }
+
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
@@ -2341,7 +2597,8 @@ sub render {
my ($course_personnel,
$current_members,
$expired_members,
- $future_members) = &Apache::lonselstudent::get_people_in_class();
+ $future_members) =
+ &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
@@ -2354,34 +2611,43 @@ sub render {
# Current personel
+ $result .= ''.&mt('Select Currently Enrolled Students and Active Course Personnel').' ';
$result .= &Apache::lonselstudent::render_student_list( $current_members,
- "current",
- \%defaultUsers,
- $self->{'multichoice'},
- $self->{'variable'},
- 1);
+ "helpform",
+ "current",
+ \%defaultUsers,
+ $self->{'multichoice'},
+ $self->{'variable'},
+ 1);
# If activeonly is not set then we can also give the expired students:
#
- if (!$self->{'activeonly'} && ((scalar @$expired_members) > 0)) {
+ if (!$self->{'activeonly'} && ((scalar(@$future_members)) > 0)) {
# And future.
+ $result .= ''.&mt('Select Future Enrolled Students and Future Course Personnel').' ';
+
$result .= &Apache::lonselstudent::render_student_list( $future_members,
- "future",
- \%defaultUsers,
- $self->{'multichoice'},
- $self->{'variable'},
- 0);
+ "helpform",
+ "future",
+ \%defaultUsers,
+ $self->{'multichoice'},
+ $self->{'variable'},
+ 0);
+ }
+ if (!$self->{'activeonly'} && ((scalar(@$expired_members)) > 0)) {
# Past
+ $result .= ''.&mt('Select Previously Enrolled Students and Inactive Course Personnel').' ';
$result .= &Apache::lonselstudent::render_student_list($expired_members,
- "past",
- \%defaultUsers,
- $self->{'multichoice'},
- $self->{'variable'},
- 0);
+ "helpform",
+ "past",
+ \%defaultUsers,
+ $self->{'multichoice'},
+ $self->{'variable'},
+ 0);
}
@@ -2392,7 +2658,7 @@ sub render {
sub postprocess {
my $self = shift;
- my $result = $env{'form.' . $self->{'variable'} . '.forminput'};
+ my $result = $env{'form.' . $self->{'variable'} . '_forminput'};
if (!$result && !$self->{'emptyallowed'}) {
if ($self->{'coursepersonnel'}) {
$self->{ERROR_MSG} =
@@ -2577,7 +2843,7 @@ sub render {
function checkall(value, checkName) {
for (i=0; i" .
" {'multichoice'} && $choices == 0) {
$result .= ' checked="checked"';
@@ -2755,7 +3021,7 @@ sub fileState {
sub postprocess {
my $self = shift;
- my $result = $env{'form.' . $self->{'variable'} . '.forminput'};
+ my $result = $env{'form.' . $self->{'variable'} . '_forminput'};
if (!$result) {
$self->{ERROR_MSG} = 'You must choose at least one file '.
'to continue.';
@@ -2845,7 +3111,7 @@ sub start_section {
return if ($token->[2]{'onlysections'});
# add in groups to the end of the list
- my %curr_groups = &Apache::loncommon::coursegroups();
+ my %curr_groups = &Apache::longroup::coursegroups();
foreach my $group_name (sort(keys(%curr_groups))) {
push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]);
}
@@ -2909,7 +3175,7 @@ sub start_group {
# Populate the CHOICES element
my %choices;
- my %curr_groups = &Apache::loncommon::coursegroups();
+ my %curr_groups = &Apache::longroup::coursegroups();
foreach my $group_name (sort {lc($a) cmp lc($b)} (keys(%curr_groups))) {
push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]);
}
@@ -2991,7 +3257,7 @@ sub render {
$result .= '' . $self->{ERROR_MSG} . '
';
}
- $result .= ' {'variable'} . '_forminput"';
if (defined($self->{'size'})) {
$result .= ' size="' . $self->{'size'} . '"';
@@ -3124,7 +3390,8 @@ sub start_clause {
die 'Error in clause of condition, Perl said: ' . $@ if $@;
if (!&$clause($helper, $paramHash)) {
# Discard all text until the /condition.
- &Apache::lonxml::get_all_text('/condition', $parser);
+ my $end_tag = $paramHash->{SKIPTAG} || '/condition';
+ &Apache::lonxml::get_all_text($end_tag, $parser);
}
}
@@ -3304,11 +3571,10 @@ sub render {
}
my $finish=&mt('Finish Course Initialization');
}
- my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');
- my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');
+ my $previous = HTML::Entities::encode(&mt("Back"), '<>&"');
+ my $next = HTML::Entities::encode(&mt("Next"), '<>&"');
my $target = " target='loncapaclient'";
- if (($env{'browser.interface'} eq 'textual') ||
- ($env{'environment.remote'} eq 'off')) { $target=''; }
+ if ($env{'environment.remote'} eq 'off') { $target=''; }
$result .= "\n" .
"