--- loncom/interface/lonselstudent.pm 2006/05/17 15:01:40 1.3 +++ loncom/interface/lonselstudent.pm 2016/10/22 02:03:31 1.17 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # lonselstudent.pm : Reusable subs for student selection. # -# $Id: lonselstudent.pm,v 1.3 2006/05/17 15:01:40 albertel Exp $ +# $Id: lonselstudent.pm,v 1.17 2016/10/22 02:03:31 raeburn 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. @@ -53,7 +61,7 @@ use HTML::Entities; # Course personnel elements include: # [0] Last, First of the user. # [1] Role held by the user. -# [2] Empty. +# [2] Section associated with role. # [3] Empty # [4] username:domain of the user. # @@ -66,25 +74,30 @@ use HTML::Entities; # [4] username:domain of the user. # sub get_people_in_class { - my %coursepersonnel = &Apache::lonnet::get_course_adv_roles(); + my ($section_restriction,$personnel_section) = @_; + my %coursepersonnel = &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1); + my $crstype = &Apache::loncommon::course_type(); # # Enumerate the course_personnel. # my @course_personnel; - for (sort keys %coursepersonnel) { - for my $role (split /,/, $coursepersonnel{$_}) { - # extract the names so we can sort them - my @people; - - for (split /,/, $role) { - push @people, [split /:/, $role]; - } - - @people = sort { $a->[0] cmp $b->[0] } @people; + foreach my $key (sort(keys(%coursepersonnel))) { + my ($role,$section) = split(/:/,$key); + # extract the names so we can sort them + next if (($personnel_section ne '') && ($personnel_section ne $section)); + my @people; + + foreach my $person (split(/,/, $coursepersonnel{$key})) { + my ($uname,$domain) = split(/:/, $person); + push(@people, [&Apache::loncommon::plainname($uname,$domain), + $uname,$domain]); + } + @people = sort { $a->[0] cmp $b->[0] } (@people); - for my $person (@people) { - push @course_personnel, [join(':', @$person), $person->[0], '', $_]; - } + foreach my $person (@people) { + push(@course_personnel, [join(':', $person->[1],$person->[2]), + $person->[0], $section, 'Active', + &Apache::lonnet::plaintext($role)]); } } # Students must be split into the three categories: @@ -102,41 +115,43 @@ sub get_people_in_class { my $classlist = &Apache::loncoursedata::get_classlist(); - my @keys = keys %{$classlist}; - # Sort by: Section, name + my @keys = keys(%{$classlist}); + # Sort by: fullname, username @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]; - } @keys; + 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, @@ -168,25 +183,30 @@ sub get_people_in_class { # This should be true for the first call for a page # and false for all other calls... only matters if # multiselect is true. +# $context - If email, do not include

tags at the end +# of the data table. # Returns: # HTML text to add to the rendering of the helper. # sub render_student_list { my ($students, $formname, $formprefix, $defaultusers, - $multiselect, $resultname, $javascript) = @_; + $multiselect, $resultname, $javascript, $context) = @_; my $result = ""; + # no students so no output + return if (!@$students); + if ($javascript && $multiselect) { $result .= < // @@ -304,25 +324,31 @@ SCRIPT $result .= ''; + $result .= ''; $result .= '
'; my $size = scalar(keys(%sections)); - $size += 3; # We have allstudents allpersonel nosection too. - if ($size > 5) { + if ($context eq 'accesstimes') { + $size += 2; + } else { + $size += 3; # We have allstudents allpersonel nosection too. + } + if ($size > 5) { $size = 5; } - $result .= ''; - $result .= ''; + $result .= '
'; + .'.unselect" value="'.&mt('Unselect').'" onclick='. + "'unselectSections(\"$formprefix.chosensections\", \"$formprefix\", document.forms.$formname)' ".' />'; } # Now we list the students, but the form element type @@ -332,11 +358,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; @@ -350,12 +376,12 @@ SCRIPT for my $student (@$students) { $result .= &Apache::loncommon::start_data_table_row(). '[0]; # Figure out which students are checked by default... - if(%$defaultusers) { + if (%$defaultusers) { if (exists ($defaultusers->{$user})) { $result .= ' checked ="checked" '; $checked = 1; @@ -364,27 +390,29 @@ SCRIPT $result .= ' checked="checked" '; $checked = 1; # First one for radio if no default specified. } - $result .= ' value="'. HTML::Entities::encode($user . ':' - .$student->[2] . ':' + $result .= ' value="'.&HTML::Entities::encode($user . ':' + .$student->[2] . ':' .$student->[1] . ':' .$student->[3] . ':' .$student->[4] . ":" .$formprefix, "<>&\"'") ."\" />\n"; - $result .= HTML::Entities::encode($student->[1], '<>&"') + $result .= &HTML::Entities::encode($student->[1], '<>&"') . ''."\n"; - $result .= HTML::Entities::encode($student->[2], '<>&"') + $result .= &HTML::Entities::encode($student->[2], '<>&"') . ''."\n"; - $result .= HTML::Entities::encode($student->[3], '<>&"') + $result .= &HTML::Entities::encode($student->[3], '<>&"') . ''."\n"; - $result .= HTML::Entities::encode($student->[4], '<>&"') + $result .= &HTML::Entities::encode($student->[4], '<>&"') . ''."\n"; - $result .= HTML::Entities::encode($student->[0], '<>&"') + $result .= &HTML::Entities::encode($student->[0], '<>&"') . ''.&Apache::loncommon::end_data_table_row(). "\n"; } - $result .= &Apache::loncommon::end_data_table(). - "

\n"; + $result .= &Apache::loncommon::end_data_table(); + if ($context ne 'email') { + $result .= "

\n"; + } return $result; }