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

raeburn raeburn at source.lon-capa.org
Mon Jun 14 12:40:45 EDT 2021


raeburn		Mon Jun 14 16:40:45 2021 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  - Integration with MSU campus information systems
    - Values in Record_Type field in RO_CLIFMS view changing from single digit
      to two-letter codes for Fall 2021 onwards
    - Add missing paren in changes in rev. 1.74
    - Housekeeping for database handle changes in rev. 1.75  
  
  
-------------- next part --------------
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.77 modules/msu/localenroll.pm:1.78
--- modules/msu/localenroll.pm:1.77	Wed Jun  9 16:11:08 2021
+++ modules/msu/localenroll.pm	Mon Jun 14 16:40:45 2021
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.77 2021/06/09 16:11:08 raeburn Exp $
+# $Id: localenroll.pm,v 1.78 2021/06/14 16:40:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -75,7 +75,6 @@
     $ENV{SYBASE} = '/usr/local/freetds';
     if ($type eq 'SISCS') {
         $datfile = 'autoenrollnew.dat';
-        delete($ENV{SYBASE});
     } elsif ($type eq 'LC') {
         $datfile = 'autoenrollmsu.dat';
     }
@@ -107,7 +106,7 @@
             $dbflag = 0;
         } else {
             if (defined($dbh)) {
-                unless ($type eq 'SISCS') {
+                if (($type eq 'SIS') || ($type eq 'RO')) {
                     $dbh->do('SET ANSI_NULLS ON');
                     $dbh->do('SET ANSI_WARNINGS ON');
                 }
@@ -120,7 +119,7 @@
 
 sub disconnect_DB() {
     my $dbh = shift;
-    $dbh->disconnect;    
+    $dbh->disconnect;
 }
 
 sub write_class_data {
@@ -320,12 +319,21 @@
             $term =~tr/a-z/A-Z/;
             $subj =~tr/a-z/A-Z/;
             $crse =~tr/a-z/A-Z/;
+            my $recordtype;
+            if (($yr > 21) || (($yr == 21) && ($sem eq 'fs'))) {
+                $recordtype = qq(Record_Type='PI' OR Record_Type='SI' OR Record_Type ='GA');
+            } else {
+                $recordtype = qq(Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9');
+            }
             if (!$dbflag) {
                 ($dbh,$dbflag) = &connect_DB('RO');
             }
+            if (!$dbflaglc) {
+                ($dbhlc,$dbflaglc) = &connect_DB('LC');
+            }
             if ($dbflag) {
 # Check if owner is in CLIFMS for this course
-                my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$owner' AND (Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9')");
+                my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$owner' AND ($recordtype)");
                 if ($clifmscount > 0) {
                     if ($dbflaglc) {
 	       	        my $loncount = $dbhlc->selectrow_array("SELECT count(*) FROM LONCAPA WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$owner'");
@@ -355,7 +363,7 @@
                         }
                         if (@netids > 0) {
                             foreach my $coowner (@netids) { 
-                                my $clifmscoowner = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$coowner' AND (Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9')");
+                                my $clifmscoowner = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$coowner' AND ($recordtype)");
                                 if ($clifmscoowner > 0) {
                                     if ($dbflaglc) {
                                         my $loncoowner = $dbhlc->selectrow_array("SELECT count(*) FROM LONCAPA WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND MSUNetID='$coowner'");
@@ -428,11 +436,13 @@
                 if ($disconnect) {
                     &disconnect_DB($dbh);
                 }
+	    } else {
+                $outcome = "Inclusion of enrollment could not be established, because a connection to the Registrar's database failed.\n";
+            }
+            if ($dbflaglc) {
                 if ($disconnectlc) {
                     &disconnect_DB($dbhlc);
                 }
-	    } else {
-                $outcome = "Inclusion of enrollment could not be established, because a connection to the Registrar's database failed.\n";
             }
         } else {
             $outcome = "Inclusion of enrollment could not be established because $course_id is not a valid MSU course section.";
@@ -540,6 +550,12 @@
         $subj =~tr/a-z/A-Z/;
         $crse =~tr/a-z/A-Z/;
         $term =~tr/a-z/A-Z/;
+        my $recordtype;
+        if (($yr > 21) || (($yr == 21) && ($sem eq 'fs'))) {
+            $recordtype = qq(Record_Type='PI' OR Record_Type='SI' OR Record_Type ='GA');
+        } else {
+            $recordtype = qq(Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9');
+        }
         my ($dbh,$dbflag,$database);
         if ($owner ne '') {
             my ($ownername,$ownerdom) = split(':',$owner);
@@ -550,7 +566,7 @@
                     if ($dbflag) {
 # Check if instructor is in CLIFMS for this course
                         eval {
-                            my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND MSUNetID='$ownername' AND (Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9')");
+                            my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND MSUNetID='$ownername' AND ($recordtype)");
                             if ($clifmscount > 0) {
                                 $outcome = 'valid';
                             }
@@ -1007,8 +1023,12 @@
     my $pidcount = 0;
     my $blankcount = 0;
     if ($class =~ m/^([suf]s\d{2})(\w{2,4})(\d{3,4}\w?)(\d{3})$/) {
+        my ($term,$subj,$crse,$sec) = ($1,$2,$3,$4);
+        $term =~tr/a-z/A-Z/;
+        $subj =~tr/a-z/A-Z/;
+        $crse =~tr/a-z/A-Z/;
         eval {
-            my $sth = $dbh->prepare("SELECT Pid,Pilot_Id FROM RO_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4'  ORDER BY Pid");
+            my $sth = $dbh->prepare("SELECT Pid,Pilot_Id FROM RO_ClassList WHERE Term_Code = '$term' AND Subj_Code = '$subj' AND Crse_Code = '$crse' AND Sctn_Code = '$sec' ORDER BY Pid");
             $sth->execute();
             while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
                 $pid =~ s/^1(\d{8})$/A$1/;
@@ -1074,12 +1094,13 @@
             $person = $1;
             my $ownerdom = $2;
             next if ($ownerdom ne $dom);
-        } elsif (defined($person) && $person ne '') {
-            $person .= ':'.$dom;
         }
         if (defined($person) && $person ne '') {
             if ($class =~ m/^([suf]s\d{2})(\w{2,4})(\d{3,4}\w?)(\d{3})$/) {
                 my ($semyr,$subj,$crs,$sec) = ($1,$2,$3,$4);
+                $semyr =~tr/a-z/A-Z/;
+                $subj =~tr/a-z/A-Z/;
+                $crs =~tr/a-z/A-Z/;
 # Check if section exists in LONCAPA table.
                 if (!$dbflaglc) {
                     ($dbhlc,$dbflaglc) = &connect_DB('LC');
@@ -1155,12 +1176,19 @@
     my ($term,$subj,$crse,$sec,$dbh) = @_;
     my @in_clifms;
     if ($dbh) {
-        my $statement = "SELECT MSUNetID FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND (Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9')";
+        my $recordtype;
+        my ($sem,$yr) = ($term =~ /^([suf]s)(\d{2})$/);
+        if (($yr > 21) || (($yr == 21) && ($sem eq 'fs'))) {
+            $recordtype = qq(Record_Type='PI' OR Record_Type='SI' OR Record_Type ='GA');
+        } else {
+            $recordtype = qq(Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9');
+        }
+        my $statement = "SELECT MSUNetID FROM RO_CLIFMS WHERE Term_Code='$term' AND Subj_Code='$subj' AND Crse_Code='$crse' AND Sctn_Code='$sec' AND ($recordtype)";
         my $sth = $dbh->prepare("$statement");
         $sth->execute();
         while ( my ($uname) = $sth->fetchrow_array ) {
             next unless ($uname =~ /^\w{2,8}$/); 
-            unless (grep(/^\Q$uname\E$/, at in_clifms) {
+            unless (grep(/^\Q$uname\E$/, at in_clifms)) {
                 push(@in_clifms,$uname);
             }
         }


More information about the LON-CAPA-cvs mailing list