--- loncom/interface/lonmsg.pm 2001/07/26 20:26:43 1.8
+++ loncom/interface/lonmsg.pm 2004/09/28 14:12:40 1.109
@@ -1,49 +1,151 @@
# The LearningOnline Network with CAPA
-#
# Routines for messaging
#
-# (Routines to control the menu
+# $Id: lonmsg.pm,v 1.109 2004/09/28 14:12:40 matthew Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# (TeX Conversion Module
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# 05/29/00,05/30 Gerd Kortemeyer)
+# /home/httpd/html/adm/gpl.txt
#
-# 10/05 Gerd Kortemeyer)
+# http://www.lon-capa.org/
#
-# 10/19,10/20,10/30,
-# 02/06/01 Gerd Kortemeyer
+
package Apache::lonmsg;
+=pod
+
+=head1 NAME
+
+Apache::lonmsg: supports internal messaging
+
+=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 then traditional email can be made to be, even
+with HTML support.
+
+Right now, this document will cover just how to send a message, since
+it is likely you will not need to programmatically read messages,
+since lonmsg already implements that functionality.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
use strict;
use Apache::lonnet();
use vars qw($msgcount);
-use HTML::TokeParser;
+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;
+
+# Querystring component with sorting type
+my $sqs;
+my $startdis;
+my $interdis;
# ===================================================================== Package
sub packagemsg {
- my ($subject,$message,$citation)=@_;
- $message=~s/\\<\;/g;
- $message=~s/\>/\>\;/g;
- $citation=~s/\\<\;/g;
- $citation=~s/\>/\>\;/g;
- $subject=~s/\\<\;/g;
- $subject=~s/\>/\>\;/g;
+ my ($subject,$message,$citation,$baseurl,$attachmenturl,
+ $recuser,$recdomain)=@_;
+ $message =&HTML::Entities::encode($message,'<>&"');
+ $citation=&HTML::Entities::encode($citation,'<>&"');
+ $subject =&HTML::Entities::encode($subject,'<>&"');
+ #remove machine specification
+ $baseurl =~ s|^http://[^/]+/|/|;
+ $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
+ #remove machine specification
+ $attachmenturl =~ s|^http://[^/]+/|/|;
+ $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
+
my $now=time;
$msgcount++;
my $partsubj=$subject;
$partsubj=&Apache::lonnet::escape($partsubj);
- $partsubj=substr($partsubj,0,50);
my $msgid=&Apache::lonnet::escape(
$now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
$ENV{'user.domain'}.':'.$msgcount.':'.$$);
- return $msgid,
- ''.$ENV{'user.name'}.''.
+ my $result=''.$ENV{'user.name'}.''.
''.$ENV{'user.domain'}.''.
''.$subject.''.
- ''.
+ ''.
''.$ENV{'SERVER_NAME'}.''.
''.$ENV{'HTTP_HOST'}.''.
''.$ENV{'REMOTE_ADDR'}.''.
@@ -53,17 +155,29 @@ sub packagemsg {
''.$ENV{'browser.mathml'}.''.
''.$ENV{'HTTP_USER_AGENT'}.''.
''.$ENV{'request.course.id'}.''.
+ ''.$ENV{'request.course.sec'}.''.
''.$ENV{'request.role'}.''.
''.$ENV{'request.filename'}.''.
''.$msgid.''.
- ''.$message.''.
- ''.$citation.'';
+ ''.$recuser.''.
+ ''.$recdomain.''.
+ ''.$message.'';
+ if (defined($citation)) {
+ $result.=''.$citation.'';
+ }
+ if (defined($baseurl)) {
+ $result.= ''.$baseurl.'';
+ }
+ if (defined($attachmenturl)) {
+ $result.= ''.$attachmenturl.'';
+ }
+ return $msgid,$result;
}
# ================================================== Unpack message into a hash
sub unpackagemsg {
- my $message=shift;
+ my ($message,$notoken)=@_;
my %content=();
my $parser=HTML::TokeParser->new(\$message);
my $token;
@@ -74,23 +188,96 @@ sub unpackagemsg {
$content{$entry}=$value;
}
}
+ if ($content{'attachmenturl'}) {
+ my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
+ if ($notoken) {
+ $content{'message'}.='
');
+ &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;}
+ unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { $r->print('Not allowed'); }
+ 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('