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

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 30 Jan 2006 07:32:23 -0000


This is a MIME encoded message

--raeburn1138606343
Content-Type: text/plain

raeburn		Mon Jan 30 02:32:23 2006 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm 
  Log:
  Eliminate duplication of message storage for broadcast and critical messages.  Message content now stored in a single record in nohist_email.db for each broadcast or critical mailing. Display of critical and broadcast messages in &disfacetoface() for individual students retrieves this message (based on msgid).
  
  
--raeburn1138606343
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060130023223.txt"

Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.173 loncom/interface/lonmsg.pm:1.174
--- loncom/interface/lonmsg.pm:1.173	Mon Jan 23 18:15:51 2006
+++ loncom/interface/lonmsg.pm	Mon Jan 30 02:32:20 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.173 2006/01/23 23:15:51 albertel Exp $
+# $Id: lonmsg.pm,v 1.174 2006/01/30 07:32:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -137,7 +137,7 @@
 
 sub packagemsg {
     my ($subject,$message,$citation,$baseurl,$attachmenturl,
-	$recuser,$recdomain,$msgid,$type)=@_;
+	$recuser,$recdomain,$msgid,$type,$crsmsgid)=@_;
     $message =&HTML::Entities::encode($message,'<>&"');
     $citation=&HTML::Entities::encode($citation,'<>&"');
     $subject =&HTML::Entities::encode($subject,'<>&"');
@@ -170,11 +170,19 @@
         $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
                             $msgcount,$course_context,$$);
     }
-    my $result='<sendername>'.$env{'user.name'}.'</sendername>'.
+    my $result = '<sendername>'.$env{'user.name'}.'</sendername>'.
            '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
            '<subject>'.$subject.'</subject>'.
-	   '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
-	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
+           '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>';
+    if (defined($crsmsgid)) {
+        $result.= '<courseid>'.$course_context.'</courseid>'.
+                  '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
+                  '<msgid>'.$msgid.'</msgid>'.
+                  '<coursemsgid>'.$crsmsgid.'</coursemsgid>'.
+                  '<message>'.$message.'</message>';
+        return ($msgid,$result);
+    }
+    $result .= '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
 	   '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
@@ -536,7 +544,7 @@
 
 sub user_normal_msg_raw {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
-	$toperm,$currid,$newid,$sentmessage)=@_;
+	$toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -546,10 +554,9 @@
     if ($homeserver ne 'no_host') {
        ($msgid,$packed_message)=
 	                 &packagemsg($subject,$message,$citation,$baseurl,
-                                     $attachmenturl,$user,$domain,$currid);
-       (undef, my $packed_message_no_citation)=
-                         &packagemsg($subject,$message,undef     ,$baseurl,
-                                     $attachmenturl,$user,$domain,$currid);
+                                     $attachmenturl,$user,$domain,$currid,
+                                                         undef,$crsmsgid);
+
 # Store in user folder
        $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':nohist_email:'.
@@ -565,6 +572,11 @@
                (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
 		|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
 					    '/'.$env{'request.course.sec'})))) {
+           (undef, my $packed_message_no_citation)=
+                             &packagemsg($subject,$message,undef     ,$baseurl,
+                                          $attachmenturl,$user,$domain,$currid,
+                                                              undef,$crsmsgid);
+
            $status .= &store_sent_mail($msgid,$packed_message_no_citation);
        }
     } else {
@@ -1424,17 +1436,29 @@
         } elsif ($content{'subject'}=~/^Broadcast/) {
             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
             if ($content{'subject'}=~/^Broadcast\./) {
-                %content=&unpackagemsg($content{'message'});
-                $content{'message'}=
+                if (defined($content{'coursemsgid'})) {
+                    my $crsmsgid = &Apache::lonnet::escape($content{'coursemsgid'});
+                    my $broadcast_message = &general_message($crsmsgid);
+                    $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
+                } else {
+                    %content=&unpackagemsg($content{'message'});
+                    $content{'message'} =
                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                     $content{'message'};
+                }
             }    
         } else {
             $result.='<h3>'.&mt('Critical Message').'</h3>';
-            %content=&unpackagemsg($content{'message'});
-            $content{'message'}=
+            if (defined($content{'coursemsgid'})) {
+                my $crsmsgid=&Apache::lonnet::escape($content{'coursemsgid'});
+                my $critical_message = &general_message($crsmsgid);
+                $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
+            } else {
+                %content=&unpackagemsg($content{'message'});
+                $content{'message'}=
                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
 		$content{'message'};
+            }
         }
         $result.=&mt('By').': <b>'.
 &Apache::loncommon::aboutmewrapper(
@@ -1457,6 +1481,18 @@
     }
 }
 
