--- loncom/publisher/lonupload.pm 2011/11/14 00:20:31 1.59 +++ loncom/publisher/lonupload.pm 2015/09/11 20:12:30 1.67 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to upload files into construction space # -# $Id: lonupload.pm,v 1.59 2011/11/14 00:20:31 raeburn Exp $ +# $Id: lonupload.pm,v 1.67 2015/09/11 20:12:30 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -125,7 +125,6 @@ use Apache::File; use File::Copy; use File::Basename; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); use Apache::lonnet; use HTML::Entities(); @@ -162,7 +161,7 @@ sub upfile_store { } sub phaseone { - my ($r,$fn,$mode)=@_; + my ($r,$fn,$mode,$uname,$udom)=@_; my $action = '/adm/upload'; if ($mode eq 'testbank') { $action = '/adm/testbank'; @@ -174,7 +173,8 @@ sub phaseone { $env{'form.upfile.filename'}=~s/\\/\//g; $env{'form.upfile.filename'}=~s/^.*\/([^\/]+)$/$1/; if (!$env{'form.upfile.filename'}) { - $r->print('

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

'); + $r->print('

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

'. + &earlyout($fn,$uname,$udom)); return; } @@ -188,6 +188,26 @@ sub phaseone { $r->print('

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

'); return; } + # Check if quota exceeded + my $filesize = length($env{'form.upfile'}); + if (!$filesize) { + $r->print('

'. + &mt('Unable to upload [_1]. (size = [_2] bytes)', + ''.$env{'form.upfile.filename'}.'', + $filesize).'
'. + &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'
'. + '

'. + &earlyout($fn,$uname,$udom)); + return; + } + $filesize = int($filesize/1000); #expressed in kb + my $output = &Apache::loncommon::excess_filesize_warning($uname,$udom,'author', + $env{'form.upfile.filename'},$filesize,'upload'); + if ($output) { + $r->print($output.&earlyout($fn,$uname,$udom)); + return; + } + # Split part that I can change from the part that I cannot change my ($fn1,$fn2)=($fn=~/^(\/priv\/[^\/]+\/[^\/]+\/)(.*)$/); # Display additional options for upload @@ -373,7 +393,7 @@ sub check_extension { if ($pathchg) { if ($mode eq 'testbank') { $returnflag = 'embedded'; - $result .= '

'.&mt('Or [_1]continue[_2] the testbank import without modifying the references(s).','','').'

'; + $result .= '

'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','','').'

'; } } } @@ -407,6 +427,8 @@ sub phasethree { my $dir_root = $r->dir_config('lonDocRoot').$url_root; my $path = &File::Basename::dirname($fn); $path =~ s{^\Q$url_root\E}{}; + my $dirpath = $url_root.$path.'/'; + $dirpath=~s{/+}{/}g; my $filename = &HTML::Entities::encode($env{'form.filename'},'<>&"'); my $state = &embedded_form_elems('modify_orightml',$filename,$mode). ''; @@ -417,7 +439,7 @@ sub phasethree { if ($mode ne 'imsimport' && $mode ne 'testbank') { $result .= '

'. &mt('View main file').'

'. - '

'. + '

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


'; } return ($result,$returnflag); @@ -446,17 +468,29 @@ sub phasefour { my $dir_root = $r->dir_config('lonDocRoot').$url_root; my $path = &File::Basename::dirname($fn); $path =~ s{^\Q$url_root\E}{}; - $result .= &Apache::loncommon::modify_html_refs($mode,$path, - $uname,$udom,$dir_root); + my $dirpath = $url_root.$path.'/'; + $dirpath=~s{/+}{/}g; + my $outcome = + &Apache::loncommon::modify_html_refs($mode,$path,$uname,$udom,$dir_root); + $result .= $outcome; if ($mode ne 'imsimport' && $mode ne 'testbank') { $result .= '

'. &mt('View main file').'

'. - '

'. + '

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


'; } return $result; } +sub earlyout { + my ($fn,$uname,$udom) = @_; + if ($fn =~ m{^(/priv/$udom/$uname(?:.*)/)[^/]*}) { + return &Apache::lonhtmlcommon::actionbox( + [''.&mt('Return to Directory').'']); + } + return; +} + # ---------------------------------------------------------------- Main Handler sub handler { @@ -475,7 +509,7 @@ sub handler { return HTTP_NOT_FOUND; } - my ($uname,$udom)=&Apache::loncacc::constructaccess($fn); + my ($uname,$udom)=&Apache::lonnet::constructaccess($fn); unless (($uname) && ($udom)) { $r->log_reason($uname.' at '.$udom. @@ -518,10 +552,10 @@ ENDJS # Breadcrumbs my $brcrum = [{'href' => &Apache::loncommon::authorspace($fn), - 'text' => 'Construction Space'}, + 'text' => 'Authoring Space'}, {'href' => '/adm/upload', - 'text' => 'Upload file to Construction Space'}]; - $r->print(&Apache::loncommon::start_page('Upload file to Construction Space', + 'text' => 'Upload file to Authoring Space'}]; + $r->print(&Apache::loncommon::start_page('Upload file to Authoring Space', $javascript, {'bread_crumbs' => $brcrum,}) .&Apache::loncommon::head_subbox( @@ -544,7 +578,7 @@ ENDJS my ($output,$returnflag) = &phasetwo($r,$fn); $r->print($output); } else { - &phaseone($r,$fn); + &phaseone($r,$fn,undef,$uname,$udom); } $r->print(&Apache::loncommon::end_page());