--- loncom/interface/lonmsgdisplay.pm 2007/01/22 21:51:05 1.65 +++ loncom/interface/lonmsgdisplay.pm 2009/07/27 12:12:47 1.131 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.65 2007/01/22 21:51:05 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.131 2009/07/27 12:12:47 kalberla 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; @@ -153,6 +136,9 @@ sub folderlist { ); + # 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', rename => 'Rename Folder', @@ -187,6 +173,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)); @@ -253,16 +241,16 @@ function folder_choice(targetform,caller '.$lt{'actn'}.'
'. &Apache::loncommon::select_form('view','folderaction',%actions).'
'. - ' + '      '. - ''. + '

-
'.&mt('New Folder').'
'. +
'.&mt('Name').'
'. '
@@ -309,11 +297,11 @@ sub scrollbuttons { } return ''.&mt('Page').': '. - ''. - ''. - ' of '.$maxdis. - ''. - '
'. + ''. + ''. + ' / '.$maxdis.' '. + ''. + '
'. &mt('[_1] messages: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).''; } # =============================================================== Status Change @@ -370,7 +358,7 @@ sub makefolder { } } else { $outcome = - &mt('Error - could not obtain lock on email folders record.'); + &mt('Error - could not obtain lock on message folders record.'); } return ($outcome,$warning); } @@ -407,6 +395,9 @@ sub renamefolder { if ($env{'form.renamed'} eq '') { return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname); } + if (defined($permfolders{$folder})) { + return &mt('The folder "[_1]" may not be renamed as it is a folder provided by the system.',$folder); + } if (defined($permfolders{$newname})) { return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is reserved for folders provided automatically by the system.',$folder,$newname); } @@ -516,7 +507,8 @@ sub movemsg { # ======================================================= Display a course list sub discourse { - my $result; + my ($statushash) = @_; + my ($result,$active,$previous,$future); my ($course_personnel, $current_members, $expired_members, @@ -525,51 +517,89 @@ sub discourse { unshift @$current_members, (@$course_personnel); my %defaultUsers; - $result .= ''."\n"; + my $tmptext; + if ($tmptext = &Apache::lonselstudent::render_student_list($current_members, + "activeusers", + "current", + \%defaultUsers, + 1,"selectedusers",1,'email') + ) { + $result .= '
' + .&mt('Bcc: course members with current access') + .'' + .'
'; + $result .= $tmptext.'

'; + if (ref($statushash) eq 'HASH') { + $statushash->{'active'} = 1; + } + } + if ($tmptext = &Apache::lonselstudent::render_student_list($expired_members, + "previoususers", + "expired", + \%defaultUsers, + 1, "selectedusers",0,'email') + ) { + $result .= '
' + .&mt('Bcc: course members with expired access') + .'' + .'
'; + $result .= $tmptext.'

