--- loncom/interface/loncreateuser.pm 2007/08/25 17:46:24 1.176 +++ loncom/interface/loncreateuser.pm 2007/10/11 02:16:25 1.189 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.176 2007/08/25 17:46:24 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.189 2007/10/11 02:16:25 albertel 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; } @@ -264,13 +289,14 @@ ENDCUSTOM sub entry_form { my ($dom,$srch,$forcenewuser) = @_; my $userpicker = - &Apache::loncommon::user_picker($dom,$srch,$forcenewuser); + &Apache::loncommon::user_picker($dom,$srch,$forcenewuser, + 'document.crtuser'); my $srchbutton = &mt('Search'); my $output = <<"ENDDOCUMENT";
$userpicker - +
ENDDOCUMENT return $output; @@ -305,7 +331,7 @@ END # =================================================================== Phase two sub print_user_selection_page { - my ($r,$response,$srch,$srch_results) = @_; + my ($r,$response,$srch,$srch_results,$context,$srcharray) = @_; my @fields = ('username','domain','lastname','firstname','permanentemail'); my $sortby = $env{'form.sortby'}; @@ -329,25 +355,34 @@ $jsback ENDSCRIPT my %lt=&Apache::lonlocal::texthash( - 'srch' => "User Search to add/modify roles", + 'usrch' => "User Search to add/modify roles", + 'stusrch' => "User Search to enroll student", + 'usel' => "Select a user to add/modify roles", + 'stusel' => "Select a user to enroll as a student", 'username' => "username", 'domain' => "domain", 'lastname' => "last name", 'firstname' => "first name", 'permanentemail' => "permanent e-mail", ); - $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript)); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"javascript:backPage(document.usersrchform,'','')", - text=>"User modify/custom role edit", - faq=>282,bug=>'Instructor Interface',}, - {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')", - text=>"Select User", - faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); - $r->print("$lt{'srch'}
"); - $r->print(&entry_form($srch->{'srchdomain'},$srch)); - $r->print('

'.&mt('Select a user to add/modify roles').'

'); + if ($context eq 'createuser') { + $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript)); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:backPage(document.usersrchform,'','')", + text=>"User modify/custom role edit", + faq=>282,bug=>'Instructor Interface',}, + {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')", + text=>"Select User", + faq=>282,bug=>'Instructor Interface',}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + $r->print("$lt{'usrch'}
"); + $r->print(&entry_form($srch->{'srchdomain'},$srch)); + $r->print('

'.$lt{'usel'}.'

'); + } else { + $r->print($jscript."$lt{'stusrch'}
"); + $r->print(&Apache::londropadd::single_user_entry_form($srch->{'srchdomain'},$srch)); + $r->print('

'.$lt{'stusel'}.'

'); + } $r->print('
'. &Apache::loncommon::start_data_table()."\n". &Apache::loncommon::start_data_table_header_row()."\n". @@ -381,19 +416,27 @@ ENDSCRIPT $r->print(&Apache::loncommon::end_data_table_row()); } $r->print(&Apache::loncommon::end_data_table().'

'); - $r->print(&Apache::lonhtmlcommon::echo_form_input(['sortby','seluname','seludom','state','phase'])); + if (ref($srcharray) eq 'ARRAY') { + foreach my $item (@{$srcharray}) { + $r->print(''."\n"); + } + } $r->print(' '."\n". ' '."\n". ' '."\n". - ' '."\n". - ' '."\n". - '
'); + ' '."\n". + ' '."\n"); $r->print($response); - $r->print(&Apache::loncommon::end_page()); + if ($context eq 'createuser') { + $r->print(''.&Apache::loncommon::end_page()); + } else { + $r->print(''."\n". + ''."\n"); + } } sub print_user_query_page { - my ($r) = @_; + my ($r,$caller) = @_; # FIXME - this is for a network-wide name search (similar to catalog search) # To use frames with similar behavior to catalog/portfolio search. # To be implemented. @@ -402,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 } @@ -416,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); @@ -624,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,}); @@ -651,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)/) { @@ -665,135 +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); - if ($newuser) { - if (&directorysrch_check($instsrch) eq 'ok') { - %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch); - 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) { @@ -932,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. @@ -968,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(). @@ -984,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( @@ -1152,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 @@ -1192,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','state'])); - $r->print(''); + $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'; @@ -1251,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); @@ -1312,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.').'

