--- loncom/auth/lonroles.pm 2003/12/30 22:45:59 1.81 +++ loncom/auth/lonroles.pm 2004/08/23 18:57:16 1.98 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.81 2003/12/30 22:45:59 www Exp $ +# $Id: lonroles.pm,v 1.98 2004/08/23 18:57:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,20 +25,6 @@ # # http://www.lon-capa.org/ # -# (Directory Indexer -# (Login Screen -# YEAR=1999 -# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer) -# 11/23 Gerd Kortemeyer) -# YEAR=2000 -# 1/14,03/06,06/01,07/22,07/24,07/25, -# 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28, -# 12/08,12/28, -# YEAR=2001 -# 01/15/01 Gerd Kortemeyer -# 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer -# 12/29 Gerd Kortemeyer -# ### package Apache::lonroles; @@ -54,40 +40,40 @@ 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 return; } -sub authorbombs { - my ($uname,$udom)=@_; - my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); - foreach (keys %bombs) { - if ($_=~/^$udom\/$uname\//) { - return ''; - } - } - return ''; -} - sub handler { my $r = shift; @@ -98,7 +84,6 @@ sub handler { # ================================================================== Roles Init - if ($ENV{'form.selectrole'}) { if ($ENV{'request.course.id'}) { my %temp=('logout_'.$ENV{'request.course.id'} => time); @@ -134,12 +119,61 @@ sub handler { # check for keyed access if (($role eq 'st') && ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) { - unless (&Apache::lonnet::validate_access_key( +# who is key authority? + my $authdom=$cdom; + my $authnum=$cnum; + if ($ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}) { + ($authnum,$authdom)= + split(/\W/,$ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}); + } +# check with key authority + unless (&Apache::lonnet::validate_access_key( $ENV{'environment.key.'.$cdom.'_'.$cnum}, - $cdom,$cnum)) { + $authdom,$authnum)) { # there is no valid key if ($ENV{'form.newkey'}) { # student attempts to register a new key + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $bodytag=&Apache::loncommon::bodytag + ('Verifying Access Key to Unlock this Course'); + 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 + + +$bodytag + +
+ + +$message
+ +
+ +ENDENTEREDKEY + return OK; } else { # print form to enter a new key &Apache::loncommon::content_type($r,'text/html'); @@ -157,7 +191,8 @@ $bodytag $swinfo
- + +
@@ -167,6 +202,10 @@ ENDENTERKEY } } } + &Apache::lonnet::log($ENV{'user.domain'}, + $ENV{'user.name'}, + $ENV{'user.home'}, + "Role ".$trolecode); my $tadv=0; if (($trolecode!~/^st/) && ($trolecode!~/^ta/) && @@ -214,7 +253,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; } } @@ -248,8 +288,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")); + 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(< @@ -315,13 +354,11 @@ ENDHEADER "
\n"); $r->print(&mt( "Author and Co-Author roles may not be available on servers other than your home server.")); - } else { - $r->print("

".&mt('Select a Course to Enter')."

\n"); } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; } - $r->print('
'); + $r->print(''); $r->print(''); $r->print(''); } @@ -331,14 +368,11 @@ ENDHEADER if ($ENV{'form.showall'}) { $r->print(' checked'); } $r->print('>'); } -# ----------------------------------------------------------------------- Table - $r->print('
'); - unless ($nochoose) { $r->print(''); } - $r->print(''."\n"); my (%roletext,%sortrole,%roleclass); + my $countactive=0; + my $inrole=0; + my $possiblerole=''; foreach $envkey (sort keys %ENV) { my $button = 1; my $switchserver=''; @@ -379,6 +413,8 @@ ENDHEADER if ($tstatus eq 'is') { $tbg='#77FF77'; $tfont='#003300'; + $possiblerole=$trolecode; + $countactive++; } elsif ($tstatus eq 'future') { $tbg='#FFFF77'; $button=0; @@ -395,6 +431,8 @@ ENDHEADER } elsif ($tstatus eq 'selected') { $tbg='#11CC55'; $tfont='#002200'; + $inrole=1; + $countactive++; $tremark.=&mt('Currently selected. '); } my $trole; @@ -413,13 +451,16 @@ ENDHEADER # First, Co-Authorship roles if ($role eq 'ca') { my $home = &Apache::lonnet::homeserver($trest,$tdom); - if ($home ne $r->dir_config('lonHostID')) { + my $allowed=0; + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } + if (!$allowed) { $button=0; $switchserver=&Apache::lonnet::escape('http://'. $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}; @@ -428,19 +469,22 @@ ENDHEADER ': '.$tdom.'
'. ' '.&mt('Server').': '.$home; $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca'; - $tremark.=&authorbombs($trest,$tdom); + $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/'); $sortkey=$role."$trest:$tdom"; } elsif ($role eq 'au') { # Authors my $home = &Apache::lonnet::homeserver ($ENV{'user.name'},$ENV{'user.domain'}); - if ($home ne $r->dir_config('lonHostID')) { + my $allowed=0; + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } + if (!$allowed) { $button=0; $switchserver=&Apache::lonnet::escape('http://'. $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}; @@ -448,7 +492,7 @@ ENDHEADER $twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server'). ': '.$home; $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca'; - $tremark.=&authorbombs($ENV{'user.name'},$tdom); + $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/'); $sortkey=$role; } elsif ($trest) { $ttype='Course'; @@ -533,6 +577,35 @@ ENDHEADER } } } +# No active roles + if ($countactive==0) { + if ($inrole) { + $r->print('

'.&mt('Currently no additional roles or courses').'

'); + } else { + $r->print('

'.&mt('Currently no active roles or courses').'

'); + } + $r->print(''); + return OK; +# Is there only one choice? + } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) { + $r->print('

'.&mt('Please stand by.').'

'. + ''); + $r->print("\n"); + $r->rflush(); + $r->print(''); + $r->print(''); + return OK; + } +# More than one possible role +# ----------------------------------------------------------------------- Table + unless (($advanced) || ($nochoose)) { + $r->print("

".&mt('Select a Course to Enter')."

\n"); + } + $r->print('
 '.&mt('User Role').''.&mt('Extent'). - ''.&mt('Start').''.&mt('End').''. - &mt('Remark').'
'); + unless ($nochoose) { $r->print(''); } + $r->print(''."\n"); my $doheaders=-1; foreach my $type ('Construction Space','Course','Domain','System') { my $haverole=0; @@ -640,7 +713,8 @@ ENDHEADER $r->print(&Apache::lonnet::getannounce()); if ($advanced) { $r->print('

This is LON-CAPA '. - $r->dir_config('lonVersion').'

'); + $r->dir_config('lonVersion').'
'. + ''.&mt('Logout').'

'); } $r->print("\n"); return OK;
 '.&mt('User Role').''.&mt('Extent'). + ''.&mt('Start').''.&mt('End').''. + &mt('Remark').'