File:
[LON-CAPA] /
loncom /
enrollment /
Autoenroll.pl
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Mon Dec 8 15:47:22 2003 UTC (20 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Added notification to course coordinators when automated enrollment update results in enrollment changes. Added saving of logfiles. Changed calling of LONCAPA::Enrollment.pm to support crosslisted courses.
1: #!/usr/bin/perl
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: use Apache::lonmsg;
11: use HTML::Entities;
12:
13: # Determine the library server's domain
14: my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
15: my $dom = $$perlvarref{'lonDefDomain'};
16: my $tmpdir = $$perlvarref{'lonDaemons'}.'/tmp';
17: $ENV{'user.domain'} = $dom;
18:
19: # Determine the present time;
20: my $timenow = time();
21:
22: # Determine the courses
23: my %courses = &Apache::lonnet::courseiddump($dom,'.',1);
24: my %affiliates = ();
25: my %enrollvar = ();
26: my %logmsg = ();
27: my %reply = ();
28: my %LC_code = ();
29: foreach my $key (sort keys %courses) {
30: my $crs;
31: if ($key =~ m/^($dom)_(\w+)$/) {
32: $crs = $2;
33: }
34:
35: # Get course settings
36: my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
37: %{$enrollvar{$crs}} = ();
38: @{$affiliates{$crs}} = ();
39: %{$LC_code{$crs}} = ();
40: foreach my $item (keys %settings) {
41: if ($item =~ m/^internal\.(.+)$/) {
42: $enrollvar{$crs}{$1} = $settings{$item};
43: } elsif ($item eq 'description') {
44: $enrollvar{$crs}{$item} = &HTML::Entities::decode($settings{$item});
45: }
46: }
47: if (($enrollvar{$crs}{autostart} <= $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
48: if ( ($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1) ) {
49: # Add to list of classes for retrieval
50: $enrollvar{$crs}{sectionnums} =~ s/ //g;
51: $enrollvar{$crs}{crosslistings} =~ s/ //g;
52: my @sections = ();
53: my @crosslistings = ();
54: if ($enrollvar{$crs}{sectionnums} =~ m/,/) {
55: @sections = split/,/,$enrollvar{$crs}{sectionnums};
56: } else {
57: $sections[0] = $enrollvar{$crs}{sectionnums};
58: }
59: if ($enrollvar{$crs}{crosslistings} =~ m/,/) {
60: @crosslistings = split/,/,$enrollvar{$crs}{crosslistings}
61: } else {
62: @crosslistings = $enrollvar{$crs}{crosslistings};
63: }
64: foreach my $sec (@sections) {
65: if ($sec =~ m/^(\w+):(\w*)$/ ) {
66: my $course_id = $enrollvar{$crs}{coursecode}.$1;
67: my $gp = $2;
68: if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
69: push @{$affiliates{$crs}}, $course_id;
70: $LC_code{$crs}{$course_id} = $gp;
71: }
72: }
73: }
74: foreach my $xlist (@crosslistings) {
75: if ($xlist =~ m/^(\w+):(\w*)$/) {
76: my $course_id = $1;
77: my $gp = $2;
78: if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
79: push @{$affiliates{$crs}}, $course_id;
80: $LC_code{$crs}{$course_id} = $gp;
81: }
82: }
83: }
84: }
85: }
86: }
87: &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
88:
89: # Now go through classes and perform required enrollment changes.
90: foreach my $crs (sort keys %enrollvar) {
91: if ($reply{$crs} > 0) {
92: if (($enrollvar{$crs}{autostart} < $timenow) && ($enrollvar{$crs}{autoend} > $timenow)) {
93: if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
94: 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');
95: my $logfile = $crs."_enrollment_log.txt";
96: open (FILE,">>$tmpdir/$logfile");
97: print FILE "********************\n".localtime(time)." Enrollment messages start --\n";
98: print FILE "$logmsg{$crs}\n";
99: print FILE "-- ".localtime(time)." Enrollment messages end\n********************\n\n";
100: close (FILE);
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;
111: my @to_notify = ();
112: if ($enrollvar{$crs}{notifylist} =~ m/,/) {
113: @to_notify = split/,/,$enrollvar{$crs}{notifylist};
114: } else {
115: $to_notify[0] = $enrollvar{$crs}{notifylist};
116: }
117: foreach my $cc (@to_notify) {
118: my ($ccname,$ccdom) = split/@/,$cc;
119: my $status = &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
120: }
121: delete($ENV{'user.name'});
122: delete($ENV{'user.home'});
123: }
124: }
125: }
126: }
127: }
128: } else {
129: print STDERR "No institutional classlist data could be retrieved for $crs\n";
130: }
131: }
132: delete($ENV{'user.domain'});
133:
134: # Check for photos
135:
136: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>