File:  [LON-CAPA] / loncom / enrollment / Autoenroll.pl
Revision 1.11: download - view: text, annotated - select for diffs
Thu Jun 17 18:31:24 2004 UTC (20 years ago) by raeburn
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, HEAD
Calls to functions in localenroll.pm mediated by lonc/lond now include domain
in the set of passed parameters to support domain-specific variants in a single
localenroll.pm file housed on a multi-domain library server.

Automated enrollment now sets first access and last access dates for student
roles based on defaults set on course creation, and modifiable via a number
of mechanisms in the Enrollment Manager, and Automated Enrollment Manager.

The Automated Enrollment Manager now provides a utility to allow enrollment type
to be toggled between 'auto' and 'manual', so that students added via CSV file
or singly can become liable for automated update (dropping, section switching
etc.).

    1: #!/usr/bin/perl
    2: #
    3: #Automated Enrollment script
    4: # $Id: Autoenroll.pl,v 1.11 2004/06/17 18:31:24 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28:     use strict;
   29:     use lib '/home/httpd/lib/perl';
   30:     use localenroll;
   31:     use LONCAPA::Configuration;
   32:     use LONCAPA::Enrollment;
   33:     use Apache::lonnet;
   34:     use Apache::loncoursedata;
   35:     use Apache::lonmsg;
   36:     use HTML::Entities;
   37: 
   38: # Determine the library server's domain and hostID
   39:     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
   40:     my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoenroll.log';
   41:     my @domains = &Apache::lonnet::current_machine_domains();
   42:     my @hostids = &Apache::lonnet::current_machine_ids();
   43: 
   44: # Determine the present time;
   45:     my $timenow = time();
   46: 
   47: # For each domain ......
   48:     foreach my $dom (@domains) {
   49:     #only run if configured to
   50:         if (! &localenroll::run($dom)) { next; }
   51:         $ENV{'user.domain'} = $dom;
   52:     # Determine the courses
   53:         my %courses = &Apache::lonnet::courseiddump($dom,'.',1,1,\@hostids); 
   54:         my %affiliates = ();
   55:         my %enrollvar = ();
   56:         my %reply = ();
   57:         my %LC_code = ();
   58:         foreach my $key (sort keys %courses) {
   59:             my $crs;
   60:             if ($key =~ m/^($dom)_(\w+)$/) {
   61:                 $crs = $2;
   62:             }
   63: 
   64: # Get course settings
   65:             my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
   66:             %{$enrollvar{$crs}} = ();
   67:             @{$affiliates{$crs}} = ();
   68:             %{$LC_code{$crs}} = ();
   69:             foreach my $item (keys %settings) {
   70:                 if ($item =~ m/^internal\.(.+)$/) {
   71:                     $enrollvar{$crs}{$1} = $settings{$item};
   72:                 } elsif ($item eq 'description') {
   73:                     $enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item});  
   74:                 } elsif ($item eq 'default_enrollment_start_date') {
   75:                     $enrollvar{$crs}{startdate} = $settings{$item};
   76:                 }  elsif ($item eq 'default_enrollment_end_date') {
   77:                     $enrollvar{$crs}{enddate} = $settings{$item};
   78:                 }
   79:             }
   80:             if (($enrollvar{$crs}{autostart} <= $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
   81:                 if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
   82: # Add to list of classes for retrieval
   83:                     $enrollvar{$crs}{sectionnums} =~ s/ //g;
   84:                     $enrollvar{$crs}{crosslistings} =~ s/ //g;
   85:                     my @sections = ();
   86:                     my @crosslistings = ();
   87:                     if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
   88:                         @sections = split/,/,$enrollvar{$crs}{sectionnums};
   89:                     } else {
   90:                         $sections[0] = $enrollvar{$crs}{sectionnums};
   91:                     }
   92:                     if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
   93:                         @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
   94:                     } else {
   95:                         @crosslistings = $enrollvar{$crs}{crosslistings};
   96:                     }
   97:                     foreach my $sec (@sections) {
   98:                         if ($sec =~ m/^(\w+):(\w*)$/ ) {
   99:                             my $course_id = $enrollvar{$crs}{coursecode}.$1;
  100:                             my $gp = $2;
  101:                             if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
  102:                                 push @{$affiliates{$crs}}, $course_id;
  103:                                 $LC_code{$crs}{$course_id} = $gp; 
  104:                             }
  105:                         }
  106:                     }
  107:                     foreach my $xlist (@crosslistings) {
  108:                         if ($xlist =~ m/^(\w+):(\w*)$/) {
  109:                             my $course_id = $1;
  110:                             my $gp = $2;
  111:                             if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
  112:                                 push @{$affiliates{$crs}}, $course_id;
  113:                                 $LC_code{$crs}{$course_id} = $gp;
  114:                             }
  115:                         }
  116:                     }
  117:                 }
  118:             }
  119:         }
  120:         my $outcome = &Apache::lonnet::fetch_enrollment_query('automated',\%affiliates,\%reply,$dom);
  121: 
  122: # Now go through classes and perform required enrollment changes.
  123:         open (my $fh,">>$logfile");
  124:         print $fh "********************\n".localtime(time)." Enrollment messages start --\n";
  125:         foreach my $crs (sort keys %enrollvar) {
  126:             my $logmsg = '';
  127:             my $newusermsg = '';
  128:             if ($reply{$crs} > 0) {
  129:                 if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
  130:                     if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
  131:                         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');
  132:                         print $fh "Messages start for $crs\n";
  133:                         print $fh "$logmsg\n";
  134:                         print $fh "Messages end for $crs\n";
  135:                         if ($changecount > 0) {
  136:                             unless ($enrollvar{$crs}{notifylist}  eq '') {
  137: # Send message about enrollment changes to notifylist.
  138: # Set $ENV{'user.name'}, $ENV{'user.home'} for use by logging in lonmsg
  139:                                 unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) )  ) {
  140:                                     $ENV{'user.name'} = $enrollvar{$crs}{'courseowner'};
  141:                                     $ENV{'user.home'} = &Apache::lonnet::homeserver($ENV{'user.name'},$dom);
  142: 
  143:                                     my $subject = "Student enrollment changes in $enrollvar{$crs}{coursecode}";
  144:                                     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;
  145:                                     unless ($newusermsg eq '') { 
  146:                                         $message .= "\n".$newusermsg;
  147:                                     }
  148:                                     my @to_notify = ();
  149:                                     if ($enrollvar{$crs}{notifylist} =~ m/,/) {
  150:                                         @to_notify = split/,/,$enrollvar{$crs}{notifylist};
  151:                                     } else {
  152:                                         $to_notify[0] = $enrollvar{$crs}{notifylist};
  153:                                     }
  154:                                     foreach my $cc (@to_notify) {
  155:                                         my ($ccname,$ccdom) = split/@/,$cc;
  156:                                         my $status =  &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
  157:                                     }
  158:                                     if ( ($enrollvar{$crs}{notifylist} eq '') && ($newusermsg ne '') ) {
  159:                                         my $subject = "New user accounts in  $enrollvar{$crs}{'coursecode'}";
  160:                                         my $status =  &Apache::lonmsg::user_normal_msg($ENV{'user.name'},$dom,$subject,$newusermsg);
  161:                                     }
  162:                                     delete($ENV{'user.name'});
  163:                                     delete($ENV{'user.home'});
  164:                                 }
  165:                             }
  166:                         }
  167:                     }
  168:                 }
  169:             } else {
  170:                 if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
  171:                     if ( ($enrollvar{$crs}{autostart} < $timenow) && ( ($enrollvar{$crs}{autoend} > $timenow) || ($enrollvar{$crs}{autoend} == 0) ) ) {
  172:                         print $fh "No institutional classlist data could be retrieved for $crs\n";
  173:                     } else {
  174:                         print $fh "Not within time window for auto-enrollment in $crs\n";
  175:                     }
  176:                 } else {
  177:                     print $fh "Auto-enrollment not currently enabled for $crs\n";
  178:                 }
  179:             }
  180:         }
  181:         print $fh "-- ".localtime(time)." Enrollment messages end\n*******************\n\n";
  182:         close($fh);
  183:         delete($ENV{'user.domain'});
  184: # Check for photos
  185:     }
  186: 
  187: 1;

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