[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm loncommon.pm londocs.pm lonmodifycourse.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Mon Jul 8 20:17:27 EDT 2013


raeburn		Tue Jul  9 00:17:27 2013 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm londocs.pm 
                     	lonmodifycourse.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Disk quotas for content uploaded directly to a course (userfiles/docs/ and 
     userfiles/supplemental).
    - Default is 500 MB, unless set at domain level, or individual course level. 
    - Domain defaults set by DC  for: official courses, unofficial courses and 
      communities set via "Course/Community defaults" in "Set domain configuration".
    - Quota for individual courses/communities set  by DC via: 
        "View or modify a course or community" 
    - &excess_filesize_authorspace() renamed as excess_filesize_warning() to
      support quota checking in course context, as well as in author context. 
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.197 loncom/interface/domainprefs.pm:1.198
--- loncom/interface/domainprefs.pm:1.197	Tue Jul  2 19:04:36 2013
+++ loncom/interface/domainprefs.pm	Tue Jul  9 00:17:22 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.197 2013/07/02 19:04:36 raeburn Exp $
+# $Id: domainprefs.pm,v 1.198 2013/07/09 00:17:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2445,9 +2445,14 @@
     my $itemcount = 1;
     my %choices =  &Apache::lonlocal::texthash (
         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
+        uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
         coursecredits        => 'Credits can be specified for courses',
     );
+    my %staticdefaults = (
+                           anonsurvey_threshold => 10,
+                           uploadquota          => 500,
+                         );
     if ($position eq 'top') {
         %defaultchecked = ('canuse_pdfforms' => 'off');
         @toggles = ('canuse_pdfforms');
@@ -2455,10 +2460,16 @@
                                                  \%choices,$itemcount);
     } else {
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        my ($currdefresponder,$def_official_credits,$def_unofficial_credits);
+        my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
         my $currusecredits = 0;
+        my @types = ('official','unofficial','community');
         if (ref($settings) eq 'HASH') {
             $currdefresponder = $settings->{'anonsurvey_threshold'};
+            if (ref($settings->{'uploadquota'}) eq 'HASH') {
+                foreach my $type (keys(%{$settings->{'uploadquota'}})) {
+                    $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
+                }
+            }
             if (ref($settings->{'coursecredits'}) eq 'HASH') {
                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
@@ -2468,10 +2479,15 @@
             }
         }
         if (!$currdefresponder) {
-            $currdefresponder = 10;
+            $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
         } elsif ($currdefresponder < 1) {
             $currdefresponder = 1;
         }
+        foreach my $type (@types) {
+            if ($curruploadquota{$type} eq '') {
+                $curruploadquota{$type} = $staticdefaults{'uploadquota'};
+            }
+        }
         $datatable .=
                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                 $choices{'anonsurvey_threshold'}.
@@ -2479,8 +2495,19 @@
                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                 '<input type="text" name="anonsurvey_threshold"'.
                 ' value="'.$currdefresponder.'" size="5" /></span>'.
-                '</td></tr>'."\n";
-        $itemcount ++;
+                '</td></tr>'."\n".
+                '<tr><td><span class="LC_nobreak">'.
+                $choices{'uploadquota'}.
+                '</span></td>'.
+                '<td align="right" class="LC_right_item">'.
+                '<table><tr>';
+        foreach my $type (@types) {
+            $datatable .= '<td align="center">'.&mt($type).'<br />'.
+                           '<input type="text" name="uploadquota_'.$type.'"'.
+                           ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
+        }
+        $datatable .= '</tr></table></td></tr>'."\n";
+        $itemcount += 2;
         my $onclick = 'toggleCredits(this.form);';
         my $display = 'none';  
         if ($currusecredits) {
@@ -7908,6 +7935,13 @@
     my ($resulttext,$errors,%changes,%defaultshash);
     my %defaultchecked = ('canuse_pdfforms' => 'off');
     my @toggles = ('canuse_pdfforms');
+    my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
+                   'uploadquota_community');
+    my @types = ('official','unofficial','community');
+    my %staticdefaults = (
+                           anonsurvey_threshold => 10,
+                           uploadquota          => 500,
+                         );
 
     $defaultshash{'coursedefaults'} = {};
 
@@ -7936,16 +7970,35 @@
             }
             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
         }
