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

raeburn raeburn@source.lon-capa.org
Tue, 11 Jan 2011 21:53:33 -0000


raeburn		Tue Jan 11 21:53:33 2011 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  - Update LONCAPA table in RO_ClassList for any co-owners with 
    faculty/supervisor status for a specific semester, course, section
    instance.
  - Access to enrollment data for sections in team taught courses in cases 
    where the owner is not instructor of record, but a co-owner is.
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.53 modules/msu/localenroll.pm:1.54
--- modules/msu/localenroll.pm:1.53	Sun Jun  6 01:07:52 2010
+++ modules/msu/localenroll.pm	Tue Jan 11 21:53:32 2011
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.53 2010/06/06 01:07:52 raeburn Exp $
+# $Id: localenroll.pm,v 1.54 2011/01/11 21:53:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -109,8 +109,20 @@
   my $pilotcount = 0;
   my $blankcount = 0;
   my $owner = &get_owner($dom,$crs);
+  my @coowners = &get_coowners($dom,$crs);
   foreach my $class (@{$coursesref}) {
+      my $canuse = 0;
       if (&check_section($class,$owner,$dom,$dbh) eq 'ok') {
+          $canuse = 1;
+      } elsif (@coowners > 0) {
+          foreach my $coowner (@coowners) {
+              if (&check_section($class,$coowner,$dom,$dbh) eq 'ok') {
+                  $canuse = 1;
+                  last;
+              }
+          }
+      }
+      if ($canuse) {
           my $xmlfile = $xmlstem.$class."_classlist.xml";
           open(FILE, ">$xmlfile");
           print FILE qq|<?xml version="1.0" encoding="UTF-8"?>
@@ -208,7 +220,7 @@
 }
 
 sub new_course {
-    my ($course_id,$owner,$dom) = @_;
+    my ($course_id,$owner,$dom,$coowners) = @_;
     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.";
@@ -246,7 +258,33 @@
                     }
                     $outcome = 'ok';
 	        } else {
-                    $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 ($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;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    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.";
+                    }
                 }
                 &disconnect_DB($dbh);
 	    } else {
@@ -513,16 +551,44 @@
     return $owner;
 }
 
+sub get_coowners {
+    my ($dom,$crs) = @_;
+    my @coowners;
+    if (defined($dom) && defined($crs)) {
+        my %settings = &Apache::lonnet::get('environment',['internal.co-owners'],$dom,$crs);
+        if (defined($settings{'internal.co-owners'}))  {
+            if ($settings{'internal.co-owners'} =~ /,/) {
+                @coowners = split(/,/,$settings{'internal.co-owners'});
+            } else {
+                @coowners = ($settings{'internal.co-owners'});
+            }
+        }
+    }
+    return @coowners;
+}
+
 sub institutional_photos {
     my ($dom,$crs,$affiliates,$result,$action,$students) = @_;
     my $outcome;
     if ($action eq 'update') {
         my ($dbh,$dbflag) = &connect_DB('RO');
         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') {
+                    $canuse = 1; 
+                } elsif (@coowners > 0) {
+                    foreach my $coowner (@coowners) {
+                        if (&check_section($class,$coowner,$dom,$dbh) eq 'ok') {
+                            $canuse = 1;
+                            last;
+                        }
+                    }
+                }
+                if ($canuse) {
                     my $pidcount = 0;
                     my $blankcount = 1;
                     my $maxtries = 5;
@@ -532,7 +598,7 @@
                                                          $class,\%stuinfo);
                         $numtries ++;
                     }
-                }
+                } 
             }
             &disconnect_DB($dbh);
             foreach my $pid (sort(keys(%stuinfo))) {