--- loncom/interface/lonhelper.pm 2006/05/09 14:38:10 1.142 +++ loncom/interface/lonhelper.pm 2006/05/09 22:15:30 1.146 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.142 2006/05/09 14:38:10 albertel Exp $ +# $Id: lonhelper.pm,v 1.146 2006/05/09 22:15:30 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2282,7 +2282,6 @@ use Apache::lonnet; # future...each one gets is own subpage of selection. # This sub renders one of these pages. # Parameters: -# $sections - Set of sections in the course (hash reference). # $students - Students in the section. (ref to array of references # to arrays). # $formprefix - form path prefix for form element names @@ -2291,24 +2290,148 @@ use Apache::lonnet; # set of students won't collide. # $defaultusers - reference to a hash containng # the set of users that should be on or off. +# $multiselect - True if multiselect allowed. +# $resultname - Name of result variable. +# $javascript - If true, the javascript to run this is output +# This should be true for the first call for a page +# and false for all other calls... only matters if +# multiselect is true. # Returns: # HTML text to add to the rendering of the helper. # sub render_student_list { - my ($self, - $sections, $students, $formprefix, $defaultusers) = @_; + my ($students, $formprefix, $defaultusers, + $multiselect, $resultname, $javascript) = @_; - my $multiselect = $self->{'multichoice'}; my $result = ""; + if ($javascript && $multiselect) { + $result .= < +// + +SCRIPT + + } + # If multiple selections are allowed, we have a listbox # at the top which allows quick selections from each section # as well as from categories of personnel. if ($multiselect) { + # Make a section hash so we can add sections to the choice: + + my %sections; + for my $student (@$students) { + my $sect = $student->[2]; + if ($sect ne "") { + $sections{$sect} = 1; + } + } + $result .= '
'; - my $size = scalar(keys(%$sections)); + my $size = scalar(keys(%sections)); $size += 3; # We have allstudents allpersonel nosection too. if ($size > 5) { $size = 5; @@ -2319,7 +2442,7 @@ sub render_student_list { $result .= ''; $result .= ''; $result .= "\n"; - foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%$sections))) { + foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) { $result .= ''."\n"; } $result .= ''; @@ -2352,7 +2475,7 @@ sub render_student_list { my $checked = 0; for my $student (@$students) { $result .= '
[0]; # Figure out which students are checked by default... @@ -2362,7 +2485,7 @@ sub render_student_list { $result .= ' checked ="checked" '; $checked = 1; } - } elsif (!$self->{'multichoice'} && !$checked) { + } elsif (!$multiselect && !$checked) { $result .= ' checked="checked" '; $checked = 1; # First one for radio if no default specified. } @@ -2433,136 +2556,6 @@ sub render { my $buttons = ''; my $var = $self->{'variable'}; - if ($self->{'multichoice'}) { - $result = < -// - -SCRIPT - - my %lt=&Apache::lonlocal::texthash( - 'ocs' => "Select Only Current Students", - 'ues' => "Unselect Expired Students", - 'sas' => "Select All Students", - 'uas' => "Unselect All Students", - 'sfsg' => "Select Current Students for Section/Group", - 'ufsg' => "Unselect for Section/Group"); - - $buttons = < - - - - - - - -

-
-BUTTONS -# $result .= $buttons; - -} if (defined $self->{ERROR_MSG}) { $result .= '' . $self->{ERROR_MSG} . '

'; @@ -2666,41 +2659,15 @@ BUTTONS } - # Create a list of the sections that can be used to create the section - # selection list boxes: - # - my %sections; - for my $key (@keys) { - my $section_name = $classlist->{$key}->[$section]; - if ($section_name ne "") { - $sections{$section_name} = 1; - } - } - - - if ($self->{'multichoice'}) { - - # 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 $result = '\n"; - - - } # Current personel - $result .= $self->render_student_list(\%sections, - $current_members, - "current", - \%defaultUsers); + $result .= &render_student_list( $current_members, + "current", + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}, + 1); # If activeonly is not set then we can also give the expired students: @@ -2709,16 +2676,20 @@ BUTTONS # And future. - $result .= $self->render_student_list(\%sections, - $future_members, - "future", - \%defaultUsers); + $result .= &render_student_list( $future_members, + "future", + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}, + 0); # Past - $result .= $self->render_student_list(\%sections, - $expired_members, - "past", - \%defaultUsers); + $result .= &render_student_list($expired_members, + "past", + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}, + 0); } @@ -3162,17 +3133,22 @@ sub start_section { my $section = Apache::loncoursedata::CL_SECTION(); my $classlist = Apache::loncoursedata::get_classlist(); - foreach (keys %$classlist) { - my $sectionName = $classlist->{$_}->[$section]; - if (!$sectionName) { + foreach my $user (keys(%$classlist)) { + my $section_name = $classlist->{$user}[$section]; + if (!$section_name) { $choices{"No section assigned"} = ""; } else { - $choices{$sectionName} = $sectionName; + $choices{$section_name} = $section_name; } } - for my $sectionName (sort(keys(%choices))) { - push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; + if (exists($choices{"No section assigned"})) { + push(@{$paramHash->{CHOICES}}, + ['No section assigned','No section assigned']); + delete($choices{"No section assigned"}); + } + for my $section_name (sort {lc($a) cmp lc($b) } (keys(%choices))) { + push @{$paramHash->{CHOICES}}, [$section_name, $section_name]; } return if ($token->[2]{'onlysections'}); @@ -3242,7 +3218,7 @@ sub start_group { my %choices; my %curr_groups = &Apache::loncommon::coursegroups(); - foreach my $group_name (sort(keys(%curr_groups))) { + foreach my $group_name (sort {lc($a) cmp lc($b)} (keys(%curr_groups))) { push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); } }