[LON-CAPA-cvs] cvs: loncom /enrollment Autoenroll.pl

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 15 May 2007 06:19:54 -0000


This is a MIME encoded message

--raeburn1179209994
Content-Type: text/plain

raeburn		Tue May 15 02:19:54 2007 EDT

  Modified files:              
    /loncom/enrollment	Autoenroll.pl 
  Log:
  Changes to notification messages sent as a result of enrollment changes:
  - sender set to value in domain preferences (if one set).
  - recipients recorded in nohist_emailrecip db
  - courseid included in message
  - storage of duplicate messages in set mail folder eliminated
  
  
--raeburn1179209994
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070515021954.txt"

Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.26 loncom/enrollment/Autoenroll.pl:1.27
--- loncom/enrollment/Autoenroll.pl:1.26	Mon May 14 13:35:01 2007
+++ loncom/enrollment/Autoenroll.pl	Tue May 15 02:19:53 2007
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 #Automated Enrollment script
-# $Id: Autoenroll.pl,v 1.26 2007/05/14 17:35:01 raeburn Exp $
+# $Id: Autoenroll.pl,v 1.27 2007/05/15 06:19:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,6 +37,7 @@
     use Apache::loncommon;
     use Apache::lonlocal;
     use HTML::Entities;
+    use LONCAPA qw(:match);
 
 # Determine the library server's domain and hostID
     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
