--- loncom/interface/loncreateuser.pm 2007/07/28 21:38:29 1.160 +++ loncom/interface/loncreateuser.pm 2007/07/30 22:44:04 1.163 @@ -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.163 2007/07/30 22:44:04 albertel 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". @@ -1841,7 +1755,7 @@ END } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - $r->print('

Create/Modify Another User

'); + $r->print('

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

'); $r->print('
'."\n"); foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') { $r->print(''."\n"); @@ -2226,7 +2140,8 @@ sub handler { &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 { @@ -2267,7 +2182,6 @@ sub handler { #-------------------------------------------------- functions for &phase_two sub user_search_result { my ($srch) = @_; - my @alldomains = sort(&Apache::lonnet::all_domains()); my %allhomes; my %inst_matches; my %srch_results; @@ -2287,7 +2201,7 @@ sub user_search_result { } if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) { if (($srch->{'srchdomain'} eq '') || - (!(grep/^\Q$srch->{'srchdomain'}\E$/,@alldomains))) { + ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) { $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.') } } @@ -2304,7 +2218,7 @@ sub user_search_result { } } if ($response ne '') { - return ($state,$response); + return ($state,''.$response.''); } if ($srch->{'srchby'} eq 'uname') { if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) { @@ -2322,18 +2236,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); } @@ -2410,11 +2343,11 @@ sub directorysrch_check { ['directorysrch'],$srch->{'srchdomain'}); if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') { if (!$dom_inst_srch{'directorysrch'}{'available'}) { - return &mt('Directory search unavailable in domain: [_1]',$srch->{'srchdomain'}); + return &mt('Institutional directory search unavailable in domain: [_1]',$srch->{'srchdomain'}); } if ($dom_inst_srch{'directorysrch'}{'localonly'}) { if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) { - return &mt('Directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'}); + return &mt('Insitutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'}); } my @usertypes = split(/:/,$env{'environment.inststatus'}); if (!@usertypes) { @@ -2510,7 +2443,7 @@ sub build_search_response { $state = 'modify'; $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}); } 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 this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}).''; if ($srch->{'srchin'} ne 'alc') { $forcenewuser = 1; my $cansrchinst = 0; @@ -2532,7 +2465,7 @@ sub build_search_response { } } } - $response .= '
'.&mt("To add as a new user:").''.&mt("Note: you can only create new users in the domain of your current role -".$env{'request.role.domain'}).'

'; + $response .= '
'.&mt("To add as a new user:").''.&mt("Note: you can only create new users in the domain of your current role - [_1]",$env{'request.role.domain'}).'

'; } } }