--- loncom/auth/lonroles.pm 2004/05/08 14:12:16 1.89 +++ loncom/auth/lonroles.pm 2004/11/09 16:18:51 1.103 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.89 2004/05/08 14:12:16 www Exp $ +# $Id: lonroles.pm,v 1.103 2004/11/09 16:18:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,23 +40,34 @@ use Apache::lonannounce; use Apache::lonlocal; sub redirect_user { - my ($r,$title,$url,$msg) = @_; + my ($r,$title,$url,$msg,$launch_nav) = @_; $msg = $title if (! defined($msg)); &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; my $swinfo=&Apache::lonmenu::rawconfig(); + my $navwindow; + if ($launch_nav eq 'on') { + $navwindow.=&Apache::lonnavmaps::launch_win('now'); + } else { + $navwindow.=&Apache::lonnavmaps::close(); + } my $bodytag=&Apache::loncommon::bodytag('Switching Role'); - $r->print (<print(<$title $bodytag - +$navwindow

$msg

+Continue ENDREDIR @@ -73,12 +84,12 @@ sub handler { # ================================================================== Roles Init - if ($ENV{'form.selectrole'}) { if ($ENV{'request.course.id'}) { my %temp=('logout_'.$ENV{'request.course.id'} => time); &Apache::lonnet::put('email_status',\%temp); - } + &Apache::lonnet::delenv('user.state.'.$ENV{'request.course.id'}); + } &Apache::lonnet::appenv("request.course.id" => '', "request.course.fn" => '', "request.course.uri" => '', @@ -88,21 +99,9 @@ sub handler { "request.role.domain" => $ENV{'user.domain'}); foreach $envkey (keys %ENV) { next if ($envkey!~/^user\.role\./); - my (undef,undef,$role,@pwhere)=split(/\./,$envkey); - my $where=join('.',@pwhere); - my $trolecode=$role.'.'.$where; + my ($where,$trolecode,$role,$tstatus,$tend,$tstart); + &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); if ($ENV{'form.'.$trolecode}) { - my ($tstart,$tend)=split(/\./,$ENV{$envkey}); - my $tstatus='is'; - if ($tstart) { - if ($tstart>$then) { - $tstatus='future'; - } - } - if ($tend) { - if ($tend<$then) { $tstatus='expired'; } - if ($tend<$now) { $tstatus='will_not'; } - } if ($tstatus eq 'is') { $where=~s/^\///; my ($cdom,$cnum,$csec)=split(/\//,$where); @@ -129,9 +128,24 @@ sub handler { my $swinfo=&Apache::lonmenu::rawconfig(); my $bodytag=&Apache::loncommon::bodytag ('Verifying Access Key to Unlock this Course'); - my $buttontext=&mt('Re-Enter Key'); - my $message=&mt('Key Verification Failed').'
'. + my $buttontext=&mt('Enter Course'); + my $message=&mt('Successfully registered key'); + my $assignresult= + &Apache::lonnet::assign_access_key( + $ENV{'form.newkey'}, + $authdom,$authnum, + $cdom,$cnum, + $ENV{'user.domain'}, + $ENV{'user.name'}, + 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '. + $trolecode); + unless ($assignresult eq 'ok') { + $assignresult=~s/^error\:\s*//; + $message=&mt($assignresult). + '
'. &mt('Logout').''; + $buttontext=&mt('Re-Enter Key'); + } $r->print(<Verifying Course Access Key @@ -143,7 +157,7 @@ $swinfo
-$message +$message
@@ -181,15 +195,15 @@ ENDENTERKEY $ENV{'user.name'}, $ENV{'user.home'}, "Role ".$trolecode); - my $tadv=0; - if (($trolecode!~/^st/) && - ($trolecode!~/^ta/) && - ($trolecode!~/^cm/)) { $tadv=1; } + &Apache::lonnet::appenv( - 'request.role' => $trolecode, - 'request.role.adv' => $tadv, + 'request.role' => $trolecode, 'request.role.domain' => $cdom, 'request.course.sec' => $csec); + my $tadv=0; + if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } + &Apache::lonnet::appenv('request.role.adv' => $tadv); + my $msg=&mt('Entering course ...'); if (($cnum) && ($role ne 'ca')) { @@ -228,7 +242,8 @@ ENDENTERKEY # # Send the user to the course they selected &redirect_user($r,&mt('Entering Course'), - $furl,$msg); + $furl,$msg, + $ENV{'environment.remotenavmap'}); return OK; } } @@ -262,10 +277,7 @@ ENDENTERKEY my $swinfo=&Apache::lonmenu::rawconfig(); my $bodytag=&Apache::loncommon::bodytag('User Roles'); - my $helptag='
'.&Apache::loncommon::help_open_topic - ("General_Intro",&mt("Click here for help")).''. - &Apache::loncommon::help_open_faq(1,&mt('Click here for FAQ')).''. - &Apache::loncommon::help_open_bug('',&mt('Click here to report bugs')).'
'; + my $helptag='
'.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).'
'; $r->print(< @@ -356,29 +368,17 @@ ENDHEADER my $roletext; my $sortkey; if ($envkey=~/^user\.role\./) { - my (undef,undef,$role,@pwhere)=split(/\./,$envkey); + my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont); + &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); next if (!defined($role) || $role eq ''); - my $where=join('.',@pwhere); - my $trolecode=$role.'.'.$where; - my ($tstart,$tend)=split(/\./,$ENV{$envkey}); - my $tremark=''; - my $tstatus='is'; - my $tpstart=' '; - my $tpend=' '; - my $tfont='#000000'; + $tremark=''; + $tpstart=' '; + $tpend=' '; + $tfont='#000000'; if ($tstart) { - if ($tstart>$then) { - $tstatus='future'; - if ($tstart<$now) { $tstatus='will'; } - } $tpstart=&Apache::lonlocal::locallocaltime($tstart); } if ($tend) { - if ($tend<$then) { - $tstatus='expired'; - } elsif ($tend<$now) { - $tstatus='will_not'; - } $tpend=&Apache::lonlocal::locallocaltime($tend); } if ($ENV{'request.role'} eq $trolecode) { @@ -437,7 +437,7 @@ ENDHEADER $Apache::lonnet::hostname{$home}. '/adm/login?domain='.$ENV{'user.domain'}. '&username='.$ENV{'user.name'}. - '&firsturl=/priv/'.$trest); + '&firsturl=/priv/'.$trest.'/'); } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; @@ -461,7 +461,7 @@ ENDHEADER $Apache::lonnet::hostname{$home}. '/adm/login?domain='.$ENV{'user.domain'}. '&username='.$ENV{'user.name'}. - '&firsturl=/priv/'.$ENV{'user.name'}); + '&firsturl=/priv/'.$ENV{'user.name'}.'/'); } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; @@ -582,7 +582,7 @@ ENDHEADER unless ($nochoose) { $r->print(' '); } $r->print(''.&mt('User Role').''.&mt('Extent'). ''.&mt('Start').''.&mt('End').''. - &mt('Remark').''."\n"); + &mt('Remarks and Calendar Announcements').''."\n"); my $doheaders=-1; foreach my $type ('Construction Space','Course','Domain','System') { my $haverole=0; @@ -597,7 +597,7 @@ ENDHEADER my $output; foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { - $output.=&mt($roletext{$sortrole{$which}}); + $output.=$roletext{$sortrole{$which}}; } } if ($output) { @@ -695,7 +695,38 @@ ENDHEADER } $r->print("\n"); return OK; -} +} + +sub role_status { + my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_; + my @pwhere = (); + if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') { + (undef,undef,$$role,@pwhere)=split(/\./,$rolekey); + unless (!defined($$role) || $$role eq '') { + $$where=join('.',@pwhere); + $$trolecode=$$role.'.'.$$where; + ($$tstart,$$tend)=split(/\./,$ENV{$rolekey}); + $$tstatus='is'; + if ($$tstart) { + if ($tstart>$then) { + $tstatus='future'; + if ($tstart<$now) { $tstatus='will'; } + } + if ($$tstart>$then) { + $$tstatus='future'; + if ($$tstart<$now) { $$tstatus='will'; } + } + } + if ($$tend) { + if ($$tend<$then) { + $$tstatus='expired'; + } elsif ($$tend<$now) { + $$tstatus='will_not'; + } + } + } + } +} 1; __END__