[LON-CAPA-cvs] cvs: loncom /automation Autocreate.pl /interface domainprefs.pm loncoursequeueadmin.pm lonrequestcourse.pm /localize/localize de.pm pt.pm /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Sun, 06 Mar 2011 21:17:28 -0000


This is a MIME encoded message

--raeburn1299446248
Content-Type: text/plain

raeburn		Sun Mar  6 21:17:28 2011 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncoursequeueadmin.pm 
                     	lonrequestcourse.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/automation	Autocreate.pl 
    /loncom/localize/localize	de.pm pt.pm 
  Log:
  - Bug 6287.
    Processing of requests for official courses queued pending validation
    by Autocreate.pl run by cron.  
      - Send LON-CAPA message (with notification e-mail to permanentemail)
        to course requestor when course is created.    
  
  
--raeburn1299446248
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20110306211728.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.142 loncom/interface/domainprefs.pm:1.143
--- loncom/interface/domainprefs.pm:1.142	Mon Feb  7 21:04:09 2011
+++ loncom/interface/domainprefs.pm	Sun Mar  6 21:17:15 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.142 2011/02/07 21:04:09 raeburn Exp $
+# $Id: domainprefs.pm,v 1.143 2011/03/06 21:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,7 +140,7 @@
 
 =over
  
-- course requests will be processed autoatically up to a limit of
+- course requests will be processed automatically up to a limit of
 N requests for the course type for the particular requestor.
 If N is undefined, there is no limit to the number of course requests
 which a course owner may submit and have processed automatically. 
@@ -1886,24 +1886,23 @@
                   '<input type="radio" name="autocreate_xml"'.
                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   '<label><input type="radio" name="autocreate_xml"'.
-                  $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
+                  $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
+                  '</td></tr><tr>'.
+                  '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
+                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+                  '<input type="radio" name="autocreate_req"'.
+                  $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
+                  '<label><input type="radio" name="autocreate_req"'.
+                  $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
     if ($numdc > 1) {
-        $datatable .= '</td><tr><td>'.
-                      &mt('XML files processed as: (choose Dom. Coord.)'). 
-                      '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
-                      '<tr class="LC_odd_row">';
+        $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
+                      &mt('Course creation processed as: (choose Dom. Coord.)').
+                      '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
         $$rowtotal ++ ;
     } else {
-        $datatable .= '</td></tr><tr>';
+        $datatable .= $dctable.'</td></tr>';
     }
-    $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
-                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
-                  '<input type="radio" name="autocreate_req"'.
-                  $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
-                  '<label><input type="radio" name="autocreate_req"'.
-                  $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
-                  '</tr>';
     return $datatable;
 }
 
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.25 loncom/interface/loncoursequeueadmin.pm:1.26
--- loncom/interface/loncoursequeueadmin.pm:1.25	Wed Dec  8 03:38:46 2010
+++ loncom/interface/loncoursequeueadmin.pm	Sun Mar  6 21:17:15 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests
 #
-# $Id: loncoursequeueadmin.pm,v 1.25 2010/12/08 03:38:46 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.26 2011/03/06 21:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -90,8 +90,8 @@
 # FIXME locallocaltime needs to be able to take $sender_lh as an argument
 #       so this can be localized to the recipients date display format/time zone
     $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