'); @@ -1337,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'}); @@ -1499,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; @@ -1517,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) { @@ -1739,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 { @@ -1949,7 +2222,7 @@ ENDCCF } $r->print(&Apache::loncommon::end_data_table(). ''."\n".''."\n". + '" />'."\n".''."\n". ''."\n". ''. &Apache::loncommon::end_page()); @@ -2059,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=''; @@ -2135,18 +2408,24 @@ sub handler { my $phase = $env{'form.phase'}; my @search = ('srchterm','srchby','srchin','srchtype','srchdomain'); + + &Apache::loncreateuser::restore_prev_selections(); + my $srch; + foreach my $item (@search) { + $srch->{$item} = $env{'form.'.$item}; + } if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) { - my $srch; - foreach my $item (@search) { - $srch->{$item} = $env{'form.'.$item}; - } + if ($env{'form.phase'} eq 'get_user_info') { - my ($state,$response,$forcenewuser,$results) = + my ($currstate,$response,$forcenewuser,$results) = &user_search_result($srch); - if ($state eq 'select') { - &print_user_selection_page($r,$response,$srch,$results); - } elsif ($state eq 'modify') { + 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') { my ($ccuname,$ccdomain); if (($srch->{'srchby'} eq 'uname') && ($srch->{'srchtype'} eq 'exact')) { @@ -2158,10 +2437,13 @@ 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 ($state eq 'query') { - &print_user_query_page($r); + } elsif ($currstate eq 'query') { + &print_user_query_page($r,'createuser'); } else { &print_username_entry_form($r,$response,$srch,$forcenewuser); } @@ -2177,7 +2459,7 @@ sub handler { } elsif ($env{'form.phase'} eq 'set_custom_roles') { &set_custom_role($r); } else { - &print_username_entry_form($r); + &print_username_entry_form($r,undef,$srch); } } else { $env{'user.error.msg'}= @@ -2187,28 +2469,40 @@ sub handler { return OK; } +sub restore_prev_selections { + my %saveable_parameters = ('srchby' => 'scalar', + 'srchin' => 'scalar', + 'srchtype' => 'scalar', + ); + &Apache::loncommon::store_settings('user','user_picker', + \%saveable_parameters); + &Apache::loncommon::restore_settings('user','user_picker', + \%saveable_parameters); +} + #-------------------------------------------------- functions for &phase_two sub user_search_result { my ($srch) = @_; my %allhomes; my %inst_matches; my %srch_results; - my ($response,$state,$forcenewuser); - $srch->{'srchterm'} =~ s/^\s+//; - $srch->{'srchterm'} =~ s/\s+$//; - + my ($response,$currstate,$forcenewuser,$dirsrchres); + $srch->{'srchterm'} =~ s/\s+/ /g; if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) { $response = &mt('Invalid search.'); } if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) { $response = &mt('Invalid search.'); } - if ($srch->{'srchtype'} !~ /^(exact|contains)$/) { + if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) { $response = &mt('Invalid search.'); } 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'}))) { @@ -2223,14 +2517,18 @@ sub user_search_result { } } } + if ($response ne '') { + $response = ''.$response.''; + } if ($srch->{'srchin'} eq 'instd') { my $instd_chk = &directorysrch_check($srch); if ($instd_chk ne 'ok') { - $response = $instd_chk; + $response = ''.$instd_chk.''. + '
'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'

'; } } if ($response ne '') { - return ($state,''.$response.''); + return ($currstate,$response); } if ($srch->{'srchby'} eq 'uname') { if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) { @@ -2239,42 +2537,53 @@ sub user_search_result { my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'}); if ($uhome eq 'no_host') { my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description'); - $response = &mt('New users can only be created in the domain to which you current role belongs - [_1].',$env{'request.role.domain'}.' ('.$domdesc.')'); + my $showdom = &display_domain_info($env{'request.role.domain'}); + $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom); } else { - $state = 'modify'; + $currstate = 'modify'; } } else { - $state = 'modify'; + $currstate = 'modify'; } } else { if ($srch->{'srchin'} eq 'dom') { if ($srch->{'srchtype'} eq 'exact') { my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'}); if ($uhome eq 'no_host') { - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } else { - $state = 'modify'; + $currstate = 'modify'; } } else { %srch_results = &Apache::lonnet::usersearch($srch); - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } } else { my $courseusers = &get_courseusers(); if ($srch->{'srchtype'} eq 'exact') { if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) { - $state = 'modify'; + $currstate = 'modify'; } else { - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } } else { foreach my $user (keys(%$courseusers)) { my ($cuname,$cudomain) = split(/:/,$user); if ($cudomain eq $srch->{'srchdomain'}) { - if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) { + my $matched = 0; + if ($srch->{'srchtype'} eq 'begins') { + if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) { + $matched = 1; + } + } else { + if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) { + $matched = 1; + } + } + if ($matched) { $srch_results{$user} = {&Apache::lonnet::get('environment', ['firstname', @@ -2283,22 +2592,31 @@ sub user_search_result { } } } - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } } } } elsif ($srch->{'srchin'} eq 'alc') { - $state = 'query'; + $currstate = 'query'; } elsif ($srch->{'srchin'} eq 'instd') { - %srch_results = &Apache::lonnet::inst_directory_query($srch); - ($state,$response,$forcenewuser) = - &build_search_response($srch,%srch_results); + ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch); + if ($dirsrchres eq 'ok') { + ($currstate,$response,$forcenewuser) = + &build_search_response($srch,%srch_results); + } else { + my $showdom = &display_domain_info($srch->{'srchdomain'}); + $response = ''. + &mt('Institutional directory search is not available in domain: [_1]',$showdom). + '
'. + &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.'). + '

