--- loncom/interface/lonmsgdisplay.pm 2006/12/08 20:32:36 1.51 +++ loncom/interface/lonmsgdisplay.pm 2009/11/26 05:21:43 1.139 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.51 2006/12/08 20:32:36 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.139 2009/11/26 05:21:43 faziophi 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; @@ -130,18 +113,18 @@ use lib '/home/httpd/lib/perl/'; use LONCAPA; # Querystring component with sorting type -my $sqs; -my $startdis; -my $interdis; +my $sqs=''; +my $startdis=''; # ============================================================ List all folders sub folderlist { - my $folder=shift; + my ($folder,$msgstatus) = @_; my %lt = &Apache::lonlocal::texthash( actn => 'Action', fold => 'Folder', show => 'Show', + status => 'Message Status', go => 'Go', nnff => 'New Name for Folder', newn => 'New Name', @@ -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', @@ -160,6 +146,10 @@ sub folderlist { ); $actions{'select_form_order'} = ['view','rename','delete']; + my %statushash = &get_msgstatus_types(); + + $statushash{'select_form_order'} = ['','new','read','replied','forwarded']; + my %permfolders = &get_permanent_folders(); my $permlist = join("','",sort(keys(%permfolders))); my ($permlistkeys,$permlistvals); @@ -173,6 +163,7 @@ sub folderlist { my %userfolders; foreach my $key (keys(%gotfolders)) { + $key =~ s/(['"])/\$1/g; #' stupid emacs $userfolders{$key} = $key; } my @userorder = sort(keys(%userfolders)); @@ -180,8 +171,9 @@ sub folderlist { my $folderlist = join("','",@userorder); $folderlist .= "','".$permlistvals; - $formhash{'select_form_order'} = ['','critical','new',@userorder,'sent','trash']; + $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 .= '
@@ -234,26 +231,26 @@ 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).'
'.$lt{'actn'}.'
'. &Apache::loncommon::select_form('view','folderaction',%actions).'

'. - ' + '
     '. - ''. + '

-
'.&mt('New Folder').'
'. +
'.&mt('Name').'
'. '
@@ -261,7 +258,7 @@ function folder_choice(targetform,caller '."\n". ''. ''. - ($folder=~/^(new|critical)/?'
':''); + ($folder=~/^critical/?'':''); return $output; } @@ -269,25 +266,43 @@ sub get_permanent_folders { my %permfolders = &Apache::lonlocal::texthash('' => 'INBOX', 'trash' => 'TRASH', - 'new' => 'New Messages Only', 'critical' => 'Critical', 'sent' => 'Sent Messages', ); return %permfolders; } +sub get_msgstatus_types { + my %statushash = &Apache::lonlocal::texthash( + '' => 'Any', + new => 'Unread', + read => 'Read', + replied => 'Replied to', + forwarded => 'Forwarded', + ); + return %statushash; +} + sub scrollbuttons { - my ($start,$maxdis,$first,$finish,$total)=@_; + my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_; unless ($total>0) { return ''; } $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('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).''; + ''.&mt('Page').': '. + ''. + ''. + ' / '.$maxdis.' '. + ''. + '
'. + &mt('[_1] messages: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).''; } # =============================================================== Status Change @@ -343,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); } @@ -354,18 +369,18 @@ 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',$folder); } my %userfolders = &Apache::lonmsg::get_user_folders(); if (!defined($userfolders{$folder})) { - return &mt('The folder [_1] does not exist so deletion is not required.', + return &mt('The folder "[_1]" does not exist so deletion is not required.', $folder); } # check folder is empty; my $suffix=&Apache::lonmsg::foldersuffix($folder); my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); if (@messages > 0) { - return &mt('The folder [_1] contains messages so it may not be deleted.'). + 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.'); } @@ -380,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); } @@ -489,7 +507,9 @@ sub movemsg { # ======================================================= Display a course list sub discourse { - my $result; + my ($statushash) = @_; + my ($result,$active,$previous,$future); + my $crstype = &Apache::loncommon::course_type(); my ($course_personnel, $current_members, $expired_members, @@ -498,51 +518,108 @@ 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') + ) { + 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", + "expired", + \%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 + .'' + .'
'; + $result .= $tmptext.'

'; + if (ref($statushash) eq 'HASH') { + $statushash->{'previous'} = 1; + } + + } + if ($tmptext = &Apache::lonselstudent::render_student_list($future_members, + "futureusers", + "future", + \%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 .= &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); + $result .= '
' + .$bcc_future_hdr + .'' + .'
'; + $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 => {}, @@ -552,9 +629,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}; @@ -568,75 +645,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| |; } @@ -666,10 +750,16 @@ sub groupmail_header { } &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($refarg) { + my $brtitle; + if (&Apache::loncommon::course_type() eq 'Community') { + $brtitle = 'View community groups'; + } else { + $brtitle = 'View course groups'; + } &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/coursegroups", text=>"Groups", - title=>"View course groups"}); + title=>$brtitle}); } &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg", @@ -678,13 +768,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; @@ -698,7 +788,7 @@ sub groupmail_sent { } my $output .= '

