version 1.1, 2006/05/11 21:10:21
|
version 1.13, 2008/11/04 03:25:53
|
Line 28
|
Line 28
|
|
|
package Apache::lonselstudent; |
package Apache::lonselstudent; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncoursedata; |
use Apache::lonlocal; |
use HTML::Entities; |
use Apache::loncoursedata(); |
|
use HTML::Entities(); |
|
|
# |
# |
# Utility function used when rendering <student> tags. |
# Utility function used when rendering <student> tags. |
# This function produces a list references to four |
# This function produces a list references to four |
# arrays: |
# arrays: |
# (\@course_personel, \@current_members, \@expired_members, \@future_members) |
# (\@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: |
# Where: |
# course_personnel - Each element of this array is itself a reference to an array |
# course_personnel - Each element of this array is itself a reference to an array |
# containing information about a member of the course staff. |
# containing information about a member of the course staff. |
Line 66 use HTML::Entities;
|
Line 74 use HTML::Entities;
|
# [4] username:domain of the user. |
# [4] username:domain of the user. |
# |
# |
sub get_people_in_class { |
sub get_people_in_class { |
|
my ($section_restriction) = @_; |
my %coursepersonnel = &Apache::lonnet::get_course_adv_roles(); |
my %coursepersonnel = &Apache::lonnet::get_course_adv_roles(); |
# |
# |
# Enumerate the course_personnel. |
# Enumerate the course_personnel. |
# |
# |
my @course_personnel; |
my @course_personnel; |
for (sort keys %coursepersonnel) { |
for my $role (sort(keys(%coursepersonnel))) { |
for my $role (split /,/, $coursepersonnel{$_}) { |
# extract the names so we can sort them |
# extract the names so we can sort them |
my @people; |
my @people; |
for my $person (split(/,/, $coursepersonnel{$role})) { |
|
my ($uname,$domain) = split(/:/, $person); |
for (split /,/, $role) { |
push(@people, [&Apache::loncommon::plainname($uname,$domain), |
push @people, [split /:/, $role]; |
$uname,$domain]); |
} |
} |
|
@people = sort { $a->[0] cmp $b->[0] } (@people); |
@people = sort { $a->[0] cmp $b->[0] } @people; |
|
|
|
for my $person (@people) { |
for my $person (@people) { |
push @course_personnel, [join(':', @$person), $person->[0], '', $_]; |
push(@course_personnel, [join(':', $person->[1],$person->[2]), |
} |
$person->[0], '', '', $role]); |
} |
} |
} |
} |
# Students must be split into the three categories: |
# Students must be split into the three categories: |
Line 102 sub get_people_in_class {
|
Line 110 sub get_people_in_class {
|
|
|
|
|
my $classlist = &Apache::loncoursedata::get_classlist(); |
my $classlist = &Apache::loncoursedata::get_classlist(); |
my @keys = keys %{$classlist}; |
my @keys = keys(%{$classlist}); |
# Sort by: Section, name |
# Sort by: fullname, username |
@keys = sort { |
@keys = sort { |
if ($classlist->{$a}->[$section] ne $classlist->{$b}->[$section]) { |
lc($classlist->{$a}[$fullname]) cmp lc($classlist->{$b}[$fullname]) || |
return $classlist->{$a}->[$section] cmp $classlist->{$b}->[$section]; |
lc($a) cmp lc($b) |
} |
} (@keys); |
return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; |
|
} @keys; |
|
|
|
|
|
|
|
|
|
for (@keys) { |
for my $user (@keys) { |
|
if (!$section_restriction || |
if ( $classlist->{$_}->[$status] eq |
($section_restriction eq $classlist->{$user}->[$section])) { |
'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. |
|
|
|
my $now = time; |
if ( $classlist->{$user}->[$status] eq |
if ($classlist->{$_}->[$start_date] > $now) { |
'Active') { |
push @future_members, [$_, $classlist->{$_}->[$fullname], |
push(@current_members, [$user, $classlist->{$user}->[$fullname], |
$classlist->{$_}->[$section], |
$classlist->{$user}->[$section], |
"Future", "Student"]; |
$classlist->{$user}->[$status], 'Student']); |
} else { |
} else { |
push @expired_members, [$_, $classlist->{$_}->[$fullname], |
# Need to figure out if this user is future or |
$classlist->{$_}->[$section], |
# Expired... If the start date is in the future |
"Expired", "Student"]; |
# 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, |
return (\@course_personnel, |
Line 155 sub get_people_in_class {
|
Line 165 sub get_people_in_class {
|
# Parameters: |
# Parameters: |
# $students - Students in the section. (ref to array of references |
# $students - Students in the section. (ref to array of references |
# to arrays). |
# to arrays). |
|
# $formname - Name of the form in which this stuff gets rendered. |
# $formprefix - form path prefix for form element names |
# $formprefix - form path prefix for form element names |
# This is used to make each form element |
# This is used to make each form element |
# so that the segments having to do with each |
# so that the segments having to do with each |
Line 167 sub get_people_in_class {
|
Line 178 sub get_people_in_class {
|
# This should be true for the first call for a page |
# This should be true for the first call for a page |
# and false for all other calls... only matters if |
# and false for all other calls... only matters if |
# multiselect is true. |
# multiselect is true. |
|
# $context - If email, do not include <br /><hr /> tags at the end |
|
# of the data table. |
# Returns: |
# Returns: |
# HTML text to add to the rendering of the helper. |
# HTML text to add to the rendering of the helper. |
# |
# |
sub render_student_list { |
sub render_student_list { |
my ($students, $formprefix, $defaultusers, |
my ($students, $formname, $formprefix, $defaultusers, |
$multiselect, $resultname, $javascript) = @_; |
$multiselect, $resultname, $javascript, $context) = @_; |
|
|
my $result = ""; |
my $result = ""; |
|
|
|
# no students so no output |
|
return if (!@$students); |
|
|
if ($javascript && $multiselect) { |
if ($javascript && $multiselect) { |
$result .= <<SCRIPT; |
$result .= <<SCRIPT; |
<script type="text/javascript"> |
<script type="text/javascript"> |
Line 184 sub render_student_list {
|
Line 200 sub render_student_list {
|
function findElement(name) { |
function findElement(name) { |
var i; |
var i; |
var ele; |
var ele; |
for(i =0; i < document.forms.helpform.elements.length; i++) { |
for(i =0; i < document.forms.$formname.elements.length; i++) { |
ele = document.forms.helpform.elements[i]; |
ele = document.forms.$formname.elements[i]; |
if(ele.name == name) { |
if(ele.name == name) { |
return ele; |
return ele; |
} |
} |
Line 219 sub render_student_list {
|
Line 235 sub render_student_list {
|
function setAllStudents(value, which) { |
function setAllStudents(value, which) { |
var i; |
var i; |
var ele; |
var ele; |
for (i =0; i < document.forms.helpform.elements.length; i++) { |
for (i =0; i < document.forms.$formname.elements.length; i++) { |
ele = document.forms.helpform.elements[i]; |
ele = document.forms.$formname.elements[i]; |
if(isStudent(ele) && rightSubForm(ele, which)) { |
if(isStudent(ele) && rightSubForm(ele, which)) { |
ele.checked=value; |
ele.checked=value; |
} |
} |
Line 229 sub render_student_list {
|
Line 245 sub render_student_list {
|
function setAllCoursePersonnel(value, which) { |
function setAllCoursePersonnel(value, which) { |
var i; |
var i; |
var ele; |
var ele; |
for (i =0; i < document.forms.helpform.elements.length; i++) { |
for (i =0; i < document.forms.$formname.elements.length; i++) { |
ele = document.forms.helpform.elements[i]; |
ele = document.forms.$formname.elements[i]; |
if(!isStudent(ele) && rightSubForm(ele, which)) { |
if(!isStudent(ele) && rightSubForm(ele, which)) { |
ele.checked = value; |
ele.checked = value; |
} |
} |
Line 239 sub render_student_list {
|
Line 255 sub render_student_list {
|
function setSection(which, value, subform) { |
function setSection(which, value, subform) { |
var i; |
var i; |
var ele; |
var ele; |
for (i =0; i < document.forms.helpform.elements.length; i++) { |
for (i =0; i < document.forms.$formname.elements.length; i++) { |
ele = document.forms.helpform.elements[i]; |
ele = document.forms.$formname.elements[i]; |
if (ele.value.indexOf(':') != -1) { |
if (ele.value.indexOf(':') != -1) { |
if ((section(ele) == which) && rightSubForm(ele, subform)) { |
if ((section(ele) == which) && rightSubForm(ele, subform)) { |
ele.checked = value; |
ele.checked = value; |
Line 257 sub render_student_list {
|
Line 273 sub render_student_list {
|
if (elem != null) { |
if (elem != null) { |
for (k = 0; k < elem.length; k++) { |
for (k = 0; k < elem.length; k++) { |
if (elem.options[k].selected) { |
if (elem.options[k].selected) { |
what = elem.options[k].text; |
what = elem.options[k].value; |
if (what == 'All Students') { |
if (what == 'allstudents') { |
setAllStudents(value, which); |
setAllStudents(value, which); |
} else if (what == 'All Course Personnel') { |
} else if (what == 'allpersonnel') { |
setAllCoursePersonnel(value, which); |
setAllCoursePersonnel(value, which); |
} else if (what == 'No Section') { |
} else if (what == 'nosection') { |
setSection('',value, which); |
setSection('',value, which); |
} else { |
} else { |
setSection(what, value, which); |
setSection(what, value, which); |
Line 309 SCRIPT
|
Line 325 SCRIPT
|
} |
} |
$result .= '<select multiple name="'.$formprefix |
$result .= '<select multiple name="'.$formprefix |
.'.chosensections" size="'.$size.'">'."\n"; |
.'.chosensections" size="'.$size.'">'."\n"; |
$result .= '<option name="allstudents">All Students</option>'; |
$result .= '<option value="allstudents">'.&mt('All Students').'</option>'; |
$result .= '<option name="allpersonnel">All Course Personnel</option>'; |
$result .= '<option value="allpersonnel">'.&mt('All Course Personnel').'</option>'; |
$result .= '<option name="nosection">No Section</option>'; |
$result .= '<option value="nosection">'.&mt('No Section').'</option>'; |
$result .= "\n"; |
$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 .= '<option name="'.$sec.'">'.$sec.'</option>'."\n"; |
$result .= '<option name="'.$sec.'">'.$sec.'</option>'."\n"; |
} |
} |
$result .= '</td><td valign="top">'; |
$result .= '</select></td><td valign="top">'; |
$result .= '<input type="button" name="'.$formprefix.'.select" value="Select" onclick=' |
$result .= '<input type="button" name="'.$formprefix.'.select" value="'.&mt('Select').'" onclick=' |
."'selectSections(\"$formprefix.chosensections\", \"$formprefix\")'".' /></td>'; |
."'selectSections(\"$formprefix.chosensections\", \"$formprefix\")'".' /></td>'; |
$result .= '<td valign="top"><input type="button" name="'.$formprefix |
$result .= '<td valign="top"><input type="button" name="'.$formprefix |
.'.unselect" value="Unselect" onclick='. |
.'.unselect" value="'.&mt('Unselect').'" onclick='. |
"'unselectSections(\"$formprefix.chosensections\", \"$formprefix\")' ".' /></td></tr></table>'; |
"'unselectSections(\"$formprefix.chosensections\", \"$formprefix\")' ".' /></td></tr></table>'; |
} |
} |
|
|
Line 329 SCRIPT
|
Line 345 SCRIPT
|
# True -> checkboxes. |
# True -> checkboxes. |
# False -> radiobuttons. |
# False -> radiobuttons. |
|
|
$result .= "<table border=\"2\">\n"; |
$result .= &Apache::loncommon::start_data_table(); |
$result .= '<tr><th></th><th align="center">Name</th>'."\n"; |
$result .= &Apache::loncommon::start_data_table_header_row(); |
$result .= ' <th align="center">Section</th>'."\n"; |
$result .= '<th></th><th>'.&mt('Name').'</th>'."\n"; |
$result .= ' <th align="center">Status</th>'."\n"; |
$result .= ' <th>'.&mt('Section').'</th>'."\n"; |
$result .= ' <th align="center">Role</th>'."\n"; |
$result .= ' <th>'.&mt('Status').'</th>'."\n"; |
$result .= ' <th align="center">Username : Domain</th></tr>'."\n"; |
$result .= ' <th>'.&mt('Role').'</th>'."\n"; |
|
$result .= ' <th>'.&mt('Username : Domain').'</th>'."\n"; |
|
$result .= &Apache::loncommon::end_data_table_header_row(); |
|
|
my $input_type; |
my $input_type; |
if ($multiselect) { |
if ($multiselect) { |
Line 345 SCRIPT
|
Line 363 SCRIPT
|
|
|
my $checked = 0; |
my $checked = 0; |
for my $student (@$students) { |
for my $student (@$students) { |
$result .= '<tr><td><input type="'.$input_type.'" name="'. |
$result .= &Apache::loncommon::start_data_table_row(). |
$resultname.".forminput".'"'; |
'<td><input type="'.$input_type.'" name="'. |
|
$resultname."_forminput".'"'; |
my $user = $student->[0]; |
my $user = $student->[0]; |
|
|
# Figure out which students are checked by default... |
# Figure out which students are checked by default... |
|
|
if(%$defaultusers) { |
if (%$defaultusers) { |
if (exists ($defaultusers->{$user})) { |
if (exists ($defaultusers->{$user})) { |
$result .= ' checked ="checked" '; |
$result .= ' checked ="checked" '; |
$checked = 1; |
$checked = 1; |
Line 360 SCRIPT
|
Line 379 SCRIPT
|
$result .= ' checked="checked" '; |
$result .= ' checked="checked" '; |
$checked = 1; # First one for radio if no default specified. |
$checked = 1; # First one for radio if no default specified. |
} |
} |
$result .= ' value="'. HTML::Entities::encode($user . ':' |
$result .= ' value="'.&HTML::Entities::encode($user . ':' |
.$student->[2] . ':' |
.$student->[2] . ':' |
.$student->[1] . ':' |
.$student->[1] . ':' |
.$student->[3] . ':' |
.$student->[3] . ':' |
.$student->[4] . ":" |
.$student->[4] . ":" |
.$formprefix, "<>&\"'") |
.$formprefix, "<>&\"'") |
."\" /></td><td>\n"; |
."\" /></td><td>\n"; |
$result .= HTML::Entities::encode($student->[1], '<>&"') |
$result .= &HTML::Entities::encode($student->[1], '<>&"') |
. '</td><td align="center" >'."\n"; |
. '</td><td align="center" >'."\n"; |
$result .= HTML::Entities::encode($student->[2], '<>&"') |
$result .= &HTML::Entities::encode($student->[2], '<>&"') |
. '</td><td align="center">'."\n"; |
. '</td><td align="center">'."\n"; |
$result .= HTML::Entities::encode($student->[3], '<>&"') |
$result .= &HTML::Entities::encode($student->[3], '<>&"') |
. '</td><td align="center">'."\n"; |
. '</td><td align="center">'."\n"; |
$result .= HTML::Entities::encode($student->[4], '<>&"') |
$result .= &HTML::Entities::encode($student->[4], '<>&"') |
. '</td><td align="center">'."\n"; |
. '</td><td align="center">'."\n"; |
$result .= HTML::Entities::encode($student->[0], '<>&"') |
$result .= &HTML::Entities::encode($student->[0], '<>&"') |
. '</td></tr>'."\n"; |
. '</td>'.&Apache::loncommon::end_data_table_row(). |
|
"\n"; |
|
} |
|
$result .= &Apache::loncommon::end_data_table(); |
|
if ($context ne 'email') { |
|
$result .= "<br /> <hr />\n"; |
} |
} |
$result .=" </table> <br /> <hr />\n"; |
|
|
|
return $result; |
return $result; |
} |
} |