-        my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
-        my $newdefresponder = $env{'form.anonsurvey_threshold'};
-        $newdefresponder =~ s/\D//g;
-        if ($newdefresponder eq '' || $newdefresponder < 1) {
-            $newdefresponder = 1;
-        }
-        $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
-        if ($currdefresponder ne $newdefresponder) {
-            unless ($currdefresponder eq '' && $newdefresponder == 10) {
-                $changes{'anonsurvey_threshold'} = 1;
+        foreach my $item (@numbers) {
+            my ($currdef,$newdef);
+            my $newdef = $env{'form.'.$item};
+            if ($item eq 'anonsurvey_threshold') {
+                $currdef = $domconfig{'coursedefaults'}{$item};
+                $newdef =~ s/\D//g;
+                if ($newdef eq '' || $newdef < 1) {
+                    $newdef = 1;
+                }
+                $defaultshash{'coursedefaults'}{$item} = $newdef;
+            } else {
+                my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
+                if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                    $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
+                }
+                $newdef =~ s/[^\w.\-]//g;
+                $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
+            }
+            if ($currdef ne $newdef) {
+                my $staticdef;
+                if ($item eq 'anonsurvey_threshold') {
+                    unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
+                        $changes{$item} = 1;
+                    }
+                } else {
+                    unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
+                        $changes{'uploadquota'} = 1;
+                    }
+                }
             }
         }
         my $officialcreds = $env{'form.official_credits'};
@@ -7971,7 +8024,7 @@
     if ($putresult eq 'ok') {
         my %domdefaults;
         if (keys(%changes) > 0) {
-            if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'})) {
+            if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                 if ($changes{'canuse_pdfforms'}) {
                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
@@ -7984,6 +8037,13 @@
                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
                     }
                 }
+                if ($changes{'uploadquota'}) {
+                    if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                        foreach my $type (@types) {
+                            $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
+                        }
+                    }
+                }
                 my $cachetime = 24*60*60;
                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
             }
