--- loncom/interface/lonmsgdisplay.pm 2006/12/08 14:43:38 1.50
+++ loncom/interface/lonmsgdisplay.pm 2019/08/12 15:19:06 1.181.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.50 2006/12/08 14:43:38 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.181.2.3 2019/08/12 15:19:06 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
@@ -93,25 +94,6 @@ addresses on their B
'."\n".
+$latexHelp." \n". +&mt("Any new text to display before the text of the original messages:").' '."\n". +''); + my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msg (@to_forward) { + $r->print(''); + } + $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}), + \%lt)); + } elsif ($broadcast ne 'upload') { + $subj_size = '50'; + $r->print(&additional_rec_row(\%lt)); + if (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) + || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})) { + $r->print(&reply_to_row(\%lt)); + } + $r->print(&msg_subject_row($dissub,\%lt,$subj_size)); + $r->print(<<"ENDCOMP"); +$attachrow + |
$lt{'gmt'}:
-
$lt{'tff'}: @@ -1310,7 +1767,7 @@ ENDBLOCK '
-'.&mt('The messages will be assembled from all lines with the respective'."\n".'username:domain, and appended to the general message text.'));
+'.&mt('The messages will be assembled from all lines with the respective [_1][_2]username:domain[_3], and appended to the general message text.','
@@ -1319,22 +1776,30 @@ $dispcrit
".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)." ".&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.')."
','',''));
$r->print(<
-$lt{'us'}: $selectlink
+$lt{'do'}:
-$domform
ENDREC
return $output;
}
+sub reply_to_row {
+ my ($lt) = @_;
+ my $radioyes = &mt('Yes');
+ my $radiono = &mt('No');
+ my $output = <<"ENDREP";
+$lt{'to'} $lt{'us'}: $lt{'do'}: $domform $selectlink
+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";
+$lt->{'ar'}: $lt->{'rt'}:
+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|
+
+|;
+ return $output;
+}
+
+sub msg_subject_row {
+ my ($dissub,$lt,$subj_size,$extra) = @_;
+ my $output = '
+
+
+ $prevbutton ';
+ return $output;
+}
+
+sub generate_preview_form {
+ my $prevbutton = (<'.$lt->{'sb'}.': '.$extra.
+ ' '.&mt('Record').'
';
} elsif ($content{'subject'}=~/^Broadcast/) {
@@ -1410,7 +1943,19 @@ sub disfacetoface {
''.&mt('Subject').': '.$content{'subject'}.'
'.
$content{'message'};
}
- }
+ }
+ } elsif ($content{'subject'}=~/^Archive/) {
+ $result.=''.&mt('Archived Message').'
';
+ 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'}.'
'.
+ $content{'message'};
+ }
} else {
$result.=''.&mt('Critical Message').'
';
if (defined($content{'coursemsgid'})) {
@@ -1435,14 +1980,16 @@ $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("$lt{'head'}
-
-
-
-$lt{'user'}:
-
-$stdbrws
-
-
-$lt{'dom'}:
-$domform '.$lt{'head'}.'
'
+ .'
'
+ .''
+ .''.&Apache::loncommon::plainname($env{'form.recuname'},
- $env{'form.recdomain'}).'
');
+ my $aboutmelink=&Apache::loncommon::aboutmewrapper(
+ &Apache::loncommon::plainname($env{'form.recuname'}
+ ,$env{'form.recdomain'})
+ ,$env{'form.recuname'},$env{'form.recdomain'});
+ $r->print('
'
+ .''
+ .&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(<'.$lt{'cbds'}.'
');
-
- if ($action eq 'store') {
- &blockstore($r);
- }
-
- $r->print($lt{'desc'}.'
- '.$lt{'mecb'}.'
');
- my %records = ();
- my $blockcount = 0;
- my $parmcount = 0;
- &get_blockdates(\%records,\$blockcount);
- if ($blockcount > 0) {
- $parmcount = &display_blocker_status($r,\%records,\%ltext);
- } else {
- $r->print($lt{'ncbc'}.'
');
- }
- &display_addblocker_table($r,$parmcount,\%ltext);
- my $end_page=&Apache::loncommon::end_page();
- $r->print(<<"END");
-
-
-
-'.$lt{'head'}.'
');
- foreach my $envkey (keys(%env)) {
- if ($envkey =~ m/^form\.modify_(\d+)$/) {
- $adds{$1} = $1;
- $removals{$1} = $1;
- $modtotal ++;
- } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
- $cancels{$1} = $1;
- unless ( defined($removals{$1}) ) {
- $removals{$1} = $1;
- $canceltotal ++;
- }
- } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
- $adds{$1} = $1;
- $addtotal ++;
- }
- }
-
- foreach my $key (keys(%removals)) {
- my $hashkey = $env{'form.key_'.$key};
- &Apache::lonnet::del('comm_block',["$hashkey"],
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- }
- foreach my $key (keys(%adds)) {
- unless ( defined($cancels{$key}) ) {
- my ($newstart,$newend) = &get_dates_from_form($key);
- my $newkey = $newstart.'____'.$newend;
- my $blocktypes = &get_block_choices($key);
- $blocking{$newkey} = {
- setter => $env{'user.name'}.':'.$env{'user.domain'},
- event => &escape($env{'form.title_'.$key}),
- blocks => $blocktypes,
- };
- }
- }
- if ($addtotal + $modtotal > 0) {
- &Apache::lonnet::put('comm_block',\%blocking,
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- }
- my $chgestotal = $canceltotal + $modtotal + $addtotal;
- if ($chgestotal > 0) {
- $r->print($lt{'tfcm'}.'');
- if ($canceltotal > 0) {
- $r->print('
');
- } else {
- $r->print($lt{'ncwm'});
- }
- $r->print('
');
- return;
-}
-
-sub get_dates_from_form {
- my $item = shift;
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
- return ($startdate,$enddate);
-}
-
-sub get_blockdates {
- my ($records,$blockcount) = @_;
- $$blockcount = 0;
- %{$records} = &Apache::lonnet::dump('comm_block',
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- $$blockcount = keys(%{$records});
-
- if ((keys(%{$records}))[0] =~ /^error: 2 /) {
- $records = {};
- $$blockcount = 0;
- }
-}
-
-sub get_block_choices {
- my $item = shift;
- my $blocklist;
- my ($typeorder,$types) = &blocktype_text();
- foreach my $type (@{$typeorder}) {
- if ($env{'form.'.$type.'_'.$item}) {
- $blocklist->{$type} = 'on';
- } else {
- $blocklist->{$type} = 'off';
- }
- }
- return $blocklist;
-}
-
-sub display_blocker_status {
- my ($r,$records,$ltext) = @_;
- my $parmcount = 0;
-
- my %lt = &Apache::lonlocal::texthash(
- 'modi' => 'Modify',
- 'canc' => 'Cancel',
- );
- my ($typeorder,$types) = &blocktype_text();
- $r->print(&Apache::loncommon::start_data_table());
- $r->print(<<"END");
-
-
-END
- foreach my $record (sort(keys(%{$records}))) {
- my $onchange = 'onFocus="javascript:window.document.forms['.
- "'blockform'].elements['modify_".$parmcount."'].".
- 'checked=true;"';
- my ($start,$end) = split(/____/,$record);
- my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
- my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
-
- my ($setuname,$setudom,$title,$blocks) =
- &Apache::loncommon::parse_block_record($$records{$record});
- $title = &HTML::Entities::encode($title,'"<>&');
- my $settername =
- &Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($setuname,$setudom),
- $setuname,$setudom);
- $r->print(&Apache::loncommon::start_data_table_row());
- $r->print(<<"END");
- $ltext->{'dura'}
- $ltext->{'setb'}
- $ltext->{'even'}
- $ltext->{'blck'}
- $ltext->{'actn'}?
- $ltext->{'star'}: $startform
-
$ltext->{'endd'}: $endform$settername
-
-
-END
- foreach my $block (@{$typeorder}) {
- my $blockstatus = '';
- if ($blocks->{$block} eq 'on') {
- $blockstatus = 'checked="true"';
- }
- $r->print('
-
');
- }
- $r->print(<<"END");
-
-END
- $r->print(&Apache::loncommon::end_data_table_row());
- $parmcount++;
- }
- $r->print(<<"END");
-
-
-
-END
- return $parmcount;
-}
-
-sub display_addblocker_table {
- my ($r,$parmcount,$ltext) = @_;
- my $start = time;
- my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
- my $onchange = 'onFocus="javascript:window.document.forms['.
- "'blockform'].elements['add_".$parmcount."'].".
- 'checked=true;"';
- my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
- my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
- my %lt = &Apache::lonlocal::texthash(
- 'addb' => 'Add block',
- 'exam' => 'e.g., Exam 1',
- 'addn' => 'Add new communication blocking periods'
- );
- my ($typeorder,$types) = &blocktype_text();
- $r->print(<<"END");
-$lt{'addn'}
-END
- $r->print(&Apache::loncommon::start_data_table());
- $r->print(<<"END");
-
-
-END
- $r->print(&Apache::loncommon::start_data_table_row());
- $r->print(<<"END");
- $ltext->{'dura'}
- $ltext->{'even'} $lt{'exam'}
- $ltext->{'blck'}
- $ltext->{'actn'}?
- $ltext->{'star'}: $startform
-
$ltext->{'endd'}: $endform
-
-END
- foreach my $block (@{$typeorder}) {
- $r->print('
-
');
- }
- $r->print(<<"END");
-
-END
- $r->print(&Apache::loncommon::end_data_table_row());
- $r->print(&Apache::loncommon::end_data_table());
- return;
-}
-
-sub blocktype_text {
- my %types = &Apache::lonlocal::texthash(
- 'com' => 'Messaging',
- 'chat' => 'Chat',
- 'boards' => 'Discussion',
- 'port' => 'Portfolio',
- 'groups' => 'Groups',
- 'blogs' => 'Blogs',
- );
- my $typeorder = ['com','chat','boards','port','groups','blogs'];
- return ($typeorder,\%types);
-}
-
# ----------------------------------------------------------- Display a message
sub displaymessage {
- my ($r,$msgid,$folder)=@_;
+ my ($r,$msgid,$folder,$msgstatus)=@_;
my $suffix=&Apache::lonmsg::foldersuffix($folder);
my %blocked = ();
my %setters = ();
@@ -1844,19 +2105,20 @@ 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.'));
+ 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){
@@ -1864,74 +2126,513 @@ 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('
');
+ my @actionlist;
if ($env{'user.adv'}) {
- $r->print(''.&mt('Functions').': '.
- ''.&mt('Reply').' '.
- ''.&mt('Forward').' '.
- ''.&mt('Mark Unread').' '.
- ''.&mt('Delete').' '.
- ''.&mt('Back to Folder Display').' ');
+
+# Prepare available functions
+ my @functionlist;
+ if (!$content{'noreplies'}) {
+ push(@functionlist,''
+ .&mt('Reply')
+ .'');
+ }
+ push(@functionlist,''
+ .&mt('Forward')
+ .'');
+ push(@functionlist,''
+ .&mt('Mark Unread')
+ .'');
+ push(@functionlist,''
+ .&mt('Delete')
+ .'');
+
+# Prepare available navigation
+ my @navigationlist;
if ($counter > 0){
- $r->print(''.&mt('Previous').' ');
+ push(@navigationlist,''
+ .&mt('Previous')
+ .'');
}
if ($counter < $number_of_messages - 1){
- $r->print(''.&mt('Next').' ');
+ push(@navigationlist,''
+ .&mt('Next')
+ .'');
+ }
+ push(@navigationlist,''
+ .&mt('Back to Folder Display')
+ .'');
+
+# Prepare available actions
+ my $symb;
+ if (defined($content{'symb'})) {
+ $symb = $content{'symb'};
+ } elsif (defined($content{'baseurl'})) {
+ $symb=&Apache::lonnet::symbread($content{'baseurl'});
}
- $r->print('
');
}
- my $tolist;
- my @recipients = ();
- for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
- $recipients[$i] = &Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($content{'recuser'}[$i],
+
+# Print functionlist, navigationlist, and actionlist in page header
+ my $functions=''.&mt('Currently available actions (will open extra window)').': ');
- my $symb=&Apache::lonnet::symbread($content{'baseurl'});
- if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
- $r->print(''.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').' ');
- }
+
+ if (($env{'request.course.id'}) && ($from_student) &&
+ (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
+ push(@actionlist,&Apache::loncommon::track_student_link(
+ 'View recent activity'
+ ,$content{'sendername'}
+ ,$content{'senderdomain'}
+ ,'check'));
+ }
if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
- $r->print(''.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').' ');
+ push(@actionlist,&Apache::loncommon::pprmlink(
+ &mt('Set/Change parameters')
+ ,$content{'sendername'}
+ ,$content{'senderdomain'}
+ ,$symb
+ ,'check'));
}
if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
- $r->print(''.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').' ');
+ push(@actionlist,&Apache::loncommon::pgrdlink(
+ &mt('Set/Change grades')
+ ,$content{'sendername'}
+ ,$content{'senderdomain'}
+ ,$symb
+ ,'check'));
}
- $r->print('
'.&mt('Subject').': '.$content{'subject'}.
- ($folder ne 'sent'?'
'.&mt('From').': '.
- &Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
- $content{'sendername'},$content{'senderdomain'}).' ('.
- $content{'sendername'}.' at '.
- $content{'senderdomain'}.') ':'
'.&mt('To').': '.
- $tolist).
- ($content{'courseid'}?'
'.&mt($crstype).': '.$courseinfo{'description'}.
- ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
- '
'.&mt('Time').': '.$content{'time'}.
- ($content{'baseurl'}?'
'.&mt('Refers to').': '.
- $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')':'').
- ''.
- &Apache::lontexconvert::msgtexconverted($content{'message'},1).
- '
'.&displayresource(%content).'
' + .&Apache::lontexconvert::msgtexconverted($content{'message'},1) + .'' + ); + if (&displayresource(%content)) { + $r->print(&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title(&mt('Resource Details')) + .&displayresource(%content) + ); + } + $r->print(&Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box()); + # Display LON-CAPA Message (End) + return; +} + +sub retrieve_recips { + my ($context,$content,$recips)= @_; + my $tonum = 0; + if (ref($content) eq 'HASH') { + my %reciphash = + &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}], + $content->{'senderdomain'},$content->{'sendername'}); + my $recipinfo = $reciphash{$content->{'recipid'}}; + if (ref($recipinfo) eq 'HASH') { + foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') { + if (ref($recipinfo->{$type}) eq 'HASH') { + if ($type eq 'to') { + $tonum = keys(%{$recipinfo->{$type}}); + } + foreach my $user (sort(keys(%{$recipinfo->{$type}}))) { + my ($uname,$udom) = split(/:/,$user); + next if (($context eq 'replying') && ($uname eq $env{'user.name'}) + && ($udom eq $env{'user.domain'})); + my $showuser =''; + if ($context eq 'replying') { + if (($type eq 'to') || ($type eq 'cc')) { + $showuser = ''; + if (ref($recips) eq 'HASH') { + push(@{$recips->{$type}},$showuser); + } + } + } + } + } + } + return $tonum; +} + +sub recipients_link { + my ($r,$content,$recipients) = @_; + my ($broadcast_link,$show); + if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) { + if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') { + if (@{$recipients->{'course_broadcast'}} > 0) { + $show = 'course'; + } + } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') { + if (@{$recipients->{'group_cc_broadcast'}} > 0) { + $show = 'group_cc'; + } + } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') { + if (@{$recipients->{'group_bcc_broadcast'}} > 0) { + $show = 'group_bcc'; + } + } + if ($show) { + my ($nothing,$height,$width,$start_page,$end_page,$body); + $nothing=&Apache::lonhtmlcommon::javascript_nothing(); + $height = 400; + $width = 600; + $start_page = + &Apache::loncommon::start_page('Broadcast List', undef, + {only_body => 1, + js_ready => 1,}); + $end_page = &Apache::loncommon::end_page({js_ready => 1,}); + $body = '
'.&mt('Attachment not included - exceeded permitted length').'
'.&mt('Could not deliver message').' '. - &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'
'); + &printheader($r,'','Messages cancelled.'); + return 'cancelled'; } + return $sendstatus; } # ===================================================================== Handler @@ -2259,21 +3098,20 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['display','replyto','forward','markread','markdel','markunread', 'sendreply','compose','sendmail','critical','recname','recdom', - 'recordftf','sortedby','block','folder','startdis','interdis', - 'showcommentbaseurl','dismode','group','subject','text','ref']); - $sqs='&sortedby='.$env{'form.sortedby'}; + 'recordftf','sortedby','folder','startdis','interdis', + 'showcommentbaseurl','dismode','group','subject','text','ref', + 'msgstatus']); + $sqs='&sortedby='.$env{'form.sortedby'}; # ------------------------------------------------------ They checked for email - unless ($env{'form.block'}) { - &Apache::lonnet::put('email_status',{'recnewemail'=>0}); - } + &Apache::lonnet::put('email_status',{'recnewemail'=>0}); # ----------------------------------------------------------------- Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/communicate", - text=>"Communication/Messages", + text=>"Messages", faq=>12,bug=>'Communication Tools',}); # ------------------------------------------------------------------ Get Folder @@ -2282,7 +3120,7 @@ sub handler { unless ($folder) { $folder=''; } else { - $sqs.='&folder='.&escape($folder); + $sqs.='&folder='.&escape($folder); } # ------------------------------------------------------------ Get Display Mode @@ -2294,15 +3132,13 @@ sub handler { } # --------------------------------------------------------------------- Display - + my $msgstatus = $env{'form.msgstatus'}; $startdis=$env{'form.startdis'}; - $startdis--; + if ($startdis ne '') { + $startdis--; + } unless ($startdis) { $startdis=0; } - $interdis=$env{'form.interdis'}; - unless ($interdis) { $interdis=20; } - $sqs.='&interdis='.$interdis; - if ($env{'form.firstview'}) { $startdis=0; } @@ -2316,28 +3152,31 @@ sub handler { $startdis++; } my $postedstartdis=$startdis+1; - $sqs.='&startdis='.$postedstartdis; + $sqs.='&startdis='.$postedstartdis; # --------------------------------------------------------------- Render Output if ($env{'form.display'}) { - &displaymessage($r,$env{'form.display'},$folder); + &displaymessage($r,$env{'form.display'},$folder,$msgstatus); } elsif ($env{'form.replyto'}) { &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode); } elsif ($env{'form.confirm'}) { &printheader($r,'','Confirmed Receipt'); my $replying = 0; foreach my $envkey (keys(%env)) { - if ($envkey=~/^form\.rec\_(.*)$/) { - $r->print(''.&mt('Confirming Receipt').': '. - &Apache::lonmsg::user_crit_received($1).''. - &mt('Failed to delete the message.').'
'. - ''.$msg."
\n"); + my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1); + $message .= ''.$msg.'
'; + $message = &Apache::loncommon::confirmwrapper($message); + $r->print($message); } &Apache::loncommunicate::menu($r); - &disall($r,($folder?$folder:$dismode)); - } elsif ($env{'form.markedmove'}) { - my ($total,$failed,@failed_msg)=(0,0); - foreach my $key (keys(%env)) { - if ($key=~/^form\.delmark_(.*)$/) { - my ($result,$msg) = - &movemsg(&unescape($1),$folder, - $env{'form.movetofolder'}); - if ($result) { + &disall($r,($folder?$folder:$dismode),$msgstatus); + } elsif ($env{'form.markedaction'} eq 'markedforward') { + my $total = 0; + my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msgid (@to_forward) { + &statuschange(&unescape($msgid),'forwarded',$folder); + $total ++; + } + if ($total > 0) { + &compout($r,undef,undef,undef,undef,$folder,$dismode,$total); + } + } elsif ($env{'form.markedaction'} eq 'markedread') { + my $total = 0; + my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msgid (@to_markread) { + &statuschange(&unescape($msgid),'read',$folder); + $total ++; + } + &printheader($r,'','Marked Messages Read'); + my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] read',$total)); + $message = &Apache::loncommon::confirmwrapper($message); + $r->print($message); + # $r->print(''); + &Apache::loncommunicate::menu($r); + &disall($r,($folder?$folder:$dismode),$msgstatus); + } elsif ($env{'form.markedaction'} eq 'markedunread') { + my $total = 0; + my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msgid (@to_markunread) { + &statuschange(&unescape($msgid),'new',$folder); + $total ++; + } + &printheader($r,'','Marked Messages Unread'); + my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] unread',$total)); + $message = &Apache::loncommon::confirmwrapper($message); + $r->print($message); + # $r->print('
'); + &Apache::loncommunicate::menu($r); + &disall($r,($folder?$folder:$dismode),$msgstatus); + } elsif ($env{'form.markedaction'} eq 'markedmove') { + my $destfolder = $env{'form.movetofolder'}; + my %gotfolders = &Apache::lonmsg::get_user_folders(); + &printheader($r,'','Moved Messages'); + if (!defined($gotfolders{$destfolder})) { + $r->print(&mt('Destination folder [_1] is not a valid folder', + ''.$destfolder.'')); + } else { + my ($total,$failed,@failed_msg)=(0,0); + my @to_move = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msgid (@to_move) { + my ($result,$msg) = &movemsg(&unescape($msgid),$folder, + $env{'form.movetofolder'}); + if ($result) { $total++; - } else { + } else { $failed++; push(@failed_msg,$msg); - } + } } - } - &printheader($r,'','Moved Messages'); - if ($failed) { - $r->print('
- '.&mt('Failed to move [_1] message(s)',$failed). - '
'); - $r->print(''. - join("
\n",@failed_msg). - "
\n"); - } - $r->print(&mt('Moved [_1] message(s)',$total).''); + my $message = ''; + if ($failed) { + $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1); + $message .= '
'. + join("
\n",@failed_msg). + "
\n"; + } + $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Moved [quant,_1,message]',$total)); + $message = &Apache::loncommon::confirmwrapper($message); + $r->print($message); + # $r->print(''); + } &Apache::loncommunicate::menu($r); - &disall($r,($folder?$folder:$dismode)); - } elsif ($env{'form.markeddel'}) { + &disall($r,($folder?$folder:$dismode),$msgstatus); + } elsif ($env{'form.markedaction'} eq 'markeddel') { my ($total,$failed,@failed_msg)=(0,0); - foreach my $key (keys(%env)) { - if ($key=~/^form\.delmark_(.*)$/) { - my ($result,$msg) = - &statuschange(&unescape($1),'deleted', - $folder); - if ($result) { - $total++; - } else { - $failed++; - push(@failed_msg,$msg); - } + my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark'); + foreach my $msgid (@to_delete) { + my ($result,$msg) = &statuschange(&unescape($msgid),'deleted', + $folder); + if ($result) { + $total++; + } else { + $failed++; + push(@failed_msg,$msg); } } &printheader($r,'','Deleted Messages'); + my $message = ''; if ($failed) { - $r->print('
- '.&mt('Failed to delete [_1] message(s)',$failed). - '
'); - $r->print(''. - join("
\n",@failed_msg). - "
\n"); - } - $r->print(&mt('Deleted [_1] message(s)',$total).''); + $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1); + $message .= '
'. + join("
\n",@failed_msg). + "
\n"; + } + $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Deleted [quant,_1,message]',$total)); + $message = &Apache::loncommon::confirmwrapper($message); + $r->print($message); + # $r->print('');
&Apache::loncommunicate::menu($r);
- &disall($r,($folder?$folder:$dismode));
+ &disall($r,($folder?$folder:$dismode),$msgstatus);
} elsif ($env{'form.markunread'}) {
&printheader($r,'','Marked Message as Unread');
&statuschange($env{'form.markunread'},'new');
&Apache::loncommunicate::menu($r);
- &disall($r,($folder?$folder:$dismode));
+ &disall($r,($folder?$folder:$dismode),$msgstatus);
} elsif ($env{'form.compose'}) {
&compout($r,'','',$env{'form.compose'});
} elsif ($env{'form.recordftf'}) {
&facetoface($r,$env{'form.recordftf'});
- } elsif ($env{'form.block'}) {
- &examblock($r,$env{'form.block'});
} elsif ($env{'form.sendmail'}) {
- &sendoffmail($r,$folder);
+ if ($env{'form.multiforward'}) {
+ &printheader($r,'','Messages being sent.');
+ my $fixed_subj = $env{'form.subject'};
+ my $suffix=&Apache::lonmsg::foldersuffix($folder);
+ my (%sendresult,%forwardok,%forwardfail,$fwdcount);
+ my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
+ foreach my $item (@to_forward) {
+ my $msgid=&unescape($item);
+ my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
+ my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
+ if ($env{'form.showorigsubj'}) {
+ $env{'form.subject'} = $fixed_subj.$content{'subject'};
+ } else {
+ $env{'form.subject'} = '';
+ }
+ my $uname = $content{'sendername'};
+ my $udom = $content{'senderdomain'};
+ &statuschange($msgid,'forwarded',$folder);
+ if ($env{'form.showorigsender'}) {
+ $env{'form.message'} = $env{'form.msgheader'}.' '.
+ &Apache::loncommon::plainname($uname,$udom).' ('.
+ $uname.':'.$udom.')';
+ }
+ $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
+ $content{'message'};
+ $env{'form.attachmenturl'} = $content{'attachmenturl'};
+ $env{'form.multiforwid'} = $item;
+ $fwdcount ++;
+ $r->print($fwdcount.': ');
+ $sendresult{$msgid} = &sendoffmail($r,$folder);
+ $r->print('
');
+ }
+ foreach my $key (keys(%sendresult)) {
+ if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
+ $forwardok{$key} = $sendresult{$key};
+ } else {
+ $forwardfail{$key} = $sendresult{$key};
+ }
+ }
+ if (keys(%forwardok) > 0) {
+ my $count = keys(%forwardok);
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('[quant,_1,message] forwarded.',$count));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
+ }
+ if (keys(%forwardfail) > 0) {
+ my $count = keys(%forwardfail);
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
+ foreach my $key (keys(%forwardfail)) {
+ $message .= '
'.&mt('Could not deliver forwarded message.').' '.
+ &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
+ }
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
+ }
+ &Apache::loncommunicate::menu($r);
+ } else {
+ &sendoffmail($r,$folder);
+ }
if ($env{'form.storebasecomment'}) {
&storecomment($r);
}
@@ -2437,21 +3378,24 @@ sub handler {
$env{'form.message'},'/adm/communicate','public');
}
if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
- &disall($r,($folder?$folder:$dismode));
+ &disall($r,($folder?$folder:$dismode),$msgstatus);
}
} elsif ($env{'form.newfolder'}) {
&printheader($r,'','New Folder');
my $showfolder = $env{'form.newfolder'};
my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
if ($makeresult eq 'ok') {
- $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'
');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" created.',$showfolder));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
} else {
- $r->print(&mt('Creation failed.').' '.$makeresult.'
'.
- $warning);
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Creation failed.').' '.$makeresult.'
'.$warning,1);
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
$showfolder = $folder;
}
&Apache::loncommunicate::menu($r);
- &disall($r,$showfolder);
+ &disall($r,$showfolder,$msgstatus);
} elsif ($env{'form.showcommentbaseurl'}) {
&storedcommentlisting($r);
} elsif ($env{'form.folderaction'} eq 'delete') {
@@ -2459,29 +3403,38 @@ sub handler {
my $showfolder = '';
my $delresult = &deletefolder($folder);
if ($delresult eq 'ok') {
- $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'
');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" deleted.',$folder));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
+ $env{'form.folder'} = '';
} else {
- $r->print(&mt('Deletion failed.').' '.$delresult.'
');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Deletion failed.').' '.$delresult,1);
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
$showfolder = $folder;
}
&Apache::loncommunicate::menu($r);
- &disall($r,$showfolder);
+ &disall($r,$showfolder,$msgstatus);
} elsif ($env{'form.folderaction'} eq 'rename') {
&printheader($r,'','Renamed Folder');
my $showfolder = $env{'form.renamed'};
my $renresult = &renamefolder($folder);
if ($renresult eq 'ok') {
- $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'
');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" renamed to "[_2]".',$folder,$showfolder));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
} else {
- $r->print(&mt('Renaming failed.').' '.$renresult.'
');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Renaming failed.').' '.$renresult,1);
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
$showfolder = $folder;
}
&Apache::loncommunicate::menu($r);
- &disall($r,$showfolder);
+ &disall($r,$showfolder,$msgstatus);
} else {
&printheader($r,'','Display All Messages');
&Apache::loncommunicate::menu($r);
- &disall($r,($folder?$folder:$dismode));
+ &disall($r,($folder?$folder:$dismode),$msgstatus);
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -2490,8 +3443,6 @@ sub handler {
=pod
-=back
-
=cut
1;