--- loncom/interface/loncreateuser.pm 2007/12/08 19:19:03 1.205 +++ loncom/interface/loncreateuser.pm 2007/12/11 02:27:24 1.206 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.205 2007/12/08 19:19:03 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.206 2007/12/11 02:27:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -707,9 +707,11 @@ $loginscript

$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain

ENDTITLE - $r->print('
'. - &personal_data_display($ccuname,$ccdomain,$newuser, - %inst_results)); + $r->print('
'); + my $personal_table = + &personal_data_display($ccuname,$ccdomain,$newuser, + $context,%inst_results); + $r->print($personal_table); my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($ccdomain,'hserver', 'default','hide'); @@ -786,10 +788,12 @@ $crumbs $forminfo

$lt{'cup'} "$ccuname" $lt{'id'} "$ccdomain"

ENDCHANGEUSER - $r->print('
'. - &personal_data_display($ccuname,$ccdomain,$newuser, - %inst_results)); - if ($context eq 'domain') { + $r->print('
'); + my ($personal_table,$showforceid) = + &personal_data_display($ccuname,$ccdomain,$newuser, + $context,%inst_results); + $r->print($personal_table); + if ($showforceid) { $r->print(&Apache::lonuserutils::forceid_change($context)); } $r->print('
'); @@ -1318,13 +1322,16 @@ sub modify_login_block { } sub personal_data_display { - my ($ccuname,$ccdomain,$newuser,%inst_results) = @_; - my ($output,%userenv); + my ($ccuname,$ccdomain,$newuser,$context,%inst_results) = @_; + my ($output,$showforceid,%userenv,%domconfig); if (!$newuser) { # Get the users information %userenv = &Apache::lonnet::get('environment', ['firstname','middlename','lastname','generation', 'permanentemail','id'],$ccdomain,$ccuname); + %domconfig = + &Apache::lonnet::get_dom('configuration',['usermodification'], + $ccdomain); } my %lt=&Apache::lonlocal::texthash( 'pd' => "Personal Data", @@ -1362,21 +1369,47 @@ sub personal_data_display { $output .= ''; } } else { + my $canmodify = 0; if (&Apache::lonnet::allowed('mau',$ccdomain)) { + $canmodify = 1; + } else { + if (ref($domconfig{'usermodification'}) eq 'HASH') { + if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') { + foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) { + if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') { + if ($domconfig{'usermodification'}{$context}{$key}{$item}) { + $canmodify = 1; + last; + } + } + } + } + } elsif ($context eq 'course') { + $canmodify = 1; + } + } + if ($canmodify) { $output .= ''; } else { $output .= $userenv{$item}; } + if ($item eq 'id') { + $showforceid = $canmodify; + } } $output .= &Apache::lonhtmlcommon::row_closure(1); } $output .= &Apache::lonhtmlcommon::end_pick_box(); - return $output; + if (wantarray) { + return ($output,$showforceid); + } else { + return $output; + } } # ================================================================= Phase Three sub update_user_data { - my ($r) = @_; + my ($r,$context) = @_; my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); # Error messages @@ -1574,10 +1607,114 @@ sub update_user_data { if ($tmp =~ /^(con_lost|error)/i) { %userenv = (); } - # Check to see if we need to change user information + my $no_forceid_alert; + # Check to see if user information can be changed + my %domconfig = + &Apache::lonnet::get_dom('configuration',['usermodification'], + $env{'form.ccdomain'}); + my @roletypes = ('active','future'); + my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@roletypes,undef,$env{'request.role.domain'}); + my @userroles; + my ($cnum,$cdom,$auname,$audom); + if ($context eq 'course') { + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if ($cnum eq '' || $cdom eq '') { + my $cid = $env{'request.course.id'}; + my %coursehash = + &Apache::lonnet::coursedescription($cid,{'one_time' => 1}); + $cdom = $coursehash{'domain'}; + $cnum = $coursehash{'num'}; + } + } elsif ($context eq 'author') { + $auname = $env{'user.name'}; + $audom = $env{'user.domain'}; + } + foreach my $item (keys(%roles)) { + my ($rolenum,$roledom,$role) = split(/:/,$item); + if ($context eq 'course') { + if ($cnum ne '' && $cdom ne '') { + if ($rolenum eq $cnum && $roledom eq $cdom) { + if (!grep(/^\Q$role\E$/,@userroles)) { + push(@userroles,$role); + } + } + } + } elsif ($context eq 'author') { + if ($rolenum eq $auname && $roledom eq $audom) { + if (!grep(/^\Q$role\E$/,@userroles)) { + push(@userroles,$role); + } + } + } + } + # Check for course or co-author roles being activated or re-enabled + if ($context eq 'author' || $context eq 'course') { + foreach my $key (keys(%env)) { + if ($context eq 'author') { + if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) { + if (!grep(/^\Q$1\E$/,@userroles)) { + push(@userroles,$1); + } + } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) { + if (!grep(/^\Q$1\E$/,@userroles)) { + push(@userroles,$1); + } + } + } elsif ($context eq 'course') { + if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) { + if (!grep(/^\Q$1\E$/,@userroles)) { + push(@userroles,$1); + } + } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) { + if (!grep(/^\Q$1\E$/,@userroles)) { + push(@userroles,$1); + } + } + } + } + } + #Check to see if we can change personal data for the user + my (@mod_disallowed,@longroles); + foreach my $role (@userroles) { + if ($role eq 'cr') { + push(@longroles,'Custom'); + } else { + push(@longroles,&Apache::lonnet::plaintext($role)); + } + } foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') { + my $canmodify = 0; + if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) { + $canmodify = 1; + } else { + if ($context eq 'course' || $context eq 'author') { + if (ref($domconfig{'usermodification'}) eq 'HASH') { + if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') { + foreach my $role (@userroles) { + if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') { + if ($domconfig{'usermodification'}{$context}{$role}{$item}) { + $canmodify = 1; + last; + } + } + } + } + } + } elsif ($context eq 'course') { + if (grep(/^st$/,@userroles)) { + $canmodify = 1; + } + } + } # Strip leading and trailing whitespace $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g; + if (!$canmodify) { + if ($env{'form.c'.$item} ne $userenv{$item}) { + push(@mod_disallowed,$item); + } + $env{'form.c'.$item} = $userenv{$item}; + } } # Check to see if we can change the ID/student number my $forceid = $env{'form.forceid'}; @@ -1591,6 +1728,7 @@ sub update_user_data { (!$forceid)) { if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) { $env{'form.cid'} = $userenv{'id'}; + $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'
'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'
'."\n"; } } if ($env{'form.cid'} ne $userenv{'id'}) { @@ -1654,13 +1792,12 @@ sub update_user_data { if ($newisdefault) { $newdefquotatext = &get_defaultquota_text($settingstatus); } - if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && - ($env{'form.cfirstname'} ne $userenv{'firstname'} || - $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'} )) { + if ($env{'form.cfirstname'} ne $userenv{'firstname'} || + $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; } if ($namechanged || $quotachanged) { @@ -1738,7 +1875,7 @@ END $newportfolioquota Mb $newdefquotatext END $r->print(&Apache::loncommon::end_data_table_row(). - &Apache::loncommon::end_data_table()); + &Apache::loncommon::end_data_table().'
'); if ($env{'form.cid'} ne $userenv{'id'}) { &Apache::lonnet::idput($env{'form.ccdomain'}, ($env{'form.ccuname'} => $env{'form.cid'})); @@ -1769,7 +1906,7 @@ END } else { # error occurred $r->print(''.&mt('Unable to successfully change environment for').' '. $env{'form.ccuname'}.' '.&mt('in domain').' '. - $env{'form.ccdomain'}.''); + $env{'form.ccdomain'}.'
'); } } else { # End of if ($env ... ) logic # They did not want to change the users name or quota but we can @@ -1789,6 +1926,27 @@ END $r->print('
['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. $olddefquotatext.']'); } + if (@mod_disallowed) { + my ($rolestr,$contextname); + if (@longroles > 0) { + $rolestr = join(', ',@longroles); + } else { + $rolestr = &mt('No roles'); + } + if ($context eq 'course') { + $contextname = &mt('course'); + } elsif ($context eq 'author') { + $contextname = &mt('co-author'); + } + $r->print(&mt('The following fields were not updated: ').'
    '); + my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles(); + foreach my $field (@mod_disallowed) { + $r->print('
  • '.$fieldtitles{$field}.'
  • '."\n"); + } + $r->print('
'.&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles: [_2].",$contextname,$rolestr).'
'.&mt('Contact your helpdesk for more information.',"javascript:helpMenu('display')").'
'); + } + $r->print($no_forceid_alert. + &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules)); } ## my $now=time; @@ -2398,7 +2556,7 @@ sub handler { if ($env{'request.course.id'}) { $context = 'course'; } elsif ($env{'request.role'} =~ /^au\./) { - $context = 'construction_space'; + $context = 'author'; } else { $context = 'domain'; } @@ -2513,7 +2671,7 @@ sub handler { $context); } } elsif ($env{'form.phase'} eq 'update_user_data') { - &update_user_data($r); + &update_user_data($r,$context); } else { &print_username_entry_form($r,undef,$srch); } @@ -2709,7 +2867,7 @@ sub get_permission { } } } - } elsif ($context eq 'construction_space') { + } elsif ($context eq 'author') { $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'}); $permission{'view'} = $permission{'cusr'}; } else {