[LON-CAPA-cvs] cvs: modules /msu localenroll.pm
raeburn
raeburn at source.lon-capa.org
Fri Mar 9 17:09:48 EST 2012
raeburn Fri Mar 9 22:09:48 2012 EDT
Modified files:
/modules/msu localenroll.pm
Log:
- Customization for MSU
- Course requests from MSU faculty/staff with Dept. Administrator status
(i.e., users with access to all classlists for a particular subject code)
will be validated, and access will be available to enrollment data in
courses they request.
-------------- next part --------------
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.55 modules/msu/localenroll.pm:1.56
--- modules/msu/localenroll.pm:1.55 Sun Mar 6 02:42:11 2011
+++ modules/msu/localenroll.pm Fri Mar 9 22:09:48 2012
@@ -1,6 +1,6 @@
# functions to glue school database system into Lon-CAPA for
# automated enrollment
-# $Id: localenroll.pm,v 1.55 2011/03/06 02:42:11 raeburn Exp $
+# $Id: localenroll.pm,v 1.56 2012/03/09 22:09:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -237,53 +237,118 @@
$outcome = "Inclusion of enrollment could not be established for the course section $course_id because the username of the owner contains invalid characters.";
return $outcome;
}
- if ($course_id =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
+ if ($course_id =~ 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/;
+ my $yr = $2;
+ my $subj = $3;
+ my $crse = $4;
+ my $sec = $5;
+ my $term = $sem.$yr;
+ $term =~tr/a-z/A-Z/;
$subj =~tr/a-z/A-Z/;
$crse =~tr/a-z/A-Z/;
my ($dbh,$dbflag) = &connect_DB('RO');
if ($dbflag) {
-# Check if instructor is in CLIFMS for this course
- my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW WHERE Term_Code='$sem' 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')");
+# 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='$sem' 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 ('$sem','$subj','$crse','$sec','$owner') ");
+ 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;
}
$outcome = 'ok';
- } else {
- if ($coowners ne '') {
- my @coowned = split(/,/,$coowners);
- if (@coowned > 0) {
- foreach my $item (@coowned) {
- if ($item =~ /^([^:]+):([^:]+)$/) {
- my $coowner = $1;
- my $coownerdom = $2;
- if (($coowner !~ /\W/) && ($coownerdom eq $dom)) {
- my $clifmscoowner = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW WHERE Term_Code='$sem' 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='$sem' 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 ('$sem','$subj','$crse','$sec','$coowner') ");
- $sthco->execute;
- $sthco->finish;
- }
- $outcome = 'ok';
- last;
+ }
+ if ($coowners ne '') {
+ my @netids = ();
+ my @coowned = split(/,/,$coowners);
+ if (@coowned > 0) {
+ foreach my $item (@coowned) {
+ if ($item =~ /^([^:]+):([^:]+)$/) {
+ my $coowner = $1;
+ my $coownerdom = $2;
+ if (($coowner !~ /\W/) && ($coownerdom eq $dom)) {
+ # Is co-owner in CLIFMS for course?
+ unless (grep(/^\Q$coowner\E$/, at netids)) {
+ push (@netids,$coowner);
+ }
+ }
+ }
+ }
+ if (@netids > 0) {
+ 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;
+ }
+ $outcome = 'ok';
+ }
+ }
+ }
+ }
+ unless ($outcome eq 'ok') {
+# is owner or co-owner a department administrator?
+ my $seq_id = &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) = $sth->fetchrow_array ) {
+ $start_seqid =~ s/^0//;
+ $end_seqid =~ s/^0//;
+ if (($seqid >= $start_seqid) &&
+ ($seqid <= $end_seqid)) {
+ $admincount ++;
+ }
+ }
+ $adminsth->finish;
+ if ($admincount > 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 $sthad = $dbh->prepare("INSERT INTO LONCAPA (Term_Code, Subj_Code, Crse_Code, Sctn_Code, MSUNetId) VALUES ('$term','$subj','$crse','$sec','$coowner') ");
+ $sthad->execute;
+ $sthad->finish;
+ }
+ $outcome = 'ok';
+ } 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) = $sth->fetchrow_array ) {
+ $start_seqid =~ s/^0//;
+ $end_seqid =~ s/^0//;
+ if (($seqid >= $start_seqid) &&
+ ($seqid <= $end_seqid)) {
+ $admincount ++;
+ }
+ }
+ $admincosth->finish;
+ if ($admincount > 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='$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;
}
+ $outcome = 'ok';
}
}
}
}
}
unless ($outcome eq 'ok') {
- $outcome = "Inclusion of enrollment could not be established for the course section $course_id because the owner of this LON-CAPA course ($owner) is not included in CLIFMS as instructional faculty for the requested semester, course and section. Please contact the administrator of the department that controls course $course_id and ask for $owner to be added as faculty or supervisor.";
+ if (@netids > 0) {
+ my $coownstr = join(',', at netids);
+ $outcome = "Inclusion of enrollment could not be established for the course section $course_id because neither the owner ($owner) or co-owners ($coownstr) of this LON-CAPA course are not included in CLIFMS as instructional faculty for the requested semester, course and section. Please contact the administrator of the department that controls course $course_id and ask for $owner to be added as faculty or supervisor.";
+ } else {
+ $outcome = "Inclusion of enrollment could not be established for the course section $course_id because the owner ($owner) of this LON-CAPA course is not included in CLIFMS as instructional faculty for the requested semester, course and section. Please contact the administrator of the department that controls course $course_id and ask for $owner to be added as faculty or supervisor.";
+ }
}
}
&disconnect_DB($dbh);
@@ -297,6 +362,38 @@
return $outcome;
}
+sub semyr_to_seqid {
+ my ($term,$sem,$yr) = @_;
+ my $seq_id = '';
+ if ($term eq 'ss00') {
+ $seqid = '996';
+ } else {
+ my %semids = (
+ us => '2',
+ fs => '4',
+ ss => '6',
+ );
+ unless ($yr =~ /^9/){
+ $seqid = '1';
+ }
+ if ($sem eq 'ss') {
+ my $seqyr;
+ if ($yr == 10) {
+ $seqyr = '09';
+ } elsif ($yr =~ /^0(\d)$/) {
+ $seqyr = '0'. $1 - 1;
+ } else {
+ $seqyr = $yr - 1;
+ }
+ $seqid .= $seqyr;
+ } else {
+ $seqid .= $yr;
+ }
+ $seqid .= $semids{$sem};
+ }
+ return $seqid;
+}
+
sub validate_courseID {
my ($course_id,$dom) = @_;
my $outcome = '';
@@ -365,14 +462,39 @@
my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW 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')");
if ($clifmscount > 0) {
$outcome = 'valid';
- } else {
- $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 ($owner).";
}
};
if ($@) {
$outcome = "There was a problem connecting to the CLIFMS database, so the course number could not be validated.";
}
- }
+ unless ($outcome eq 'valid') {
+# Check if instructor is a Dept. Administrator
+ eval {
+ my $seq_id = &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) = $sth->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.";
+ }
+ }
+ unless ($outcome eq 'valid') {
+ $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 ($owner).";
+ }
+ }
} else {
$outcome = "The username provided for the course owner did not conform to the format used for MSU NetIDs.";
}
More information about the LON-CAPA-cvs
mailing list