--- loncom/interface/loncreateuser.pm 2007/08/31 17:58:47 1.182 +++ loncom/interface/loncreateuser.pm 2007/10/09 17:33:57 1.188 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.182 2007/08/31 17:58:47 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.188 2007/10/09 17:33:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,7 +68,6 @@ use Apache::longroup; use LONCAPA qw(:DEFAULT :match); my $loginscript; # piece of javascript used in two separate instances -my $generalrule; my $authformnop; my $authformkrb; my $authformint; @@ -76,14 +75,24 @@ my $authformfsys; my $authformloc; sub initialize_authen_forms { + my ($dom,$curr_authtype) = @_; my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/); $krbdefdom= uc($krbdefdom); my %param = ( formname => 'document.cu', - kerb_def_dom => $krbdefdom - ); + kerb_def_dom => $krbdefdom, + domain => $dom, + ); + my %abv_auth = &auth_abbrev(); + if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):$/) { + my $long_auth = $1; + my %abv_auth = &auth_abbrev(); + $param{'curr_authtype'} = $abv_auth{$long_auth}; + if ($long_auth =~ /^krb(4|5)$/) { + $param{'curr_kerb_ver'} = $1; + } + } # no longer static due to configurable kerberos defaults # $loginscript = &Apache::loncommon::authform_header(%param); - $generalrule = &Apache::loncommon::authform_authorwarning(%param); $authformnop = &Apache::loncommon::authform_nochange(%param); # no longer static due to configurable kerberos defaults # $authformkrb = &Apache::loncommon::authform_kerberos(%param); @@ -92,6 +101,15 @@ sub initialize_authen_forms { $authformloc = &Apache::loncommon::authform_local(%param); } +sub auth_abbrev { + my %abv_auth = ( + krb4 => 'krb', + internal => 'int', + localuth => 'loc', + unix => 'fsys', + ); + return %abv_auth; +} # ======================================================= Existing Custom Roles @@ -175,8 +193,13 @@ END_SCRIPT } my $output = $quota_javascript. '

'.$lt{'disk'}.'

