--- loncom/interface/loncreateuser.pm 2007/08/25 17:46:24 1.176 +++ loncom/interface/loncreateuser.pm 2007/08/25 19:52:29 1.177 @@ -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.177 2007/08/25 19:52:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2203,7 +2203,7 @@ sub user_search_result { 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 '') { @@ -2274,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', @@ -2309,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'}, @@ -2318,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)) { @@ -2327,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'},