--- loncom/interface/loncommon.pm	2013/07/02 19:04:36	1.1134
+++ loncom/interface/loncommon.pm	2013/07/03 05:03:12	1.1135
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1134 2013/07/02 19:04:36 raeburn Exp $
+# $Id: loncommon.pm,v 1.1135 2013/07/03 05:03:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8759,6 +8759,47 @@ sub default_quota {
     }
 }
 
+###############################################
+
+=pod
+
+=item * &excess_filesize_authorspace()
+
+Returns warning message if upload of file to authoring space, or copying
+of existing file within authoring space will cause quota to be exceeded.
+
+Inputs: 6
+1. username
+2. domain
+3. directory path for top level of current authoring space
+4. filename of file for which action is being requested
+5. filesize (kB) of file
+6. action being taken: copy or upload.
+
+Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
+         otherwise return null. 
+
+=cut
+
+sub excess_filesize_authorspace {
+    my ($uname,$udom,$authorspace,$filename,$filesize,$action) = @_;
+    my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
+    $disk_quota = int($disk_quota * 1000);
+    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
+    if (($current_disk_usage + $filesize) > $disk_quota) {
+        return '<p><span class="LC_warning">'.
+                &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
+                    '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
+               '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+                            $disk_quota,$current_disk_usage).
+               '</p>';
+    }
+    return;
+}
+
+###############################################
+
+
 sub get_secgrprole_info {
     my ($cdom,$cnum,$needroles,$type)  = @_;
     my %sections_count = &get_sections($cdom,$cnum);