'. - &mt('Send another group email').''.'   '. + &mt('Send another group message').''.'   '. ''. &mt('Return to group page').''; return $output; @@ -708,28 +798,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 '') { @@ -744,10 +865,9 @@ $content{'sendername'}.':'. } sub sortedmessages { - my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_; + 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; @@ -761,10 +881,12 @@ sub sortedmessages { } foreach my $msgid (@messages) { + next if ($msgid eq ''); 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); my $description = &get_course_desc($fromcid,\%descriptions); my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, $esc_msgid,$description); @@ -860,191 +982,154 @@ sub get_course_desc { } } -# ======================================================== Display new messages - - -sub disnew { - my $r=shift; - my %lt=&Apache::lonlocal::texthash( - 'nm' => 'New Messages', - 'su' => 'Subject', - 'co' => 'Course', - 'da' => 'Date', - 'us' => 'Username', - 'op' => 'Open', - 'do' => 'Domain' - ); - my @msgids = sort(&Apache::lonnet::getkeys('nohist_email')); - my @newmsgs; - my %setters = (); - my %blocked = (); - my $numblocked = 0; - # Check for blocking of display because of scheduled online exams. - my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); - my %status_cache = - &Apache::lonnet::get('email_status',\@msgids); - my %descriptions; - foreach my $id (@msgids) { - my $msgid=&escape($id); - my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)= - &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache); - if (defined($sendtime) && $sendtime!~/error/) { - my $description = &get_course_desc($fromcid,\%descriptions); - my $numsendtime = $sendtime; - $sendtime = &Apache::lonlocal::locallocaltime($sendtime); - if ($status eq 'new') { - if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) { - $blocked{$id} = 'ON'; - $numblocked ++; - } else { - push(@newmsgs, { - msgid => $msgid, - sendtime => $sendtime, - shortsub => $shortsubj, - from => $fromname, - fromdom => $fromdom, - course => $description, - }); - } - } - } - } - if ($#newmsgs >= 0) { - $r->print(<$lt{'nm'} - - -TABLEHEAD - foreach my $msg (@newmsgs) { - $r->print(<<"ENDLINK"); - - -ENDLINK - foreach my $item ('sendtime','from','fromdom','shortsub','course') { - $r->print(""); - } - $r->print(""); - } - $r->print('
 $lt{'da'}$lt{'us'}$lt{'do'}$lt{'su'}$lt{'co'}
$lt{'op'}$msg->{$item}
'); - } elsif ($numblocked == 0) { - $r->print("

".&mt('You have no unread messages')."

"); - } - if ($numblocked > 0) { - my $beginblock = &Apache::lonlocal::locallocaltime($startblock); - my $finishblock = &Apache::lonlocal::locallocaltime($endblock); - $r->print('

'.&mt('You have [quant,_1,blocked unread message,blocked unread messages].',$numblocked).'

'."\n". - &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).'
'."\n". - &Apache::loncommon::build_block_table($startblock,$endblock, - \%setters)); - } -} - - # ======================================================== Display all messages sub disall { - my ($r,$folder)=@_; - $r->print(&folderlist($folder)); - if ($folder eq 'new') { - &disnew($r); - } elsif ($folder eq 'critical') { + my ($r,$folder,$msgstatus)=@_; + my %saveable = ('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); } else { - &disfolder($r,$folder); + &disfolder($r,$folder,$msgstatus); } } # ============================================================ Display a folder sub disfolder { - my ($r,$folder)=@_; + my ($r,$folder,$msgstatus)=@_; + my %statushash = &get_msgstatus_types(); my %blocked = (); my %setters = (); my $numblocked = 0; my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); + my %lt = &Apache::lonlocal::texthash( + sede => 'Select a destination folder to which the messages will be moved.', + 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; i ENDDISHEADER - my $fsqs='&folder='.$folder; - my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); + + my $fsqs='&folder='.$folder; + my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus); my $totalnumber=$#temp+1; - unless ($totalnumber>0) { - $r->print('

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

