--- loncom/interface/loncreateuser.pm 2007/08/16 21:16:39 1.173 +++ loncom/interface/loncreateuser.pm 2007/08/26 15:31:03 1.178 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.173 2007/08/16 21:16:39 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.178 2007/08/26 15:31:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1446,7 +1446,7 @@ sub update_user_data { $changeHash{'middlename'} = $env{'form.cmiddlename'}; $changeHash{'lastname'} = $env{'form.clastname'}; $changeHash{'generation'} = $env{'form.cgeneration'}; - $changeHash{'permanentemail'} = $env{'form.permanentemail'}; + $changeHash{'permanentemail'} = $env{'form.cpermanentemail'}; my $putresult = &Apache::lonnet::put ('environment',\%changeHash, $env{'form.ccdomain'},$env{'form.ccuname'}); @@ -1472,7 +1472,7 @@ sub update_user_data { $lt{'lst'} $lt{'gen'} $lt{'mail'} - $lt{'disk'} + $lt{'disk'} $lt{'prvs'} $userenv{'firstname'} $userenv{'middlename'} @@ -2194,14 +2194,16 @@ sub user_search_result { my %inst_matches; my %srch_results; my ($response,$state,$forcenewuser); + $srch->{'srchterm'} =~ s/^\s+//; + $srch->{'srchterm'} =~ s/\s+$//; - if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) { + 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 '') { @@ -2215,8 +2217,10 @@ sub user_search_result { } if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') || ($srch->{'srchin'} eq 'alc')) { - if ($srch->{'srchterm'} !~ /^$match_username$/) { - $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); + if ($srch->{'srchby'} eq 'uname') { + if ($srch->{'srchterm'} !~ /^$match_username$/) { + $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); + } } } if ($srch->{'srchin'} eq 'instd') { @@ -2270,7 +2274,17 @@ sub user_search_result { 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', @@ -2305,6 +2319,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'}, @@ -2314,6 +2330,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)) { @@ -2323,7 +2341,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'}, @@ -2393,7 +2419,8 @@ sub directorysrch_check { 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') { @@ -2405,11 +2432,20 @@ sub directorysrch_check { } } 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('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$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('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}}); + } } } }