--- loncom/interface/lonmsg.pm 2004/05/10 22:39:51 1.100
+++ loncom/interface/lonmsg.pm 2004/09/28 14:12:40 1.109
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.100 2004/05/10 22:39:51 albertel Exp $
+# $Id: lonmsg.pm,v 1.109 2004/09/28 14:12:40 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -74,6 +74,18 @@ email program, so they have full access
interface, or other features they may wish to use in response to the
student's query.
+=item * B: LON-CAPA can block display of e-mails that are
+sent to a student during an online exam. A course coordinator or
+instructor can set an open and close date/time for scheduled online
+exams in a course. If a user uses the LON-CAPA internal messaging
+system to display e-mails during the scheduled blocking event,
+display of all e-mail sent during the blocking period will be
+suppressed, and a message of explanation, including details of the
+currently active blocking periods will be displayed instead. A user
+who has a course coordinator or instructor role in a course will be
+unaffected by any blocking periods for the course, unless the user
+also has a student role in the course, AND has selected the student role.
+
=back
Users can ask LON-CAPA to forward messages to conventional e-mail
@@ -105,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,'<>&"');
@@ -144,6 +159,8 @@ sub packagemsg {
''.$ENV{'request.role'}.''.
''.$ENV{'request.filename'}.''.
''.$msgid.''.
+ ''.$recuser.''.
+ ''.$recdomain.''.
''.$message.'';
if (defined($citation)) {
$result.=''.$citation.'';
@@ -189,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});
@@ -207,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
@@ -429,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';
}
@@ -482,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',
@@ -547,39 +642,36 @@ sub discourse {
ENDDISHEADER
- my %coursepersonnel=
- &Apache::lonnet::get_course_adv_roles();
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
+ $r->print('
'.
&mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
@@ -613,25 +705,35 @@ $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 @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);
- push @temp ,\@temp1;
+ # Check whether message was sent during blocking period.
+ if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
+ my $escid = &Apache::lonnet::unescape($msgid);
+ $$blocked{$escid} = 'ON';
+ $$numblocked ++;
+ } else {
+ push @temp ,\@temp1;
+ }
}
#default sort
@temp = sort {$a->[0] <=> $b->[0]} @temp;
@@ -671,8 +773,14 @@ sub sortedmessages {
# ======================================================== Display all messages
sub disall {
- my $r=shift;
- $r->print(<print(<
function checkall() {
for (i=0; i
ENDDISHEADER
- $r->print('