--- loncom/interface/lonhelper.pm 2005/10/17 18:20:59 1.123 +++ loncom/interface/lonhelper.pm 2006/01/17 18:39:50 1.129 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.123 2005/10/17 18:20:59 albertel Exp $ +# $Id: lonhelper.pm,v 1.129 2006/01/17 18:39:50 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 @@ -2017,6 +2021,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 +2081,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 . "' />"; @@ -2350,6 +2374,18 @@ BUTTONS $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 @@ -2415,7 +2451,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; } @@ -2942,6 +2984,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 @@ -3323,8 +3432,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" . @@ -3525,6 +3637,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();