--- loncom/auth/lonroles.pm 2001/12/21 16:57:54 1.32 +++ loncom/auth/lonroles.pm 2003/12/08 14:25:15 1.79 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.32 2001/12/21 16:57:54 harris41 Exp $ +# $Id: lonroles.pm,v 1.79 2003/12/08 14:25:15 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,9 +36,8 @@ # 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 # ### @@ -51,6 +50,32 @@ use Apache::Constants qw(:common); use Apache::File(); use Apache::lonmenu; use Apache::loncommon; +use Apache::lonannounce; +use Apache::lonlocal; + +sub redirect_user { + my ($r,$title,$url,$msg) = @_; + $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 $bodytag=&Apache::loncommon::bodytag('Switching Role'); + $r->print (<$title + + + +$bodytag + +

$msg

+ + +ENDREDIR + return; +} sub handler { @@ -64,89 +89,163 @@ sub handler { # ================================================================== Roles Init if ($ENV{'form.selectrole'}) { - &Apache::lonnet::appenv("request.course.id" => '', - "request.course.fn" => '', - "request.course.uri" => '', - "request.course.sec" => '', - "request.role" => 'cm'); + if ($ENV{'request.course.id'}) { + 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.adv" => $ENV{'user.adv'}, + "request.role.domain" => $ENV{'user.domain'}); foreach $envkey (keys %ENV) { - if ($envkey=~/^user\.role\./) { - my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey); + 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.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; - print (<Entering Course - + 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 + &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 + ('Enter Access Key to Unlock this Course'); + $r->print(<Entering Course Access Key - +$bodytag -$msg - - -ENDREDIR +
+ + + +
+ +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=&mt('Entering course ...'); + + if (($cnum) && ($role ne 'ca')) { + my ($furl,$ferr)= + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + if (($ENV{'form.orgurl'}) && + ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) { + my $dest=$ENV{'form.orgurl'}; + if ( &Apache::lonnet::mod_perl_version() == 2 ) { + &Apache::lonnet::cleanenv(); + } + $r->internal_redirect($dest); + return OK; + } else { + unless ($ENV{'request.course.id'}) { + &Apache::lonnet::appenv( + "request.course.id" => $cdom.'_'.$cnum); + $furl='/adm/roles?tryagain=1'; + $msg= + '

'. + &mt('Could not initialize course at this time.'). + '

'.&mt('Please try again.').'

'.$ferr; + } + + # 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"; + } + # + # Send the user to the course they selected + &redirect_user($r,&mt('Entering Course'), + $furl,$msg); return OK; - } - } - } - } - } + } + } + # + # Send the user to the construction space they selected + if ($role =~ /^(au|ca)$/) { + my $redirect_url = '/priv/'; + if ($role eq 'au') { + $redirect_url.=$ENV{'user.name'}; + } else { + $where =~ /\/(.*)$/; + $redirect_url .= $1; + } + $redirect_url .= '/'; + &redirect_user($r,&mt('Entering Construction Space'), + $redirect_url); + return OK; + } + } + } } - } - + } + # =============================================================== No Roles Init - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; return OK if $r->header_only; - my $swinfo=&Apache::lonmenu::rawconfig; + 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")); $r->print(< LON-CAPA User Roles - + +$bodytag +$helptag