[LON-CAPA-cvs] cvs: loncom / lond lonsql /enrollment Autoenroll.pl /interface loncreatecourse.pm lonmodifycourse.pm lonpopulate.pm /lonnet/perl lonnet.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 08 Jun 2004 22:09:45 -0000


This is a MIME encoded message

--raeburn1086732585
Content-Type: text/plain

raeburn		Tue Jun  8 18:09:45 2004 EDT

  Modified files:              
    /loncom	lond lonsql 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/interface	lonpopulate.pm loncreatecourse.pm 
                     	lonmodifycourse.pm 
    /loncom/enrollment	Autoenroll.pl 
  Log:
  Changes to support autoenroll calls from a remote server.
  
  lond on the homeserver for the course(s) handles requests from the remote
  server for institutional data (e.g., classlists, valid institutional courseIDs,
  institutional section numbers for a course code, validation of course owners), by
  calling the appropriate functions in the homeserver's localenroll.pm
  
  All replies are made directly with the exception of fetch_enrollment_query, which
  is shipped over to lonsql, in case retrieval of institutional classlists is a
  protracted process.
  
  lonsql on the homeserver for the course(s) calls localenroll::fetch_enrollment()
  and writes XML files of enrollment data to /home/httpd/perl/tmp
   
  Transfer of classlist data occurs later following an autoretrieve call from the 
  remote server. It is planned to generalize this function and add encryption to the transfer back to the client.
  
  Autoenroll.pl called by cron on a library server, now only carries out updates for
  courses in its domain, for which the library server is the course's homeserver. If a domain has multiple library servers Autoenroll.pl will need to be run on each library server. 
  
  
--raeburn1086732585
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040608180945.txt"

Index: loncom/lond
diff -u loncom/lond:1.192 loncom/lond:1.193
--- loncom/lond:1.192	Tue Jun  1 05:58:30 2004
+++ loncom/lond	Tue Jun  8 18:09:44 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.192 2004/06/01 09:58:30 foxr Exp $
+# $Id: lond,v 1.193 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,6 +45,7 @@
 use Authen::Krb5;
 use lib '/home/httpd/lib/perl/';
 use localauth;
+use localenroll;
 use File::Copy;
 use LONCAPA::ConfigFileEdit;
 
