--- loncom/interface/loncommon.pm 2007/05/15 20:05:13 1.535 +++ loncom/interface/loncommon.pm 2007/05/29 17:48:44 1.536 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.535 2007/05/15 20:05:13 albertel Exp $ +# $Id: loncommon.pm,v 1.536 2007/05/29 17:48:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -5227,11 +5227,18 @@ Incoming parameters: 2. user's domain 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, -it will return that, otherwise it returns the default -for users in the domain. +it will return that, otherwise it returns the maximal default +defined for the user's instituional status(es) in the domain. =cut @@ -5240,7 +5247,7 @@ for users in the domain. sub get_user_quota { my ($uname,$udom) = @_; - my $quota; + my ($quota,$quotatype,$settingstatus,$defquota); if (!defined($udom)) { $udom = $env{'user.domain'}; } @@ -5250,23 +5257,38 @@ sub get_user_quota { if (($udom eq '' || $uname eq '') || ($udom eq 'public') && ($uname eq 'public')) { $quota = 0; + $quotatype = 'default'; + $defquota = 0; } else { + my $inststatus; if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { $quota = $env{'environment.portfolioquota'}; + $inststatus = $env{'environment.inststatus'}; } else { - my %userenv = &Apache::lonnet::dump('environment',$udom,$uname); + my %userenv = + &Apache::lonnet::get('environment',['portfolioquota', + 'inststatus'],$udom,$uname); my ($tmp) = keys(%userenv); if ($tmp !~ /^(con_lost|error|no_such_host)/i) { $quota = $userenv{'portfolioquota'}; + $inststatus = $userenv{'inststatus'}; } else { undef(%userenv); } } + ($defquota,$settingstatus) = &default_quota($udom,$inststatus); 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; + } } ############################################### @@ -5275,32 +5297,68 @@ sub get_user_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: 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: 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, it will return that, otherwise it returns 20 (for backwards compatibility with domains which have not set up a configuration 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 ############################################### sub default_quota { - my ($udom) = @_; - my %defaults = &Apache::lonnet::get_dom('configuration', - ['portfolioquota'],$udom); - if ($defaults{'portfolioquota'} ne '') { - return $defaults{'portfolioquota'}; + my ($udom,$inststatus) = @_; + my ($defquota,$settingstatus); + my %quotahash = &Apache::lonnet::get_dom('configuration', + ['quota'],$udom); + 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 { - return '20'; + return $defquota; } }