--- loncom/interface/lonhelper.pm 2005/10/17 21:17:59 1.127 +++ loncom/interface/lonhelper.pm 2006/03/07 21:36:49 1.134 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.127 2005/10/17 21:17:59 albertel Exp $ +# $Id: lonhelper.pm,v 1.134 2006/03/07 21:36:49 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -576,6 +576,7 @@ sub display { my $html=&Apache::lonxml::xmlbegin(); my $stateTitle=&mt($state->title()); my $helperTitle = &mt($self->{TITLE}); + my $browser_searcher_js = &Apache::loncommon::browser_and_searcher_javascript(); my $bodytag = &Apache::loncommon::bodytag($helperTitle,'',''); my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); @@ -586,6 +587,9 @@ sub display { $html $loncapaHelper: $helperTitle + $bodytag HEADER @@ -1557,6 +1561,8 @@ sub render { my $date; my $time=time; + $date = localtime($time); + $date->min(0); my ($anytime,$onclick); if (defined($self->{DEFAULT_VALUE})) { @@ -1564,14 +1570,18 @@ sub render { 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; } + if (lc($time) eq 'anytime') { + $anytime=1; + } else { + $date = localtime($time); + } + } else { + } if ($anytime) { $onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\""; } # Default date: The current hour. - $date = localtime($time); - $date->min(0); if (defined $self->{ERROR_MSG}) { $result .= '' . $self->{ERROR_MSG} . '

'; @@ -2296,6 +2306,13 @@ sub render { } } } + function checkexpired() { + for (i=0; i
BUTTONS + $result .= $buttons; + } if (defined $self->{ERROR_MSG}) { @@ -2383,6 +2402,7 @@ BUTTONS delete($defaultUsers{''}); } my $choices = []; + my $expired_students = []; # Will hold expired students. # Load up the non-students, if necessary if ($self->{'coursepersonnel'}) { @@ -2420,15 +2440,67 @@ BUTTONS } return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; } @keys; + # + # 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; + } # username, fullname, section, type for (@keys) { - # Filter out inactive students if we've set "activeonly" - if (!$self->{'activeonly'} || $classlist->{$_}->[$status] eq + + # We split the active students into the choices array and + # inactive ones into expired_students so that we can put them in 2 separate + # tables. + + if ( $classlist->{$_}->[$status] eq 'Active') { push @$choices, [$_, $classlist->{$_}->[$fullname], $classlist->{$_}->[$section], $classlist->{$_}->[$status], 'Student']; + } else { + push @$expired_students, [$_, $classlist->{$_}->[$fullname], + $classlist->{$_}->[$section], + $classlist->{$_}->[$status], 'Student']; } } @@ -2443,6 +2515,9 @@ BUTTONS "".&mt('Username').":".&mt('Domain').""; my $checked = 0; + # + # Give the active students and staff: + # for my $choice (@$choices) { $result .= "[0],'<>&"') . "\n"; } - $result .= "\n\n"; - $result .= $buttons; + + # If activeonly is not set then we can also give the expired students: # - # 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; + if (!$self->{'activeonly'} && ((scalar @$expired_students) > 0)) { + $result .= "

Inactive students:

\n"; + $result .= < + + + + + +INACTIVEBUTTONS + $result .= "\n"; + + for my $choice (@$expired_students) { + $result .= "\n\n\n\n"; } - # 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"; + $result .= "
[0]; + if (exists($defaultUsers{$user})) { + $result .= " checked='checked' "; + $checked = 1; } + } elsif (!$self->{'multichoice'} && !$checked) { + $result .= " checked='checked' "; + $checked = 1; + } + $result .= + " value='" . HTML::Entities::encode($choice->[0] . ':' + .$choice->[2] . ':' + .$choice->[1] . ':' + .$choice->[3], "<>&\"'") + . "' />" + . HTML::Entities::encode($choice->[1],'<>&"') + . "" + . HTML::Entities::encode($choice->[2],'<>&"') + . "" + . HTML::Entities::encode($choice->[3],'<>&"') + . "" + . HTML::Entities::encode($choice->[4],'<>&"') + . "" + . HTML::Entities::encode($choice->[0],'<>&"') + . "
\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; } @@ -2915,8 +2996,12 @@ package Apache::lonhelper::section;
allows the user to choose one or more sections from the current course. -It takes the standard attributes "variable", "multichoice", and -"nextstate", meaning what they do for most other elements. +It takes the standard attributes "variable", "multichoice", +"allowempty" and "nextstate", meaning what they do for most other +elements. + +also takes a boolean 'onlysections' whcih will restrict this to only +have sections and not include groups =cut @@ -2946,6 +3031,7 @@ sub start_section { $paramHash->{'variable'} = $token->[2]{'variable'}; $helper->declareVar($paramHash->{'variable'}); $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; + $paramHash->{'allowempty'} = $token->[2]{'allowempty'}; if (defined($token->[2]{'nextstate'})) { $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; } @@ -2965,8 +3051,16 @@ sub start_section { } for my $sectionName (sort(keys(%choices))) { - - push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; + push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; + } + return if ($token->[2]{'onlysections'}); + + # add in groups to the end of the list + my %curr_groups; + if (&Apache::loncommon::coursegroups(\%curr_groups)) { + foreach my $group_name (sort(keys(%curr_groups))) { + push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); + } } } @@ -2980,6 +3074,72 @@ sub end_section { } 1; +package Apache::lonhelper::group; + +=pod + +=head2 Element: groupX + + allows the user to choose one or more groups from the current course. + +It takes the standard attributes "variable", "multichoice", + "allowempty" and "nextstate", meaning what they do for most other + elements. + +=cut + +no strict; +@ISA = ("Apache::lonhelper::choices"); +use strict; + +BEGIN { + &Apache::lonhelper::register('Apache::lonhelper::group', + ('group')); +} + +sub new { + my $ref = Apache::lonhelper::choices->new(); + bless($ref); +} + +sub start_group { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target ne 'helper') { + return ''; + } + + $paramHash->{CHOICES} = []; + + $paramHash->{'variable'} = $token->[2]{'variable'}; + $helper->declareVar($paramHash->{'variable'}); + $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; + $paramHash->{'allowempty'} = $token->[2]{'allowempty'}; + if (defined($token->[2]{'nextstate'})) { + $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; + } + + # Populate the CHOICES element + my %choices; + + my %curr_groups; + if (&Apache::loncommon::coursegroups(\%curr_groups)) { + foreach my $group_name (sort(keys(%curr_groups))) { + push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); + } + } +} + +sub end_group { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target ne 'helper') { + return ''; + } + Apache::lonhelper::group->new(); +} +1; + package Apache::lonhelper::string; =pod @@ -3566,6 +3726,11 @@ sub render { $result .= '
  • '.&mt('for section [_1]',"$section").'
  • '; $result .= "&\"") . "' />\n"; + } elsif ($vars->{TARGETS} eq 'group') { + my $group = $vars->{GROUP_NAME}; + $result .= '
  • '.&mt('for group [_1]',"$group").'
  • '; + $result .= "&\"") . "' />\n"; } else { # FIXME: This is probably wasteful! Store the name! my $classlist = Apache::loncoursedata::get_classlist();