@@ -53,7 +54,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.192 $'; #' stupid emacs
+my $VERSION='$Revision: 1.193 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -2532,7 +2533,7 @@
 		    }
 # ------------------------------------------------------------------- querysend
 		} elsif ($userinput =~ /^querysend/) {
-		    if(isClient) {
+		    if (isClient) {
 			my ($cmd,$query,
 			    $arg1,$arg2,$arg3)=split(/\:/,$userinput);
 			$query=~s/\n*$//g;
@@ -2863,6 +2864,78 @@
 		    } else {
 			print $client "refused\n";
 		    }
+#------------------------------- is auto-enrollment enabled?
+                } elsif ($userinput =~/^autorun/) {
+                    if (isClient) {
+                        my $outcome = &localenroll::run();
+                        print $client "$outcome\n";
+                    } else {
+                        print $client "0\n";
+                    }
+#------------------------------- get official sections (for auto-enrollment).
+                } elsif ($userinput =~/^autogetsections/) {
+                    if (isClient) {
+                        my ($cmd,$coursecode)=split(/:/,$userinput);
+                        my @secs = &localenroll::get_sections($coursecode);
+                        my $seclist = &escape(join(':',@secs));
+                        print $client "$seclist\n";
+                    } else {
+                        print $client "refused\n";
+                    }
+#----------------------- validate owner of new course section (for auto-enrollment).
+                } elsif ($userinput =~/^autonewcourse/) {
+                    if (isClient) {
+                        my ($cmd,$course_id,$owner)=split(/:/,$userinput);
+                        my $outcome = &localenroll::new_course($course_id,$owner);
+                        print $client "$outcome\n";
+                    } else {
+                        print $client "refused\n";
+                    }
+#-------------- validate course section in schedule of classes (for auto-enrollment).
+                } elsif ($userinput =~/^autovalidatecourse/) {
+                    if (isClient) {
+                        my ($cmd,$course_id)=split(/:/,$userinput);
+                        my $outcome=&localenroll::validate_courseID($course_id);
+                        print $client "$outcome\n";
+                    } else {
+                        print $client "refused\n";
+                    }
+#--------------------------- create password for new user (for auto-enrollment).
+                } elsif ($userinput =~/^autocreatepassword/) {
+                    if (isClient) {
+                        my ($cmd,$authparam)=split(/:/,$userinput);
+                        my ($create_passwd,$authchk) = @_;
+                        ($authparam,$create_passwd,$authchk) = &localenroll::create_password($authparam);
+                        print $client &escape($authparam.':'.$create_passwd.':'.$authchk)."\n";
+                    } else {
+                        print $client "refused\n";
+                    }
+#---------------------------  read and remove temporary files (for auto-enrollment).
+                } elsif ($userinput =~/^autoretrieve/) {
+                    if (isClient) {
+                        my ($cmd,$filename) = split(/:/,$userinput);
+                        my $source = $perlvar{'lonDaemons'}.'/tmp/'.$filename;
+                        if ( (-e $source) && ($filename ne '') ) {
+                            my $reply = '';
+                            if (open(my $fh,$source)) {
+                                while (<$fh>) {
+                                    chomp($_);
+                                    $_ =~ s/^\s+//g;
+                                    $_ =~ s/\s+$//g;
+                                    $reply .= $_;
+                                }
+                                close($fh);
+                                print $client &escape($reply)."\n";
+#                                unlink($source);
+                            } else {
+                                print $client "error\n";
+                            }
+                        } else {
+                            print $client "error\n";
+                        }
+                    } else {
+                        print $client "refused\n";
+                    }
 # ------------------------------------------------------------- unknown command
 
 		} else {
Index: loncom/lonsql
diff -u loncom/lonsql:1.61 loncom/lonsql:1.62
--- loncom/lonsql:1.61	Thu May 20 10:15:29 2004
+++ loncom/lonsql	Tue Jun  8 18:09:44 2004
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.61 2004/05/20 14:15:29 matthew Exp $
+# $Id: lonsql,v 1.62 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,6 +115,7 @@
 use Tie::RefHash;
 use DBI;
 use File::Find;
+use localenroll;
 
 ########################################################
 ########################################################
@@ -406,6 +407,23 @@
                     $result='no_such_file';
                 }
                 # end of log query
+            } elsif ($query eq 'fetchenrollment') {
+                # retrieve institutional class lists
+                my $dom = &unescape($arg1);
+                my %affiliates = ();
+                my %replies = ();
+                my $locresult = '';
+                my $querystr = &unescape($arg3);
+                foreach (split/%%/,$querystr) {
+                    if (/^(\w+)=([^=]+)$/) {
+                        @{$affiliates{$1}} = split/,/,$2;
+                    }
+                }
+                $locresult = &localenroll::fetch_enrollment($dom,\%affiliates,\%replies);
+                $result = &escape($locresult.':');
+                if ($locresult) {
+                    $result .= &escape(join(':',map{$_.'='.$replies{$_}} keys %replies));
+                }
             } else {
                 # Do an sql query
                 $result = &do_sql_query($query,$arg1,$arg2);
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.505 loncom/lonnet/perl/lonnet.pm:1.506
--- loncom/lonnet/perl/lonnet.pm:1.505	Fri May 28 13:33:41 2004
+++ loncom/lonnet/perl/lonnet.pm	Tue Jun  8 18:09:44 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.505 2004/05/28 17:33:41 albertel Exp $
+# $Id: lonnet.pm,v 1.506 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1615,21 +1615,22 @@
 }
 
 sub courseiddump {
-    my ($domfilter,$descfilter,$sincefilter)=@_;
+    my ($domfilter,$descfilter,$sincefilter,$hostid)=@_;
     my %returnhash=();
     unless ($domfilter) { $domfilter=''; }
     foreach my $tryserver (keys %libserv) {
-	if ((!$domfilter) || ($hostdom{$tryserver} eq $domfilter)) {
-	    foreach (
-             split(/\&/,&reply('courseiddump:'.$hostdom{$tryserver}.':'.
+        if (($hostid && $tryserver eq $hostid) || (!$hostid)) {
+	    if ((!$domfilter) || ($hostdom{$tryserver} eq $domfilter)) {
+	        foreach (
+                 split(/\&/,&reply('courseiddump:'.$hostdom{$tryserver}.':'.
 			       $sincefilter.':'.&escape($descfilter),
                                $tryserver))) {
-		my ($key,$value)=split(/\=/,$_);
-                if (($key) && ($value)) {
-		    $returnhash{&unescape($key)}=&unescape($value);
+		    my ($key,$value)=split(/\=/,$_);
+                    if (($key) && ($value)) {
+		        $returnhash{&unescape($key)}=&unescape($value);
+                    }
                 }
             }
-
         }
     }
     return %returnhash;
@@ -3053,6 +3054,48 @@
     return get_query_reply($queryid);
 }
 
+# ------- Request retrieval of institutional classlists from course homerserver
+
+sub fetch_enrollment_query {
+    my ($homeserver,$dom,$affiliatesref,$replyref) = @_;
+    my $host=$hostname{$homeserver};
+    my $cmd = '';
+    foreach (keys %{$affiliatesref}) {
+        $cmd .= $_.'='.join(",",@{$$affiliatesref{$_}}).'%%'; 
+    }
+    $cmd =~ s/%%$//;
+    $cmd = &escape($cmd);
+    my $query = 'fetchenrollment';
+    my $queryid=&reply("querysend:".$query.':'.$dom.':'.$ENV{'user.name'}.':'.$cmd,$homeserver);
+    unless ($queryid=~/^\Q$host\E\_/) { return 'error: '.$queryid; }
+    my $reply = &get_query_reply($queryid);
+    unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
+        unless ($homeserver eq $perlvar{'lonHostID'}) {
+            my @responses = split/:/,$reply;
+            my $pathname = $perlvar{'lonDaemons'}.'/tmp';
+            foreach (@responses) {
+                my ($key,$value) = split/=/,$_;
+                $$replyref{$key} = $value;
+                if ($value > 0) {
+                    foreach (@{$$affiliatesref{$key}}) {
+                        my $filename = $dom.'_'.$key.'_'.$_.'_classlist.xml';
+                        my $destname = $pathname.'/'.$filename;
+                        my $xml_classlist = &reply("autoretrieve:".$filename,$homeserver);
+                        unless ($xml_classlist =~ /^error/) {
+                            if ( open(FILE,">$destname") ) {
+                                print FILE &unescape($xml_classlist);
+                                close(FILE);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return 'ok';
+    }
+    return 'error';
+}
+
 sub get_query_reply {
     my $queryid=shift;
     my $replyfile=$perlvar{'lonDaemons'}.'/tmp/'.$queryid;
@@ -3097,6 +3140,49 @@
     return &log_query($uname,$udom,'userlog',%filters);
 }
 
+#--------- Call auto-enrollment subs in localenroll.pm for homeserver for course 
+
+sub auto_run {
+    my $homeserver = shift;
+    my $response = &reply('autorun',$homeserver);
+    return $response;
+}
+                                                                                   
+sub auto_get_sections {
+    my ($homeserver,$coursecode) = @_;
+    my @secs = ();
+    my $response=&unescape(&reply('autogetsections:'.$coursecode,$homeserver));
+    unless ($response eq 'refused') {
+        @secs = split/:/,$response;
+    }
+    return @secs;
+}
+                                                                                   
+sub auto_new_course {
+    my ($homeserver,$course_id,$owner) = @_;
+    my $response=&unescape(&reply('autonewcourse:'.$course_id.':'.$owner,$homeserver));
+    return $response;
+}
+                                                                                   
+sub auto_validate_courseID {
+    my ($homeserver,$course_id) = @_;
+    my $response=&unescape(&reply('autovalidatecourse:'.$course_id,$homeserver));
+    return $response;
+}
+                                                                                   
+sub auto_create_password {
+    my ($homeserver,$authparam) = @_;
+    my $create_passwd = 0;
+    my $authchk = '';
+    my $response=&unescape(&reply('autocreatepassword:'.$authparam,$homeserver));
+    if ($response eq 'refused') {
+        $authchk = 'refused';
+    } else {
+        ($authparam,$create_passwd,$authchk) = split/:/,$response;
+    }
+    return ($authparam,$create_passwd,$authchk);
+}
+
 # ------------------------------------------------------------------ Plain Text
 
 sub plaintext {
Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.11 loncom/interface/lonpopulate.pm:1.12
--- loncom/interface/lonpopulate.pm:1.11	Fri Apr 16 09:26:44 2004
+++ loncom/interface/lonpopulate.pm	Tue Jun  8 18:09:44 2004
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.11 2004/04/16 13:26:44 albertel Exp $
+# $Id: lonpopulate.pm,v 1.12 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -207,7 +207,7 @@
 ###############################################################
 
 sub print_main_frame {
-  my ($r,$realm,$dom,$crs,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$tasktitleref,$homeserver,$server) = @_;
   my $action = "information";
   if (exists($ENV{'form.action'}) ) {
       $action = $ENV{'form.action'};
@@ -641,7 +641,8 @@
             </form> 
       ");
   } elsif ($action eq "sections") {
-      my @sections = &localenroll::get_sections($enrollvar{coursecode});
+      my @sections = ();
+      @sections = &Apache::lonnet::auto_get_sections($homeserver,$enrollvar{coursecode});
       my @storedsections = ();
       my @currsections = ();
       my %sec_id = ();
@@ -1156,7 +1157,7 @@
 }
 
 sub print_crosslistings_menu () {
-  my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
   my @currxlists = ();
   my @xlists = ();
@@ -1259,7 +1260,7 @@
 }
 
 sub print_crosslistings_response () {
-  my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currxlists = ();
   my @xlists = ();
@@ -1289,14 +1290,24 @@
           my $xl = "newcross_".$i;
           my $gp = "newgroupid_".$i;
           if ( exists($ENV{"form.$xl"}) ) {
-              my $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"});
+              my $coursecheck = '';
+#              if ($homeserver eq $server) {
+#                  $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"});
+#              } else {
+                  $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$ENV{"form.$xl"});
+#              }
               if ($coursecheck eq 'ok') {
-                  my $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner);
+                  my $addcheck = '';
+#                  if ($homeserver eq $server) {
+#                      $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner);
+#                  } else {
+                      $addcheck = &Apache::lonnet::auto_new_course($homeserver,$ENV{"form.$xl"},$owner);
+#                  }
                   if ($addcheck eq 'ok') {
                      push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                   } else {
                      push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
-                  } 
+                  }
               } else {
                   push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck;
               }
@@ -1371,7 +1382,7 @@
 }
 
 sub print_sections_menu () {
-  my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currsections = ();
   my @sections = ();
@@ -1410,9 +1421,19 @@
                   $seccount ++;
               } else {
                   my $newsec = $coursecode.$ENV{"form.$secnum"};
-                  my $coursecheck = &localenroll::validate_courseID($newsec);
+                  my $coursecheck = '';
+#                  if ($homeserver eq $server) {
+#                      $coursecheck = &localenroll::validate_courseID($newsec);
+#                  } else  {
+                      $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
+#                  }
                   if ($coursecheck eq 'ok') {
-                      my $addcheck = &localenroll::new_course($newsec,$owner);
+                      my $addcheck = '';
+#                      if ($homeserver eq $server) {
+#                          $addcheck = &localenroll::new_course($newsec,$owner);
+#                      } else {
+                          $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
+#                      }
                       if ($addcheck eq 'ok') {
                           push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                           $seccount ++;
@@ -1555,7 +1576,7 @@
 }
 
 sub print_sections_response () {
-  my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currsections = ();
   my @sections = ();
@@ -1587,9 +1608,19 @@
           if ( exists($ENV{"form.$sec"}) ) {
               unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) {
                   my $newsec = $coursecode.$ENV{"form.$sec"};
-                  my $coursecheck = &localenroll::validate_courseID($newsec);
+                  my $coursecheck = '';
+#                  if ($homeserver eq $server) {
+#                      $coursecheck = &localenroll::validate_courseID($newsec);
+#                  } else {
+                      $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
+#                  }
                   if ($coursecheck eq 'ok') {
-                      my $addcheck = &localenroll::new_course($newsec,$owner);
+                      my $addcheck = '';
+#                      if ($homeserver eq $server) {
+#                          $addcheck = &localenroll::new_course($newsec,$owner);
+#                      } else {
+                          $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
+#                      }
                       if ($addcheck eq 'ok') {
                           push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                       } else {
@@ -1691,7 +1722,7 @@
 }
 
 sub print_update_result () {
-  my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my $response = '';
   my $updateadds = 0;
   my $updatedrops = 0;
@@ -1763,7 +1794,11 @@
 
       if (@allcourses > 0) {
           @{$affiliates{$crs}} = @allcourses;
-          &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
+#          if ($homeserver eq $server) {
+#              &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
+#          } else {
+              &Apache::lonnet::fetch_enrollment_query($homeserver,$dom,\%affiliates,\%reply);
+#          }
           if ($reply{$crs} > 0) {
               ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
           } else {
@@ -2004,6 +2039,10 @@
             }
         }
     }
+
+# Determine course home server and current server
+    my $homeserver = &Apache::lonnet::homeserver($crs,$dom);
+    my $server = $Apache::lonnet::perlvar{'lonHostID'};
   
     my $reply = 0;
     unless ($state eq "choose") { $reply = 1; }
@@ -2012,7 +2051,7 @@
     &print_navmenu($r,\@tasks,\%tasklong);
     
     if (($state eq "choose") || ($action eq "information")) {
-        &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
+        &print_main_frame($r,$realm,$dom,$crs,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "chgsettings") {
         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "setdates") {
@@ -2020,17 +2059,17 @@
     } elsif ($action eq "notify") {
         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "sections") {
-        &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
+        &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "crosslist") {
-        &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
+        &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "updatenow") {
-        &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
+        &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "photos") {
         &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "newcross") {
-        &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
+        &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);    
     } elsif ($action eq "newsections") {
-        &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
+        &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     }
     &print_doc_base($r);  
     return OK;
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.57 loncom/interface/loncreatecourse.pm:1.58
--- loncom/interface/loncreatecourse.pm:1.57	Tue May 11 02:02:58 2004
+++ loncom/interface/loncreatecourse.pm	Tue Jun  8 18:09:44 2004
@@ -1,7 +1,7 @@
-# The LearningOnline Network
+#meserver The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.57 2004/05/11 06:02:58 albertel Exp $
+# $Id: loncreatecourse.pm,v 1.58 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -479,6 +479,7 @@
 sub create_course {
     my $r=shift;
     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
+    my $this_server = $Apache::lonnet::perlvar{'lonHostID'};
     my $ccuname=$ENV{'form.ccuname'};
     my $ccdomain=$ENV{'form.ccdomain'};
     $ccuname=~s/\W//g;
@@ -627,7 +628,7 @@
     if (@affiliates > 0) {
         my @badclasses = ();
         foreach my $class (@affiliates) {
-            my $addcheck =  &localenroll::new_course($class,$cenv{'internal.courseowner'});
+            my $addcheck = &Apache::lonnet::auto_new_course($crsuhome,$class,$cenv{'internal.courseowner'});
             unless ($addcheck eq 'ok') {
                 push @badclasses, $class; 
             }
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.6 loncom/interface/lonmodifycourse.pm:1.7
--- loncom/interface/lonmodifycourse.pm:1.6	Wed Dec 31 13:32:23 2003
+++ loncom/interface/lonmodifycourse.pm	Tue Jun  8 18:09:44 2004
@@ -197,7 +197,7 @@
 	        } else {
 	            $enrollvar{$1} = localtime($settings{$item});
 	        }
-            } else {
+            } elsif ($1 eq "courseowner" || $1 eq "authtype" || $1 eq "autharg" || $1 eq "sectionnums" || $1 eq "coursecode") {
 	        $enrollvar{$1} = $settings{$item};
             }
         }
@@ -425,6 +425,8 @@
     my ($r,$tasklongref,$typeref) = @_;
     my $dom = $ENV{'user.domain'};
     my $crs = $ENV{'form.course'};
+    my $homeserver = &Apache::lonnet::homeserver($crs,$dom);
+    my $server = $Apache::lonnet::perlvar{'lonHostID'};
 
     unless ( &check_course($dom,$crs) eq 'ok' ) {
         &print_header($r,$tasklongref);
@@ -550,9 +552,9 @@
 	                    foreach my $sec (@sections) {
 		                if ($sec =~ m/^(.+):/) {
 		                    my $course_id = $newattr{'coursecode'}.$1;
-			            my $course_check = &localenroll::validate_courseID($course_id);
-			            if ($course_check eq 'ok') {  
-                                        my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
+                                    my $course_check = &Apache::lonnet::auto_validate_courseID($homeserver,$course_id);
+			            if ($course_check eq 'ok') {
+                                        my $outcome = &Apache::lonnet::auto_new_course($homeserver,$course_id,$newattr{'courseowner'});
 			                unless ($outcome eq 'ok') { 
 				            $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $outcome.<br/>");
 			                }
@@ -567,7 +569,7 @@
                             foreach my $sec (@sections) {
                                 if ($sec =~ m/^(.+):/) {
                                     my $course_id = $newattr{'coursecode'}.$1;
-                                    my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
+                                    my $outcome = &Apache::lonnet::auto_new_course($homeserver,$course_id,$newattr{'courseowner'});
                                     unless ($outcome eq 'ok') {
                                         $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $outcome.<br/>");
                                     }
@@ -582,7 +584,7 @@
 	            if ( (@xlists > 0) && ($changeowner) ) {
 	                foreach my $xlist (@xlists) {
 		            if ($xlist =~ m/^(.+):/) {
-                                my $outcome = &localenroll::new_course($1,$newattr{'courseowner'});
+                                my $outcome = &Apache::lonnet::auto_new_course($homeserver,$1,$newattr{'courseowner'});
 		                unless ($outcome eq 'ok') {
 			            $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for crosslisted class: ").$1.&mt(" for the following reason: $outcome.<br/>");
 		                }
Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.8 loncom/enrollment/Autoenroll.pl:1.9
--- loncom/enrollment/Autoenroll.pl:1.8	Thu Mar 18 14:40:39 2004
+++ loncom/enrollment/Autoenroll.pl	Tue Jun  8 18:09:44 2004
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 #Automated Enrollment script
-# $Id: Autoenroll.pl,v 1.8 2004/03/18 19:40:39 raeburn Exp $
+# $Id: Autoenroll.pl,v 1.9 2004/06/08 22:09:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,17 +39,18 @@
 #only run if configured to
     if (! &localenroll::run()) { exit; }
 
-# Determine the library server's domain
+# Determine the library server's domain and hostID
     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
     my $dom = $$perlvarref{'lonDefDomain'};
     my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log';
     $ENV{'user.domain'} = $dom;
+    my $hostid = $$perlvarref{'lonHostID'};
 
 # Determine the present time;
     my $timenow = time();
 
 # Determine the courses
-    my %courses = &Apache::lonnet::courseiddump($dom,'.',1); 
+    my %courses = &Apache::lonnet::courseiddump($dom,'.',1,$hostid); 
     my %affiliates = ();
     my %enrollvar = ();
     my %reply = ();
@@ -112,7 +113,7 @@
             }
         }
     }
-    &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
+    my $outcome = &Apache::lonnet::fetch_enrollment_query($hostid,$dom,\%affiliates,\%reply);
 
 # Now go through classes and perform required enrollment changes.
     open (my $fh,">>$logfile");

--raeburn1086732585--