@@ -7997,6 +8057,17 @@
                     }
                 } elsif ($item eq 'anonsurvey_threshold') {
                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
+                } elsif ($item eq 'uploadquota') {
+                    if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                        $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
+                                       '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
+                                       '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
+                                       '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
+                                       '</ul>'.
+                                       '</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
+                    }
                 } elsif ($item eq 'coursecredits') {
                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                         if (($domdefaults{'officialcredits'} eq '') &&
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1135 loncom/interface/loncommon.pm:1.1136
--- loncom/interface/loncommon.pm:1.1135	Wed Jul  3 05:03:12 2013
+++ loncom/interface/loncommon.pm	Tue Jul  9 00:17:22 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1135 2013/07/03 05:03:12 raeburn Exp $
+# $Id: loncommon.pm,v 1.1136 2013/07/09 00:17:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8568,7 +8568,9 @@
 1. user's username
 2. user's domain
 3. quota name - portfolio, author, or course
-   (if no quota name provided, defaults to portfolio).  
+   (if no quota name provided, defaults to portfolio).
+4. crstype - official, unofficial or community, if quota name is
+   course
 
 Returns:
 1. Disk quota (in Mb) assigned to student.
@@ -8590,7 +8592,7 @@
 
 
 sub get_user_quota {
-    my ($uname,$udom,$quotaname) = @_;
+    my ($uname,$udom,$quotaname,$crstype) = @_;
     my ($quota,$quotatype,$settingstatus,$defquota);
     if (!defined($udom)) {
         $udom = $env{'user.domain'};
@@ -8641,7 +8643,12 @@
         if ($quota eq '' || wantarray) {
             if ($quotaname eq 'course') {
                 my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
-                $defquota = $domdefs{'uploadquota'};
+                if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) { 
+                    $defquota = $domdefs{$crstype.'quota'};
+                }
+                if ($defquota eq '') {
+                    $defquota = 500;
+                }
             } else {
                 ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
             }
@@ -8763,15 +8770,19 @@
 
 =pod
 
-=item * &excess_filesize_authorspace()
+=item * &excess_filesize_warning()
 
 Returns warning message if upload of file to authoring space, or copying
-of existing file within authoring space will cause quota to be exceeded.
+of existing file within authoring space will cause quota for the authoring
+space to be exceeded,
+
+Same, if upload of a file directly to a course/community via Course Editor
+will cause quota for uploaded content for the course to be exceeded.  
 
 Inputs: 6
-1. username
+1. username or coursenum
 2. domain
-3. directory path for top level of current authoring space
+3. context ('author' or 'course')
 4. filename of file for which action is being requested
 5. filesize (kB) of file
 6. action being taken: copy or upload.
@@ -8781,11 +8792,19 @@
 
 =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
+sub excess_filesize_warning {
+    my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
+    my $current_disk_usage = 0;
+    my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
+    if ($context eq 'author') {
+        my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
+        $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
+    } else {
+        foreach my $subdir ('docs','supplemental') {
+            $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
+        }
+    }
     $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.",
@@ -8800,6 +8819,8 @@
 ###############################################
 
 
+
+
 sub get_secgrprole_info {
     my ($cdom,$cnum,$needroles,$type)  = @_;
     my %sections_count = &get_sections($cdom,$cnum);
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.551 loncom/interface/londocs.pm:1.552
--- loncom/interface/londocs.pm:1.551	Sat May 25 21:56:23 2013
+++ loncom/interface/londocs.pm	Tue Jul  9 00:17:22 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.551 2013/05/25 21:56:23 raeburn Exp $
+# $Id: londocs.pm,v 1.552 2013/07/09 00:17:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2802,8 +2802,30 @@
 }
 
 sub process_file_upload {
-    my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
+    my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
 # upload a file, if present
+    my $filesize = length($env{'form.uploaddoc'});
+    if (!$filesize) {
+        $$upload_output = '<div class="LC_error">'.
+                           &mt('Unable to upload [_1]. (size = [_2] bytes)',
+                          '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
+                          $filesize).'<br />'.
+                          &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
+                          '</div>';
+        return;
+    }
+    my $quotatype = 'unofficial';
+    if ($crstype eq 'Community') {
+        $quotatype = 'community';    
+    } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.instcode'}) {
+        $quotatype = 'official';
+    }
+    if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
+        $filesize = int($filesize/1000); #expressed in kb
+        $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
+                                                                      $env{'form.uploaddoc.filename'},$filesize,'upload');
+        return if ($$upload_output);
+    }
     my ($parseaction,$showupload,$nextphase,$mimetype);
     if ($env{'form.parserflag'}) {
         $parseaction = 'parse';
@@ -4358,7 +4380,7 @@
           # Process file upload - phase one - upload and parse primary file.
 	  undef($hadchanges);
           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
-                                              \%allfiles,\%codebase,$context);
+                                              \%allfiles,\%codebase,$context,$crstype);
 	  if ($hadchanges) {
 	      &mark_hash_old();
 	  }
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.60 loncom/interface/lonmodifycourse.pm:1.61
--- loncom/interface/lonmodifycourse.pm:1.60	Fri Mar  1 05:01:26 2013
+++ loncom/interface/lonmodifycourse.pm	Tue Jul  9 00:17:23 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.60 2013/03/01 05:01:26 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.61 2013/07/09 00:17:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -219,20 +219,22 @@
 sub print_modification_menu {
     my ($r,$cdesc,$domdesc,$dom,$type) = @_;
     &print_header($r,$type);
-    my ($ccrole,$categorytitle,$setquota_text,$setparams_text,$cat_text);
+    my ($ccrole,$categorytitle,$setquota_text,$setuploadquota_text,$setparams_text,$cat_text);
     if ($type eq 'Community') {
         $ccrole = 'co';
     } else {
         $ccrole = 'cc';
-    } 
+    }
     if ($type eq 'Community') {
         $categorytitle = 'View/Modify Community Settings';
         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
+        $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); 
         $setparams_text = 'View/Modify community owner';
         $cat_text = 'View/Modify catalog settings for community';
     } else {
         $categorytitle = 'View/Modify Course Settings';
         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
+        $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
         if (&showcredits($dom)) {
             $setparams_text = 'View/Modify course owner, institutional code, and default authentication and credits';
         } else {
@@ -261,7 +263,7 @@
                 linktitle => ''
             },
             {
-                linktext => 'View/Modify quota for group portfolio files',
+                linktext => 'View/Modify quotas for group portfolio files, and for uploaded content.',
                 url => &phaseurl('setquota'),
                 permission => 1,
                 #help => '',
@@ -317,6 +319,7 @@
         }
     }
     $menu_html .= '<li>'.$setquota_text.'</li>'.
+                  '<li>'.$setuploadquota_text.'</li>'.
                   '<li>'.$anon_text.'</li>'."\n";
     foreach my $item (@additional_params) {
         if ($type eq 'Community') {
@@ -420,28 +423,55 @@
 
 sub print_setquota {
     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
+    my $lctype = lc($type);
+    my $headline = &mt("Set disk space quotas for $lctype: [_1]",
+                     '<span class="LC_nobreak">'.$cdesc.'</span>');
     my %lt = &Apache::lonlocal::texthash(
-                'cquo' => 'Disk space for storage of group portfolio files for:',
-                'gpqu' => 'Course portfolio files disk space',
+                'gpqu' => 'Disk space for storage of group portfolio files',
+                'upqu' => 'Disk space for storage of content directly uploaded to course via Content Editor',
                 'modi' => 'Save',
                 'back' => 'Pick another action',
     );
-    if ($type eq 'Community') {
-        $lt{'gpqu'} = &mt('Community portfolio files disk space');
-    }
-    my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
+    my %staticdefaults = (
+                           coursequota   => 20,
+                           uploadquota   => 500,
+                         );
+    my %settings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota','internal.instcode'],
+                                        $cdom,$cnum);
     my $coursequota = $settings{'internal.coursequota'};
+    my $uploadquota = $settings{'internal.uploadquota'};
     if ($coursequota eq '') {
-        $coursequota = 20;
+        $coursequota = $staticdefaults{'coursequota'};
+    }
+    if ($uploadquota eq '') {
+        my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+        if ($type eq 'Community') {
+            $uploadquota = $domdefs{$lctype.'quota'};
+        } elsif ($settings{'internal.instcode'}) {
+            $uploadquota = $domdefs{'officialquota'};
+        } else {
+            $uploadquota = $domdefs{'unofficialquota'};
+        }
+        if ($uploadquota eq '') {
+            $uploadquota = $staticdefaults{'uploadquota'};
+        }
     }
     &print_header($r,$type);
     my $hidden_elements = &hidden_form_elements();
-    my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
+    my $porthelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
+    my $uploadhelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Upload_Quota');
     $r->print(<<ENDDOCUMENT);
 <form action="/adm/modifycourse" method="post" name="setquota" onsubmit="return verify_quota();">
-<h3>$lt{'cquo'} <span class="LC_nobreak">$cdesc</span></h3>
+<h3>$headline</h3>
+<p><span class="LC_nobreak">
+$porthelpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> MB
+</span>
+<br />
+<span class="LC_nobreak">
+$uploadhelpitem $lt{'upqu'}: <input type="text" size="4" name="uploadquota" value="$uploadquota" /> MB
+</span>
+</p>
 <p>
-$helpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb     
 <input type="submit" value="$lt{'modi'}" />
 </p>
 $hidden_elements
@@ -1126,58 +1156,104 @@
 sub modify_quota {
     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
     &print_header($r,$type);
+    my $lctype = lc($type);
+    my $headline = &mt("Disk space quotas for $lctype: [_1]",
+                     '<span class="LC_nobreak">'.$cdesc.'</span>');
     $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
-              '<h3>'.&mt('Disk space for storage of group portfolio files for:').
-              ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
-    my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
-    my $defaultquota = 20;
-    if ($env{'form.coursequota'} ne '') {
-        my $newquota = $env{'form.coursequota'};
-        if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
-            $newquota = $1;
-            if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
-                $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] Mb.',$env{'form.coursequota'}));
+              '<h3>'.$headline.'</h3>');
+    my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
+    my %staticdefaults = (
+                           coursequota   => 20,
+                           uploadquota   => 500,
+                         );
+    my %default;
+    $default{'coursequota'} = $staticdefaults{'coursequota'};
+    my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+    $default{'uploadquota'} = $domdefs{'uploadquota'};
+    if ($default{'uploadquota'} eq '') {
+        $default{'uploadquota'} = $staticdefaults{'uploadquota'};
+    }
+    my (%cenv,%showresult);
+    foreach my $item ('coursequota','uploadquota') {
+        if ($env{'form.'.$item} ne '') {
+            my $newquota = $env{'form.'.$item};
+            if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
+                $newquota = $1;
+                if ($oldsettings{'internal.'.$item} == $newquota) {
+                    if ($item eq 'coursequota') {
+                        $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] MB.',$newquota).'<br />');
+                    } else {
+                        $r->print(&mt('The disk space allocated for files uploaded via the Content Editor remains unchanged as [_1] MB.',$newquota).'<br />');
+                    }
+                } else {
+                    $cenv{'internal.'.$item} = $newquota;
+                    $showresult{$item} = 1;
+                }
             } else {
-                my %cenv = (
-                           'internal.coursequota' => $env{'form.coursequota'},
-                           );
-                my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
-                                                    $cnum);
-                if (($oldsettings{'internal.coursequota'} eq '') && 
-                    ($env{'form.coursequota'} == $defaultquota)) {
+                if ($item eq 'coursequota') { 
+                    $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'<br />');
+                } else {
+                    $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'<br />');
+
+                }
+            }
+        }
+    }
+    if (keys(%cenv)) {
+        my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
+                                            $cnum);
+        foreach my $key (sort(keys(%showresult))) {
+            if (($oldsettings{'internal.'.$key} eq '') && 
+                ($env{'form.'.$key} == $default{$key})) {
+                if ($key eq 'uploadquota') {
                     if ($type eq 'Community') {
-                         $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] Mb.',$defaultquota));
+                        $r->print(&mt('The disk space allocated for files uploaded to this community via the Content Editor is the default quota for this domain: [_1] MB.',
+                                      $default{$key}).'<br />');
                     } else {
-                         $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] Mb.',$defaultquota));
+                        $r->print(&mt('The disk space allocated for files uploaded to this course via the Content Editor is the default quota for this domain: [_1] MB.',
+                                      $default{$key}).'<br />');
                     }
-                } else {
-                    if ($putreply eq 'ok') {
-                        my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
-                        $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] Mb.','<b>'.$updatedsettings{'internal.coursequota'}.'</b>'));
-                        my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
-                        if ($usage >= $updatedsettings{'internal.coursequota'}) {
-                            my $newoverquota;
-                            if ($usage < $oldsettings{'internal.coursequota'}) {
-                                $newoverquota = 'now';
-                            }
-                            $r->print('<p>');
-                            if ($type eq 'Community') {
-                                $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
-                                          &mt('Upload of new portfolio files and assignment of a non-zero Mb quota to new groups in the community will not be possible until some files have been deleted, and total usage is below community quota.'));
-                            } else {
-                                $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
-                                          &mt('Upload of new portfolio files and assignment of a non-zero Mb quota to new groups in the course will not be possible until some files have been deleted, and total usage is below course quota.'));
-                            }
-                            $r->print('</p>');
-                        }
+                } else { 
+                    if ($type eq 'Community') {
+                        $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.',
+                                      $default{$key}).'<br />');
                     } else {
-                        $r->print(&mt('An error occurred storing the quota for group portfolio files: ').
-                                  $putreply);
+                        $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] MB.',
+                                      $default{$key}).'<br />');
                     }
                 }
