--- loncom/interface/lonmsgdisplay.pm 2006/12/07 21:06:57 1.48
+++ loncom/interface/lonmsgdisplay.pm 2010/06/06 02:40:30 1.153
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.48 2006/12/07 21:06:57 albertel Exp $
+# $Id: lonmsgdisplay.pm,v 1.153 2010/06/06 02:40:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,12 +33,13 @@ package Apache::lonmsgdisplay;
=head1 NAME
-Apache::lonmsg: supports internal messaging
+Apache::lonmsgdisplay: 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.
+lonmsgdisplay provides a handler to allow users to read, send,
+and delete messages, and to create and delete message folders,
+and to move messages between folders.
=head1 OVERVIEW
@@ -74,8 +75,8 @@ 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
+=item * B: LON-CAPA can block selected communication
+features for students 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,
@@ -93,25 +94,6 @@ addresses on their B screen, but g
are much more useful than 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.
-
-The routines used to package messages and unpackage messages are not
-only used by lonmsg when creating/extracting messages for LON-CAPA's
-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
-with $email in stored
-Domain Coordinator e-mail for the storage of information about
-recipients of the message/e-mail.
-
-=head1 FUNCTIONS
-
-=over 4
-
=cut
use strict;
@@ -119,6 +101,7 @@ use Apache::lonnet;
use HTML::TokeParser();
use Apache::Constants qw(:common);
use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::lontexconvert();
use HTML::Entities();
use Apache::lonlocal;
@@ -130,21 +113,32 @@ use lib '/home/httpd/lib/perl/';
use LONCAPA;
# Querystring component with sorting type
-my $sqs;
-my $startdis;
-my $interdis;
+my $sqs='';
+my $startdis='';
# ============================================================ List all folders
sub folderlist {
- my $folder=shift;
+ my ($folder,$msgstatus) = @_;
my %lt = &Apache::lonlocal::texthash(
actn => 'Action',
fold => 'Folder',
show => 'Show',
+ status => 'Message Status',
go => 'Go',
+ nnff => 'New Name for Folder',
+ newn => 'New Name',
+ thfm => 'The folder may not be renamed',
+ fmnb => 'folder may not be renamed as it is a folder provided by the system.',
+ asth => 'as this name is already in use for a system-provided or user-defined folder.',
+ the => 'The',
+ tnfm => 'The new folder may not be named',
+
);
+ # set se lastvisit for the new mail check in the toplevel menu
+ &Apache::lonnet::appenv({'user.mailcheck.lastvisit'=>time});
+
my %actions = &Apache::lonlocal::texthash(
view => 'View Folder',
rename => 'Rename Folder',
@@ -152,6 +146,10 @@ sub folderlist {
);
$actions{'select_form_order'} = ['view','rename','delete'];
+ my %statushash = &Apache::lonlocal::texthash(&get_msgstatus_types());
+
+ $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
+
my %permfolders = &get_permanent_folders();
my $permlist = join("','",sort(keys(%permfolders)));
my ($permlistkeys,$permlistvals);
@@ -165,6 +163,7 @@ sub folderlist {
my %userfolders;
foreach my $key (keys(%gotfolders)) {
+ $key =~ s/(['"])/\$1/g; #' stupid emacs
$userfolders{$key} = $key;
}
my @userorder = sort(keys(%userfolders));
@@ -172,8 +171,9 @@ sub folderlist {
my $folderlist = join("','",@userorder);
$folderlist .= "','".$permlistvals;
- $formhash{'select_form_order'} = ['','critical','new',@userorder,'sent','trash'];
+ $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
my $output = qq||;
+ my %show = ('select_form_order' => [10,20,50,100,200],
+ map {$_=>$_} (10,20,50,100,200));
+
$output .= '
-The messages will be assembled from all lines with the respective
-username:domain, and appended to the general message text.
+'.&mt('The messages will be assembled from all lines with the respective'."\n".'username:domain, and appended to the general message text.'));
+ $r->print(<
$dispcrit
-
+
ENDUPLOAD
}
- if ($broadcast eq 'group') {
- if ($group eq '') {
- my $studentsel = &discourse();
- $r->print($studentsel);
- }
- }
if ($env{'form.displayedcrit'}) {
$r->print('');
}
- $r->print(''.
- &Apache::lonfeedback::generate_preview_button('compemail','message').
- &Apache::lonhtmlcommon::htmlareaselectactive('message'));
+ $r->print('');
+ if ($hasfloat) {
+ unless($env{'environment.wysiwygeditor'} eq 'on') {
+ $r->print('');
+ }
+ }
+ $r->print(&generate_preview_form);
+}
+
+sub check_group_priv {
+ my ($group) = @_;
+ my $cid = $env{'request.course.id'};
+ my $sec = $env{'request.course.sec'};
+ return if !$cid;
+ my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
+ my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
+ my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
+ if ($viewgrps || $editgrps || $can_broadcast) {
+ return 1;
+ }
+ return;
}
-# ---------------------------------------------------- Display all face to face
-
sub recipient_input_row {
my ($dom,%lt) = @_;
my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
@@ -1327,19 +1761,83 @@ sub recipient_input_row {
&Apache::loncommon::selectstudent_link('compemail','recuname',
'recdomain');
my $output = <<"ENDREC";
-
ENDREC
return $output;
}
+sub reply_to_row {
+ my ($lt) = @_;
+ my $radioyes = &mt('Yes');
+ my $radiono = &mt('No');
+ my $output = <<"ENDREP";
+
$lt->{'ar'}: $lt->{'rt'}:
+ENDREP
+ return $output;
+}
+
+sub additional_rec_row {
+ my ($lt) = @_;
+ my $cc = &mt('Cc:');
+ my $bcc = &mt('Bcc:');
+ my $exmpl = &mt('username:domain,username:domain,...');
+ my $output = <<"ENDADD";
+
+ENDADD
+ return $output;
+}
+
+sub submit_button_row {
+ my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
+ my $pre=&mt("Show Preview and Check Spelling");
+ my $value=&mt('Send');
+ my $prevbutton = '';
+ my $output = qq|
+
+|;
+ if ($is_crsform) {
+ $output .= ''."\n";
+ if ($group ne '') {
+ $output .= ''."\n";
+ }
+ }
+ $output .= qq|
+
+
+
+
$prevbutton
+|;
+ return $output;
+}
+
+sub msg_subject_row {
+ my ($dissub,$lt,$subj_size,$extra) = @_;
+ my $output = '
'.$lt->{'sb'}.': '.$extra.
+ '
';
+ return $output;
+}
+
+sub generate_preview_form {
+ my $prevbutton = (<
+
+
+
+ENDPREVIEW
+}
+
+# ---------------------------------------------------- Display all face to face
+
sub retrieve_instructor_comments {
my ($user,$domain)=@_;
my $target=$env{'form.grade_target'};
if (! $env{'request.course.id'}) { return; }
- if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})
- && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
+ && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
'/'.$env{'request.course.sec'})) {
return;
}
@@ -1362,24 +1860,28 @@ sub retrieve_instructor_comments {
}
sub disfacetoface {
- my ($r,$user,$domain)=@_;
- my $target=$env{'form.grade_target'};
+ my ($r,$user,$domain,$target)=@_;
+ if ($target eq '') {
+ $target=$env{'form.grade_target'};
+ }
unless ($env{'request.course.id'}) { return; }
- if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
- && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
+ && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
'/'.$env{'request.course.sec'})) {
- $r->print('Not allowed');
+ $r->print(&mt('Not allowed'));
return;
}
my %records=&Apache::lonnet::dump('nohist_email',
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'},
'%255b'.$user.'%253a'.$domain.'%255d');
- my $result='';
+ my $result='
';
foreach my $key (sort(keys(%records))) {
my %content=&Apache::lonmsg::unpackagemsg($records{$key});
next if ($content{'senderdomain'} eq '');
- &Apache::lonfeedback::newline_to_br(\$content{'message'});
+ if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
+ &Apache::lonfeedback::newline_to_br(\$content{'message'});
+ }
if ($content{'subject'}=~/^Record/) {
$result.='
';
+ if (defined($content{'coursemsgid'})) {
+ my $crsmsgid = &escape($content{'coursemsgid'});
+ my $archive_message = &general_message($crsmsgid);
+ $content{'message'} = ''.&mt('Subject').': '.$content{'message'}.' '.$archive_message;
+ } else {
+ %content=&Apache::lonmsg::unpackagemsg($content{'message'});
+ $content{'message'} =
+ ''.&mt('Subject').': '.$content{'subject'}.' '.&mt('Critical Message').'';
if (defined($content{'coursemsgid'})) {
@@ -1420,15 +1935,17 @@ $content{'sendername'}.':'.
}
# Check to see if there were any messages.
if ($result eq '') {
- my $lctype = lc(&Apache::loncommon::course_type());
+ my $lctype = &mt(lc(&Apache::loncommon::course_type()));
if ($target ne 'tex') {
$r->print("
".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)."
");
} else {
$r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
}
+ } elsif ($target ne 'tex') {
+ $r->print($result.'
');
} else {
- $r->print($result);
- }
+ $r->print(&Apache::lonxml::xmlparse($r, 'tex', $result));
+ }
}
sub general_message {
@@ -1447,18 +1964,18 @@ sub general_message {
sub facetoface {
my ($r,$stage)=@_;
- if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
- && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
+ && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
'/'.$env{'request.course.sec'})) {
- $r->print('Not allowed');
+ $r->print(&mt('Not allowed'));
return;
}
my $crstype = &Apache::loncommon::course_type();
- my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
- : 'faculty and staff';
+ my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
+ : 'faculty and staff';
&printheader($r,
'/adm/email?recordftf=query',
- "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
+ "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
# from query string
if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
@@ -1473,25 +1990,28 @@ sub facetoface {
('stdselect','recuname','recdomain');
my %lt=&Apache::lonlocal::texthash('user' => 'Username',
'dom' => 'Domain',
- 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
+ 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
'subm' => 'Retrieve discussion and message records',
'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
'post' => 'Post this Record');
- $r->print(<<"ENDTREC");
-
'
+ .&mt('Discussion and message records for [_1] ([_2])'
+ ,$aboutmelink
+ ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
+ .'
'
+ );
&disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
$r->print(<
@@ -1530,14 +2059,21 @@ sub examblock {
$r->print('Not allowed');
return;
}
- my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
- : 'students';
+ my $usertype;
+ my $crstype = &Apache::loncommon::course_type();
+ if ($crstype eq 'Community') {
+ $usertype = 'members';
+ } else {
+ $usertype = 'students';
+ }
+ my $lctype = lc($crstype);
my %lt=&Apache::lonlocal::texthash(
'comb' => 'Communication Blocking',
'cbds' => 'Communication blocking during scheduled exams',
- 'desc' => "You can use communication blocking to prevent $usertype enrolled in this course from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype 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.",
+ 'desc' => "You can use communication blocking to prevent $usertype enrolled in this $lctype from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course or community, 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'
+ 'ncbc' => 'No communication blocks currently saved',
+ 'stor' => 'Save',
);
my %ltext = &Apache::lonlocal::texthash(
@@ -1576,7 +2112,7 @@ sub examblock {
$r->print(<<"END");
-
+
$end_page
END
@@ -1587,10 +2123,6 @@ sub blockstore {
my $r = shift;
my %lt=&Apache::lonlocal::texthash(
'tfcm' => 'The following changes were made',
- 'cbps' => 'communication blocking period(s)',
- 'werm' => 'was/were removed',
- 'wemo' => 'was/were modified',
- 'wead' => 'was/were added',
'ncwm' => 'No changes were made.'
);
my %adds = ();
@@ -1647,13 +2179,13 @@ sub blockstore {
if ($chgestotal > 0) {
$r->print($lt{'tfcm'}.'
');
if ($canceltotal > 0) {
- $r->print('
'.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'
');
+ $r->print('
'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'
');
}
if ($modtotal > 0) {
- $r->print('
'.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'
');
+ $r->print('
'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'
');
}
if ($addtotal > 0) {
- $r->print('
'.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'
');
+ $r->print('
'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'
END
foreach my $record (sort(keys(%{$records}))) {
@@ -1735,7 +2267,7 @@ END
$setuname,$setudom);
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
-
@@ -1743,13 +2275,18 @@ END
foreach my $block (@{$typeorder}) {
my $blockstatus = '';
if ($blocks->{$block} eq 'on') {
- $blockstatus = 'checked="true"';
+ $blockstatus = 'checked="checked"';
}
- $r->print(' ');
+ $r->print(' ');
}
$r->print(<<"END");
-
+
+
END
$r->print(&Apache::loncommon::end_data_table_row());
$parmcount++;
@@ -1786,7 +2323,7 @@ END
$ltext->{'dura'}
$ltext->{'even'} $lt{'exam'}
$ltext->{'blck'}
-
$ltext->{'actn'}?
+
$ltext->{'actn'}
END
$r->print(&Apache::loncommon::start_data_table_row());
@@ -1796,11 +2333,13 @@ END
END
foreach my $block (@{$typeorder}) {
- $r->print(' ');
+ $r->print(' ');
}
$r->print(<<"END");
-
-
+
+
END
$r->print(&Apache::loncommon::end_data_table_row());
$r->print(&Apache::loncommon::end_data_table());
@@ -1810,7 +2349,7 @@ END
sub blocktype_text {
my %types = &Apache::lonlocal::texthash(
'com' => 'Messaging',
- 'chat' => 'Chat',
+ 'chat' => 'Chat Room',
'boards' => 'Discussion',
'port' => 'Portfolio',
'groups' => 'Groups',
@@ -1823,7 +2362,7 @@ sub blocktype_text {
# ----------------------------------------------------------- Display a message
sub displaymessage {
- my ($r,$msgid,$folder)=@_;
+ my ($r,$msgid,$folder,$msgstatus)=@_;
my $suffix=&Apache::lonmsg::foldersuffix($folder);
my %blocked = ();
my %setters = ();
@@ -1832,19 +2371,21 @@ sub displaymessage {
# info to generate "next" and "previous" buttons and check if message is blocked
my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
- my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
+ my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
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);
+ #$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);
+ my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
+ $r->print(" ".$blocktext);
return;
}
- &statuschange($msgid,'read',$folder);
+ if ($msgstatus eq '') {
+ &statuschange($msgid,'read',$folder);
+ }
my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
-
my $counter=0;
- $r->print('
');
my $escmsgid=&escape($msgid);
foreach (@messages) {
if ($_->[5] eq $escmsgid){
@@ -1852,74 +2393,492 @@ sub displaymessage {
}
$counter++;
}
- $r->print('
');
+
+ my $see_anonymous;
+ my $from_student = 0;
+ if ($env{'request.course.id'} eq $content{'courseid'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $username = $content{'sendername'}.':'.$content{'senderdomain'};
+ my %classlist_entry =
+ &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
+ if (exists($classlist_entry{$username})) {
+ $from_student = 1;
+ $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
+ }
+ }
+
+
my $number_of_messages = scalar(@messages); #subtract 1 for last index
# start output
&printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
-# Functions
- $r->print('