--- loncom/interface/lonsource.pm 2015/05/23 18:10:02 1.33
+++ loncom/interface/lonsource.pm 2017/10/07 21:07:17 1.38
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Source Code handler
#
-# $Id: lonsource.pm,v 1.33 2015/05/23 18:10:02 raeburn Exp $
+# $Id: lonsource.pm,v 1.38 2017/10/07 21:07:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,7 @@ use Apache::lonhtmlcommon();
use Apache::lonsequence();
use Apache::Constants qw(:common :http);
use Apache::lonmeta;
+use Apache::lonenc();
use Apache::File;
use Apache::lonlocal;
use HTML::Entities;
@@ -44,8 +45,9 @@ use LONCAPA qw(:DEFAULT :match);
sub make_link {
my ($filename, $listname) = @_;
- my $sourcelink = "/adm/source?inhibitmenu=yes&filename=".$filename."&listname=".$listname;
-
+ my $sourcelink = '/adm/source?inhibitmenu=yes&filename='.
+ &escape(&escape($filename)).'&listname='.
+ &escape(&escape($listname));
return $sourcelink;
}
@@ -88,58 +90,41 @@ sub copy_author {
sub copy_stage {
my ($r, $filename, $listname, $newpath) = @_;
-#Figure out if we are author or co-author
- my ($role,$author_name,$domain)=©_author();
-
-# Construct path to copy and filter out any possibly nasty stuff
- my $path_to_new_file = $r->dir_config('lonDocRoot').
- "/priv/$domain/$author_name/$newpath/$listname";
- $path_to_new_file=~s/\.\.//g;
- $path_to_new_file=~s/\~//g;
- $path_to_new_file=~s/\/+/\//g;
-
-#Just checking again for access as we want to make sure that it is really ok now that we have the real path
-
- my ($uname,$udom)= &Apache::lonnet::constructaccess($path_to_new_file);
-
- if (!$uname || !$udom) {
- $r->print(&Apache::loncommon::start_page('Not Allowed',undef,{'only_body' => 1}));
- $r->print(&mt('Not allowed to create file [_1]', $path_to_new_file));
- $r->print(&Apache::loncommon::end_page());
- return;
- }
+ my ($path_to_new_file,$uname,$udom) = &get_path_to_newfile($r,$newpath,$listname);
#allowed
- $r->print(&Apache::loncommon::start_page('Copying Source',undef,{'only_body' => 1}));
- my $result = &Apache::loncfile::exists($uname, $udom, $path_to_new_file);
- $r->print($result);
- if(($result) && ($result =~ m|published|) ) {
- &delete_copy_file($r, $newpath, $filename, $path_to_new_file, '1');
- } elsif(($result) && ($result =~ m|exists!|)) {
- &confirm($r, $newpath, $filename, $path_to_new_file);
- } else {
- ©_file($r, $newpath, $filename, $path_to_new_file);
+ if ($path_to_new_file) {
+ $r->print(&Apache::loncommon::start_page('Copying Source',undef,{'only_body' => 1}));
+ my $result = &Apache::loncfile::exists($uname, $udom, $path_to_new_file);
+ $r->print($result);
+ if (($result) && ($result =~ /published/)) {
+ &delete_copy_file($r, $newpath, $filename, $path_to_new_file, '1');
+ } elsif (($result) && ($result =~ /exists\!/)) {
+ &confirm($r, $newpath, $filename, $listname);
+ } else {
+ ©_file($r, $newpath, $filename, $path_to_new_file);
+ }
+ $r->print(&Apache::loncommon::end_page());
}
-
- $r->print(&Apache::loncommon::end_page());
+ return;
}
sub confirm {
- my ($r, $newpath, $filename, $path_to_new_file) = @_;
+ my ($r, $newpath, $filename, $listname) = @_;
$r->print(''.&mt('Press delete to remove file and replace it with a copy of the source you are viewing.').'
');
$r->print('
'
.&mt('Cannot delete non-obsolete published file.')
.'
'
@@ -148,11 +133,12 @@ sub delete_copy_file {
$r->print('
'.&mt('Error:').' '.$!.'
'); return 0; } @@ -162,6 +148,7 @@ sub delete_copy_file { } ©_file($r, $newpath, $filename, $path_to_new_file); $r->print(&Apache::loncommon::end_page()); + return; } } @@ -206,19 +193,31 @@ sub copy_file { .&mt('Close Window').'" name="close" onclick="window.close()" />' .''); #Some 1.3'ish feature is to include the derivative feature, will go here..' + return; } sub print_item { - my ($r,$filename,$listname) = @_; - my $file_output = - &includemeta(&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$filename), - $filename); + my ($r,$filename,$listname,$context) = @_; + my $file_output; + if ($context eq 'view') { + $file_output = + &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$filename); + } else { + $file_output = + &includemeta(&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$filename), + $filename); + } $r->print(&Apache::loncommon::start_page('View Source Code',undef, {'only_body' => 1})); if ($file_output ne '') { my $access_to_cstr; my $lonhost = $r->dir_config('lonHostID'); - if (&Apache::lonnet::is_library($lonhost)) { + if ($context eq 'view') { + $r->print('