--- loncom/auth/lonroles.pm 2010/06/02 15:41:50 1.250 +++ loncom/auth/lonroles.pm 2013/06/02 02:21:43 1.287 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.250 2010/06/02 15:41:50 raeburn Exp $ +# $Id: lonroles.pm,v 1.287 2013/06/02 02:21:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,10 +138,12 @@ use Apache::lonlocal; use Apache::lonpageflip(); use Apache::lonnavdisplay(); use Apache::loncoursequeueadmin; +use Apache::longroup; +use Apache::lonrss; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; - + sub redirect_user { my ($r,$title,$url,$msg) = @_; @@ -203,13 +205,49 @@ sub handler { my $now=time; my $then=$env{'user.login.time'}; my $refresh=$env{'user.refresh.time'}; + my $update=$env{'user.update.time'}; if (!$refresh) { $refresh = $then; } + if (!$update) { + $update = $then; + } + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + +# -------------------------------------------------- Check if setting hot list + my $hotlist; + if ($env{'form.action'} eq 'verify_and_change_rolespref') { + $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r); + } + +# -------------------------------------------------------- Check for new roles + my $updateresult; + if ($env{'form.state'} eq 'doupdate') { + my $show_course=&Apache::loncommon::show_course(); + my $checkingtxt; + if ($show_course) { + $checkingtxt = &mt('Checking for new courses ...'); + } else { + $checkingtxt = &mt('Checking for new roles ...'); + } + $updateresult = $checkingtxt; + $updateresult .= &update_session_roles(); + &Apache::lonnet::appenv({'user.update.time' => $now}); + $update = $now; + &Apache::loncoursequeueadmin::reqauthor_check(); + } + +# -------------------------------------------------- Check for author requests + my $reqauthor; + if ($env{'form.state'} eq 'requestauthor') { + $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update); + } + my $envkey; my %dcroles = (); - my $numdc = &check_fordc(\%dcroles,$then); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + my $numdc = &check_fordc(\%dcroles,$update,$then); + my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'}; # ================================================================== Roles Init if ($env{'form.selectrole'}) { @@ -223,8 +261,17 @@ sub handler { if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role if ($env{'form.switchrole'}) { - if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { - &adhoc_course_role($refresh,$then); + my $switch_is_active; + if (defined($env{'user.role.'.$env{'form.switchrole'}})) { + my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); + if (!$end || $end > $now) { + if (!$start || $start < $update) { + $switch_is_active = 1; + } + } + } + unless ($switch_is_active) { + &adhoc_course_role($refresh,$update,$then); } } my %temp=('logout_'.$env{'request.course.id'} => time); @@ -235,6 +282,7 @@ sub handler { "request.course.fn" => '', "request.course.uri" => '', "request.course.sec" => '', + "request.course.tied" => '', "request.role" => 'cm', "request.role.adv" => $env{'user.adv'}, "request.role.domain" => $env{'user.domain'}}); @@ -245,8 +293,10 @@ sub handler { if (my ($ccrole,$domain,$coursenum) = ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { - &Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $then,$refresh,$now,$ccrole); + if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum, + $update,$refresh,$now,$ccrole)) { + &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time}); + } } last; } @@ -261,6 +311,7 @@ sub handler { my $trolecode = 'au./'.$domain.'/'; my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); + return OK; } last; } @@ -272,6 +323,7 @@ sub handler { my $trolecode = 'ca./'.$domain.'/'.$user; my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); + return OK; } last; } @@ -286,13 +338,14 @@ sub handler { if ($dcroles{$domain}) { my ($server_status,$home) = &check_author_homeserver($user,$domain); if (($server_status eq 'ok') || ($server_status eq 'switchserver')) { - &Apache::lonnet::check_adhoc_privs($domain,$user,$then, + &Apache::lonnet::check_adhoc_privs($domain,$user,$update, $refresh,$now,'ca'); if ($server_status eq 'switchserver') { my $trolecode = 'ca./'.$domain.'/'.$user; my $switchserver = '/adm/switchserver?' .'otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); + return OK; } } else { delete($env{$envkey}); @@ -308,12 +361,48 @@ sub handler { foreach $envkey (keys %env) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); - &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where, + &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where, \$trolecode,\$tstatus,\$tstart,\$tend); if ($env{'form.'.$trolecode}) { if ($tstatus eq 'is') { $where=~s/^\///; my ($cdom,$cnum,$csec)=split(/\//,$where); + if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { + my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'}; + my @ids = &Apache::lonnet::current_machine_ids(); + unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) { + my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); + if ($curr_reqd_hash{'internal.releaserequired'} ne '') { + my ($switchserver,$switchwarning) = + &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'}); + if ($switchwarning ne '' || $switchserver ne '') { + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $end_page=&Apache::loncommon::end_page(); + $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server'). + '
');
+ if ($switchwarning) {
+ $r->print($switchwarning.'
');
+ if (&Apache::loncommon::show_course()) {
+ $r->print(&mt('Display courses'));
+ } else {
+ $r->print(&mt('Display roles'));
+ }
+ $r->print('');
+ } elsif ($switchserver) {
+ $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
+ '
'.
+ ''.
+ &mt('Switch Server').
+ '');
+ }
+ $r->print('