@@ -152,48 +153,80 @@
                         print $fh "$logmsg\n";
                         print $fh &mt('Messages end for [_1]',$crs)."\n";
                         if ($changecount > 0) {
-                            unless ($enrollvar{$crs}{notifylist}  eq '') {
-# Send message about enrollment changes to notifylist.
 # Set $env{'user.name'}, $env{'user.domain'}, $env{'user.home'}
-# for use by logging in lonmsg
-                                unless ( ($enrollvar{$crs}{'courseowner'} eq '') || (!defined($enrollvar{$crs}{'courseowner'}) )  ) {
-                                    if ($enrollvar{$crs}{'courseowner'} =~ /:/) {
-                                        ($env{'user.name'},$env{'user.domain'}) = split(/:/,$enrollvar{$crs}{'courseowner'});
-                                    } else {
-                                        $env{'user.name'} = $enrollvar{$crs}{'courseowner'};
-                                        $env{'user.domain'} = $dom;
-                                    }
-                                    $env{'user.home'} = &Apache::lonnet::homeserver($env{'user.name'},$env{'user.domain'});
-
-                                    my $subject = &mt('Student enrollment changes in [_1]',$enrollvar{$crs}{coursecode});
-                                    my $message = &mt('The following [quant,_1,change] occurred in [_2] - [_3] as a result of the automated classlist update:',$changecount,$enrollvar{$crs}{description},$enrollvar{$crs}{coursecode})."\n\n".$response;
-                                    unless ($newusermsg eq '') { 
-                                        $message .= "\n".$newusermsg;
-                                    }
-                                    my @to_notify = ();
-                                    if ($enrollvar{$crs}{notifylist} =~ m/,/) {
-                                        @to_notify = split/,/,$enrollvar{$crs}{notifylist};
-                                    } else {
-                                        $to_notify[0] = $enrollvar{$crs}{notifylist};
-                                    }
-                                    foreach my $cc (@to_notify) {
-                                        my ($ccname,$ccdom);
-                                        if ($cc =~ /:/) {
-                                            ($ccname,$ccdom) = split(/:/,$cc);
-                                        } elsif ($cc =~ /\@/) {
-                                            ($ccname,$ccdom) = split(/\@/,$cc);
-                                        }
-                                        my $status =  &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message);
-                                    }
-                                    if ( ($enrollvar{$crs}{notifylist} eq '') && ($newusermsg ne '') ) {
+# and $env{'request.course.id'} for use by logging in lonmsg
+                            $env{'request.course.id'} = $dom.'_'.$crs;
+                            my ($ownername,$ownerdom);
+                            if ($enrollvar{$crs}{'courseowner'} ne '') {
+                                if ($enrollvar{$crs}{'courseowner'} =~ /:/) {
+                                    ($ownername,$ownerdom) =
+                                        split(/:/,$enrollvar{$crs}{'courseowner'});
+                                } else {
+                                    $ownername = $enrollvar{$crs}{'courseowner'}; 
+                                    $ownerdom = $dom;
+                                }
+                            }
+                            if (($settings->{'sender_uname'} ne '') && 
+                                ($settings->{'sender_domain'} ne '')) {
+                                $env{'user.name'} = $settings->{'sender_uname'};
+                                $env{'user.domain'} = $settings->{'sender_domain'};
+                            } else {
+                                $env{'user.name'} = $ownername;
+                                $env{'user.domain'} = $ownerdom;
+                            }
+                            if ($enrollvar{$crs}{notifylist}  eq '') {
+                                if ($newusermsg ne '') {
+                                    if (($ownername =~ /^$match_username$/) && 
+                                        ($ownerdom =~ /^$match_domain$/)) {
                                         my $subject = &mt('New user accounts in [_1]',$enrollvar{$crs}{'coursecode'});
-                                        my $status =  &Apache::lonmsg::user_normal_msg($env{'user.name'},$env{'user.domain'},$subject,$newusermsg);
+                                        my $status =  &Apache::lonmsg::user_normal_msg($ownername,$ownerdom,$subject,$newusermsg);
                                     }
-                                    delete($env{'user.name'});
-                                    delete($env{'user.home'});
-                                    $env{'user.domain'} = $dom;
+                                }
+                            } else {
+                                my $msgcc;
+# Send message about enrollment changes to notifylist.
+                                $env{'user.home'} = &Apache::lonnet::homeserver($env{'user.name'},$env{'user.domain'});
+                                my $subject = &mt('Student enrollment changes in [_1]',$enrollvar{$crs}{coursecode});
+                                my $message = &mt('The following [quant,_1,change] occurred in [_2] - [_3] as a result of the automated classlist update:',$changecount,$enrollvar{$crs}{description},$enrollvar{$crs}{coursecode})."\n\n".$response;
+                                unless ($newusermsg eq '') { 
+                                    $message .= "\n".$newusermsg;
+                                }
+                                my @to_notify = split(/,/,$enrollvar{$crs}{notifylist});
+                                my $numsent = 0;
+                                my @recusers;
+                                my @recudoms;
+                                foreach my $cc (@to_notify) {
+                                    my ($ccname,$ccdom);
+                                    if ($cc =~ /:/) {
+                                        ($ccname,$ccdom) = split(/:/,$cc);
+                                    } elsif ($cc =~ /\@/) {
+                                        ($ccname,$ccdom) = split(/\@/,$cc);
+                                    }
+                                    push(@recusers,$ccname);
+                                    push(@recudoms,$ccdom);
+                                    $msgcc->{$ccname.':'.$ccdom}='';
+                                    $numsent ++;
+                                }
+                                my %reciphash = (
+                                    cc => $msgcc,
+                                );
+                                my %sentmessage;
+                                my $stamp = time;
+                                my $msgcount = &Apache::lonmsg::get_uniq();
+                                &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$env{'user.name'},$env{'user.domain'},$msgcount,$crs,$$,$message,\@recusers,\@recudoms);
+                                my ($recipid,$recipstatus) =
+                                    &Apache::lonmsg::store_recipients($subject,
+                                    $env{'user.name'},$env{'user.domain'},\%reciphash);
+                                foreach my $recip (sort(keys(%{$msgcc}))) {
+                                    my ($ccname,$ccdom) = split(/:/,$recip);
+                                    my $status =  
+                                        &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,undef,\%sentmessage,undef,undef,undef,1,$recipid);
                                 }
                             }
+                            delete($env{'user.name'});
+                            delete($env{'user.home'});
+                            delete($env{'request.course.id'});
+                            $env{'user.domain'} = $dom;
                         }
                     }
                 }

--raeburn1179209994--