+//
+
+$navwindow
+$msg
+$end_page
+ENDREDIR
+ return;
+}
+
+sub error_page {
+ my ($r,$error,$dest)=@_;
+ &Apache::loncommon::content_type($r,'text/html');
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
+ return OK if $r->header_only;
+ # Breadcrumbs
+ my $brcrum = [{'href' => $dest,
+ 'text' => 'Problems during Course Initialization'},];
+ $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
+ undef,
+ {'bread_crumbs' => $brcrum,})
+ );
+ $r->print(
+ ''.
+ ''.&mt('The following problems occurred:').
+ '
'.
+ $error.
+ '
'.&mt('Continue').''
+ );
+ $r->print(&Apache::loncommon::end_page());
+}
sub handler {
my $r = shift;
my $now=time;
- my $then=$ENV{'user.login.time'};
+ my $then=$env{'user.login.time'};
+ my $refresh=$env{'user.refresh.time'};
+ if (!$refresh) {
+ $refresh = $then;
+ }
my $envkey;
-
+ my %dcroles = ();
+ my $numdc = &check_fordc(\%dcroles,$then);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+ my $custommenu = &Apache::loncommon::needs_gci_custom();
# ================================================================== Roles Init
+ if ($env{'form.selectrole'}) {
+
+ my $locknum=&Apache::lonnet::get_locks();
+ if ($locknum) { return 409; }
- if ($ENV{'form.selectrole'}) {
- if ($ENV{'request.course.id'}) {
- my %temp=('logout_'.$ENV{'request.course.id'} => time);
+ if ($env{'form.newrole'}) {
+ $env{'form.'.$env{'form.newrole'}}=1;
+ }
+ if ($env{'request.course.id'}) {
+ # Check if user is CC trying to select a course role
+ if ($env{'form.switchrole'}) {
+ if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
+ &adhoc_course_role($refresh,$then);
+ }
+ }
+ my %temp=('logout_'.$env{'request.course.id'} => time);
&Apache::lonnet::put('email_status',\%temp);
+ &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
+ }
+ &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'}});
+# Check if user is a DC trying to enter a course or author space and needs privs to be created
+ if ($numdc > 0) {
+ foreach my $envkey (keys %env) {
+# Is this an ad-hoc Coordinator role?
+ if (my ($ccrole,$domain,$coursenum) =
+ ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
+ if ($dcroles{$domain}) {
+ &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $then,$refresh,$now,$ccrole);
+ }
+ last;
+ }
+# Is this an ad-hoc CA-role?
+ if (my ($domain,$user) =
+ ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+ if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
+ delete($env{$envkey});
+ $env{'form.au./'.$domain.'/'} = 1;
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'au./'.$domain.'/';
+ my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ }
+ last;
+ }
+ if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
+ if (((($castart) && ($castart < $now)) || !$castart) &&
+ ((!$caend) || (($caend) && ($caend > $now)))) {
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'ca./'.$domain.'/'.$user;
+ my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ }
+ last;
+ }
+ }
+ # Check if author blocked ca-access
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
+ if ($blocked{'domcoord.author'} eq 'blocked') {
+ delete($env{$envkey});
+ $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
+ last;
+ }
+ if ($dcroles{$domain}) {
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
+ &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
+ $refresh,$now,'ca');
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'ca./'.$domain.'/'.$user;
+ my $switchserver = '/adm/switchserver?'
+ .'otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ }
+ } else {
+ delete($env{$envkey});
+ }
+ } else {
+ delete($env{$envkey});
+ }
+ last;
+ }
+ }
+ }
+ if (($env{'form.cm'}) && ($env{'form.orgurl'})) {
+ $r->internal_redirect($env{'form.orgurl'});
}
- &Apache::lonnet::appenv("request.course.id" => '',
- "request.course.fn" => '',
- "request.course.uri" => '',
- "request.course.sec" => '',
- "request.role" => 'cm',
- "request.role.domain" => $ENV{'user.domain'});
- foreach $envkey (keys %ENV) {
+ 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 (<Entering Course
-
-
-
-$bodytag
-
-$msg
-
-