--- loncom/interface/loncreateuser.pm 2006/12/01 21:52:29 1.141
+++ loncom/interface/loncreateuser.pm 2007/05/29 17:48:44 1.149
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.141 2006/12/01 21:52:29 albertel Exp $
+# $Id: loncreateuser.pm,v 1.149 2007/05/29 17:48:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -122,11 +122,72 @@ sub portfolio_quota {
my ($ccuname,$ccdomain) = @_;
my %lt = &Apache::lonlocal::texthash(
'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
);
- my $output = '
'.$lt{'disk'}.' '.
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
+ }
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ if ($quotatype eq 'custom') {
+ $custom_on = $custom_off;
+ $custom_off = ' ';
+ $showquota = $currquota;
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota would be [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota would be [_1]
+ Mb, as determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ } else {
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota is [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota of [_1]
+ Mb, is determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ }
+ my $output = $quota_javascript.
+ ''.$lt{'disk'}.' '.
+ $lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.''.$lt{'chqu'}.
+ ': '.
+ ' '.$lt{'defa'}.' ('.$defquota.' Mb). '.
+ ' '.
+ $lt{'cust'}.': '.
' Mb';
+ $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
+ '/> Mb';
return $output;
}
@@ -135,7 +196,6 @@ sub portfolio_quota {
sub print_username_entry_form {
my ($r) = @_;
my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
my $selscript=&Apache::loncommon::studentbrowser_javascript();
my $start_page =
@@ -235,7 +295,7 @@ sub print_user_modification_page {
);
$loginscript = &Apache::loncommon::authform_header(%param);
$authformkrb = &Apache::loncommon::authform_kerberos(%param);
-
+
$ccuname =&LONCAPA::clean_username($ccuname);
$ccdomain=&LONCAPA::clean_domain($ccdomain);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
@@ -358,36 +418,6 @@ sub print_user_modification_page {
}
return -1;
}
-
- function setType() {
- var crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
- rolevals = new Array("$rolevalslist");
- if (crstype == 'Group') {
- if (document.cu.currsec.options[0].text == "$pickcrsfirst") {
- document.cu.currsec.options[0].text = "$pickgrpfirst";
- }
- grprolenames = new Array("$grprolenameslist");
- for (var i=0; i
ENDFORMINFO
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
- my %incdomains;
my %inccourses;
- foreach my $item (values(%Apache::lonnet::hostdom)) {
- $incdomains{$item}=1;
- }
foreach my $key (keys(%env)) {
if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
$inccourses{$1.'_'.$2}=1;
@@ -962,7 +988,7 @@ ENDNOPRIV
&mt('Extent').''.
''.&mt('Start').' '.&mt('End').' '.
&Apache::loncommon::end_data_table_header_row();
- foreach my $thisdomain ( sort( keys(%incdomains))) {
+ foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
foreach my $role ('dc','li','dg','au','sc') {
if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
my $plrole=&Apache::lonnet::plaintext($role);
@@ -1099,8 +1125,8 @@ ENDNEWUSERHEAD
if (lc($desiredhost) eq 'default') {
$desiredhost = undef;
} else {
- my %home_servers = &Apache::loncommon::get_library_servers
- ($env{'form.ccdomain'});
+ my %home_servers =
+ &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
if (! exists($home_servers{$desiredhost})) {
$r->print($error.&mt('Invalid home server specified'));
return;
@@ -1117,7 +1143,7 @@ ENDNEWUSERHEAD
my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
$r->print(' '.&mt('Home server').': '.$home.' '.
- $Apache::lonnet::libserv{$home});
+ &Apache::lonnet::hostname($home));
} elsif (($env{'form.login'} ne 'nochange') &&
($env{'form.login'} ne '' )) {
# Modify user privileges
@@ -1150,7 +1176,8 @@ ENDMODIFYUSERHEAD
# Check for need to change
my %userenv = &Apache::lonnet::get
('environment',['firstname','middlename','lastname','generation',
- 'portfolioquota'],$env{'form.ccdomain'},$env{'form.ccuname'});
+ 'portfolioquota','inststatus'],$env{'form.ccdomain'},
+ $env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
%userenv = ();
@@ -1160,22 +1187,55 @@ ENDMODIFYUSERHEAD
# Strip leading and trailing whitespace
$env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
}
- my ($quotachanged,$namechanged,$oldportfolioquota);
+ my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
+ $inststatus,$isdefault,$defquotatext);
+ my ($defquota,$settingstatus) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
my %changeHash;
- if (exists($userenv{'portfolioquota'})) {
+ if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
- if (exists($env{'form.portfolioquota'})) {
- if ($env{'form.portfolioquota'} ne $userenv{'portfolioquota'}) {
- if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
- # Current user has quota modification privileges
- $quotachanged = 1;
- $changeHash{'portfolioquota'} = $env{'form.portfolioquota'};
- }
+ if ($env{'form.customquota'} == 1) {
+ if ($env{'form.portfolioquota'} eq '') {
+ $newportfolioquota = 0;
+ } else {
+ $newportfolioquota = $env{'form.portfolioquota'};
+ $newportfolioquota =~ s/[^\d\.]//g;
}
+ if ($newportfolioquota != $userenv{'portfolioquota'}) {
+ $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ }
+ } else {
+ $quotachanged = "a_admin('',\%changeHash);
+ $newportfolioquota = $defquota;
+ $isdefault = 1;
}
} else {
- $oldportfolioquota =
- &Apache::loncommon::default_quota($env{'form.ccdomain'});
+ $oldportfolioquota = $defquota;
+ if ($env{'form.customquota'} == 1) {
+ if ($env{'form.portfolioquota'} eq '') {
+ $newportfolioquota = 0;
+ } else {
+ $newportfolioquota = $env{'form.portfolioquota'};
+ $newportfolioquota =~ s/[^\d\.]//g;
+ }
+ $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ } else {
+ $newportfolioquota = $defquota;
+ $isdefault = 1;
+ }
+ }
+ if ($isdefault) {
+ if ($settingstatus eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ my ($usertypes,$order) =
+ &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+ if ($usertypes->{$settingstatus} eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+ }
+ }
}
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
($env{'form.cfirstname'} ne $userenv{'firstname'} ||
@@ -1219,16 +1279,24 @@ ENDMODIFYUSERHEAD
$userenv{'middlename'}
$userenv{'lastname'}
$userenv{'generation'}
- $oldportfolioquota
+ $oldportfolioquota Mb
$lt{'chto'}
$env{'form.cfirstname'}
$env{'form.cmiddlename'}
$env{'form.clastname'}
$env{'form.cgeneration'}
- $env{'form.portfolioquota'} Mb
+ $newportfolioquota Mb $defquotatext
END
+ if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
+ ($env{'form.ccuname'} eq $env{'user.name'})) {
+ my %newenvhash;
+ foreach my $key (keys(%changeHash)) {
+ $newenvhash{'environment.'.$key} = $changeHash{$key};
+ }
+ &Apache::lonnet::appenv(%newenvhash);
+ }
} else { # error occurred
$r->print("".&mt('Unable to successfully change environment for')." ".
$env{'form.ccuname'}." ".&mt('in domain')." ".
@@ -1255,8 +1323,10 @@ END
$lt{'gen'}: $userenv{'generation'}
END
if ($putresult eq 'ok') {
- if ($oldportfolioquota ne $env{'form.portfolioquota'}) {
- $r->print(''.$lt{'disk'}.': '.$env{'form.portfolioquota'}.' Mb ');
+ if ($oldportfolioquota != $newportfolioquota) {
+ $r->print(''.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
+ $defquotatext.' ');
+ &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
}
}
}
@@ -1394,7 +1464,7 @@ END
$r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
}
}
- } elsif ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_([^\_]+)$/) {
+ } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
my ($one,$two,$three)=($1,$2,$3);
@@ -1481,6 +1551,17 @@ END
$r->print(&Apache::loncommon::end_page());
}
+sub quota_admin {
+ my ($setquota,$changeHash) = @_;
+ my $quotachanged;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ # Current user has quota modification privileges
+ $quotachanged = 1;
+ $changeHash->{'portfolioquota'} = $setquota;
+ }
+ return $quotachanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1868,7 +1949,7 @@ sub course_sections {
$output = ''."\n";
+ $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
foreach my $sec (@sections) {
$output .= ''.$sec." \n";
}
@@ -1887,7 +1968,6 @@ sub course_level_dc {
('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'';
my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
my %lt=&Apache::lonlocal::texthash(
- 'typ' => "Type",
'rol' => "Role",
'grs' => "Section",
'exs' => "Existing sections",
@@ -1900,14 +1980,9 @@ sub course_level_dc {
my $header = ''.&mt('Course Level').' '.
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
- ''.$lt{'typ'}.' '.$courseform.' '.$lt{'rol'}.' '.$lt{'grs'}.' '.$lt{'sta'}.' '.$lt{'end'}.' '.
+ ''.$courseform.' '.$lt{'rol'}.' '.$lt{'grs'}.' '.$lt{'sta'}.' '.$lt{'end'}.' '.
&Apache::loncommon::end_data_table_header_row();
- my $otheritems = &Apache::loncommon::start_data_table_row().
- ''."\n".
- ' '.&mt('Please select')."\n".
- ' '.&mt('Course')."\n".
- ' '.&mt('Non-standard course')."\n".
- ' '."\n".
+ my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
' '."\n".
''."\n";
foreach my $role ('st','ta','ep','in','cc') {