--- loncom/enrollment/Enrollment.pm 2006/02/07 16:20:49 1.29 +++ loncom/enrollment/Enrollment.pm 2010/08/20 21:44:59 1.43 @@ -1,5 +1,5 @@ # Automated Enrollment manager -# $Id: Enrollment.pm,v 1.29 2006/02/07 16:20:49 albertel Exp $ +# $Id: Enrollment.pm,v 1.43 2010/08/20 21:44:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,6 +27,7 @@ package LONCAPA::Enrollment; use Apache::loncoursedata; use Apache::lonnet; +use Apache::loncommon(); use Apache::lonmsg; use Apache::lonlocal; use HTML::Entities; @@ -91,9 +92,17 @@ sub update_LC { open(FILE,"<$$configvars{'lonTabDir'}.'/rolesplain.tab"); my @rolesplain = ; close(FILE); - foreach (@rolesplain) { - if ($_ =~ /^(st|ta|ex|ad|in|cc):([\w\s]+)$/) { - $longroles{$1} = $2; + foreach my $item (@rolesplain) { + if ($_ =~ /^(st|ta|ex|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) { + if ($courseinfo{'type'} eq 'Community') { + unless($1 eq 'cc') { + $longroles{$1} = $3; + } + } else { + unless($1 eq 'co') { + $longroles{$1} = $2; + } + } } } @@ -114,18 +123,7 @@ sub update_LC { # Get latest institutional enrollment for this class. my %allenrolled = (); my @reg_students = (); - my %place = (); - $place{'autharg'} = &CL_autharg(); - $place{'authtype'} = &CL_authtype(); - $place{'email'} = &CL_email(); - $place{'enddate'} = &CL_enddate(); - $place{'firstname'} = &CL_firstname(); - $place{'generation'} = &CL_generation(); - $place{'groupID'} = &CL_groupID(); - $place{'lastname'} = &CL_lastname(); - $place{'middlename'} = &CL_middlename(); - $place{'startdate'} = &CL_startdate(); - $place{'studentID'} = &CL_studentID(); + my %place = &place_hash(); my %ucount = (); my %enrollinfo = (); foreach my $class (@{$classesref}) { @@ -146,7 +144,7 @@ sub update_LC { my @okusers = (); foreach my $uname (@reg_students) { if (grep/^$uname$/,@excludedstudents) { - $$logmsg .= "No re-enrollment for $uname - user was previously manually unenrolled and locked.".$linefeed; + $$logmsg .= &mt('No re-enrollment for [_1] - user was previously manually unenrolled and locked.',$uname).$linefeed; } elsif (@{$allenrolled{$uname}} > 1) { my @sections = (); my $saved; @@ -169,19 +167,19 @@ sub update_LC { push @okusers, $uname; } elsif (@sections > 1) { - $$logmsg .= "$uname appears in classlists for more than one section of this course, i.e. in sections: "; + $$logmsg .= &mt('[_1] appears in classlists for more than one section of this course, i.e. in sections: ',$uname); foreach (@sections) { $$logmsg .= " $_,"; } chop($$logmsg); - $$logmsg .= ". Because of this ambiguity, no enrollment action was taken for this student.".$linefeed; + $$logmsg .= '. '.&mt('Because of this ambiguity, no enrollment action was taken for this student.').$linefeed; } } else { @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]}; push @okusers, $uname; } } -# Get mapping of student IDs to usernames for users in institutional data for this class +# Get mapping of student/employee IDs to usernames for users in institutional data for this class my @allINids = (); my %unameFromINid = (); foreach my $uname (@okusers) { @@ -210,24 +208,32 @@ sub update_LC { # Check for studentID changes if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) ) { unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) { - $$logmsg .= "Change in ID for $uname. StudentID in LON-CAPA system is $uidhash{$uname}; StudentID in institutional data is $stuinfo[ $place{studentID} ]".$linefeed; + $$logmsg .= &mt('Change in ID for [_1]. StudentID in LON-CAPA system is [_2]; StudentID in institutional data is [_3].',$uname,$uidhash{$uname},$stuinfo[ $place{studentID} ]).$linefeed; } } # Check for switch from manual to auto unless (($$currlist{$uname}[$type] eq "auto") || ($$currlist{$uname}[$lockedtype] eq "1") || (!$adds) ) { # drop manually added student - my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid); + my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid,'',$context); # re-enroll as auto student if ($drop_reply !~ /^ok/) { - $$logmsg .= "An error occured during the attempt to convert $uname from a manual type to an auto type student - $drop_reply.".$linefeed; + $$logmsg .= &mt('An error occured during the attempt to convert [_1] from a manual type to an auto type student - [_2].',$uname,$drop_reply).$linefeed; } else { # re-enroll as auto student my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc); &prepare_add($authtype,$autharg,$enddate,$startdate,\@stuinfo,\%place,\$dom,\$uname,\$auth,\$authparam,\$first,\$middle,\$last,\$gene,\$usec,\$end,\$start,\$emailaddr,\$pid,\$emailenc); if ($$currlist{$uname}[$sec] ne $usec) { - $switchresult .= "Section for $uname switched from $$currlist{$uname}[$sec] to ".$usec.$linefeed; + my $showoldsec = $$currlist{$uname}[$sec]; + if ($$currlist{$uname}[$sec] eq '') { + $showoldsec = &mt('none'); + } + my $showsec = $usec; + if ($usec eq '') { + $showsec = &mt('none'); + } + $switchresult .= &mt("Section for [_1] switched from '[_2]' to '[_3]'.",$uname,$showoldsec,$showsec).$linefeed; if ($context eq 'automated') { - $$logmsg .= "Section switch for $uname from $$currlist{$uname}[$sec] to ".$usec.$linefeed; ; + $$logmsg .= &mt("Section switch for [_1] from '[_2]' to '[_3]'.",$uname,$showoldsec,$usec).$linefeed; } $switchcount ++; } @@ -240,12 +246,12 @@ sub update_LC { if ( (grep/^$uname$/,@futurestudents) && ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) { my $datechange = &datechange_check($$currlist{$uname}[$cstart],$$currlist{$uname}[$cend],$startdate,$enddate); 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); + my $modify_access_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context); $access = &showaccess($enddate,$startdate); if ($modify_access_result =~ /^ok/) { - $$logmsg .= "Change in access dates for $uname.".$access.$linefeed; + $$logmsg .= &mt('Change in access dates for [_1].',$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; + $$logmsg .= &mt('Error when attempting to change start and/or end access dates for [_1] in section: [_2] -error [_3].',$uname,$stuinfo[$place{groupID}],$modify_access_result).$linefeed; } } } @@ -258,26 +264,26 @@ sub update_LC { if ($$currlist{$uname}[$sec]) { $uurl.='/'.$$currlist{$uname}[$sec]; } - my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime); + my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime,'','','',$context); if ($expire_role_result eq 'ok') { 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); + $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,'',$context); } else { - $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid); + $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context); $access = &showaccess($enddate,$startdate); } if ($modify_section_result =~ /^ok/) { - $switchresult .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$access.$linefeed; + $switchresult .= &mt("Section for [_1] switched from old section: '[_2]' to new section: '[_3]'.",$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$access.$linefeed; if ($context eq 'automated') { - $$logmsg .= "Section switch for $uname from $$currlist{$uname}[$sec] to $stuinfo[ $place{groupID} ]".$linefeed; + $$logmsg .= &mt('Section switch for [_1] from [_2] to [_3]',$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$linefeed; } $switchcount ++; } 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 .= &mt("Error when attempting section change for [_1], from old section: '[_2]' to new section: '[_3]' -error: [_4]",$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ],$modify_section_result).$linefeed; } } else { - $$logmsg .= "Error when attempting to expire role for $uname in old section" .$$currlist{$uname}[$sec]." -error: $expire_role_result".$linefeed; + $$logmsg .= &mt("Error when attempting to expire role for [_1] in old section: '[_2]' -error: '[_3]'.",$uname,$$currlist{$uname}[$sec],$expire_role_result).$linefeed; } } } @@ -285,15 +291,15 @@ sub update_LC { # Check for changed usernames by checking studentIDs if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) { foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } } ) { - $$logmsg .= "A possible change in username has been detected for a student enrolled in this course. The existing LON-CAPA classlist contains user: $match and student ID: ".$stuinfo[ $place{studentID} ].". "; + $$logmsg .= &mt('A possible change in username has been detected for a student enrolled in this course.').' '.&mt('The existing LON-CAPA classlist contains user: [_1] and student/employee ID: [_2].',$match,$stuinfo[ $place{studentID} ]); if (grep/^$match$/,@okusers) { - $$logmsg .= "The username $match remains in the institutional classlist, but the same student ID is used for new user: $uname now found in the institutional classlist. You may need to contact your Domain Coordinator to determine how to reolve this issue and whether to move student data files for user: $match to $uname. "; + $$logmsg .= &mt('The username [_1] remains in the institutional classlist, but the same student/employee ID is used for new user: [_2] now found in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to determine how to resolve this issue and whether to move student data files for user: [_1] to [_2].',$match,$uname).' '; } else { unless ($drops == 1) { - $$logmsg .= "This username - $match - has been dropped from the institutional classlist, but the student ID of this user is also used by $uname who now appears in the institutional classlist. You may need to contact your Domain Coordinator to request a move of the student data files for user: $match to $uname. "; + $$logmsg .= &mt('This username - [_1] - has been dropped from the institutional classlist, but the student/employee ID of this user is also used by [_2] who now appears in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to request a move of the student data files for user: [_1] to [_2].',$match,$uname).' '; } } - $$logmsg .= "Because of this student ID conflict, the new username - $uname - has not been added to the LON-CAPA classlist.".$linefeed; + $$logmsg .= &mt('Because of this student/employee ID conflict, the new username - [_1] - has not been added to the LON-CAPA classlist',$uname).$linefeed; } } elsif ($adds == 1) { my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc); @@ -322,11 +328,11 @@ sub update_LC { 'linefeed' => $linefeed, 'role' => 'st' }; - my $outcome = &create_newuser($args,$logmsg,$newusermsg,\$enrollcount,\$addresult,\%longroles,\%courseinfo); + my $outcome = &create_newuser($args,$logmsg,$newusermsg,\$enrollcount,\$addresult,\%longroles,\%courseinfo,$context); } else { &execute_add($context,'newstudent',$uname,$dom,$auth,$authparam,$first,$middle,$last,$gene,$pid,$usec,$end,$start,$emailenc,$cid,\$addresult,\$enrollcount,$linefeed,$logmsg); } - if ($courseinfo{'showphotos'}) { + if ($courseinfo{'showphoto'}) { my ($result,$resulttype) = &Apache::lonnet::auto_checkphotos($uname,$dom,$pid); if ($resulttype) { @@ -337,7 +343,7 @@ sub update_LC { } } } - if ($courseinfo{'showphotos'}) { + if ($courseinfo{'showphoto'}) { if (keys(%{$phototypes})>0) { my %lt = &photo_response_types(); foreach my $type (sort(keys(%{$phototypes}))) { @@ -348,7 +354,7 @@ sub update_LC { &mt('For [_1] students, photos ',$numphoto). $lt{$type}.'