--- loncom/interface/lonhelper.pm 2006/05/05 14:35:44 1.140 +++ loncom/interface/lonhelper.pm 2006/05/09 21:39:47 1.144 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.140 2006/05/05 14:35:44 albertel Exp $ +# $Id: lonhelper.pm,v 1.144 2006/05/09 21:39:47 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2291,14 +2291,16 @@ 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. # Returns: # HTML text to add to the rendering of the helper. # sub render_student_list { - my ($self, - $sections, $students, $formprefix, $defaultusers) = @_; + my ( + $sections, $students, $formprefix, $defaultusers, + $multiselect, $resultname) = @_; - my $multiselect = $self->{'multichoice'}; my $result = ""; # If multiple selections are allowed, we have a listbox @@ -2324,10 +2326,10 @@ sub render_student_list { } $result .= ''; $result .= ''; + ."'selectSections(\"$formprefix.chosensections\", \"$formprefix\")'".' />'; $result .= ''; + "'unselectSections(\"$formprefix.chosensections\", \"$formprefix\")' ".' />'; } # Now we list the students, but the form element type @@ -2352,7 +2354,7 @@ sub render_student_list { my $checked = 0; for my $student (@$students) { $result .= '[0]; # Figure out which students are checked by default... @@ -2362,7 +2364,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. } @@ -2370,7 +2372,8 @@ sub render_student_list { .$student->[2] . ':' .$student->[1] . ':' .$student->[3] . ':' - .$student->[4], "<>&\"'") + .$student->[4] . ":" + .$formprefix, "<>&\"'") ."\" />\n"; $result .= HTML::Entities::encode($student->[1], '<>&"') . ''."\n"; @@ -2464,41 +2467,48 @@ sub render { return ""; } } + function rightSubForm(element, which) { + if (element.value.indexOf(which) != -1) { + return true; + } else { + return false; + } + } - function setAllStudents(value) { + function setAllStudents(value, which) { var i; var ele; for (i =0; i < document.forms.helpform.elements.length; i++) { ele = document.forms.helpform.elements[i]; - if(isStudent(ele)) { + if(isStudent(ele) && rightSubForm(ele, which)) { ele.checked=value; } } } - function setAllCoursePersonnel(value) { + function setAllCoursePersonnel(value, which) { var i; var ele; for (i =0; i < document.forms.helpform.elements.length; i++) { ele = document.forms.helpform.elements[i]; - if(!isStudent(ele)) { + if(!isStudent(ele) && rightSubForm(ele, which)) { ele.checked = value; } } } - function setSection(which, value) { + function setSection(which, value, subform) { var i; var ele; for (i =0; i < document.forms.helpform.elements.length; i++) { ele = document.forms.helpform.elements[i]; if (ele.value.indexOf(':') != -1) { - if (section(ele) == which) { + if ((section(ele) == which) && rightSubForm(ele, subform)) { ele.checked = value; } } } } - function setCheckboxes(listbox, value) { + function setCheckboxes(listbox, which, value) { var k; var elem; var what; @@ -2508,103 +2518,26 @@ sub render { if (elem.options[k].selected) { what = elem.options[k].text; if (what == 'All Students') { - setAllStudents(value); + setAllStudents(value, which); } else if (what == 'All Course Personnel') { - setAllCoursePersonnel(value); + setAllCoursePersonnel(value, which); } else if (what == 'No Section') { - setSection('',value); + setSection('',value, which); } else { - setSection(what, value); + setSection(what, value, which); } } } } } - function selectSections(listbox) { - setCheckboxes(listbox, true); + function selectSections(listbox, which) { + setCheckboxes(listbox, which, true); } - function unselectSections(listbox) { - setCheckboxes(listbox, false); - } - /* ----------------------------- */ - - function checkall(value, checkName) { - for (i=0; i SCRIPT @@ -2766,10 +2699,12 @@ BUTTONS # Current personel - $result .= $self->render_student_list(\%sections, + $result .= &render_student_list(\%sections, $current_members, "current", - \%defaultUsers); + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}); # If activeonly is not set then we can also give the expired students: @@ -2778,16 +2713,20 @@ BUTTONS # And future. - $result .= $self->render_student_list(\%sections, + $result .= &render_student_list(\%sections, $future_members, "future", - \%defaultUsers); + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}); # Past - $result .= $self->render_student_list(\%sections, + $result .= &render_student_list(\%sections, $expired_members, "past", - \%defaultUsers); + \%defaultUsers, + $self->{'multichoice'}, + $self->{'variable'}); } @@ -3231,26 +3170,29 @@ 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'}); # 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]); - } + my %curr_groups = &Apache::loncommon::coursegroups(); + foreach my $group_name (sort(keys(%curr_groups))) { + push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); } } @@ -3312,11 +3254,9 @@ sub start_group { # 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]); - } + my %curr_groups = &Apache::loncommon::coursegroups(); + foreach my $group_name (sort {lc($a) cmp lc($b)} (keys(%curr_groups))) { + push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); } }