'; + if (ref($statushash) eq 'HASH') { + $statushash->{'previous'} = 1; + } - $result .= &Apache::lonselstudent::render_student_list($current_members, - "compemail", - "current", - \%defaultUsers, - 1,"selectedusers",1); - - $result .= &Apache::lonselstudent::render_student_list($expired_members, - "compemail", - "expired", - \%defaultUsers, - 1, "selectedusers",0); - $result .= &Apache::lonselstudent::render_student_list($future_members, - "compemail", - "future", - \%defaultUsers, - 1, "selectedusers", 0); + } + if ($tmptext = &Apache::lonselstudent::render_student_list($future_members, + "futureusers", + "future", + \%defaultUsers, + 1, "selectedusers",0,'email') + ) { + $result .= '
' + .&mt('Bcc: course members with future access') + .'' + .'
'; + $result .= $tmptext.'
'; + if (ref($statushash) eq 'HASH') { + $statushash->{'future'} = 1; + } + + } return $result; } sub disgroup { - my ($cdom,$cnum,$group,$viewgrps,$editgrps) = @_; - my $result; + my ($r,$cdom,$cnum,$group,$access_status) = @_; + my $hasfloat; # Needs to be in a course if (!($env{'request.course.fn'})) { - $result = &mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.'); - return $result; + $r->print(''.&mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.').''); + return; } if ($cdom eq '' || $cnum eq '') { - $result = &mt('Error: could not determine domain or number of course'); - return $result; + $r->print(''.&mt('Error: could not determine domain or number of course').''); + return; } my ($memberinfo,$numitems) = &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]); my @statustypes = ('active'); + my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); + my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); if ($viewgrps || $editgrps) { push(@statustypes,('future','previous')); } if (keys(%{$memberinfo}) == 0) { - $result = &mt('As this group has no members, there are no '. - 'recipients to select.'); - return $result; + $r->print(''. + &mt('As this group has no members, there are no recipients to select'). + ''); + return; } else { - $result = &mt('Select message recipients from the group members listed below.
'); + $hasfloat = 1; + unless($env{'environment.wysiwygeditor'} eq 'on') { + $r->print('
'); + } my %Sortby = ( active => {}, previous => {}, @@ -579,9 +609,9 @@ sub disgroup { 'name' => 'Name', 'usnm' => 'Username', 'doma' => 'Domain', - 'active' => 'Active Members', - 'previous' => 'Former Members', - 'future' => 'Future Members', + 'active' => 'Broadcast to Active Members', + 'previous' => 'Broadcast (Bcc) to Former Members', + 'future' => 'Broadcast (Bcc) to Future Members', ); foreach my $user (sort(keys(%{$memberinfo}))) { my $status = $$memberinfo{$user}{status}; @@ -595,75 +625,82 @@ sub disgroup { push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user); } } - $result .= &group_check_uncheck(); - $result .= ''. - ''; + $r->print(&group_check_uncheck()); foreach my $status (@statustypes) { if (ref($numitems) eq 'HASH') { if ((defined($$numitems{$status})) && ($$numitems{$status})) { - $result.='". - "". - "". - &Apache::loncommon::end_data_table_header_row(); + my $formname = $status.'users'; + if (ref($access_status) eq 'HASH') { + $access_status->{$status} = $$numitems{$status}; + } + $r->print('
'. + ''.$lt{$status}.''. + '
'. + ''. + ''. + '  '. + ''. + ''); + if ($status eq 'active') { + $r->print((' 'x3).''); + } + $r->print('
'.&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + "
". + "". + "". + &Apache::loncommon::end_data_table_header_row()); foreach my $key (sort(keys(%{$Sortby{$status}}))) { foreach my $user (@{$Sortby{$status}{$key}}) { - $result .= - &Apache::loncommon::start_data_table_row(). - ''. + $$memberinfo{$user}{'fullname'}.''. ''. ''. - &Apache::loncommon::end_data_table_row(); + &Apache::loncommon::end_data_table_row()); } } - $result .= &Apache::loncommon::end_data_table(); + $r->print(&Apache::loncommon::end_data_table().''. + '
'); } } - $result .= ''; } - $result .= '
'. - '
'.$lt{$status}. - ''. - ''. - '  '. - ''. - '

'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(); - $result .= "
$lt{'name'}$lt{'usnm'}$lt{'doma'}$lt{'name'}$lt{'usnm'}$lt{'doma'}print(&Apache::loncommon::start_data_table_row(). + ''. - $$memberinfo{$user}{'fullname'}.''.$$memberinfo{$user}{'uname'}.''.$$memberinfo{$user}{'udom'}.'  
'; + unless($env{'environment.wysiwygeditor'} eq 'on') { + $r->print('
'); + } } - return $result; + return $hasfloat; } sub group_check_uncheck { my $output = qq| |; } @@ -705,13 +742,13 @@ sub groupmail_header { {href=>"/adm/email?compose=group&group=". "$env{'form.group'}&$refarg", text=>"Send a Message in a Group", - title=>"Compose Group Email Message"},); + title=>"Compose Group Message"},); if ($action eq 'sending') { &Apache::lonhtmlcommon::add_breadcrumb ({text=>"Messages being sent.", - title=>"Messages sent"},); + title=>"E-mails sent"},); } - my $groupheader = &Apache::loncommon::start_page('Group Email'); + my $groupheader = &Apache::loncommon::start_page('Group Message'); $groupheader .= &Apache::lonhtmlcommon::breadcrumbs ('Group - '.$env{'form.group'}.' Email'); return $groupheader; @@ -725,7 +762,7 @@ sub groupmail_sent { } my $output .= '

'. - &mt('Send another group email').''.'   '. + &mt('Send another group message').''.'   '. ''. &mt('Return to group page').''; return $output; @@ -735,28 +772,59 @@ sub groupmail_sent { sub discrit { my $r=shift; - my $header = '

'.&mt('Critical Messages').'

'. - '
'. - ''; + my $header = '

'.&mt('Critical Messages').'

' + .'
' + .&mt('Access to other pages will be prevented until you have moved all critical messages to your inbox.') + .'

' + .'' + .''; my %what=&Apache::lonnet::dump('critical'); my $result = ''; foreach my $key (sort(keys(%what))) { my %content=&Apache::lonmsg::unpackagemsg($what{$key}); next if ($content{'senderdomain'} eq ''); - $result.='
'.&mt('From').': '. -&Apache::loncommon::aboutmewrapper( - &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. -$content{'sendername'}.':'. - $content{'senderdomain'}.') '.$content{'time'}. - '
'.&mt('Subject').': '.$content{'subject'}. - '
'.
-              &Apache::lontexconvert::msgtexconverted($content{'message'}).
-            '
'. -&mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox'). - '
'. - ''. - ''; + $result .= &Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('From'),undef,'LC_oddrow_value') + .''.&Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'' + .' ('.$content{'sendername'}.':'.$content{'senderdomain'}.')' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::row_title(&mt('Date'),undef,'LC_evenrow_value') + .$content{'time'} + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::row_title(&mt('Subject'),undef,'LC_oddrow_value') + .$content{'subject'} + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value') + .'
'.&Apache::lontexconvert::msgtexconverted($content{'message'}).'
' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title('',undef,'LC_oddrow_value') + .'
'; + my ($rec_button,$reprec_button); + $rec_button = &mt('Move to Inbox'); + if (!$content{'noreplies'}) { + $reprec_button = &mt('Move to Inbox/Compose reply'); + } + if ($content{'sendback'}) { + $rec_button = &mt('Confirm Receipt'); + if (!$content{'noreplies'}) { + $reprec_button = &mt('Confirm Receipt and Reply'); + } + $result .= &mt('You have to confirm that you have received this message before you can view other pages. After confirmation, this message will be moved to your regular inbox'); + } else { + $result .= &mt('Access to other pages will be prevented until you have moved the message to your inbox.'); + } + $result .= '
' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::row_title('',undef,'LC_evenrow_value') + .''; + if (!$content{'noreplies'}) { + $result .= '' + } + $result .= &Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + .'
'; } # Check to see if there were any messages. if ($result eq '') { @@ -787,6 +855,7 @@ sub sortedmessages { } foreach my $msgid (@messages) { + next if ($msgid eq ''); my $esc_msgid=&escape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) = &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef, @@ -891,8 +960,7 @@ sub get_course_desc { sub disall { my ($r,$folder,$msgstatus)=@_; - my %saveable = ('folder' => 'scalar', - 'msgstatus' => 'scalar', + my %saveable = ('msgstatus' => 'scalar', 'sortedby' => 'scalar', 'interdis' => 'scalar', ); @@ -927,18 +995,9 @@ sub disfolder { my $jscript = &Apache::loncommon::check_uncheck_jscript(); $r->print(< +// ENDDISHEADER - my $fsqs='&folder='.$folder; + my $fsqs='&folder='.$folder; my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus); my $totalnumber=$#temp+1; if ($totalnumber < 1) { @@ -1038,11 +1097,13 @@ ENDDISHEADER $r->print("\n"); my $suffix = &Apache::lonmsg::foldersuffix($folder); + my $count = 0; for (my $n=$firstdis;$n<=$lastdis;$n++) { my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID, $description,$recv_name,$recv_domain)= @{$temp[$n]}; if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) { + $count ++; if ($status eq 'new') { $r->print(''); } elsif ($status eq 'read') { @@ -1054,28 +1115,34 @@ 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); - my $count = $n +1; - $r->print(''.(($status eq 'new')?'':''). + $r->print(''.(($status eq 'new')?'':''). $count.'.'.(($status eq 'new')?'':'').' '. ''); + ' value="'.$origID.'" />'); foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) { $r->print(''.(($status eq 'new')?'':''). ''. - $item.(($status eq 'new')?'':'').''); + $item.(($status eq 'new')?'':'').''); } my $showstatus; my %statushash = &get_msgstatus_types(); @@ -1103,7 +1170,7 @@ ENDDISHEADER ''."\n". ' '."\n". ''.&mt('Action').'
'."\n". - ' '."\n"); if ($folder ne 'trash') { $r->print(' '."\n"); @@ -1138,7 +1205,7 @@ ENDDISHEADER '" onclick="javascript:validate_checkedaction()"/>'."\n". ''); my $postedstartdis=$startdis+1; - $r->print(''); + $r->print(''); if ($numblocked > 0) { $r->print(&blocked_in_folder($numblocked,$startblock,$endblock, \%setters)); @@ -1151,8 +1218,12 @@ sub blocked_in_folder { 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); + #$output .= &Apache::loncommon::build_block_table($startblock,$endblock, + # $setters); + + my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com"); + $output .="

