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

raeburn raeburn at source.lon-capa.org
Fri Jan 10 17:45:56 EST 2025


raeburn		Fri Jan 10 22:45:56 2025 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - Value(s) set for "E-mail from course requests requiring approval" in
    "E-mail addresses and helpform" domain configuration item are used.
  
  
-------------- next part --------------
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.117 loncom/interface/lonrequestcourse.pm:1.118
--- loncom/interface/lonrequestcourse.pm:1.117	Wed Mar 29 16:01:13 2023
+++ loncom/interface/lonrequestcourse.pm	Fri Jan 10 22:45:55 2025
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.117 2023/03/29 16:01:13 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.118 2025/01/10 22:45:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3919,7 +3919,7 @@
                 if (($code) || ((ref($postprocess) eq 'HASH') && 
                                 (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
                     $output .= &notification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
-                                                         $dom,$cnum,$now,$code,$postprocess);
+                                                         $dom,$cnum,$now,$code,$postprocess,$crstype);
                 }
                 if ($code) {
                     $reqhash{'code'} = $code;
@@ -4032,7 +4032,7 @@
                     unless ($disposition eq 'pending') { 
                         $output .= '<br />'.
                                    &notification_information($disposition,$req_notifylist,
-                                                             $dom,$cnum,$now);
+                                                             $dom,$cnum,$now,'','',$crstype);
                     }
                 } else {
                     $reqstatus = 'domainerror';
@@ -4065,13 +4065,13 @@
                     $output .= '<p>'.&mt('Your course request has been updated').'</p>';
                 }
                 if ($disposition eq 'approval') {
-                    $output .= &notification_information($disposition,$req_notifylist,$dom,$cnum,$now);
+                    $output .= &notification_information($disposition,$req_notifylist,$dom,$cnum,$now,'','',$crstype);
                 }
             }
             if ($disposition eq 'approval') {
                 if ((ref($postprocess) eq 'HASH') && 
                     ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) { 
-                    &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+                    &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
                     $customized = $postprocess->{'createdcustomized'};
                 }
             } elsif ($disposition eq 'pending') {
@@ -4083,7 +4083,7 @@
                 if ($pendingform) {
                     $output .= $pendingform;
                 } else { 
-                    $output .= &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+                    $output .= &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
                 }
                 if (ref($postprocess) eq 'HASH') {
                     $customized = $postprocess->{'createdcustomized'};
@@ -4281,7 +4281,7 @@
 }
 
 sub notification_information {
-    my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
+    my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess,$crstype) = @_;
     my %emails = &Apache::loncommon::getemails();
     my $address;
     if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
@@ -4297,12 +4297,46 @@
         if ($address ne '') {
             $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
         }
+        my %possemails;
+        my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                     $env{'user.domain'});
+        my $emailto = &Apache::loncommon::build_recipient_list(undef,'requestsmail',$dom);
+        if ($emailto) {
+            map { $possemails{$_} = 1; } (split(/,/,$emailto));
+        }
         if ($req_notifylist) {
-            my $fullname = &Apache::loncommon::plainname($env{'user.name'},
-                                                         $env{'user.domain'});
+            if ($emailto) {
+                foreach my $recip (split(/,/,$req_notifylist)) {
+                    my ($uname,$udom) = split(/:/,$recip);
+                    my %emails = &Apache::loncommon::getemails($uname,$udom);
+                    foreach my $type ('permanentemail','notification') {
+                        if ((exists($emails{$type})) && ($emails{$type} ne '')) {
+                            my @to = split(/,/,$emails{$type});
+                            foreach my $addr (@to) {
+                                if (($addr ne '') && ($addr =~ m/\@/)) {
+                                    if (exists($possemails{$addr})) {
+                                        delete($possemails{$addr});
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
             my $sender = $env{'user.name'}.':'.$env{'user.domain'};
             &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
-                                                                      'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
+                                                                      undef,$env{'form.cdescr'},$now,'coursereq',$sender,'','',$crstype);
+        }
+#
+# If domain configuration for "E-mail addresses and helpform" has values set
+# for "E-mail from course requests requiring approval", send email to those
+# addresse(es) when a course request is queued, pending approval, unless
+# the email address will already receive a notification email, because of
+# values set for "Receive notification of course requests requiring approval"
+# in "Request creation of courses" configuration item.
+#
+        if ($emailto && keys(%possemails)) {
+            &notify_admin($dom,$crstype,$env{'form.cdescr'},"$fullname ($env{'user.name'}:$env{'user.domain'})",$now,\%possemails);
         }
         if (ref($postprocess) eq 'HASH') {
             if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
@@ -4383,7 +4417,7 @@
                     $type = 'uniquecode';
                 }
                 &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
-                                                                          $now,$type,$sender);
+                                                                          $now,$type,$sender,'','',$crstype);
             }
         }
     } else {
@@ -4394,6 +4428,52 @@
     return $output;
 }
 
+sub notify_admin {
+    my ($dom,$crstype,$contextdesc,$textstr,$timestamp,$emailsref) = @_;
+    if ((ref($emailsref) eq 'HASH') && (keys(%{$emailsref}))) {
+        my $emailto = join(',',sort(keys(%{$emailsref})));
+        my (@rawmsg,$rawsubj,$msgtxt);
+        if ($crstype eq 'community') {
+            $rawsubj = 'Community request to review';
+            $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
+        } else {
+            $rawsubj = 'Course request to review';
+            $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
+        }
+        $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
+        push(@rawmsg,{
+                      mt  => $msgtxt,
+                      args => ["\n  $contextdesc\n",$textstr,$timestamp],
+                     },
+                     {
+                      mt =>'[_1]A Domain Coordinator will use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which can either be approved or rejected.',
+                      args => ["\n","\n\n","\n\n"],
+                     });
+
+        my $sender_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
+        my $subject = &mt_user($sender_lh,$rawsubj);
+        my $message = '';
+        foreach my $item (@rawmsg) {
+            if (ref($item) eq 'HASH') {
+                if (ref($item->{args}) eq 'ARRAY') {
+                    $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
+                } else {
+                    $message .= &mt_user($sender_lh,$item->{mt})."\n";
+                }
+            }
+        }
+        my $chgmail = "To: $emailto\n".
+                      "Subject: $subject\n".
+                      "Content-type: text/plain\; charset=UTF-8\n".
+                      "MIME-Version: 1.0\n\n".
+                      "$message\n\n";
+        if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
+            print $mailh $chgmail;
+            close($mailh);
+        }
+    }
+}
+
 sub pending_validation_form {
     my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
     my $output;


More information about the LON-CAPA-cvs mailing list