--- loncom/auth/lonroles.pm 2003/10/04 18:13:36 1.74 +++ loncom/auth/lonroles.pm 2004/05/08 14:12:16 1.89 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.74 2003/10/04 18:13:36 www Exp $ +# $Id: lonroles.pm,v 1.89 2004/05/08 14:12:16 www 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; @@ -123,12 +109,46 @@ 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('Re-Enter Key'); + my $message=&mt('Key Verification Failed').'
'. + &mt('Logout').''; + $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'); @@ -146,7 +166,8 @@ $bodytag $swinfo
- + +
@@ -156,6 +177,10 @@ ENDENTERKEY } } } + &Apache::lonnet::log($ENV{'user.domain'}, + $ENV{'user.name'}, + $ENV{'user.home'}, + "Role ".$trolecode); my $tadv=0; if (($trolecode!~/^st/) && ($trolecode!~/^ta/) && @@ -202,7 +227,7 @@ ENDENTERKEY } # # Send the user to the course they selected - &redirect_user($r,'Entering Course', + &redirect_user($r,&mt('Entering Course'), $furl,$msg); return OK; } @@ -218,7 +243,7 @@ ENDENTERKEY $redirect_url .= $1; } $redirect_url .= '/'; - &redirect_user($r,'Entering Construction Space', + &redirect_user($r,&mt('Entering Construction Space'), $redirect_url); return OK; } @@ -237,8 +262,10 @@ ENDENTERKEY my $swinfo=&Apache::lonmenu::rawconfig(); my $bodytag=&Apache::loncommon::bodytag('User Roles'); - my $helptag=&Apache::loncommon::help_open_topic - ("General_Intro","Click here for help"); + 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')).'
'; $r->print(< @@ -304,13 +331,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(''); } @@ -320,16 +345,16 @@ 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=''; + my $roletext; + my $sortkey; if ($envkey=~/^user\.role\./) { my (undef,undef,$role,@pwhere)=split(/\./,$envkey); next if (!defined($role) || $role eq ''); @@ -365,6 +390,8 @@ ENDHEADER if ($tstatus eq 'is') { $tbg='#77FF77'; $tfont='#003300'; + $possiblerole=$trolecode; + $countactive++; } elsif ($tstatus eq 'future') { $tbg='#FFFF77'; $button=0; @@ -381,6 +408,8 @@ ENDHEADER } elsif ($tstatus eq 'selected') { $tbg='#11CC55'; $tfont='#002200'; + $inrole=1; + $countactive++; $tremark.=&mt('Currently selected. '); } my $trole; @@ -399,7 +428,10 @@ 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}. @@ -409,16 +441,21 @@ ENDHEADER } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; - $ttype=&mt('Construction Space'); + $ttype='Construction Space'; $twhere=&mt('User').': '.$trest.'
'.&mt('Domain'). ': '.$tdom.'
'. ' '.&mt('Server').': '.$home; $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca'; + $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}. @@ -428,18 +465,21 @@ ENDHEADER } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; - $ttype=&mt('Construction Space'); + $ttype='Construction Space'; $twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server'). ': '.$home; $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca'; + $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/'); + $sortkey=$role; } elsif ($trest) { - $ttype=&mt('Course'); + $ttype='Course'; if ($tsection) { $ttype.='
'.&mt('Section/Group').': '.$tsection; } my $tcourseid=$tdom.'_'.$trest; if ($ENV{'course.'.$tcourseid.'.description'}) { $twhere=$ENV{'course.'.$tcourseid.'.description'}; + $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey; unless ($twhere eq &mt('Currently not available')) { $twhere.=' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont). @@ -449,6 +489,8 @@ ENDHEADER my %newhash=Apache::lonnet::coursedescription ($tcourseid); if (%newhash) { + $sortkey=$role."\0".$tdom."\0".$newhash{'description'}. + "\0".$envkey; $twhere=$newhash{'description'}. ' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont). @@ -456,55 +498,116 @@ ENDHEADER } else { $twhere=&mt('Currently not available'); $ENV{'course.'.$tcourseid.'.description'}=$twhere; + $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey; } } if ($role ne 'st') { $twhere.="
".&mt('Domain').":".$tdom; } } elsif ($tdom) { - $ttype=&mt('Domain'); + $ttype='Domain'; $twhere=$tdom; + $sortkey=$role.$twhere; } else { - $ttype=&mt('System'); + $ttype='System'; $twhere=&mt('system wide'); + $sortkey=$role.$twhere; } - $r->print('
'); + $roletext.=''; unless ($nochoose) { if (!$button) { if ($switchserver) { - $r->print(''); + $roletext.=''; } else { - $r->print(''); + $roletext.=(''); } } elsif ($tstatus eq 'is') { - $r->print(''); } elsif ($tryagain) { - $r->print - (''); + $roletext.= + ''; } elsif ($advanced) { - $r->print - (''); + $roletext.= + ''; } else { - $r->print(''); + $roletext.=''; } } $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); - $r->print(''."\n"); + ' '."\n"; + $roletext{$envkey}=$roletext; + if (!$sortkey) {$sortkey=$twhere."\0".$envkey;} + $sortrole{$sortkey}=$envkey; + $roleclass{$envkey}=$ttype; } } } +# 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').'
'.&mt('Switch Server').''.&mt('Switch Server').'    '.$trole. + $roletext.=''.$trole. ''.$ttype. ''.$twhere. ''.$tpstart. ''.$tpend. ''.$tremark. - ' 
'); + unless ($nochoose) { $r->print(''); } + $r->print(''."\n"); + my $doheaders=-1; + foreach my $type ('Construction Space','Course','Domain','System') { + my $haverole=0; + foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { + if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { + $haverole=1; + } + } + if ($haverole) { $doheaders++; } + } + foreach my $type ('Construction Space','Course','Domain','System') { + 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}}); + } + } + if ($output) { + if ($doheaders > 0) { + $r->print("". + ""); + } + $r->print($output); + } + } my $tremark=''; my $tfont='#003300'; if ($ENV{'request.role'} eq 'cm') { @@ -587,7 +690,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').'
".&mt($type)."