--- loncom/interface/lonmsg.pm 2006/03/21 20:54:35 1.179
+++ loncom/interface/lonmsg.pm 2009/01/04 16:21:10 1.214.2.4
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.179 2006/03/21 20:54:35 albertel Exp $
+# $Id: lonmsg.pm,v 1.214.2.4 2009/01/04 16:21:10 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,7 +26,6 @@
# http://www.lon-capa.org/
#
-
package Apache::lonmsg;
=pod
@@ -37,61 +36,7 @@ Apache::lonmsg: supports internal messag
=head1 SYNOPSIS
-lonmsg provides routines for sending messages, receiving messages, and
-a handler to allow users to read, send, and delete messages.
-
-=head1 OVERVIEW
-
-=head2 Messaging Overview
-
-XLON-CAPA provides an internal messaging system similar to
-email, but customized for LON-CAPA's usage. LON-CAPA implements its
-own messaging system, rather then building on top of email, because of
-the features LON-CAPA messages can offer that conventional e-mail can
-not:
-
-=over 4
-
-=item * B: A message the recipient B
-acknowlegde receipt of before they are allowed to continue using the
-system, preventing a user from claiming they never got a message
-
-=item * B: LON-CAPA can reliably send reciepts informing the
-sender that it has been read; again, useful for preventing students
-from claiming they did not see a message. (While conventional e-mail
-has some reciept support, it's sporadic, e-mail client-specific, and
-generally the receiver can opt to not send one, making it useless in
-this case.)
-
-=item * B: LON-CAPA knows about the sender, such as where
-they are in a course. When a student mails an instructor asking for
-help on the problem, the instructor receives not just the student's
-question, but all submissions the student has made up to that point,
-the user's rendering of the problem, and the complete view the student
-saw of the resource, including discussion up to that point. Finally,
-the instructor is reading all of this inside of LON-CAPA, not their
-email program, so they have full access to LON-CAPA's grading
-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
-addresses on their B screen, but generally, LON-CAPA messages
-are much more useful than traditional email can be made to be, even
-with HTML support.
+lonmsg provides routines for sending messages.
Right now, this document will cover just how to send a message, since
it is likely you will not need to programmatically read messages,
@@ -102,10 +47,10 @@ only used by lonmsg when creating/extrac
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 $uname and
-$udom in stored internal messages, compared
+similar. The differences are the use of $uname and
+$udom in stored internal messages, compared
with $email in stored
-Domain Coordinator e-mail for the storage of information about
+Domain Coordinator e-mail for the storage of information about
recipients of the message/e-mail.
=head1 FUNCTIONS
@@ -116,59 +61,39 @@ recipients of the message/e-mail.
use strict;
use Apache::lonnet;
-use vars qw($msgcount);
use HTML::TokeParser();
-use Apache::Constants qw(:common);
-use Apache::loncommon();
-use Apache::lontexconvert();
-use HTML::Entities();
-use Mail::Send;
use Apache::lonlocal;
-use Apache::loncommunicate;
-use Apache::lonfeedback;
-use Apache::lonrss();
-
-# Querystring component with sorting type
-my $sqs;
-my $startdis;
-my $interdis;
+use Mail::Send;
+use LONCAPA qw(:DEFAULT :match);
+
+{
+ my $uniq;
+ sub get_uniq {
+ $uniq++;
+ return $uniq;
+ }
+}
# ===================================================================== Package
sub packagemsg {
my ($subject,$message,$citation,$baseurl,$attachmenturl,
- $recuser,$recdomain,$msgid,$type,$crsmsgid)=@_;
+ $recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error,$recipid)=@_;
$message =&HTML::Entities::encode($message,'<>&"');
$citation=&HTML::Entities::encode($citation,'<>&"');
$subject =&HTML::Entities::encode($subject,'<>&"');
#remove machine specification
- $baseurl =~ s|^http://[^/]+/|/|;
+ $baseurl =~ s|^https?\://[^/]+/|/|;
$baseurl =&HTML::Entities::encode($baseurl,'<>&"');
#remove machine specification
- $attachmenturl =~ s|^http://[^/]+/|/|;
+ $attachmenturl =~ s|^https?\://[^/]+/|/|;
$attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
- my $course_context;
- if (defined($env{'form.replyid'})) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
- split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));
- $course_context = $origcid;
- }
- foreach my $key (keys(%env)) {
- if ($key=~/^form\.(rep)?rec\_(.*)$/) {
- my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
- split(/\:/,&Apache::lonnet::unescape($2));
- $course_context = $origcid;
- last;
- }
- }
- unless(defined($course_context)) {
- $course_context = $env{'request.course.id'};
- }
+ my $course_context = &get_course_context();
my $now=time;
- $msgcount++;
+ my $msgcount = &get_uniq();
unless(defined($msgid)) {
$msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
- $msgcount,$course_context,$$);
+ $msgcount,$course_context,$symb,$error,$$);
}
my $result = ''.$env{'user.name'}.''.
''.$env{'user.domain'}.''.
@@ -195,12 +120,15 @@ sub packagemsg {
''.$env{'request.role'}.''.
''.$env{'request.filename'}.''.
''.$msgid.'';
+ if (defined($env{'form.group'})) {
+ $result .= ''.$env{'form.group'}.'';
+ }
if (ref($recuser) eq 'ARRAY') {
for (my $i=0; $i<@{$recuser}; $i++) {
if ($type eq 'dcmail') {
my ($username,$email) = split(/:/,$$recuser[$i]);
- $username = &Apache::lonnet::unescape($username);
- $email = &Apache::lonnet::unescape($email);
+ $username = &unescape($username);
+ $email = &unescape($email);
$username = &HTML::Entities::encode($username,'<>&"');
$email = &HTML::Entities::encode($email,'<>&"');
$result .= ''.
@@ -224,13 +152,67 @@ sub packagemsg {
if (defined($attachmenturl)) {
$result.= ''.$attachmenturl.'';
}
- return $msgid,$result;
+ if (defined($symb)) {
+ $result.= ''.$symb.'';
+ if ($course_context ne '') {
+ if ($course_context eq $env{'request.course.id'}) {
+ my $resource_title = &Apache::lonnet::gettitle($symb);
+ if (defined($resource_title)) {
+ $result .= ''.$resource_title.'';
+ }
+ }
+ }
+ }
+ if (defined($recipid)) {
+ $result.= ''.$recipid.'';
+ }
+ if ($env{'form.can_reply'} eq 'N') {
+ $result .= '1';
+ }
+ if ($env{'form.reply_to_addr'}) {
+ my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
+ if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
+ if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
+ $result .= ''.$env{'form.reply_to_addr'}.'';
+ }
+ }
+ }
+ return ($msgid,$result);
+}
+
+sub get_course_context {
+ my $course_context;
+ my $msgkey;
+ if (defined($env{'form.replyid'})) {
+ $msgkey = $env{'form.replyid'};
+ } elsif (defined($env{'form.forwid'})) {
+ $msgkey = $env{'form.forwid'}
+ } elsif (defined($env{'form.multiforwid'})) {
+ $msgkey = $env{'form.multiforwid'};
+ }
+ if ($msgkey ne '') {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
+ split(/\:/,&unescape($msgkey));
+ $course_context = $origcid;
+ }
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.(rep)?rec\_(.*)$/) {
+ my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
+ split(/\:/,&unescape($2));
+ $course_context = $origcid;
+ last;
+ }
+ }
+ if ($course_context eq '') {
+ $course_context = $env{'request.course.id'};
+ }
+ return $course_context;
}
# ================================================== Unpack message into a hash
sub unpackagemsg {
- my ($message,$notoken)=@_;
+ my ($message,$notoken,$noattachmentlink)=@_;
my %content=();
my $parser=HTML::TokeParser->new(\$message);
my $token;
@@ -250,7 +232,7 @@ sub unpackagemsg {
}
}
if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
- if ($content{'attachmenturl'}) {
+ if (($content{'attachmenturl'}) && (!$noattachmentlink)) {
my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
if ($notoken) {
$content{'message'}.='
'.&mt('Attachment').': '.$fname.'';
@@ -268,17 +250,21 @@ sub unpackagemsg {
# ======================================================= Get info out of msgid
sub buildmsgid {
- my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
- $subject=&Apache::lonnet::escape($subject);
- return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.
- $udom.':'.$msgcount.':'.$course_context.':'.$pid));
+ my ($now,$subject,$uname,$udom,$msgcount,$course_context,$symb,$error,$pid) = @_;
+ $subject=&escape($subject);
+ $symb = &escape($symb);
+ return(&escape($now.':'.$subject.':'.$uname.':'.
+ $udom.':'.$msgcount.':'.$course_context.':'.$pid.':'.$symb.':'.$error));
}
sub unpackmsgid {
my ($msgid,$folder,$skipstatus,$status_cache)=@_;
- $msgid=&Apache::lonnet::unescape($msgid);
+ $msgid=&unescape($msgid);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
- $processid)=split(/\:/,&Apache::lonnet::unescape($msgid));
+ $processid,$symb,$error) = split(/\:/,&unescape($msgid));
+ $shortsubj = &unescape($shortsubj);
+ $shortsubj = &HTML::Entities::decode($shortsubj);
+ $symb = &unescape($symb);
if (!defined($processid)) { $fromcid = ''; }
my %status=();
unless ($skipstatus) {
@@ -291,18 +277,54 @@ sub unpackmsgid {
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
unless ($status{$msgid}) { $status{$msgid}='new'; }
}
- return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
+ return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid,$symb,$error);
}
sub sendemail {
- my ($to,$subject,$body)=@_;
+ my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;
+ my $senderaddress='';
+ my $replytoaddress='';
+ if ($env{'form.can_reply'} eq 'N') {
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ my $hostname = &Apache::lonnet::hostname($lonhost);
+ $replytoaddress = 'do-not-reply@'.$hostname;
+ } else {
+ my %senderemails;
+ my $have_sender;
+ if ($env{'form.reply_to_addr'}) {
+ my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
+ if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
+ if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
+ %senderemails =
+ &Apache::loncommon::getemails($replytoname,$replytodom);
+ $have_sender = 1;
+ }
+ }
+ }
+ if (!$have_sender) {
+ %senderemails=&Apache::loncommon::getemails();
+ }
+ foreach my $type ('permanentemail','critnotification','notification') {
+ if ($senderemails{$type}) {
+ ($senderaddress) = split(/,/,$senderemails{$type});
+ last if ($senderaddress);
+ }
+ }
+ }
$body=
- "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
- "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
+ "*** ".&mt_user($user_lh,'This is an automatic message generated by the LON-CAPA system.')."\n".
+ "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this message'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ".
+ &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body;
my $msg = new Mail::Send;
$msg->to($to);
$msg->subject('[LON-CAPA] '.$subject);
+ if ($replytoaddress) {
+ $msg->add('Reply-to',$replytoaddress);
+ }
+ if ($senderaddress) {
+ $msg->add('From',$senderaddress);
+ }
if (my $fh = $msg->open()) {
print $fh $body;
$fh->close;
@@ -312,41 +334,100 @@ sub sendemail {
# ==================================================== Send notification emails
sub sendnotification {
- my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
+ my ($to,$touname,$toudom,$subj,$crit,$text,$msgid)=@_;
my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
unless ($sender=~/\w/) {
- $sender=$env{'user.name'}.'@'.$env{'user.domain'};
+ $sender=$env{'user.name'}.':'.$env{'user.domain'};
}
my $critical=($crit?' critical':'');
+
$text=~s/\<\;/\/gs;
- $text=~s/\<\/*[^\>]+\>//gs;
- my $url='http://'.
- $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
- '/adm/email?username='.$touname.'&domain='.$toudom;
- my $body=(<]+\>//gs;
+ }
+ $body = $bodybegin.$bodysubj.$sendtext.$bodyend;
+ }
+ &sendemail($addr,$subject,$body,$touname,$toudom,$user_lh);
+ }
+ } else {
+ if ($blocked) {
+ $body = $bodybegin."\n".$blocktext."\n".$bodyend;
+ } else {
+ $text =~ s/\<\/*[^\>]+\>//gs;
+ $body = $bodybegin.$bodysubj.$text.$bodyend;
+ }
+ &sendemail($to,$subject,$body,$touname,$toudom,$user_lh);
+ }
}
# ============================================================= Check for email
sub newmail {
if ((time-$env{'user.mailcheck.time'})>300) {
my %what=&Apache::lonnet::get('email_status',['recnewemail']);
- &Apache::lonnet::appenv('user.mailcheck.time'=>time);
+ &Apache::lonnet::appenv({'user.mailcheck.time'=>time});
if ($what{'recnewemail'}>0) { return 1; }
}
return 0;
@@ -369,12 +450,14 @@ sub author_res_msg {
my $homeserver=&Apache::lonnet::homeserver($author,$domain);
if ($homeserver ne 'no_host') {
my $id=unpack("%32C*",$message);
+ $message .= "
This error occurred on machine ".
+ $Apache::lonnet::perlvar{'lonHostID'}."
";
my $msgid;
($msgid,$message)=&packagemsg($filename,$message);
return &Apache::lonnet::reply('put:'.$domain.':'.$author.
':nohist_res_msgs:'.
- &Apache::lonnet::escape($filename.'_'.$id).'='.
- &Apache::lonnet::escape($message),$homeserver);
+ &escape($filename.'_'.$id).'='.
+ &escape($message),$homeserver);
}
return 'no_host';
}
@@ -384,7 +467,7 @@ sub author_res_msg {
sub retrieve_author_res_msg {
my $url=shift;
$url=&Apache::lonnet::declutter($url);
- my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
+ my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
my $msgs='';
foreach (keys %errormsgs) {
@@ -404,7 +487,7 @@ sub retrieve_author_res_msg {
sub del_url_author_res_msg {
my $url=shift;
$url=&Apache::lonnet::declutter($url);
- my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
+ my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
my @delmsgs=();
foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
if ($_=~/^\Q$url\E\_\d+$/) {
@@ -418,7 +501,7 @@ sub del_url_author_res_msg {
sub clear_author_res_msg {
my $url=shift;
$url=&Apache::lonnet::declutter($url);
- my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
+ my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
my @delmsgs=();
foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
if ($_=~/^\Q$url\E/) {
@@ -439,40 +522,63 @@ sub all_url_author_res_msg {
return %returnhash;
}
+# ====================================== Add a comment to the User Notes screen
+
+sub store_instructor_comment {
+ my ($msg,$uname,$udom) = @_;
+ my $cid = $env{'request.course.id'};
+ my $cnum = $env{'course.'.$cid.'.num'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
+ my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
+ if ($result eq 'ok' || $result eq 'con_delayed') {
+
+ }
+ return $result;
+}
+
# ================================================== Critical message to a user
sub user_crit_msg_raw {
- my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
+ $nosentstore,$recipid,$attachmenturl)=@_;
# Check if allowed missing
- my $status='';
+ my ($status,$packed_message);
my $msgid='undefined';
unless (($message)&&($user)&&($domain)) { $status='empty'; };
my $text=$message;
my $homeserver=&Apache::lonnet::homeserver($user,$domain);
if ($homeserver ne 'no_host') {
- ($msgid,$message)=&packagemsg($subject,$message);
- if ($sendback) { $message.='true'; }
- $status=&Apache::lonnet::critical(
- 'put:'.$domain.':'.$user.':critical:'.
- &Apache::lonnet::escape($msgid).'='.
- &Apache::lonnet::escape($message),$homeserver);
+ ($msgid,$packed_message)=&packagemsg($subject,$message,undef,undef,
+ $attachmenturl,undef,undef,undef,undef,undef,
+ undef,undef,$recipid);
+ if ($sendback) { $packed_message.='true'; }
+ $status=&Apache::lonnet::cput('critical', {$msgid => $packed_message},
+ $domain,$user);
if (defined($sentmessage)) {
- $$sentmessage = $message;
+ $$sentmessage = $packed_message;
+ }
+ if (!$nosentstore) {
+ (undef,my $packed_message_no_citation) =
+ &packagemsg($subject,$message,undef,undef,$attachmenturl,$user,
+ $domain,$msgid);
+ if ($status eq 'ok' || $status eq 'con_delayed') {
+ &store_sent_mail($msgid,$packed_message_no_citation);
+ }
}
} else {
$status='no_host';
}
+
# Notifications
- my %userenv = &Apache::lonnet::get('environment',['critnotification',
- 'permanentemail'],
- $domain,$user);
+ my %userenv = &Apache::loncommon::getemails($user,$domain);
if ($userenv{'critnotification'}) {
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
- $text);
+ $text,$msgid);
}
if ($toperm && $userenv{'permanentemail'}) {
&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
- $text);
+ $text,$msgid);
}
# Log this
&Apache::lonnet::logthis(
@@ -489,29 +595,46 @@ sub user_crit_msg_raw {
=pod
-=item * B: Sends
- a critical message $message to the $user at $domain. If $sendback is true,
- a reciept will be sent to the current user when $user recieves the message.
+=item * B:
+ Sends a critical message $message to the $user at $domain. If $sendback
+ is true, a receipt will be sent to the current user when $user receives
+ the message.
+
+ Additionally it will check if the user has a Forwarding address
+ set, and send the message to that address instead
+
+ returns
+ - in array context a list of results for each message that was sent
+ - in scalar context a space seperated list of results for each
+ message sent
=cut
sub user_crit_msg {
- my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
- my $status='';
+ my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
+ $nosentstore,$recipid,$attachmenturl)=@_;
+ my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
my $msgforward=$userenv{'msgforward'};
if ($msgforward) {
- foreach (split(/\,/,$msgforward)) {
- my ($forwuser,$forwdomain)=split(/\:/,$_);
- $status.=
- &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
- $sendback,$toperm,$sentmessage).' ';
+ foreach my $addr (split(/\,/,$msgforward)) {
+ my ($forwuser,$forwdomain)=split(/\:/,$addr);
+ push(@status,
+ &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
+ $sendback,$toperm,$sentmessage,$nosentstore,
+ $recipid,$attachmenturl));
}
} else {
- $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);
+ push(@status,
+ &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
+ $toperm,$sentmessage,$nosentstore,$recipid,
+ $attachmenturl));
}
- return $status;
+ if (wantarray) {
+ return @status;
+ }
+ return join(' ',@status);
}
# =================================================== Critical message received
@@ -520,14 +643,24 @@ sub user_crit_received {
my $msgid=shift;
my %message=&Apache::lonnet::get('critical',[$msgid]);
my %contents=&unpackagemsg($message{$msgid},1);
+ my $destname = $contents{'sendername'};
+ my $destdom = $contents{'senderdomain'};
+ if ($contents{'replytoaddr'}) {
+ my ($repname,$repdom) = split(/:/,$contents{'replytoaddr'});
+ if (&Apache::lonnet::homeserver($repname,$repdom) ne 'no_host') {
+ $destname = $repname;
+ $destdom = $repdom;
+ }
+ }
my $status='rec: '.($contents{'sendback'}?
- &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
- &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
- &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
- ' acknowledged receipt of message'."\n".' "'.
- $contents{'subject'}.'"'."\n".&mt('dated').' '.
- $contents{'time'}.".\n"
- ):'no msg req');
+ &user_normal_msg($destname,$destdom,&mt('Receipt').': '.$env{'user.name'}.
+ ' '.&mt('at').' '.$env{'user.domain'}.', '.
+ $contents{'subject'},&mt('User').' '.$env{'user.name'}.
+ ' '.&mt('at').' '.$env{'user.domain'}.
+ ' acknowledged receipt of message'."\n".' "'.
+ $contents{'subject'}.'"'."\n".&mt('dated').' '.
+ $contents{'time'}.".\n"
+ ):'no msg req');
$status.=' trans: '.
&Apache::lonnet::put(
'nohist_email',{$contents{'msgid'} => $message{$msgid}});
@@ -544,7 +677,8 @@ sub user_crit_received {
sub user_normal_msg_raw {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_;
+ $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
+ $error,$nosentstore,$recipid)=@_;
# Check if allowed missing
my ($status,$packed_message);
my $msgid='undefined';
@@ -555,55 +689,48 @@ sub user_normal_msg_raw {
($msgid,$packed_message)=
&packagemsg($subject,$message,$citation,$baseurl,
$attachmenturl,$user,$domain,$currid,
- undef,$crsmsgid);
+ undef,$crsmsgid,$symb,$error,$recipid);
# Store in user folder
- $status=&Apache::lonnet::critical(
- 'put:'.$domain.':'.$user.':nohist_email:'.
- &Apache::lonnet::escape($msgid).'='.
- &Apache::lonnet::escape($packed_message),$homeserver);
+ $status=
+ &Apache::lonnet::cput('nohist_email',{$msgid => $packed_message},
+ $domain,$user);
# Save new message received time
&Apache::lonnet::put
('email_status',{'recnewemail'=>time},$domain,$user);
-# Into sent-mail folder unless a broadcast message or critical message
- unless (($env{'request.course.id'}) &&
- (($env{'form.sendmode'} eq 'group') ||
- (($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'})))) {
- (undef, my $packed_message_no_citation)=
- &packagemsg($subject,$message,undef ,$baseurl,
- $attachmenturl,$user,$domain,$currid,
- undef,$crsmsgid);
-
- $status .= &store_sent_mail($msgid,$packed_message_no_citation);
+# Into sent-mail folder if sent mail storage required
+ if (!$nosentstore) {
+ (undef,my $packed_message_no_citation) =
+ &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
+ $user,$domain,$currid,undef,$crsmsgid,$symb,$error);
+ if ($status eq 'ok' || $status eq 'con_delayed') {
+ &store_sent_mail($msgid,$packed_message_no_citation);
+ }
+ }
+ if (ref($newid) eq 'SCALAR') {
+ $$newid = $msgid;
+ }
+ if (ref($sentmessage) eq 'SCALAR') {
+ $$sentmessage = $packed_message;
}
- } else {
- $status='no_host';
- }
- if (defined($newid)) {
- $$newid = $msgid;
- }
- if (defined($sentmessage)) {
- $$sentmessage = $packed_message;
- }
-
# Notifications
- my %userenv = &Apache::lonnet::get('environment',['notification',
- 'permanentemail'],
- $domain,$user);
- if ($userenv{'notification'}) {
- &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
- $text);
- }
- if ($toperm && $userenv{'permanentemail'}) {
- &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
- $text);
- }
- &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
- $env{'user.home'},
- 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
+ my %userenv = &Apache::loncommon::getemails($user,$domain);
+ if ($userenv{'notification'}) {
+ &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
+ $text,$msgid);
+ }
+ if ($toperm && $userenv{'permanentemail'}) {
+ if ((!$userenv{'notification'}) || ($userenv{'notification'} ne $userenv{'permanentemail'})) {
+ &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
+ $text,$msgid);
+ }
+ }
+ &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
+ $env{'user.home'},
+ 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
+ } else {
+ $status='no_host';
+ }
return $status;
}
@@ -611,81 +738,102 @@ sub user_normal_msg_raw {
=pod
-=item * B: Sends a message to the
- $user at $domain, with subject $subject and message $message.
+=item * B:
+ Sends a message to the $user at $domain, with subject $subject and message $message.
+
+ Additionally it will check if the user has a Forwarding address
+ set, and send the message to that address instead
+
+ returns
+ - in array context a list of results for each message that was sent
+ - in scalar context a space seperated list of results for each
+ message sent
=cut
sub user_normal_msg {
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
- $toperm,$sentmessage)=@_;
- my $status='';
+ $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid)=@_;
+ my @status;
my %userenv = &Apache::lonnet::get('environment',['msgforward'],
$domain,$user);
my $msgforward=$userenv{'msgforward'};
if ($msgforward) {
foreach (split(/\,/,$msgforward)) {
my ($forwuser,$forwdomain)=split(/\:/,$_);
- $status.=
+ push(@status,
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
$citation,$baseurl,$attachmenturl,$toperm,
- undef,undef,$sentmessage).' ';
+ undef,undef,$sentmessage,undef,$symb,
+ $restitle,$error,$nosentstore,$recipid));
}
- } else {
- $status=&user_normal_msg_raw($user,$domain,$subject,$message,
+ } else {
+ push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
$citation,$baseurl,$attachmenturl,$toperm,
- undef,undef,$sentmessage);
+ undef,undef,$sentmessage,undef,$symb,
+ $restitle,$error,$nosentstore,$recipid));
}
+ if (wantarray) {
+ return @status;
+ }
+ return join(' ',@status);
+}
+
+sub process_sent_mail {
+ my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,$context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,$symb,$error,$senderuname,$senderdom,$recipid) = @_;
+ my $sentsubj;
+ if ($numsent > 1) {
+ $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
+ } else {
+ if ($subj_prefix) {
+ $sentsubj = $subj_prefix.' ';
+ }
+ $sentsubj .= $msgsubj;
+ }
+ $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
+ my $sentmsgid =
+ &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);
+ (undef,my $sentmessage) =
+ &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,
+ $recudoms,$sentmsgid,undef,undef,$symb,$error,$recipid);
+ my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,
+ $senderdom);
return $status;
}
sub store_sent_mail {
- my ($msgid,$message) = @_;
- my $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'});
+ my ($msgid,$message,$senderuname,$senderdom) = @_;
+ if ($senderuname eq '') {
+ $senderuname = $env{'user.name'};
+ }
+ if ($senderdom eq '') {
+ $senderdom = $env{'user.domain'};
+ }
+ my $status =' '.&Apache::lonnet::cput('nohist_email_sent',
+ {$msgid => $message},
+ $senderdom,$senderuname);
return $status;
}
-# ============================================================ List all folders
-
-sub folderlist {
- my $folder=shift;
- my @allfolders=&Apache::lonnet::getkeys('email_folders');
- if ($allfolders[0]=~/^error:/) { @allfolders=(); }
- return '':'');
-}
-
-sub scrollbuttons {
- my ($start,$maxdis,$first,$finish,$total)=@_;
- unless ($total>0) { return ''; }
- $start++; $maxdis++;$first++;$finish++;
- return
- &mt('Page').': '.
- ''.
- ''.
- ' of '.$maxdis.
- ''.
- ' '.
- &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'';
+sub store_recipients {
+ my ($subject,$sendername,$senderdom,$reciphash) = @_;
+ my $context = &get_course_context();
+ my $now = time();
+ my $msgcount = &get_uniq();
+ my $recipid =
+ &buildmsgid($now,$subject,$sendername,$senderdom,$msgcount,$context,$$);
+ my %recipinfo = (
+ $recipid => $reciphash,
+ );
+ my $status = &Apache::lonnet::put('nohist_emailrecip',\%recipinfo,
+ $senderdom,$sendername);
+ if ($status eq 'ok') {
+ return ($recipid,$status);
+ } else {
+ return (undef,$status);
+ }
}
# =============================================================== Folder suffix
@@ -693,1792 +841,143 @@ sub scrollbuttons {
sub foldersuffix {
my $folder=shift;
unless ($folder) { return ''; }
- return '_'.&Apache::lonnet::escape($folder);
-}
-
-# =============================================================== Status Change
-
-sub statuschange {
- 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'.$suffix,{$msgid => $newstatus});
- }
- if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
- &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
- }
- if ($newstatus eq 'deleted') {
- &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
- }
-}
-
-# ============================================================= Make new folder
-
-sub makefolder {
- my ($newfolder)=@_;
- if (($newfolder eq 'sent')
- || ($newfolder eq 'critical')
- || ($newfolder eq 'trash')
- || ($newfolder eq 'new')) { return; }
- &Apache::lonnet::put('email_folders',{$newfolder => time});
-}
-
-# ======================================================== Move between folders
-
-sub movemsg {
- my ($msgid,$srcfolder,$trgfolder)=@_;
- if ($srcfolder eq 'new') { $srcfolder=''; }
- 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
- unless ($trgfolder eq 'trash') {
- my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
- &Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}});
- }
-# Delete orginals
- &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
- &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
-}
-
-# ======================================================= Display a course list
-
-sub discourse {
- my $r=shift;
- my $classlist = &Apache::loncoursedata::get_classlist();
- my $now=time;
- my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All',
- 'cfs' => 'Check Section/Group',
- 'cfn' => 'Uncheck All');
- $r->print(<
-
-
-
-
-
-
-ENDDISHEADER
- 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('
'.
- '
('.$_.'),
'.$role.'
');
- }
- }
- $r->print('
');
- my $sort = sub {
- my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
- if (!$aname) { $aname=$a; }
- my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
- if (!$bname) { $bname=$b; }
- return $aname cmp $bname;
- };
- foreach my $student (sort $sort (keys(%{$classlist}))) {
- my $info=$classlist->{$student};
- my ($sname,$sdom,$status,$fullname,$section) =
- (@{$info}[&Apache::loncoursedata::CL_SNAME(),
- &Apache::loncoursedata::CL_SDOM(),
- &Apache::loncoursedata::CL_STATUS(),
- &Apache::loncoursedata::CL_FULLNAME(),
- &Apache::loncoursedata::CL_SECTION()]);
- next if ($status ne 'Active');
- next if ($env{'request.course.sec'} &&
- $section ne $env{'request.course.sec'});
- my $key = 'send_to_&&&'.$section.'&&&_'.$student;
- if (! defined($fullname) || $fullname eq '') { $fullname = $sname; }
- $r->print('
'.$sname.'@'.$sdom.'
'.$section.
- '
');
- }
- $r->print('
');
-}
-
-# ==================================================== Display Critical Message
-
-sub discrit {
- my $r=shift;
- my $header = '
'.&mt('Critical Messages').'
'.
- '');
-}
-
-sub sortedmessages {
- 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;
- 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,undef,
- \%status_cache);
- my $description = &get_course_desc($fromcid,\%descriptions);
- my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
- $msgid,$description);
- # 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;
- if ($env{'form.sortedby'} eq "date"){
- @temp = sort {$a->[0] <=> $b->[0]} @temp;
- }
- if ($env{'form.sortedby'} eq "revdate"){
- @temp = sort {$b->[0] <=> $a->[0]} @temp;
- }
- if ($env{'form.sortedby'} eq "user"){
- @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 ($env{'form.sortedby'} eq "domain"){
- @temp = sort {$a->[3] cmp $b->[3]} @temp;
- }
- if ($env{'form.sortedby'} eq "revdomain"){
- @temp = sort {$b->[3] cmp $a->[3]} @temp;
- }
- if ($env{'form.sortedby'} eq "subject"){
- @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
- }
- 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;
- }
- if ($env{'form.sortedby'} eq "revstatus"){
- @temp = sort {$b->[4] cmp $a->[4]} @temp;
- }
- 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
-
-
-sub disnew {
- my $r=shift;
- my %lt=&Apache::lonlocal::texthash(
- 'nm' => 'New Messages',
- 'su' => 'Subject',
- 'co' => 'Course',
- 'da' => 'Date',
- 'us' => 'Username',
- 'op' => 'Open',
- 'do' => 'Domain'
- );
- my @msgids = sort(&Apache::lonnet::getkeys('nohist_email'));
- my @newmsgs;
- my %setters = ();
- my $startblock = 0;
- my $endblock = 0;
- my %blocked = ();
- 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($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') {
- if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) {
- $blocked{$_} = 'ON';
- $numblocked ++;
- } else {
- push @newmsgs, {
- msgid => $msgid,
- sendtime => $sendtime,
- shortsub => &Apache::lonnet::unescape($shortsubj),
- from => $fromname,
- fromdom => $fromdom,
- course => $description
- }
+ my $suffix;
+ my %folderhash = &get_user_folders($folder);
+ if (ref($folderhash{$folder}) eq 'HASH') {
+ $suffix = '_'.&escape($folderhash{$folder}{'id'});
+ } else {
+ $suffix = '_'.&escape($folder);
+ }
+ return $suffix;
+}
+
+# ========================================================= User-defined folders
+
+sub get_user_folders {
+ my ($folder) = @_;
+ my %userfolders =
+ &Apache::lonnet::dump('email_folders',undef,undef,$folder);
+ my $lock = "\0".'lock_counter'; # locks db while counter incremented
+ my $counter = "\0".'idcount'; # used in suffix for email db files
+ if (defined($userfolders{$lock})) {
+ delete($userfolders{$lock});
+ }
+ if (defined($userfolders{$counter})) {
+ delete($userfolders{$counter});
+ }
+ return %userfolders;
+}
+
+sub secapply {
+ my $rec=shift;
+ my $defaultflag=shift;
+ $rec=~s/\s+//g;
+ $rec=~s/\@/\:/g;
+ my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
+ if ($sections_or_groups) {
+ foreach my $item (split(/\;/,$sections_or_groups)) {
+ if (($item eq $env{'request.course.sec'}) ||
+ ($defaultflag && ($item eq '*'))) {
+ return $adr;
+ } elsif ($env{'request.course.groups'}) {
+ my @usersgroups = split(/:/,$env{'request.course.groups'});
+ if (grep(/^\Q$item\E$/,@usersgroups)) {
+ return $adr;
}
- }
- }
- }
- if ($#newmsgs >= 0) {
- $r->print(<$lt{'nm'}
-
 
-
$lt{'da'}
$lt{'us'}
$lt{'do'}
$lt{'su'}
$lt{'co'}
-TABLEHEAD
- foreach my $msg (@newmsgs) {
- $r->print(<<"ENDLINK");
-
");
- $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because '));
- }
- $r->print(
-&mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.');
- &build_block_table($r,$startblock,$endblock,\%setters);
- }
-}
-
-
-# ======================================================== Display all messages
-
-sub disall {
- my ($r,$folder)=@_;
- $r->print(&folderlist($folder));
- if ($folder eq 'new') {
- &disnew($r);
- } elsif ($folder eq 'critical') {
- &discrit($r);
- } else {
- &disfolder($r,$folder);
- }
-}
-
-# ============================================================ Display a folder
-
-sub disfolder {
- my ($r,$folder)=@_;
- my %blocked = ();
- my %setters = ();
- my $startblock;
- my $endblock;
- my $numblocked = 0;
- &blockcheck(\%setters,\$startblock,\$endblock);
- $r->print(<
- function checkall() {
- for (i=0; i
-ENDDISHEADER
- my $fsqs='&folder='.$folder;
- my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
- my $totalnumber=$#temp+1;
- unless ($totalnumber>0) {
- $r->print('
'.&mt('Empty Folder').'
');
- return;
- }
- unless ($interdis) {
- $interdis=20;
- }
- my $number=int($totalnumber/$interdis);
- if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
- my $firstdis=$interdis*$startdis;
- if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
- my $lastdis=$firstdis+$interdis-1;
- if ($lastdis>$#temp) { $lastdis=$#temp; }
- $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber));
- $r->print('');
- if ($numblocked > 0) {
- my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
- my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
- $r->print('
'.
- $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.'));
- &build_block_table($r,$startblock,$endblock,\%setters);
- }
-}
-
-# ============================================================== Compose output
-
-sub compout {
- my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_;
- my $suffix=&foldersuffix($folder);
-
- if ($broadcast eq 'individual') {
- &printheader($r,'/adm/email?compose=individual',
- 'Send a Message');
- } elsif ($broadcast) {
- &printheader($r,'/adm/email?compose=group',
- 'Broadcast Message');
- } elsif ($forwarding) {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/email?display=".&Apache::lonnet::escape($forwarding),
- text=>"Display Message"});
- &printheader($r,'/adm/email?forward='.&Apache::lonnet::escape($forwarding),
- 'Forwarding a Message');
- } elsif ($replying) {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/email?display=".&Apache::lonnet::escape($replying),
- text=>"Display Message"});
- &printheader($r,'/adm/email?replyto='.&Apache::lonnet::escape($replying),
- 'Replying to a Message');
- } elsif ($replycrit) {
- $r->print('
'.&mt('Replying to a Critical Message').'
');
- $replying=$replycrit;
- } else {
- &printheader($r,'/adm/email?compose=upload',
- 'Distribute from Uploaded File');
- }
-
- my $dispcrit='';
- my $dissub='';
- my $dismsg='';
- my $disbase='';
- my $func=&mt('Send New');
- my %lt=&Apache::lonlocal::texthash('us' => 'Username',
- 'do' => 'Domain',
- 'ad' => 'Additional Recipients',
- 'sb' => 'Subject',
- 'ca' => 'Cancel',
- 'ma' => 'Mail');
-
- 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=
- '
');
- &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
- $r->print(<
-
-
-ENDRHEAD
- $r->print(<$lt{'newr'}
-
-
-
-
-
-ENDBFORM
- }
-}
-
-# ----------------------------------------------------------- Blocking during exams
-
-sub examblock {
- my ($r,$action) = @_;
- unless ($env{'request.course.id'}) { return;}
- if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
- && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
- '/'.$env{'request.course.sec'})) {
- $r->print('Not allowed');
- return;
- }
- my %lt=&Apache::lonlocal::texthash(
- 'comb' => 'Communication Blocking',
- 'cbds' => 'Communication blocking during scheduled exams',
- 'desc' => 'You can use communication blocking to prevent students enrolled in this course from displaying LON-CAPA messages sent by other students during an online exam. As blocking of communication could potentially interrupt legitimate communication between students who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.',
- 'mecb' => 'Modify existing communication blocking periods',
- 'ncbc' => 'No communication blocks currently stored'
- );
-
- my %ltext = &Apache::lonlocal::texthash(
- 'dura' => 'Duration',
- 'setb' => 'Set by',
- 'even' => 'Event',
- 'actn' => 'Action',
- 'star' => 'Start',
- 'endd' => 'End'
- );
-
- &printheader($r,'/adm/email?block=display',$lt{'comb'});
- $r->print('
-END
- return;
-}
-
-sub blockcheck {
- my ($setters,$startblock,$endblock) = @_;
- # Retrieve active student roles and active course coordinator/instructor roles
- my @livecses = ();
- my @staffcses = ();
- $$startblock = 0;
- $$endblock = 0;
- foreach (keys %env) {
- if ($_ =~ m-^user\.role\.(st|cc|in)\./(.+)$-) {
- my $role = $1;
- my $cse = $2;
- $cse =~ s|/|_|;
- if ($env{$_} =~ m/^(\d*)\.(\d*)$/) {
- unless (($2 > 0 && $2 < time) || ($1 > time)) {
- if ($role eq 'st') {
- push @livecses, $cse;
- } else {
- unless (grep/^$cse$/,@staffcses) {
- push @staffcses, $cse;
- }
- }
- }
- }
- } elsif ($_ =~ m-user\.role\.cr/(\w+)/(\w+)/([^/]+)\./(.+)$- ) {
- my $rolepriv = $env{'user.role..rolesdef_'.$3};
- }
- }
- # Retrieve blocking times and identity of blocker for active courses for students.
- if (@livecses > 0) {
- foreach my $cse (@livecses) {
- my ($cdom,$crs) = split/_/,$cse;
- if ( (grep/^$cse$/,@staffcses) && ($env{'request.role'} !~ m-^st\./$cdom/$crs$-) ) {
- next;
- } else {
- %{$$setters{$cse}} = ();
- @{$$setters{$cse}{'staff'}} = ();
- @{$$setters{$cse}{'times'}} = ();
- my %records = &Apache::lonnet::dump('comm_block',$cdom,$crs);
- foreach (keys %records) {
- if ($_ =~ m/^(\d+)____(\d+)$/) {
- if ($1 <= time && $2 >= time) {
- my ($staff,$title) = split/:/,$records{$_};
- push @{$$setters{$cse}{'staff'}}, $staff;
- push @{$$setters{$cse}{'times'}}, $_;
- if ( ($$startblock == 0) || ($$startblock > $1) ) {
- $$startblock = $1;
- }
- if ( ($$endblock == 0) || ($$endblock < $2) ) {
- $$endblock = $2;
- }
- }
- }
- }
- }
- }
- }
-}
-
-sub build_block_table {
- my ($r,$startblock,$endblock,$setters) = @_;
- my $function = &Apache::loncommon::get_users_function();
- my $color = &Apache::loncommon::designparm($function.'.tabbg',
- $env{'user.domain'});
- my %lt = &Apache::lonlocal::texthash(
- 'cacb' => 'Currently active communication blocks',
- 'cour' => 'Course',
- 'dura' => 'Duration',
- 'blse' => 'Block set by'
- );
- $r->print(<<"END");
- $lt{'cacb'}:
-
-
-
-
-
-
-
-
-
$lt{'cour'}
-
$lt{'dura'}
-
$lt{'blse'}
-
-END
- foreach (keys %{$setters}) {
- my %courseinfo=&Apache::lonnet::coursedescription($_);
- for (my $i=0; $i<@{$$setters{$_}{staff}}; $i++) {
- my ($uname,$udom) = split/\@/,$$setters{$_}{staff}[$i];
- my $fullname = &Apache::loncommon::plainname($uname,$udom);
- my ($openblock,$closeblock) = split/____/,$$setters{$_}{times}[$i];
- $openblock = &Apache::lonlocal::locallocaltime($openblock);
- $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
- $r->print('
'.$courseinfo{'description'}.'
'.
- '
'.$openblock.' to '.$closeblock.'
'.
- '
'.$fullname.' ('.$uname.'@'.$udom.
- ')
');
- }
- }
- $r->print('
');
-}
-
-# ----------------------------------------------------------- Display a message
-
-sub displaymessage {
- my ($r,$msgid,$folder)=@_;
- my $suffix=&foldersuffix($folder);
- my %blocked = ();
- my %setters = ();
- my $startblock = 0;
- my $endblock = 0;
- my $numblocked = 0;
-# info to generate "next" and "previous" buttons and check if message is blocked
- &blockcheck(\%setters,\$startblock,\$endblock);
- my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
- if ( $blocked{$msgid} eq 'ON' ) {
- &printheader($r,'/adm/email',&mt('Display a Message'));
- $r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.'));
- &build_block_table($r,$startblock,$endblock,\%setters);
- return;
- }
- &statuschange($msgid,'read',$folder);
- my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
- my %content=&unpackagemsg($message{$msgid});
-
- my $counter=0;
- $r->print('
');
- my $number_of_messages = scalar(@messages); #subtract 1 for last index
-# start output
- &printheader($r,'/adm/email?display='.&Apache::lonnet::escape($msgid),'Display a Message','',$content{'baseurl'});
- my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
-# Functions
- $r->print('
'.&displayresource(%content).'');
- return;
-}
-
-# =========================================================== Show the citation
-
-sub displayresource {
- my %content=@_;
-#
-# If the recipient is in the same course that the message was sent from and
-# has sufficient privileges, show "all details," else show citation
-#
- if (($env{'request.course.id'} eq $content{'courseid'})
- && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
- my $symb=&Apache::lonnet::symbread($content{'baseurl'});
-# Could not get a symb, give up
- unless ($symb) { return $content{'citation'}; }
-# Have a symb, can render
- return '
'.&mt('Current attempts of student (if applicable)').'