--- loncom/enrollment/Enrollment.pm 2004/03/18 16:46:28 1.12 +++ loncom/enrollment/Enrollment.pm 2004/06/17 18:31:24 1.15 @@ -1,5 +1,5 @@ # Automated Enrollment manager -# $Id: Enrollment.pm,v 1.12 2004/03/18 16:46:28 raeburn Exp $ +# $Id: Enrollment.pm,v 1.15 2004/06/17 18:31:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,12 +49,19 @@ sub update_LC { my $status=&Apache::loncoursedata::CL_STATUS; my $type=&Apache::loncoursedata::CL_TYPE; my @localstudents = (); + my @futurestudents = (); + my @activestudents = (); my $currlist; foreach my $uname (keys %{$roster} ) { if ($uname =~ m/^(.+):$dom$/) { if ($$roster{$uname}[$status] eq "Active") { + push @activestudents, $1; + @{$$currlist{$1}} = @{$$roster{$uname}}; push @localstudents, $1; + } elsif ( ($$roster{$uname}[$cstart] > time) && ($$roster{$uname}[$cend] > time || $$roster{$uname}[$cend] == 0 || $$roster{$uname}[$cend] eq '') ) { + push @futurestudents, $1; @{$$currlist{$1}} = @{$$roster{$uname}}; + push @localstudents, $1; } } } @@ -174,6 +181,7 @@ sub update_LC { unless ($uname eq '') { my %uidhash=&Apache::lonnet::idrget($dom,$uname); my @stuinfo = @{$enrollinfo{$uname}}; + my $access = ''; if (grep/^$uname$/,@localstudents) { # Check for studentID changes if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) ) { @@ -181,9 +189,34 @@ sub update_LC { $$logmsg .= "Change in ID for $uname. StudentID in LON-CAPA system is $uidhash{$uname}; StudentID in institutional data is $stuinfo[ $place{studentID} ]".$linefeed; } } - # Check for section changes - unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) { + if ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) { +# Check for access date changes for students with access starting in the future. + if ( (grep/^$uname$/,@futurestudents) && ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) { + my $datechange = 0; + unless ($$currlist{$uname}[$cstart] eq $startdate) { + $datechange = 1; + } + if (!$datechange) { + if (!$$currlist{$uname}[$cend]) { + if ($enddate) { + $datechange = 1; + } + } elsif ($$currlist{$uname}[$cend] ne $enddate) { + $datechange = 1; + } + } + if ($datechange) { + my $modify_access_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto',$cid); + $access = &showaccess($enddate,$startdate); + if ($modify_access_result =~ /^ok/) { + $$logmsg .= "Change in access dates for $uname.".$access.$linefeed; + } else { + $$logmsg .= "Error when attempting to change start and/or end access dates for $uname in section: ".$stuinfo[ $place{groupID} ]." -error $modify_access_result".$linefeed; + } + } + } + } else { if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) { # Delete from roles.db for current section my $expiretime = time; @@ -194,9 +227,15 @@ sub update_LC { } my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime); if ($expire_role_result eq 'ok') { - my $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$$currlist{$uname}[$cend],$$currlist{$uname}[$cstart],'auto',$cid); + my $modify_section_result; + if (grep/^$uname$/,@activestudents) { + $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$$currlist{$uname}[$cend],$$currlist{$uname}[$cstart],'auto',$cid); + } else { + $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto',$cid); + $access = &showaccess($enddate,$startdate); + } if ($modify_section_result =~ /^ok/) { - $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$linefeed; + $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$access.$linefeed; } else { $$logmsg .= "Error when attempting section change for $uname from old section ".$$currlist{$uname}[$sec]." to new section: ".$stuinfo[ $place{groupID} ]." -error: $modify_section_result".$linefeed; } @@ -233,7 +272,7 @@ sub update_LC { $usec =~ s/\W//g; unless ($emailaddr =~/^[^\@]+\@[^\@]+$/) { $emailaddr =''; } - my $emailenc = &HTML::Entities::encode($emailaddr); + my $emailenc = &HTML::Entities::encode($emailaddr,'<>&"'); # Use course defaults where entry is absent if ( ($auth eq '') || (!defined($auth)) ) { @@ -285,8 +324,9 @@ sub update_LC { # Now create user. my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid); if ($reply eq 'ok') { + $access = &showaccess($end,$start); $enrollcount ++; - $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed; + $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$access.$linefeed; if ($context eq 'automated') { $$logmsg .= "New $dom user $uname added successfully."; } @@ -354,6 +394,7 @@ sub update_LC { if ($krbdefdom ne $authparam) { $$logmsg .= "Kerberos domain mismatch for $uname - '$krbdefdom' in system, '$authparam' based on information in classlist or default for this course.".$linefeed; } + } # Check user data if ($first ne $userenv{'firstname'} || @@ -379,8 +420,9 @@ sub update_LC { # Assign the role of student in the course. my $classlist_reply = &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto',$cid); if ($classlist_reply eq 'ok') { + $access = &showaccess($end,$start); $enrollcount ++; - $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed; + $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$access.$linefeed; if ($context eq 'automated') { $$logmsg .= "Existing $dom user $uname enrolled successfully.".$linefeed; } @@ -405,7 +447,7 @@ sub update_LC { push @saved,$uname; } } elsif (@saved == 0) { - my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,undef,$cid); + my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto',$cid); if ($drop_reply !~ /^ok/) { $$logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $drop_reply.".$linefeed; } else { @@ -462,6 +504,24 @@ sub update_LC { return ($changecount,$addresult.$dropresult); } +sub showaccess { + my ($end,$start) = @_; + my $showstart; + my $showend; + if ( (!$start) || ($start <= time) ) { + $showstart = 'immediately'; + } else { + $showstart = &Apache::lonlocal::locallocaltime($start); + } + if (!$end) { + $showend = 'no end date'; + } else { + $showend = &Apache::lonlocal::locallocaltime($end); + } + my $access_msg = " Access starts: ".$showstart.", ends: ".$showend."."; + return $access_msg; +} + sub parse_classlist { my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_; my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";