--- loncom/publisher/lonunauthorized.pm 2011/11/14 16:05:44 1.13.2.1 +++ loncom/publisher/lonunauthorized.pm 2016/06/19 04:27:58 1.18 @@ -1,7 +1,7 @@ # The LearningOnline Network # Unauthorized to access construction space # -# $Id: lonunauthorized.pm,v 1.13.2.1 2011/11/14 16:05:44 raeburn Exp $ +# $Id: lonunauthorized.pm,v 1.18 2016/06/19 04:27:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,7 +32,6 @@ use strict; use Apache::Constants qw(:common); use Apache::loncommon; use Apache::lonnet; -use Apache::loncacc; use Apache::lonlocal; use LONCAPA(); use HTML::Entities(); @@ -46,18 +45,18 @@ sub handler { # ------------------------------------------------------------ Print the screen # Figure out who the user is and what they wanted to access - my ($ownername,$ownerdomain); + my ($ownername,$ownerdomain,$ownerhome); if ($env{'request.editurl'} ne '') { - ($ownername,$ownerdomain) = - &Apache::loncacc::constructaccess($env{'request.editurl'},$r->dir_config('lonDefDomain')); + ($ownername,$ownerdomain,$ownerhome) = + &Apache::lonnet::constructaccess($env{'request.editurl'}); } # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($env{'request.role'} =~ /^(au|ca|aa)/) { &Apache::lonhtmlcommon::add_breadcrumb({ - 'text' => 'Construction Space', - 'href' => &Apache::loncommon::authorspace(), + 'text' => 'Authoring Space', + 'href' => &Apache::loncommon::authorspace($env{'request.editurl'}), }); } elsif (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { @@ -68,14 +67,13 @@ sub handler { } # print header - $r->print(&Apache::loncommon::start_page("Failed Access to Construction Space", + $r->print(&Apache::loncommon::start_page("Failed Access to Authoring Space", undef, {'domain' => $ownerdomain,}). &Apache::lonhtmlcommon::breadcrumbs()); # figure out what went wrong if ($ownerdomain) { - my $ownerhome=&Apache::lonnet::homeserver($ownername,$ownerdomain); if ($ownerhome eq 'no_host') { $r->print('

'. &mt('Unable to determine home server for this resource: [_1]', @@ -87,8 +85,8 @@ sub handler { my $switchlink = '/adm/switchserver?otherserver='.$ownerhome. '&origurl='.&HTML::Entities::encode($env{'request.editurl'},'<>&"'); $r->print('

'. - &mt('The construction space for this resource is located on another server.'). - ' '.&Apache::lonnet::hostname($ownerhome).''. + &mt('The Authoring Space for this resource is located on a different server: [_1]', + ''.&Apache::lonnet::hostname($ownerhome).''). '

'. '

'. &mt('Switch Server').''. @@ -123,7 +121,7 @@ sub handler { $option = 'decompress'; } elsif ($name eq 'qualifiedfilename') { $qualifiedfilename = $value; - } elsif ($name = 'versionone') { + } elsif ($name eq 'versionone') { if ($value eq 'priv') { $option = 'cstr'; } @@ -162,7 +160,7 @@ sub handler { '

'); } else { if (($action eq 'diff') && ($option eq 'cstr')) { - $filename =~ s{^/res/$LONCAPA::domain_re/($LONCAPA::username_re)}{/priv/$1}; + $filename =~ s{^/res/}{/priv/}; } $r->print('

'. $deniedactions{$action}.'

'. @@ -181,7 +179,7 @@ sub handler { &mt('There is a problem with the filename').' '. ''.$r->uri.'

'. '

'. - &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).'). + &mt('You may be attempting to edit a versioned file (files in Authoring Space may not include a version number before the extension).'). '

'); } else { $r->print('

'. @@ -193,28 +191,63 @@ sub handler { &mt('There is a problem with the filename').' '. ''.$env{'request.editurl'}.'

'. '

'. - &mt('You may be attempting to edit a versioned file (files in construction space may not include a version number before the extension).'). + &mt('You may be attempting to edit a versioned file (files in Authoring Space may not include a version number before the extension).'). '

'); } else { $r->print('

' .&mt('You do not have authoring privileges for this resource').' ' .''.$env{'request.editurl'}.'' .'

'); - my ($realownername) = - ($env{'request.editurl'}=~m{(?:~|priv/|home/)($LONCAPA::username_re)}); + my ($realownerdom,$realownername) = + ($env{'request.editurl'}=~m{^/priv/($LONCAPA::domain_re)/($LONCAPA::username_re)}); my $realownerhome= - &Apache::lonnet::homeserver($realownername, - $r->dir_config('lonDefDomain')); + &Apache::lonnet::homeserver($realownername,$realownerdom); unless ($realownerhome eq 'no_host') { - my $plainname=&Apache::loncommon::plainname($realownername,$r->dir_config('lonDefDomain')); - my $user=$realownername.':'.$r->dir_config('lonDefDomain'); - my $userlink=&Apache::loncommon::aboutmewrapper( - $plainname.' ('.$user.')' - ,$realownername - ,$r->dir_config('lonDefDomain')); - $r->print('

' - .&mt('Contact [_1] for access.',$userlink) - .'

'); + if (&Apache::lonnet::is_course($realownerdom,$realownername)) { + my $ccrole = 'cc'; + my %crsenv = &Apache::lonnet::coursedescription("$realownerdom/$realownername",{one_time => 1}); + my $cdesc = $crsenv{'description'}; + my $crstype = $crsenv{'type'}; + if ($crstype eq 'Community') { + $ccrole = 'co'; + } + my $rolename = $crsenv{$ccrole.'.plaintext'}; + if ($rolename eq '') { + $rolename = &Apache::lonnet::plaintext($ccrole,$crstype,$realownerdom.'_'.$realownername,1); + } + my $allowed = &Apache::lonnet::allowed('mdc',$realownerdom.'_'.$realownername); + if (!$allowed) { + my %roleshash = &Apache::lonnet::get_my_roles('','','userroles',['active'], + [$ccrole],[$realownerdom]); + if (exists($roleshash{$realownername.':'.$realownerdom.':'.$ccrole})) { + $r->print(&mt('[_1]Switch role[_2] for access', + '&"'). + '&orgurl='.&HTML::Entities::encode($env{'request.editurl'},'<>&"'). + '">','')); + } else { + if ($crstype eq 'Community') { + $r->print('

' + .&mt('Contact a [_1] in the community ([_2]) for access.',$rolename,$cdesc) + .'

'); + } else { + $r->print('

' + .&mt('Contact a [_1] in the course ([_2]) for access.',$rolename,$cdesc) + .'

'); + } + } + } + } else { + my $plainname=&Apache::loncommon::plainname($realownername,$realownerdom); + my $user=$realownername.':'.$realownerdom; + my $userlink=&Apache::loncommon::aboutmewrapper( + $plainname.' ('.$user.')' + ,$realownername + ,$realownerdom); + $r->print('

' + .&mt('Contact [_1] for access.',$userlink) + .'

'); + } } } $r->print(&Apache::loncommon::end_page());