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

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 08 Dec 2003 15:47:22 -0000


This is a MIME encoded message

--raeburn1070898442
Content-Type: text/plain

raeburn		Mon Dec  8 10:47:22 2003 EDT

  Modified files:              
    /loncom/enrollment	Autoenroll.pl 
  Log:
  Added notification to course coordinators when automated enrollment update results in enrollment changes. Added saving of logfiles. Changed calling of LONCAPA::Enrollment.pm to support crosslisted courses.
  
  
--raeburn1070898442
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20031208104722.txt"

Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.1 loncom/enrollment/Autoenroll.pl:1.2
--- loncom/enrollment/Autoenroll.pl:1.1	Fri Dec  5 12:08:09 2003
+++ loncom/enrollment/Autoenroll.pl	Mon Dec  8 10:47:22 2003
@@ -1,98 +1,136 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
 
-  use strict;
-  use lib '/home/httpd/lib/perl';
-  use localenroll;
-  use LONCAPA::Configuration;
-  use LONCAPA::Enrollment;
-  use Apache::lonnet;
-  use Apache::loncoursedata;
+    use strict;
+    use lib '/home/httpd/lib/perl';
+    use localenroll;
+    use LONCAPA::Configuration;
+    use LONCAPA::Enrollment;
+    use Apache::lonnet;
+    use Apache::loncoursedata;
+    use Apache::lonmsg;
+    use HTML::Entities;
 
 # Determine the library server's domain
-  my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
-  my $dom = $$perlvarref{'lonDefDomain'};
-  print "Domain is $dom\n";
+    my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
+    my $dom = $$perlvarref{'lonDefDomain'};
+    my $tmpdir = $$perlvarref{'lonDaemons'}.'/tmp';
+    $ENV{'user.domain'} = $dom;
 
 # Determine the present time;
-  my $timenow = time();
+    my $timenow = time();
 
 # Determine the courses
