--- loncom/publisher/lonupload.pm 2009/07/06 13:30:49 1.48 +++ loncom/publisher/lonupload.pm 2010/02/16 10:26:17 1.49 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Handler to upload files into construction space # -# $Id: lonupload.pm,v 1.48 2009/07/06 13:30:49 bisitz Exp $ +# $Id: lonupload.pm,v 1.49 2010/02/16 10:26:17 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -165,59 +165,74 @@ sub phaseone { } elsif ($mode eq 'imsimport') { $action = '/adm/imsimport'; } + + # Check for file to be uploaded $env{'form.upfile.filename'}=~s/\\/\//g; $env{'form.upfile.filename'}=~s/^.*\/([^\/]+)$/$1/; - if ($env{'form.upfile.filename'}) { - $fn=~s/\/[^\/]+$//; - $fn=~s/([^\/])$/$1\//; - $fn.=$env{'form.upfile.filename'}; - $fn=~s/^\///; - $fn=~s/(\/)+/\//g; - -# Fn is the full path to the destination filename. -# - - &Debug($r, "Filename for upload: $fn"); - if (($fn) && ($fn!~/\/$/)) { - $r->print('
'. - ''. - ''. - ''.&mt('Save uploaded file as [_1]', - "/priv/$uname/". - ''). - '
'. - '
'.&mt('Choose file type:').' -'.&Apache::loncommon::help_open_topic("Uploading_File_Options").' -
-
-'); - $r->print('
'); - # Check for bad extension and warn user - if ($fn=~/\.(\w+)$/ && - (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { + if (!$env{'form.upfile.filename'}) { + $r->print('

'.&mt('No upload file specified.').'

'); + return; + } + + $fn=~s/\/[^\/]+$//; + $fn=~s/([^\/])$/$1\//; + $fn.=$env{'form.upfile.filename'}; + $fn=~s/^\///; + $fn=~s/(\/)+/\//g; + # Fn is the full path to the destination filename. + + # Check for illegal filename + &Debug($r, "Filename for upload: $fn"); + if (!(($fn) && ($fn!~/\/$/))) { + $r->print('

'.&mt('Illegal filename.').'

'); + return; + } + + # Display additional options for upload + # and upload button + $r->print( + '
' + .'' + .'' + .'' + ); + $r->print( + &Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('Save uploaded file as')) + .'/priv/'.$uname.'/' + .'' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title(&mt('File Type')) + .''.&Apache::loncommon::help_open_topic("Uploading_File_Options") + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + ); + $r->print( + '

' + .'' + .'

' + .'
' + ); + + # Check for bad extension and warn user + if ($fn=~/\.(\w+)$/ && + (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { $r->print('

' - .&mt('The extension on this file, [_1], is reserved internally by LON-CAPA.','"'.$1.'"') + .&mt('The extension on this file, [_1], is reserved internally by LON-CAPA.', + ''.$1.'') .'
'.&mt('Please change the extension.') .'

'); - } elsif($fn=~/\.(\w+)$/ && - !defined(&Apache::loncommon::fileembstyle($1))) { + } elsif($fn=~/\.(\w+)$/ && + !defined(&Apache::loncommon::fileembstyle($1))) { $r->print('

' - .&mt('The extension on this file, [_1], is not recognized by LON-CAPA.','"'.$1.'"') + .&mt('The extension on this file, [_1], is not recognized by LON-CAPA.', + ''.$1.'') .'
'.&mt('Please change the extension.') .'

'); - } - } else { - $r->print(''.&mt('Illegal filename.').''); - } - } else { - $r->print(''.&mt('No upload file specified.').''); } } @@ -250,17 +265,22 @@ sub phasetwo { my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; my $dirpath=$path.'/'; $dirpath=~s/\/+/\//g; - $output .= &mt('Upload cancelled.').'
'. - &mt('Back to Directory').''; - } elsif ((-e $target) && (!$env{'form.override'})) { - $output .= '
'. - &mt('File [_1] exists. Overwrite?',''.$fn.''). - ''. - ''. - ''. - ''. - ''. - '
'; + $output .= '

'.&mt('Upload cancelled.').'

' + .'

'. + &mt('Back to Directory').'

'; + } elsif ((-e $target) && (!$env{'form.override'})) { + $output .= '
' + .'

' + .&mt('File [_1] already exists.', + ''.$fn.'') + .'' + .'' + .'' + .'

' + .'' + .' ' + .'

' + .'
'; } else { my $source=$r->dir_config('lonDaemons').'/tmp/'.$datatoken.'.tmp'; my $dirpath=$path.'/'; @@ -289,31 +309,39 @@ sub check_extension { # Check for bad extension and disallow upload if ($fn=~/\.(\w+)$/ && (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { - $result .= &mt('File [_1] could not be copied.', - ''.$fn.' '). - '

'. - &mt('The extension on this file is reserved internally by LON-CAPA.'). - '

'; + $result .= '

'. + &mt('File [_1] could not be copied.', + ''.$fn.' '). + '
'. + &mt('The extension on this file is reserved internally by LON-CAPA.'). + '

'; } elsif ($fn=~/\.(\w+)$/ && !defined(&Apache::loncommon::fileembstyle($1))) { - $result .= &mt('File [_1] could not be copied.', - ''.$fn.' '). - '

'. - &mt('The extension on this file is not recognized by LON-CAPA.'). - '

'; + $result .= '

'. + &mt('File [_1] could not be copied.', + ''.$fn.' '). + '
'. + &mt('The extension on this file is not recognized by LON-CAPA.'). + '

'; } elsif (-d $target) { - $result .= &mt('File [_1] could not be copied.', - ''.$fn.''). - '

'. - &mt('The target is an existing directory.'). - '

'; + $result .= '

'. + &mt('File [_1] could not be copied.', + ''.$fn.''). + '
'. + &mt('The target is an existing directory.'). + '

'; } 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).'

'; + $result .= '

' + .&mt('Your file - [_1] - was uploaded successfully.', + ''.$fn.'') + .'

'; } else { - $result .= &mt('File copied.').'
'; + $result .= '

' + .&mt('File copied.') + .'

'; } # Check for embedded objects. my (%allfiles,%codebase); @@ -342,15 +370,15 @@ STATE } } if (($mode ne 'imsimport') && ($mode ne 'testbank')) { - $result .= '
'. - &mt('View file').''; + $result .= '
'. + &mt('View file').''; } } else { $result .= &mt('Failed to copy: [_1].',$!); } if ($mode ne 'imsimport' && $mode ne 'testbank') { - $result .= '
'. - &mt('Back to Directory').'
'; + $result .= '
'. + &mt('Back to Directory').'
'; } return ($result,$returnflag); }