'. - $lt{'cuqu'}.': '.$currquota.' Mb.  '. - $defaultinfo.'
'.$lt{'chqu'}. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(). + ''.$lt{'cuqu'}.': '.$currquota.' Mb.  '. + $defaultinfo.''. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::start_data_table_row(). + ''.$lt{'chqu'}. ': '. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(); return $output; } @@ -420,10 +445,42 @@ sub print_user_query_page { sub print_user_modification_page { my ($r,$ccuname,$ccdomain,$srch,$response) = @_; - unless (($ccuname) && ($ccdomain)) { - &print_username_entry_form($r); + if (($ccuname eq '') || ($ccdomain eq '')) { + my $usermsg = &mt('No username and/or domain provided.'); + &print_username_entry_form($r,$usermsg); return; } + my %abv_auth = &auth_abbrev(); + my ($curr_authtype,$instsrch,$rulematch,$rules,%inst_results, + $curr_kerb_ver,$newuser); + my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); + if ($uhome eq 'no_host') { + $newuser = 1; + $instsrch = + { + srchin => 'instd', + srchby => 'uname', + srchtype => 'exact', + srchterm => $ccuname, + srchdomain => $ccdomain, + }; + (my $usercheckmsg,$rulematch,$rules,%inst_results) = + &Apache::loncommon::username_rule_check($instsrch,'new'); + if ($usercheckmsg) { + &print_username_entry_form($r,$usercheckmsg); + return; + } + } else { + $newuser = 0; + my $currentauth = + &Apache::lonnet::queryauthenticate($ccuname,$ccdomain); + if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) { + $curr_authtype = $abv_auth{$1}; + if ($currentauth =~ /^krb(4|5)/) { + $curr_kerb_ver = $1; + } + } + } if ($response) { $response = '
'.$response } @@ -434,7 +491,10 @@ sub print_user_modification_page { my %param = ( formname => 'document.cu', kerb_def_dom => $krbdefdom, - kerb_def_auth => $krbdef + kerb_def_auth => $krbdef, + curr_authtype => $curr_authtype, + curr_kerb_ver => $curr_kerb_ver, + domain => $ccdomain, ); $loginscript = &Apache::loncommon::authform_header(%param); $authformkrb = &Apache::loncommon::authform_kerberos(%param); @@ -642,10 +702,17 @@ ENDSECCODE $nondc_setsection_code,$groupslist); my ($jsback,$elements) = &crumb_utilities(); - + my $javascript_validations; + if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($uhome eq 'no_host')) { + my ($krbdef,$krbdefdom) = + &Apache::loncommon::get_kerberos_defaults($ccdomain); + $javascript_validations = + &Apache::londropadd::javascript_validations('auth',$krbdefdom,undef, + undef,$ccdomain); + } $js .= "\n". - ''; - + ''; my $start_page = &Apache::loncommon::start_page('Create Users, Change User Privileges', $js,{'add_entries' => \%loaditem,}); @@ -669,13 +736,12 @@ ENDSECCODE my $forminfo =<<"ENDFORMINFO";
- - + + ENDFORMINFO - my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); my %inccourses; foreach my $key (keys(%env)) { if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) { @@ -683,137 +749,141 @@ ENDFORMINFO } } if ($uhome eq 'no_host') { - my $newuser; - my $instsrch = { - srchin => 'instd', - srchby => 'uname', - srchtype => 'exact', - }; - if ($env{'form.phase'} eq 'userpicked') { - $instsrch->{'srchterm'} = $env{'form.seluname'}; - $instsrch->{'srchdomain'} = $env{'form.seludom'}; - } else { - $instsrch->{'srchterm'} = $ccuname; - $instsrch->{'srchdomain'} = $ccdomain, - } - if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) { - $newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'}; - } - my (%dirsrch_results,%inst_results,$dirsrchres); - if ($newuser) { - if (&directorysrch_check($instsrch) eq 'ok') { - ($dirsrchres,%dirsrch_results) = &Apache::lonnet::inst_directory_query($instsrch); - if ($dirsrchres eq 'ok') { - if (ref($dirsrch_results{$newuser}) eq 'HASH') { - %inst_results = %{$dirsrch_results{$newuser}}; - } - } - } - } - my $home_server_list= - ''."\n". - &Apache::loncommon::home_server_option_list($ccdomain); - - my %lt=&Apache::lonlocal::texthash( - 'cnu' => "Create New User", - 'nu' => "New User", - 'id' => "in domain", - 'pd' => "Personal Data", - 'fn' => "First Name", - 'mn' => "Middle Name", - 'ln' => "Last Name", - 'gen' => "Generation", - 'mail' => "Permanent e-mail address", - 'idsn' => "ID/Student Number", - 'hs' => "Home Server", - 'lg' => "Login Data" - ); my $portfolioform; if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) { # Current user has quota modification privileges - $portfolioform = &portfolio_quota($ccuname,$ccdomain); + $portfolioform = '
'.&portfolio_quota($ccuname,$ccdomain); } - my $genhelp=&Apache::loncommon::help_open_topic('Generation'); - &initialize_authen_forms(); - $r->print(< 'Create New User', + 'ind' => 'in domain', + 'lg' => 'Login Data', + ); + $r->print(<$lt{'cnu'} $response $forminfo -

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

-

$lt{'pd'}

-

- - - - - - - - - - - -
$lt{'fn'}
$lt{'mn'}
$lt{'ln'}
$lt{'gen'}$genhelp
$lt{'mail'}
-$lt{'idsn'}

-$lt{'hs'}: -
-

$lt{'lg'}

-

$generalrule

-

$authformkrb

-

$authformint

-

$authformfsys

-

$authformloc

-
-$portfolioform -ENDNEWUSER +

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

+ENDTITLE + $r->print('
'. + &personal_data_display($ccuname,$ccdomain,$newuser, + %inst_results)); + my ($home_server_pick,$numlib) = + &Apache::loncommon::home_server_form_item($ccdomain,'hserver', + 'default','hide'); + if ($numlib > 1) { + $r->print(" +
+$lt{'hs'}: $home_server_pick +
"); + } else { + $r->print($home_server_pick); + } + $r->print('
'."\n".'

'. + $lt{'lg'}.'

'); + my ($fixedauth,$varauth,$authmsg); + if ($rulematch) { + if (ref($rules) eq 'HASH') { + if (ref($rules->{$rulematch}) eq 'HASH') { + my $authtype = $rules->{$rulematch}{'authtype'}; + if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) { + $r->print(&set_login($ccdomain)); + } else { + my $authparm = $rules->{$rulematch}{'authparm'}; + if ($authtype =~ /^krb(4|5)$/) { + my $ver = $1; + if ($authparm ne '') { + $fixedauth = <<"KERB"; + + + +KERB + $authmsg = $rules->{$rulematch}{'authmsg'}; + } + } else { + $fixedauth = +''."\n"; + if ($rules->{$rulematch}{'authparmfixed'}) { + $fixedauth .= +''."\n"; + } else { + $varauth = +''."\n"; + } + } + } + } else { + $r->print(&set_login($ccdomain)); + } + } + if ($authmsg) { + $r->print(<print(&set_login($ccdomain)); + } + $r->print(< +ENDPORT } else { # user already exists my %lt=&Apache::lonlocal::texthash( - 'cup' => "Change User Privileges", - 'usr' => "User", + 'cup' => "Existing user ", 'id' => "in domain", - 'fn' => "first name", - 'mn' => "middle name", - 'ln' => "last name", - 'gen' => "generation", - 'email' => "permanent e-mail", ); $r->print(<$lt{'cup'} $forminfo -

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

+

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

ENDCHANGEUSER - # Get the users information - my %userenv = - &Apache::lonnet::get('environment', - ['firstname','middlename','lastname','generation', - 'permanentemail','portfolioquota'],$ccdomain,$ccuname); - my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname); - $r->print(' -
'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). -''.$lt{'fn'}.''.$lt{'mn'}.''.$lt{'ln'}.''.$lt{'gen'}.''.$lt{'email'}.''. - &Apache::loncommon::end_data_table_header_row(). - &Apache::loncommon::start_data_table_row()); - foreach my $item ('firstname','middlename','lastname','generation','permanentemail') { - if (&Apache::lonnet::allowed('mau',$ccdomain)) { - $r->print(<<"END"); - -END - } else { - $r->print(''.$userenv{$item}.''); - } + $r->print('
'. + &personal_data_display($ccuname,$ccdomain,$newuser, + %inst_results). + '
'); + my $user_auth_text = + &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth); + my $user_quota_text; + if (&Apache::lonnet::allowed('mpq',$ccdomain)) { + # Current user has quota modification privileges + $user_quota_text = &portfolio_quota($ccuname,$ccdomain); + } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) { + # Get the user's portfolio information + my %portq = &Apache::lonnet::get('environment',['portfolioquota'], + $ccdomain,$ccuname); + + my %lt=&Apache::lonlocal::texthash( + 'dska' => "Disk space allocated to user's portfolio files", + 'youd' => "You do not have privileges to modify the portfolio quota for this user.", + 'ichr' => "If a change is required, contact a domain coordinator for the domain", + ); + $user_quota_text = <$lt{'dska'} +$lt{'youd'} $lt{'ichr'}: $ccdomain +ENDNOPORTPRIV + } + if ($user_auth_text ne '') { + $r->print('
'.$user_auth_text); + if ($user_quota_text ne '') { + $r->print($user_quota_text); + } + $r->print('
'); + + } elsif ($user_quota_text ne '') { + $r->print('
'.$user_quota_text.'
'); } - $r->print(&Apache::loncommon::end_data_table_row(). - &Apache::loncommon::end_data_table()); + $r->print(''); + my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname); # Build up table of user roles to allow revocation of a role. my ($tmp) = keys(%rolesdump); unless ($tmp =~ /^(con_lost|error)/i) { @@ -952,7 +1022,7 @@ END $plaintext=&Apache::lonnet::plaintext($role_code,$class) } else { $plaintext= - "Customrole '$croletitle' defined by $croleuname\@$croleudom"; + "Customrole '$croletitle'
defined by $croleuname\@$croleudom"; } $row.= ''.$plaintext. ''.$area. @@ -988,7 +1058,6 @@ END } if ($rolesdisplay == 1) { $r->print(' -

'.$lt{'rer'}.'

'. &Apache::loncommon::start_data_table("LC_createuser"). &Apache::loncommon::start_data_table_header_row(). @@ -1004,128 +1073,16 @@ END $r->print(&Apache::loncommon::end_data_table()); } } # End of unless - my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain); - if ($currentauth=~/^krb(4|5):/) { - $currentauth=~/^krb(4|5):(.*)/; - my $krbdefdom=$2; - my %param = ( formname => 'document.cu', - kerb_def_dom => $krbdefdom - ); - $loginscript = &Apache::loncommon::authform_header(%param); - } - # Check for a bad authentication type - unless ($currentauth=~/^krb(4|5):/ or - $currentauth=~/^unix:/ or - $currentauth=~/^internal:/ or - $currentauth=~/^localauth:/ - ) { # bad authentication scheme - if (&Apache::lonnet::allowed('mau',$ccdomain)) { - &initialize_authen_forms(); - my %lt=&Apache::lonlocal::texthash( - 'err' => "ERROR", - 'uuas' => "This user has an unrecognized authentication scheme", - 'sldb' => "Please specify login data below", - 'ld' => "Login Data" - ); - $r->print(< - -$lt{'err'}: -$lt{'uuas'} ($currentauth). $lt{'sldb'}. -

$lt{'ld'}

-

$generalrule

-

$authformkrb

-

$authformint

-

$authformfsys

-

$authformloc

-ENDBADAUTH - } else { - # This user is not allowed to modify the user's - # authentication scheme, so just notify them of the problem - my %lt=&Apache::lonlocal::texthash( - 'err' => "ERROR", - 'uuas' => "This user has an unrecognized authentication scheme", - 'adcs' => "Please alert a domain coordinator of this situation" - ); - $r->print(< - $lt{'err'}: -$lt{'uuas'} ($currentauth). $lt{'adcs'}. -
-ENDBADAUTH - } - } else { # Authentication type is valid - my $authformcurrent=''; - my $authform_other=''; - &initialize_authen_forms(); - if ($currentauth=~/^krb(4|5):/) { - $authformcurrent=$authformkrb; - $authform_other="

$authformint

\n". - "

$authformfsys

$authformloc

"; - } - elsif ($currentauth=~/^internal:/) { - $authformcurrent=$authformint; - $authform_other="

$authformkrb

". - "

$authformfsys

$authformloc

"; - } - elsif ($currentauth=~/^unix:/) { - $authformcurrent=$authformfsys; - $authform_other="

$authformkrb

". - "

$authformint

$authformloc;

"; - } - elsif ($currentauth=~/^localauth:/) { - $authformcurrent=$authformloc; - $authform_other="

$authformkrb

". - "

$authformint

$authformfsys

"; - } - $authformcurrent.=' (will override current values)
'; - if (&Apache::lonnet::allowed('mau',$ccdomain)) { - # Current user has login modification privileges - my %lt=&Apache::lonlocal::texthash( - 'ccld' => "Change Current Login Data", - 'enld' => "Enter New Login Data" - ); - $r->print(< - -

$lt{'ccld'}

-

$generalrule

-

$authformnop

-

$authformcurrent

-

$lt{'enld'}

-$authform_other -ENDOTHERAUTHS - } else { - if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) { - my %lt=&Apache::lonlocal::texthash( - 'ccld' => "Change Current Login Data", - 'yodo' => "You do not have privileges to modify the authentication configuration for this user.", - 'ifch' => "If a change is required, contact a domain coordinator for the domain", - ); - $r->print(< -

$lt{'ccld'}

-$lt{'yodo'} $lt{'ifch'}: $ccdomain -ENDNOPRIV - } - } - if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) { - # Current user has quota modification privileges - $r->print(&portfolio_quota($ccuname,$ccdomain)); - } - } ## End of "check for bad authentication type" logic } ## End of new user/old user logic - $r->print('

'.&mt('Add Roles').'

'); + my $addrolesdisplay = 0; + $r->print('

'.&mt('Add Roles').'

'); # # Co-Author # if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) && ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) { # No sense in assigning co-author role to yourself + $addrolesdisplay = 1; my $cuname=$env{'user.name'}; my $cudom=$env{'request.role.domain'}; my %lt=&Apache::lonlocal::texthash( @@ -1172,6 +1129,13 @@ ENDNOPRIV "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.''."\n". &Apache::loncommon::end_data_table_row()."\n". &Apache::loncommon::end_data_table()); + } elsif (!(&authorpriv($env{'user.name'},$env{'request.role.domain'}))) { + $r->print(''. + &mt('You do not have privileges to assign co-author roles.'). + ''); + } elsif (($env{'user.name'} eq $ccuname) && + ($env{'user.domain'} eq $ccdomain)) { + $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted')); } # # Domain level @@ -1212,33 +1176,314 @@ ENDNOPRIV $domaintext.= &Apache::loncommon::end_data_table(); if ($num_domain_level > 0) { $r->print($domaintext); + $addrolesdisplay = 1; } # -# Course and group levels +# Course level # if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) { $r->print(&course_level_dc($1,'Course')); - $r->print('
'."\n"); + $r->print('
'."\n"); + } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/$}) { + if ($addrolesdisplay) { + $r->print('
print(' onClick="verify_message(this.form)" \>'."\n"); + } else { + $r->print('onClick="this.form.submit()" \>'."\n"); + } + } else { + $r->print('
'. + &mt('Back to previous page').''); + } } else { $r->print(&course_level_table(%inccourses)); - $r->print('
'."\n"); + $r->print('
'."\n"); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate'])); + $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain'])); $r->print(''); $r->print(''); $r->print("".&Apache::loncommon::end_page()); } +sub user_authentication { + my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_; + my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain); + my ($loginscript,$outcome); + if ($currentauth=~/^(krb)(4|5):(.*)/) { + my $long_auth = $1.$2; + my $curr_kerb_ver = $2; + my $krbdefdom=$3; + my $curr_authtype = $abv_auth->{$long_auth}; + my %param = ( formname => 'document.cu', + kerb_def_dom => $krbdefdom, + domain => $ccdomain, + curr_authtype => $curr_authtype, + curr_kerb_ver => $curr_kerb_ver, + ); + $loginscript = &Apache::loncommon::authform_header(%param); + } + # Check for a bad authentication type + if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) { + # bad authentication scheme + my %lt=&Apache::lonlocal::texthash( + 'err' => "ERROR", + 'uuas' => "This user has an unrecognized authentication scheme", + 'adcs' => "Please alert a domain coordinator of this situation", + 'sldb' => "Please specify login data below", + 'ld' => "Login Data" + ); + if (&Apache::lonnet::allowed('mau',$ccdomain)) { + &initialize_authen_forms($ccdomain); + my $choices = &set_login($ccdomain); + $outcome = < +$loginscript + +$lt{'err'}: +$lt{'uuas'} ($currentauth). $lt{'sldb'}. +

