--- loncom/interface/lonviewclasslist.pm 2007/09/07 00:09:07 1.9 +++ loncom/interface/lonviewclasslist.pm 2013/07/15 17:00:19 1.15 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to display the classlist # -# $Id: lonviewclasslist.pm,v 1.9 2007/09/07 00:09:07 albertel Exp $ +# $Id: lonviewclasslist.pm,v 1.15 2013/07/15 17:00:19 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,6 +34,7 @@ use strict; use Apache::loncoursedata(); use Apache::loncommon(); use Apache::lonhtmlcommon(); +use Apache::courseprefs(); use Apache::Constants qw(:common :http REDIRECT); use Apache::lonlocal; use Apache::lonnet; @@ -60,14 +61,8 @@ sub handler { $r->send_http_header; return OK; } -# &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, -# ['action','state']); - &Apache::lonhtmlcommon::clear_breadcrumbs(); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/viewclasslist", - text=>"View Classlist", - faq=>9,bug=>'Instructor Interface',}); - # Needs to be in a course + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['register','forceedit','action','symb','todocs']); if (! ($env{'request.course.fn'})) { $env{'user.error.msg'}= "/adm/viewclasslist:not in course role"; @@ -76,24 +71,112 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; # - my $start_page = &Apache::loncommon::start_page('Classlist'); - my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs(undef, - 'Enrollment Manager'); + my $start_page; + if ($env{'form.register'}) { + $start_page = &Apache::loncommon::start_page('Classlist',undef, + {'force_register' => $env{'form.register'}}); + } else { + my $brcrum = [{'href' => 'adm/viewclasslist', + 'text' => 'View Classlist'},]; + $start_page = &Apache::loncommon::start_page('Classlist',undef, + {'bread_crumbs' => $brcrum}); + } $r->print(< 0) { - $r->print(&html_classlist($r,\%viewsettings)); + if (($env{'form.forceedit'}) || ($env{'form.action'} eq 'setconfig')) { + if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { + my $crstype = &Apache::loncommon::course_type(); + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $rosterprefs = &roster_prefs($crstype); + my $allitems = {}; + if ($env{'form.action'} eq 'setconfig') { + my %values=&Apache::lonnet::dump('environment',$cdom,$cnum); + if (keys(%values) > 0) { + my ($numchanged,%changes,%disallowed); + my $prefs = { + classlists => $rosterprefs, + }; + $changes{'classlists'} = {}; + &Apache::courseprefs::process_changes($cdom,'classlists',\%values, + $rosterprefs, + $changes{'classlists'}, + $allitems,\%disallowed,$crstype); + my $message; + if (keys(%{$changes{'classlists'}}) > 0) { + my $actions = ['classlists']; + $message = + &Apache::courseprefs::store_changes($cdom,$cnum,$actions, + $actions,$prefs,\%values, + \%changes,$crstype); + } else { + if ($crstype eq 'Community') { + $message = &mt('No changes made to community settings.'); + } else { + $message = &mt('No changes made to course settings.'); + } + } + $r->print(&Apache::loncommon::confirmwrapper($message)); + } else { + $r->print('
'. + &mt('Unable to retrieve current settings.').'
'. + &mt('No changes saved.'). + '
'); + } + } else { + my $current = {}; + my @settings = ('student_classlist_view','student_classlist_opt_in', + 'student_classlist_portfiles'); + foreach my $setting (@settings) { + $current->{$setting} = $env{"course.$env{'request.course.id'}.$setting"}; + } + my ($output,$rowtotal) = + &Apache::courseprefs::print_config_box($r,$cdom,'display', + 'viewableroster', + $rosterprefs,$current, + $allitems,$crstype); + if ($output) { + $r->print('
'."\n". + ''."\n". + ''."\n". + ''."\n"); + if ($env{'form.symb'}) { + $r->print(''."\n"); + } + if ($env{'form.symb'}) { + $r->print(''."\n"); + } + $r->print('
'. + $output. + '

'. + ''. + '
'); + } else { + $r->print('
'. + &mt('No student-viewable course roster settings available.'). + '
'); + } + } + } else { + $r->print('
'. + &mt('You do not have rights to modify student-viewable course roster settings.'). + '
'); + } } else { - $r->print('

