[LON-CAPA-cvs] cvs: loncom /enrollment Autoenroll.pl

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 11 Dec 2003 03:24:20 -0000


raeburn		Wed Dec 10 22:24:20 2003 EDT

  Modified files:              
    /loncom/enrollment	Autoenroll.pl 
  Log:
  Added e-mailing of usernames and passwords to new accounts if e-mail addresses provided for the new users, or to the course owner via a LON-CAPA message if no e-mail addresses available.
  
  
Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.3 loncom/enrollment/Autoenroll.pl:1.4
--- loncom/enrollment/Autoenroll.pl:1.3	Tue Dec  9 15:06:37 2003
+++ loncom/enrollment/Autoenroll.pl	Wed Dec 10 22:24:20 2003
@@ -1,30 +1,4 @@
 #!/usr/bin/perl
-#
-#Automated enroll script
-# $Id: Autoenroll.pl,v 1.3 2003/12/09 20:06:37 albertel Exp $
-#
-# Copyright Michigan State University Board of Trustees
-#
-# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
-#
-# LON-CAPA is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# LON-CAPA is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with LON-CAPA; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-# /home/httpd/html/adm/gpl.txt
-#
-# http://www.lon-capa.org/
-#
 
     use strict;
     use lib '/home/httpd/lib/perl';
@@ -39,7 +13,7 @@
 # Determine the library server's domain
     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
     my $dom = $$perlvarref{'lonDefDomain'};
-    my $tmpdir = $$perlvarref{'lonDaemons'}.'/tmp';
+    my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log';
     $ENV{'user.domain'} = $dom;
 
 # Determine the present time;
@@ -49,7 +23,6 @@
     my %courses = &Apache::lonnet::courseiddump($dom,'.',1); 
     my %affiliates = ();
     my %enrollvar = ();
-    my %logmsg = ();
     my %reply = ();
     my %LC_code = ();
     foreach my $key (sort keys %courses) {
@@ -113,17 +86,18 @@
     &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
 
 # Now go through classes and perform required enrollment changes.
+    open (my $fh,">>$logfile");
+    print $fh "********************\n".localtime(time)." Enrollment messages start --\n";
     foreach my $crs (sort keys %enrollvar) {
+        my $logmsg = '';
+        my $newusermsg = '';
         if ($reply{$crs} > 0) {
             if (($enrollvar{$crs}{autostart} < $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
                 if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
-                    my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},\@{$affiliates{$crs}},\%{$LC_code{$crs}},\$logmsg{$crs},'automated');
-                    my $logfile = $crs."_enrollment_log.txt";
-                    open (FILE,">>$tmpdir/$logfile");
-                    print FILE "********************\n".localtime(time)." Enrollment messages start --\n";
-                    print FILE "$logmsg{$crs}\n";
-                    print FILE "-- ".localtime(time)." Enrollment messages end\n********************\n\n"; 
-                    close (FILE);
+                    my ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$enrollvar{$crs}{autoadds},$enrollvar{$crs}{autodrops},$enrollvar{$crs}{startdate},$enrollvar{$crs}{enddate},$enrollvar{$crs}{authtype},$enrollvar{$crs}{autharg},\@{$affiliates{$crs}},\%{$LC_code{$crs}},\$logmsg,\$newusermsg,'automated');
+                    print $fh "Messages start for $crs\n";
+                    print $fh "$logmsg\n";
+                    print $fh "Messages end for $crs\n";
                     if ($changecount > 0) {
                         unless ($enrollvar{$crs}{notifylist}  eq '') {
 # Send message about enrollment changes to notifylist.
@@ -134,6 +108,10 @@
 
                                 my $subject = "Student enrollment changes in $enrollvar{$crs}{coursecode}";
                                 my $message = "The following $changecount change(s) occurred in $enrollvar{$crs}{description} - $enrollvar{$crs}{coursecode} as a result of the automated classlist update:\n\n".$response;
+                                unless ($newusermsg eq '') 
+                                {
+                                   $message .= "\n".$newusermsg;
+                                }
                                 my @to_notify = ();
                                 if ($enrollvar{$crs}{notifylist} =~ m/,/) {
                                     @to_notify = split/,/,$enrollvar{$crs}{notifylist};
@@ -144,6 +122,10 @@
                                     my ($ccname,$ccdom) = split/@/,$cc;
                                     my $status =  &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
                                 }
+                                if ( ($enrollvar{$crs}{notifylist} eq '') && ($newusermsg ne '') ) {
+                                     my $subject = "New user accounts in  $enrollvar{$crs}{'coursecode'}";
+                                     my $status =  &Apache::lonmsg::user_normal_msg($ENV{'user.name'},$dom,$subject,$newusermsg);
+                                }
                                 delete($ENV{'user.name'});
                                 delete($ENV{'user.home'});
                             }
@@ -152,9 +134,11 @@
                 }
             }
         } else {
-            print STDERR "No institutional classlist data could be retrieved for $crs\n";
+            print $fh "No institutional classlist data could be retrieved for $crs\n";
         }
     }
+    print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n";
+    close($fh);
     delete($ENV{'user.domain'});
 
 # Check for photos