-  my %courses = &Apache::lonnet::courseiddump($dom,'.',1); 
-  my %affiliates = ();
-  my %enrollvar = ();
-  my %LC_code = ();
-  foreach my $key (sort keys %courses) {
-      my $crs;
-      if ($key =~ m/^($dom)_(\w+)$/) {
-          $crs = $2;
-      }
+    my %courses = &Apache::lonnet::courseiddump($dom,'.',1); 
+    my %affiliates = ();
+    my %enrollvar = ();
+    my %logmsg = ();
+    my %reply = ();
+    my %LC_code = ();
+    foreach my $key (sort keys %courses) {
+        my $crs;
+        if ($key =~ m/^($dom)_(\w+)$/) {
+            $crs = $2;
+        }
 
 # Get course settings
-      my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
-      %{$enrollvar{$crs}} = ();
-      @{$affiliates{$crs}} = ();
-      %{$LC_code{$crs}} = ();
-      foreach my $item (keys %settings) {
-          if ($item =~ m/^internal\.(.+)$/) {
-              $enrollvar{$crs}{$1} = $settings{$item};
-          }
-      }
-      if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {
-          if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) {
+        my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
+        %{$enrollvar{$crs}} = ();
+        @{$affiliates{$crs}} = ();
+        %{$LC_code{$crs}} = ();
+        foreach my $item (keys %settings) {
+            if ($item =~ m/^internal\.(.+)$/) {
+                $enrollvar{$crs}{$1} = $settings{$item};
+            } elsif ($item eq 'description') {
+                $enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item});  
+            }
+        }
+        if (($enrollvar{$crs}{autostart} <= $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
+            if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
 # Add to list of classes for retrieval
-              $enrollvar{$crs}{sectionnums} =~ s/ //g;
-              $enrollvar{$crs}{crosslistings} =~ s/ //g;
-              my @sections = ();
-              my @crosslistings = ();
-              if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
-                  @sections = split/,/,$enrollvar{$crs}{sectionnums};
-              } else {
-                  @$sections = $enrollvar{$crs}{sectionnums};
-              }
-              if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
-                  @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
-              } else {
-                  @crosslistings = $enrollvar{$crs}{crosslistings};
-              }
-              foreach my $sec (@sections) {  
-                  if ($sec =~ m/^(\w+):/(\w*)$) {
-                      my $course_id = $enrollvar{$crs}{coursecode}.$1;
-                      my $gp = $2;
-                      if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
-                          push @{$affiliates{$crs}}, $course_id;
-                          $LC_code{$crs}{$course_id} = $gp; 
-                      }
-                  }
-              }
-              foreach my $xlist (@crosslistings) {
-                  if ($xlist =~ m/^(\w+):(\w*)$/) {
-                      my $course_id = $1;
-                      my $gp = $2;
-                      if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
-                          push @{$affiliates{$crs}}, $course_id;
-                          $LC_code{$crs}{$course_id} = $gp;
-                      }
-                  }
-              }
-          }
-      }
-      print "Key is $key, Value is $courses{$key}\n";
-  }
-  &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
+                $enrollvar{$crs}{sectionnums} =~ s/ //g;
+                $enrollvar{$crs}{crosslistings} =~ s/ //g;
+                my @sections = ();
+                my @crosslistings = ();
+                if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
+                    @sections = split/,/,$enrollvar{$crs}{sectionnums};
+                } else {
+                    $sections[0] = $enrollvar{$crs}{sectionnums};
+                }
+                if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
+                    @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
+                } else {
+                    @crosslistings = $enrollvar{$crs}{crosslistings};
+                }
+                foreach my $sec (@sections) {
+                    if ($sec =~ m/^(\w+):(\w*)$/ ) {
+                        my $course_id = $enrollvar{$crs}{coursecode}.$1;
+                        my $gp = $2;
+                        if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
+                            push @{$affiliates{$crs}}, $course_id;
+                            $LC_code{$crs}{$course_id} = $gp; 
+                        }
+                    }
+                }
+                foreach my $xlist (@crosslistings) {
+                    if ($xlist =~ m/^(\w+):(\w*)$/) {
+                        my $course_id = $1;
+                        my $gp = $2;
+                        if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
+                            push @{$affiliates{$crs}}, $course_id;
+                            $LC_code{$crs}{$course_id} = $gp;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
 
 # Now go through classes and perform required enrollment changes.
-  foreach my $crs (sort keys %enrollvar) {
-      if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {
-          if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
-              my $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}},"automated");
-              unless ($enrollvar{$crs}{notifylist}  eq '') {
-# Send message about enrollment changes to notifylist.              
-              }
-          }
-      }
-  }
+    foreach my $crs (sort keys %enrollvar) {
+        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);
+                    if ($changecount > 0) {
+                        unless ($enrollvar{$crs}{notifylist}  eq '') {
+# Send message about enrollment changes to notifylist.
+# Set $ENV{'user.name'}, $ENV{'user.home'} for use by logging in lonmsg
+                            unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) )  ) {
+                                $ENV{'user.name'} = $enrollvar{$crs}{'courseowner'};
+                                $ENV{'user.home'} = &Apache::lonnet::homeserver($ENV{'user.name'},$dom);
+
+                                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;
+                                my @to_notify = ();
+                                if ($enrollvar{$crs}{notifylist} =~ m/,/) {
+                                    @to_notify = split/,/,$enrollvar{$crs}{notifylist};
+                                } else {
+                                    $to_notify[0] = $enrollvar{$crs}{notifylist};
+                                }
+                                foreach my $cc (@to_notify) {
+                                    my ($ccname,$ccdom) = split/@/,$cc;
+                                    my $status =  &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
+                                }
+                                delete($ENV{'user.name'});
+                                delete($ENV{'user.home'});
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            print STDERR "No institutional classlist data could be retrieved for $crs\n";
+        }
+    }
+    delete($ENV{'user.domain'});
 
 # Check for photos
-
 
 1;

--raeburn1070898442--