--- loncom/interface/lonmsg.pm 2005/05/20 17:00:40 1.143
+++ loncom/interface/lonmsg.pm 2005/12/10 00:46:34 1.164
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.143 2005/05/20 17:00:40 albertel Exp $
+# $Id: lonmsg.pm,v 1.164 2005/12/10 00:46:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -97,6 +97,17 @@ Right now, this document will cover just
it is likely you will not need to programmatically read messages,
since lonmsg already implements that functionality.
+The routines used to package messages and unpackage messages are not
+only used by lonmsg when creating/extracting messages for LON-CAPA's
+internal messaging system, but also by lonnotify.pm which is available
+for use by Domain Coordinators to broadcast standard e-mail to specified
+users in their domain. The XML packaging used in the two cases is very
+similar. The differences are the use of $uname and
+$udom in stored internal messages, compared
+with $email in stored
+Domain Coordinator e-mail for the storage of information about
+recipients of the message/e-mail.
+
=head1 FUNCTIONS
=over 4
@@ -114,6 +125,8 @@ use HTML::Entities();
use Mail::Send;
use Apache::lonlocal;
use Apache::loncommunicate;
+use Apache::lonfeedback;
+use Apache::lonrss();
# Querystring component with sorting type
my $sqs;
@@ -124,7 +137,7 @@ my $interdis;
sub packagemsg {
my ($subject,$message,$citation,$baseurl,$attachmenturl,
- $recuser,$recdomain)=@_;
+ $recuser,$recdomain,$msgid,$type)=@_;
$message =&HTML::Entities::encode($message,'<>&"');
$citation=&HTML::Entities::encode($citation,'<>&"');
$subject =&HTML::Entities::encode($subject,'<>&"');
@@ -134,15 +147,29 @@ sub packagemsg {
#remove machine specification
$attachmenturl =~ s|^http://[^/]+/|/|;
$attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
-
+ my $course_context;
+ if (defined($env{'form.replyid'})) {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
+ split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));
+ $course_context = $origcid;
+ }
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.(rep)?rec\_(.*)$/) {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
+ split(/\:/,&Apache::lonnet::unescape($2));
+ $course_context = $origcid;
+ last;
+ }
+ }
+ unless(defined($course_context)) {
+ $course_context = $env{'request.course.id'};
+ }
my $now=time;
$msgcount++;
- my $partsubj=$subject;
- $partsubj=&Apache::lonnet::escape($partsubj);
- my $msgid=&Apache::lonnet::escape(
- $now.':'.$partsubj.':'.$env{'user.name'}.':'.
- $env{'user.domain'}.':'.$msgcount.':'.
- $env{'request.course.id'}.':'.$$);
+ unless(defined($msgid)) {
+ $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
+ $msgcount,$course_context,$$);
+ }
my $result=''.$env{'user.name'}.' '.
''.$env{'user.domain'}.' '.
''.$subject.' '.
@@ -155,14 +182,31 @@ sub packagemsg {
''.$env{'browser.version'}.' '.
''.$env{'browser.mathml'}.' '.
''.$ENV{'HTTP_USER_AGENT'}.' '.
- ''.$env{'request.course.id'}.' '.
+ ''.$course_context.' '.
''.$env{'request.course.sec'}.' '.
''.$env{'request.role'}.' '.
''.$env{'request.filename'}.' '.
- ''.$msgid.' '.
- ''.$recuser.' '.
- ''.$recdomain.' '.
- ''.$message.' ';
+ ''.$msgid.' ';
+ if (ref($recuser) eq 'ARRAY') {
+ for (my $i=0; $i<@{$recuser}; $i++) {
+ if ($type eq 'dcmail') {
+ my ($username,$email) = split(/:/,$$recuser[$i]);
+ $username = &Apache::lonnet::unescape($username);
+ $email = &Apache::lonnet::unescape($email);
+ $username = &HTML::Entities::encode($username,'<>&"');
+ $email = &HTML::Entities::encode($email,'<>&"');
+ $result .= ''.
+ $email.' ';
+ } else {
+ $result .= ''.$$recuser[$i].' '.
+ ''.$$recdomain[$i].' ';
+ }
+ }
+ } else {
+ $result .= ''.$recuser.' '.
+ ''.$recdomain.' ';
+ }
+ $result .= ''.$message.' ';
if (defined($citation)) {
$result.=''.$citation.' ';
}
@@ -186,7 +230,15 @@ sub unpackagemsg {
if ($token->[0] eq 'S') {
my $entry=$token->[1];
my $value=$parser->get_text('/'.$entry);
- $content{$entry}=$value;
+ if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
+ push(@{$content{$entry}},$value);
+ } elsif ($entry eq 'recipient') {
+ my $username = $token->[2]{'username'};
+ $username = &HTML::Entities::decode($username,'<>&"');
+ $content{$entry}{$username} = $value;
+ } else {
+ $content{$entry}=$value;
+ }
}
}
if ($content{'attachmenturl'}) {
@@ -206,15 +258,25 @@ sub unpackagemsg {
# ======================================================= Get info out of msgid
+sub buildmsgid {
+ my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
+ $subject=&Apache::lonnet::escape($subject);
+ return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.
+ $udom.':'.$msgcount.':'.$course_context.':'.$pid));
+}
+
sub unpackmsgid {
- my ($msgid,$folder)=@_;
+ my ($msgid,$folder,$skipstatus)=@_;
$msgid=&Apache::lonnet::unescape($msgid);
- my $suffix=&foldersuffix($folder);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/,
&Apache::lonnet::unescape($msgid));
- my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
- if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
- unless ($status{$msgid}) { $status{$msgid}='new'; }
+ my %status=();
+ unless ($skipstatus) {
+ my $suffix=&foldersuffix($folder);
+ &Apache::lonnet::get('email_status'.$suffix,[$msgid]);
+ if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
+ unless ($status{$msgid}) { $status{$msgid}='new'; }
+ }
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
}
@@ -337,7 +399,20 @@ sub del_url_author_res_msg {
}
return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
}
+# =================================== Clear out all author messages in URL path
+sub clear_author_res_msg {
+ my $url=shift;
+ $url=&Apache::lonnet::declutter($url);
+ my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
+ my @delmsgs=();
+ foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
+ if ($_=~/^\Q$url\E/) {
+ push (@delmsgs,$_);
+ }
+ }
+ return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
+}
# ================= Return hash with URLs for which there is a resource message
sub all_url_author_res_msg {
@@ -353,7 +428,7 @@ sub all_url_author_res_msg {
# ================================================== Critical message to a user
sub user_crit_msg_raw {
- my ($user,$domain,$subject,$message,$sendback,$toperm)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
# Check if allowed missing
my $status='';
my $msgid='undefined';
@@ -367,13 +442,9 @@ sub user_crit_msg_raw {
'put:'.$domain.':'.$user.':critical:'.
&Apache::lonnet::escape($msgid).'='.
&Apache::lonnet::escape($message),$homeserver);
- if ($env{'request.course.id'}) {
- &user_normal_msg_raw(
- $env{'course.'.$env{'request.course.id'}.'.num'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- 'Critical ['.$user.':'.$domain.']',
- $message);
- }
+ if (defined($sentmessage)) {
+ $$sentmessage = $message;
+ }
} else {
$status='no_host';
}
@@ -411,7 +482,7 @@ sub user_crit_msg_raw {
=cut
sub user_crit_msg {
- my ($user,$domain,$subject,$message,$sendback,$toperm)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
my $status='';
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -421,10 +492,10 @@ sub user_crit_msg {
my ($forwuser,$forwdomain)=split(/\:/,$_);
$status.=
&user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
- $sendback,$toperm).' ';
+ $sendback,$toperm,$sentmessage).' ';
}
} else {
- $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm);
+ $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);
}
return $status;
}
@@ -459,7 +530,7 @@ sub user_crit_received {
sub user_normal_msg_raw {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm)=@_;
+ $toperm,$currid,$newid,$sentmessage)=@_;
# Check if allowed missing
my $status='';
my $msgid='undefined';
@@ -468,7 +539,7 @@ sub user_normal_msg_raw {
my $homeserver=&Apache::lonnet::homeserver($user,$domain);
if ($homeserver ne 'no_host') {
($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
- $attachmenturl,$user,$domain);
+ $attachmenturl,$user,$domain,$currid);
# Store in user folder
$status=&Apache::lonnet::critical(
'put:'.$domain.':'.$user.':nohist_email:'.
@@ -477,15 +548,23 @@ sub user_normal_msg_raw {
# Save new message received time
&Apache::lonnet::put
('email_status',{'recnewemail'=>time},$domain,$user);
-# Into sent-mail folder
- $status.=' '.&Apache::lonnet::critical(
- 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
- ':nohist_email_sent:'.
- &Apache::lonnet::escape($msgid).'='.
- &Apache::lonnet::escape($message),$env{'user.home'});
+# Into sent-mail folder unless a broadcast message or critical message
+ unless (($env{'request.course.id'}) &&
+ (($env{'form.sendmode'} eq 'group') ||
+ (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
+ (&Apache::lonnet::allowed('srm',$env{'request.course.id'})))) {
+ $status .= &store_sent_mail($msgid,$message);
+ }
} else {
$status='no_host';
}
+ if (defined($newid)) {
+ $$newid = $msgid;
+ }
+ if (defined($sentmessage)) {
+ $$sentmessage = $message;
+ }
+
# Notifications
my %userenv = &Apache::lonnet::get('environment',['notification',
'permanentemail'],
@@ -516,7 +595,7 @@ sub user_normal_msg_raw {
sub user_normal_msg {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm)=@_;
+ $toperm,$sentmessage)=@_;
my $status='';
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
@@ -526,15 +605,24 @@ sub user_normal_msg {
my ($forwuser,$forwdomain)=split(/\:/,$_);
$status.=
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
- $citation,$baseurl,$attachmenturl,$toperm).' ';
+ $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage).' ';
}
} else {
$status=&user_normal_msg_raw($user,$domain,$subject,$message,
- $citation,$baseurl,$attachmenturl,$toperm);
+ $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage);
}
return $status;
}
+sub store_sent_mail {
+ my ($msgid,$message) = @_;
+ my $status =' '.&Apache::lonnet::critical(
+ 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
+ ':nohist_email_sent:'.
+ &Apache::lonnet::escape($msgid).'='.
+ &Apache::lonnet::escape($message),$env{'user.home'});
+ return $status;
+}
# ============================================================ List all folders
@@ -564,13 +652,14 @@ sub scrollbuttons {
my ($start,$maxdis,$first,$finish,$total)=@_;
unless ($total>0) { return ''; }
$start++; $maxdis++;$first++;$finish++;
- return
+ return
+ &mt('Page').': '.
' '.
' '.
' of '.$maxdis.
' '.
' '.
- &mt('Messages [_1] through [_2] of [_3]',$first,$finish,$total).'';
+ &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'';
}
# =============================================================== Folder suffix
@@ -596,6 +685,9 @@ sub statuschange {
if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
+ if ($newstatus eq 'deleted') {
+ &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
+ }
}
# ============================================================= Make new folder
@@ -768,8 +860,9 @@ sub sortedmessages {
my $msgid=&Apache::lonnet::escape($_);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
&Apache::lonmsg::unpackmsgid($msgid,$folder);
+ my $description = &get_course_desc($fromcid);
my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
- $msgid);
+ $msgid,$description);
# Check whether message was sent during blocking period.
if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
my $escid = &Apache::lonnet::unescape($msgid);
@@ -805,6 +898,12 @@ sub sortedmessages {
if ($env{'form.sortedby'} eq "revsubject"){
@temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
}
+ if ($env{'form.sortedby'} eq "course"){
+ @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
+ }
+ if ($env{'form.sortedby'} eq "revcourse"){
+ @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
+ }
if ($env{'form.sortedby'} eq "status"){
@temp = sort {$a->[4] cmp $b->[4]} @temp;
}
@@ -814,6 +913,18 @@ sub sortedmessages {
return @temp;
}
+sub get_course_desc {
+ my ($fromcid) = @_;
+ my $description;
+ if (defined($env{'course.'.$fromcid.'.description'})) {
+ $description = $env{'course.'.$fromcid.'.description'};
+ } else {
+ my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
+ $description = $courseinfo{'description'};
+ }
+ return $description;
+}
+
# ======================================================== Display new messages
@@ -822,6 +933,7 @@ sub disnew {
my %lt=&Apache::lonlocal::texthash(
'nm' => 'New Messages',
'su' => 'Subject',
+ 'co' => 'Course',
'da' => 'Date',
'us' => 'Username',
'op' => 'Open',
@@ -843,6 +955,7 @@ sub disnew {
my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
&Apache::lonmsg::unpackmsgid($_);
if (defined($sendtime) && $sendtime!~/error/) {
+ my $description = &get_course_desc($fromcid);
my $numsendtime = $sendtime;
$sendtime = &Apache::lonlocal::locallocaltime($sendtime);
if ($status eq 'new') {
@@ -855,7 +968,8 @@ sub disnew {
sendtime => $sendtime,
shortsub => &Apache::lonnet::unescape($shortsubj),
from => $fromname,
- fromdom => $fromdom
+ fromdom => $fromdom,
+ course => $description
}
}
}
@@ -865,14 +979,15 @@ sub disnew {
$r->print(<$lt{'nm'}
 
-$lt{'da'} $lt{'us'} $lt{'do'} $lt{'su'}
+$lt{'da'} $lt{'us'} $lt{'do'} $lt{'su'} $lt{'co'}
TABLEHEAD
foreach my $msg (@newmsgs) {
$r->print(<<"ENDLINK");
-
+
$lt{'op'}
ENDLINK
- foreach ('sendtime','from','fromdom','shortsub') {
+ foreach ('sendtime','from','fromdom','shortsub','course') {
$r->print("$msg->{$_} ");
}
$r->print(" ");
@@ -986,6 +1101,12 @@ ENDDISHEADER
$r->print(''.&mt('Subject').' ');
}
$r->print('');
+ if ($env{'form.sortedby'} eq "revcourse") {
+ $r->print(''.&mt('Course').' ');
+ } else {
+ $r->print(''.&mt('Course').' ');
+ }
+ $r->print(' ');
if ($env{'form.sortedby'} eq "revstatus") {
$r->print(''.&mt('Status').' ');
} else {
@@ -993,16 +1114,16 @@ ENDDISHEADER
}
$r->print("\n");
for (my $n=$firstdis;$n<=$lastdis;$n++) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @{$temp[$n]};
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,$description)= @{$temp[$n]};
if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
if ($status eq 'new') {
- $r->print('');
+ $r->print(' ');
} elsif ($status eq 'read') {
- $r->print(' ');
+ $r->print(' ');
} elsif ($status eq 'replied') {
- $r->print(' ');
+ $r->print(' ');
} else {
- $r->print(' ');
+ $r->print(' ');
}
$r->print(''.&mt('Open').' '.
@@ -1011,7 +1132,7 @@ ENDDISHEADER
' '.&Apache::lonlocal::locallocaltime($sendtime).' '.
$fromname.' '.$fromdomain.' '.
&Apache::lonnet::unescape($shortsubj).' '.
- $status." \n");
+ $description.''.$status.' '."\n");
} elsif ($status eq 'deleted') {
# purge
&movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
@@ -1095,8 +1216,9 @@ sub compout {
' '.&mt('Send as critical message').' ' .
&mt('and return receipt') . ' ' . $crithelp .
' '.
-&mt('Send copy to permanent email address (if known)').'
';
- }
+&mt('Send copy to permanent email address (if known)').''.
+''; }
my %message;
my %content;
my $defdom=$env{'user.domain'};
@@ -1173,7 +1295,7 @@ ENDREC
$lt{'sb'}:
$latexHelp
-
$dispcrit
$disbase
@@ -1192,7 +1314,7 @@ ENDCOMP
Subject:
General message text
-$dismsg
+$dismsg
The file format for the uploaded portion of the message is:
@@ -1214,7 +1336,9 @@ ENDUPLOAD
if ($broadcast eq 'group') {
&discourse;
}
- $r->print('');
+ $r->print(''.
+ &Apache::lonfeedback::generate_preview_button('compemail','message').
+ &Apache::lonhtmlcommon::htmlareaselectactive('message'));
}
# ---------------------------------------------------- Display all face to face
@@ -1235,8 +1359,8 @@ sub retrieve_instructor_comments {
my %content=&unpackagemsg($records{$_});
next if ($content{'senderdomain'} eq '');
next if ($content{'subject'} !~ /^Record/);
- # $content{'message'}=~s/\n/\ /g;
- $result.='Recorded by '.
+ # &Apache::lonfeedback::newline_to_br(\$content{'message'});
+ $result.='Recorded by '.
$content{'sendername'}.'@'.$content{'senderdomain'}."\n";
$result.=
&Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
@@ -1259,11 +1383,17 @@ sub disfacetoface {
foreach (sort keys %records) {
my %content=&unpackagemsg($records{$_});
next if ($content{'senderdomain'} eq '');
- $content{'message'}=~s/\n/\ /g;
+ &Apache::lonfeedback::newline_to_br(\$content{'message'});
if ($content{'subject'}=~/^Record/) {
$result.='
'.&mt('Record').' ';
} elsif ($content{'subject'}=~/^Broadcast/) {
$result .=''.&mt('Broadcast Message').' ';
+ if ($content{'subject'}=~/^Broadcast\./) {
+ %content=&unpackagemsg($content{'message'});
+ $content{'message'}=
+ ''.&mt('Subject').': '.$content{'subject'}.' '.
+ $content{'message'};
+ }
} else {
$result.=''.&mt('Critical Message').' ';
%content=&unpackagemsg($content{'message'});
@@ -1339,12 +1469,13 @@ ENDTREC
($env{'form.recdomain'}) && ($env{'form.recuname'})) {
chomp($env{'form.newrecord'});
if ($env{'form.newrecord'}) {
+ my $recordtxt = $env{'form.newrecord'};
&user_normal_msg_raw(
$env{'course.'.$env{'request.course.id'}.'.num'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
&mt('Record').
' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']',
- $env{'form.newrecord'});
+ $recordtxt);
}
$r->print(''.&Apache::loncommon::plainname($env{'form.recuname'},
$env{'form.recdomain'}).' ');
@@ -1776,7 +1907,7 @@ sub displaymessage {
''.&mt('Mark Unread').' '.
'Delete '.
+ '">'.&mt('Delete').' '.
''.&mt('Back to Folder Display').' ');
@@ -1789,6 +1920,30 @@ sub displaymessage {
'">'.&mt('Next').' ');
}
$r->print('');
+ if ($env{'user.adv'}) {
+ $r->print(''.&mt('Currently available actions (will open extra window)').': ');
+ my $symb=&Apache::lonnet::symbread($content{'baseurl'});
+ if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
+ $r->print(''.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').' ');
+ }
+ if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
+ $r->print(''.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').' ');
+ }
+ if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
+ $r->print(''.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').' ');
+ }
+ $r->print('
');
+ }
+ my $tolist;
+ my @recipients = ();
+ for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
+ $recipients[$i] = &Apache::loncommon::aboutmewrapper(
+ &Apache::loncommon::plainname($content{'recuser'}[$i],
+ $content{'recdomain'}[$i]),
+ $content{'recuser'}[$i],$content{'recdomain'}[$i]).
+ ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
+ }
+ $tolist = join(', ',@recipients);
$r->print(''.&mt('Subject').': '.$content{'subject'}.
($folder ne 'sent'?''.&mt('From').': '.
&Apache::loncommon::aboutmewrapper(
@@ -1796,11 +1951,7 @@ sub displaymessage {
$content{'sendername'},$content{'senderdomain'}).' ('.
$content{'sendername'}.' at '.
$content{'senderdomain'}.') ':''.&mt('To').': '.
- &Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($content{'recuser'},$content{'recdomain'}),
- $content{'recuser'},$content{'recdomain'}).' ('.
- $content{'recuser'}.' at '.
- $content{'recdomain'}.') ').
+ $tolist).
($content{'courseid'}?''.&mt('Course').': '.$courseinfo{'description'}.
($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):'').
''.&mt('Time').': '.$content{'time'}.
@@ -1852,7 +2003,8 @@ sub header {
my ($r,$title,$baseurl)=@_;
$r->print(&Apache::lonxml::xmlbegin().
''.&Apache::lonxml::fontsettings().
- 'Communication and Messages ');
+ 'Communication and Messages '.
+ &Apache::lonhtmlcommon::htmlareaheaders());
if ($baseurl) {
$r->print(" ");
}
@@ -1914,6 +2066,8 @@ sub sendoffmail {
my ($r,$folder)=@_;
my $suffix=&foldersuffix($folder);
my $sendstatus='';
+ my %specialmsg_status;
+ my $numspecial = 0;
if ($env{'form.send'}) {
&printheader($r,'','Messages being sent.');
$r->rflush();
@@ -1958,42 +2112,102 @@ sub sendoffmail {
$toaddr{$auname.':'.$audom}='';
}
}
+
+ my $savemsg;
+ my $msgtype;
+ my %sentmessage;
+ if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
+ (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
+ $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
+ $msgtype = 'critical';
+ } else {
+ $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
+ }
foreach (keys %toaddr) {
my ($recuname,$recdomain)=split(/\:/,$_);
- my $msgtxt;
- if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
- (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
- $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
- } else {
- $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
- }
+ my $msgtxt = $savemsg;
if ($toaddr{$_}) { $msgtxt.=' '.$toaddr{$_}; }
- my $thismsg;
+ my $thismsg;
if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
(&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
$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'});
+ $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,
- $content{'citation'},undef,undef,$env{'form.permanent'});
- if (($env{'request.course.id'}) && ($env{'form.sendmode'} eq 'group')) {
- &user_normal_msg_raw(
- $env{'course.'.$env{'request.course.id'}.'.num'},
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- 'Broadcast ['.$recuname.':'.$recdomain.']',
- $msgtxt);
- }
+ $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
+ }
+ if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
+ ($env{'form.sendmode'} eq 'group'))) {
+ $specialmsg_status{$recuname.':'.$recdomain} = $thismsg;
+ if ($thismsg eq 'ok') {
+ $numspecial ++;
+ }
}
$r->print($thismsg.' ');
$sendstatus.=' '.$thismsg;
}
+ if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
+ || ($msgtype eq 'critical'))) {
+ my $subj_prefix;
+ if ($msgtype eq 'critical') {
+ $subj_prefix = 'Critical.';
+ } else {
+ $subj_prefix = 'Broadcast.';
+ }
+ my ($specialmsgid,$specialresult);
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $course_str = &Apache::lonnet::escape('['.$cnum.':'.$cdom.']');
+
+ if ($numspecial) {
+ $specialresult = &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
+ ' '.$course_str,$savemsg,undef,undef,undef,
+ undef,undef,\$specialmsgid);
+ $specialmsgid = &Apache::lonnet::unescape($specialmsgid);
+ }
+ if ($specialresult eq 'ok') {
+ my $record_sent;
+ my @recusers = ();
+ my @recudoms = ();
+ my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) =
+ split(/\:/,&Apache::lonnet::unescape($specialmsgid));
+ foreach my $recipient (sort(keys(%toaddr))) {
+ if ($specialmsg_status{$recipient} eq 'ok') {
+ my $usersubj = $subj_prefix.'['.$recipient.']';
+ 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);
+ my ($uname,$udom) = split/:/,$recipient;
+ push(@recusers,$uname);
+ push(@recudoms,$udom);
+ }
+ }
+ if (@recusers) {
+ my $specialmessage;
+ my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
+ &Apache::lonfeedback::clear_out_html($env{'form.subject'});
+ $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);
+ $record_sent = &store_sent_mail($specialmsgid,$specialmessage);
+ }
+ } else {
+ &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
+ }
+ }
} else {
&printheader($r,'','No messages sent.');
}
@@ -2159,6 +2373,13 @@ sub handler {
if ($env{'form.storebasecomment'}) {
&storecomment($r);
}
+ if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
+ &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ 'Course_Announcements',
+ $env{'form.subject'},
+ $env{'form.message'},'/adm/communicate','public');
+ }
&disall($r,($folder?$folder:$dismode));
} elsif ($env{'form.newfolder'}) {
&printheader($r,'','New Folder');