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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 03 Jan 2008 20:47:19 -0000


raeburn		Thu Jan  3 15:47:19 2008 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  - check_section() can check for access to a section by the course owner, and any co-owners.
  - backwards compatibility for course owners defined in pre-2.2 LON-CAPA, and not updataed since, (owner is username instead of username:domain).
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.32 modules/msu/localenroll.pm:1.33
--- modules/msu/localenroll.pm:1.32	Fri Nov  9 21:05:38 2007
+++ modules/msu/localenroll.pm	Thu Jan  3 15:47:17 2008
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.32 2007/11/10 02:05:38 raeburn Exp $
+# $Id: localenroll.pm,v 1.33 2008/01/03 20:47:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -427,34 +427,40 @@
     my ($class,$owner,$dom,$dbh) = @_;
     my $sectioncheck = 0;
     my $dbflag = 0;
-    if ($owner =~ /^([^:]+):([^:]+)$/) {
-        $owner = $1;
-        my $ownerdom = $2;
-        if ($ownerdom ne $dom) {
-            return $sectioncheck;
+    my @owners = split(/,/,$owner);
+    foreach my $person (@owners) {
+        if ($person =~ /^([^:]+):([^:]+)$/) {
+            $person = $1;
+            my $ownerdom = $2;
+            if ($ownerdom ne $dom) {
+                return $sectioncheck;
+            }
+        } elsif (defined($person) && $person ne '') {
+            $person .= ':'.$dom;
         }
-    }
-    if (defined($owner) && $owner ne '') {
-        if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
+        if (defined($person) && $person ne '') {
+            if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
 # Check if section exists in LONCAPA table.
-            if (!defined($dbh)) {
-                ($dbh,$dbflag) = &connect_DB('RO');
-                if (!$dbflag) {
-                    return $sectioncheck;
+                if (!defined($dbh)) {
+                    ($dbh,$dbflag) = &connect_DB('RO');
+                    if (!$dbflag) {
+                        return $sectioncheck;
+                    }
                 }
-            }
-            $sectioncheck = $dbh->selectrow_array(
-                                 "SELECT count(*) FROM LONCAPA ".
-                                 "WHERE Term_Code = '$1' AND Subj_Code = '$2' ".
-                                 "AND Crse_Code = '$3' AND Sctn_Code = '$4' ".
-                                 "AND MSUNetID = '$owner'");
-            if ($sectioncheck == 0) {
-                my $outcome = &new_course($class,$owner,$dom);
-                if ($outcome eq 'ok') {
+                $sectioncheck = $dbh->selectrow_array(
+                                     "SELECT count(*) FROM LONCAPA ".
+                                     "WHERE Term_Code = '$1' AND Subj_Code = '$2' ".
+                                     "AND Crse_Code = '$3' AND Sctn_Code = '$4' ".
+                                     "AND MSUNetID = '$person'");
+                if ($sectioncheck == 0) {
+                    my $outcome = &new_course($class,$person,$dom);
+                    if ($outcome eq 'ok') {
+                        $sectioncheck = 'ok';
+                    }
+                } elsif ($sectioncheck > 0) {
                     $sectioncheck = 'ok';
                 }
-            } elsif ($sectioncheck > 0) {
-                $sectioncheck = 'ok';
+                last if ($sectioncheck eq 'ok');
             }
         }
     }