--- loncom/interface/lonmsgdisplay.pm 2006/12/23 06:22:36 1.56.2.1 +++ loncom/interface/lonmsgdisplay.pm 2007/04/22 02:25:36 1.69 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.56.2.1 2006/12/23 06:22:36 albertel Exp $ +# $Id: lonmsgdisplay.pm,v 1.69 2007/04/22 02:25:36 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 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; @@ -132,7 +115,6 @@ use LONCAPA; # Querystring component with sorting type my $sqs; my $startdis; -my $interdis; # ============================================================ List all folders @@ -230,6 +212,10 @@ function folder_choice(targetform,caller } } |; + my %show = ('select_form_order' => [10,20,50,100,200], + map {$_=>$_} (10,20,50,100,200)); + + $output .= '
@@ -240,12 +226,9 @@ function folder_choice(targetform,caller -
'.$lt{'fold'}.'
'."\n". &Apache::loncommon::select_form($folder,'folder',%formhash).'
'.$lt{'show'}.'
- +
'.$lt{'show'}.'
'."\n". + &Apache::loncommon::select_form($env{'form.interdis'},'interdis', + %show).'
'.$lt{'status'}.'
'."\n". &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).' @@ -301,16 +284,20 @@ sub scrollbuttons { $start++; $maxdis++;$first++;$finish++; my %statushash = &get_msgstatus_types(); - + my $status; + if ($msgstatus eq '') { + $status = &mt('All'); + } else { + $status = $statushash{$msgstatus}; + } return - ''.&mt('Page').': '. - ''. - ''. - ' of '.$maxdis. - ''. - '
'. - &mt('_location_in_mail_folder',$msgstatus,$statushash{$msgstatus}, - $first,$finish,$total).''; + ''.&mt('Page').': '. + ''. + ''. + ' of '.$maxdis. + ''. + '
'. + &mt('[_1] messages: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).''; } # =============================================================== Status Change @@ -389,8 +376,8 @@ sub deletefolder { my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); if (@messages > 0) { return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder). - '
'. - &mt('Delete or move the messages to a different folder first.'); + '
'. + &mt('Delete or move the messages to a different folder first.'); } my $delresult = &Apache::lonnet::del('email_folders',[$folder]); return $delresult; @@ -770,7 +757,6 @@ sub sortedmessages { my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_; my $suffix=&Apache::lonmsg::foldersuffix($folder); my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); - #unpack the varibles and repack into temp for sorting my @temp; my %descriptions; @@ -785,7 +771,7 @@ sub sortedmessages { foreach my $msgid (@messages) { my $esc_msgid=&escape($msgid); - my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)= + my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) = &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef, \%status_cache); next if ($msgstatus ne '' && $msgstatus ne $status); @@ -888,6 +874,17 @@ sub get_course_desc { sub disall { my ($r,$folder,$msgstatus)=@_; + my %saveable = ('folder' => 'scalar', + 'msgstatus' => 'scalar', + 'sortedby' => 'scalar', + 'interdis' => 'scalar', + ); + &Apache::loncommon::store_settings('user','mail',\%saveable); + &Apache::loncommon::restore_settings('user','mail',\%saveable); + $folder ||= $env{'form.folder'}; + $msgstatus ||= $env{'form.msgstatus'}; + $env{'form.interdis'} ||= 20; + $r->print(&folderlist($folder,$msgstatus)); if ($folder eq 'critical') { &discrit($r); @@ -910,19 +907,11 @@ sub disfolder { nome => 'No messages have been selected to apply ths action to.', chec => 'Check the checkbox for at least one message.', ); + my $jscript = &Apache::loncommon::check_uncheck_jscript(); $r->print(< - function checkall() { - for (i=0; i 0) { + for (var i=0; iprint('

'.&mt('_empty_mail_folder', - $msgstatus, - $statushash{$msgstatus}).'

'); + if ($msgstatus eq '') { + $r->print('

'.&mt('Empty Folder').'

'); + } elsif ($msgstatus eq 'replied') { + $r->print('

'.&mt('You have not replied to any messages in this folder.').'

'); + } else { + $r->print('

'.&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.').'

