[LON-CAPA-cvs] cvs: loncom /enrollment Enrollment.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 30 Apr 2008 23:59:14 -0000


raeburn		Wed Apr 30 19:59:14 2008 EDT

  Modified files:              
    /loncom/enrollment	Enrollment.pm 
  Log:
  Bug 5176. Record of role changes in a course in nohist_rolelog.db
  - Pass context arg to lonnet::assignrole() and lonnet::modify_student_enrollment().
  - Replace separate subroutines (CL_*) for authargm authtype, email,enddate, etc indices with call to &place_hash() and retrieve as a hash.  
  
  
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.37 loncom/enrollment/Enrollment.pm:1.38
--- loncom/enrollment/Enrollment.pm:1.37	Sat Dec 22 21:48:50 2007
+++ loncom/enrollment/Enrollment.pm	Wed Apr 30 19:59:13 2008
@@ -1,5 +1,5 @@
 # Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.37 2007/12/23 02:48:50 raeburn Exp $
+# $Id: Enrollment.pm,v 1.38 2008/04/30 23:59:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,18 +115,7 @@
 # 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}) {
@@ -217,7 +206,7 @@
 # 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 .= &mt('An error occured during the attempt to convert [_1] from a manual type to an auto type student - [_2].',$uname,$drop_reply).$linefeed;
@@ -267,7 +256,7 @@
                         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) {
@@ -331,7 +320,7 @@
                                     '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);
                     }
@@ -388,13 +377,13 @@
                             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,'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);
                         if ($drop_reply !~ /^ok/) {
                             $$logmsg .= &mt('An error occured during the attempt to expire the [_1] from the old section [_2] - [_3].',$uname,$$currlist{$uname}[$sec],$drop_reply).$linefeed;
                         } else {
                             $dropcount ++;
                             my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
-                            $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname.' '.&mt("dropped from section/group: '[_1]'.",$$currlist{$uname}[$sec]).$linefeed; 
+                            $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname.' '.&mt("dropped from section: '[_1]'.",$$currlist{$uname}[$sec]).$linefeed; 
                             if ($context eq 'automated') {
                                 $$logmsg .= &mt('User [_1] student role expired from course.',$uname).$linefeed;
                             }
@@ -520,7 +509,7 @@
                 $outcome = $result;
             }
         } else {
-            $outcome=&Apache::lonnet::modifystudent($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto','',$cid);
+            $outcome=&Apache::lonnet::modifystudent($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto','',$cid,'',$called_context);
         }
         if ($outcome eq 'ok') {
             my $access = &showaccess($end,$start);
@@ -528,7 +517,7 @@
             if ($usec eq '') {
                 $showsec = &mt('none');
             }
-            $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section/group: '[_1]'.",$showsec).$access.$linefeed;
+            $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section: '[_1]'.",$showsec).$access.$linefeed;
             unless ($context eq 'createowner' || $context eq 'createcourse') {
                 $$enrollcount ++;
             }
@@ -699,10 +688,10 @@
             $showsec = &mt('none');
         }
         if ($caller eq 'switchtype') {
-            $$logmsg .= &mt("Existing user [_1] detected in institutional classlist - switched from 'manual' to 'auto' enrollment in section/group [_2].",$uname,$showsec).$access.$linefeed;
+            $$logmsg .= &mt("Existing user [_1] detected in institutional classlist - switched from 'manual' to 'auto' enrollment in section [_2].",$uname,$showsec).$access.$linefeed;
         } elsif ($caller eq 'newstudent') {
             $$enrollcount ++;
-            $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section/group '[_1]'.",$showsec).$access.$linefeed;
+            $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section '[_1]'.",$showsec).$access.$linefeed;
         }
         if ($context eq 'automated') {
             $$logmsg .= &mt('Existing [_1] user [_2] enrolled successfully.',$dom,$uname).$linefeed;
@@ -860,17 +849,22 @@
     return;
 }
 
-sub CL_autharg { return 0; }
-sub CL_authtype { return 1;}
-sub CL_email { return 2;}
-sub CL_enddate { return 3;}
-sub CL_firstname { return 4;}
-sub CL_generation { return 5;}
-sub CL_groupID { return 6;}
-sub CL_lastname { return 7;}
-sub CL_middlename { return 8;}
-sub CL_startdate { return 9; }
-sub CL_studentID { return 10; }
+sub place_hash {
+    my %place = (
+                  autharg   => 0,
+                  authtype  => 1,
+                  email     => 2,
+                  enddate   => 3,
+                  firstname => 4,
+                  generation => 5,
+                  groupID    => 6,
+                  lastname   => 7,
+                  middlename => 8,
+                  startdate  => 9,
+                  studentID  => 10,
+                );
+    return %place;
+}
 
 sub photo_response_types {
     my %lt = &Apache::lonlocal::texthash(