+sub general_message {
+    my ($crsmsgid) = @_;
+    my %general_content;
+    if ($crsmsgid) { 
+        my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
+                           $env{'course.'.$env{'request.course.id'}.'.domain'},
+                           $env{'course.'.$env{'request.course.id'}.'.num'});
+        %general_content = &unpackagemsg($course_content{$crsmsgid});
+    }
+    return $general_content{'message'};
+}
+
 # ---------------------------------------------------------------- Face to face
 
 sub facetoface {
@@ -2160,6 +2196,7 @@
         my $savemsg;
         my $msgtype;
         my %sentmessage;
+        my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'});
         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
             (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
 	     || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
@@ -2181,15 +2218,12 @@
 		 || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
 					     '/'.$env{'request.course.sec'}))) {
 		$r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');
-		$thismsg=&user_crit_msg($recuname,$recdomain,
-					&Apache::lonfeedback::clear_out_html($env{'form.subject'}),
-					$msgtxt,
-					$env{'form.sendbck'},$env{'form.permanent'},\$sentmessage{$_});
+		$thismsg=&user_crit_msg($recuname,$recdomain,$msgsubj,$msgtxt,
+				$env{'form.sendbck'},$env{'form.permanent'},
+                                                             \$sentmessage{$_});
 	    } else {
 		$r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');
-		$thismsg=&user_normal_msg($recuname,$recdomain,
-					  &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
-					  $msgtxt,
+		$thismsg=&user_normal_msg($recuname,$recdomain,$msgsubj,$msgtxt,
 					  $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
             }
 	    if (($env{'request.course.id'}) && (($msgtype eq 'critical') || 
@@ -2225,7 +2259,7 @@
                 my $record_sent;
                 my @recusers = ();
                 my @recudoms = ();
-                my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) = 
+                my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) = 
                             split(/\:/,&Apache::lonnet::unescape($specialmsgid));
                 foreach my $recipient (sort(keys(%toaddr))) {
                     if ($specialmsg_status{$recipient} eq 'ok') {
@@ -2233,8 +2267,8 @@
                         my $usermsgid = &buildmsgid($stamp,$usersubj,$msgname,
                                               $msgdom,$msgcount,$context,$pid);
                         &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
-                        ' ['.$recipient.']',$sentmessage{$recipient},
-                        undef,undef,undef,undef,$usermsgid);
+                                             ' ['.$recipient.']',$msgsubj,undef,
+                        undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
                         my ($uname,$udom) = split/:/,$recipient;
                         push(@recusers,$uname);
                         push(@recudoms,$udom);
@@ -2243,14 +2277,12 @@
                 if (@recusers) {
                     my $specialmessage;
                     my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
-                    &Apache::lonfeedback::clear_out_html($env{'form.subject'});
+                                                                       $msgsubj;
                     $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
                     my $sentmsgid = &buildmsgid($stamp,$sentsubj,$msgname,
                                               $msgdom,$msgcount,$context,$pid);
-                    ($specialmsgid,$specialmessage) =
-                         &packagemsg(&Apache::lonfeedback::clear_out_html(
-                             $env{'form.subject'}),$savemsg,undef,undef,undef,
-                                            \@recusers,\@recudoms,$sentmsgid);
+                    ($specialmsgid,$specialmessage) = &packagemsg($msgsubj,$savemsg,
+                            undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
                     $record_sent = &store_sent_mail($specialmsgid,$specialmessage);
                 }
             } else {

--raeburn1138606343--