$lt{'ld'}

+$choices +ENDBADAUTH + } else { + # This user is not allowed to modify the user's + # authentication scheme, so just notify them of the problem + $outcome = < $lt{'err'}: +$lt{'uuas'} ($currentauth). $lt{'adcs'}. + +ENDBADAUTH + } + } else { # Authentication type is valid + my $authformcurrent=''; + my $authform_other=''; + &initialize_authen_forms($ccdomain,$currentauth); + my ($authformcurrent,$authform_other,$can_modify) = + &modify_login_block($ccdomain,$currentauth); + if (&Apache::lonnet::allowed('mau',$ccdomain)) { + # Current user has login modification privileges + my %lt=&Apache::lonlocal::texthash ( + 'ld' => "Login Data", + 'ccld' => "Change Current Login Data", + 'enld' => "Enter New Login Data" + ); + $outcome = + ''."\n". + '

'.$lt{'ld'}.'

'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(). + ''.$authformnop; + if ($can_modify) { + $outcome .= ''."\n". + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::start_data_table_row(). + ''.$authformcurrent.''. + &Apache::loncommon::end_data_table_row()."\n"; + } else { + $outcome .= ' ('.$authformcurrent.')'; + } + if ($authform_other ne '') { + $outcome .= $authform_other; + } + $outcome .= &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(); + } else { + if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) { + my %lt=&Apache::lonlocal::texthash( + 'ccld' => "Change Current Login Data", + 'yodo' => "You do not have privileges to modify the authentication configuration for this user.", + 'ifch' => "If a change is required, contact a domain coordinator for the domain", + ); + $outcome .= <$lt{'ccld'} +$lt{'yodo'} $lt{'ifch'}: $ccdomain +ENDNOPRIV + } + } + } ## End of "check for bad authentication type" logic + return $outcome; +} + +sub set_login { + my ($dom) = @_; + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); + my $response; + my ($authnum,%can_assign) = + &Apache::loncommon::get_assignable_auth($dom); + if ($authnum) { + $response = &Apache::loncommon::start_data_table(); + if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) { + $response .= &Apache::loncommon::start_data_table_row(). + ''.$authformkrb.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + if ($can_assign{'int'}) { + $response .= &Apache::loncommon::start_data_table_row(). + ''.$authformint.''. + &Apache::loncommon::end_data_table_row()."\n" + } + if ($can_assign{'loc'}) { + $response .= &Apache::loncommon::start_data_table_row(). + ''.$authformloc.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + $response .= &Apache::loncommon::end_data_table(); + } + return $response; +} + +sub modify_login_block { + my ($dom,$currentauth) = @_; + 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); + 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" + } + if ($can_assign{'loc'}) { + $authform_other .= &Apache::loncommon::start_data_table_row(). + ''.$authformloc.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) { + $show_override_msg = 1; + } + } 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"; + } + if ($can_assign{'loc'}) { + $authform_other .= &Apache::loncommon::start_data_table_row(). + ''.$authformloc.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + if ($can_assign{'int'}) { + $show_override_msg = 1; + } + } 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"; + } + if ($can_assign{'int'}) { + $authform_other .= &Apache::loncommon::start_data_table_row(). + ''.$authformint.''. + &Apache::loncommon::end_data_table_row()."\n" + } + if ($can_assign{'loc'}) { + $authform_other .= &Apache::loncommon::start_data_table_row(). + ''.$authformloc.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + if ($can_assign{'fsys'}) { + $show_override_msg = 1; + } + } 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"; + } + if ($can_assign{'int'}) { + $authform_other .= &Apache::loncommon::start_data_table_row(). + ''.$authformint.''. + &Apache::loncommon::end_data_table_row()."\n" + } + if ($can_assign{'loc'}) { + $show_override_msg = 1; + } + } + if ($show_override_msg) { + $authformcurrent.= ' '. + &mt('will override current values'). + '
'; + } + return ($authformcurrent,$authform_other,$show_override_msg); +} + +sub personal_data_display { + my ($ccuname,$ccdomain,$newuser,%inst_results) = @_; + my ($output,%userenv); + if (!$newuser) { + # Get the users information + %userenv = &Apache::lonnet::get('environment', + ['firstname','middlename','lastname','generation', + 'permanentemail','id'],$ccdomain,$ccuname); + } + my %lt=&Apache::lonlocal::texthash( + 'pd' => "Personal Data", + 'firstname' => "First Name", + 'middlename' => "Middle Name", + 'lastname' => "Last Name", + 'generation' => "Generation", + 'permanentemail' => "Permanent e-mail address", + 'id' => "ID/Student Number", + 'hs' => "Home Server", + 'lg' => "Login Data" + ); + my @userinfo = ('firstname','middlename','lastname','generation', + 'permanentemail','id'); + my %textboxsize = ( + firstname => '15', + middlename => '15', + lastname => '15', + generation => '5', + permanentemail => '25', + id => '15', + ); + my $genhelp=&Apache::loncommon::help_open_topic('Generation'); + $output = '

'.$lt{'pd'}.'

'. + &Apache::lonhtmlcommon::start_pick_box(); + foreach my $item (@userinfo) { + my $rowtitle = $lt{$item}; + if ($item eq 'generation') { + $rowtitle = $genhelp.$rowtitle; + } + $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n"; + if ($newuser) { + if ($inst_results{$item} ne '') { + $output .= ''.$inst_results{$item}; + } else { + $output .= ''; + } + } else { + if (&Apache::lonnet::allowed('mau',$ccdomain)) { + $output .= ''; + } else { + $output .= $userenv{$item}; + } + } + $output .= &Apache::lonhtmlcommon::row_closure(1); + } + $output .= &Apache::lonhtmlcommon::end_pick_box(); + return $output; +} + # ================================================================= Phase Three sub update_user_data { my ($r) = @_; my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); # Error messages - my $error = ''.&mt('Error').':'; - my $end = &Apache::loncommon::end_page(); - + my $error = ''.&mt('Error').': '; + my $end = '

'. + ''. + &mt('Return to previous page').''.&Apache::loncommon::end_page(); my $title; if (exists($env{'form.makeuser'})) { $title='Set Privileges for New User'; @@ -1271,6 +1516,7 @@ sub update_user_data { $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); my %disallowed; + $r->print(&update_result_form($uhome)); # Check Inputs if (! $env{'form.ccuname'} ) { $r->print($error.&mt('No login name specified').'.'.$end); @@ -1332,8 +1578,8 @@ sub update_user_data { } - $r->print('

'.&mt('User [_1] in domain [_2]', - $env{'form.ccuname'}, $env{'form.ccdomain'}).'

'); + $r->print('

'.&mt('User [_1] in domain [_2]', + $env{'form.ccuname'}, $env{'form.ccdomain'}).'

'); if ($env{'form.makeuser'}) { $r->print('

'.&mt('Creating new account.').'

'); @@ -1357,10 +1603,10 @@ sub update_user_data { # Call modifyuser my $result = &Apache::lonnet::modifyuser ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'}, - $amode,$genpwd,$env{'form.cfirst'}, - $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'}, - undef,$desiredhost - ); + $amode,$genpwd,$env{'form.cfirstname'}, + $env{'form.cmiddlename'},$env{'form.clastname'}, + $env{'form.cgeneration'},undef,$desiredhost, + $env{'form.cpermanentemail'}); $r->print(&mt('Generating user').': '.$result); my $home = &Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); @@ -1519,9 +1765,9 @@ END &Apache::lonnet::appenv(%newenvhash); } } else { # error occurred - $r->print("

