Diff for /loncom/enrollment/Autoenroll.pl between versions 1.1 and 1.12

version 1.1, 2003/12/05 17:08:09 version 1.12, 2004/11/27 17:23:09
Line 1 Line 1
 #!/usr/bin/perl -w  #!/usr/bin/perl
   #
   use strict;  #Automated Enrollment script
   use lib '/home/httpd/lib/perl';  # $Id$
   use localenroll;  #
   use LONCAPA::Configuration;  # Copyright Michigan State University Board of Trustees
   use LONCAPA::Enrollment;  #
   use Apache::lonnet;  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   use Apache::loncoursedata;  #
   # LON-CAPA is free software; you can redistribute it and/or modify
 # Determine the library server's domain  # it under the terms of the GNU General Public License as published by
   my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');  # the Free Software Foundation; either version 2 of the License, or
   my $dom = $$perlvarref{'lonDefDomain'};  # (at your option) any later version.
   print "Domain is $dom\n";  #
   # 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';
       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 and hostID
       my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
       my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log';
       my @domains = &Apache::lonnet::current_machine_domains();
       my @hostids = &Apache::lonnet::current_machine_ids();
   
 # Determine the present time;  # Determine the present time;
   my $timenow = time();      my $timenow = time();
   
 # Determine the courses  # For each domain ......
   my %courses = &Apache::lonnet::courseiddump($dom,'.',1);       foreach my $dom (@domains) {
   my %affiliates = ();      #only run if configured to
   my %enrollvar = ();          if (! &localenroll::run($dom)) { next; }
   my %LC_code = ();          $ENV{'user.domain'} = $dom;
   foreach my $key (sort keys %courses) {      # Determine the courses
       my $crs;          my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.',1,\@hostids); 
       if ($key =~ m/^($dom)_(\w+)$/) {          my %affiliates = ();
           $crs = $2;          my %enrollvar = ();
       }          my %reply = ();
           my %LC_code = ();
           foreach my $key (sort keys %courses) {
               my $crs;
               if ($key =~ m/^($dom)_(\w+)$/) {
                   $crs = $2;
               }
   
 # Get course settings  # Get course settings
       my %settings = &Apache::lonnet::dump('environment',$dom,$crs);              my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
       %{$enrollvar{$crs}} = ();              %{$enrollvar{$crs}} = ();
       @{$affiliates{$crs}} = ();              @{$affiliates{$crs}} = ();
       %{$LC_code{$crs}} = ();              %{$LC_code{$crs}} = ();
       foreach my $item (keys %settings) {              foreach my $item (keys %settings) {
           if ($item =~ m/^internal\.(.+)$/) {                  if ($item =~ m/^internal\.(.+)$/) {
               $enrollvar{$crs}{$1} = $settings{$item};                      $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)) {                  } elsif ($item eq 'default_enrollment_start_date') {
           if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) {                      $enrollvar{$crs}{startdate} = $settings{$item};
                   }  elsif ($item eq 'default_enrollment_end_date') {
                       $enrollvar{$crs}{enddate} = $settings{$item};
                   }
               }
               if (($enrollvar{$crs}{autostart} <= $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
                   if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
 # Add to list of classes for retrieval  # Add to list of classes for retrieval
               $enrollvar{$crs}{sectionnums} =~ s/ //g;                      $enrollvar{$crs}{sectionnums} =~ s/ //g;
               $enrollvar{$crs}{crosslistings} =~ s/ //g;                      $enrollvar{$crs}{crosslistings} =~ s/ //g;
               my @sections = ();                      my @sections = ();
               my @crosslistings = ();                      my @crosslistings = ();
               if ($enrollvar{$crs}{sectionnums} =~ m/,/) {                      if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
                   @sections = split/,/,$enrollvar{$crs}{sectionnums};                          @sections = split/,/,$enrollvar{$crs}{sectionnums};
               } else {                      } else {
                   @$sections = $enrollvar{$crs}{sectionnums};                          $sections[0] = $enrollvar{$crs}{sectionnums};
               }                      }
               if ($enrollvar{$crs}{crosslistings} =~ m/,/) {                      if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
                   @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}                          @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
               } else {                      } else {
                   @crosslistings = $enrollvar{$crs}{crosslistings};                          @crosslistings = $enrollvar{$crs}{crosslistings};
               }                      }
               foreach my $sec (@sections) {                        foreach my $sec (@sections) {
                   if ($sec =~ m/^(\w+):/(\w*)$) {                          if ($sec =~ m/^(\w+):(\w*)$/ ) {
                       my $course_id = $enrollvar{$crs}{coursecode}.$1;                              my $course_id = $enrollvar{$crs}{coursecode}.$1;
                       my $gp = $2;                              my $gp = $2;
                       if (!grep/^$course_id$/,@{$affiliates{$crs}}) {                              if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
                           push @{$affiliates{$crs}}, $course_id;                                  push @{$affiliates{$crs}}, $course_id;
                           $LC_code{$crs}{$course_id} = $gp;                                   $LC_code{$crs}{$course_id} = $gp; 
                       }                              }
                   }                          }
               }                      }
               foreach my $xlist (@crosslistings) {                      foreach my $xlist (@crosslistings) {
                   if ($xlist =~ m/^(\w+):(\w*)$/) {                          if ($xlist =~ m/^(\w+):(\w*)$/) {
                       my $course_id = $1;                              my $course_id = $1;
                       my $gp = $2;                              my $gp = $2;
                       if (!grep/^$course_id$/,@{$affiliates{$crs}}) {                              if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
                           push @{$affiliates{$crs}}, $course_id;                                  push @{$affiliates{$crs}}, $course_id;
                           $LC_code{$crs}{$course_id} = $gp;                                  $LC_code{$crs}{$course_id} = $gp;
                       }                              }
                   }                          }
               }                      }
           }                  }
       }              }
       print "Key is $key, Value is $courses{$key}\n";          }
   }          my $outcome = &Apache::lonnet::fetch_enrollment_query('automated',\%affiliates,\%reply,$dom);
   &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);  
   
 # Now go through classes and perform required enrollment changes.  # Now go through classes and perform required enrollment changes.
   foreach my $crs (sort keys %enrollvar) {          open (my $fh,">>$logfile");
       if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {          print $fh "********************\n".localtime(time)." Enrollment messages start --\n";
           if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {          print $fh "Response from fetch_enrollment_query was $outcome\n";
               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");          foreach my $crs (sort keys %enrollvar) {
               unless ($enrollvar{$crs}{notifylist}  eq '') {              my $logmsg = '';
 # Send message about enrollment changes to notifylist.                            my $newusermsg = '';
               }              if ($reply{$crs} > 0) {
           }                  if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
       }                      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,\$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.
   # 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;
                                       unless ($newusermsg eq '') { 
                                           $message .= "\n".$newusermsg;
                                       }
                                       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);
                                       }
                                       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'});
                                   }
                               }
                           }
                       }
                   }
               } else {
                   if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
                       if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
                           print $fh "No institutional classlist data could be retrieved for $crs\n";
                       } else {
                           print $fh "Not within time window for auto-enrollment in $crs\n";
                       }
                   } else {
                       print $fh "Auto-enrollment not currently enabled for $crs\n";
                   }
               }
           }
           print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n";
           close($fh);
           delete($ENV{'user.domain'});
 # Check for photos  # Check for photos
       }
   
 1;  1;

Removed from v.1.1  
changed lines
  Added in v.1.12


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>