Diff for /loncom/interface/loncommon.pm between versions 1.535 and 1.536

version 1.535, 2007/05/15 20:05:13 version 1.536, 2007/05/29 17:48:44
Line 5227  Incoming parameters: Line 5227  Incoming parameters:
 2. user's domain  2. user's domain
   
 Returns:  Returns:
 1. Disk quota (in Mb) assigned to student.   1. Disk quota (in Mb) assigned to student.
   2. (Optional) Type of setting: custom or default
      (individually assigned or default for user's 
      institutional status).
   3. (Optional) - User's institutional status (e.g., faculty, staff
      or student - types as defined in localenroll::inst_usertypes 
      for user's domain, which determines default quota for user.
   4. (Optional) - Default quota which would apply to the user.
   
 If a value has been stored in the user's environment,   If a value has been stored in the user's environment, 
 it will return that, otherwise it returns the default  it will return that, otherwise it returns the maximal default
 for users in the domain.  defined for the user's instituional status(es) in the domain.
   
 =cut  =cut
   
Line 5240  for users in the domain. Line 5247  for users in the domain.
   
 sub get_user_quota {  sub get_user_quota {
     my ($uname,$udom) = @_;      my ($uname,$udom) = @_;
     my $quota;      my ($quota,$quotatype,$settingstatus,$defquota);
     if (!defined($udom)) {      if (!defined($udom)) {
         $udom = $env{'user.domain'};          $udom = $env{'user.domain'};
     }      }
Line 5250  sub get_user_quota { Line 5257  sub get_user_quota {
     if (($udom eq '' || $uname eq '') ||      if (($udom eq '' || $uname eq '') ||
         ($udom eq 'public') && ($uname eq 'public')) {          ($udom eq 'public') && ($uname eq 'public')) {
         $quota = 0;          $quota = 0;
           $quotatype = 'default';
           $defquota = 0; 
     } else {      } else {
           my $inststatus;
         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {          if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
             $quota = $env{'environment.portfolioquota'};              $quota = $env{'environment.portfolioquota'};
               $inststatus = $env{'environment.inststatus'};
         } else {          } else {
             my %userenv = &Apache::lonnet::dump('environment',$udom,$uname);              my %userenv = 
                   &Apache::lonnet::get('environment',['portfolioquota',
                                        'inststatus'],$udom,$uname);
             my ($tmp) = keys(%userenv);              my ($tmp) = keys(%userenv);
             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {              if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                 $quota = $userenv{'portfolioquota'};                  $quota = $userenv{'portfolioquota'};
                   $inststatus = $userenv{'inststatus'};
             } else {              } else {
                 undef(%userenv);                  undef(%userenv);
             }              }
         }          }
           ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
         if ($quota eq '') {          if ($quota eq '') {
             $quota = &default_quota($udom);              $quota = $defquota;
               $quotatype = 'default';
           } else {
               $quotatype = 'custom';
         }          }
     }      }
     return $quota;      if (wantarray) {
           return ($quota,$quotatype,$settingstatus,$defquota);
       } else {
           return $quota;
       }
 }  }
   
 ###############################################  ###############################################
Line 5275  sub get_user_quota { Line 5297  sub get_user_quota {
   
 =item * &default_quota()  =item * &default_quota()
   
 Retrieves default quota assigned for storage of user portfolio files  Retrieves default quota assigned for storage of user portfolio files,
   given an (optional) user's institutional status.
   
 Incoming parameters:  Incoming parameters:
 1. domain  1. domain
   2. (Optional) institutional status(es).  This is a : separated list of 
      status types (e.g., faculty, staff, student etc.)
      which apply to the user for whom the default is being retrieved.
      If the institutional status string in undefined, the domain
      default quota will be returned. 
   
 Returns:  Returns:
 1. Default disk quota (in Mb) for user portfolios in the domain.  1. Default disk quota (in Mb) for user portfolios in the domain.
   2. (Optional) institutional type which determined the value of the
      default quota.
   
 If a value has been stored in the domain's configuration db,  If a value has been stored in the domain's configuration db,
 it will return that, otherwise it returns 20 (for backwards   it will return that, otherwise it returns 20 (for backwards 
 compatibility with domains which have not set up a configuration  compatibility with domains which have not set up a configuration
 db file; the original statically defined portfolio quota was 20 Mb).   db file; the original statically defined portfolio quota was 20 Mb). 
   
   If the user's status includes multiple types (e.g., staff and student),
   the largest default quota which applies to the user determines the
   default quota returned.
   
 =cut  =cut
   
 ###############################################  ###############################################
   
   
 sub default_quota {  sub default_quota {
     my ($udom) = @_;      my ($udom,$inststatus) = @_;
     my %defaults = &Apache::lonnet::get_dom('configuration',      my ($defquota,$settingstatus);
                                             ['portfolioquota'],$udom);      my %quotahash = &Apache::lonnet::get_dom('configuration',
     if ($defaults{'portfolioquota'} ne '') {                                              ['quota'],$udom);
         return $defaults{'portfolioquota'};      if (ref($quotahash{'quota'}) eq 'HASH') {
           if ($inststatus ne '') {
               my @statuses = split(/:/,$inststatus);
               foreach my $item (@statuses) {
                   if ($quotahash{'quota'}{$item} ne '') {
                       if ($defquota eq '') {
                           $defquota = $quotahash{'quota'}{$item};
                           $settingstatus = $item;
                       } elsif ($quotahash{'quota'}{$item} > $defquota) {
                           $defquota = $quotahash{'quota'}{$item};
                           $settingstatus = $item;
                       }
                   }
               }
           }
           if ($defquota eq '') {
               $defquota = $quotahash{'quota'}{'default'};
               $settingstatus = 'default';
           }
       } else {
           $settingstatus = 'default';
           $defquota = 20;
       }
       if (wantarray) {
           return ($defquota,$settingstatus);
     } else {      } else {
         return '20';          return $defquota;
     }      }
 }  }
   

Removed from v.1.535  
changed lines
  Added in v.1.536


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>