".$blocktext; + return $output; } @@ -1196,7 +1267,14 @@ sub compout { text=>"Display All Messages"}); &printheader($r,'/adm/email?compose=multiforward', 'Forwarding Multiple Messages'); - $r->print(&mt('Each of the [quant,_1,message] you checked will be forwarded to the recipient(s) you select below.',$multiforward).'
'); + if ($multiforward > 1) { + $r->print(&mt('Each of the [quant,_1,message] you checked' + .' will be forwarded to the recipient(s) you select below.',$multiforward) + .'
'); + } else { + $r->print(&mt('The message you checked will be forwarded to the recipient(s) you select below.').'
'); + } + } else { &printheader($r,'/adm/email?compose=upload', 'Distribute from Uploaded File'); @@ -1206,42 +1284,126 @@ sub compout { my $dissub=''; my $dismsg=''; my $disbase=''; - my $func=&mt('Send New'); + my $attachrow; + my $func1='Send'; # do not translate here! + my %func2=( # do not translate here! + 'ma' => 'Message', + 'msg' => 'Messages', + ); my %lt=&Apache::lonlocal::texthash('us' => 'Username', 'do' => 'Domain', 'ad' => 'Additional Recipients', + 'rt' => 'Reply to', + 'ar' => 'Allow replies', 'sb' => 'Subject', 'ca' => 'Cancel', - 'ma' => 'Mail', - 'msg' => 'Messages', 'gen' => 'Generate messages from a file', 'gmt' => 'General message text', 'tff' => 'The file format for the uploaded portion of the message is', 'uas' => 'Upload and Send', + 'atta' => 'Attachment', + 'to' => 'To:', ); + my %attachmax = ( + text => &mt('(128 KB max size)'), + num => 131072, + ); + if (!$forwarding && !$multiforward) { + $attachrow = ''.$lt{'atta'}.' '.$attachmax{'text'}.': '; + } if (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); $dispcrit= - '

