--- loncom/auth/lonroles.pm 2003/02/03 18:03:52 1.50 +++ loncom/auth/lonroles.pm 2003/06/18 13:13:10 1.60 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.50 2003/02/03 18:03:52 harris41 Exp $ +# $Id: lonroles.pm,v 1.60 2003/06/18 13:13:10 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,7 @@ use Apache::Constants qw(:common); use Apache::File(); use Apache::lonmenu; use Apache::loncommon; +use Apache::lonannounce; sub handler { @@ -67,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= - '

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 (<$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/roles'; + $msg= + '

Could not initialize course at this time.

Please try again.

'; + } + + # Check to see if the user is a CC entering a course + # for the first time + my (undef, undef, $role, $courseid) = split(/\./, $envkey); + if (substr($courseid, 0, 1) eq '/') { + $courseid = substr($courseid, 1); + } + $courseid =~ s/\//_/; + if ($role eq 'cc' && $ENV{'course.' . $courseid . + '.course.helper.not.run'}) { + $furl = "/adm/helper/course.initialization.helper"; + } + + $r->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 @@ -131,10 +188,10 @@ $swinfo ENDREDIR return OK; - } - } - } - } + } + } + } + } } } @@ -146,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(< @@ -167,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? @@ -199,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("

Select a Course to Enter

\n"); } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; @@ -234,8 +291,8 @@ ENDHEADER # ----------------------------------------------------------------------- Table $r->print(''); unless ($nochoose) { $r->print(''); } - $r->print(''. - ''."\n"); + $r->print(''. + ''."\n"); foreach $envkey (sort keys %ENV) { my $button = 1; @@ -310,8 +367,11 @@ ENDHEADER my $home = &Apache::lonnet::homeserver($trest,$tdom); if ($home ne $r->dir_config('lonHostID')) { $button=0; - $switchserver='http://'. - $Apache::lonnet::hostname{$home}.'/priv/'.$trest; + $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}; @@ -325,9 +385,11 @@ ENDHEADER ($ENV{'user.name'},$ENV{'user.domain'}); if ($home ne $r->dir_config('lonHostID')) { $button=0; - $switchserver='http://'. - $Apache::lonnet::hostname{$home}.'/priv/'. - $ENV{'user.name'}; + $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}; @@ -343,10 +405,10 @@ ENDHEADER if ($ENV{'course.'.$tcourseid.'.description'}) { $twhere=$ENV{'course.'.$tcourseid.'.description'}; unless ($twhere eq 'Currently not available') { - $twhere.=' '. + $twhere.=' '. &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont). ''; - } + } } else { my %newhash=Apache::lonnet::coursedescription ($tcourseid); @@ -369,7 +431,6 @@ ENDHEADER $twhere='system wide'; } -# ----- do not trust the indention below here ----- $r->print(''); unless ($nochoose) { if (!$button) { @@ -390,14 +451,17 @@ ENDHEADER $r->print(''); } } - $r->print(''."\n"); - } + } } } my $tremark=''; @@ -410,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
 '.$trole. + $tremark.=&Apache::lonannounce::showday(time,1, + &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); + + $r->print(''.$trole. ''.$ttype. ''.$twhere. ''.$tpstart. ''.$tpend. ''.$tremark. ' 
  No role specified'. ''.$tremark. @@ -425,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;