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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 26 Aug 2008 07:04:37 -0000


raeburn		Tue Aug 26 03:04:37 2008 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  check_section() returns 'ok' if owner is affiliated with section.
  MSU NetIDs are 2 - 8 characters
  write_class_data() needs to split class into semyear, subjext, coursenumber and section. 
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.38 modules/msu/localenroll.pm:1.39
--- modules/msu/localenroll.pm:1.38	Tue Aug 26 01:01:35 2008
+++ modules/msu/localenroll.pm	Tue Aug 26 03:04:35 2008
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.38 2008/08/26 05:01:35 raeburn Exp $
+# $Id: localenroll.pm,v 1.39 2008/08/26 07:04:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -110,33 +110,41 @@
   my $blankcount = 0;
   my $owner = &get_owner($dom,$crs);
   foreach my $class (@{$coursesref}) {
-      if (&check_section($class,$owner,$dom,$dbh) > 0) {
+      if (&check_section($class,$owner,$dom,$dbh) eq 'ok') {
           my $xmlfile = $xmlstem.$class."_classlist.xml";
           open(FILE, ">$xmlfile");
           print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE text>
 <students>
 |;
-          my $sth = $dbh->prepare("SELECT Pid,Pilot_Id,Student_Name FROM LONCAPA_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4'  ORDER BY Student_Name");
-          $sth->execute();
-          while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
-              if ($pilot =~ m/^\w{1,8}$/) {
-                  $pilotcount ++;
-                  $name =~ s/^\s//g;
-                  $name =~ s/\s$//g;
-                  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/) {
-                      $first = substr($given,0,index($given," "));
-                      $middle = substr($given,index($given," ")+1);
-                      $middle =~ s/\s//g;
-                  } else {
-                      $first = $given;
-                  }
-                  $first =~ s/\s$//g;
-                  print FILE qq| <student username="$pilot">
+          if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
+              my $sem = $1;
+              my $subj = $2;
+              my $crse = $3;
+              my $sec = $4;
+              $sem =~tr/a-z/A-Z/;
+              $subj =~tr/a-z/A-Z/;
+              $crse =~tr/a-z/A-Z/;
+              my $sth = $dbh->prepare("SELECT Pid,Pilot_Id,Student_Name FROM LONCAPA_ClassList WHERE Term_Code = '$sem' AND Subj_Code = '$subj' AND Crse_Code = '$crse' AND Sctn_Code = '$sec'  ORDER BY Student_Name");
+              $sth->execute();
+              while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
+                  if ($pilot =~ m/^\w{2,8}$/) {
+                      $pilotcount ++;
+                      $name =~ s/^\s//g;
+                      $name =~ s/\s$//g;
+                      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/) {
+                          $first = substr($given,0,index($given," "));
+                          $middle = substr($given,index($given," ")+1);
+                          $middle =~ s/\s//g;
+                      } else {
+                          $first = $given;
+                      }
+                      $first =~ s/\s$//g;
+                      print FILE qq| <student username="$pilot">
   <autharg>MSU.EDU</autharg>
   <authtype>krb4</authtype>
   <email>$pilot\@msu.edu</email>
@@ -150,16 +158,17 @@
   <studentID>$pid</studentID>
  </student>
 |;
-              } elsif ($pilot eq '') {
-                  $blankcount ++;
-              }
+                  } elsif ($pilot eq '') {
+                      $blankcount ++;
+                  }
 # Format for startdate is YYYY:MM:DD:HH:MM:SS
 # Format forenddate is YYYY:MM:DD:HH:MM:SS
 # Authentication is one of: krb4, krb5, int or loc
 # Password is either the password for int, or Kerberos domain (for krb4 or krb5), or argument (for loc).
 # If authentication, password, startdate or enddate are blank, the default for the course is used.  These defaults can be modified using the Automated Enrollment Manager.
+              }
+              $sth->finish;
           }
-          $sth->finish;
           print FILE qq|</students>|;
           close(FILE);
       }
@@ -342,7 +351,7 @@
         if ($dbflag) {
             my %stuinfo;
             foreach my $class (@{$$affiliates{$crs}}) {
-                if (&check_section($class,$owner,$dom,$dbh) > 0) {
+                if (&check_section($class,$owner,$dom,$dbh) eq 'ok') {
                     my $pidcount = 0;
                     my $blankcount = 1;
                     my $maxtries = 5;
@@ -426,7 +435,7 @@
 
 sub check_section {
     my ($class,$owner,$dom,$dbh) = @_;
-    my $sectioncheck = 0;
+    my $sectioncheck;
     my $dbflag = 0;
     my @owners = split(/,/,$owner);
     foreach my $person (@owners) {