--- loncom/publisher/lonupload.pm 2012/10/29 17:38:55 1.61
+++ loncom/publisher/lonupload.pm 2013/07/02 19:04:49 1.63
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to upload files into construction space
#
-# $Id: lonupload.pm,v 1.61 2012/10/29 17:38:55 raeburn Exp $
+# $Id: lonupload.pm,v 1.63 2013/07/02 19:04:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -161,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';
@@ -173,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;
}
@@ -187,6 +188,32 @@ 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 $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in Mb
+ $disk_quota = int($disk_quota * 1000);
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
+ if (($current_disk_usage + $filesize) > $disk_quota){
+ $r->print(''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$env{'form.upfile.filename'}.'',$filesize).''.
+ '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).
+ ''.
+ &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
@@ -457,6 +484,15 @@ sub phasefour {
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 {
@@ -518,10 +554,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 +580,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());