--- loncom/enrollment/Enrollment.pm 2003/12/11 03:26:15 1.8 +++ loncom/enrollment/Enrollment.pm 2004/03/18 16:46:28 1.12 @@ -1,5 +1,5 @@ # Automated Enrollment manager -# $Id: Enrollment.pm,v 1.8 2003/12/11 03:26:15 raeburn Exp $ +# $Id: Enrollment.pm,v 1.12 2004/03/18 16:46:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -185,11 +185,23 @@ sub update_LC { # Check for section changes unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) { if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) { - 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); - if ($modify_section_result =~ /^ok/) { - $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$linefeed; +# Delete from roles.db for current section + my $expiretime = time; + my $uurl='/'.$cid; + $uurl=~s/\_/\//g; + if ($$currlist{$uname}[$sec]) { + $uurl.='/'.$$currlist{$uname}[$sec]; + } + 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); + if ($modify_section_result =~ /^ok/) { + $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$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; + } } 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; + $$logmsg .= "Error when attempting to expire role for $uname in old section" .$$currlist{$uname}[$sec]." -error: $expire_role_result".$linefeed; } } } @@ -230,9 +242,6 @@ sub update_LC { if ( ($authparam eq '') || (!defined($authparam)) ) { $authparam = $autharg; } - if ($auth =~ m/^krb/) { - $auth .= ":".$authparam; - } if ( ($end eq '') || (!defined($end)) ) { $end = $enddate; } @@ -251,18 +260,19 @@ sub update_LC { my $authchk = ''; unless ($authparam eq '') { $authchk = 'ok'; }; # If no account exists and passwords should be generated - if ($authtype eq "int") { + if ($auth eq "internal") { if ($authparam eq '') { ($authparam) = &create_password(); if ($authparam eq '') { - $authchk = ''; + $authchk = ''; } else { $create_passwd = 1; + $authchk = 'ok'; } } - } elsif ($authtype eq "local") { - ($authparam,$create_passwd,$authchk) = &localenroll::create_password($authparam); - } elsif ($authtype =~ m/^krb/) { + } elsif ($auth eq "localauth") { + ($authparam,$create_passwd,$authchk) = &localenroll::create_password($authparam); + } elsif ($auth =~ m/^krb/) { if ($authparam eq '') { $$logmsg .= "No Kerberos domain was provided for the new user - $uname, so the new student was not enrolled in the course.".$linefeed; $authchk = 'invalid'; @@ -329,22 +339,22 @@ sub update_LC { } my $krbdefdom = ''; my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom); - if ($currentauth=~/^krb(4|5):/) { - $currentauth=~/^krb(4|5):(.*)/; - $krbdefdom=$1; - } - if ($currentauth=~/^krb(4|5):/ || - $currentauth=~/^unix:/ || - $currentauth=~/^internal:/ || - $currentauth=~/^localauth:/) { - + if ($currentauth=~/^(krb[45]):(.*)/) { + $currentauth = $1; + $krbdefdom = $2; + } elsif ($currentauth=~ /^(unix|internal|localauth):/) { + $currentauth = $1; } else { $$logmsg .= "Invalid authentication method $currentauth for $uname.".$linefeed; } # Report if authentication methods are different. - if ($currentauth ne $auth ) { - $$logmsg .= "Authentication mismatch for $uname - $currentauth in system, $auth based on information in classlist or default for this course.".$linefeed; - } + if ($currentauth ne $auth) { + $$logmsg .= "Authentication type mismatch for $uname - '$currentauth' in system, '$auth' based on information in classlist or default for this course.".$linefeed; + } elsif ($auth =~ m/^krb/) { + 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'} || $middle ne $userenv{'middlename'} || @@ -527,7 +537,7 @@ sub process_date { sub create_password { my $passwd = ''; - my @letts = "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"; + my @letts = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); for (my $i=0; $i<8; $i++) { my $lettnum = int (rand 2); my $item = ''; @@ -545,6 +555,44 @@ sub create_password { return ($passwd); } +sub check_user_status { + my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_; + my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname); + my @uroles = keys %userinfo; + my $srchstr; + my $active_chk = 'none'; + if (@uroles > 0) { + if ( ($role eq 'cc') || ($secgrp eq '') || ( !defined($secgrp) ) ) { + $srchstr = '/'.$cdom.'/'.$crs.'_'.$role; + } else { + $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role; + } + if (grep/^$srchstr$/,@uroles) { + my $role_end = 0; + my $role_start = 0; + $active_chk = 'ok'; + if ( $userinfo{$srchstr} =~ m/^($role)_(\d+)/ ) { + $role_end = $2; + if ( $userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/ ) + { + $role_start = $3; + } + } + if ($role_start > 0) { + if (time < $role_start) { + $active_chk = 'expired'; + } + } + if ($role_end > 0) { + if (time > $role_end) { + $active_chk = 'expired'; + } + } + } + } + return $active_chk; +} + sub CL_autharg { return 0; } sub CL_authtype { return 1;} sub CL_email { return 2;}