--- loncom/interface/lonhelper.pm 2005/10/11 22:05:20 1.122 +++ loncom/interface/lonhelper.pm 2006/03/02 23:56:55 1.131 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.122 2005/10/11 22:05:20 albertel Exp $ +# $Id: lonhelper.pm,v 1.131 2006/03/02 23:56:55 foxr 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} . '

'; @@ -2017,6 +2027,18 @@ 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 $@; + my @defaultSymbs = &$valueFunc($helper, $self); + if (!$multichoice && @defaultSymbs) { # only allowed 1 + @defaultSymbs = ($defaultSymbs[0]); + } + %defaultSymbs = map { if ($_) {($_,1) } } @defaultSymbs; + delete($defaultSymbs{''}); + } # 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 @@ -2065,13 +2087,21 @@ BUTTONS } $col .= "symb(); + if (exists($defaultSymbs{$symb})) { + $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 . "' />"; @@ -2189,6 +2219,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 @@ -2224,6 +2258,7 @@ sub start_student { if (defined($token->[2]{'nextstate'})) { $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; } + $paramHash->{'emptyallowed'} = $token->[2]{'emptyallowed'}; } @@ -2339,12 +2374,26 @@ SCRIPT
BUTTONS + $result .= $buttons; + } if (defined $self->{ERROR_MSG}) { $result .= '' . $self->{ERROR_MSG} . '

'; } + my %defaultUsers; + if (defined($self->{DEFAULT_VALUE})) { + my $valueFunc = eval($self->{DEFAULT_VALUE}); + die 'Error in default value code for variable ' . + $self->{'variable'} . ', Perl said: ' . $@ if $@; + my @defaultUsers = &$valueFunc($helper, $self); + if (!$self->{'multichoice'} && @defaultUsers) { # only allowed 1 + @defaultUsers = ($defaultUsers[0]); + } + %defaultUsers = map { if ($_) {($_,1) } } @defaultUsers; + delete($defaultUsers{''}); + } my $choices = []; # Load up the non-students, if necessary @@ -2383,6 +2432,50 @@ 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) { @@ -2410,7 +2503,13 @@ BUTTONS $result .= "{'multichoice'} && !$checked) { + if (%defaultUsers) { + my $user=$choice->[0]; + if (exists($defaultUsers{$user})) { + $result .= " checked='checked' "; + $checked = 1; + } + } elsif (!$self->{'multichoice'} && !$checked) { $result .= " checked='checked' "; $checked = 1; } @@ -2433,51 +2532,8 @@ BUTTONS } $result .= "\n\n"; - $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; } @@ -2485,9 +2541,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; } @@ -2932,6 +2993,73 @@ 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", 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'}; + if (defined($token->[2]{'nextstate'})) { + $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; + } + + # Populate the CHOICES element + my %choices; + + my $numgroups; + my %curr_groups; + if (&Apache::loncommon::coursegroups(\%curr_groups)) { + foreach my $group_name (keys %curr_groups) { + $choices{$group_name} = $group_name; + } + } + foreach my $group_name (sort(keys(%choices))) { + 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 @@ -3313,8 +3441,11 @@ sub render { } my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); + my $target = " target='loncapaclient'"; + if (($env{'browser.interface'} eq 'textual') || + ($env{'environment.remote'} eq 'off')) { $target=''; } $result .= "
\n" . - "
\n" . + "\n" . "" . "" . "\n" . @@ -3515,6 +3646,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();