--- loncom/auth/lonroles.pm 2011/09/27 20:33:34 1.256.2.6 +++ loncom/auth/lonroles.pm 2012/02/08 16:27:35 1.256.2.6.2.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.256.2.6 2011/09/27 20:33:34 raeburn Exp $ +# $Id: lonroles.pm,v 1.256.2.6.2.2 2012/02/08 16:27:35 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -57,8 +57,7 @@ course they should act on, etc. Both in handler determines via C's C<&allowed> function that a certain action is not allowed, C is used as error handler. This allows the user to select another role which may have permission to do -what they were trying to do. C can also be accessed via the -B button in the Remote Control. +what they were trying to do. =begin latex @@ -218,12 +217,33 @@ 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; + } + +# -------------------------------------------------------- Check for new roles + my $updateresult; + if ($env{'form.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; + } + my $envkey; my %dcroles = (); - my $numdc = &check_fordc(\%dcroles,$then); + my $numdc = &check_fordc(\%dcroles,$update,$then); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'}; @@ -243,13 +263,13 @@ sub handler { 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 < $refresh) { + if (!$start || $start < $update) { $switch_is_active = 1; } } } unless ($switch_is_active) { - &adhoc_course_role($refresh,$then); + &adhoc_course_role($refresh,$update,$then); } } my %temp=('logout_'.$env{'request.course.id'} => time); @@ -271,7 +291,7 @@ sub handler { ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { &Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $then,$refresh,$now,$ccrole); + $update,$refresh,$now,$ccrole); } last; } @@ -311,7 +331,7 @@ 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; @@ -333,7 +353,7 @@ 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') { @@ -494,6 +514,11 @@ ENDENTERKEY my $msg; my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + unless (($ferr) || ($env{'form.switchrole'})) { + &Apache::lonnet::put('nohist_crslastlogin', + {$env{'user.name'}.':'.$env{'user.domain'}. + ':'.$csec.':'.$role => $now},$cdom,$cnum); + } if (($env{'form.orgurl'}) && ($env{'form.orgurl'}!~/^\/adm\/flip/)) { my $dest=$env{'form.orgurl'}; @@ -675,6 +700,13 @@ function enterrole (thisform,rolecode,bu alert('$standby'); } } + +function setToUpdate(thisform) { + thisform.doupdate.value='1'; + thisform.selectrole.value=''; + thisform.submit(); +} + // ]]> ENDHEADER @@ -737,13 +769,14 @@ ENDHEADER } # -------------------------------------------------------- Choice or no choice? if ($nochoose) { - $r->print("

".&mt('Sorry ...')."

\n". - &mt('This action is currently not authorized.').''. - &Apache::loncommon::end_page()); - return OK; + $r->print("

".&mt('Sorry ...')."

\n". + &mt('This action is currently not authorized.').''. + &Apache::loncommon::end_page()); + return OK; } else { + $r->print($updateresult); if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { - $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; + $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } $r->print('
'); $r->print(''); @@ -753,23 +786,45 @@ ENDHEADER $r->rflush(); my (%roletext,%sortrole,%roleclass,%futureroles,%timezones); - my ($countactive,$countfuture,$inrole,$possiblerole) = - &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass, + my ($countactive,$countfuture,$inrole,$possiblerole) = + &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass, \%futureroles,\%timezones,$loncaparev); - $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); + my $updatebutton = &mt('Check for role changes'); + my $show_course=&Apache::loncommon::show_course(); + if ($show_course) { + $updatebutton = &mt('Check for new courses'); + } + my $do_update; + unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) { + $do_update = ''. + ''; + } if ($env{'user.adv'}) { - $r->print('

' - .' ' - .'

'); + my $showall = '