--- loncom/interface/lonmsgdisplay.pm 2006/04/23 05:34:45 1.9
+++ loncom/interface/lonmsgdisplay.pm 2006/04/25 19:50:09 1.13
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.9 2006/04/23 05:34:45 albertel Exp $
+# $Id: lonmsgdisplay.pm,v 1.13 2006/04/25 19:50:09 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -392,18 +392,30 @@ sub sortedmessages {
my %descriptions;
my %status_cache =
&Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
- foreach (@messages) {
- my $msgid=&Apache::lonnet::escape($_);
+
+ my $get_received;
+ if ($folder eq 'sent'
+ && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
+ $get_received = 1;
+ }
+
+ foreach my $msgid (@messages) {
+ my $esc_msgid=&Apache::lonnet::escape($msgid);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
- &Apache::lonmsg::unpackmsgid($msgid,$folder,undef,
+ &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
\%status_cache);
my $description = &get_course_desc($fromcid,\%descriptions);
my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
- $msgid,$description);
+ $esc_msgid,$description);
+ if ($get_received) {
+ my %message = &Apache::lonnet::get('nohist_email'.$suffix,
+ [$msgid]);
+ my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
+ push(@temp1,$content{'recuser'},$content{'recdomain'});
+ }
# Check whether message was sent during blocking period.
if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
- my $escid = &Apache::lonnet::unescape($msgid);
- $$blocked{$escid} = 'ON';
+ $$blocked{$msgid} = 'ON';
$$numblocked ++;
} else {
push @temp ,\@temp1;
@@ -418,16 +430,32 @@ sub sortedmessages {
@temp = sort {$b->[0] <=> $a->[0]} @temp;
}
if ($env{'form.sortedby'} eq "user"){
- @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
+ if ($get_received) {
+ @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
+ } else {
+ @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
+ }
}
if ($env{'form.sortedby'} eq "revuser"){
- @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
+ if ($get_received) {
+ @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
+ } else {
+ @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
+ }
}
if ($env{'form.sortedby'} eq "domain"){
- @temp = sort {$a->[3] cmp $b->[3]} @temp;
+ if ($get_received) {
+ @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
+ } else {
+ @temp = sort {$a->[3] cmp $b->[3]} @temp;
+ }
}
if ($env{'form.sortedby'} eq "revdomain"){
- @temp = sort {$b->[3] cmp $a->[3]} @temp;
+ if ($get_received) {
+ @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
+ } else {
+ @temp = sort {$b->[3] cmp $a->[3]} @temp;
+ }
}
if ($env{'form.sortedby'} eq "subject"){
@temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
@@ -662,7 +690,9 @@ ENDDISHEADER
my $suffix = &Apache::lonmsg::foldersuffix($folder);
for (my $n=$firstdis;$n<=$lastdis;$n++) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,$description)= @{$temp[$n]};
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
+ $description,$recv_name,$recv_domain)=
+ @{$temp[$n]};
if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
if ($status eq 'new') {
$r->print('
');
@@ -675,12 +705,17 @@ ENDDISHEADER
}
my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
if ($folder eq 'sent') {
- my $msg_id = &Apache::lonnet::unescape($origID);
- my %message=&Apache::lonnet::get('nohist_email'.$suffix,
- [$msg_id]);
- my %content=&Apache::lonmsg::unpackagemsg($message{$msg_id});
- $dis_name = join('
',@{$content{'recuser'}});
- $dis_domain = join('
',@{$content{'recdomain'}});
+ if (defined($recv_name) && !defined($recv_domain)) {
+ $dis_name = join('
',@{$recv_name});
+ $dis_domain = join('
',@{$recv_domain});
+ } else {
+ my $msg_id = &Apache::lonnet::unescape($origID);
+ my %message = &Apache::lonnet::get('nohist_email'.$suffix,
+ [$msg_id]);
+ my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
+ $dis_name = join('
',@{$content{'recuser'}});
+ $dis_domain = join('
',@{$content{'recdomain'}});
+ }
}
$r->print(' | '.&mt('Open').' | '.
@@ -1684,17 +1719,17 @@ sub sendoffmail {
%content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
&statuschange($msgid,'replied',$folder);
}
- my %toaddr=();
- undef %toaddr;
+
+ my %toaddr;
if ($env{'form.sendmode'} eq 'group') {
- foreach (keys %env) {
- if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
+ foreach $address (keys(%env)) {
+ if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
$toaddr{$1}='';
}
}
} elsif ($env{'form.sendmode'} eq 'upload') {
- foreach (split(/[\n\r\f]+/,$env{'form.upfile'})) {
- my ($rec,$txt)=split(/\s*\:\s*/,$_);
+ foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
+ my ($rec,$txt)=split(/\s*\:\s*/,$line);
if ($txt) {
$rec=~s/\@/\:/;
$toaddr{$rec}.=$txt."\n";
@@ -1726,33 +1761,43 @@ sub sendoffmail {
$savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
}
- foreach (keys %toaddr) {
- my ($recuname,$recdomain)=split(/\:/,$_);
+ foreach my $address (sort(keys(%toaddr))) {
+ my ($recuname,$recdomain)=split(/\:/,$address);
my $msgtxt = $savemsg;
- if ($toaddr{$_}) { $msgtxt.=' '.$toaddr{$_}; }
- my $thismsg;
+ if ($toaddr{$address}) { $msgtxt.=' '.$toaddr{$address}; }
+ my @thismsg;
if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
(&Apache::lonnet::allowed('srm',$env{'request.course.id'})
|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
'/'.$env{'request.course.sec'}))) {
- $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');
- $thismsg=&Apache::lonmsg::user_crit_msg($recuname,$recdomain,$msgsubj,$msgtxt,
- $env{'form.sendbck'},$env{'form.permanent'},
- \$sentmessage{$_});
+ $r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': ');
+ @thismsg=
+ &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
+ $msgsubj,$msgtxt,
+ $env{'form.sendbck'},
+ $env{'form.permanent'},
+ \$sentmessage{$address});
} else {
$r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');
- $thismsg=&Apache::lonmsg::user_normal_msg($recuname,$recdomain,$msgsubj,$msgtxt,
- $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
+ @thismsg=
+ &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
+ $msgsubj,$msgtxt,
+ $content{'citation'},
+ undef,undef,
+ $env{'form.permanent'},
+ \$sentmessage{$address});
}
if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
($env{'form.sendmode'} eq 'group'))) {
- $specialmsg_status{$recuname.':'.$recdomain} = $thismsg;
- if ($thismsg eq 'ok') {
- $numspecial ++;
- }
+ $specialmsg_status{$recuname.':'.$recdomain} =
+ join(' ',@thismsg);
+ foreach my $result (@thismsg) {
+ if ($result eq 'ok') {
+ $numspecial++;
+ }
+ }
}
- $r->print($thismsg.' ');
- $sendstatus.=' '.$thismsg;
+ $sendstatus.=' '.join(' ',@thismsg);
}
if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
|| ($msgtype eq 'critical'))) {
@@ -1775,10 +1820,11 @@ sub sendoffmail {
}
if ($specialresult eq 'ok') {
my $record_sent;
- my @recusers = ();
- my @recudoms = ();
- my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
- split(/\:/,&Apache::lonnet::unescape($specialmsgid));
+ my @recusers;
+ my @recudoms;
+ 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') {
my $usersubj = $subj_prefix.'['.$recipient.']';
@@ -1790,15 +1836,15 @@ sub sendoffmail {
&Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
' ['.$recipient.']',$msgsubj,undef,
undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
- my ($uname,$udom) = split/:/,$recipient;
+ my ($uname,$udom) = split(/:/,$recipient);
push(@recusers,$uname);
push(@recudoms,$udom);
}
}
if (@recusers) {
my $specialmessage;
- my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
- $msgsubj;
+ my $sentsubj =
+ $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
$sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
my $sentmsgid =
&Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
@@ -1934,7 +1980,8 @@ sub handler {
my ($result,$msg) =
&statuschange($env{'form.markdel'},'deleted',$folder);
if (!$result) {
- $r->print('Failed to delete the message. '.
+ $r->print(''.
+ &mt('Failed to delete the message.').' '.
''.$msg." \n");
}
&Apache::loncommunicate::menu($r);
@@ -1957,12 +2004,13 @@ sub handler {
&printheader($r,'','Moved Messages');
if ($failed) {
$r->print('
- Failed to move '.$failed.' message(s) ');
+ '.&mt('Failed to move [_1] message(s)',$failed).
+ '');
$r->print(''.
join(" \n",@failed_msg).
" \n");
}
- $r->print('Moved '.$total.' message(s)');
+ $r->print(&mt('Moved [_1] message(s)',$total).' ');
&Apache::loncommunicate::menu($r);
&disall($r,($folder?$folder:$dismode));
} elsif ($env{'form.markeddel'}) {
@@ -1983,12 +2031,13 @@ sub handler {
&printheader($r,'','Deleted Messages');
if ($failed) {
$r->print('
- Failed to delete '.$failed.' message(s) ');
+ '.&mt('Failed to delete [_1] message(s)',$failed).
+ '');
$r->print(''.
join(" \n",@failed_msg).
" \n");
}
- $r->print('Deleted '.$total.' message(s)');
+ $r->print(&mt('Deleted [_1] message(s)',$total).' ');
&Apache::loncommunicate::menu($r);
&disall($r,($folder?$folder:$dismode));
} elsif ($env{'form.markunread'}) {
|