Diff for /loncom/enrollment/Enrollment.pm between versions 1.2 and 1.4

version 1.2, 2003/12/05 17:31:40 version 1.4, 2003/12/05 19:07:19
Line 123  sub update_LC { Line 123  sub update_LC {
     }      }
 # Get mapping of student IDs to usernames for users in institutional data for this class    # Get mapping of student IDs to usernames for users in institutional data for this class  
     my @allINids = ();      my @allINids = ();
       my %unameFromINid = ();
     foreach my $uname (@okusers) {      foreach my $uname (@okusers) {
         $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;          $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
         my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];          my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
Line 148  sub update_LC { Line 149  sub update_LC {
 # Check for section changes  # Check for section changes
             unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {              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";                  $logmsg .= "Found a section difference for $uname - ".$$currlist{$uname}[$sec] ."versus ".$stuinfo[ $place{groupID} ]." in class $crs\n";
                 if ($$currlist{$uname}[$type] eq "auto") {                  if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
                     my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],$nowtime,undef,undef,undef,undef,'auto',$cid);                      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/) {                      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";                          $logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $modify_section_result\n";
                     }                      }
Line 163  sub update_LC { Line 164  sub update_LC {
                     my $newend = $stuinfo[ $place{enddate} ];                      my $newend = $stuinfo[ $place{enddate} ];
                     my $newstart = $stuinfo[ $place{startdate} ];                      my $newstart = $stuinfo[ $place{startdate} ];
                     if ($newend eq '') {                      if ($newend eq '') {
                         $end = $enddate;                          $newend = $enddate;
                     }                      }
                     if ($newstart eq '') {                      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);                       &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$newend,$newstart); 
       delete($ENV{'allowed.cst'});
                 }                  }
             }              }
         }          }
Line 209  sub update_LC { Line 213  sub update_LC {
                 if ($authparam eq '') {                  if ($authparam eq '') {
                     $authparam = $autharg;                      $authparam = $autharg;
                 }                  }
                   if ($auth =~ m/^krb/) {
                       $auth .= ":".$authparam;
                   }
                 if ($end eq '') {                  if ($end eq '') {
                     $end = $enddate;                      $end = $enddate;
                 }                  }
Line 223  sub update_LC { Line 230  sub update_LC {
 # Check for existing account in this LON-CAPA domain for this username  # Check for existing account in this LON-CAPA domain for this username
                 my $uhome=&Apache::lonnet::homeserver($uname,$dom);                  my $uhome=&Apache::lonnet::homeserver($uname,$dom);
                 if ($uhome eq 'no_host') { # User does not exist                  if ($uhome eq 'no_host') { # User does not exist
                     $create_passwd = 0;                      my $create_passwd = 0;
                     if ($passwd eq '') {                      my $authchk = '';
                       unless ($authparam eq '') { $authchk = 'ok'; };
 # If no account exists and passwords should be generated  # If no account exists and passwords should be generated
                         if (($authtype eq "int") || ($authtype eq "loc")) {                      if ($authtype eq "int") {
                             ($passwd,$create_passwd) = &create_password($authtype); }                          if ($authparam eq '') {
                         } elsif ($authtype =~ m/^krb/) {                              ($authparam,$create_passwd,$authchk) = &create_password();
                             $passwd = $autharg;                          }
                         } else {                      } elsif ($authtype eq "local") {
                             $logmsg .= "Invalid authentication type for $uname in $crs\n";                          if ($authparam eq '') {
                         }                                ($authparam,$create_passwd,$authchk) = &create_password();
                     }                          }
 # Now create user.                      } elsif ($authtype =~ m/^krb/) {
                     my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);                          if ($authparam eq '') {
                     if ($reply eq 'ok') {                              $logmsg .= "No Kerberos domain available for the new user - $uname in course $crs - no enrollment occurred.\n";
                         $enrollcount ++;                              $authchk = 'invalid';
                         $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) {                      } 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  # 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 {                          } 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 {                  } else {
 # Get the user's information and authentication  # Get the user's information and authentication
Line 265  sub update_LC { Line 284  sub update_LC {
 # Get the user's e-mail address  # Get the user's e-mail address
                     if ($userenv{critnotification} =~ m/%40/) {                      if ($userenv{critnotification} =~ m/%40/) {
                         unless ($emailenc eq $userenv{critnotification}) {                          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/) {                      if ($userenv{notification} =~ m/%40/) {
                         unless ($emailenc eq $userenv{critnotification}) {                          unless ($emailenc eq $userenv{critnotification}) {
Line 305  sub update_LC { Line 325  sub update_LC {
                         $changeHash{'id'} = $pid;                          $changeHash{'id'} = $pid;
                         my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);                          my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
                         if ($putresult eq 'ok') {                          if ($putresult eq 'ok') {
                             $logmsg .= "User: $uname enrolled in $crs\n";                               $logmsg .= "User information updated for user: $uname prior to enrollment 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";  
                             }  
                         } else {                          } 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";
                       }
                 }                  }
             }              }
         }          }
Line 392  sub update_LC { Line 406  sub update_LC {
 }   } 
   
 sub parse_classlist {  sub parse_classlist {
   my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;                  my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;            
   my $configvars = &LONCAPA::Configuration::read_conf();      my $configvars = &LONCAPA::Configuration::read_conf();
   my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";      my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";
   my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] );      my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] );
   foreach my $uname ( sort keys %{$$enrolled{'student'}} ) {      foreach my $uname ( sort keys %{$$enrolled{'student'}} ) {
       @{ $$studentsref{$uname} } = ();          @{ $$studentsref{$uname} } = ();
       foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) {          foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) {
           my $value = $$enrolled{'student'}{$uname}{$key};              my $value = $$enrolled{'student'}{$uname}{$key};
           if (ref($value)) {              if (ref($value)) {
               $$studentsref{$uname}[ $$placeref{$key} ] = '';                  $$studentsref{$uname}[ $$placeref{$key} ] = '';
           } else {              } else {
               if ($key eq 'groupID') {                  if ($key eq 'groupID') {
                   $$studentsref{$uname}[ $$placeref{$key} ] = $groupID;                      $$studentsref{$uname}[ $$placeref{$key} ] = $groupID;
               } else {                  } else {
                   $$studentsref{$uname}[ $$placeref{$key} ] = $value;                      $$studentsref{$uname}[ $$placeref{$key} ] = $value;
               }                  }
           }              }
       }          }
   }      }
 #  if (-e "$xmlfile") {  #    if (-e "$xmlfile") {
 #      unlink $xmlfile;  #        unlink $xmlfile;
 #  }  #    }
   return;      return;
 }  }
   
 sub create_password {  sub create_password {
       my ($authparam,$create_passwd,$authreply);
       return ($authparam,$create_passwd,$authreply);
 }  }
   
 sub CL_autharg { return 0; }  sub CL_autharg { return 0; }

Removed from v.1.2  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>