'. - &mt("Display of a student-viewable course roster is not currently enabled."). - '

'); + + # Print classlist + 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 @@ -123,6 +206,37 @@ sub retrieve_view_settings { return %viewsettings; } +sub roster_prefs { + my ($crstype) = @_; + my %lt; + if ($crstype eq 'Community') { + %lt = &Apache::lonlocal::texthash ( + stuv => 'Member-viewable membership list options', + stul => 'Member agreement needed to be listed', + ); + } else { + %lt = &Apache::lonlocal::texthash( + stuv => 'Student-viewable classlist options', + stul => 'Student agreement needed to be listed', + ); + } + $lt{'incl'} = &mt('Include link to accessible portfolio files'); + + return + { text => 'Student-viewable roster settings', + header => [ {col1 => 'Setting', + col2 => $lt{'stuv'}}], + ordered => ['student_classlist_view', + 'student_classlist_opt_in', + 'student_classlist_portfiles'], + itemtext => { + student_classlist_view => $lt{'stuv'}, + student_classlist_opt_in => $lt{'stul'}, + student_classlist_portfiles => $lt{'incl'}, + }, + }; +} + sub html_classlist { my ($r,$viewsettings) = @_; my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster); @@ -132,7 +246,7 @@ sub html_classlist { if ($env{'form.action'} eq 'setenv') { $Str .= &process_student_prefs(); } - $Str .= '

'.&mt('Student-viewable course roster').'

'; + $Str .= '

'.&mt('Student-viewable course roster').'

'; $cid = $env{'request.course.id'}; $cdom = $env{'course.'.$cid.'.domain'}; @@ -140,16 +254,16 @@ sub html_classlist { if ($viewsettings->{'limit_to_section'}) { if ($env{'request.course.sec'} eq '') { - $title = '

'.&mt('Students with no section').'

'; + $title = '

'.&mt('Students with no section').'

'; $listtype = 'without a section'; } else { - $title ='

'.&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').'

'; + $title .= '

'.&mt('Students in any section').'

'; $listtype = 'in the course'; } @@ -262,7 +376,7 @@ sub html_classlist { ''.(' 'x2). &Apache::loncommon::messagewrapper (' '. - $username.'@'.$domain,$username,$domain).''; + $username.':'.$domain,$username,$domain).''; if (! $viewsettings->{'limit_to_section'}) { $Str .= ''.$section.''; } @@ -296,19 +410,22 @@ sub print_roster_form { $showoff = ' checked="checked" '; $showon = ' '; } - my $output = '

'.&mt('Your roster setting').'

'; + 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('You are currently [_1]not[_2] listed in the student-viewable roster.','',''); } $output .= '
'.&mt('Include yourself in the roster?').'  '. - '
'. + ''. '  

'. ''. - '

'; + ''. + '

'; return $output; } @@ -337,19 +454,28 @@ sub process_student_prefs { my $putresult = &Apache::lonnet::put('environment', \%changeHash,$udom,$uname); if ($putresult eq 'ok') { - &Apache::lonnet::appenv(%changeHash); + &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); + $output .= + &Apache::lonhtmlcommon::confirm_success( + &mt('Display of your name in the student-viewable roster set to [_1].',''.$visibility.'')); } else { - $output .= ''.&mt('Error occurred saving display setting.').''; + $output .= + &Apache::lonhtmlcommon::confirm_success( + &mt('Error occurred saving display setting.'),1); } } else { - $output .= ''.&mt('Error occurred saving display setting.').''; + $output .= + &Apache::lonhtmlcommon::confirm_success( + &mt('Error occurred saving display setting.'),1); } } else { - $output .= &mt('Display of your name in the student-viewable roster unchanged (set to [_1]).',$visibility); + $output .= + &Apache::lonhtmlcommon::confirm_success( + &mt('Display of your name in the student-viewable roster unchanged (set to [_1]).',''.$visibility.'')); } + $output = &Apache::loncommon::confirmwrapper($output); return $output; }