--- loncom/interface/lonmsgdisplay.pm 2006/12/23 18:27:28 1.58 +++ 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.58 2006/12/23 18:27:28 raeburn 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; @@ -774,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; @@ -789,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); @@ -925,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('There are no '.lc($statushash{$msgstatus}).' messages in this folder.').'

'); } + if ($numblocked > 0) { + $r->print(&blocked_in_folder($numblocked,$startblock,$endblock, + \%setters)); + } return; } my $interdis = $env{'form.interdis'}; @@ -1053,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); @@ -1073,7 +1064,7 @@ ENDDISHEADER ' value="'.$origID.'" />'); foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) { $r->print(''.(($status eq 'new')?'':''). - ''. + ''. $item.(($status eq 'new')?'':'').''); } my $showstatus; @@ -1098,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 { @@ -1950,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}); @@ -1989,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(''); } @@ -2013,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( @@ -2023,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 @@ -2042,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 @@ -2205,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}=''; @@ -2234,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, @@ -2260,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++; } } @@ -2292,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, @@ -2654,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; @@ -2684,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').'