[LON-CAPA-cvs] cvs: modules /raeburn Enrollment.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 04 Dec 2003 17:02:53 -0000
This is a MIME encoded message
--raeburn1070557373
Content-Type: text/plain
raeburn Thu Dec 4 12:02:53 2003 EDT
Modified files:
/modules/raeburn Enrollment.pm
Log:
Changes to the way the CL_TYPE attribute is set for user records in classlist.db - either to auto (if user is being added from institutional classlist, or blank if user's role is being expired because user has vanished from institutional classlist).
--raeburn1070557373
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20031204120253.txt"
Index: modules/raeburn/Enrollment.pm
diff -u modules/raeburn/Enrollment.pm:1.1 modules/raeburn/Enrollment.pm:1.2
--- modules/raeburn/Enrollment.pm:1.1 Mon Dec 1 19:32:39 2003
+++ modules/raeburn/Enrollment.pm Thu Dec 4 12:02:53 2003
@@ -22,10 +22,12 @@
my $currlist;
foreach my $uname (keys %{$roster} ) {
if ($uname =~ m/^(.+):$dom$/) {
- push @localstudents, $1;
- @{$$currlist{$1}} = @{$$roster{$uname}};
+ if ($$roster{$uname}[$status] eq "Active") {
+ push @localstudents, $1;
+ @{$$currlist{$1}} = @{$$roster{$uname}};
+ }
}
- }
+ }
my $linefeed = '';
my $addresult = '';
my $dropresult = '';
@@ -89,7 +91,6 @@
for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
my @stuinfo = @{$allenrolled{$uname}[$i]};
my $secnum = $stuinfo[ $place{'groupID'} ];
- print STDERR "Section $secnum for $uname\n";
unless ($secnum eq '') {
unless (grep/^$secnum$/,@sections) {
$saved = $i;
@@ -121,8 +122,8 @@
# Get mapping of student IDs to usernames for users in institutional data for this class
my @allINids = ();
foreach my $uname (@okusers) {
- my @stuinfo = @{$enrollinfo{$uname}};
- my $stuID = $stuinfo[ $place{'studentID'} ];
+ $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
+ my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
if (grep/^$stuID$/,@allINids) {
push @{$unameFromINid{$stuID}},$uname;
} else {
@@ -144,11 +145,11 @@
# Check for section changes
unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
- print STDERR "Found a section difference for $uname - ".$$currlist{$uname}[$sec] ."versus ".$stuinfo[ $place{groupID} ]."\n";
+ $logmsg .= "Found a section difference for $uname - ".$$currlist{$uname}[$sec] ."versus ".$stuinfo[ $place{groupID} ]." in class $crs\n";
if ($$currlist{$uname}[$type] eq "auto") {
- my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],$nowtime,undef,undef,undef,undef);
+ my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],$nowtime,undef,undef,undef,undef,'auto');
if ($modify_section_result !~ /^ok/) {
- $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec]\n";
+ $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $modify_section_result\n";
}
# Assign the role of student in the new section
@@ -157,8 +158,7 @@
if ($stuinfo[$sec]) {
$uurl.='/'.$stuinfo[$sec];
}
- print STDERR "Section is $uurl\n";
- &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$stuinfo[$end],$stuinfo[ $place{start} ],"auto");
+ &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$stuinfo[$end],$stuinfo[ $place{start} ]);
}
}
}
@@ -218,7 +218,7 @@
# If no account exists and passwords should be generated
if (($authtype eq "int") || ($authtype eq "loc")) {
($passwd,$create_passwd) = &create_password($authtype); }
- } elsif ($authtype eq "krb") {
+ } elsif ($authtype =~ m/^krb/) {
$passwd = $autharg;
} else {
$logmsg .= "Invalid authentication type for $uname in $crs\n";
@@ -245,7 +245,6 @@
} else {
$logmsg .= "An error occurred adding new user $uname - $reply\n";
}
-# Add 'auto' status to classlist.db file
} else {
# Get the user's information and authentication
my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification'],$dom,$uname);
@@ -293,19 +292,29 @@
$changeHash{'middlename'} = $middle;
$changeHash{'lastname'} = $last;
$changeHash{'generation'} = $gene;
+ $changeHash{'id'} = $pid;
my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
if ($putresult eq 'ok') {
$logmsg .= "User: $uname enrolled in $crs\n";
# Assign the role of student
- my $uurl='/'.$cid;
- $uurl=~s/\_/\//g;
- if ($usec) {
- $uurl.='/'.$usec;
+ $classlist_reply = &modify_student_enrollment($$configvars{'lonHostID'},$dom,$cid,$crs,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto');
+ if ($classlist_reply eq 'ok') {
+ my $uurl='/'.$cid;
+ $uurl=~s/\_/\//g;
+ if ($usec) {
+ $uurl.='/'.$usec;
+ }
+ &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$enddate,$startdate);
+ $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
+ $enrollcount ++;
+ $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
+ $logmsg .= "Existing user $uname enrolled successfully in $crs\n";
+
+ } else {
+ $logmsg .= "There was a problem updating the classlist db file for user $uname to show the new enrollment, so no enrollment occurred in $crs\n";
}
- &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$enddate,$startdate);
- $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
- $enrollcount ++;
-# Add 'auto' status to classlist.db file -this is already done.
+ } else {
+ $logmsg .= "There was a problem modifying user data for existing user - $uname, so no enrollment occurred in $crs.\n";
}
}
}
@@ -324,15 +333,15 @@
$logmsg .= "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}[ $place{studentID} ]. 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";
push @saved,$uname;
}
- }
- } elsif (@saved == 0) {
- my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],$nowtime,undef,undef,undef,undef);
- if ($modify_section_result !~ /^ok/) {
- $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec]\n";
- } else {
- $dropcount ++;
- my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
- $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname." dropped from section/group ".$$currlist{$uname}[$sec].$linefeed;
+ } elsif (@saved == 0) {
+ my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,undef);
+ if ($drop_reply !~ /^ok/) {
+ $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $drop_reply\n";
+ } else {
+ $dropcount ++;
+ my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
+ $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname." dropped from section/group ".$$currlist{$uname}[$sec].$linefeed;
+ }
}
}
}
@@ -373,8 +382,7 @@
}
sub modifystudent {
- my ($hostID,$udom,$cid,$crs,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec,
- $end,$start,$forceid,$desiredhome,$email,$type,$context)=@_;
+ my ($hostID,$udom,$cid,$crs,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec,$end,$start,$forceid,$desiredhome,$email,$type,$context)=@_;
# --------------------------------------------------------------- Make the user
my $reply=&Apache::lonnet::modifyuser
($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$forceid,
@@ -383,7 +391,7 @@
# This will cause &modify_student_enrollment to get the uid from the
# students environment
$uid = undef if (!$forceid);
- if ($context eq "adsgsasa") {
+ if ($context eq "dadagrrg") {
$reply = &Apache::lonnet::modify_student_enrollment($udom,$cid,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type);
} else {
$reply = &modify_student_enrollment($hostID,$udom,$cid,$crs,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type);
@@ -420,7 +428,7 @@
$uid = $tmp{'id'} if (!defined($uid) || $uid eq '');
}
my $fullname = &Apache::loncoursedata::ProcessFullName($last,$gene,$first,$middle);
- my $reply=&Apache::lonnet::critical('put:'.$udom.':'.$crs.':classlist:'.&Apache::lonnet::escape($uname.':'.$udom).'='.&Apache::lonnet::escape(join(':',$end,$start,$uid,$usec,$fullname,,$type)),$hostID);
+ my $reply=&Apache::lonnet::critical('put:'.$udom.':'.$crs.':classlist:'.&Apache::lonnet::escape($uname.':'.$udom).'='.&Apache::lonnet::escape(join(':',$end,$start,$uid,$usec,$fullname,$type)),$hostID);
unless (($reply eq 'ok') || ($reply eq 'delayed')) {
return 'error: '.$reply;
}
@@ -437,8 +445,7 @@
sub parse_classlist {
my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
my $configvars = &LONCAPA::Configuration::read_conf();
- my $xmlfile = "/tmp/".$dom."_".$crs."_classlist.xml";
-# my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";
+ my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";
my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] );
foreach my $uname ( sort keys %{$$enrolled{'student'}} ) {
@{ $$studentsref{$uname} } = ();
--raeburn1070557373--