'; + } } } else { if ($srch->{'srchin'} eq 'dom') { %srch_results = &Apache::lonnet::usersearch($srch); - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } elsif ($srch->{'srchin'} eq 'crs') { my $courseusers = &get_courseusers(); @@ -2309,6 +2627,8 @@ sub user_search_result { if ($srch->{'srchby'} eq 'lastname') { if ((($srch->{'srchtype'} eq 'exact') && ($names{'lastname'} eq $srch->{'srchterm'})) || + (($srch->{'srchtype'} eq 'begins') && + ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) || (($srch->{'srchtype'} eq 'contains') && ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) { $srch_results{$user} = {firstname => $names{'firstname'}, @@ -2318,6 +2638,8 @@ sub user_search_result { } } elsif ($srch->{'srchby'} eq 'lastfirst') { my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'}); + $srchlast =~ s/\s+$//; + $srchfirst =~ s/^\s+//; if ($srch->{'srchtype'} eq 'exact') { if (($names{'lastname'} eq $srchlast) && ($names{'firstname'} eq $srchfirst)) { @@ -2327,7 +2649,15 @@ sub user_search_result { }; } - } elsif ($srch->{'srchtype'} eq 'contains') { + } elsif ($srch->{'srchtype'} eq 'begins') { + if (($names{'lastname'} =~ /^\Q$srchlast\E/i) && + ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) { + $srch_results{$user} = {firstname => $names{'firstname'}, + lastname => $names{'lastname'}, + permanentemail => $emails{'permanentemail'}, + }; + } + } else { if (($names{'lastname'} =~ /\Q$srchlast\E/i) && ($names{'firstname'} =~ /\Q$srchfirst\E/i)) { $srch_results{$user} = {firstname => $names{'firstname'}, @@ -2338,17 +2668,25 @@ sub user_search_result { } } } - ($state,$response,$forcenewuser) = + ($currstate,$response,$forcenewuser) = &build_search_response($srch,%srch_results); } elsif ($srch->{'srchin'} eq 'alc') { - $state = 'query'; + $currstate = 'query'; } elsif ($srch->{'srchin'} eq 'instd') { - %srch_results = &Apache::lonnet::inst_directory_query($srch); - ($state,$response,$forcenewuser) = - &build_search_response($srch,%srch_results); + ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch); + if ($dirsrchres eq 'ok') { + ($currstate,$response,$forcenewuser) = + &build_search_response($srch,%srch_results); + } else { + my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = ''. + &mt('Institutional directory search is not available in domain: [_1]',$showdom). + '
'. + &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.'). + '

