--- loncom/interface/loncreateuser.pm	2007/08/16 21:36:13	1.174
+++ 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.174 2007/08/16 21:36:13 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.177 2007/08/25 19:52:29 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1472,7 +1472,7 @@ sub update_user_data {
     <th>$lt{'lst'}</th>
     <th>$lt{'gen'}</th>
     <th>$lt{'mail'}</th>
-    <th>$lt{'disk'}<th></tr>
+    <th>$lt{'disk'}</th></tr>
 <tr><td>$lt{'prvs'}</td>
     <td>$userenv{'firstname'}  </td>
     <td>$userenv{'middlename'} </td>
@@ -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'},