[LON-CAPA-cvs] cvs: modules /msu localenroll.pm

raeburn raeburn@source.lon-capa.org
Thu, 25 Mar 2010 04:06:16 -0000


raeburn		Thu Mar 25 04:06:16 2010 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  - Use similar strategy for extracting middle name from a given names field,
    as is used for classlist data, when query_user_tables() and ldap_search()
    to retrieve user data from HR tables/LDAP for:
    (a) individual user search
    (b) Autoupdate.pl
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.47 modules/msu/localenroll.pm:1.48
--- modules/msu/localenroll.pm:1.47	Mon Feb 22 21:18:14 2010
+++ modules/msu/localenroll.pm	Thu Mar 25 04:06:16 2010
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.47 2010/02/22 21:18:14 raeburn Exp $
+# $Id: localenroll.pm,v 1.48 2010/03/25 04:06:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -130,20 +130,20 @@
               while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
                   if ($pilot =~ m/^\w{2,8}$/) {
                       $pilotcount ++;
-                      $name =~ s/^\s//g;
-                      $name =~ s/\s$//g;
+                      $name =~ s/^\s+//;
+                      $name =~ s/\s+$//;
                       my ($last,$given,$first,$middle);
                       $last = substr($name,0,index($name,","));
                       $given = substr($name,index($name,",")+1);
                       $given =~ s/^\s//g;
-                      if ($given =~ m/\w\s\w/) {
+                      if ($given =~ m/\w\s+\w/) {
                           $first = substr($given,0,index($given," "));
                           $middle = substr($given,index($given," ")+1);
                           $middle =~ s/\s//g;
                       } else {
                           $first = $given;
                       }
-                      $first =~ s/\s$//g;
+                      $first =~ s/\s+$//;
                       print FILE qq| <student username="$pilot">
   <autharg>MSU.EDU</autharg>
   <authtype>krb4</authtype>
@@ -800,8 +800,19 @@
             my $statement = "SELECT MSUNetID,Pid,FirstName,LastName,Person_Type FROM $table $condition";
             my $sth = $dbh->prepare("$statement");
             $sth->execute();
-            while ( my($uname,$pid,$first,$last,$type) = $sth->fetchrow_array ) {
+            while ( my($uname,$pid,$given,$last,$type) = $sth->fetchrow_array ) {
                 $pid=lc($pid);
+                $given =~ s/^\s+//;
+                my ($first,$middle);
+                if ($given =~ m/\w\s+\w/) {
+                    $first = substr($given,0,index($given," "));
+                    $middle = substr($given,index($given," ")+1);
+                    $middle =~ s/^\s+//g;
+                    $middle =~ s/\s+$//g;
+                } else {
+                    $first = $given;
+                }
+                $first =~ s/\s+$//;
                 if (ref($instusers->{$uname}) eq 'HASH') {
                     if (ref($instusers->{$uname}{'inststatus'}) eq 'ARRAY') {
                         if (!grep(/^$type$/,@{$instusers->{$uname}{'inststatus'}})) {
@@ -835,11 +846,12 @@
                         }
                     }
                 } else {
-                    $instusers->{$uname} = {firstname => $first,
-                                           lastname => $last,
-                                           id => $pid,
-                                           permanentemail => $uname.'@msu.edu',
-                                           inststatus => [$type],
+                    $instusers->{$uname} = {firstname      =>  $first,
+                                            middlename     => $middle
+                                            lastname       => $last,
+                                            id             => $pid,
+                                            permanentemail => $uname.'@msu.edu',
+                                            inststatus => [$type],
                                          };
                 }
                 if (defined($instids->{$pid})) {
@@ -886,7 +898,18 @@
         foreach my $entry ($mesg->entries) {
             my $uname = $entry->get_value('uid');
             next if ($uname eq '');
-            my $first = $entry->get_value('givenName');
+            my $given = $entry->get_value('givenName');
+            $given =~ s/^\s+//;
+            my ($first,$middle);
+            if ($given =~ m/\w\s+\w/) {
+                $first = substr($given,0,index($given," "));
+                $middle = substr($given,index($given," ")+1);
+                $middle =~ s/^\s+//g;
+                $middle =~ s/\s+$//g;
+            } else {
+                $first = $given;
+            }
+            $first =~ s/\s+$//;
             my $last = $entry->get_value('sn');
             my $email = $entry->get_value('mail');
             my $type;
@@ -911,11 +934,12 @@
                     }
                 }
             } else {
-                $instusers->{$uname} = {firstname => $first,
-                                        lastname => $last,
-                                        id => '',
+                $instusers->{$uname} = {firstname      => $first,
+                                        middlename     => $middle,
+                                        lastname       => $last,
+                                        id             => '',
                                         permanentemail => $email,
-                                        inststatus => [$type],
+                                        inststatus     => [$type],
                                      };
             }
         }