+                delete($showresult{$key});
+            }
+        }
+        if ($putreply eq 'ok') {
+            my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
+            if ($showresult{'coursequota'}) {
+                $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] MB.',
+                              '<b>'.$updatedsettings{'internal.coursequota'}.'</b>').'<br />');
+                my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
+                if ($usage >= $updatedsettings{'internal.coursequota'}) {
+                    my $newoverquota;
+                    if ($usage < $oldsettings{'internal.coursequota'}) {
+                        $newoverquota = 'now';
+                    }
+                    $r->print('<p>');
+                    if ($type eq 'Community') {
+                        $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
+                                  &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the community will not be possible until some files have been deleted, and total usage is below community quota.'));
+                    } else {
+                        $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
+                                  &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the course will not be possible until some files have been deleted, and total usage is below course quota.'));
+                    }
+                    $r->print('</p>');
+                }
+            }
+            if ($showresult{'uploadquota'}) {
+                $r->print(&mt('The disk space allocated for content uploaded directly via the Content Editor is now: [_1] MB.',
+                              '<b>'.$updatedsettings{'internal.uploadquota'}.'</b>').'<br />');
             }
         } else {
-            $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
+            $r->print(&mt('An error occurred storing the quota(s) for group portfolio files and/or uploaded content.').
+                      $putreply);
         }
     }
     $r->print('<p>'.
@@ -1552,7 +1628,7 @@
       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
           'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
-          'threshold','defaultcredits'])."\n".
+          'threshold','defaultcredits','uploadquota'])."\n".
           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
     return $hidden_elements;
 }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1229 loncom/lonnet/perl/lonnet.pm:1.1230
--- loncom/lonnet/perl/lonnet.pm:1.1229	Tue Jul  2 19:04:56 2013
+++ loncom/lonnet/perl/lonnet.pm	Tue Jul  9 00:17:27 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1229 2013/07/02 19:04:56 raeburn Exp $
+# $Id: lonnet.pm,v 1.1230 2013/07/09 00:17:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2010,13 +2010,16 @@
         }
     }
     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
-        foreach my $item ('canuse_pdfforms','uploadquota') {
-            $domdefaults{$item} = $domconfig{'coursedefaults'}{$item};
-        }
+        $domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'};
         if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
             $domdefaults{'officialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'official'};
             $domdefaults{'unofficialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'};
         }
+        if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+            $domdefaults{'officialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'official'};
+            $domdefaults{'unofficialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'unofficial'};
+            $domdefaults{'communityquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'community'};           
+        }
     }
     if (ref($domconfig{'usersessions'}) eq 'HASH') {
         if (ref($domconfig{'usersessions'}{'remote'}) eq 'HASH') {


More information about the LON-CAPA-cvs mailing list