--- loncom/publisher/lonunauthorized.pm 2018/11/26 13:07:41 1.17.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.17.2.1 2018/11/26 13:07:41 raeburn Exp $ +# $Id: lonunauthorized.pm,v 1.18 2016/06/19 04:27:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,8 +102,7 @@ sub handler { if ($ENV{'REDIRECT_URL'} =~ m{^/adm/([^/]+)}) { my $action = $1; my ($option,$filename,$filename1,$filename2,$decompress, - $qualifiedfilename,$warning); - my %deniedactions = &get_denied_action_text(); + $qualifiedfilename); if ($ENV{'REDIRECT_QUERY_STRING'} ne '') { foreach my $pair (split(/&/,$ENV{'REDIRECT_QUERY_STRING'})) { my ($name,$value) = split(/=/,$pair); @@ -131,11 +130,11 @@ sub handler { $option = 'cstr'; } } elsif ($name eq 'filetwo') { - $option = $value; + $option = $value; } } if (($action eq 'upload') || ($action eq 'testbank')) { - if (($filename1 ne '') && ($filename2 ne '')) { + if (($filename1 ne '') && ($filename ne '')) { $filename = $filename1.$filename2; } } elsif ($action eq 'cfile') { @@ -145,6 +144,8 @@ sub handler { $filename = $qualifiedfilename; } } + my %deniedactions = &get_denied_action_text(); + my $warning; if ($option eq 'decompress') { $warning = $deniedactions{$option}; } else { @@ -172,33 +173,6 @@ sub handler { &mt('You are not permitted to take this action.'). '
'); } - } elsif (($action eq 'upload') || ($action eq 'testbank')) { - $filename1 = $env{'form.filename1'}; - $filename2 = $env{'form.filename2'}; - if (($filename1 ne '') && ($filename2 ne '')) { - $filename = $filename1.$filename2; - } - $warning = $deniedactions{$action}; - if ($warning) { - if ($filename =~ m{^/priv/.+\.\d+\.[^.]+$}) { - $r->print(''. - &mt('There is a problem with the filename').' '. - ''.$filename.'
'. - ''. - &mt('The suggested filename may not include the pattern ".number.extension" as LON-CAPA reserves that pattern for its internal versioning mechanism.'). - '
'); - } else { - $r->print(''. - $deniedactions{$action}.'
'. - &mt('You do not have authoring privileges for this resource').' '. - ''.$filename.''. - '
'); - } - } else { - $r->print(''. - &mt('You are not permitted to take this action.'). - '
'); - } } } elsif ($r->uri =~ m{priv/.+\.\d+\.[^.]+$}) { $r->print(''. @@ -229,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());