".&mt('Unable to successfully change environment for')." ". - $env{'form.ccuname'}." ".&mt('in domain')." ". - $env{'form.ccdomain'}."

"); + $r->print(''.&mt('Unable to successfully change environment for').' '. + $env{'form.ccuname'}.' '.&mt('in domain').' '. + $env{'form.ccdomain'}.''); } } else { # End of if ($env ... ) logic my $putresult; @@ -1537,8 +1783,7 @@ END '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'}  ($lt{'mail'}: $userenv{'permanentemail'})

END if ($putresult eq 'ok') { if ($oldportfolioquota != $newportfolioquota) { @@ -1759,20 +2004,28 @@ END } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - $r->print('

'.&mt('Create/Modify Another User').'

'); - $r->print('
'."\n"); + $r->print(&Apache::loncommon::end_page()); +} + +sub update_result_form { + my ($uhome) = @_; + my $outcome = + ''."\n"; foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') { - $r->print(''."\n"); + $outcome .= ''."\n"; } foreach my $item ('sortby','seluname','seludom') { if (exists($env{'form.'.$item})) { - $r->print(''."\n"); + $outcome .= ''."\n"; } } - $r->print(''."\n". - ''."\n". - '
'); - $r->print(&Apache::loncommon::end_page()); + if ($uhome eq 'no_host') { + $outcome .= ''."\n"; + } + $outcome .= ''."\n". + ''."\n". + ''; + return $outcome; } sub classlist_drop { @@ -2079,14 +2332,14 @@ sub set_custom_role { &Apache::lonnet::get('roles',["rolesdef_$rolename"]); # ------------------------------------------------------- Does this role exist? - $r->print('

'); + $r->print('

'); if (($rdummy ne 'con_lost') && ($roledef ne '')) { $r->print(&mt('Existing Role').' "'); } else { $r->print(&mt('New Role').' "'); $roledef=''; } - $r->print($rolename.'"

'); + $r->print($rolename.'"'); # ------------------------------------------------------- What can be assigned? my $sysrole=''; my $domrole=''; @@ -2164,6 +2417,9 @@ sub handler { if ($env{'form.phase'} eq 'get_user_info') { my ($currstate,$response,$forcenewuser,$results) = &user_search_result($srch); + if ($env{'form.currstate'} eq 'modify') { + $currstate = $env{'form.currstate'}; + } if ($currstate eq 'select') { &print_user_selection_page($r,$response,$srch,$results,'createuser',\@search); } elsif ($currstate eq 'modify') { @@ -2178,6 +2434,9 @@ sub handler { } $ccuname =&LONCAPA::clean_username($ccuname); $ccdomain=&LONCAPA::clean_domain($ccdomain); + if ($env{'form.forcenewuser'}) { + $response = ''; + } &print_user_modification_page($r,$ccuname,$ccdomain,$srch, $response); } elsif ($currstate eq 'query') { @@ -2214,9 +2473,7 @@ sub user_search_result { my %inst_matches; my %srch_results; my ($response,$currstate,$forcenewuser,$dirsrchres); - $srch->{'srchterm'} =~ s/^\s+//; - $srch->{'srchterm'} =~ s/\s+$//; - + $srch->{'srchterm'} =~ s/\s+/ /g; if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) { $response = &mt('Invalid search.'); } @@ -2229,6 +2486,9 @@ sub user_search_result { if ($srch->{'srchterm'} eq '') { $response = &mt('You must enter a search term.'); } + if ($srch->{'srchterm'} =~ /^\s+$/) { + $response = &mt('Your search term must contain more than just spaces.'); + } if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) { if (($srch->{'srchdomain'} eq '') || ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) { @@ -2493,7 +2753,6 @@ sub directorysrch_check { } } - sub get_courseusers { my %advhash; my $classlist = &Apache::loncoursedata::get_classlist(); @@ -2706,9 +2965,9 @@ ENDTIMEENTRY if (%sections_count) { my $currsec = &course_sections(\%sections_count,$customrole); $table.= - ''. - ''. + '
'.$lt{'exs'}.'
'. - $currsec.'
'. + ''. ''. ''. @@ -2733,8 +2992,11 @@ ENDENTRY } return '' if ($table eq ''); # return nothing if there is nothing # in the table - my $result = ' -

'.$lt{'crl'}.'

'. + my $result; + if (!$env{'request.course.id'}) { + $result = '

'.$lt{'crl'}.'

'."\n"; + } + $result .= &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). '
'. + $lt{'exs'}.'
'.$currsec.'
   '.$lt{'new'}.'
'. '
'.$lt{'act'}.''.$lt{'rol'}.''.$lt{'ext'}.'