[LON-CAPA-cvs] cvs: modules /msu localenroll.pm
raeburn
raeburn at source.lon-capa.org
Sat Jun 5 11:27:59 EDT 2021
raeburn Sat Jun 5 15:27:59 2021 EDT
Modified files:
/modules/msu localenroll.pm
Log:
- Integration with MSU campus information systems.
If course owner or co-owner is a department administrator, and is not
also a designated instructor or the semester instance of the course section,
populate the LONCAPA table with username(s) of designated instructors.
-------------- next part --------------
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.73 modules/msu/localenroll.pm:1.74
--- modules/msu/localenroll.pm:1.73 Sat Jun 5 15:03:01 2021
+++ modules/msu/localenroll.pm Sat Jun 5 15:27:59 2021
@@ -1,6 +1,6 @@
# functions to glue school database system into Lon-CAPA for
# automated enrollment
-# $Id: localenroll.pm,v 1.73 2021/06/05 15:03:01 raeburn Exp $
+# $Id: localenroll.pm,v 1.74 2021/06/05 15:27:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,7 +51,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);
$numtries ++;
}
$$replyref{$crs} = $pilotcount;
@@ -137,6 +137,39 @@
}
}
}
+ unless ($canuse) {
+ # Check if the owner or any of the co-owner(s) is a Dept. Administrator
+ my $check_clifms;
+ if ($class =~ m/^([suf]s)(\d{2})(\w{2,4})(\d{3,4}\w?)(\d{3})$/) {
+ my ($sem,$yr,$subj,$crse,$sec) = ($1,$2,$3,$4,$5);
+ $sem =~tr/a-z/A-Z/;
+ $subj =~tr/a-z/A-Z/;
+ $crse =~tr/a-z/A-Z/;
+ my ($check_clifms,$error);
+ if (&is_dept_administrator($sem,$yr,$subj,$crse,$owner,$dbh,\$error)) {
+ $check_clifms = 1;
+ } elsif (@coowners) {
+ foreach my $coowner (@coowners) {
+ if (&is_dept_administrator($sem,$yr,$subj,$crse,$owner,$dbh,\$error)) {
+ $check_clifms = 1;
+ last;
+ }
+ }
+ }
+ if ($check_clifms) {
+ 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;
+ }
+ $canuse = 1;
+ }
+ }
+ }
+ }
if ($canuse) {
my $xmlfile = $xmlstem.$class."_classlist.xml";
open(FILE, ">$xmlfile");
@@ -320,21 +353,12 @@
}
}
unless ($outcome eq 'ok') {
-# is owner or co-owner a department administrator?
- my $seqid = &semyr_to_seqid($term,$sem,$yr);
- my $admincount = 0;
- my $adminsth = $dbh->prepare("SELECT Start_Term_Seq_Id,End_Term_Seq_Id FROM LONCAPA_DeptAdministrators WHERE subj_code = '$subj' AND crse_code = '$crse' AND PilotID = '$owner'");
- $adminsth->execute();
- while (my($start_seqid,$end_seqid) = $adminsth->fetchrow_array ) {
- $start_seqid =~ s/^0//;
- $end_seqid =~ s/^0//;
- if (($seqid >= $start_seqid) &&
- ($seqid <= $end_seqid)) {
- $admincount ++;
- }
- }
- $adminsth->finish;
- if ($admincount > 0) {
+ my ($check_clifms,$error);
+#
+# is the owner or any co-owners not in CLIFMS for this term, subject, course, section instance
+# 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') ");
@@ -345,30 +369,29 @@
} else {
if (@netids > 0) {
foreach my $coowner (@netids) {
- $admincount = 0;
- my $admincosth = $dbh->prepare("SELECT Start_Term_Seq_Id,End_Term_Seq_Id FROM LONCAPA_DeptAdministrators WHERE subj_code = '$subj' AND crse_code = '$crse' AND PilotID = '$coowner'");
- $admincosth->execute();
- while (my($start_seqid,$end_seqid) = $admincosth->fetchrow_array ) {
- $start_seqid =~ s/^0//;
- $end_seqid =~ s/^0//;
- if (($seqid >= $start_seqid) &&
- ($seqid <= $end_seqid)) {
- $admincount ++;
- }
- }
- $admincosth->finish;
- if ($admincount > 0) {
+ 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') ");
- $sthcoad->execute;
- $sthcoad->finish;
+ $sthcoad->execute;
+ $sthcoad->finish;
+ }
}
$outcome = 'ok';
}
}
}
}
+ 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;
+ }
+ }
+ }
}
unless ($outcome eq 'ok') {
if (@netids > 0) {
@@ -511,29 +534,14 @@
}
unless ($outcome eq 'valid') {
# Check if instructor is a Dept. Administrator
- eval {
- my $seqid = &semyr_to_seqid($term,$sem,$yr);
- my $admincount = 0;
- my $adminsth = $dbh->prepare("SELECT Start_Term_Seq_Id,End_Term_Seq_Id FROM LONCAPA_DeptAdministrators WHERE subj_code = '$subj' AND crse_code = '$crse' AND PilotID = '$ownername'");
- $adminsth->execute();
- while (my($start_seqid,$end_seqid) = $adminsth->fetchrow_array ) {
- $start_seqid =~ s/^0//;
- $end_seqid =~ s/^0//;
- if (($seqid >= $start_seqid) &&
- ($seqid <= $end_seqid)) {
- $admincount ++;
- }
- }
- $adminsth->finish;
- if ($admincount > 0) {
- $outcome = 'valid';
- }
- };
- if ($@) {
- $outcome = "There was a problem connecting to the DepartmentAdministrators database, so the course number could not be validated.";
+ my $error;
+ if (&is_dept_administrator($sem,$yr,$subj,$crse,$ownername,$dbh,\$error)) {
+ $outcome = 'valid';
+ } elsif ($error) {
+ $outcome = $error;
}
}
- unless ($outcome eq 'valid') {
+ unless ($outcome) {
$outcome = "There was no match in the MSU $database database to the combination of semester ($term), subject ($subj), course number ($crse) for the specified owner ($ownername).";
}
}
@@ -1061,6 +1069,56 @@
return $sectioncheck;
}
+sub is_dept_administrator {
+ my ($sem,$yr,$subj,$crse,$owner,$dbh,$error) = @_;
+ my $outcome;
+ my $term = $sem.$yr;
+ if ($dbh) {
+ eval {
+ my $seqid = &semyr_to_seqid($term,$sem,$yr);
+ my $admincount = 0;
+ my $adminsth = $dbh->prepare("SELECT Start_Term_Seq_Id,End_Term_Seq_Id FROM LONCAPA_DeptAdministrators WHERE subj_code = '$subj' AND crse_code = '$crse' AND PilotID = '$owner'");
+ $adminsth->execute();
+ while (my($start_seqid,$end_seqid) = $adminsth->fetchrow_array ) {
+ $start_seqid =~ s/^0//;
+ $end_seqid =~ s/^0//;
+ if (($seqid >= $start_seqid) &&
+ ($seqid <= $end_seqid)) {
+ $admincount ++;
+ }
+ }
+ $adminsth->finish;
+ if ($admincount > 0) {
+ $outcome = 'valid';
+ }
+ };
+ if ($@) {
+ if (ref($error)) {
+ $$error = "There was a problem connecting to the DepartmentAdministrators database.";
+ }
+ }
+ }
+ return $outcome;
+}
+
+sub get_inst_instructors {
+ my ($term,$subj,$crse,$sec,$dbh) = @_;
+ my @in_clifms;
+ if ($dbh) {
+ my $statement = "SELECT MSUNetID FROM RO_CLIFMS_VIEW 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 $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) {
+ push(@in_clifms,$uname);
+ }
+ }
+ $sth->finish;
+ }
+ return @in_clifms;
+}
+
sub instcode_defaults {
my ($dom,$defaults,$code_order) = @_;
%{$defaults} = (
More information about the LON-CAPA-cvs
mailing list