' . $crithelp . - '

'. - '' . $crithelp . - '

'. -'

'; - } + ''.$crithelp.'  '.&mt('Require return receipt?').'  
'. + '
'. +'
'; + } + if ($broadcast ne 'group') { + if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) || + &Apache::lonnet::allowed('dff',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})) { + + $dispcrit.='
'; + } + } + my %message; my %content; + my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast); my $defdom=$env{'user.domain'}; + if ($broadcast eq 'group') { + my %access_status = ( + active => 0, + previous => 0, + future => 0, + ); + + if ($group eq '') { + my $studentsel = &discourse(\%access_status); + if ($studentsel) { + if ($env{'environment.wysiwygeditor'} eq 'on') { + $r->print($studentsel); + } else { + $r->print('
'.$studentsel.'
'); + } + $hasfloat = 1; + } + } else { + $can_grp_broadcast = &check_group_priv($group); + if ($can_grp_broadcast) { + $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status); + } + } + if ($hasfloat) { + $sendmode = ''."\n"; + $broadcast_js = qq| + + +|; + } + } if ($forwarding) { %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]); %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder); $dispcrit.=''; - $func=&mt('Forward'); + $func1='Forward'; # do not translate here! $dissub=&mt('Forwarding').': '.$content{'subject'}; $dismsg=&mt('Forwarded message from').' '. @@ -1255,7 +1417,7 @@ sub compout { %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder); $dispcrit.=''; - $func=&mt('Send Reply to'); + $func1='Send Reply to'; # do not translate here! $dissub=&mt('Reply').': '.$content{'subject'}; $dismsg='> '.$content{'message'}; @@ -1265,56 +1427,142 @@ sub compout { if ($content{'baseurl'}) { $disbase=''; if ($env{'user.adv'}) { - $disbase.='