[LON-CAPA-cvs] cvs: loncom(version_2_1_X) /interface lonmsg.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Sun, 23 Apr 2006 05:47:34 -0000
albertel Sun Apr 23 01:47:34 2006 EDT
Modified files: (Branch: version_2_1_X)
/loncom/interface lonmsg.pm
Log:
- backport 1.9 of lonmsgdisplay
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.173 loncom/interface/lonmsg.pm:1.173.2.1
--- loncom/interface/lonmsg.pm:1.173 Mon Jan 23 18:15:51 2006
+++ loncom/interface/lonmsg.pm Sun Apr 23 01:47:33 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.173.2.1 2006/04/23 05:47:33 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -700,8 +700,9 @@
&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
if ($newstatus eq 'deleted') {
- &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
- }
+ return &movemsg($msgid,$folder,'trash');
+ }
+ return ;
}
# ============================================================= Make new folder
@@ -722,19 +723,53 @@
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
@@ -1163,7 +1198,9 @@
$description.'</td><td>'.$status.'</td></tr>'."\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("</table>\n<p>".
@@ -2378,31 +2415,63 @@
&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
} elsif ($env{'form.markdel'}) {
&printheader($r,'','Deleted Message');
- &statuschange($env{'form.markdel'},'deleted',$folder);
+ my ($result,$msg) =
+ &statuschange($env{'form.markdel'},'deleted',$folder);
+ if (!$result) {
+ $r->print('<p style="color: red">Failed to delete the message.</p>'.
+ '<p style="color: red">'.$msg."</p>\n");
+ }
&Apache::loncommunicate::menu($r);
&disall($r,($folder?$folder:$dismode));
} elsif ($env{'form.markedmove'}) {
- my $total=0;
- foreach (keys %env) {
- if ($_=~/^form\.delmark_(.*)$/) {
- &movemsg(&Apache::lonnet::unescape($1),$folder,
- $env{'form.movetofolder'});
- $total++;
+ my ($total,$failed,@failed_msg)=(0,0);
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.delmark_(.*)$/) {
+ my ($result,$msg) =
+ &movemsg(&Apache::lonnet::unescape($1),$folder,
+ $env{'form.movetofolder'});
+ if ($result) {
+ $total++;
+ } else {
+ $failed++;
+ push(@failed_msg,$msg);
+ }
}
}
&printheader($r,'','Moved Messages');
+ if ($failed) {
+ $r->print('<p style="color: red;">
+ Failed to move '.$failed.' message(s)</p>');
+ $r->print('<p style="color: red;">'.
+ join("</p>\n<p style=\"color: red;\">",@failed_msg).
+ "</p>\n");
+ }
$r->print('Moved '.$total.' message(s)<p>');
&Apache::loncommunicate::menu($r);
&disall($r,($folder?$folder:$dismode));
} elsif ($env{'form.markeddel'}) {
- my $total=0;
- foreach (keys %env) {
- if ($_=~/^form\.delmark_(.*)$/) {
- &statuschange(&Apache::lonnet::unescape($1),'deleted',$folder);
- $total++;
+ my ($total,$failed,@failed_msg)=(0,0);
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.delmark_(.*)$/) {
+ my ($result,$msg) =
+ &statuschange(&Apache::lonnet::unescape($1),'deleted',
+ $folder);
+ if ($result) {
+ $total++;
+ } else {
+ $failed++;
+ push(@failed_msg,$msg);
+ }
}
}
&printheader($r,'','Deleted Messages');
+ if ($failed) {
+ $r->print('<p style="color: red;">
+ Failed to delete '.$failed.' message(s)</p>');
+ $r->print('<p style="color: red;">'.
+ join("</p>\n<p style=\"color: red;\">",@failed_msg).
+ "</p>\n");
+ }
$r->print('Deleted '.$total.' message(s)<p>');
&Apache::loncommunicate::menu($r);
&disall($r,($folder?$folder:$dismode));