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

raeburn raeburn@source.lon-capa.org
Sat, 25 Jul 2009 16:56:12 -0000


raeburn		Sat Jul 25 16:56:12 2009 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  - New routine &validate_instcode() used to check if institutional code exists
   - checks in CLIFMS if optional course owner's MSUNet ID is provided
   - otherwise checks in SISCRSS.
  
  - &possible_instcodes()
    - takes additional argument - $code_order - ref to ARRAY which is populated with list of code compenents in the order they should be combined to create instcode.
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.40 modules/msu/localenroll.pm:1.41
--- modules/msu/localenroll.pm:1.40	Thu Jun 11 20:09:25 2009
+++ modules/msu/localenroll.pm	Sat Jul 25 16:56:12 2009
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.40 2009/06/11 20:09:25 raeburn Exp $
+# $Id: localenroll.pm,v 1.41 2009/07/25 16:56:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -262,7 +262,7 @@
 sub validate_courseID {
     my ($course_id,$dom) = @_;
     my $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 $term = $1;
         my $subj = $2;
         my $crse = $3;
@@ -296,6 +296,69 @@
     return $outcome;
 }
 
+sub validate_instcode {
+    my ($dom,$instcode,$owner) = @_;
+    my $outcome = '';
+    if ($instcode =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)$/) {
+        my $term = $1;
+        my $subj = $2;
+        my $crse = $3;
+        $subj =~tr/a-z/A-Z/;
+        $crse =~tr/a-z/A-Z/;
+        $term =~tr/a-z/A-Z/;
+        my ($dbh,$dbflag,$database);
+        if (defined($owner)) {
+            if ($owner =~ /^\w{2,8}$/) {
+                $database = 'RO';
+                ($dbh,$dbflag) = &connect_DB($database);
+                if ($dbflag) {
+# Check if instructor is in CLIFMS for this course
+                    eval {
+                        my $clifmscount = $dbh->selectrow_array("SELECT count(*) FROM RO_CLIFMS_VIEW WHERE Term_Code='$sem' AND Subj_Code='$subj' AND Crse_Code='$crse' AND MSUNetID='$owner' AND (Record_Type='1' OR Record_Type='2' OR Record_Type ='3' OR Record_Type = '9')");
+                        if ($clifmscount > 0) {
+                            $outcome = 'ok';
+                        } 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 SIS database, so the course number could not be validated.";
+                    }
+                }
+            } else {
+                $outcome = "The username provided for the course owner did conform to the format used for MSU NetIDs.";
+            }
+        } else {
+            $database = 'SIS';  
+            ($dbh,$dbflag) = &connect_DB('SIS');
+            if ($dbflag) {
+                eval {
+                    my $quotedsubj = $dbh5->quote($subj);
+                    my $quotedcrse = $dbh4->quote($crse);
+                    my $quotedterm = $dbh4->quote($term);
+                    my $count = $dbh4->selectrow_array( "SELECT count(*) FROM SISCRSS WHERE Subj_Code = $quotedsubj AND Crse_Code= $quotedcrse AND Sctn_Term_Code =$quotedterm ");
+                    if ($count > 0) {
+                        $outcome = 'ok';
+                    } else {
+                        $outcome = "There was no match in the MSU $database database to the combination of semester ($term), subject ($subj), course number ($crse) you entered.";
+                    }
+                };
+                if ($@) {
+                    $outcome = "There was a problem connecting to the SIS database, so the course number could not be validated.";
+                }
+            }
+        }
+        if ($dbflag) {
+            &disconnect_DB($dbh);
+        } else {
+            $outcome = "There was a problem connecting to the $database database, so the course number could not be validated.";
+        }
+    } else {
+        $outcome = "One or more of the combination of semester, year, subject and course number you provided do not conform to the format used at MSU.";
+    }
+    return $outcome;
+}
+
 sub create_password {
     my ($authparam,$dom) = @_;
     my $authchk = 'ok';
@@ -331,8 +394,9 @@
 }
 
 sub possible_instcodes {
-    my ($dom,$codetitles,$cat_titles,$cat_order) = @_;
+    my ($dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
     @{$codetitles} = ("Year","Semester","Department","Number");
+    @{$code_order} = ("Semester","Year","Department","Number");
     %{$$cat_titles{'Semester'}} = (
                    fs => 'Fall',
                    ss => 'Spring',