--- loncom/interface/lonviewclasslist.pm 2006/08/25 03:26:05 1.7
+++ loncom/interface/lonviewclasslist.pm 2007/09/07 00:09:07 1.9
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to display the classlist
#
-# $Id: lonviewclasslist.pm,v 1.7 2006/08/25 03:26:05 raeburn Exp $
+# $Id: lonviewclasslist.pm,v 1.9 2007/09/07 00:09:07 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -83,16 +83,17 @@ sub handler {
$start_page
$breadcrumbs
ENDHEADER
- #
+
+ # Get classlist view settings
+ my %viewsettings = &retrieve_view_settings();
+
# Print classlist
- my $cid = $env{'request.course.id'};
- my $viewpermission = 'course.'.$cid.'.student_classlist_view';
- if (&allowed_to_view_classlist()) {
- $r->print(&html_classlist());
- } else {
- $r->print('
'.
- &mt("You are not authorized to view the classlist for your course.").
- '
');
+ if (keys(%viewsettings) > 0) {
+ $r->print(&html_classlist($r,\%viewsettings));
+ } else {
+ $r->print(''.
+ &mt("Display of a student-viewable course roster is not currently enabled.").
+ '
');
}
#
# Finish up
@@ -100,56 +101,147 @@ ENDHEADER
return OK;
}
-sub allowed_to_view_classlist {
- return 0 if (! exists($env{'request.course.id'}));
- my $cid = $env{'request.course.id'};
- my $viewpermission = 'course.'.$cid.'.student_classlist_view';
- if (exists($env{$viewpermission}) &&
- $env{$viewpermission} =~ /^(all|section)$/) {
- return $env{$viewpermission};
- } else {
- return 0;
+sub retrieve_view_settings {
+ my %viewsettings;
+ if (exists($env{'request.course.id'})) {
+ my $cid = $env{'request.course.id'};
+ my $viewpermission = 'course.'.$cid.'.student_classlist_view';
+ my $student_opt_in = 'course.'.$cid.'.student_classlist_opt_in';
+ my $portfiles_link = 'course.'.$cid.'.student_classlist_portfiles';
+ if (exists($env{$viewpermission}) &&
+ $env{$viewpermission} =~ /^(all|section)$/) {
+ $viewsettings{'permission'} = $env{$viewpermission};
+ if ($viewsettings{'permission'} =~ /^section$/i) {
+ $viewsettings{'limit_to_section'} = 1;
+ } else {
+ $viewsettings{'limit_to_section'} = 0;
+ }
+ $viewsettings{'student_opt_in'} = $env{$student_opt_in};
+ $viewsettings{'portfiles_link'} = $env{$portfiles_link};
+ }
}
+ return %viewsettings;
}
sub html_classlist {
- my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
- my $Str;
- if ($limit_to_section) {
+ my ($r,$viewsettings) = @_;
+ my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster);
+ my $fullroster = &Apache::loncoursedata::get_classlist();
+ my $classlist;
+
+ if ($env{'form.action'} eq 'setenv') {
+ $Str .= &process_student_prefs();
+ }
+ $Str .= ''.&mt('Student-viewable course roster').'
';
+
+ $cid = $env{'request.course.id'};
+ $cdom = $env{'course.'.$cid.'.domain'};
+ $cnum = $env{'course.'.$cid.'.num'};
+
+ if ($viewsettings->{'limit_to_section'}) {
if ($env{'request.course.sec'} eq '') {
- $Str .= ''.
- &mt('Students with no section').'
';
+ $title = ''.&mt('Students with no section').'
';
+ $listtype = 'without a section';
} else {
- $Str.=''.
- &mt('Students in section "[_1]"',
- $env{'request.course.sec'}).
- '
';
+ $title =''.&mt('Students in section "[_1]"',
+ $env{'request.course.sec'}).'
';
+ $listtype = 'in the section';
+ $secdisplay = " ($env{'request.course.sec'}) ";
}
+ } else {
+ $title .= ''.&mt('Students in any section').'
';
+ $listtype = 'in the course';
}
- #
- my $classlist = &Apache::loncoursedata::get_classlist();
- #
+
+ if ($viewsettings->{'student_opt_in'}) {
+ if ($env{'request.role'} =~ /^st/) {
+ $Str .= &print_roster_form();
+ }
+ %publicroster = &Apache::lonnet::dump('publicroster',$cdom,$cnum);
+ }
+
+ $Str .= $title;
+
+ my $fullcount = 0;
+ my $publiccount = 0;
+ my $displaycount = 0;
+ my $sectionidx = &Apache::loncoursedata::CL_SECTION();
+ my $statusidx = &Apache::loncoursedata::CL_STATUS();
+
+ foreach my $student (keys(%{$fullroster})) {
+ my $section = $fullroster->{$student}->[$sectionidx];
+ my $status = $fullroster->{$student}->[$statusidx];
+ next if (lc($status) ne 'active');
+ if ($viewsettings->{'limit_to_section'}) {
+ next if ($section ne $env{'request.course.sec'});
+ }
+ $fullcount ++;
+ if ($viewsettings->{'student_opt_in'}) {
+ if ($publicroster{$student}) {
+ $classlist->{$student} = $fullroster->{$student};
+ $publiccount ++;
+ }
+ } else {
+ $classlist->{$student} = $fullroster->{$student};
+ }
+ }
+ if ($viewsettings->{'student_opt_in'}) {
+ $displaycount = $publiccount;
+ if ($fullcount > $publiccount) {
+ if ($publiccount) {
+ $Str .= &mt('Only students who have opted to be listed in the roster ([_1] out of [_2] students) are shown.',$publiccount,$fullcount).'
';
+ } else {
+ if ($fullcount == 1) {
+ $Str .= &mt('The single student '.$listtype.'[_1] has opted not to be listed in the roster.',$secdisplay);
+ } else {
+ $Str .= &mt('None of the [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
+ }
+ return $Str;
+ }
+ } else {
+ if ($fullcount > 1) {
+ $Str .= &mt('All [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
+ } elsif ($fullcount == 1) {
+ $Str .= &mt('The single student '.$listtype.'[_1] has opted to be listed in the roster.',$secdisplay);
+ }
+ }
+ } else {
+ $displaycount = $fullcount;
+ if ($fullcount > 1) {
+ $Str .= &mt('All [_1] students '.$listtype.'[_2] are listed in the roster.',$fullcount,$secdisplay);
+ } elsif ($fullcount == 1) {
+ $Str .= &mt('There is only a single student '.$listtype.'[_1]',$secdisplay);
+ }
+ }
+ undef($fullroster);
+
+ if (!$displaycount) {
+ $Str .= &mt('There are currently no students to display.');
+ return $Str;
+ }
+
# Set up a couple variables.
my $usernameidx = &Apache::loncoursedata::CL_SNAME();
my $domainidx = &Apache::loncoursedata::CL_SDOM();
my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
- my $sectionidx = &Apache::loncoursedata::CL_SECTION();
- my $statusidx = &Apache::loncoursedata::CL_STATUS();
- #
+
# Sort the students
my $sortby = $fullnameidx;
my @Sorted_Students = sort {
lc($classlist->{$a}->[$sortby]) cmp lc($classlist->{$b}->[$sortby])
} (keys(%$classlist));
- $Str .= ''.$/.
- ''.
+ $Str .= '
'.&Apache::loncommon::start_data_table()."\n".
+ &Apache::loncommon::start_data_table_header_row()."\n".
' | '. # for the count
''.&mt('Student').' | '.
''.&mt('Username').' | ';
- if (! $limit_to_section) {
+ if (! $viewsettings->{'limit_to_section'}) {
$Str .= ''.&mt('Section').' | ';
}
- $Str .='
'.$/;
+ if ($viewsettings->{'portfiles_link'}) {
+ $Str .= ''.&mt('Available Portfolio files').' | ';
+ }
+ $Str .= &Apache::loncommon::end_data_table_header_row();
my $count ++;
foreach my $student (@Sorted_Students) {
my $username = $classlist->{$student}->[$usernameidx];
@@ -159,14 +251,10 @@ sub html_classlist {
$fullname = &mt('Name not given');
}
my $section = $classlist->{$student}->[$sectionidx];
- my $status = $classlist->{$student}->[$statusidx];
- next if (lc($status) ne 'active');
- if ($limit_to_section) {
- if ($section ne $env{'request.course.sec'}) {
- next;
- }
+ if ($section eq '') {
+ $section = &mt('none');
}
- $Str .= ''.
+ $Str .= &Apache::loncommon::start_data_table_row()."\n".
''.$count++.' | '.
''.&Apache::loncommon::aboutmewrapper($fullname,
$username,
@@ -175,15 +263,99 @@ sub html_classlist {
&Apache::loncommon::messagewrapper
(' '.
$username.'@'.$domain,$username,$domain).' | ';
- if (! $limit_to_section) {
+ if (! $viewsettings->{'limit_to_section'}) {
$Str .= ''.$section.' | ';
}
- $Str .= '
'.$/;
+ if ($viewsettings->{'portfiles_link'}) {
+ my $filecounts = &Apache::lonaboutme::portfolio_files($r,'showlink',undef,undef,$domain,$username,$fullname);
+ my $link;
+ if (ref($filecounts) eq 'HASH') {
+ $link = &mt('[quant,_1,file,files,No files]',$filecounts->{'both'});
+ if ($filecounts->{'both'} > 0) {
+ $link = ''.$link.'';
+ }
+ } else {
+ $link = ''.&mt("Error retrieving file information.").'';
+ }
+ $Str .= ''.$link.' | ';
+ }
+ $Str .= &Apache::loncommon::end_data_table_row()."\n";
}
- $Str .= '
';
+ $Str .= &Apache::loncommon::end_data_table();
return $Str;
}
+sub print_roster_form {
+ my $cid = $env{'request.course.id'};
+ my $showinroster = $env{'environment.internal.'.$cid.'.showinroster'};
+ my ($showoff,$showon);
+ if ($showinroster) {
+ $showon = ' checked="checked" ';
+ $showoff = ' ';
+ } else {
+ $showoff = ' checked="checked" ';
+ $showon = ' ';
+ }
+ my $output = '
'.&mt('Your roster setting').'
';
+ if ($showinroster) {
+ $output .= &mt('You are currently listed in the student-viewable roster.');
+ } else {
+ $output .= &mt('You are currently not listed in the student-viewable roster.');
+ }
+ $output .= '
'.&mt('Include yourself in the roster?').' '.
+ '
';
+ return $output;
+}
+
+sub process_student_prefs {
+ my $cid = $env{'request.course.id'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $cnum = $env{'course.'.$cid.'.num'};
+ my $uname = $env{'user.name'};
+ my $udom = $env{'user.domain'};
+ my $student = $uname.':'.$udom;
+ my %pubroster = &Apache::lonnet::get('publicroster',[$student],$cdom,$cnum);
+ my $visibility = &mt('off');
+ my $showinroster = $env{'form.showinroster'};
+ if ($showinroster) {
+ $visibility = &mt('on');
+ }
+ my $sturoster = 0;
+ if ($pubroster{$student}) {
+ $sturoster = 1;
+ }
+ my $output;
+ if ($sturoster ne $showinroster) {
+ my %changeHash = (
+ 'environment.internal.'.$cid.'.showinroster' => $showinroster,
+ );
+ my $putresult = &Apache::lonnet::put('environment',
+ \%changeHash,$udom,$uname);
+ if ($putresult eq 'ok') {
+ &Apache::lonnet::appenv(%changeHash);
+ my $result = &Apache::lonnet::put('publicroster',{$student => $showinroster,},$cdom,$cnum);
+ if ($result eq 'ok') {
+ $output .= &mt('Display of your name in the student-viewable roster set to [_1].',$visibility);
+ } else {
+ $output .= ''.&mt('Error occurred saving display setting.').'';
+ }
+ } else {
+ $output .= ''.&mt('Error occurred saving display setting.').'';
+ }
+ } else {
+ $output .= &mt('Display of your name in the student-viewable roster unchanged (set to [_1]).',$visibility);
+ }
+ return $output;
+}
+
+
+
+
###################################################################
###################################################################