--- loncom/interface/loncreateuser.pm 2007/12/06 04:03:35 1.203 +++ 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.203 2007/12/06 04:03:35 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); @@ -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 = ''."\n". + ''. + ''. + '
'.$authformcurrent. + '
   '.&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 { @@ -1623,10 +1609,12 @@ sub update_user_data { } } 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) { @@ -1636,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 '') { @@ -1656,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'} || @@ -1681,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", @@ -1729,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()); @@ -1741,7 +1735,7 @@ 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()); @@ -1778,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", @@ -1794,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.']'); } } ## @@ -2035,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 =