--- loncom/interface/lonmsg.pm 2005/05/20 17:00:40 1.143
+++ loncom/interface/lonmsg.pm 2006/04/23 05:47:33 1.173.2.1
@@ -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.173.2.1 2006/04/23 05:47:33 albertel 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 ".
@@ -1087,7 +1273,9 @@ sub compout {
'ca' => 'Cancel',
'ma' => 'Mail');
- if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
+ if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
$dispcrit=
' ' . $crithelp .
@@ -1095,8 +1283,9 @@ sub compout {
'' . $crithelp .
'
'.
- &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 +699,10 @@ sub statuschange {
if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
+ if ($newstatus eq 'deleted') {
+ return &movemsg($msgid,$folder,'trash');
+ }
+ return ;
}
# ============================================================= Make new folder
@@ -616,19 +723,53 @@ sub movemsg {
if ($srcfolder eq 'new') { $srcfolder=''; }
my $srcsuffix=&foldersuffix($srcfolder);
my $trgsuffix=&foldersuffix($trgfolder);
+ if ($srcsuffix eq $trgsuffix) {
+ return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
+ }
# Copy message
my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
- &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}});
+ if (!exists($message{$msgid}) || $message{$msgid} eq '') {
+ if (&Apache::slotrequest::network_error(%message)) {
+ return (0,&mt('Message not moved, A network error occurred.'));
+ } else {
+ return (0,&mt('Message not moved as the message is no longer in the source folder.'));
+ }
+ }
+
+ my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
+ {$msgid => $message{$msgid}});
+ if (&Apache::slotrequest::network_error($result)) {
+ return (0,&mt('Message not moved, A network error occurred.'));
+ }
# Copy status
unless ($trgfolder eq 'trash') {
- my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
- &Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}});
+ my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
+ # a non-existant status is the mark of an unread msg
+ if (&Apache::slotrequest::network_error(%status)) {
+ return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
+ }
+ my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
+ {$msgid => $status{$msgid}});
+ if (&Apache::slotrequest::network_error($result)) {
+ return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
+ }
}
+
# Delete orginals
- &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
- &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
+ my $result_del_msg =
+ &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
+ my $result_del_stat =
+ &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
+ if (&Apache::slotrequest::network_error($result_del_msg)) {
+ return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
+ }
+ if (&Apache::slotrequest::network_error($result_del_stat)) {
+ return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
+ }
+
+ return (1);
}
# ======================================================= Display a course list
@@ -764,12 +905,17 @@ sub sortedmessages {
my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
#unpack the varibles and repack into temp for sorting
my @temp;
+ my %descriptions;
+ my %status_cache =
+ &Apache::lonnet::get('email_status'.&foldersuffix($folder),\@messages);
foreach (@messages) {
my $msgid=&Apache::lonnet::escape($_);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
- &Apache::lonmsg::unpackmsgid($msgid,$folder);
+ &Apache::lonmsg::unpackmsgid($msgid,$folder,undef,
+ \%status_cache);
+ my $description = &get_course_desc($fromcid,\%descriptions);
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 +951,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 +966,27 @@ sub sortedmessages {
return @temp;
}
+sub get_course_desc {
+ my ($fromcid,$descriptions) = @_;
+ my $description;
+ if (!$fromcid) {
+ return $description;
+ } else {
+ if (defined($$descriptions{$fromcid})) {
+ $description = $$descriptions{$fromcid};
+ } else {
+ if (defined($env{'course.'.$fromcid.'.description'})) {
+ $description = $env{'course.'.$fromcid.'.description'};
+ } else {
+ my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'};
+ $description = $courseinfo{'description'};
+ }
+ $$descriptions{$fromcid} = $description;
+ }
+ return $description;
+ }
+}
+
# ======================================================== Display new messages
@@ -822,15 +995,13 @@ sub disnew {
my %lt=&Apache::lonlocal::texthash(
'nm' => 'New Messages',
'su' => 'Subject',
+ 'co' => 'Course',
'da' => 'Date',
'us' => 'Username',
'op' => 'Open',
'do' => 'Domain'
);
- my @msgids = sort split(/\&/,&Apache::lonnet::reply
- ('keys:'.$env{'user.domain'}.':'.
- $env{'user.name'}.':nohist_email',
- $env{'user.home'}));
+ my @msgids = sort(&Apache::lonnet::getkeys('nohist_email'));
my @newmsgs;
my %setters = ();
my $startblock = 0;
@@ -839,10 +1010,15 @@ sub disnew {
my $numblocked = 0;
# Check for blocking of display because of scheduled online exams.
&blockcheck(\%setters,\$startblock,\$endblock);
+ my %status_cache =
+ &Apache::lonnet::get('email_status',\@msgids);
+ my %descriptions;
foreach (@msgids) {
+ my $msgid=&Apache::lonnet::escape($_);
my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
- &Apache::lonmsg::unpackmsgid($_);
+ &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache);
if (defined($sendtime) && $sendtime!~/error/) {
+ my $description = &get_course_desc($fromcid,\%descriptions);
my $numsendtime = $sendtime;
$sendtime = &Apache::lonlocal::locallocaltime($sendtime);
if ($status eq 'new') {
@@ -851,11 +1027,12 @@ sub disnew {
$numblocked ++;
} else {
push @newmsgs, {
- msgid => $_,
+ msgid => $msgid,
sendtime => $sendtime,
shortsub => &Apache::lonnet::unescape($shortsubj),
from => $fromname,
- fromdom => $fromdom
+ fromdom => $fromdom,
+ course => $description
}
}
}
@@ -865,14 +1042,15 @@ sub disnew {
$r->print(<
\n
+ 
-$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");
-
+
");
@@ -986,6 +1164,12 @@ ENDDISHEADER
$r->print(''.&mt('Subject').'');
}
$r->print('$lt{'op'}
ENDLINK
- foreach ('sendtime','from','fromdom','shortsub') {
+ foreach ('sendtime','from','fromdom','shortsub','course') {
$r->print("$msg->{$_} ");
}
$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 +1177,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(' \n");
+ $description.''.&mt('Open').' '.
@@ -1011,10 +1195,12 @@ ENDDISHEADER
' '.&Apache::lonlocal::locallocaltime($sendtime).' '.
$fromname.' '.$fromdomain.' '.
&Apache::lonnet::unescape($shortsubj).' '.
- $status." '.$status.' '."\n");
} elsif ($status eq 'deleted') {
# purge
- &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
+ my ($result,$msg) =
+ &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
+
}
}
$r->print("