[LON-CAPA-cvs] cvs: loncom /interface loncoursequeueadmin.pm

raeburn raeburn@source.lon-capa.org
Fri, 04 Sep 2009 23:01:58 -0000


raeburn		Fri Sep  4 23:01:58 2009 EDT

  Modified files:              
    /loncom/interface	loncoursequeueadmin.pm 
  Log:
  - Additional arg for &build_batchcreatehash() - context 
    - determines if user information for owner is from %env, or from call to 
      &Apache::lonnet::userenvironment().
  - Set start and end dates for roles for additional personnel. For student roles use
    the defaults specified in the request for accessstart and accessend. 
  
  
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.7 loncom/interface/loncoursequeueadmin.pm:1.8
--- loncom/interface/loncoursequeueadmin.pm:1.7	Thu Aug 27 00:06:18 2009
+++ loncom/interface/loncoursequeueadmin.pm	Fri Sep  4 23:01:58 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests 
 #
-# $Id: loncoursequeueadmin.pm,v 1.7 2009/08/27 00:06:18 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.8 2009/09/04 23:01:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -879,7 +879,7 @@
         $owneremail = $emails{$email};
         last if ($owneremail ne '');
     }
-    my %reqdetails = &build_batchcreatehash($dom,$details,$owneremail,$domdefs);
+    my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
     my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
                   \%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult,
                   \$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
@@ -892,7 +892,7 @@
 }
 
 sub build_batchcreatehash {
-    my ($dom,$details,$owneremail,$domdefs) = @_;
+    my ($dom,$context,$details,$owneremail,$domdefs) = @_;
     my %batchhash;
     my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
     if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
@@ -913,12 +913,42 @@
         } else {
             $batchhash{'crstype'} = 'Course';
         }
-        $batchhash{'users'}{$details->{$owner}} = {
-                                 firstname => $env{'environment.first'},
-                                 lastname  => $env{'environment.last'},
-                                 emailenc  => $emailenc,
-                                 email     => $owneremail,
-                             };
+        my ($owner_firstname,$owner_lastname);
+        if ($context eq 'domain') {
+            my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
+                                                           $details->{'owner'},
+                                                           'firstname','lastname');
+            $owner_firstname = $userenv{'firstname'};
+            $owner_lastname = $userenv{'lastname'};
+        } else {
+            $owner_firstname = $env{'environment.firstname'};
+            $owner_lastname = $env{'environment.lastname'};
+        }
+        if (ref($details->{'personnel'}) eq 'HASH') {
+            %{$batchhash{'users'}} = %{$details->{'personnel'}};
+            if (ref($batchhash{'users'}) eq 'HASH') {  
+                foreach my $userkey (keys(%{$batchhash{'users'}})) {
+                    if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
+                        if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
+                            foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
+                                my $start = '';
+                                my $end = '';
+                                if ($role eq 'st') {
+                                    $start = $details->{'accessstart'};
+                                    $end = $details->{'accessend'};
+                                }
+                                $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
+                                $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
+                            } 
+                        }
+                    }
+                }
+            }
+        }
+        $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
+        $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
+        $batchhash{'users'}{$owner}{emailenc} = $emailenc;
+        $batchhash{'users'}{$owner}{owneremail} = $owneremail;
     }
     return %batchhash;
 }