--- loncom/publisher/lonunauthorized.pm 2013/06/07 16:07:49 1.17 +++ 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.17 2013/06/07 16:07:49 bisitz Exp $ +# $Id: lonunauthorized.pm,v 1.18 2016/06/19 04:27:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -203,15 +203,51 @@ sub handler { my $realownerhome= &Apache::lonnet::homeserver($realownername,$realownerdom); unless ($realownerhome eq 'no_host') { - 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) - .'

'); + 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());