'); + } + if ($numblocked > 0) { + $r->print(&blocked_in_folder($numblocked,$startblock,$endblock, + \%setters)); + } return; } - unless ($interdis) { - $interdis=20; - } + my $interdis = $env{'form.interdis'}; my $number=int($totalnumber/$interdis); - if ($interdis) { - if ($totalnumber%$interdis == 0) { - $number--; - } + if ($totalnumber%$interdis == 0) { + $number--; } if (($startdis<0) || ($startdis>$number)) { $startdis=$number; } @@ -1038,16 +1037,23 @@ ENDDISHEADER } my ($dis_name,$dis_domain) = ($fromname,$fromdomain); if ($folder eq 'sent') { - if (defined($recv_name) && !defined($recv_domain)) { - $dis_name = join('
',@{$recv_name}); - $dis_domain = join('
',@{$recv_domain}); + if (defined($recv_name) && defined($recv_domain)) { + if (ref($recv_name) eq 'ARRAY' && + ref($recv_domain) eq 'ARRAY') { + $dis_name = join('
',@{$recv_name}); + $dis_domain = join('
',@{$recv_domain}); + } } else { my $msg_id = &unescape($origID); my %message = &Apache::lonnet::get('nohist_email'.$suffix, [$msg_id]); my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id}); - $dis_name = join('
',@{$content{'recuser'}}); - $dis_domain = join('
',@{$content{'recdomain'}}); + if (ref($content{'recuser'}) eq 'ARRAY') { + $dis_name = join('
',@{$content{'recuser'}}); + } + if (ref($content{'recdomain'}) eq 'ARRAY') { + $dis_domain = join('
',@{$content{'recdomain'}}); + } } } my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime); @@ -1083,8 +1089,8 @@ ENDDISHEADER $r->print(''."\n". ''); } $r->print('
'. - '
'."\n". - ''."\n". + '
'."\n". + ''."\n". '
 '.&mt('Action').'
'."\n". ' '); if ($numblocked > 0) { - my $beginblock = &Apache::lonlocal::locallocaltime($startblock); - my $finishblock = &Apache::lonlocal::locallocaltime($endblock); - $r->print('

'. - &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock)); - $r->print(&Apache::loncommon::build_block_table($startblock,$endblock, - \%setters)); + $r->print(&blocked_in_folder($numblocked,$startblock,$endblock, + \%setters)); } } +sub blocked_in_folder { + my ($numblocked,$startblock,$endblock,$setters) = @_; + my $beginblock = &Apache::lonlocal::locallocaltime($startblock); + my $finishblock = &Apache::lonlocal::locallocaltime($endblock); + my $output = '

