--- loncom/interface/lonmsgdisplay.pm 2007/12/08 00:25:14 1.83 +++ 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.83 2007/12/08 00:25:14 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 # @@ -102,6 +102,8 @@ use HTML::TokeParser(); use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::lonhtmlcommon(); +use Apache::longroup; +use Apache::lonnavmaps; use Apache::lontexconvert(); use HTML::Entities(); use Apache::lonlocal; @@ -110,31 +112,36 @@ use Apache::lonfeedback; use Apache::lonrss(); use Apache::lonselstudent(); use lib '/home/httpd/lib/perl/'; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); # Querystring component with sorting type -my $sqs; -my $startdis; +my $sqs=''; +my $startdis=''; # ============================================================ List all folders sub folderlist { my ($folder,$msgstatus) = @_; - my %lt = &Apache::lonlocal::texthash( + my %html_lt = &Apache::lonlocal::texthash( actn => 'Action', fold => 'Folder', show => 'Show', status => 'Message Status', go => 'Go', + + ); + &html_escape(\%html_lt); + my %js_lt = &Apache::lonlocal::texthash( 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', + fmnb => 'Folder may not be renamed as it is a folder provided by the system.', + asth => 'Requested name already in use for a system-provided or user-defined folder.', ); + &js_escape(\%js_lt); + + # 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', @@ -143,7 +150,7 @@ sub folderlist { ); $actions{'select_form_order'} = ['view','rename','delete']; - my %statushash = &get_msgstatus_types(); + my %statushash = &Apache::lonlocal::texthash(&get_msgstatus_types()); $statushash{'select_form_order'} = ['','new','read','replied','forwarded']; @@ -170,6 +177,7 @@ sub folderlist { $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 .= '
'. - &Apache::lonfeedback::generate_preview_button('compemail','message'). - &Apache::lonhtmlcommon::htmlareaselectactive('message')); + $r->print(''); + if ($hasfloat) { + $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'); @@ -1486,7 +1807,7 @@ sub recipient_input_row { &Apache::loncommon::selectstudent_link('compemail','recuname', 'recdomain'); my $output = <<"ENDREC"; -+ + + | $prevbutton |
".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)."
"); + $r->print("".&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.')."
"); } else { - $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\'); + $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\'); } + } elsif ($target eq 'tex') { + $r->print(&Apache::lonxml::xmlparse($r,$target,$result)); } else { - $r->print($result); + $r->print('$lt{'user'}: | - | -$stdbrws - | -
$lt{'dom'}: | -$domform |
'); my $escmsgid=&escape($msgid); foreach (@messages) { if ($_->[5] eq $escmsgid){ @@ -2062,7 +2126,6 @@ sub displaymessage { } $counter++; } - $r->print(''); my $see_anonymous; my $from_student = 0; @@ -2082,65 +2145,140 @@ sub displaymessage { 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('
'.&mt('Functions').': | '); + +# Prepare available functions + my @functionlist; if (!$content{'noreplies'}) { - $r->print(''.&mt('Reply').' | '); - } - $r->print(''.&mt('Forward').' | '. - ''.&mt('Mark Unread').' | '. - ''.&mt('Delete').' | '. - ''.&mt('Back to Folder Display').' | '); + 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').' | '); - } - $r->print('
'.&mt('Currently available actions (will open extra window)').': | '); - 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('
'. - &Apache::lontexconvert::msgtexconverted($content{'message'},1). - '
' + .&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_cc_recips { - my ($context,%content) = @_; - my %reciphash = - &Apache::lonnet::get('nohist_emailrecip',[$content{'recipid'}], - $content{'senderdomain'},$content{'sendername'}); - my $recipinfo = $reciphash{$content{'recipid'}}; - my @ccs; - if (ref($recipinfo) eq 'HASH') { - if (ref($recipinfo->{'cc'}) eq 'HASH') { - foreach my $cc (sort(keys(%{$recipinfo->{'cc'}}))) { - my ($ccname,$ccdom) = split(/:/,$cc); - if (!(($ccname eq $env{'user.name'}) && - ($ccdom eq $env{'user.domain'}))) { - my $showcc =''; - if ($context eq 'replying') { - $showcc = ''; - } - $showcc .= ''; - push(@ccs,$showcc); +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 @ccs; + 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)").'
'); + my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not deliver message'),1); + $message .= ''. - &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),$msgstatus); @@ -2770,7 +3217,10 @@ sub handler { $total ++; } &printheader($r,'','Marked Messages Read'); - $r->print(&mt('Marked [_1] message(s) read',$total).''); + 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') { @@ -2781,7 +3231,10 @@ sub handler { $total ++; } &printheader($r,'','Marked Messages Unread'); - $r->print(&mt('Marked [_1] message(s) unread',$total).'
'); + 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') { @@ -2790,7 +3243,7 @@ sub handler { &printheader($r,'','Moved Messages'); if (!defined($gotfolders{$destfolder})) { $r->print(&mt('Destination folder [_1] is not a valid folder', - $destfolder)); + ''.$destfolder.'')); } else { my ($total,$failed,@failed_msg)=(0,0); my @to_move = &Apache::loncommon::get_env_multiple('form.delmark'); @@ -2804,15 +3257,17 @@ sub handler { push(@failed_msg,$msg); } } - 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),$msgstatus); @@ -2830,15 +3285,17 @@ sub handler { } } &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),$msgstatus);
} elsif ($env{'form.markunread'}) {
@@ -2850,8 +3307,6 @@ sub handler {
&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'}) {
if ($env{'form.multiforward'}) {
&printheader($r,'','Messages being sent.');
@@ -2862,7 +3317,7 @@ sub handler {
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);
+ my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
if ($env{'form.showorigsubj'}) {
$env{'form.subject'} = $fixed_subj.$content{'subject'};
} else {
@@ -2876,8 +3331,10 @@ sub handler {
&Apache::loncommon::plainname($uname,$udom).' ('.
$uname.':'.$udom.')';
}
- $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
- $content{'message'};
+ $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);
@@ -2892,19 +3349,19 @@ sub handler {
}
if (keys(%forwardok) > 0) {
my $count = keys(%forwardok);
- $r->print('
'.
- &mt('[quant,_1,message] forwarded.',$count).
- '');
+ 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);
- $r->print('
'.
- &mt('Could not forward [quant,_1,message].',$count).
- ' ');
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
foreach my $key (keys(%forwardfail)) {
- $r->print(&mt('Could not deliver forwarded message.').' '.
- &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').
');
+ $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 {
@@ -2928,10 +3385,13 @@ sub handler {
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);
@@ -2943,10 +3403,14 @@ 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);
@@ -2956,9 +3420,13 @@ sub handler {
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);