--- loncom/interface/lonmsgdisplay.pm 2010/08/20 19:12:22 1.124.4.11 +++ loncom/interface/lonmsgdisplay.pm 2023/10/07 01:47:21 1.181.2.9.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.124.4.11 2010/08/20 19:12:22 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.181.2.9.2.3 2023/10/07 01:47:21 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; @@ -109,32 +111,35 @@ use Apache::loncommunicate; use Apache::lonfeedback; use Apache::lonrss(); use Apache::lonselstudent(); +use Apache::lonenc(); 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}); @@ -182,16 +187,16 @@ function folder_choice(targetform,caller if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') { for (var i=0; i + - - - - +
'.$lt{'fold'}.'
'."\n". - &Apache::loncommon::select_form($folder,'folder',%formhash).' +
'.$html_lt{'fold'}.'
'."\n". + &Apache::loncommon::select_form($folder,'folder',\%formhash).'
'.$lt{'show'}.'
'."\n". +
'.$html_lt{'show'}.'
'."\n". &Apache::loncommon::select_form($env{'form.interdis'},'interdis', - %show).' + \%show).'
'.$lt{'status'}.'
'."\n". - &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).' +
'.$html_lt{'status'}.'
'."\n". + &Apache::loncommon::select_form($msgstatus,'msgstatus',\%statushash).'
'.$lt{'actn'}.'
'. - &Apache::loncommon::select_form('view','folderaction',%actions).' -

'. - ' +
+ '.$html_lt{'actn'}.'
'."\n".' + '. + &Apache::loncommon::select_form('view','folderaction',\%actions). + ' + +
+ '.&mt('New Folder').'
'."\n".' + + + +
-      - - '. - '