-    my $msgcc;
-    my ($rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
+    my ($msgcc,$rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
+    my ($senderuname,$senderudom) = split(':',$sender);
     if ($context eq 'coursemanagers') {
         $rawsubj = 'Self-enrollment requests processed';
         push(@rawmsg,{
@@ -138,6 +138,15 @@
         if (ref($textstr) eq 'ARRAY') {
             push(@rawmsg,@{$textstr});
         }
+    } elsif ($context eq 'pendingrequestor') {
+        if ($crstype eq 'Community') {
+            $rawsubj = 'Community request';
+        } else {
+            $rawsubj = 'Processed course request';
+        }
+        if (ref($textstr) eq 'ARRAY') {
+            push(@rawmsg,@{$textstr});
+        }
     } elsif ($context eq 'coursereq') {
         if ($crstype eq 'community') {
             $rawsubj = 'Community request to review';
@@ -213,7 +222,7 @@
             $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
         }
     }
-    &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms);
+    &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom);
     my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
     my $status;
     foreach my $recip (sort(keys(%{$msgcc}))) {
@@ -446,8 +455,8 @@
 sub update_request_queue {
     my ($context,$cdom,$cnum,$coursedesc) = @_;
     my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
-        $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
-        $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
+        $stucounts,$idx,$classlist,%requesthash,$cid,$domdesc,$now,
+        $sender,$approvedmsg,$rejectedmsg,$beneficiary,
         @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
         @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
         @rejections,@rejectionerrors,@nopermissions,%courseroles,
@@ -461,16 +470,7 @@
         $beneficiary = 'enroller';
         $cid = $env{'request.course.id'};
         $crstype = lc(&Apache::loncommon::course_type());
-        my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
-        $hostname = &Apache::lonnet::hostname($chome);
-        $protocol = $Apache::lonnet::protocol{$chome};
-        $protocol = 'http' if ($protocol ne 'https');
-        my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
-        if ($domdefaults{'portal_def'}) {
-            $firsturl = $domdefaults{'portal_def'};
-        } else {
-            $firsturl = $protocol.'://'.$hostname;
-        }
+        $firsturl = &course_portal_url($cnum,$cdom);
         %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
         $access_start =  $env{'course.'.$cid.'.internal.selfenroll_start_access'};
         $access_end =  $env{'course.'.$cid.'.internal.selfenroll_end_access'};
@@ -497,16 +497,7 @@
             $queue = 'pending';
         }
         %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_'.$queue);
-        my $chome = &Apache::lonnet::domain($cdom,'primary');
-        $hostname = &Apache::lonnet::hostname($chome);
-        $protocol = $Apache::lonnet::protocol{$chome};
-        $protocol = 'http' if ($protocol ne 'https');
-        my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
-        if ($domdefaults{'portal_def'}) {
-            $firsturl = $domdefaults{'portal_def'};
-        } else {
-            $firsturl = $protocol.'://'.$hostname;
-        }
+        $firsturl= &course_portal_url($cnum,$cdom);
         my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
             if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') { 
@@ -588,7 +579,8 @@
                         $stucounts->{'allstudents'} ++;
                         $stucounts->{'selfenrolled'} ++;
                         &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
-                                       $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
+                                       $cid,$coursedesc,$now,$beneficiary,$sender,
+                                       undef,undef,$crstype);
                         my %userrequest = (
                             $cdom.'_'.$cnum => {
                                 timestamp   => $now,
@@ -658,8 +650,9 @@
                                 unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
                                     push(@warn_dels,$cnum);
                                 }
-                                &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
-                                              $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
+                                &send_selfserve_notification($ownername.':'.$ownerdom,
+                                              $approvedmsg,$cid,$coursedesc,$now,
+                                              $beneficiary,$sender,undef,undef,$crstype);
                                 my %reqhash = (
                                                 reqtime     => $history{'reqtime'},
                                                 crstype     => $history{'crstype'},
@@ -712,7 +705,8 @@
             if ($context eq 'course') {
                 my $user = $item;
                 &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
-                                             $now,$beneficiary,$sender,undef,undef,$crstype);
+                                             $now,$beneficiary,$sender,undef,undef,
+                                             $crstype);
                 my ($uname,$udom) = split(/:/,$user);
                 my %userrequest = (
                     $cdom.'_'.$cnum => {
@@ -1008,6 +1002,22 @@
     return $output;
 }
 
+sub course_portal_url {
+    my ($cnum,$cdom) = @_;
+    my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
+    my $hostname = &Apache::lonnet::hostname($chome);
+    my $protocol = $Apache::lonnet::protocol{$chome};
+    $protocol = 'http' if ($protocol ne 'https');
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+    my $firsturl;
+    if ($domdefaults{'portal_def'}) {
+        $firsturl = $domdefaults{'portal_def'};
+    } else {
+        $firsturl = $protocol.'://'.$hostname;
+    }
+    return $firsturl;
+}
+
 sub get_student_counts {
     my ($cdom,$cnum) = @_;
     my (%idx,%stucounts);
@@ -1295,17 +1305,17 @@
 }
 
 sub update_coursereq_status {
-    my ($reqhash,$dom,$cnum,$reqstatus,$context) = @_;
+    my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_;
     my ($storeresult,$statusresult,$output);
     my $requestkey = $dom.'_'.$cnum;
     if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
         $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
-                                                       'courserequests');
+                                                       'courserequests',$udom,$uname);
         if ($storeresult eq 'ok') {
             my %status = (
                              'status:'.$dom.':'.$cnum => $reqstatus,
                          );
-            $statusresult = &Apache::lonnet::put('courserequests',\%status);
+            $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname);
         }
     } else {
         $storeresult = 'error: invalid requestkey format';
@@ -1317,7 +1327,7 @@
         } else {
             $output =  '<span class="LC_warning">'.$output.'</span><br />';
         }
-        &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
+        &Apache::lonnet::logthis("Error saving course request - $requestkey for $uname:$udom - $storeresult");
     } elsif ($statusresult ne 'ok') {
         $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
         if ($context eq 'domain') {
@@ -1325,13 +1335,13 @@
         } else {
             $output = '<span class="LC_warning">'.$output.'</span><br />';
         }
-        &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
+        &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $uname:$udom) - $statusresult");
     }
     return ($storeresult,$output);
 }
 
 sub process_official_reqs {
-    my ($context,$dom) = @_;
+    my ($context,$dom,$dcname,$dcdom) = @_;
     my $reqsnamespace = 'courserequestqueue';
     my %requesthash =
         &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending');
@@ -1409,7 +1419,27 @@
                     if ($result eq 'created') {
                         $disposition = 'created';
                         $reqstatus = 'created';
-                        push(@{$newcids{$instcode}},$dom.'_'.$cnum);
+                        my $cid = $dom.'_'.$cnum;
+                        push(@{$newcids{$instcode}},$cid);
+                        if ($dcname && $dcdom) {
+                            my $firsturl = &course_portal_url($cnum,$dom);
+                            my $beneficiary = 'pendingrequestor';
+                            my $now = time;
+                            my $owner = $ownername.':'.$ownerdom;
+                            my $approvedmsg =
+                                [{
+                                    mt => 'Your request course, queued pending validation has now been created.',
+                                 },
+                                 {
+                                    mt   => 'Visit [_1], to log-in and access the course.',
+                                    args => [$firsturl],
+                                 }];
+                            my $sender = $dcname.':'.$dcdom;
+                            &send_selfserve_notification($owner,$approvedmsg,
+                                                         $cid,$cdescr,$now,
+                                                         $beneficiary,$sender,
+                                                         undef,undef,$crstype);
+                        }
                     }
                 } elsif ($disposition eq 'rejected') {
                     $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed;
@@ -1445,7 +1475,8 @@
                 unless ($disposition eq 'pending') {
                     my ($statusresult,$output) =
                         &update_coursereq_status(\%requesthash,$dom,$cnum,
-                                                 $reqstatus,'domain');
+                                                 $reqstatus,'domain',$ownerdom,
+                                                 $ownername);
                     unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
                         $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed;
                     }
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.62 loncom/interface/lonrequestcourse.pm:1.63
--- loncom/interface/lonrequestcourse.pm:1.62	Mon Jan 24 00:59:50 2011
+++ loncom/interface/lonrequestcourse.pm	Sun Mar  6 21:17:15 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.62 2011/01/24 00:59:50 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.63 2011/03/06 21:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3489,7 +3489,7 @@
         }
         ($storeresult,my $updateresult) = 
             &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
