[LON-CAPA-cvs] cvs: modules /raeburn Autoenroll.pl
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 02 Dec 2003 00:16:13 -0000
This is a MIME encoded message
--raeburn1070324173
Content-Type: text/plain
raeburn Mon Dec 1 19:16:13 2003 EDT
Modified files:
/modules/raeburn Autoenroll.pl
Log:
12/1/2003 version of automated enrollment script - called by cron to carry out nightly enrollment update. SPR 12/1/2003.
--raeburn1070324173
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20031201191613.txt"
Index: modules/raeburn/Autoenroll.pl
diff -u modules/raeburn/Autoenroll.pl:1.3 modules/raeburn/Autoenroll.pl:1.4
--- modules/raeburn/Autoenroll.pl:1.3 Thu Nov 20 19:30:25 2003
+++ modules/raeburn/Autoenroll.pl Mon Dec 1 19:16:13 2003
@@ -2,9 +2,9 @@
use strict;
use lib '/home/httpd/lib/perl';
+ use localenroll;
use LONCAPA::Configuration;
- use LONCAPA::InfoServices;
- use LONCAPA::Enrollment:
+ use LONCAPA::Enrollment;
use Apache::lonnet;
use Apache::loncoursedata;
@@ -20,6 +20,7 @@
my %courses = &Apache::lonnet::courseiddump($dom,'.',1);
my %affiliates = ();
my %enrollvar = ();
+ my %LC_code = ();
foreach my $key (sort keys %courses) {
my $crs;
if ($key =~ m/^($dom)_(\w+)$/) {
@@ -30,6 +31,7 @@
my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
%{$enrollvar{$crs}} = ();
@{$affiliates{$crs}} = ();
+ %{$LC_code{$crs}} = ();
foreach my $item (keys %settings) {
if ($item =~ m/^internal\.(.+)$/) {
$enrollvar{$crs}{$1} = $settings{$item};
@@ -52,263 +54,45 @@
} else {
@crosslistings = $enrollvar{$crs}{crosslistings};
}
- foreach my $sec (@sections) {
- my $course_id = $enrollvar{$crs}{coursecode}.$sec;
- if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
- push @{$affiliates{$crs}}, $course_id;
+ foreach my $sec (@sections) {
+ if ($sec =~ m/^(\w+):/(\w*)$) {
+ my $course_id = $enrollvar{$crs}{coursecode}.$1;
+ my $gp = $2;
+ if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
+ push @{$affiliates{$crs}}, $course_id;
+ $LC_code{$crs}{$course_id} = $gp;
+ }
}
}
foreach my $xlist (@crosslistings) {
- if (!grep/^$xlist$/,@{$affiliates{$crs}}) {
- push @{$affiliates{$crs}}, $xlist;
+ if ($xlist =~ m/^(\w+):(\w*)$/) {
+ my $course_id = $1;
+ my $gp = $2;
+ if (!grep/^$course_id$/,@{$affiliates{$crs}}) {
+ push @{$affiliates{$crs}}, $course_id;
+ $LC_code{$crs}{$course_id} = $gp;
+ }
}
}
}
}
print "Key is $key, Value is $courses{$key}\n";
}
- &LONCAPA::InfoServices::update_officialclasslists(\%affiliates);
+ &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
# Now go through classes and perform required enrollment changes.
foreach my $crs (sort keys %enrollvar) {
if (($enrollvar{$crs}{autostart} >= $timenow) && ($enrollvar{$crs}{autoend} < $timenow)) {
if (($enrollvar{$crs}{autoadds} == 1) || ($enrollvar{$crs}{autodrops} == 1)) {
-# Get current LON-CAPA student enrollment for this class
- my $cid = $dom."_".$crs;
- my ($currlist) = &Apache::loncoursedata::get_classlist($cid,$dom,$crs);
- my $cend = &Apache::loncoursedata::CL_END
- my $cstart = &Apache::loncoursedata::CL_START;
- my $stuid=&Apache::loncoursedata::CL_ID;
- my $sec=&Apache::loncoursedata::CL_SECTION;
- my $status=&Apache::loncoursedata::CL_STATUS;
- my @currstudents = sort(keys %{$currlist});
-
-# Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class
- my @LCids = ();
- my %unameFromLCid = ();
- foreach my $uname (sort keys %{$currlist}) {
- my $stuID = $$currlist{$uname}[$stuid];
- if (!grep/^$stuID$/,@LCids) {
- push @LCids, $stuID;
- @{$unameFromLCid{$stuID}} = ();
- }
- push @{$unameFromLCid{$stuID}},$uname;
- }
-
-# Get latest institutional enrollment for this class.
- my %allenrolled = ();
- my @reg_students = ();
- my $id = &LONCAPA::Enrollment::CL_ID;
- my $amode = &LONCAPA::Enrollment::CL_AUTHMECH;
- my $password = &LONCAPA::Enrollment::CL_PASSWD;
- my $fname = &LONCAPA::Enrollment::CL_FIRST;
- my $mname = &LONCAPA::Enrollment::CL_MIDDLE;
- my $lname = &LONCAPA::Enrollment::CL_LAST;
- my $gen = &LONCAPA::Enrollment::CL_GEN;
- my $sect = &LONCAPA::Enrollment::CL_SECTION;
- my $start = &LONCAPA::Enrollment::CL_START;
- my $end = &LONCAPA::Enrollment::CL_END;
- my $email = &LONCAPA::Enrollment::CL_EMAIL;
-
- foreach my $class (@{$affiliates{$crs}}) {
- my $enrolled = &LONCAPA::Enrollment::parse_classlist($class);
- foreach my $uname (sort keys %{$enrolled}) {
- if (!grep/^$uname$/,@reg_students) {
- push @reg_students,$uname;
- @{$allenrolled{$uname}} = ();
- }
- push @{$allenrolled{$uname}},$enrolled{$uname};
- }
- }
-# Check for multiple sections for a single student
- my @okusers = ();
- foreach my $uname (@reg_students) {
- if (@{$allenrolled{$uname}} > 1) {
- my @sections = ();
- my $saved;
- for (my $i=0; $i<@{$allenrolled{$uname}; $i++) {
- my @stuinfo = split/:/,$$allenrolled{$uname}[$i];
- my $secnum = $stuinfo[$sect];
- unless ($secnum eq '') {
- unless (grep/^$secnum$/,@sections) {
- $saved = $i;
- push @sections,$secnum;
- }
- }
- }
- if (@sections == 0) {
- @{$allenrolled{$uname}} = ("$$allenrolled{$uname}[0]");
- push @okusers, $uname;
- }
- elsif (@sections == 1) {
- @{$allenrolled{$uname}} = ("$$allenrolled{$uname}[$saved]");
- push @okusers, $uname;
- }
- elsif (@sections > 1) {
- my $dupmsg = "$uname appears in classlists for two sections of $crs -";
- foreach (@sections) {
- $dupmsg .= " $_,";
- }
- chop($dupmsg);
- $dupmsg .= " No automated enrollment action taken for this student.\n";
- print "$dupmsg\n";
- }
- } else {
- push @okusers, $uname;
- }
- }
-# Get mapping of student IDs to usernames for users in institutional data for this class
- my @allINids = ();
- foreach my $uname (@okusers) {
- @stuinfo = split/:/,$$allenrolled{$uname}[0];
- my $stuID = $stuinfo[$id];
- if (grep/^$stuID$/,@allINids) {
- push @{$unameFromINid{$stuID}},$uname;
- } else {
- push @allINids, $stuID;
- @{$unameFromINid{$stuID}} = $uname;
- }
- }
-# Compare IDs with existing LON-CAPA enrollment for this class
- foreach my $uname (@okusers) {
- my %uidhash=&Apache::lonnet::idrget($dom,$uname);
- my @stuinfo = split/:/,$$allenrolled{$uname}[0];
- if (grep/^$uname$/,@currstudents) {
-# Check for studentID changes
- if (($uidhash{$uname}) && ($uidhash{$uname}!~/error\:/) {
- unless ($uidhash{$uname} eq $stuinfo[$id]) {
- print "Change in ID for $uname in class: $crs. StudentID in LON-CAPA system is $uidhash{$uname}, StudentID in institutional data is $stuinfo[$id]\n";
- }
- }
-# Check for section changes
- unless ($$currlist{$uname}[$sec] eq $stuinfo[$sec]) {
- if ($$currlist{$uname}[$status] eq "auto") {
- my $modify_section_result = &Apache::londropadd::modifysection($dom,$uname,$cid,$stuinfo[$sec],undef);
- if ($modify_section_results !~ /^ok/) {
- print("An error occured during the attempt to change the section for $uname from $$currlist{$uname}[$sec] to $stuinfo[$sec]\n");
- }
- }
- }
- }
- elsif ($uname ne '') {
-# Check for changed usernames by checking studentIDs
- if (grep/^$$currlist{$uname}[$id]$/,@allINids) {
- foreach my $match @{$unameFromINid{$$currlist{$student}[$id]}} {
- if (grep/^$match$/,@okusers) {
- print "A possible change in username has been detected for a student enrolled in $crs. The existing LON-CAPA classlist contains user: $uname and student ID: $$currlist{$uname}[$id]. This username has been dropped from the institutional classlist, but the same student ID is used for user: $match who still appears in the institutional classlist. You may need to move the student data files for user: $uname to $match\n";
- }
- }
- }
-# Add student to LON-CAPA classlist
- elsif ($enrollvar{$crs}{autoadds} == 1) {
- my $authtype = $stuinfo[$amode];
- my $passwd = $stuinfo[$password];
- my $first = $stuinfo[$fname];
- my $middle = $stuinfo[$mname];
- my $last = $stuinfo[$lname];
- my $gene = $stuinfo[$gen];
- my $section = $stuinfo[$sect];
- my $enddate = $stuinfo[$end];
- my $startdate = $stuinfo[$start];
- my $address = $stuinfo[$email];
- my $pid = $stuinfo[$id];
-
-# remove non alphanumeric values from section
- $section =~ s/\W//g;
-
- unless ($address=~/^[^\@]+\@[^\@]+$/) { $address=''; }
-
-# Use course defaults where entry is absent
- if ($authtype eq '') {
- $authtype = $enrollvar{$crs}{authtype};
- }
- if ($enddate eq '') {
- $enddate = $enrollvar{$crs}{enddate};
- }
- if ($startdate eq '') {
- $startdate = $enrollvar{$crs}{startdate};
- }
- if ($passwd eq '') {
-# If no account exists and passwords should be generated
- $passwd = &LONCAPA::Enrollment::create_password();
- }
-# Clean up whitespace
- foreach (\$dom,\$uname,\$pid,\$first,\$middle,\$last,\$gene,\$section) {
- $$_ =~ s/(\s+$|^\s+)//g;
- }
- my $reply=&modifystudent($dom,$cid,$uname,$pid,$authtype,$passwd,$first,$middle,$last,$gene,$section,$enddate,$startdate,'',undef,$stuinfo[$email]);
- }
- }
- }
-# Do drops
- if ($enrollvar{$crs}{autodrops} == 1) {
-# Check for changed usernames by checking studentIDs
+ 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");
+ unless ($enrollvar{$crs}{notifylist} eq '') {
+# Send message about enrollment changes to notifylist.
}
}
}
}
+# Check for photos
-sub modifystudent {
- my ($udom,$cid,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec,
- $end,$start,$forceid,$desiredhome,$email)=@_;
-# --------------------------------------------------------------- Make the user
- my $reply=&modifyuser
- ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$forceid,
- $desiredhome,$email);
- unless ($reply eq 'ok') { return $reply; }
- # This will cause &modify_student_enrollment to get the uid from the
- # students environment
- $uid = undef if (!$forceid);
- $reply = &modify_student_enrollment($udom,$cid,$uname,$uid,$first,$middle,
- $last,$gene,$usec,$end,$start);
- return $reply;
-}
-
-sub modify_student_enrollment {
- my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start) = @_;
- # Make sure the user exists
- my $uhome=&homeserver($uname,$udom);
- if (($uhome eq '') || ($uhome eq 'no_host')) {
- return 'error: no such user';
- }
- #
- # Get student data if we were not given enough information
- if (!defined($first) || $first eq '' ||
- !defined($last) || $last eq '' ||
- !defined($uid) || $uid eq '' ||
- !defined($middle) || $middle eq '' ||
- !defined($gene) || $gene eq '') {
- # They did not supply us with enough data to enroll the student, so
- # we need to pick up more information.
- my %tmp = &get('environment',
- ['firstname','middlename','lastname', 'generation','id']
- ,$udom,$uname);
- foreach (keys(%tmp)) {
- &logthis("key $_ = ".$tmp{$_});
- }
- $first = $tmp{'firstname'} if (!defined($first) || $first eq '');
- $middle = $tmp{'middlename'} if (!defined($middle) || $middle eq '');
- $last = $tmp{'lastname'} if (!defined($last) || $last eq '');
- $gene = $tmp{'generation'} if (!defined($gene) || $gene eq '');
- $uid = $tmp{'id'} if (!defined($uid) || $uid eq '');
- }
- my $fullname = &Apache::loncoursedata::ProcessFullName($last,$gene,
- $first,$middle);
- my $reply=critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
- $ENV{'course.'.$cid.'.num'}.':classlist:'.
- &escape($uname.':'.$udom).'='.
- &escape(join(':',$end,$start,$uid,$usec,$fullname)),
- $ENV{'course.'.$cid.'.home'});
- unless (($reply eq 'ok') || ($reply eq 'delayed')) {
- return 'error: '.$reply;
- }
- # Add student role to user
- my $uurl='/'.$cid;
- $uurl=~s/\_/\//g;
- if ($usec) {
- $uurl.='/'.$usec;
- }
- return &assignrole($udom,$uname,$uurl,'st',$end,$start);
-}
+1;
--raeburn1070324173--