'. + &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock); + $output .= &Apache::loncommon::build_block_table($startblock,$endblock, + $setters); + return $output; +} + # ============================================================== Compose output sub compout { @@ -1935,7 +1948,9 @@ sub displaymessage { &build_block_table($r,$startblock,$endblock,\%setters); 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}); @@ -1974,9 +1989,14 @@ sub displaymessage { '">'.&mt('Next').'
'); + my $symb; + if (defined($content{'symb'})) { + $symb = $content{'symb'}; + } elsif (defined($content{'baseurl'})) { + $symb=&Apache::lonnet::symbread($content{'baseurl'}); + } if ($env{'user.adv'}) { $r->print(''); - my $symb=&Apache::lonnet::symbread($content{'baseurl'}); if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) { $r->print(''); } @@ -1998,6 +2018,18 @@ sub displaymessage { ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') '; } $tolist = join(', ',@recipients); + my ($restitle,$baseurl,$refers_to); + if (defined($content{'resource_title'})) { + $restitle = $content{'resource_title'}; + } else { + if (defined($content{'baseurl'})) { + $restitle = &Apache::lonnet::gettitle($content{'baseurl'}); + } + } + if (defined($content{'baseurl'})) { + $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'}); + } + $r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'})); $r->print('
'.&mt('Subject').': '.$content{'subject'}. ($folder ne 'sent'?'
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( @@ -2008,13 +2040,57 @@ sub displaymessage { $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'}).')':''). - '

'.
+	      '
'.&mt('Time').': '.$content{'time'}); + if ($baseurl) { + if (defined($content{'courseid'}) && defined($env{'request.course.id'})) { + if ($content{'courseid'} eq $env{'request.course.id'}) { + my $symblink; + my $showsymb = &Apache::lonenc::check_decrypt($symb); + my $showurl = &Apache::lonenc::check_decrypt($baseurl); + my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl', + $showsymb,$env{'user.domain'},$env{'user.name'}); + if ($symb) { + if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) { + $showsymb = &Apache::lonenc::check_encrypt($symb); + } + $symblink = '?symb='.$showsymb; + } + if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) { + $showurl = $baseurl; + } + $r->print('
'.&mt('Refers to').': '.$restitle.''); + $refers_to = 1; + } + } + if (!$refers_to) { + if ($baseurl =~ m-^/enc/-) { + if (defined($content{'courseid'})) { + if (!$env{'request.course.id'}) { + my $unencurl = + &Apache::lonenc::unencrypted($baseurl, + $content{'courseid'}); + if ($unencurl ne '') { + if (&Apache::lonnet::allowed('bre',$unencurl)) { + $r->print('
'.&mt('Refers to'). + ': '. + $restitle.''); + } + } + } + } + } else { + if (&Apache::lonnet::allowed('bre',$baseurl)) { + $r->print('
'.&mt('Refers to'). + ': '.$restitle.''); + } + } + } + } + $r->print('

'.
 	      &Apache::lontexconvert::msgtexconverted($content{'message'},1).
 	      '

'.&displayresource(%content).'

'); - return; + return; } # =========================================================== Show the citation @@ -2027,7 +2103,12 @@ sub displayresource { # if (($env{'request.course.id'} eq $content{'courseid'}) && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) { - my $symb=&Apache::lonnet::symbread($content{'baseurl'}); + my $symb; + if (defined($content{'symb'})) { + $symb = $content{'symb'}; + } else { + $symb=&Apache::lonnet::symbread($content{'baseurl'}); + } # Could not get a symb, give up unless ($symb) { return $content{'citation'}; } # Have a symb, can render @@ -2190,7 +2271,7 @@ sub sendoffmail { } } if ($env{'form.additionalrec'}) { - foreach my $rec (split(/\,/,$env{'form.additionalrec'})) { + foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec'})) { my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { $toaddr{$auname.':'.$audom}=''; @@ -2219,11 +2300,9 @@ sub sendoffmail { my $msgtxt = $savemsg; if ($toaddr{$address}) { $msgtxt.='
'.$toaddr{$address}; } my @thismsg; - if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. - '/'.$env{'request.course.sec'}))) { - $r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': '); + if ($msgtype eq 'critical') { + $r->print(&mt('Sending critical message').' '. + $recuname.':'.$recdomain.': '); @thismsg= &Apache::lonmsg::user_crit_msg($recuname,$recdomain, $msgsubj,$msgtxt, @@ -2245,7 +2324,7 @@ sub sendoffmail { $specialmsg_status{$recuname.':'.$recdomain} = join(' ',@thismsg); foreach my $result (@thismsg) { - if ($result eq 'ok') { + if ($result eq 'ok' || $result eq 'con_delayed') { $numspecial++; } } @@ -2277,7 +2356,7 @@ sub sendoffmail { split(/\:/,&unescape($specialmsgid)); foreach my $recipient (sort(keys(%toaddr))) { - if ($specialmsg_status{$recipient} eq 'ok') { + if ($specialmsg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) { my $usersubj = $subj_prefix.'['.$recipient.']'; my $usermsgid = &Apache::lonmsg::buildmsgid($stamp,$usersubj, @@ -2391,10 +2470,6 @@ sub handler { } unless ($startdis) { $startdis=0; } - $interdis=$env{'form.interdis'}; - unless ($interdis) { $interdis=20; } - $sqs.='&interdis='.$interdis; - if ($env{'form.firstview'}) { $startdis=0; } @@ -2643,6 +2718,7 @@ sub handler { my $delresult = &deletefolder($folder); if ($delresult eq 'ok') { $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'
'); + $env{'form.folder'} = ''; } else { $r->print(&mt('Deletion failed.').' '.$delresult.'
'); $showfolder = $folder; @@ -2673,8 +2749,6 @@ sub handler { =pod -=back - =cut 1;
'.&mt('Currently available actions (will open extra window)').':'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'