Annotation of loncom/enrollment/Autoenroll.pl, revision 1.1
1.1 ! raeburn 1: #!/usr/bin/perl -w
! 2:
! 3: use strict;
! 4: use lib '/home/httpd/lib/perl';
! 5: use localenroll;
! 6: use LONCAPA::Configuration;
! 7: use LONCAPA::Enrollment;
! 8: use Apache::lonnet;
! 9: use Apache::loncoursedata;
! 10:
! 11: # Determine the library server's domain
! 12: my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
! 13: my $dom = $$perlvarref{'lonDefDomain'};
! 14: print "Domain is $dom\n";
! 15:
! 16: # Determine the present time;
! 17: my $timenow = time();
! 18:
! 19: # Determine the courses
! 20: my %courses = &Apache::lonnet::courseiddump($dom,'.',1);
! 21: my %affiliates = ();
! 22: my %enrollvar = ();
! 23: my %LC_code = ();
! 24: foreach my $key (sort keys %courses) {
! 25: my $crs;
! 26: if ($key =~ m/^($dom)_(\w+)$/) {
! 27: $crs = $2;
! 28: }
! 29:
! 30: # Get course settings
! 31: my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
! 32: %{$enrollvar{$crs}} = ();
! 33: @{$affiliates{$crs}} = ();
! 34: %{$LC_code{$crs}} = ();
! 35: foreach my $item (keys %settings) {
! 36: if ($item =~ m/^internal\.(.+)$/) {
! 37: $enrollvar{$crs}{$1} = $settings{$item};
! 38: }
! 39: }
! 40: if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {
! 41: if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) {
! 42: # Add to list of classes for retrieval
! 43: $enrollvar{$crs}{sectionnums} =~ s/ //g;
! 44: $enrollvar{$crs}{crosslistings} =~ s/ //g;
! 45: my @sections = ();
! 46: my @crosslistings = ();
! 47: if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
! 48: @sections = split/,/,$enrollvar{$crs}{sectionnums};
! 49: } else {
! 50: @$sections = $enrollvar{$crs}{sectionnums};
! 51: }
! 52: if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
! 53: @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
! 54: } else {
! 55: @crosslistings = $enrollvar{$crs}{crosslistings};
! 56: }
! 57: foreach my $sec (@sections) {
! 58: if ($sec =~ m/^(\w+):/(\w*)$) {
! 59: my $course_id = $enrollvar{$crs}{coursecode}.$1;
! 60: my $gp = $2;
! 61: if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
! 62: push @{$affiliates{$crs}}, $course_id;
! 63: $LC_code{$crs}{$course_id} = $gp;
! 64: }
! 65: }
! 66: }
! 67: foreach my $xlist (@crosslistings) {
! 68: if ($xlist =~ m/^(\w+):(\w*)$/) {
! 69: my $course_id = $1;
! 70: my $gp = $2;
! 71: if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
! 72: push @{$affiliates{$crs}}, $course_id;
! 73: $LC_code{$crs}{$course_id} = $gp;
! 74: }
! 75: }
! 76: }
! 77: }
! 78: }
! 79: print "Key is $key, Value is $courses{$key}\n";
! 80: }
! 81: &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
! 82:
! 83: # Now go through classes and perform required enrollment changes.
! 84: foreach my $crs (sort keys %enrollvar) {
! 85: if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {
! 86: if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
! 87: 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");
! 88: unless ($enrollvar{$crs}{notifylist} eq '') {
! 89: # Send message about enrollment changes to notifylist.
! 90: }
! 91: }
! 92: }
! 93: }
! 94:
! 95: # Check for photos
! 96:
! 97:
! 98: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>