--- loncom/interface/loncreateuser.pm 2007/07/28 21:38:29 1.160 +++ loncom/interface/loncreateuser.pm 2007/07/30 00:31:27 1.162 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.160 2007/07/28 21:38:29 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.162 2007/07/30 00:31:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -200,111 +200,13 @@ sub print_username_entry_form { $formtoset = 'docustom'; $env{'form.rolename'} = $env{'form.startrolename'}; } - my ($newuserscript,$newuservalidate); - - if ($forcenewuser) { - $newuserscript = <<"ENDSCRIPT"; - -function setSearch() { - var createnew = 0; - for (var i=0; i'."\n". &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}). - $newuserscript.$validatescript.''."\n"; + ''."\n"; my %loaditems = ( 'onload' => "javascript:setFormElements(document.$formtoset)", @@ -516,8 +418,6 @@ sub print_user_modification_page { $loginscript = &Apache::loncommon::authform_header(%param); $authformkrb = &Apache::loncommon::authform_kerberos(%param); - $ccuname =&LONCAPA::clean_username($ccuname); - $ccdomain=&LONCAPA::clean_domain($ccdomain); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); my $dc_setcourse_code = ''; my $nondc_setsection_code = ''; @@ -762,16 +662,30 @@ ENDFORMINFO } } if ($uhome eq 'no_host') { - my $instsrch = { + my $newuser; + my $instsrch = { srchin => 'instd', - srchterm => $env{'form.seluname'}, - srchdomain => $env{'form.seludom'}, srchby => 'uname', srchtype => 'exact', }; - my %inst_results; - if (directorysrch_check($instsrch) eq 'ok') { - %inst_results = &Apache::lonnet::inst_directory_query($instsrch); + 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". @@ -2222,11 +2136,13 @@ sub handler { if ($env{'form.phase'} eq 'get_user_info') { my ($state,$response,$forcenewuser,$results) = &user_search_result($srch); + print STDERR "Got $state,$response,$forcenewuser\n"; if ($state eq 'select') { &print_user_selection_page($r,$response,$srch,$results); } elsif ($state eq 'modify') { my ($ccuname,$ccdomain); - if ($srch->{'srchby'} eq 'uname') { + if (($srch->{'srchby'} eq 'uname') && + ($srch->{'srchtype'} eq 'exact')) { $ccuname = $srch->{'srchterm'}; $ccdomain= $srch->{'srchdomain'}; } else { @@ -2322,18 +2238,37 @@ sub user_search_result { } } else { if ($srch->{'srchin'} eq 'dom') { - my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'}); - if ($uhome eq 'no_host') { + if ($srch->{'srchtype'} eq 'exact') { + my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'}); + if ($uhome eq 'no_host') { + ($state,$response,$forcenewuser) = + &build_search_response($srch,%srch_results); + } else { + $state = 'modify'; + } + } else { + %srch_results = &Apache::lonnet::usersearch($srch); ($state,$response,$forcenewuser) = &build_search_response($srch,%srch_results); - } else { - $state = 'modify'; } } else { my %courseusers = &get_courseusers(); - if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) { - $state = 'modify'; + if ($srch->{'srchtype'} eq 'exact') { + if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) { + $state = 'modify'; + } else { + ($state,$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) { + $srch_results{$user} = ''; + } + } + } ($state,$response,$forcenewuser) = &build_search_response($srch,%srch_results); }