--- loncom/interface/loncreateuser.pm 2007/11/15 19:06:28 1.195 +++ loncom/interface/loncreateuser.pm 2007/11/15 21:24:51 1.196 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.195 2007/11/15 19:06:28 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.196 2007/11/15 21:24:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -440,7 +440,7 @@ sub print_user_query_page { } sub print_user_modification_page { - my ($r,$ccuname,$ccdomain,$srch,$response) = @_; + my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_; if (($ccuname eq '') || ($ccdomain eq '')) { my $usermsg = &mt('No username and/or domain provided.'); &print_username_entry_form($r,$usermsg); @@ -448,30 +448,32 @@ sub print_user_modification_page { } my %abv_auth = &auth_abbrev(); my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser, - %alerts,%curr_rules); + %alerts,%curr_rules,%got_rules); my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); if ($uhome eq 'no_host') { $newuser = 1; my $checkhash; my $checks = { 'username' => 1 }; - $checkhash->{$ccuname.':'.$ccdomain} = { 'status' => 'new' }; + $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser }; &Apache::loncommon::user_rule_check($checkhash,$checks, - \%alerts,\%rulematch,\%inst_results,\%curr_rules); - if (ref($alerts{$ccuname.':'.$ccdomain}) eq 'HASH') { - if ($alerts{$ccuname.':'.$ccdomain}{'username'}) { - my $domdesc = + \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules); + if (ref($alerts{'username'}) eq 'HASH') { + if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') { + my $domdesc = &Apache::lonnet::domain($ccdomain,'description'); - my $userchkmsg; - if (ref($curr_rules{$ccdomain}) eq 'HASH') { - $userchkmsg = - &Apache::loncommon::instrule_disallow_msg('username', + if ($alerts{'username'}{$ccdomain}{$ccuname}) { + my $userchkmsg; + if (ref($curr_rules{$ccdomain}) eq 'HASH') { + $userchkmsg = + &Apache::loncommon::instrule_disallow_msg('username', $domdesc,1). &Apache::loncommon::user_rule_formats($ccdomain, $domdesc,$curr_rules{$ccdomain}{'username'}, 'username'); - } - &print_username_entry_form($r,$userchkmsg); - return; + } + &print_username_entry_form($r,$userchkmsg); + return; + } } } } else { @@ -790,6 +792,9 @@ $lt{'hs'}: $home_server_pick } else { $r->print($home_server_pick); } + if ($context eq 'domain') { + $r->print(&Apache::lonuserutils::forceid_change()); + } $r->print(''."\n".'

'. $lt{'lg'}.'

'); my ($fixedauth,$varauth,$authmsg); @@ -1585,26 +1590,30 @@ sub update_user_data { my %checkhash; my %checks = ('id' => 1); %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = ( - 'status' => 'new', - 'id' => $env{'form.cid'} + 'newuser' => 1, + 'id' => $env{'form.cid'}, ); - &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts, - \%rulematch,\%inst_results,\%curr_rules); - if (ref($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}) eq 'HASH') { - if ($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}{'id'}) { - my $domdesc = - &Apache::lonnet::domain($env{'form.ccdomain'},'description'); - my $userchkmsg; - if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') { - $userchkmsg = - &Apache::loncommon::instrule_disallow_msg('id', - $domdesc,1). - &Apache::loncommon::user_rule_formats($env{'form.ccdomain'}, - $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id'); - } - $r->print($error.&mt('Invalid ID format').$end. - $userchkmsg.$rtnlink); - return; + if ($env{'form.cid'} ne '') { + &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts, + \%rulematch,\%inst_results,\%curr_rules); + if (ref($alerts{'id'}) eq 'HASH') { + if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') { + my $domdesc = + &Apache::lonnet::domain($env{'form.ccdomain'},'description'); + if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) { + my $userchkmsg; + if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') { + $userchkmsg = + &Apache::loncommon::instrule_disallow_msg('id', + $domdesc,1). + &Apache::loncommon::user_rule_formats($env{'form.ccdomain'}, + $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id'); + } + $r->print($error.&mt('Invalid ID format').$end. + $userchkmsg.$rtnlink); + return; + } + } } } # Call modifyuser @@ -1644,17 +1653,40 @@ sub update_user_data { # Check for need to change my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', - 'permanentemail','portfolioquota','inststatus'], + 'id','permanentemail','portfolioquota','inststatus'], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { %userenv = (); } # Check to see if we need to change user information - foreach my $item ('firstname','middlename','lastname','generation','permanentemail') { + foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') { # Strip leading and trailing whitespace $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 $checkhash; + my $checks = { 'id' => 1 }; + $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} = + { 'newuser' => $newuser, + 'id' => $env{'form.cid'}, + }; + &Apache::loncommon::user_rule_check($checkhash,$checks, + \%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; + } + } + } my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota, $inststatus,$isdefault,$defquotatext); my ($defquota,$settingstatus) = @@ -1710,6 +1742,7 @@ sub update_user_data { $env{'form.cmiddlename'} ne $userenv{'middlename'} || $env{'form.clastname'} ne $userenv{'lastname'} || $env{'form.cgeneration'} ne $userenv{'generation'} || + $env{'form.cid'} ne $userenv{'id'} || $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) { $namechanged = 1; } @@ -1719,6 +1752,7 @@ sub update_user_data { $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, @@ -1731,6 +1765,7 @@ sub update_user_data { 'mddl' => "middle", 'lst' => "last", 'gen' => "generation", + 'id' => "ID/Student number", 'mail' => "permanent e-mail", 'disk' => "disk space allocated to portfolio files", 'prvs' => "Previous", @@ -1744,6 +1779,7 @@ sub update_user_data { $lt{'mddl'} $lt{'lst'} $lt{'gen'} + $lt{'id'} $lt{'mail'} $lt{'disk'} $lt{'prvs'} @@ -1751,6 +1787,7 @@ sub update_user_data { $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'} + $userenv{'id'} $userenv{'permanentemail'} $oldportfolioquota Mb @@ -1759,10 +1796,24 @@ sub update_user_data { $env{'form.cmiddlename'} $env{'form.clastname'} $env{'form.cgeneration'} + $env{'form.cid'} $env{'form.cpermanentemail'} $newportfolioquota Mb $defquotatext END + if (($forceid) && ($recurseid) && (!$disallowed_id) && + (&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.'
'); + } if (($env{'form.ccdomain'} eq $env{'user.domain'}) && ($env{'form.ccuname'} eq $env{'user.name'})) { my %newenvhash; @@ -1786,12 +1837,19 @@ END # They did not want to change the users name but we can # still tell them what the name is my %lt=&Apache::lonlocal::texthash( + 'id' => "ID/Student number", 'mail' => "Permanent e-mail", 'disk' => "Disk space allocated to user's portfolio files", ); $r->print(<<"END"); -

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}  ($lt{'mail'}: $userenv{'permanentemail'})

+

$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 '. @@ -1824,7 +1882,7 @@ END $env{'form.ccdomain'},$now); $r->print($result); } - } + } if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) { # Revoke custom role $r->print(&mt('Revoking custom role:'). @@ -2511,7 +2569,7 @@ sub handler { $response = ''; } &print_user_modification_page($r,$ccuname,$ccdomain, - $srch,$response); + $srch,$response,$context); } elsif ($currstate eq 'query') { &print_user_query_page($r,'createuser'); } else { @@ -2521,7 +2579,8 @@ sub handler { } elsif ($env{'form.phase'} eq 'userpicked') { my $ccuname = &LONCAPA::clean_username($env{'form.seluname'}); my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'}); - &print_user_modification_page($r,$ccuname,$ccdomain,$srch); + &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'', + $context); } } elsif ($env{'form.phase'} eq 'update_user_data') { &update_user_data($r);