--- loncom/enrollment/Enrollment.pm 2003/12/05 17:04:37 1.1 +++ loncom/enrollment/Enrollment.pm 2003/12/05 19:07:19 1.4 @@ -123,6 +123,7 @@ sub update_LC { } # Get mapping of student IDs to usernames for users in institutional data for this class my @allINids = (); + my %unameFromINid = (); foreach my $uname (@okusers) { $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/; my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ]; @@ -148,8 +149,8 @@ sub update_LC { # Check for section changes unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) { $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,'auto',$cid); + if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) { + my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto',$cid); if ($modify_section_result !~ /^ok/) { $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $modify_section_result\n"; } @@ -161,14 +162,17 @@ sub update_LC { $uurl.='/'.$stuinfo[ $place{groupID} ]; } my $newend = $stuinfo[ $place{enddate} ]; - my $newstart = $stuinfo[ $place{startdate} ]); + my $newstart = $stuinfo[ $place{startdate} ]; if ($newend eq '') { - $end = $enddate; + $newend = $enddate; } if ($newstart eq '') { - $start = $startdate; + $newstart = $startdate; } + #explicitly allow acces to creating students + $ENV{'allowed.cst'}='F'; &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$newend,$newstart); + delete($ENV{'allowed.cst'}); } } } @@ -209,6 +213,9 @@ sub update_LC { if ($authparam eq '') { $authparam = $autharg; } + if ($auth =~ m/^krb/) { + $auth .= ":".$authparam; + } if ($end eq '') { $end = $enddate; } @@ -223,37 +230,49 @@ sub update_LC { # Check for existing account in this LON-CAPA domain for this username my $uhome=&Apache::lonnet::homeserver($uname,$dom); if ($uhome eq 'no_host') { # User does not exist - $create_passwd = 0; - if ($passwd eq '') { + my $create_passwd = 0; + my $authchk = ''; + unless ($authparam eq '') { $authchk = 'ok'; }; # If no account exists and passwords should be generated - if (($authtype eq "int") || ($authtype eq "loc")) { - ($passwd,$create_passwd) = &create_password($authtype); } - } elsif ($authtype =~ m/^krb/) { - $passwd = $autharg; - } else { - $logmsg .= "Invalid authentication type for $uname in $crs\n"; - } - } -# 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') { - $enrollcount ++; - $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed; - $logmsg .= "New user $uname added successfully. "; - unless ($emailenc eq '') { - my %emailHash; - $emailHash{'critnotification'} = $emailenc; - $emailHash{'notification'} = $emailenc; - my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname); + if ($authtype eq "int") { + if ($authparam eq '') { + ($authparam,$create_passwd,$authchk) = &create_password(); + } + } elsif ($authtype eq "local") { + if ($authparam eq '') { + ($authparam,$create_passwd,$authchk) = &create_password(); + } + } elsif ($authtype =~ m/^krb/) { + if ($authparam eq '') { + $logmsg .= "No Kerberos domain available for the new user - $uname in course $crs - no enrollment occurred.\n"; + $authchk = 'invalid'; } - if ($create_passwd) { + } else { + $authchk = 'invalid'; + $logmsg .= "Invalid authentication type for new user - $uname in course $crs - no enrollment occurred.\n"; + } + unless ($authchk eq 'ok') { +# 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') { + $enrollcount ++; + $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed; + $logmsg .= "New user $uname added successfully. "; + unless ($emailenc eq '') { + my %emailHash; + $emailHash{'critnotification'} = $emailenc; + $emailHash{'notification'} = $emailenc; + my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname); + } + if ($create_passwd) { # Send e-mail with inital password to new user at $emailaddr - $logmsg .= "Initial password - - sent to $emailaddr\n"; + $logmsg .= "Initial password - - sent to $emailaddr\n"; + } else { + $logmsg .= "\n"; + } } else { - $logmsg .= "\n"; + $logmsg .= "An error occurred adding new user $uname - $reply\n"; } - } else { - $logmsg .= "An error occurred adding new user $uname - $reply\n"; } } else { # Get the user's information and authentication @@ -265,7 +284,8 @@ sub update_LC { # Get the user's e-mail address if ($userenv{critnotification} =~ m/%40/) { unless ($emailenc eq $userenv{critnotification}) { - $logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - $emailenc\n"; + $logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - $emailenc\n"; + } } if ($userenv{notification} =~ m/%40/) { unless ($emailenc eq $userenv{critnotification}) { @@ -305,28 +325,22 @@ sub update_LC { $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 - $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"; - } + $logmsg .= "User information updated for user: $uname prior to enrollment in $crs\n"; } else { - $logmsg .= "There was a problem modifying user data for existing user - $uname, so no enrollment occurred in $crs.\n"; + $logmsg .= "There was a problem modifying user data for existing user - $uname, enrollment will still be attempted for user in $crs.\n"; } } + +# 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') { + $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 for this user in $crs\n"; + } } } } @@ -392,34 +406,34 @@ sub update_LC { } sub parse_classlist { - my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_; - my $configvars = &LONCAPA::Configuration::read_conf(); - my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml"; - my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] ); - foreach my $uname ( sort keys %{$$enrolled{'student'}} ) { - @{ $$studentsref{$uname} } = (); - foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) { - my $value = $$enrolled{'student'}{$uname}{$key}; - if (ref($value)) { - $$studentsref{$uname}[ $$placeref{$key} ] = ''; - } else { - if ($key eq 'groupID') { - $$studentsref{$uname}[ $$placeref{$key} ] = $groupID; - } else { - $$studentsref{$uname}[ $$placeref{$key} ] = $value; - } - } - } - } -# if (-e "$xmlfile") { -# unlink $xmlfile; -# } - return; + my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_; + my $configvars = &LONCAPA::Configuration::read_conf(); + my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml"; + my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] ); + foreach my $uname ( sort keys %{$$enrolled{'student'}} ) { + @{ $$studentsref{$uname} } = (); + foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) { + my $value = $$enrolled{'student'}{$uname}{$key}; + if (ref($value)) { + $$studentsref{$uname}[ $$placeref{$key} ] = ''; + } else { + if ($key eq 'groupID') { + $$studentsref{$uname}[ $$placeref{$key} ] = $groupID; + } else { + $$studentsref{$uname}[ $$placeref{$key} ] = $value; + } + } + } + } +# if (-e "$xmlfile") { +# unlink $xmlfile; +# } + return; } sub create_password { - - + my ($authparam,$create_passwd,$authreply); + return ($authparam,$create_passwd,$authreply); } sub CL_autharg { return 0; }