--- loncom/interface/loncreateuser.pm 2007/12/05 21:23:14 1.202
+++ loncom/interface/loncreateuser.pm 2007/12/08 19:19:03 1.205
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.202 2007/12/05 21:23:14 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.205 2007/12/08 19:19:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -76,7 +76,7 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
- my ($dom,$curr_authtype) = @_;
+ my ($dom,$curr_authtype,$mode) = @_;
my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
$krbdefdom= uc($krbdefdom);
my %param = ( formname => 'document.cu',
@@ -91,6 +91,9 @@ sub initialize_authen_forms {
if ($long_auth =~ /^krb(4|5)$/) {
$param{'curr_kerb_ver'} = $1;
}
+ if ($mode eq 'modifyuser') {
+ $param{'mode'} = $mode;
+ }
}
# no longer static due to configurable kerberos defaults
# $loginscript = &Apache::loncommon::authform_header(%param);
@@ -787,7 +790,7 @@ ENDCHANGEUSER
&personal_data_display($ccuname,$ccdomain,$newuser,
%inst_results));
if ($context eq 'domain') {
- $r->print(&Apache::lonuserutils::forceid_change());
+ $r->print(&Apache::lonuserutils::forceid_change($context));
}
$r->print('');
my $user_auth_text =
@@ -1197,12 +1200,8 @@ $lt{'uuas'} ($currentauth). $lt{'adcs'}.
ENDBADAUTH
}
} else { # Authentication type is valid
- &initialize_authen_forms($ccdomain,$currentauth);
- my $authformnop_row;
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- $authformnop_row = &Apache::loncommon::start_data_table_row();
- }
- my ($authformcurrent,$authform_other,$can_modify) =
+ &initialize_authen_forms($ccdomain,$currentauth,'modifyuser');
+ my ($authformcurrent,$can_modify,@authform_others) =
&modify_login_block($ccdomain,$currentauth);
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
# Current user has login modification privileges
@@ -1217,7 +1216,7 @@ ENDBADAUTH
''."\n".
'
'.$lt{'ld'}.'
'.
&Apache::loncommon::start_data_table().
- $authformnop_row.
+ &Apache::loncommon::start_data_table_row().
''.$authformnop;
if ($can_modify) {
$outcome .= ' | '."\n".
@@ -1229,11 +1228,12 @@ ENDBADAUTH
$outcome .= ' ('.$authformcurrent.')'.
&Apache::loncommon::end_data_table_row()."\n";
}
- if ($authform_other ne '') {
- $outcome .= $authform_other;
+ foreach my $item (@authform_others) {
+ $outcome .= &Apache::loncommon::start_data_table_row().
+ ''.$item.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
}
- $outcome .= &Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table();
+ $outcome .= &Apache::loncommon::end_data_table();
} else {
if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
my %lt=&Apache::lonlocal::texthash(
@@ -1256,18 +1256,14 @@ sub modify_login_block {
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
my ($authnum,%can_assign) =
&Apache::loncommon::get_assignable_auth($dom);
- my ($authformcurrent,$authform_other,$show_override_msg);
+ my ($authformcurrent,@authform_others,$show_override_msg);
if ($currentauth=~/^krb(4|5):/) {
$authformcurrent=$authformkrb;
if ($can_assign{'int'}) {
- $authform_other = &Apache::loncommon::start_data_table_row().
- ''.$authformint.' | '.
- &Apache::loncommon::end_data_table_row()."\n"
+ push(@authform_others,$authformint);
}
if ($can_assign{'loc'}) {
- $authform_other .= &Apache::loncommon::start_data_table_row().
- ''.$authformloc.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformloc);
}
if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
$show_override_msg = 1;
@@ -1275,14 +1271,10 @@ sub modify_login_block {
} elsif ($currentauth=~/^internal:/) {
$authformcurrent=$authformint;
if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
- $authform_other = &Apache::loncommon::start_data_table_row().
- ''.$authformkrb.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformkrb);
}
if ($can_assign{'loc'}) {
- $authform_other .= &Apache::loncommon::start_data_table_row().
- ''.$authformloc.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformloc);
}
if ($can_assign{'int'}) {
$show_override_msg = 1;
@@ -1290,19 +1282,13 @@ sub modify_login_block {
} elsif ($currentauth=~/^unix:/) {
$authformcurrent=$authformfsys;
if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
- $authform_other = &Apache::loncommon::start_data_table_row().
- ''.$authformkrb.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformkrb);
}
if ($can_assign{'int'}) {
- $authform_other .= &Apache::loncommon::start_data_table_row().
- ''.$authformint.' | '.
- &Apache::loncommon::end_data_table_row()."\n"
+ push(@authform_others,$authformint);
}
if ($can_assign{'loc'}) {
- $authform_other .= &Apache::loncommon::start_data_table_row().
- ''.$authformloc.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformloc);
}
if ($can_assign{'fsys'}) {
$show_override_msg = 1;
@@ -1310,25 +1296,25 @@ sub modify_login_block {
} elsif ($currentauth=~/^localauth:/) {
$authformcurrent=$authformloc;
if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
- $authform_other = &Apache::loncommon::start_data_table_row().
- ''.$authformkrb.' | '.
- &Apache::loncommon::end_data_table_row()."\n";
+ push(@authform_others,$authformkrb);
}
if ($can_assign{'int'}) {
- $authform_other .= &Apache::loncommon::start_data_table_row().
- ''.$authformint.' | '.
- &Apache::loncommon::end_data_table_row()."\n"
+ push(@authform_others,$authformint);
}
if ($can_assign{'loc'}) {
$show_override_msg = 1;
}
}
if ($show_override_msg) {
- $authformcurrent.= ' '.
+ $authformcurrent = ''.$authformcurrent.
+ ' |
'."\n".
+ ' | '.
+ ''.&mt('Currently in use').' | '.
+ ''.
&mt('will override current values').
- ' ';
+ ' |
';
}
- return ($authformcurrent,$authform_other,$show_override_msg);
+ return ($authformcurrent,$show_override_msg,@authform_others);
}
sub personal_data_display {
@@ -1591,17 +1577,23 @@ sub update_user_data {
# Check to see if we need to change user information
foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
# Strip leading and trailing whitespace
- $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
}
# Check to see if we can change the ID/student number
my $forceid = $env{'form.forceid'};
my $recurseid = $env{'form.recurseid'};
my $newuser = 0;
- my $disallowed_id = 0;
my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
- if (!$forceid) {
- $env{'form.cid'} = $userenv{'id'};
- } elsif ($env{'form.cid'} ne $userenv{'id'}) {
+ my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+ $env{'form.ccuname'});
+ if (($uidhash{$env{'form.ccuname'}}) &&
+ ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
+ (!$forceid)) {
+ if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+ $env{'form.cid'} = $userenv{'id'};
+ }
+ }
+ if ($env{'form.cid'} ne $userenv{'id'}) {
my $checkhash;
my $checks = { 'id' => 1 };
$checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
@@ -1612,15 +1604,17 @@ sub update_user_data {
\%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
- $disallowed_id = 1;
+ $env{'form.cid'} = $userenv{'id'};
}
}
}
my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
- $inststatus,$isdefault,$defquotatext);
+ $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+ $newdefquotatext);
my ($defquota,$settingstatus) =
&Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
my %changeHash;
+ $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
if ($env{'form.customquota'} == 1) {
@@ -1630,15 +1624,16 @@ sub update_user_data {
$newportfolioquota = $env{'form.portfolioquota'};
$newportfolioquota =~ s/[^\d\.]//g;
}
- if ($newportfolioquota != $userenv{'portfolioquota'}) {
+ if ($newportfolioquota != $oldportfolioquota) {
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
}
} else {
$quotachanged = "a_admin('',\%changeHash);
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 1;
}
} else {
+ $oldisdefault = 1;
$oldportfolioquota = $defquota;
if ($env{'form.customquota'} == 1) {
if ($env{'form.portfolioquota'} eq '') {
@@ -1650,21 +1645,14 @@ sub update_user_data {
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
} else {
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 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 ($oldisdefault) {
+ $olddefquotatext = &get_defaultquota_text($settingstatus);
+ }
+ if ($newisdefault) {
+ $newdefquotatext = &get_defaultquota_text($settingstatus);
}
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
($env{'form.cfirstname'} ne $userenv{'firstname'} ||
@@ -1675,18 +1663,30 @@ sub update_user_data {
$env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
$namechanged = 1;
}
- if ($namechanged) {
- # Make the change
+ if ($namechanged || $quotachanged) {
$changeHash{'firstname'} = $env{'form.cfirstname'};
$changeHash{'middlename'} = $env{'form.cmiddlename'};
$changeHash{'lastname'} = $env{'form.clastname'};
$changeHash{'generation'} = $env{'form.cgeneration'};
$changeHash{'id'} = $env{'form.cid'};
$changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
- my $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- if ($putresult eq 'ok') {
+ my ($quotachgresult,$namechgresult);
+ if ($quotachanged) {
+ $quotachgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ if ($namechanged) {
+ # Make the change
+ $namechgresult =
+ &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+ $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+ $changeHash{'firstname'},$changeHash{'middlename'},
+ $changeHash{'lastname'},$changeHash{'generation'},
+ $changeHash{'id'},undef,$changeHash{'permanentemail'});
+ }
+ if (($namechanged && $namechgresult eq 'ok') ||
+ ($quotachanged && $quotachgresult eq 'ok')) {
# Tell the user we changed the name
my %lt=&Apache::lonlocal::texthash(
'uic' => "User Information Changed",
@@ -1723,7 +1723,7 @@ END
$userenv{'generation'} |
$userenv{'id'} |
$userenv{'permanentemail'} |
- $oldportfolioquota Mb |
+ $oldportfolioquota Mb $olddefquotatext |
END
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::start_data_table_row());
@@ -1735,22 +1735,28 @@ END
$env{'form.cgeneration'} |
$env{'form.cid'} |
$env{'form.cpermanentemail'} |
- $newportfolioquota Mb $defquotatext |
+ $newportfolioquota Mb $newdefquotatext |
END
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table());
- if (($forceid) && ($recurseid) && (!$disallowed_id) &&
- (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
- my %userupdate = (
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ &Apache::lonnet::idput($env{'form.ccdomain'},
+ ($env{'form.ccuname'} => $env{'form.cid'}));
+ if (($recurseid) &&
+ (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+ my %userupdate = (
lastname => $env{'form.clasaname'},
middlename => $env{'form.cmiddlename'},
firstname => $env{'form.cfirstname'},
generation => $env{'fora.cgeneration'},
id => $env{'form.cid'},
);
- my $idresult = &propagate_id_change($env{'form.ccname'},
- $env{'form.ccdomain'},\%userupdate);
- $r->print('
'.$idresult.'
');
+ my $idresult =
+ &Apache::lonuserutils::propagate_id_change(
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ \%userupdate);
+ $r->print('
'.$idresult.'
');
+ }
}
if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
($env{'form.ccuname'} eq $env{'user.name'})) {
@@ -1766,14 +1772,8 @@ END
$env{'form.ccdomain'}.'');
}
} else { # End of if ($env ... ) logic
- my $putresult;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- }
- # They did not want to change the users name but we can
- # still tell them what the name is
+ # They did not want to change the users name or quota but we can
+ # still tell them what the name and quota are
my %lt=&Apache::lonlocal::texthash(
'id' => "ID/Student number",
'mail' => "Permanent e-mail",
@@ -1782,19 +1782,12 @@ END
$r->print(<<"END");
$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
END
- if ($userenv{'permanentemail'} eq '') {
- $r->print('
');
- } else {
- $r->print(' ('.$lt{'mail'}.': '.
- $userenv{'permanentemail'}.')');
- }
- if ($putresult eq 'ok') {
- if ($oldportfolioquota != $newportfolioquota) {
- $r->print(''.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
- $defquotatext.'
');
- &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
- }
+ if ($userenv{'permanentemail'} ne '') {
+ $r->print('
['.$lt{'mail'}.': '.
+ $userenv{'permanentemail'}.']');
}
+ $r->print('
['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
+ $olddefquotatext.']');
}
}
##
@@ -2023,6 +2016,23 @@ END
$r->print(&Apache::loncommon::end_page());
}
+sub get_defaultquota_text {
+ my ($settingstatus) = @_;
+ my $defquotatext;
+ 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});
+ }
+ }
+ return $defquotatext;
+}
+
sub update_result_form {
my ($uhome) = @_;
my $outcome =