--- loncom/interface/lonselstudent.pm 2006/05/11 21:10:21 1.1 +++ 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.1 2006/05/11 21:10:21 foxr 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,25 +74,25 @@ 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. # 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; + for my $role (sort(keys(%coursepersonnel))) { + # extract the names so we can sort them + my @people; + for my $person (split(/,/, $coursepersonnel{$role})) { + 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], '', $_]; - } + for my $person (@people) { + push(@course_personnel, [join(':', $person->[1],$person->[2]), + $person->[0], '', '', $role]); } } # Students must be split into the three categories: @@ -102,41 +110,44 @@ sub get_people_in_class { my $classlist = &Apache::loncoursedata::get_classlist(); - my @keys = keys %{$classlist}; + 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]; - } @keys; + 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, @@ -155,6 +166,7 @@ sub get_people_in_class { # Parameters: # $students - Students in the section. (ref to array of references # to arrays). +# $formname - Name of the form in which this stuff gets rendered. # $formprefix - form path prefix for form element names # This is used to make each form element # so that the segments having to do with each @@ -171,11 +183,14 @@ sub get_people_in_class { # HTML text to add to the rendering of the helper. # sub render_student_list { - my ($students, $formprefix, $defaultusers, + my ($students, $formname, $formprefix, $defaultusers, $multiselect, $resultname, $javascript) = @_; my $result = ""; + # no students so no output + return if (!@$students); + if ($javascript && $multiselect) { $result .= < @@ -184,8 +199,8 @@ sub render_student_list { function findElement(name) { var i; var ele; - for(i =0; i < document.forms.helpform.elements.length; i++) { - ele = document.forms.helpform.elements[i]; + for(i =0; i < document.forms.$formname.elements.length; i++) { + ele = document.forms.$formname.elements[i]; if(ele.name == name) { return ele; } @@ -219,8 +234,8 @@ sub render_student_list { function setAllStudents(value, which) { var i; var ele; - for (i =0; i < document.forms.helpform.elements.length; i++) { - ele = document.forms.helpform.elements[i]; + for (i =0; i < document.forms.$formname.elements.length; i++) { + ele = document.forms.$formname.elements[i]; if(isStudent(ele) && rightSubForm(ele, which)) { ele.checked=value; } @@ -229,8 +244,8 @@ sub render_student_list { function setAllCoursePersonnel(value, which) { var i; var ele; - for (i =0; i < document.forms.helpform.elements.length; i++) { - ele = document.forms.helpform.elements[i]; + for (i =0; i < document.forms.$formname.elements.length; i++) { + ele = document.forms.$formname.elements[i]; if(!isStudent(ele) && rightSubForm(ele, which)) { ele.checked = value; } @@ -239,8 +254,8 @@ sub render_student_list { 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]; + for (i =0; i < document.forms.$formname.elements.length; i++) { + ele = document.forms.$formname.elements[i]; if (ele.value.indexOf(':') != -1) { if ((section(ele) == which) && rightSubForm(ele, subform)) { ele.checked = value; @@ -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 .= ''; } @@ -329,12 +344,14 @@ SCRIPT # True -> checkboxes. # False -> radiobuttons. - $result .= "\n"; - $result .= ''."\n"; - $result .= ' '."\n"; - $result .= ' '."\n"; - $result .= ' '."\n"; - $result .= ' '."\n"; + $result .= &Apache::loncommon::start_data_table(); + $result .= &Apache::loncommon::start_data_table_header_row(); + $result .= ''."\n"; + $result .= ' '."\n"; + $result .= ' '."\n"; + $result .= ' '."\n"; + $result .= ' '."\n"; + $result .= &Apache::loncommon::end_data_table_header_row(); my $input_type; if ($multiselect) { @@ -345,13 +362,14 @@ SCRIPT my $checked = 0; for my $student (@$students) { - $result .= ''."\n"; + $result .= &HTML::Entities::encode($student->[0], '<>&"') + . ''.&Apache::loncommon::end_data_table_row(). + "\n"; } - $result .="
NameSectionStatusRoleUsername : Domain
'.&mt('Name').''.&mt('Section').''.&mt('Status').''.&mt('Role').''.&mt('Username : Domain').'
[0]; # Figure out which students are checked by default... - if(%$defaultusers) { + if (%$defaultusers) { if (exists ($defaultusers->{$user})) { $result .= ' checked ="checked" '; $checked = 1; @@ -360,25 +378,27 @@ 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], '<>&"') - . '


\n"; + $result .= &Apache::loncommon::end_data_table(). + "

\n"; return $result; }