--- loncom/interface/lonselstudent.pm 2006/05/17 15:20:56 1.5 +++ loncom/interface/lonselstudent.pm 2007/11/01 19:56:39 1.10 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # lonselstudent.pm : Reusable subs for student selection. # -# $Id: lonselstudent.pm,v 1.5 2006/05/17 15:20:56 albertel Exp $ +# $Id: lonselstudent.pm,v 1.10 2007/11/01 19:56:39 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,15 +28,23 @@ package Apache::lonselstudent; use Apache::lonnet; -use Apache::loncoursedata; -use HTML::Entities; +use Apache::lonlocal; +use Apache::loncoursedata(); +use HTML::Entities(); # # Utility function used when rendering tags. # This function produces a list references to four # arrays: # (\@course_personel, \@current_members, \@expired_members, \@future_members) -# +# +# +# Parameters; +# +# restrict - Optional.. if present and defined should be a section name. +# The *_members arrays will then only contain people +# in that section +# # Where: # course_personnel - Each element of this array is itself a reference to an array # containing information about a member of the course staff. @@ -66,6 +74,7 @@ use HTML::Entities; # [4] username:domain of the user. # sub get_people_in_class { + my ($section_restriction) = @_; my %coursepersonnel = &Apache::lonnet::get_course_adv_roles(); # # Enumerate the course_personnel. @@ -104,38 +113,41 @@ sub get_people_in_class { my @keys = keys(%{$classlist}); # Sort by: Section, name @keys = sort { - if ($classlist->{$a}->[$section] ne $classlist->{$b}->[$section]) { - return $classlist->{$a}->[$section] cmp $classlist->{$b}->[$section]; - } - return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; + lc($classlist->{$a}[$section]) cmp lc($classlist->{$b}[$section]) || + lc($classlist->{$a}[$fullname]) cmp lc($classlist->{$b}[$fullname]) || + lc($a) cmp lc($b) } (@keys); - for (@keys) { - - if ( $classlist->{$_}->[$status] eq - 'Active') { - push(@current_members, [$_, $classlist->{$_}->[$fullname], - $classlist->{$_}->[$section], - $classlist->{$_}->[$status], 'Student']); - } else { - # Need to figure out if this user is future or - # Expired... If the start date is in the future - # the user is future...else expired. + for my $user (@keys) { + if (!$section_restriction || + ($section_restriction eq $classlist->{$user}->[$section])) { - my $now = time; - if ($classlist->{$_}->[$start_date] > $now) { - push(@future_members, [$_, $classlist->{$_}->[$fullname], - $classlist->{$_}->[$section], - "Future", "Student"]); + if ( $classlist->{$user}->[$status] eq + 'Active') { + push(@current_members, [$user, $classlist->{$user}->[$fullname], + $classlist->{$user}->[$section], + $classlist->{$user}->[$status], 'Student']); } else { - push(@expired_members, [$_, $classlist->{$_}->[$fullname], - $classlist->{$_}->[$section], - "Expired", "Student"]); + # Need to figure out if this user is future or + # Expired... If the start date is in the future + # the user is future...else expired. + + my $now = time; + if ($classlist->{$user}->[$start_date] > $now) { + push(@future_members, [$user, $classlist->{$user}->[$fullname], + $classlist->{$user}->[$section], + "Future", "Student"]); + } else { + push(@expired_members, [$user, + $classlist->{$user}->[$fullname], + $classlist->{$user}->[$section], + "Expired", "Student"]); + } + } - } } return (\@course_personnel, @@ -176,6 +188,9 @@ sub render_student_list { my $result = ""; + # no students so no output + return if (!@$students); + if ($javascript && $multiselect) { $result .= < @@ -257,12 +272,12 @@ sub render_student_list { if (elem != null) { for (k = 0; k < elem.length; k++) { if (elem.options[k].selected) { - what = elem.options[k].text; - if (what == 'All Students') { + what = elem.options[k].value; + if (what == 'allstudents') { setAllStudents(value, which); - } else if (what == 'All Course Personnel') { + } else if (what == 'allpersonnel') { setAllCoursePersonnel(value, which); - } else if (what == 'No Section') { + } else if (what == 'nosection') { setSection('',value, which); } else { setSection(what, value, which); @@ -309,18 +324,18 @@ SCRIPT } $result .= ''; $result .= ''; } @@ -331,11 +346,11 @@ SCRIPT $result .= &Apache::loncommon::start_data_table(); $result .= &Apache::loncommon::start_data_table_header_row(); - $result .= 'Name'."\n"; - $result .= ' Section'."\n"; - $result .= ' Status'."\n"; - $result .= ' Role'."\n"; - $result .= ' Username : Domain'."\n"; + $result .= ''.&mt('Name').''."\n"; + $result .= ' '.&mt('Section').''."\n"; + $result .= ' '.&mt('Status').''."\n"; + $result .= ' '.&mt('Role').''."\n"; + $result .= ' '.&mt('Username : Domain').''."\n"; $result .= &Apache::loncommon::end_data_table_header_row(); my $input_type; @@ -349,7 +364,7 @@ SCRIPT for my $student (@$students) { $result .= &Apache::loncommon::start_data_table_row(). '[0]; # Figure out which students are checked by default...