-
'.&mt('Name').'
'. - ' -
- - -'."\n". + +'."\n". ''. ''. ($folder=~/^critical/?'':''); @@ -265,8 +271,8 @@ sub get_permanent_folders { my %permfolders = &Apache::lonlocal::texthash('' => 'INBOX', 'trash' => 'TRASH', - 'critical' => 'Critical', - 'sent' => 'Sent Messages', + 'critical' => 'CRITICAL', + 'sent' => 'SENT MESSAGES', ); return %permfolders; } @@ -295,14 +301,27 @@ sub scrollbuttons { } else { $status = $statushash{$msgstatus}; } - return - ''.&mt('Page').': '. - ''. - ''. - ' of '.$maxdis. - ''. - '
'. - &mt('[_1] messages: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).''; + my $output = ''.&mt('Page:').' '; + if ($maxdis == 1) { + # No buttons if only one page is displayed + $output .= '1/1'; + } else { + $output .= + ''. + ''. + ' / '.$maxdis.' '. + ''. + ''; + } + $output .= + '

' + .''.&mt($status.' messages:').' ' + .&mt('showing messages [_1] through [_2] of [_3].', + $first,$finish,$total) + .'

' + .''; + + return $output; } # =============================================================== Status Change @@ -369,7 +388,7 @@ sub deletefolder { my ($folder)=@_; my %permfolders = &get_permanent_folders(); if (defined($permfolders{$folder})) { - return &mt('The folder "[_1]" may not be deleted',$folder); + return &mt('The folder "[_1]" may not be deleted.',$permfolders{$folder}); } my %userfolders = &Apache::lonmsg::get_user_folders(); if (!defined($userfolders{$folder})) { @@ -525,20 +544,20 @@ sub discourse { \%defaultUsers, 1,"selectedusers",1,'email') ) { - my $bcc_curr_hdr; - if ($crstype eq 'Community') { - $bcc_curr_hdr = &mt('Bcc: community participants with current access'); - } else { - $bcc_curr_hdr = &mt('Bcc: course members with current access'); - } - $result .= '
' - .''.$bcc_curr_hdr.'' - .'' - .'
'; - $result .= $tmptext.'

'; - if (ref($statushash) eq 'HASH') { - $statushash->{'active'} = 1; - } + my $bcc_curr_hdr; + if ($crstype eq 'Community') { + $bcc_curr_hdr = &mt('Bcc: community participants with current access'); + } else { + $bcc_curr_hdr = &mt('Bcc: course members with current access'); + } + $result .= '
' + .$bcc_curr_hdr + .'' + .'
'; + $result .= $tmptext.'

'; + if (ref($statushash) eq 'HASH') { + $statushash->{'active'} = 1; + } } if ($tmptext = &Apache::lonselstudent::render_student_list($expired_members, "previoususers", @@ -546,20 +565,21 @@ sub discourse { \%defaultUsers, 1, "selectedusers",0,'email') ) { - my $bcc_prev_hdr; - if ($crstype eq 'Community') { - $bcc_prev_hdr = &mt('Bcc: community participants with expired access'); - } else { - $bcc_prev_hdr = &mt('Bcc: course members with expired access'); - } - $result .= '
' - .''.$bcc_prev_hdr.'' - .'' - .'
'; + my $bcc_prev_hdr; + if ($crstype eq 'Community') { + $bcc_prev_hdr = &mt('Bcc: community participants with expired access'); + } else { + $bcc_prev_hdr = &mt('Bcc: course members with expired access'); + } + $result .= '
' + .$bcc_prev_hdr + .'' + .''; $result .= $tmptext.'

'; if (ref($statushash) eq 'HASH') { $statushash->{'previous'} = 1; } + } if ($tmptext = &Apache::lonselstudent::render_student_list($future_members, "futureusers", @@ -567,20 +587,22 @@ sub discourse { \%defaultUsers, 1, "selectedusers",0,'email') ) { - my $bcc_future_hdr; - if ($crstype eq 'Community') { - $bcc_future_hdr = &mt('Bcc: community participants with future access'); - } else { - $bcc_future_hdr = &mt('Bcc: course members with future access'); - } - $result .= '
' - .''.$bcc_future_hdr.'' - .'' - .'
'; + my $bcc_future_hdr; + if ($crstype eq 'Community') { + $bcc_future_hdr = &mt('Bcc: community participants with future access'); + } else { + $bcc_future_hdr = &mt('Bcc: course members with future access'); + } + + $result .= '
' + .$bcc_future_hdr + .'' + .''; $result .= $tmptext.'
'; if (ref($statushash) eq 'HASH') { $statushash->{'future'} = 1; } + } return $result; } @@ -614,9 +636,7 @@ sub disgroup { return; } else { $hasfloat = 1; - unless($env{'environment.wysiwygeditor'} eq 'on') { - $r->print('
'); - } + $r->print('
'); my %Sortby = ( active => {}, previous => {}, @@ -650,8 +670,9 @@ sub disgroup { if (ref($access_status) eq 'HASH') { $access_status->{$status} = $$numitems{$status}; } - $r->print('
'.$lt{$status}. - '
'. + $r->print('
'. + ''.$lt{$status}.''. + ''. ''. ''. @@ -688,9 +709,7 @@ sub disgroup { } } } - unless($env{'environment.wysiwygeditor'} eq 'on') { - $r->print('
'); - } + $r->print('
'); } return $hasfloat; } @@ -698,7 +717,7 @@ sub disgroup { sub group_check_uncheck { my $output = qq| '; + if ($head_extra) { + $extra .= "\n$head_extra"; + } $r->print(&Apache::loncommon::start_page('Messages', $extra)); $r->print(&Apache::lonhtmlcommon::breadcrumbs @@ -2903,11 +2758,11 @@ sub header { # ---------------------------------------------------------------- Print header sub printheader { - my ($r,$url,$desc,$title,$baseurl)=@_; + my ($r,$url,$desc,$title,$baseurl,$head_extra)=@_; &Apache::lonhtmlcommon::add_breadcrumb ({href=>$url, text=>$desc}); - &header($r,$title,$baseurl); + &header($r,$title,$baseurl,$head_extra); } # ------------------------------------------------------------ Store the comment @@ -2931,7 +2786,7 @@ sub storedcommentlisting { '^'.&escape(&escape($env{'form.showcommentbaseurl'}))); $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef, {'onlybody' => 1})); - if ((keys %msgs)[0]=~/^error\:/) { + if ((keys(%msgs))[0]=~/^error\:/) { $r->print(&mt('No saved comments yet.')); } else { my $found=0; @@ -2964,7 +2819,14 @@ sub sendoffmail { $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; } - if ($env{'form.send'}) { + my $clientip = &Apache::lonnet::get_requestor_ip($r); + my %setters; + my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) = + &Apache::loncommon::blockcheck(\%setters,'com',$clientip); + if ($by_ip) { + &printheader($r,'','Sending messages blocked from your location.'); + return 'blocked'; + } elsif ($env{'form.send'}) { if (!$env{'form.multiforward'}) { if ($group eq '') { &printheader($r,'','Messages being sent.'); @@ -3134,7 +2996,7 @@ sub sendoffmail { &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'}); } if ($env{'form.attachment'}) { - if (length($env{'form.attachment'})<131072) { + if (length($env{'form.attachment'}) <= 1048576) { $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now); } else { $r->print('

'.&mt('Attachment not included - exceeded permitted length').'

'); @@ -3146,6 +3008,7 @@ sub sendoffmail { } my @recusers; my @recudoms; + my %permresults; foreach my $address (sort(keys(%toaddr))) { my ($recuname,$recdomain)=split(/\:/,$address); my $msgtxt = $savemsg; @@ -3162,7 +3025,8 @@ sub sendoffmail { $env{'form.sendbck'}, $env{'form.permanent'}, \$sentmessage{$address}, - $nosentstore,$recipid); + $nosentstore,$recipid, + $attachmenturl,\%permresults); } else { $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': '); @thismsg= @@ -3173,13 +3037,20 @@ sub sendoffmail { $env{'form.permanent'}, \$sentmessage{$address}, undef,undef,undef, - $nosentstore,$recipid); + $nosentstore,$recipid, + \%permresults); } $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg); if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) { $numsent++; push(@recusers,$recuname); push(@recudoms,$recdomain); + if ($1 eq 'ok') { + $r->print('ok '); + } + if ($permresults{$recuname.':'.$recdomain}) { + $r->print(' (email) '); + } } $sendstatus.=' '.join(' ',@thismsg); } @@ -3255,7 +3126,7 @@ sub sendoffmail { '','','','',$recipid); } } - if (!$env{'form.multiforward'}) { + if (!$env{'form.multiforward'}) { if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Completed.')); $message = &Apache::loncommon::confirmwrapper($message); @@ -3298,16 +3169,29 @@ 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', + 'recordftf','sortedby','folder','startdis','interdis', 'showcommentbaseurl','dismode','group','subject','text','ref', - 'msgstatus']); + 'msgstatus','btoken']); $sqs='&sortedby='.$env{'form.sortedby'}; -# ------------------------------------------------------ They checked for email - unless ($env{'form.block'}) { - &Apache::lonnet::put('email_status',{'recnewemail'=>0}); +# ----------- Check if access was from balancer to server with existing session + + if ($env{'form.btoken'}) { + my %info = &Apache::lonnet::tmpget($env{'form.btoken'}); + &Apache::lonnet::tmpdel($env{'form.btoken'}); + delete($env{'form.btoken'}); + unless ($env{'form.display'}) { + if (($info{'display'}) && ($info{'mailrecip'})) { + if (&unescape($info{'mailrecip'}) eq $env{'user.name'}.':'.$env{'user.domain'}) { + $env{'form.display'} = &unescape($info{'display'}); + } + } + } } +# ------------------------------------------------------ They checked for email + &Apache::lonnet::put('email_status',{'recnewemail'=>0}); + # ----------------------------------------------------------------- Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -3395,7 +3279,7 @@ sub handler { &statuschange($env{'form.markdel'},'deleted',$folder); if (!$result) { my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1); - $message .= '

'.$msg.'

'; + $message .= '

'.$msg.'

'; $message = &Apache::loncommon::confirmwrapper($message); $r->print($message); } @@ -3422,6 +3306,7 @@ sub handler { 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') { @@ -3435,6 +3320,7 @@ sub handler { 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') { @@ -3443,7 +3329,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'); @@ -3457,16 +3343,17 @@ sub handler { push(@failed_msg,$msg); } } - my $message; + my $message = ''; if ($failed) { - $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1); - $message .= '

'. - join("

\n

",@failed_msg). + $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); @@ -3484,16 +3371,17 @@ sub handler { } } &printheader($r,'','Deleted Messages'); - my $message; + my $message = ''; if ($failed) { - $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1); - $message .= '

'. - join("

\n

",@failed_msg). + $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'}) { @@ -3505,8 +3393,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.'); @@ -3557,8 +3443,12 @@ sub handler { 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 .= '
'.&mt('Could not deliver forwarded message.').' '; + if ($forwardfail{$key} eq 'blocked') { + $message .= &mt('Sending messages is blocked from your IP address'); + } else { + $message .= &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')'; + } } $message = &Apache::loncommon::confirmwrapper($message); $r->print($message);