--- loncom/publisher/lonunauthorized.pm 2006/12/06 22:22:39 1.6 +++ loncom/publisher/lonunauthorized.pm 2011/11/30 18:38:58 1.13.2.2 @@ -1,7 +1,7 @@ # The LearningOnline Network # Unauthorized to access construction space # -# $Id: lonunauthorized.pm,v 1.6 2006/12/06 22:22:39 albertel Exp $ +# $Id: lonunauthorized.pm,v 1.13.2.2 2011/11/30 18:38:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::lonnet; use Apache::loncacc; use Apache::lonlocal; use LONCAPA(); +use HTML::Entities(); sub handler { my $r = shift; @@ -45,48 +46,195 @@ sub handler { # ------------------------------------------------------------ Print the screen # Figure out who the user is and what they wanted to access - my ($ownername,$ownerdomain)= - &Apache::loncacc::constructaccess($env{'request.editurl'},$r->dir_config('lonDefDomain')); + my ($ownername,$ownerdomain); + if ($env{'request.editurl'} ne '') { + ($ownername,$ownerdomain) = + &Apache::loncacc::constructaccess($env{'request.editurl'},$r->dir_config('lonDefDomain')); + } + + # Breadcrumbs + &Apache::lonhtmlcommon::clear_breadcrumbs(); + if ($env{'request.role'} =~ /^(au|ca|aa)/) { + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'Construction Space', + 'href' => &Apache::loncommon::authorspace(), + }); + } elsif (($env{'request.course.id'}) && + (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { + &Apache::lonhtmlcommon::add_breadcrumb({ + 'text' => 'Course Contents', + 'href' => '/adm/coursedocs', + }); + } + # print header $r->print(&Apache::loncommon::start_page("Failed Access to Construction Space", undef, - {'domain' => $ownerdomain,})); + {'domain' => $ownerdomain,}). + &Apache::lonhtmlcommon::breadcrumbs()); # figure out what went wrong if ($ownerdomain) { - $r->print('
'. -&mt('The constuction space for this resource is located on another server.'). -'
'); my $ownerhome=&Apache::lonnet::homeserver($ownername,$ownerdomain); - unless ($ownerhome eq 'no_host') { - $r->print( - "".&mt('Please log into')." ".$Apache::lonnet::hostname{$ownerhome}. - " ".&mt('to edit.')."
"); + if ($ownerhome eq 'no_host') { + $r->print(''. + &mt('Unable to determine home server for this resource: [_1]', + ''.$env{'request.editurl'}.''). + '
'); + } else { + my @hosts = &Apache::lonnet::current_machine_ids(); + if (!grep(/^\Q$ownerhome\E$/,@hosts)) { + 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('Switch Server').''. + '
'); + } else { + $r->print(''. + &mt('You do not have authoring privileges for this resource').' '. + ''.$env{'request.editurl'}.''. + '
'); + } + } + } elsif (!$env{'request.editurl'}) { + if ($ENV{'REDIRECT_URL'} =~ m{^/adm/([^/]+)}) { + my $action = $1; + my ($option,$filename,$filename1,$filename2,$decompress, + $qualifiedfilename); + if ($ENV{'REDIRECT_QUERY_STRING'} ne '') { + foreach my $pair (split(/&/,$ENV{'REDIRECT_QUERY_STRING'})) { + my ($name,$value) = split(/=/,$pair); + if ($name eq 'filename') { + if (($action eq 'publish') || ($action eq 'cfile')) { + $filename = &LONCAPA::unescape($value); + } else { + $filename = $value; + } + } elsif ($name eq 'filename1') { + $filename1 = $value; + } elsif ($name eq 'filename2') { + $filename2 = $value; + } elsif ($name eq 'decompress') { + $decompress = $value; + $option = 'decompress'; + } elsif ($name eq 'qualifiedfilename') { + $qualifiedfilename = $value; + } elsif ($name eq 'versionone') { + if ($value eq 'priv') { + $option = 'cstr'; + } + } elsif ($name eq 'versiontwo') { + if ($value eq 'priv') { + $option = 'cstr'; + } + } elsif ($name eq 'filetwo') { + $option = $value; + } + } + if (($action eq 'upload') || ($action eq 'testbank')) { + if (($filename1 ne '') && ($filename ne '')) { + $filename = $filename1.$filename2; + } + } elsif ($action eq 'cfile') { + if ($decompress ne '') { + $filename = $decompress; + } elsif ($qualifiedfilename ne '') { + $filename = $qualifiedfilename; + } + } + my %deniedactions = &get_denied_action_text(); + my $warning; + if ($option eq 'decompress') { + $warning = $deniedactions{$option}; + } else { + $warning = $deniedactions{$action}; + } + if ($warning) { + if (($action eq 'diff') && ($option ne 'cstr')) { + $r->print(''. + $deniedactions{$action}.'
'. + &mt('You do not have privileges to view the published resource').' '. + ''.$filename.''. + '
'); + } else { + if (($action eq 'diff') && ($option eq 'cstr')) { + $filename =~ s{^/res/$LONCAPA::domain_re/($LONCAPA::username_re)}{/priv/$1}; + } + $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(''. + &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).'). + '
'); + } else { + $r->print(''. + &mt('You are not permitted to take this action.'). + '
'); } + } elsif ($env{'request.editurl'} =~ m{priv/.+\.\d+\.[^.]+$}) { + $r->print(''. + &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).'). + '
'); } 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 $realownerhome= &Apache::lonnet::homeserver($realownername, - $r->dir_config('lonDefDomain')); + $r->dir_config('lonDefDomain')); unless ($realownerhome eq 'no_host') { - $r->print("".&mt('Contact')." ". - &Apache::loncommon::aboutmewrapper( - &Apache::loncommon::plainname($realownername, - $r->dir_config('lonDefDomain')).' ('. - $realownername.&mt(' at '). - $r->dir_config('lonDefDomain').')', - $realownername,$r->dir_config('lonDefDomain')). - ' for access.
'); + 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) + .'
'); } } - $r->print(&Apache::loncommon::end_page()); return OK; -} +} + +sub get_denied_action_text { + my %deniedtext = + &Apache::lonlocal::texthash( + cfile => 'Copying, moving, renaming or creating file not allowed.', + publish => 'Publishing not allowed.', + upload => 'Uploading file not allowed.', + testbank => 'Uploading testbank file not allowed', + retrieve => 'Retrieving version information not allowed.', + cleanup => 'Clean up of file not allowed.', + diff => 'Display of differences between file versions disallowed.', + decompress => 'Decompression of archive file disallowed.', + ); + return %deniedtext; +} 1; __END__