'); + if ($totalnumber < 1) { + 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 ($totalnumber%$interdis == 0) { + $number--; + } + if (($startdis<0) || ($startdis>$number)) { $startdis=$number; } my $firstdis=$interdis*$startdis; if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; } my $lastdis=$firstdis+$interdis-1; if ($lastdis>$#temp) { $lastdis=$#temp; } - $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber)); + $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus)); $r->print(''. - '
 '); + ''); + $r->print(''.&mt('Date').''); } else { - $r->print(''.&mt('Date').''); + $r->print(''.&mt('Date').''); } $r->print(''); + $r->print(''.&mt('Status').''); } else { - $r->print(''.&mt('Status').''); + $r->print(''.&mt('Status').''); } $r->print("\n"); my $suffix = &Apache::lonmsg::foldersuffix($folder); + my $count = $firstdis; 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') { @@ -1056,26 +1141,46 @@ 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'}}); + } } } - $r->print(''. - ''."\n"); + my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime); + $r->print(''); + foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) { + $r->print(''); + } + my $showstatus; + my %statushash = &get_msgstatus_types(); + if ($status eq '') { + $showstatus = ''; + } else { + $showstatus = $statushash{$status}; + } + $r->print(''."\n"); } elsif ($status eq 'deleted') { # purge my ($result,$msg) = @@ -1083,39 +1188,76 @@ ENDDISHEADER } } - $r->print("
 '); if ($env{'form.sortedby'} eq "revdate") { - $r->print(''.&mt('Date').''); if ($env{'form.sortedby'} eq "revuser") { - $r->print(''.&mt('Username').''); + $r->print(''.&mt('Username').''); } else { - $r->print(''.&mt('Username').''); + $r->print(''.&mt('Username').''); } $r->print(''); if ($env{'form.sortedby'} eq "revdomain") { - $r->print(''.&mt('Domain').''); + $r->print(''.&mt('Domain').''); } else { - $r->print(''.&mt('Domain').''); + $r->print(''.&mt('Domain').''); } $r->print(''); if ($env{'form.sortedby'} eq "revsubject") { - $r->print(''.&mt('Subject').''); + $r->print(''.&mt('Subject').''); } else { - $r->print(''.&mt('Subject').''); + $r->print(''.&mt('Subject').''); } $r->print(''); if ($env{'form.sortedby'} eq "revcourse") { - $r->print(''.&mt('Course').''); + $r->print(''.&mt('Course').''); } else { - $r->print(''.&mt('Course').''); + $r->print(''.&mt('Course').''); } $r->print(''); if ($env{'form.sortedby'} eq "revstatus") { - $r->print(''.&mt('Status').'
'.&mt('Open').''. - ($folder ne 'trash'?''.&mt('Delete'):' ').''.&Apache::lonlocal::locallocaltime($sendtime).''. - $dis_name.''.$dis_domain.''. - $shortsubj.''. - $description.''.$status.'
'.(($status eq 'new')?'':''). + $count.'.'.(($status eq 'new')?'':'').' '. + ''.(($status eq 'new')?'':''). + ''. + $item.(($status eq 'new')?'':'').''.(($status eq 'new')?'':'').$description. + (($status eq 'new')?'':'').''. + (($status eq 'new')?'':'').$showstatus. + (($status eq 'new')?'':'').'
\n

". - ''.&mt('Check All').' '. - ''.&mt('Uncheck All').'

'. - ''); + $r->print("
\n"); + $r->print(' + + '."\n". + ''."\n"); + + if (keys(%gotfolders) > 0) { + $r->print(''); + } + $r->print(''."\n". + '
'. + '
'."\n". + ''."\n". + '
 '.&mt('Action').'
'."\n". + '

'); + $r->print(' '."\n"); } - $r->print('

'); - my %gotfolders = &Apache::lonmsg::get_user_folders(); - my %userfolders; - foreach my $key (keys(%gotfolders)) { - $userfolders{$key} = $key; + if ($msgstatus ne 'read') { + $r->print(' ."\n"'); } - $r->print( - &Apache::loncommon::select_form('','movetofolder', - %userfolders)); + if ($msgstatus ne 'unread') { + $r->print(' '."\n"); + } + $r->print(' '."\n"); + + my %gotfolders = &Apache::lonmsg::get_user_folders(); + if (keys(%gotfolders) > 0) { + $r->print(' '); + } + $r->print("\n".'

'.&mt('Destination folder').'
'); + my %userfolders; + foreach my $key (keys(%gotfolders)) { + $userfolders{$key} = $key; + } + $userfolders{''} = ""; + $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders). + '
   '. + '
'); my $postedstartdis=$startdis+1; - $r->print(''); + $r->print(''); 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); + + my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com"); + $output .="

".$blocktext; + + return $output; +} + # ============================================================== Compose output sub compout { - my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_; + my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode, + $multiforward)=@_; my $suffix=&Apache::lonmsg::foldersuffix($folder); my ($cdom,$cnum,$group,$refarg); if (exists($env{'form.group'})) { @@ -1145,6 +1287,21 @@ sub compout { } elsif ($replycrit) { $r->print('

'.&mt('Replying to a Critical Message').'

'); $replying=$replycrit; + } elsif ($multiforward) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/email?folder=".&escape($folder), + text=>"Display All Messages"}); + &printheader($r,'/adm/email?compose=multiforward', + 'Forwarding Multiple Messages'); + 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'); @@ -1154,41 +1311,140 @@ 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', '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 $crstype = &Apache::loncommon::course_type(); my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); + my $rsstxt; + if (&Apache::loncommon::course_type() eq 'Community') { + $rsstxt = &mt('Include in community RSS newsfeed'); + } else { + $rsstxt = &mt('Include in course RSS newsfeed'); + } $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'})) { + + my $rectxt; + if (&Apache::loncommon::course_type() eq 'Community') { + $rectxt = &mt("Include in community's 'User records' for recipient(s)"); + } else { + $rectxt = &mt("Include in course's 'User records' for recipient(s)"); + } + + $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').' '. @@ -1202,7 +1458,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'}; @@ -1212,74 +1468,193 @@ sub compout { if ($content{'baseurl'}) { $disbase=''; if ($env{'user.adv'}) { - $disbase.='