'; + } } } - return ($state,$response,$forcenewuser,\%srch_results); + return ($currstate,$response,$forcenewuser,\%srch_results); } sub directorysrch_check { @@ -2357,13 +2695,14 @@ sub directorysrch_check { my $response; my %dom_inst_srch = &Apache::lonnet::get_dom('configuration', ['directorysrch'],$srch->{'srchdomain'}); + my $showdom = &display_domain_info($srch->{'srchdomain'}); if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') { if (!$dom_inst_srch{'directorysrch'}{'available'}) { - return &mt('Institutional directory search unavailable in domain: [_1]',$srch->{'srchdomain'}); + return &mt('Institutional directory search is not available in domain: [_1]',$showdom); } if ($dom_inst_srch{'directorysrch'}{'localonly'}) { if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) { - return &mt('Insitutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'}); + return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom); } my @usertypes = split(/:/,$env{'environment.inststatus'}); if (!@usertypes) { @@ -2384,41 +2723,50 @@ sub directorysrch_check { push (@longtypes,$insttypes->{$item}); } my $insttype_str = join(', ',@longtypes); - return &mt('Directory search in domain: [_1] is unavailable to your user type: ',$srch->{'srchdomain'}).$insttype_str; + return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str; } } else { $can_search = 1; } } else { - return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'}); + return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom); } my %longtext = &Apache::lonlocal::texthash ( uname => 'username', lastfirst => 'last name, first name', lastname => 'last name', contains => 'contains', - exact => 'as exact match to' + exact => 'as exact match to', + begins => 'begins with', ); if ($can_search) { if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') { if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) { - return &mt('Directory search in domain: [_1] is not available for searching by "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchby'}}); + return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}}); } } else { - return &mt('Directory search in domain: [_1] is not available.', $srch->{'srchdomain'}); + return &mt('Institutional directory search in domain: [_1] is not available.', $showdom); } } if ($can_search) { - if (($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') || - ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) { - return 'ok'; - } else { - return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}}); + if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') { + if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) { + return 'ok'; + } else { + return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}}); + } + } else { + if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') && + ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) || + ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) { + return 'ok'; + } else { + return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}}); + } } } } - sub get_courseusers { my %advhash; my $classlist = &Apache::loncoursedata::get_classlist(); @@ -2435,32 +2783,41 @@ sub get_courseusers { sub build_search_response { my ($srch,%srch_results) = @_; - my ($state,$response,$forcenewuser); + my ($currstate,$response,$forcenewuser); my %names = ( 'uname' => 'username', 'lastname' => 'last name', 'lastfirst' => 'last name, first name', 'crs' => 'this course', - 'dom' => 'this domain', - 'instd' => "your institution's directory", + 'dom' => 'LON-CAPA domain: ', + 'instd' => 'the institutional directory for domain: ', ); my %single = ( + begins => 'A match', contains => 'A match', - exact => 'An exact match', + exact => 'An exact match', ); my %nomatch = ( + begins => 'No match', contains => 'No match', - exact => 'No exact match', + exact => 'No exact match', ); if (keys(%srch_results) > 1) { - $state = 'select'; + $currstate = 'select'; } else { if (keys(%srch_results) == 1) { - $state = 'modify'; - $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}); + $currstate = 'modify'; + $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}); + if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') { + $response .= &display_domain_info($srch->{'srchdomain'}); + } } else { - $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}).''; + $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'}); + if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') { + $response .= &display_domain_info($srch->{'srchdomain'}); + } + $response .= ''; if ($srch->{'srchin'} ne 'alc') { $forcenewuser = 1; my $cansrchinst = 0; @@ -2472,20 +2829,36 @@ sub build_search_response { } } } - if (($srch->{'srchby'} eq 'lastfirst') || - ($srch->{'srchby'} eq 'lastname')) { - if ($srch->{'srchin'} eq 'crs') { - $response .= '
'.&mt('You may want to broaden your search to the whole domain.'); - } elsif ($srch->{'srchin'} eq 'dom') { - if ($cansrchinst) { - $response .= '
'.&mt('You may want to broaden your search to a search of the institutional directory for this domain.'); - } + if ((($srch->{'srchby'} eq 'lastfirst') || + ($srch->{'srchby'} eq 'lastname')) && + ($srch->{'srchin'} eq 'dom')) { + if ($cansrchinst) { + $response .= '
'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.'); } } + if ($srch->{'srchin'} eq 'crs') { + $response .= '
'.&mt('You may want to broaden your search to the selected LON-CAPA domain.'); + } + } + if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) { + my $showdom = &display_domain_info($env{'request.role.domain'}); + $response .= '

'.&mt("To add a new user (you can only create new users in your current role's domain - [_1]):",$env{'request.role.domain'}).'
  • '.&mt("Set 'Domain/institution to search' to: [_1]",$showdom).'
  • '.&mt("Set 'Search criteria' to: 'username is ...... in selected LON-CAPA domain'").'
  • '.&mt('Provide the proposed username').'
  • '.&mt('Search').'

'; } } } - return ($state,$response,$forcenewuser); + return ($currstate,$response,$forcenewuser); +} + +sub display_domain_info { + my ($dom) = @_; + my $output = $dom; + if ($dom ne '') { + my $domdesc = &Apache::lonnet::domain($dom,'description'); + if ($domdesc ne '') { + $output .= ' ('.$domdesc.')'; + } + } + return $output; } sub crumb_utilities { @@ -2501,12 +2874,19 @@ sub crumb_utilities { rolename => 'selectbox', newrolename => 'textbox', }, + studentform => { + srchterm => 'text', + srchin => 'selectbox', + srchby => 'selectbox', + srchtype => 'selectbox', + srchdomain => 'selectbox', + }, ); my $jsback .= qq| function backPage(formname,prevphase,prevstate) { formname.phase.value = prevphase; - formname.state.value = prevstate; + formname.currstate.value = prevstate; formname.submit(); } |; @@ -2599,9 +2979,9 @@ ENDTIMEENTRY if (%sections_count) { my $currsec = &course_sections(\%sections_count,$customrole); $table.= - ''. - ''. + '
'.$lt{'exs'}.'
'. - $currsec.'
'. + ''. ''. ''. @@ -2626,8 +3006,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'}.'