Annotation of loncom/enrollment/Autoenroll.pl, revision 1.3

1.2       raeburn     1: #!/usr/bin/perl
1.3     ! albertel    2: #
        !             3: #Automated enroll script
        !             4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www 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: #
1.1       raeburn    28: 
1.2       raeburn    29:     use strict;
                     30:     use lib '/home/httpd/lib/perl';
                     31:     use localenroll;
                     32:     use LONCAPA::Configuration;
                     33:     use LONCAPA::Enrollment;
                     34:     use Apache::lonnet;
                     35:     use Apache::loncoursedata;
                     36:     use Apache::lonmsg;
                     37:     use HTML::Entities;
1.1       raeburn    38: 
                     39: # Determine the library server's domain
1.2       raeburn    40:     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
                     41:     my $dom = $$perlvarref{'lonDefDomain'};
                     42:     my $tmpdir = $$perlvarref{'lonDaemons'}.'/tmp';
                     43:     $ENV{'user.domain'} = $dom;
1.1       raeburn    44: 
                     45: # Determine the present time;
1.2       raeburn    46:     my $timenow = time();
1.1       raeburn    47: 
                     48: # Determine the courses
1.2       raeburn    49:     my %courses = &Apache::lonnet::courseiddump($dom,'.',1); 
                     50:     my %affiliates = ();
                     51:     my %enrollvar = ();
                     52:     my %logmsg = ();
                     53:     my %reply = ();
                     54:     my %LC_code = ();
                     55:     foreach my $key (sort keys %courses) {
                     56:         my $crs;
                     57:         if ($key =~ m/^($dom)_(\w+)$/) {
                     58:             $crs = $2;
                     59:         }
1.1       raeburn    60: 
                     61: # Get course settings
1.2       raeburn    62:         my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
                     63:         %{$enrollvar{$crs}} = ();
                     64:         @{$affiliates{$crs}} = ();
                     65:         %{$LC_code{$crs}} = ();
                     66:         foreach my $item (keys %settings) {
                     67:             if ($item =~ m/^internal\.(.+)$/) {
                     68:                 $enrollvar{$crs}{$1} = $settings{$item};
                     69:             } elsif ($item eq 'description') {
                     70:                 $enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item});  
                     71:             }
                     72:         }
                     73:         if (($enrollvar{$crs}{autostart} <= $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
                     74:             if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
1.1       raeburn    75: # Add to list of classes for retrieval
1.2       raeburn    76:                 $enrollvar{$crs}{sectionnums} =~ s/ //g;
                     77:                 $enrollvar{$crs}{crosslistings} =~ s/ //g;
                     78:                 my @sections = ();
                     79:                 my @crosslistings = ();
                     80:                 if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
                     81:                     @sections = split/,/,$enrollvar{$crs}{sectionnums};
                     82:                 } else {
                     83:                     $sections[0] = $enrollvar{$crs}{sectionnums};
                     84:                 }
                     85:                 if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
                     86:                     @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
                     87:                 } else {
                     88:                     @crosslistings = $enrollvar{$crs}{crosslistings};
                     89:                 }
                     90:                 foreach my $sec (@sections) {
                     91:                     if ($sec =~ m/^(\w+):(\w*)$/ ) {
                     92:                         my $course_id = $enrollvar{$crs}{coursecode}.$1;
                     93:                         my $gp = $2;
                     94:                         if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
                     95:                             push @{$affiliates{$crs}}, $course_id;
                     96:                             $LC_code{$crs}{$course_id} = $gp; 
                     97:                         }
                     98:                     }
                     99:                 }
                    100:                 foreach my $xlist (@crosslistings) {
                    101:                     if ($xlist =~ m/^(\w+):(\w*)$/) {
                    102:                         my $course_id = $1;
                    103:                         my $gp = $2;
                    104:                         if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
                    105:                             push @{$affiliates{$crs}}, $course_id;
                    106:                             $LC_code{$crs}{$course_id} = $gp;
                    107:                         }
                    108:                     }
                    109:                 }
                    110:             }
                    111:         }
                    112:     }
                    113:     &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
1.1       raeburn   114: 
                    115: # Now go through classes and perform required enrollment changes.
1.2       raeburn   116:     foreach my $crs (sort keys %enrollvar) {
                    117:         if ($reply{$crs} > 0) {
                    118:             if (($enrollvar{$crs}{autostart} < $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
                    119:                 if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
                    120:                     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');
                    121:                     my $logfile = $crs."_enrollment_log.txt";
                    122:                     open (FILE,">>$tmpdir/$logfile");
                    123:                     print FILE "********************\n".localtime(time)." Enrollment messages start --\n";
                    124:                     print FILE "$logmsg{$crs}\n";
                    125:                     print FILE "-- ".localtime(time)." Enrollment messages end\n********************\n\n"; 
                    126:                     close (FILE);
                    127:                     if ($changecount > 0) {
                    128:                         unless ($enrollvar{$crs}{notifylist}  eq '') {
                    129: # Send message about enrollment changes to notifylist.
                    130: # Set $ENV{'user.name'}, $ENV{'user.home'} for use by logging in lonmsg
                    131:                             unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) )  ) {
                    132:                                 $ENV{'user.name'} = $enrollvar{$crs}{'courseowner'};
                    133:                                 $ENV{'user.home'} = &Apache::lonnet::homeserver($ENV{'user.name'},$dom);
                    134: 
                    135:                                 my $subject = "Student enrollment changes in $enrollvar{$crs}{coursecode}";
                    136:                                 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;
                    137:                                 my @to_notify = ();
                    138:                                 if ($enrollvar{$crs}{notifylist} =~ m/,/) {
                    139:                                     @to_notify = split/,/,$enrollvar{$crs}{notifylist};
                    140:                                 } else {
                    141:                                     $to_notify[0] = $enrollvar{$crs}{notifylist};
                    142:                                 }
                    143:                                 foreach my $cc (@to_notify) {
                    144:                                     my ($ccname,$ccdom) = split/@/,$cc;
                    145:                                     my $status =  &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
                    146:                                 }
                    147:                                 delete($ENV{'user.name'});
                    148:                                 delete($ENV{'user.home'});
                    149:                             }
                    150:                         }
                    151:                     }
                    152:                 }
                    153:             }
                    154:         } else {
                    155:             print STDERR "No institutional classlist data could be retrieved for $crs\n";
                    156:         }
                    157:     }
                    158:     delete($ENV{'user.domain'});
1.1       raeburn   159: 
                    160: # Check for photos
                    161: 
                    162: 1;

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