--- loncom/auth/lonroles.pm 2003/01/16 01:37:26 1.48 +++ loncom/auth/lonroles.pm 2003/06/03 14:08:32 1.58 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.48 2003/01/16 01:37:26 www Exp $ +# $Id: lonroles.pm,v 1.58 2003/06/03 14:08:32 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,9 +36,7 @@ # 12/08,12/28, # YEAR=2001 # 01/15/01 Gerd Kortemeyer -# 02/27/01 Scott Harrison # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer -# 12/21 Scott Harrison # 12/29 Gerd Kortemeyer # ### @@ -52,6 +50,7 @@ use Apache::Constants qw(:common); use Apache::File(); use Apache::lonmenu; use Apache::loncommon; +use Apache::lonannounce; sub handler { @@ -69,57 +68,113 @@ sub handler { my %temp=('logout_'.$ENV{'request.course.id'} => time); &Apache::lonnet::put('email_status',\%temp); } - &Apache::lonnet::appenv("request.course.id" => '', - "request.course.fn" => '', - "request.course.uri" => '', - "request.course.sec" => '', - "request.role" => 'cm', - "request.role.domain" => $ENV{'user.domain'}); + &Apache::lonnet::appenv("request.course.id" => '', + "request.course.fn" => '', + "request.course.uri" => '', + "request.course.sec" => '', + "request.role" => 'cm', + "request.role.adv" => $ENV{'user.adv'}, + "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; 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); - &Apache::lonnet::appenv('request.role' => $trolecode, - 'request.role.domain' => $cdom, - 'request.course.sec' => $csec); - my $msg='Entering course ...'; - if (($cnum) && ($role ne 'ca')) { - my ($furl,$ferr)= - &Apache::lonuserstate::readmap($cdom.'/'.$cnum); - if (($ENV{'form.orgurl'}) && - ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) { - $r->internal_redirect($ENV{'form.orgurl'}); - return OK; - } else { - unless ($ENV{'request.course.id'}) { - &Apache::lonnet::appenv( - "request.course.id" => $cdom.'_'.$cnum); - $furl='/adm/notfound.html'; - $msg= + 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); +# check for keyed access + if (($role eq 'st') && + ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) { + unless (&Apache::lonnet::validate_access_key( + $ENV{'environment.key.'.$cdom.'_'.$cnum}, + $cdom,$cnum)) { +# there is no valid key + if ($ENV{'form.newkey'}) { +# student attempts to register a new key + } else { +# print form to enter a new key + $r->content_type('text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $bodytag=&Apache::loncommon::bodytag + ('Enter Access Key to Unlock this Course'); + $r->print(<Entering Course Access Key + + +$bodytag + +
+ + + +
+ +ENDENTERKEY + return OK; + } + } + } + my $tadv=0; + if (($trolecode!~/^st/) && + ($trolecode!~/^ta/) && + ($trolecode!~/^cm/)) { $tadv=1; } + &Apache::lonnet::appenv( + 'request.role' => $trolecode, + 'request.role.adv' => $tadv, + 'request.role.domain' => $cdom, + 'request.course.sec' => $csec); + my $msg='Entering course ...'; + if (($cnum) && ($role ne 'ca')) { + my ($furl,$ferr)= + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + if (($ENV{'form.orgurl'}) && + ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) { + $r->internal_redirect($ENV{'form.orgurl'}); + return OK; + } else { + unless ($ENV{'request.course.id'}) { + &Apache::lonnet::appenv( + "request.course.id" => $cdom.'_'.$cnum); + $furl='/adm/notfound.html'; + $msg= '

Could not initialize top-level map.

'; - } - $r->content_type('text/html'); - &Apache::loncommon::no_cache($r); - $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig($r); - my $bodytag=&Apache::loncommon::bodytag('Switching Role'); - print (<content_type('text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $bodytag=&Apache::loncommon::bodytag('Switching Role'); + print (<Entering Course @@ -133,10 +188,10 @@ $swinfo ENDREDIR return OK; - } - } - } - } + } + } + } + } } } @@ -148,10 +203,10 @@ ENDREDIR $r->send_http_header; return OK if $r->header_only; - my $swinfo=&Apache::lonmenu::rawconfig($r); + 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"); + ("General_Intro","Click here for help"); $r->print(< @@ -169,8 +224,8 @@ ENDHEADER my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'}); if ($ENV{'user.error.msg'}) { - $r->log_reason( - "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn); + $r->log_reason( + "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn); } # ---------------------------------------------------------------- Who is this? @@ -201,27 +256,27 @@ ENDHEADER # -------------------------------------------------------- Choice or no choice? if ($nochoose) { if ($advanced) { - $r->print("

Assigned User Roles

\n"); + $r->print("

Assigned User Roles

\n"); } else { - $r->print("

Sorry ...

\nThis resource might be part of"); - if ($ENV{'request.course.id'}) { - $r->print(' another'); - } else { - $r->print(' a certain'); - } - $r->print(' course.'); - return OK; + $r->print("

Sorry ...

\nThis resource might be part of"); + if ($ENV{'request.course.id'}) { + $r->print(' another'); + } else { + $r->print(' a certain'); + } + $r->print(' course.'); + return OK; } } else { if ($advanced) { - $r->print("Your home server is ". - $Apache::lonnet::hostname{&Apache::lonnet::homeserver - ($ENV{'user.name'},$ENV{'user.domain'})}. - "
\n"); - $r->print("Author and Co-Author roles may not be available on ". - "servers other than your home server."); + $r->print("Your home server is ". + $Apache::lonnet::hostname{&Apache::lonnet::homeserver + ($ENV{'user.name'},$ENV{'user.domain'})}. + "
\n"); + $r->print("Author and Co-Author roles may not be available on ". + "servers other than your home server."); } else { - $r->print("

Enter a Course

\n"); + $r->print("

Enter a Course

\n"); } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; @@ -236,11 +291,12 @@ ENDHEADER # ----------------------------------------------------------------------- Table $r->print(''); unless ($nochoose) { $r->print(''); } - $r->print(''. - ''."\n"); + $r->print(''. + ''."\n"); foreach $envkey (sort keys %ENV) { my $button = 1; + my $switchserver=''; if ($envkey=~/^user\.role\./) { my (undef,undef,$role,@pwhere)=split(/\./,$envkey); next if (!defined($role) || $role eq ''); @@ -278,12 +334,14 @@ ENDHEADER $tfont='#003300'; } elsif ($tstatus eq 'future') { $tbg='#FFFF77'; + $button=0; } elsif ($tstatus eq 'will') { $tbg='#FFAA77'; $tremark.='Active at next login. '; } elsif ($tstatus eq 'expired') { $tbg='#FF7777'; $tfont='#330000'; + $button=0; } elsif ($tstatus eq 'will_not') { $tbg='#AAFF77'; $tremark.='Expired after logout. '; @@ -307,7 +365,14 @@ ENDHEADER # First, Co-Authorship roles if ($role eq 'ca') { my $home = &Apache::lonnet::homeserver($trest,$tdom); - $button = 0 if ($home ne $r->dir_config('lonHostID')); + if ($home ne $r->dir_config('lonHostID')) { + $button=0; + $switchserver=&Apache::lonnet::escape('http://'. + $Apache::lonnet::hostname{$home}. + '/adm/login?domain='.$ENV{'user.domain'}. + '&username='.$ENV{'user.name'}. + '&firsturl=/priv/'.$trest); + } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; $ttype='Construction Space'; @@ -318,7 +383,14 @@ ENDHEADER # Authors my $home = &Apache::lonnet::homeserver ($ENV{'user.name'},$ENV{'user.domain'}); - $button = 0 if ($home ne $r->dir_config('lonHostID')); + if ($home ne $r->dir_config('lonHostID')) { + $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'}); + } #next if ($home eq 'no_host'); $home = $Apache::lonnet::hostname{$home}; $ttype='Construction Space'; @@ -333,16 +405,18 @@ ENDHEADER if ($ENV{'course.'.$tcourseid.'.description'}) { $twhere=$ENV{'course.'.$tcourseid.'.description'}; unless ($twhere eq 'Currently not available') { - $twhere= - &Apache::loncommon::syllabuswrapper($twhere,$trest,$tdom,$tfont); - } + $twhere.=' '. + &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont). + ''; + } } else { my %newhash=Apache::lonnet::coursedescription ($tcourseid); if (%newhash) { - $twhere= -&Apache::loncommon::syllabuswrapper($newhash{'description'},$trest,$tdom, - $tfont); + $twhere=$newhash{'description'}. + ' '. + &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont). + ''; } else { $twhere='Currently not available'; $ENV{'course.'.$tcourseid.'.description'}=$twhere; @@ -357,11 +431,15 @@ ENDHEADER $twhere='system wide'; } -# ----- do not trust the indention below here ----- $r->print(''); unless ($nochoose) { if (!$button) { - $r->print(''); + if ($switchserver) { + $r->print(''); + } else { + $r->print(''); + } } elsif ($tstatus eq 'is') { $r->print(''); @@ -373,14 +451,17 @@ ENDHEADER $r->print(''); } } - $r->print(''."\n"); - } + } } } my $tremark=''; @@ -393,11 +474,11 @@ ENDHEADER $r->print(''); } unless ($nochoose) { - if ($ENV{'request.role'} ne 'cm') { - $r->print(''); - } else { - $r->print(''); - } + if ($ENV{'request.role'} ne 'cm') { + $r->print(''); + } else { + $r->print(''); + } } $r->print('
 User RoleExtentStartEndRemark
User RoleExtentStartEndRemark
 Switch Server  '.$trole. + $tremark.=&Apache::lonannounce::showday(time,1, + &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); + + $r->print(''.$trole. ''.$ttype. ''.$twhere. ''.$tpstart. ''.$tpend. ''.$tremark. ' 
  No role specified'. ''.$tremark. @@ -408,58 +489,59 @@ ENDHEADER $r->print("\n"); } # ------------------------------------------------------------ Privileges Info - if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) { - $r->print('

Current Privileges

'); + if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) { + $r->print('

Current Privileges

'); - foreach $envkey (sort keys %ENV) { - if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) { - my $where=$envkey; - $where=~s/^user\.priv\.$ENV{'request.role'}\.//; - my $ttype; - my $twhere; - my ($tdom,$trest,$tsec)= - split(/\//,Apache::lonnet::declutter($where)); - if ($trest) { - if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') { - $ttype='Construction Space'; - $twhere='User: '.$trest.', Domain: '.$tdom; - } else { - $ttype='Course'; - $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'}; - if ($tsec) { - $twhere.=' (Section/Group: '.$tsec.')'; - } - } - } elsif ($tdom) { - $ttype='Domain'; - $twhere=$tdom; - } else { - $ttype='System'; - $twhere='/'; - } - $r->print("\n

".$ttype.': '.$twhere.'

    '); - foreach (sort split(/:/,$ENV{$envkey})) { - if ($_) { - my ($prv,$restr)=split(/\&/,$_); - my $trestr=''; - if ($restr ne 'F') { - my $i; - $trestr.=' ('; - for ($i=0;$iprint('
  • '.Apache::lonnet::plaintext($prv).$trestr. - '
  • '); - } - } - $r->print('
'); - } + foreach $envkey (sort keys %ENV) { + if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) { + my $where=$envkey; + $where=~s/^user\.priv\.$ENV{'request.role'}\.//; + my $ttype; + my $twhere; + my ($tdom,$trest,$tsec)= + split(/\//,Apache::lonnet::declutter($where)); + if ($trest) { + if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') { + $ttype='Construction Space'; + $twhere='User: '.$trest.', Domain: '.$tdom; + } else { + $ttype='Course'; + $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'}; + if ($tsec) { + $twhere.=' (Section/Group: '.$tsec.')'; + } + } + } elsif ($tdom) { + $ttype='Domain'; + $twhere=$tdom; + } else { + $ttype='System'; + $twhere='/'; + } + $r->print("\n

".$ttype.': '.$twhere.'

    '); + foreach (sort split(/:/,$ENV{$envkey})) { + if ($_) { + my ($prv,$restr)=split(/\&/,$_); + my $trestr=''; + if ($restr ne 'F') { + my $i; + $trestr.=' ('; + for ($i=0;$iprint('
  • '. + Apache::lonnet::plaintext($prv).$trestr. + '
  • '); + } + } + $r->print('
'); + } + } } - } $r->print("\n"); return OK;