version 1.36, 2008/01/15 16:04:38
|
version 1.38.2.3, 2008/12/21 04:43:41
|
Line 71 sub upfile_store {
|
Line 71 sub upfile_store {
|
return $datatoken; |
return $datatoken; |
} |
} |
|
|
|
|
sub phaseone { |
sub phaseone { |
my ($r,$fn,$uname,$udom,$mode)=@_; |
my ($r,$fn,$uname,$udom,$mode)=@_; |
my $action = '/adm/upload'; |
my $action = '/adm/upload'; |
Line 99 sub phaseone {
|
Line 98 sub phaseone {
|
'<input type="hidden" name="datatoken" value="'. |
'<input type="hidden" name="datatoken" value="'. |
&upfile_store.'" />'. |
&upfile_store.'" />'. |
'<input type="hidden" name="uploaduname" value="'.$uname. |
'<input type="hidden" name="uploaduname" value="'.$uname. |
'" />'.&mt('Save uploaded file as '). |
'" />'.&mt('Save uploaded file as [_1]', |
"<span class='LC_filename'>/priv/$uname/</span>". |
'<span class="LC_filename">/priv/'.$uname.'/</span>'. |
'<input type="text" size="50" name="filename" value="'.$fn. |
'<input type="text" size="50" name="filename" value="'.$fn. |
'" /><br />'. |
'" />'). |
|
'<br />'. |
'<br />'.&mt('Choose file type:').' |
'<br />'.&mt('Choose file type:').' |
<select name="filetype"> |
<select name="filetype"> |
<option value="standard" selected>'.&mt('Regular file').' |
<option value="standard" selected>'.&mt('Regular file').' |
Line 116 sub phaseone {
|
Line 116 sub phaseone {
|
# Check for bad extension and warn user |
# Check for bad extension and warn user |
if ($fn=~/\.(\w+)$/ && |
if ($fn=~/\.(\w+)$/ && |
(&Apache::loncommon::fileembstyle($1) eq 'hdn')) { |
(&Apache::loncommon::fileembstyle($1) eq 'hdn')) { |
$r->print('<span class="LC_error">'.&mt('The extension on this file,'). |
$r->print('<p class="LC_error">' |
' "'.$1.'"'.&mt(', is reserved internally by LON-CAPA.'). |
.&mt('The extension on this file, [_1], is reserved internally by LON-CAPA.','"'.$1.'"' ) |
' <br />'.&mt('Please change the extension.').'</span>'); |
.' <br />'.&mt('Please change the extension.') |
|
.'</p>'); |
} elsif($fn=~/\.(\w+)$/ && |
} elsif($fn=~/\.(\w+)$/ && |
!defined(&Apache::loncommon::fileembstyle($1))) { |
!defined(&Apache::loncommon::fileembstyle($1))) { |
$r->print('<span class="LC_error">'.&mt('The extension on this file,'). |
$r->print('<p class="LC_error">' |
' "'.$1.'"'.&mt(', is not recognized by LON-CAPA.'). |
.&mt('The extension on this file, [_1], is not recognized by LON-CAPA.','"'.$1.'"') |
' <br />'.&mt('Please change the extension.'). |
.' <br />'.&mt('Please change the extension.') |
'</span>'); |
.'</p>'); |
} |
} |
} else { |
} else { |
$r->print('<span class="LC_error">'.&mt('Illegal filename.').'</span>'); |
$r->print('<span class="LC_error">'.&mt('Illegal filename.').'</span>'); |
Line 136 sub phaseone {
|
Line 137 sub phaseone {
|
|
|
sub phasetwo { |
sub phasetwo { |
my ($r,$tfn,$uname,$udom,$mode)=@_; |
my ($r,$tfn,$uname,$udom,$mode)=@_; |
|
my $output; |
my $action = '/adm/upload'; |
my $action = '/adm/upload'; |
my $returnflag = ''; |
my $returnflag = ''; |
if ($mode eq 'testbank') { |
if ($mode eq 'testbank') { |
Line 162 sub phasetwo {
|
Line 164 sub phasetwo {
|
my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; |
my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; |
my $dirpath=$path.'/'; |
my $dirpath=$path.'/'; |
$dirpath=~s/\/+/\//g; |
$dirpath=~s/\/+/\//g; |
$r->print(&mt('Upload cancelled.').'<br /><font size="+2"><a href="'.$dirpath.'">'. |
$output .= &mt('Upload cancelled.').'<br /><font size="+2"><a href="'.$dirpath.'">'. |
&mt('Back to Directory').'</a></font>'); |
&mt('Back to Directory').'</a></font>'; |
} elsif ((-e $target) && (!$env{'form.override'})) { |
} elsif ((-e $target) && (!$env{'form.override'})) { |
$r->print('<form action="'.$action.'" method="post">'. |
$output .= '<form action="'.$action.'" method="post">'. |
&mt('File [_1] exists. Overwrite?','<span class="LC_filename">'.$fn.'</span>'). |
&mt('File [_1] exists. Overwrite?','<span class="LC_filename">'.$fn.'</span>'). |
'<input type="hidden" name="phase" value="two" />'. |
'<input type="hidden" name="phase" value="two" />'. |
'<input type="hidden" name="filename" value="'."$url".'" />'. |
'<input type="hidden" name="filename" value="'.$url.'" />'. |
'<input type="hidden" name="datatoken" value="'.$datatoken.'" />'. |
'<input type="hidden" name="datatoken" value="'.$datatoken.'" />'. |
'<input type="submit" name="override" value="'.&mt('Yes').'" />'. |
'<input type="submit" name="override" value="'.&mt('Yes').'" />'. |
'<input type="submit" name="cancel" value="'.&mt('Cancel').'" />'. |
'<input type="submit" name="cancel" value="'.&mt('Cancel').'" />'. |
'</form>'); |
'</form>'; |
} else { |
} else { |
my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; |
my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; |
my $dirpath=$path.'/'; |
my $dirpath=$path.'/'; |
$dirpath=~s/\/+/\//g; |
$dirpath=~s/\/+/\//g; |
# Check for bad extension and disallow upload |
# Check for bad extension and disallow upload |
if ($fn=~/\.(\w+)$/ && |
my $result; |
(&Apache::loncommon::fileembstyle($1) eq 'hdn')) { |
($result,$returnflag) = &check_extension($fn,$mode,$source,$target,$action,$dirpath,$url); |
$r->print(&mt('File').' <span class="LC_filename">'.$fn.'</span> '. |
$output .= $result; |
&mt('could not be copied.').'<br />'. |
|
'<span class="LC_error">'. |
|
&mt('The extension on this file is reserved internally by LON-CAPA.'). |
|
'</span>'); |
|
$r->print('<br /><font size=+2><a href="'.$dirpath.'">'. |
|
&mt('Back to Directory').'</a></font>'); |
|
} elsif ($fn=~/\.(\w+)$/ && |
|
!defined(&Apache::loncommon::fileembstyle($1))) { |
|
$r->print(&mt('File').' <span class="LC_filename">'.$fn.'</span> '. |
|
&mt('could not be copied.').'<br />'. |
|
'<span class="LC_error">'. |
|
&mt('The extension on this file is not recognized by LON-CAPA.'). |
|
'</span>'); |
|
$r->print('<br /><font size="+2"><a href="'.$dirpath.'">'. |
|
&mt('Back to Directory').'</a></font>'); |
|
} elsif (-d $target) { |
|
$r->print('File <span class="LC_filename">'.$fn.'</span> could not be copied.<br />'. |
|
'<span class="LC_error">'. |
|
&mt('The target is an existing directory.'). |
|
'</span><br />'); |
|
$r->print('<font size="+2"><a href="'.$dirpath.'">'. |
|
&mt('Back to Directory').'</a></font>'); |
|
} elsif (copy($source,$target)) { |
|
chmod(0660, $target); # Set permissions to rw-rw---. |
|
if ($mode eq 'testbank' || $mode eq 'imsimport') { |
|
$r->print(&mt("Your file - $fn - was uploaded successfully")."<br /><br />"); |
|
$returnflag = 'ok'; |
|
} else { |
|
$r->print(&mt('File copied.')); |
|
$r->print('<br /><font size="+2"><a href="'.$url.'">'. |
|
&mt('View file').'</a></font>'); |
|
$r->print('<br /><font size="+2"><a href="'.$dirpath.'">'. |
|
&mt('Back to Directory').'</a></font><br />'); |
|
} |
|
} else { |
|
$r->print('Failed to copy: '.$!); |
|
$r->print('<br /><font size="+2"><a href="'.$path.'">'. |
|
&mt('Back to Directory').'</a></font>'); |
|
} |
|
} |
} |
} else { |
} else { |
$r->print('<span class="LC_error">'. |
$output .= '<span class="LC_error">'. |
&mt('Please use browser "Back" button and pick a filename'). |
&mt('Please use browser "Back" button and pick a filename'). |
'</span><br />'); |
'</span><br />'; |
} |
} |
} else { |
} else { |
$r->print('<span class="LC_error">'. |
$output .= '<span class="LC_error">'. |
&mt('Please use browser "Back" button and pick a filename'). |
&mt('Please use browser "Back" button and pick a filename'). |
'</span><br />>'); |
'</span><br />'; |
|
} |
|
return ($output,$returnflag); |
|
} |
|
|
|
sub check_extension { |
|
my ($fn,$mode,$source,$target,$action,$dirpath,$url) = @_; |
|
my ($result,$returnflag); |
|
# Check for bad extension and disallow upload |
|
if ($fn=~/\.(\w+)$/ && |
|
(&Apache::loncommon::fileembstyle($1) eq 'hdn')) { |
|
$result .= &mt('File [_1] could not be copied.', |
|
'<span class="LC_filename">'.$fn.'</span> '). |
|
'<p class="LC_error">'. |
|
&mt('The extension on this file is reserved internally by LON-CAPA.'). |
|
'</p>'; |
|
} elsif ($fn=~/\.(\w+)$/ && |
|
!defined(&Apache::loncommon::fileembstyle($1))) { |
|
$result .= &mt('File [_1] could not be copied.', |
|
'<span class="LC_filename">'.$fn.'</span> '). |
|
'<p class="LC_error">'. |
|
&mt('The extension on this file is not recognized by LON-CAPA.'). |
|
'</p>'; |
|
} elsif (-d $target) { |
|
$result .= &mt('File [_1] could not be copied.', |
|
'<span class="LC_filename">'.$fn.'</span>'). |
|
'<p class="LC_error">'. |
|
&mt('The target is an existing directory.'). |
|
'</p>'; |
|
} elsif (copy($source,$target)) { |
|
chmod(0660, $target); # Set permissions to rw-rw---. |
|
if ($mode eq 'testbank' || $mode eq 'imsimport') { |
|
$returnflag = 'ok'; |
|
$result .= &mt('Your file - [_1] - was uploaded successfully',$fn).'<br /><br />'; |
|
} else { |
|
$result .= &mt('File copied.').'<br />'; |
|
} |
|
# Check for embedded objects. |
|
my (%allfiles,%codebase); |
|
my ($text,$header,$css,$js); |
|
if (($mode ne 'imsimport') && ($target =~ /\.(htm|html|shtml)$/i)) { |
|
my (%allfiles,%codebase); |
|
&Apache::lonnet::extract_embedded_items($target,\%allfiles,\%codebase); |
|
if (keys(%allfiles) > 0) { |
|
my $state = <<STATE; |
|
<input type="hidden" name="action" value="upload_embedded" /> |
|
<input type="hidden" name="currentpath" value="$env{'form.currentpath'}" /> |
|
<input type="hidden" name="mode" value="$mode" /> |
|
<input type="hidden" name="phase" value="three" /> |
|
<input type="hidden" name="filename" value="$url" /> |
|
STATE |
|
$result .= "<h3>".&mt("Reference Warning")."</h3>". |
|
"<p>".&mt("Completed upload of the file. This file contained references to other files.")."</p>". |
|
"<p>".&mt("Please select the locations from which the referenced files are to be uploaded.")."</p>". |
|
&Apache::loncommon::ask_for_embedded_content($action,$state,\%allfiles,\%codebase, |
|
{'error_on_invalid_names' => 1, |
|
'ignore_remote_references' => 1,}); |
|
if ($mode eq 'testbank') { |
|
$returnflag = 'embedded'; |
|
$result .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without these files','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>'; |
|
} |
|
} |
|
} |
|
if (($mode ne 'imsimport') && ($mode ne 'testbank')) { |
|
$result .= '<br /><font size="+2"><a href="'.$url.'">'. |
|
&mt('View file').'</a></font>'; |
|
} |
|
} else { |
|
$result .= &mt('Failed to copy: [_1].',$!); |
|
} |
|
if ($mode ne 'imsimport' && $mode ne 'testbank') { |
|
$result .= '<br /><font size="+2"><a href="'.$dirpath.'">'. |
|
&mt('Back to Directory').'</a></font><br />'; |
|
} |
|
return ($result,$returnflag); |
|
} |
|
|
|
sub phasethree { |
|
my ($r,$fn,$uname,$udom,$mode) = @_; |
|
my $result; |
|
my $dir_root = '/home/'.$uname.'/public_html'; |
|
my $url_root = '/priv/'.$uname; |
|
my $base = &File::Basename::basename($fn); |
|
my $path = &File::Basename::dirname($fn); |
|
$result = &Apache::loncommon::upload_embedded($mode,$path,$uname,$udom, |
|
$dir_root,$url_root); |
|
if ($mode ne 'imsimport' && $mode ne 'testbank') { |
|
$result = '<br /><font size="+2"><a href="'.$url_root.$fn.'">'. |
|
&mt('View main file').'</a></font>'. |
|
'<br /><font size="+2"><a href="'.$url_root.$path.'">'. |
|
&mt('Back to Directory').'</a></font><br />'; |
} |
} |
return $returnflag; |
return $result; |
} |
} |
|
|
# ---------------------------------------------------------------- Main Handler |
# ---------------------------------------------------------------- Main Handler |
Line 251 sub handler {
|
Line 304 sub handler {
|
} |
} |
|
|
unless ($env{'form.phase'} eq 'two') { |
unless ($env{'form.phase'} eq 'two') { |
my %body_layout = ('rightmargin' => "0", |
|
'leftmargin' => "0", |
|
'marginwidth' => "0", |
|
'topmargin' => "0", |
|
'marginheight' => "0"); |
|
my $start_page = |
|
&Apache::loncommon::start_page('Importing a Testbank file into LON-CAPA', |
|
undef, |
|
{'only_body' => 1, |
|
'add_entries' => \%body_layout, |
|
'js_ready' => 1,}); |
|
my $end_page = |
|
&Apache::loncommon::end_page({'js_ready' => 1,}); |
|
|
|
$javascript = qq| |
$javascript = qq| |
function verifyForm() { |
function verifyForm() { |
var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value |
var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value |
Line 284 function verifyForm() {
|
Line 323 function verifyForm() {
|
($uname,$udom)= |
($uname,$udom)= |
&Apache::loncacc::constructaccess($env{'form.filename'}, |
&Apache::loncacc::constructaccess($env{'form.filename'}, |
$r->dir_config('lonDefDomain')); |
$r->dir_config('lonDefDomain')); |
|
|
unless (($uname) && ($udom)) { |
unless (($uname) && ($udom)) { |
$r->log_reason($uname.' at '.$udom. |
$r->log_reason($uname.' at '.$udom. |
' trying to publish file '.$env{'form.filename'}. |
' trying to publish file '.$env{'form.filename'}. |
Line 295 function verifyForm() {
|
Line 335 function verifyForm() {
|
my $fn; |
my $fn; |
if ($env{'form.filename'}) { |
if ($env{'form.filename'}) { |
$fn=$env{'form.filename'}; |
$fn=$env{'form.filename'}; |
$fn=~s/^http\:\/\/[^\/]+\///; |
$fn=~s/^https?\:\/\/[^\/]+\///; |
$fn=~s/^\///; |
$fn=~s/^\///; |
$fn=~s{(~|priv/)($LONCAPA::username_re)}{}; |
$fn=~s{(~|priv/)($LONCAPA::username_re)}{}; |
$fn=~s/\/+/\//g; |
$fn=~s/\/+/\//g; |
Line 318 function verifyForm() {
|
Line 358 function verifyForm() {
|
$javascript)); |
$javascript)); |
|
|
if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { |
if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { |
$r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname. |
$r->print('<h3><span class="LC_error">'.&mt('Co-Author').': '.$uname. |
&mt(' at ').$udom.'</font></h3>'); |
&mt(' at ').$udom.'</span></h3>'); |
} |
} |
|
|
if ($env{'form.phase'} eq 'two') { |
if ($env{'form.phase'} eq 'three') { |
&phasetwo($r,$fn,$uname,$udom); |
my $output = &phasethree($r,$fn,$uname,$udom,'author'); |
|
$r->print($output); |
|
} elsif ($env{'form.phase'} eq 'two') { |
|
my ($output,$returnflag) = &phasetwo($r,$fn,$uname,$udom); |
|
$r->print($output); |
} else { |
} else { |
&phaseone($r,$fn,$uname,$udom); |
&phaseone($r,$fn,$uname,$udom); |
} |
} |
Line 377 Start page output
|
Line 421 Start page output
|
|
|
=item * |
=item * |
|
|
output relevant interface phase (phaseone or phasetwo) |
output relevant interface phase (phaseone or phasetwo or phasethree) |
|
|
=item * |
=item * |
|
|
(phase one is to specify upload file; phase two is to handle conditions |
(phase one is to specify upload file; phase two is to handle conditions |
subsequent to specification--like overwriting an existing file) |
subsequent to specification--like overwriting an existing file; phase three |
|
is to handle processing of secondary uploads - of embedded objects in an |
|
html file). |
|
|
=back |
=back |
|
|
Line 401 as overwriting an existing file).
|
Line 447 as overwriting an existing file).
|
|
|
=item * |
=item * |
|
|
|
phasethree() : Interface for handling secondary uploads of embedded objects |
|
in an html file. |
|
|
|
=item * |
|
|
upfile_store() : Store contents of uploaded file into temporary space. Invoked |
upfile_store() : Store contents of uploaded file into temporary space. Invoked |
by phaseone subroutine. |
by phaseone subroutine. |
|
|
|
=item * |
|
|
|
check_extension() : Checks if filename extension is permitted and checks type |
|
of file - if html file, calls parser to check for embedded objects. |
|
Invoked by phasetwo subroutine. |
|
|
=back |
=back |
|
|
=cut |
=cut |