--- loncom/interface/lonmsg.pm 2004/06/02 20:40:07 1.102
+++ loncom/interface/lonmsg.pm 2004/10/26 19:50:15 1.111
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.102 2004/06/02 20:40:07 raeburn Exp $
+# $Id: lonmsg.pm,v 1.111 2004/10/26 19:50:15 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -117,11 +117,14 @@ use Apache::loncommunicate;
# Querystring component with sorting type
my $sqs;
+my $startdis;
+my $interdis;
# ===================================================================== Package
sub packagemsg {
- my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_;
+ my ($subject,$message,$citation,$baseurl,$attachmenturl,
+ $recuser,$recdomain)=@_;
$message =&HTML::Entities::encode($message,'<>&"');
$citation=&HTML::Entities::encode($citation,'<>&"');
$subject =&HTML::Entities::encode($subject,'<>&"');
@@ -156,6 +159,8 @@ sub packagemsg {
''.$ENV{'request.role'}.' '.
''.$ENV{'request.filename'}.' '.
''.$msgid.' '.
+ ''.$recuser.' '.
+ ''.$recdomain.' '.
''.$message.' ';
if (defined($citation)) {
$result.=''.$citation.' ';
@@ -201,10 +206,12 @@ sub unpackagemsg {
# ======================================================= Get info out of msgid
sub unpackmsgid {
- my $msgid=&Apache::lonnet::unescape(shift);
+ my ($msgid,$folder)=@_;
+ $msgid=&Apache::lonnet::unescape($msgid);
+ my $suffix=&foldersuffix($folder);
my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
&Apache::lonnet::unescape($msgid));
- my %status=&Apache::lonnet::get('email_status',[$msgid]);
+ my %status=&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});
@@ -219,10 +226,14 @@ sub sendemail {
my $msg = new Mail::Send;
$msg->to($to);
$msg->subject('[LON-CAPA] '.$subject);
+ my %oldENV=%ENV;
+ undef(%ENV);
if (my $fh = $msg->open()) {
print $fh $body;
$fh->close;
}
+ %ENV=%oldENV;
+ undef(%oldENV);
}
# ==================================================== Send notification emails
@@ -441,13 +452,21 @@ 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);
+ $attachmenturl,$user,$domain);
+# Store in user folder
$status=&Apache::lonnet::critical(
'put:'.$domain.':'.$user.':nohist_email:'.
&Apache::lonnet::escape($msgid).'='.
&Apache::lonnet::escape($message),$homeserver);
+# 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'});
} else {
$status='no_host';
}
@@ -494,30 +513,94 @@ sub user_normal_msg {
}
+# ============================================================ List all folders
+
+sub folderlist {
+ my $folder=shift;
+ my @allfolders=&Apache::lonnet::getkeys('email_folders');
+ if ($allfolders[0]=~/^error:/) { @allfolders=(); }
+ return '
';
+}
+
+# =============================================================== Folder suffix
+
+sub foldersuffix {
+ my $folder=shift;
+ unless ($folder) { return ''; }
+ return '_'.&Apache::lonnet::escape($folder);
+}
+
# =============================================================== Status Change
sub statuschange {
- my ($msgid,$newstatus)=@_;
- my %status=&Apache::lonnet::get('email_status',[$msgid]);
+ my ($msgid,$newstatus,$folder)=@_;
+ my $suffix=&foldersuffix($folder);
+ my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
unless ($status{$msgid}) { $status{$msgid}='new'; }
unless (($status{$msgid} eq 'replied') ||
($status{$msgid} eq 'forwarded')) {
- &Apache::lonnet::put('email_status',{$msgid => $newstatus});
+ &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
- &Apache::lonnet::put('email_status',{$msgid => $newstatus});
+ &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
}
}
+# ============================================================= Make new folder
+
+sub makefolder {
+ my ($newfolder)=@_;
+ &Apache::lonnet::put('email_folders',{$newfolder => time});
+}
+
+# ======================================================== Move between folders
+
+sub movemsg {
+ my ($msgid,$srcfolder,$trgfolder)=@_;
+ my $unmsgid=&Apache::lonnet::unescape($msgid);
+ my $srcsuffix=&foldersuffix($srcfolder);
+ my $trgsuffix=&foldersuffix($trgfolder);
+
+# Copy message
+ my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
+ &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}});
+
+# Copy status
+ my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$unmsgid]);
+ &Apache::lonnet::put('email_status'.$trgsuffix,{$unmsgid => $status{$unmsgid}});
+# See if was deleted -> becomes "read" in trash
+ my $currentstatus=(&unpackmsgid($status{$unmsgid}),$srcfolder);
+ if ($currentstatus eq 'deleted') {
+ &statuschange($msgid,'read',$trgfolder);
+ }
+# Delete orginals
+ &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
+ &Apache::lonnet::del('email_status'.$srcsuffix,[$unmsgid]);
+}
+
# ======================================================= Display a course list
sub discourse {
my $r=shift;
- my %courselist=&Apache::lonnet::dump(
- 'classlist',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my $classlist = &Apache::loncoursedata::get_classlist();
my $now=time;
my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All',
'cfs' => 'Check for Section/Group',
@@ -559,39 +642,36 @@ sub discourse {
ENDDISHEADER
- my %coursepersonnel=
- &Apache::lonnet::get_course_adv_roles();
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
+ $r->print('
');
foreach my $role (sort keys %coursepersonnel) {
- foreach (split(/\,/,$coursepersonnel{$role})) {
- my ($puname,$pudom)=split(/\:/,$_);
- $r->print(
- ' '.
- &Apache::loncommon::plainname($puname,
- $pudom).' ('.$_.'), '.$role.' ');
- }
+ foreach (split(/\,/,$coursepersonnel{$role})) {
+ my ($puname,$pudom)=split(/\:/,$_);
+ $r->print(''.
+ ' '.
+ &Apache::loncommon::plainname($puname,$pudom).
+ ' '.
+ '('.$_.'), '.$role.' ');
+ }
}
-
- foreach (sort keys %courselist) {
- my ($end,$start)=split(/\:/,$courselist{$_});
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- if ($active) {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::get('environment',
- ['firstname','middlename','lastname','generation'],
- $sdom,$sname);
- my $section=&Apache::lonnet::usection
- ($sdom,$sname,$ENV{'request.course.id'});
- $r->print(
- ' '.
- $reply{'firstname'}.' '.
- $reply{'middlename'}.' '.
- $reply{'lastname'}.' '.
- $reply{'generation'}.
- ' ('.$_.') '.$section);
- }
+ $r->print('
');
}
# ==================================================== Display Critical Message
@@ -607,13 +687,13 @@ sub discrit {
my %content=&unpackagemsg($what{$_});
next if ($content{'senderdomain'} eq '');
$content{'message'}=~s/\n/\ /g;
- $result.=' '.&mt('From').': '.
+ $result.=' '.&mt('From').': '.
&Apache::loncommon::aboutmewrapper(
&Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
$content{'sendername'}.'@'.
$content{'senderdomain'}.') '.$content{'time'}.
- ' '.&mt('Subject').': '.$content{'subject'}.
- ''.
+ ' '.&mt('Subject').': '.$content{'subject'}.
+ ''.
&Apache::lontexconvert::msgtexconverted($content{'message'}).
' '.
&mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
@@ -625,23 +705,25 @@ $content{'sendername'}.'@'.
# Check to see if there were any messages.
if ($result eq '') {
$result = "".&mt('You have no critical messages.')." ".
- ''.&mt('Select a course').' ';
+ ''.&mt('Select a course').' '.
+ ''.&mt('Communicate').' ';
} else {
$r->print($header);
}
$r->print($result);
- $r->print(' ');
+ $r->print(' ');
}
sub sortedmessages {
- my ($blocked,$startblock,$endblock,$numblocked) = @_;
- my @messages = &Apache::lonnet::getkeys('nohist_email');
+ my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_;
+ my $suffix=&foldersuffix($folder);
+ my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
#unpack the varibles and repack into temp for sorting
my @temp;
foreach (@messages) {
my $msgid=&Apache::lonnet::escape($_);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
- &Apache::lonmsg::unpackmsgid($msgid);
+ &Apache::lonmsg::unpackmsgid($msgid,$folder);
my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
$msgid);
# Check whether message was sent during blocking period.
@@ -691,7 +773,7 @@ sub sortedmessages {
# ======================================================== Display all messages
sub disall {
- my $r=shift;
+ my ($r,$folder)=@_;
my %blocked = ();
my %setters = ();
my $startblock;
@@ -719,42 +801,50 @@ sub disall {
}
ENDDISHEADER
- $r->print(''.&mt('Display All Messages').'