-                $cnum,$reqstatus,'request');
+                $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
         if ($modified && $queued && $storeresult eq 'ok') {
             if ($crstype eq 'community') {
                 $output .= '<p>'.&mt('Your community request has been updated').'</p>';
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1104 loncom/lonnet/perl/lonnet.pm:1.1105
--- loncom/lonnet/perl/lonnet.pm:1.1104	Thu Feb 24 23:55:58 2011
+++ loncom/lonnet/perl/lonnet.pm	Sun Mar  6 21:17:18 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1104 2011/02/24 23:55:58 raeburn Exp $
+# $Id: lonnet.pm,v 1.1105 2011/03/06 21:17:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7292,8 +7292,8 @@
                     $namevalue.=&escape($key).'='.&freeze_escape($$storehash{$key}).'&';
                 }
                 $namevalue=~s/\&$//;
-                $result =  &reply("store:$env{'user.domain'}:$env{'user.name'}:".
-                                  "$namespace:$datakey:$namevalue",$uhome);
+                $result =  &reply("store:$udom:$uname:$namespace:$datakey:".
+                                  $namevalue,$uhome);
             }
         } else {
             $result = 'error: data to store was not a hash reference'; 
Index: loncom/automation/Autocreate.pl
diff -u loncom/automation/Autocreate.pl:1.16 loncom/automation/Autocreate.pl:1.17
--- loncom/automation/Autocreate.pl:1.16	Sun Sep 26 02:29:55 2010
+++ loncom/automation/Autocreate.pl	Sun Mar  6 21:17:23 2011
@@ -2,7 +2,7 @@
 #
 # Automated Course Creation script
 #
-# $Id: Autocreate.pl,v 1.16 2010/09/26 02:29:55 raeburn Exp $
+# $Id: Autocreate.pl,v 1.17 2011/03/06 21:17:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -135,9 +135,6 @@
                 if ($settings->{'xml'}) {
                     if ($settings->{'xmldc'}) {
                         my ($dcname,$dcdom) = split(':',$settings->{'xmldc'});
-                        $env{'user.name'} = $dcname;
-                        $env{'user.domain'} = $dcdom;
-                        $env{'request.role.domain'} = $dom;
                         if (!&check_activedc($dcdom,$dcname,$dom)) {
                             print $fh "Autocreate.pl in domain $dom configured to run under the auspices of a user without an active domain coordinator role in the domain - course creation will be skipped.\n\n";
                             next;
@@ -149,7 +146,7 @@
                     }
                 }
                 if ($settings->{'req'}) {
-                    my $output = &Apache::loncoursequeueadmin::process_official_reqs('auto',$dom);
+                    my $output = &Apache::loncoursequeueadmin::process_official_reqs('auto',$dom,$dcname,$dcdom);
                     if ($output) {
                         print $fh $output;
                     }
Index: loncom/localize/localize/de.pm
diff -u loncom/localize/localize/de.pm:1.412 loncom/localize/localize/de.pm:1.413
--- loncom/localize/localize/de.pm:1.412	Fri Mar  4 16:24:08 2011
+++ loncom/localize/localize/de.pm	Sun Mar  6 21:17:26 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # German Localization Lexicon
 #
-# $Id: de.pm,v 1.412 2011/03/04 16:24:08 bisitz Exp $
+# $Id: de.pm,v 1.413 2011/03/06 21:17:26 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -20261,7 +20261,7 @@
    'With validation'
 => 'mit Bestätigung',
 
-   'XML files processed as: (choose Dom. Coord.)'
+   'Course creation processed: (choose Dom. Coord.)'
 => 'XML-Dateien werden verarbeitet von: (Dom.-Koord. auswählen)',
 
    'You can only use this screen to select courses and communities in the current domain.'
Index: loncom/localize/localize/pt.pm
diff -u loncom/localize/localize/pt.pm:1.52 loncom/localize/localize/pt.pm:1.53
--- loncom/localize/localize/pt.pm:1.52	Thu Jan  6 02:24:21 2011
+++ loncom/localize/localize/pt.pm	Sun Mar  6 21:17:27 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Portuguese Localization Lexicon
 #
-# $Id: pt.pm,v 1.52 2011/01/06 02:24:21 raeburn Exp $
+# $Id: pt.pm,v 1.53 2011/03/06 21:17:27 raeburn Exp $
 #
 # Copyright UNICAMP, Sao Paulo
 # Supported in part by Partnership in Global Learning
@@ -20095,8 +20095,8 @@
    'With validation'
 => 'With validation',
 
-   'XML files processed as: (choose Dom. Coord.)'
-=> 'XML files processed as: (choose Dom. Coord.)',
+   'Course creation processed as: (choose Dom. Coord.)'
+=> 'Course creation processed as: (choose Dom. Coord.)',
 
    'Yes, and show correct answer if they exceed the maximum number of tries.'
 => 'Yes, and show correct answer if they exceed the maximum number of tries.',

--raeburn1299446248--