[LON-CAPA-cvs] cvs: modules /msu localenroll.pm
raeburn
raeburn at source.lon-capa.org
Sat Jun 5 11:54:30 EDT 2021
raeburn Sat Jun 5 15:54:30 2021 EDT
Modified files:
/modules/msu localenroll.pm
Log:
- Integration with MSU campus information systems
LONCAPA table moved from RO's database to a MySQL database on the LON-CAPA
library server.
-------------- next part --------------
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.74 modules/msu/localenroll.pm:1.75
--- modules/msu/localenroll.pm:1.74 Sat Jun 5 15:27:59 2021
+++ modules/msu/localenroll.pm Sat Jun 5 15:54:30 2021
@@ -1,6 +1,6 @@
# functions to glue school database system into Lon-CAPA for
# automated enrollment
-# $Id: localenroll.pm,v 1.74 2021/06/05 15:27:59 raeburn Exp $
+# $Id: localenroll.pm,v 1.75 2021/06/05 15:54:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,6 +43,7 @@
my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
my ($dbh,$dbflag) = &connect_DB('RO',$$configvars{'lonDaemons'});
+ my ($dbhlc,$dbflaglc) = &connect_DB('LC',$$configvars{'lonDaemons'});
if ($dbflag) {
foreach my $crs (sort keys %{$affiliatesref}) {
my $xmlstem = $$configvars{'lonDaemons'}.'/tmp/';
@@ -51,7 +52,7 @@
my $maxtries = 5;
my $numtries = 0;
while ( ($numtries < $maxtries) && ($blankcount > 0) ) {
- ($pilotcount,$blankcount) = &write_class_data($dbh,$xmlstem,\@{$$affiliatesref{$crs}},$dom,$crs);
+ ($pilotcount,$blankcount) = &write_class_data($dbh,$xmlstem,\@{$$affiliatesref{$crs}},$dom,$crs,$dbhlc);
$numtries ++;
}
$$replyref{$crs} = $pilotcount;
@@ -75,6 +76,8 @@
if ($type eq 'SISCS') {
$datfile = 'autoenrollnew.dat';
delete($ENV{SYBASE});
+ } elsif ($type eq 'LC') {
+ $datfile = 'autoenrollmsu.dat';
}
if (-e "$keydir/$datfile") {
if (open(my $fh,'<',"$keydir/$datfile")) {
@@ -92,6 +95,8 @@
$DB_PATH = "dbi:Sybase:server=msudata;database=HR";
} elsif ($type eq 'SISCS') {
$DB_PATH = 'dbi:Oracle://ebsprd390d.ais.msu.edu:1521/MSUEDW.EBSP.MSU.EDU';
+ } elsif ($type eq 'LC') {
+ $DB_PATH = "DBI:mysql:msuenroll";
}
my $dbh;
@@ -119,7 +124,7 @@
}
sub write_class_data {
- my ($dbh,$xmlstem,$coursesref,$dom,$crs) = @_;
+ my ($dbh,$xmlstem,$coursesref,$dom,$crs,$dbhlc) = @_;
$xmlstem .= $dom."_".$crs."_";
my $pilotcount = 0;
my $blankcount = 0;
@@ -127,11 +132,11 @@
my @coowners = &get_coowners($dom,$crs);
foreach my $class (@{$coursesref}) {
my $canuse = 0;
- if (&check_section($class,$owner,$dom,$dbh) eq 'ok') {
+ if (&check_section($class,$owner,$dom,$dbh,$dbhlc) eq 'ok') {
$canuse = 1;
} elsif (@coowners > 0) {
foreach my $coowner (@coowners) {
- if (&check_section($class,$coowner,$dom,$dbh) eq 'ok') {
+ if (&check_section($class,$coowner,$dom,$dbh,$dbhlc) eq 'ok') {
$canuse = 1;
last;
}
@@ -160,12 +165,14 @@
my $term = $sem.$yr;
my @instructors = &get_inst_instructors($term,$subj,$crse,$sec,$dbh);
if (@instructors) {
- foreach my $user (@instructors) {
- my $sth = $dbh->prepare("INSERT IGNORE INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$user') ");
- $sth->execute;
- $sth->finish;
+ if ($dbhlc) {
+ foreach my $user (@instructors) {
+ my $sth = $dbhlc->prepare("INSERT IGNORE INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$user') ");
+ $sth->execute;
+ $sth->finish;
+ }
+ $canuse = 1;
}
- $canuse = 1;
}
}
}
@@ -277,13 +284,19 @@
}
sub new_course {
- my ($course_id,$owner,$dom,$coowners,$dbh) = @_;
+ my ($course_id,$owner,$dom,$coowners,$dbh,$dbhlc) = @_;
my $dbflag = 0;
+ my $dbflaglc = 0;
my $disconnect = 1;
+ my $disconnectlc = 1;
if (defined($dbh)) {
$disconnect = 0;
$dbflag = 1;
}
+ if (defined($dbhlc)) {
+ $disconnectlc = 0;
+ $dbflaglc = 1;
+ }
my $outcome = '';
if ($owner eq '') {
$outcome = "Inclusion of enrollment could not be established for the course section $course_id because no owner was provided for this LON-CAPA course.";
@@ -313,11 +326,13 @@
# Check if owner is in CLIFMS for this course
my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW 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')");
if ($clifmscount > 0) {
- my $loncount = $dbh->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'");
- if ($loncount == 0) {
- my $sth = $dbh->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$owner') ");
- $sth->execute;
- $sth->finish;
+ 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'");
+ if ($loncount == 0) {
+ my $sth = $dbhlc->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$owner') ");
+ $sth->execute;
+ $sth->finish;
+ }
}
$outcome = 'ok';
}
@@ -341,11 +356,13 @@
foreach my $coowner (@netids) {
my $clifmscoowner = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW 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')");
if ($clifmscoowner > 0) {
- my $loncoowner = $dbh->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'");
- if ($loncoowner == 0) {
- my $sthco = $dbh->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$coowner') ");
- $sthco->execute;
- $sthco->finish;
+ 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'");
+ if ($loncoowner == 0) {
+ my $sthco = $dbhlc->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$coowner') ");
+ $sthco->execute;
+ $sthco->finish;
+ }
}
$outcome = 'ok';
}
@@ -359,20 +376,23 @@
# a department administrator for the subject and course number for the relevant time period.
#
if (&is_dept_administrator($sem,$yr,$subj,$crse,$owner,$dbh,\$error)) {
- my $loncount = $dbh->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'");
- if ($loncount == 0) {
- my $sthad = $dbh->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$owner') ");
- $sthad->execute;
- $sthad->finish;
+ 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'");
+ if ($loncount == 0) {
+ my $sthad = $dbhlc->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$owner') ");
+ $sthad->execute;
+ $sthad->finish;
+ }
}
$outcome = 'ok';
} else {
if (@netids > 0) {
foreach my $coowner (@netids) {
if (&is_dept_administrator($sem,$yr,$subj,$crse,$coowner,$dbh,\$error)) {
- my $loncount = $dbh->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'");
- if ($loncount == 0) {
- my $sthcoad = $dbh->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$coowner') ");
+ 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='$coowner'");
+ if ($loncount == 0) {
+ my $sthcoad = $dbhlc->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$coowner') ");
$sthcoad->execute;
$sthcoad->finish;
}
@@ -385,10 +405,12 @@
if ($outcome eq 'ok') {
my @instructors = &get_inst_instructors($term,$subj,$crse,$sec,$dbh);
if (@instructors) {
- foreach my $user (@instructors) {
- my $sth = $dbh->prepare("INSERT IGNORE INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$user') ");
- $sth->execute;
- $sth->finish;
+ if ($dbflaglc) {
+ foreach my $user (@instructors) {
+ my $sth = $dbhlc->prepare("INSERT IGNORE INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$user') ");
+ $sth->execute;
+ $sth->finish;
+ }
}
}
}
@@ -405,6 +427,9 @@
if ($disconnect) {
&disconnect_DB($dbh);
}
+ if ($disconnectlc) {
+ &disconnect_DB($dbhlc);
+ }
} else {
$outcome = "Inclusion of enrollment could not be established, because a connection to the Registrar's database failed.\n";
}
@@ -778,14 +803,18 @@
my ($owners,$cdom,$classes,$validated) = @_;
if ((ref($classes) eq 'HASH') && (ref($validated) eq 'HASH')) {
my ($dbh,$dbflag) = &connect_DB('RO');
+ my ($dbhlc,$dbflaglc) = &connect_DB('LC');
if ($dbflag) {
foreach my $class (keys(%{$classes})){
- if (&check_section($class,$owners,$cdom,$dbh) eq 'ok') {
+ if (&check_section($class,$owners,$cdom,$dbh,$dbhlc) eq 'ok') {
$validated->{$class} = 1;
}
}
&disconnect_DB($dbh);
}
+ if ($dbflaglc) {
+ &disconnect_DB($dbhlc);
+ }
}
return 'ok';
}
@@ -920,17 +949,18 @@
my $outcome;
if ($action eq 'update') {
my ($dbh,$dbflag) = &connect_DB('RO');
+ my ($dbhlc,$dbflaglc) = &connect_DB('LC');
my $owner = &get_owner($dom,$crs);
my @coowners = &get_coowners($dom,$crs);
if ($dbflag) {
my %stuinfo;
foreach my $class (@{$$affiliates{$crs}}) {
my $canuse = 0;
- if (&check_section($class,$owner,$dom,$dbh) eq 'ok') {
+ if (&check_section($class,$owner,$dom,$dbh,$dbhlc) eq 'ok') {
$canuse = 1;
} elsif (@coowners > 0) {
foreach my $coowner (@coowners) {
- if (&check_section($class,$coowner,$dom,$dbh) eq 'ok') {
+ if (&check_section($class,$coowner,$dom,$dbh,$dbhlc) eq 'ok') {
$canuse = 1;
last;
}
@@ -961,6 +991,9 @@
}
$outcome = 'ok';
}
+ if ($dbflaglc) {
+ &disconnect_DB($dbhlc);
+ }
}
foreach my $type (keys(%{$result})) {
$$result{$type} =~ s/\&$//;
@@ -1019,14 +1052,20 @@
}
sub check_section {
- my ($class,$owner,$dom,$dbh) = @_;
+ my ($class,$owner,$dom,$dbh,$dbhlc) = @_;
my $sectioncheck;
my $dbflag = 0;
+ my $dbflaglc = 0;
my $disconnect = 1;
+ my $disconnectlc = 1;
if (defined($dbh)) {
$disconnect = 0;
$dbflag = 1;
}
+ if (defined($dbhlc)) {
+ $disconnectlc = 0;
+ $dbflaglc = 1;
+ }
my @owners = split(/,/,$owner);
foreach my $person (@owners) {
if ($person =~ /^([^:]+):([^:]+)$/) {
@@ -1040,9 +1079,9 @@
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);
# Check if section exists in LONCAPA table.
- if (!$dbflag) {
- ($dbh,$dbflag) = &connect_DB('RO');
- if (!$dbflag) {
+ if (!$dbflaglc) {
+ ($dbhlc,$dbflaglc) = &connect_DB('LC');
+ if (!$dbflaglc) {
return $sectioncheck;
}
}
@@ -1050,9 +1089,15 @@
"WHERE Term_Code = '$semyr' AND Subj_Code = '$subj' ".
"AND Crse_Code = '$crs' AND Sctn_Code = '$sec' ".
"AND MSUNetID = '$person'";
- $sectioncheck = $dbh->selectrow_array($statement);
+ $sectioncheck = $dbhlc->selectrow_array($statement);
if ($sectioncheck == 0) {
- my $outcome = &new_course($class,$person,$dom,undef,$dbh);
+ if (!$dbflag) {
+ ($dbh,$dbflag) = &connect_DB('RO');
+ if (!$dbflag) {
+ return $sectioncheck;
+ }
+ }
+ my $outcome = &new_course($class,$person,$dom,undef,$dbh,$dbhlc);
if ($outcome eq 'ok') {
$sectioncheck = 'ok';
}
@@ -1066,6 +1111,9 @@
if (($dbflag) && ($disconnect)) {
&disconnect_DB($dbh);
}
+ if (($dbflaglc) && ($disconnectlc)) {
+ &disconnect_DB($dbhlc);
+ }
return $sectioncheck;
}
More information about the LON-CAPA-cvs
mailing list