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