--- loncom/interface/lonmsgdisplay.pm 2006/05/17 09:46:01 1.25 +++ loncom/interface/lonmsgdisplay.pm 2006/12/08 14:43:38 1.50 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.25 2006/05/17 09:46:01 foxr Exp $ +# $Id: lonmsgdisplay.pm,v 1.50 2006/12/08 14:43:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,7 +28,6 @@ package Apache::lonmsgdisplay; -use Apache::lonselstudent; =pod @@ -75,8 +74,8 @@ email program, so they have full access interface, or other features they may wish to use in response to the student's query. -=item * B: LON-CAPA can block display of e-mails that are -sent to a student during an online exam. A course coordinator or +=item * B: LON-CAPA can block selected communication +features for students during an online exam. A course coordinator or instructor can set an open and close date/time for scheduled online exams in a course. If a user uses the LON-CAPA internal messaging system to display e-mails during the scheduled blocking event, @@ -126,6 +125,9 @@ use Apache::lonlocal; use Apache::loncommunicate; use Apache::lonfeedback; use Apache::lonrss(); +use Apache::lonselstudent(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; # Querystring component with sorting type my $sqs; @@ -136,24 +138,142 @@ my $interdis; sub folderlist { my $folder=shift; - my @allfolders=&Apache::lonnet::getkeys('email_folders'); - if ($allfolders[0]=~/^error:/) { @allfolders=(); } - return '
'. - &mt('Folder').': '. - &Apache::loncommon::select_form($folder,'folder', - ('' => &mt('INBOX'),'trash' => &mt('TRASH'), - 'new' => &mt('New Messages Only'), - 'critical' => &mt('Critical'), - 'sent' => &mt('Sent Messages'), - map { $_ => $_ } @allfolders)). - ' '.&mt('Show'). - ''. - '
'. + my %lt = &Apache::lonlocal::texthash( + actn => 'Action', + fold => 'Folder', + show => 'Show', + go => 'Go', + 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', + + ); + + my %actions = &Apache::lonlocal::texthash( + view => 'View Folder', + rename => 'Rename Folder', + delete => 'Delete Folder', + ); + $actions{'select_form_order'} = ['view','rename','delete']; + + my %permfolders = &get_permanent_folders(); + my $permlist = join("','",sort(keys(%permfolders))); + my ($permlistkeys,$permlistvals); + foreach my $key (sort(keys(%permfolders))) { + $permlistvals .= $permfolders{$key}."','"; + $permlistkeys .= $key."','"; + } + $permlistvals =~ s/','$//; + $permlistkeys =~ s/','$//; + my %gotfolders = &Apache::lonmsg::get_user_folders(); + my %userfolders; + + foreach my $key (keys(%gotfolders)) { + $userfolders{$key} = $key; + } + my @userorder = sort(keys(%userfolders)); + my %formhash = (%permfolders,%userfolders); + my $folderlist = join("','",@userorder); + $folderlist .= "','".$permlistvals; + + $formhash{'select_form_order'} = ['','critical','new',@userorder,'sent','trash']; + my $output = qq||; + $output .= ' + + + + + + +
+ + + + + + +
'.$lt{'fold'}.'
'."\n". + &Apache::loncommon::select_form($folder,'folder',%formhash).' +
'.$lt{'show'}.'
+ +
'.$lt{'actn'}.'
'. + &Apache::loncommon::select_form('view','folderaction',%actions).' +

'. + ' +
+
     + '. + '

+
'.&mt('New Folder').'
'. + ' +
+
'."\n". ''. - ($folder=~/^(new|critical)/?'
':''); + ''. + ($folder=~/^(new|critical)/?'':''); + return $output; +} + +sub get_permanent_folders { + my %permfolders = + &Apache::lonlocal::texthash('' => 'INBOX', + 'trash' => 'TRASH', + 'new' => 'New Messages Only', + 'critical' => 'Critical', + 'sent' => 'Sent Messages', + ); + return %permfolders; } sub scrollbuttons { @@ -193,14 +313,123 @@ sub statuschange { # ============================================================= Make new folder sub makefolder { - my ($newfolder)=@_; - if (($newfolder eq 'sent') - || ($newfolder eq 'critical') - || ($newfolder eq 'trash') - || ($newfolder eq 'new')) { return; } - &Apache::lonnet::put('email_folders',{$newfolder => time}); + my ($newfolder) = @_; + my %permfolders = &get_permanent_folders(); + my %userfolders = &Apache::lonmsg::get_user_folders(); + my ($outcome,$warning); + if (defined($userfolders{$newfolder})) { + return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder); + } + foreach my $perm (keys(%permfolders)) { + if ($permfolders{$perm} eq $newfolder) { + return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder); + } + } + if (&get_msgfolder_lock() eq 'ok') { + my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']); + my $lastcount = $counter_hash{"\0".'idcount'}; + my $folder_id = $lastcount + 1; + while (defined($userfolders{$folder_id})) { + $folder_id ++; + } + my %folderinfo = ( id => $folder_id, + created => time, ); + $outcome = + &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo, + "\0".'idcount' => $folder_id}); + my $releaseresult = &release_msgfolder_lock(); + if ($releaseresult ne 'ok') { + $warning = $releaseresult; + } + } else { + $outcome = + &mt('Error - could not obtain lock on email folders record.'); + } + return ($outcome,$warning); } +# ============================================================= Delete folder + +sub deletefolder { + my ($folder)=@_; + my %permfolders = &get_permanent_folders(); + if (defined($permfolders{$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.', + $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.'). + '
'. + &mt('Delete or move the messages to a different folder first.'); + } + my $delresult = &Apache::lonnet::del('email_folders',[$folder]); + return $delresult; +} + +sub renamefolder { + my ($folder) = @_; + my $newname = $env{'form.renamed'}; + my %permfolders = &get_permanent_folders(); + 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{$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); + } + my %userfolders = &Apache::lonmsg::get_user_folders(); + if (defined($userfolders{$newname})) { + return &mt('The folder "[_1]" may not be renamed to "[_2]" because the new name you requested is already being used for an existing folder.',$folder,$newname); + } + if (!defined($userfolders{$folder})) { + return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname); + } + my %folderinfo; + if (ref($userfolders{$folder}) eq 'HASH') { + %folderinfo = %{$userfolders{$folder}}; + } else { + %folderinfo = ( id => $folder, + created => $userfolders{$folder},); + } + my $outcome = + &Apache::lonnet::put('email_folders',{$newname => \%folderinfo}); + if ($outcome eq 'ok') { + $outcome = &Apache::lonnet::del('email_folders',[$folder]); + } + return $outcome; +} + +sub get_msgfolder_lock { + # get lock for mail folder counter. + my $lockhash = { "\0".'lock_counter' => time, }; + my $tries = 0; + my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash); + while (($gotlock ne 'ok') && $tries <3) { + $tries ++; + sleep(1); + $gotlock = &Apache::lonnet::newput('email_folders',$lockhash); + } + return $gotlock; +} + +sub release_msgfolder_lock { + # remove lock + my @del_lock = ("\0".'lock_counter'); + my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock); + if ($dellockoutcome ne 'ok') { + return ('
'.&mt('Warning: failed to release lock for counter').'
'); + } else { + return 'ok'; + } +} + + # ======================================================== Move between folders sub movemsg { @@ -215,7 +444,7 @@ sub movemsg { # Copy message my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]); if (!exists($message{$msgid}) || $message{$msgid} eq '') { - if (&Apache::slotrequest::network_error(%message)) { + if (&Apache::lonnet::error(%message)) { return (0,&mt('Message not moved, A network error occurred.')); } else { return (0,&mt('Message not moved as the message is no longer in the source folder.')); @@ -224,7 +453,7 @@ sub movemsg { my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix, {$msgid => $message{$msgid}}); - if (&Apache::slotrequest::network_error($result)) { + if (&Apache::lonnet::error($result)) { return (0,&mt('Message not moved, A network error occurred.')); } @@ -232,12 +461,12 @@ sub movemsg { unless ($trgfolder eq 'trash') { my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]); # a non-existant status is the mark of an unread msg - if (&Apache::slotrequest::network_error(%status)) { + if (&Apache::lonnet::error(%status)) { return (0,&mt('Message copied to new folder but status was not, A network error occurred.')); } my $result=&Apache::lonnet::put('email_status'.$trgsuffix, {$msgid => $status{$msgid}}); - if (&Apache::slotrequest::network_error($result)) { + if (&Apache::lonnet::error($result)) { return (0,&mt('Message copied to new folder but status was not, A network error occurred.')); } } @@ -247,10 +476,10 @@ sub movemsg { &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]); my $result_del_stat = &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]); - if (&Apache::slotrequest::network_error($result_del_msg)) { + if (&Apache::lonnet::error($result_del_msg)) { return (0,&mt('Message copied, but unable to delete the original from the source folder.')); } - if (&Apache::slotrequest::network_error($result_del_stat)) { + if (&Apache::lonnet::error($result_del_stat)) { return (0,&mt('Message copied, but unable to delete the original status from the source folder.')); } @@ -264,148 +493,215 @@ sub discourse { my ($course_personnel, $current_members, $expired_members, - $future_members) = &Apache::lonselstudent::get_people_in_class(); + $future_members) = + &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'}); unshift @$current_members, (@$course_personnel); my %defaultUsers; + + $result .= ''."\n"; - $result = &Apache::lonselstudent::render_student_list($current_members, - "compemail", - "current", - \%defaultUsers, - 1,"selectedusers",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); return $result; } -# --------------------------------- No longer needed ..old display course list. -sub discourse_obsolete { - my $r=shift; - my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist(); - my ($classgroups,$studentgroups) = - &Apache::loncoursedata::get_group_memberships($classlist,$keylist); - my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All', - 'cfs' => 'Check Section/Group', - 'cfn' => 'Uncheck All'); - if (defined($env{'form.group'})) { - $r->print(''."\n"); - } - $r->print(< - -  - -  - -

-ENDDISHEADER - my %coursepersonnel=&Apache::lonnet::get_course_adv_roles(); - $r->print(&Apache::loncommon::start_data_table()); - if (keys(%coursepersonnel) > 0) { - $r->print('

Non-students

'); - $r->print(&Apache::loncommon::start_data_table()); - $r->print('NameUsername:DomainRole'); - foreach my $role (sort(keys(%coursepersonnel))) { - foreach my $user (split(/\,/,$coursepersonnel{$role})) { - my ($puname,$pudom)=split(/\:/,$user); - $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(''. - '('.$user.'),'.$role.''); - $r->print(&Apache::loncommon::end_data_table_row()); + } else { + for (var i=0; iprint(&Apache::loncommon::end_data_table()); } - if (keys(%{$classlist}) > 0) { - $r->print('

Students

'); - $r->print(&Apache::loncommon::start_data_table()); - $r->print('NameUsername:DomainSectionGroups'); - my $sort = sub { - my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]); - if (!$aname) { $aname=$a; } - my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]); - if (!$bname) { $bname=$b; } - return $aname cmp $bname; - }; - foreach my $student (sort $sort (keys(%{$classlist}))) { - my $info=$classlist->{$student}; - my ($sname,$sdom,$status,$fullname,$section) = - (@{$info}[&Apache::loncoursedata::CL_SNAME(), - &Apache::loncoursedata::CL_SDOM(), - &Apache::loncoursedata::CL_STATUS(), - &Apache::loncoursedata::CL_FULLNAME(), - &Apache::loncoursedata::CL_SECTION()]); - next if ($status ne 'Active'); - next if ($env{'request.course.sec'} && - $section ne $env{'request.course.sec'}); - my @studentsgroups = - &Apache::loncoursedata::get_students_groups($student,$status, - $classgroups); - my $grouplist = join(', ',@studentsgroups); - my $key = 'send_to_&&&'.$section.'&&&_'.$student; - if (! defined($fullname) || $fullname eq '') {$fullname = $sname;} - my $checked = ''; - my $groupcount = 0; - my $groupitems; - $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(''.$groupitems. - ''.$sname.':'.$sdom.''.$section. - ''.$grouplist.''); - $r->print(&Apache::loncommon::end_data_table_row()); +} + + |; +} + +sub groupmail_header { + my ($action,$group,$cdom,$cnum) = @_; + my ($description,$refarg); + if (!$cdom || !$cnum) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + if (exists($env{'form.ref'})) { + $refarg = 'ref='.$env{'form.ref'}; + } + if (!$group) { + $group = $env{'form.group'}; + } + if ($group eq '') { + return ''; + } else { + my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group); + if (defined($curr_groups{$group})) { + my %groupinfo = + &Apache::longroup::get_group_settings($curr_groups{$group}); + $description = &unescape($groupinfo{'description'}); } - $r->print(&Apache::loncommon::end_data_table()); } + &Apache::lonhtmlcommon::clear_breadcrumbs(); + if ($refarg) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/coursegroups", + text=>"Groups", + title=>"View course groups"}); + } + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg", + text=>"Group: $description", + title=>"Go to group's home page"}, + {href=>"/adm/email?compose=group&group=". + "$env{'form.group'}&$refarg", + text=>"Send a Message in a Group", + title=>"Compose Group Email Message"},); + if ($action eq 'sending') { + &Apache::lonhtmlcommon::add_breadcrumb + ({text=>"Messages being sent.", + title=>"Messages sent"},); + } + my $groupheader = &Apache::loncommon::start_page('Group Email'); + $groupheader .= &Apache::lonhtmlcommon::breadcrumbs + ('Group - '.$env{'form.group'}.' Email'); + return $groupheader; +} + +sub groupmail_sent { + my ($group,$cdom,$cnum) = @_; + my $refarg; + if (exists($env{'form.ref'})) { + $refarg = 'ref='.$env{'form.ref'}; + } + my $output .= '

'. + &mt('Send another group email').''.'   '. + ''. &mt('Return to group page').''; + return $output; } # ==================================================== Display Critical Message @@ -417,8 +713,8 @@ sub discrit { ''; my %what=&Apache::lonnet::dump('critical'); my $result = ''; - foreach (sort keys %what) { - my %content=&Apache::lonmsg::unpackagemsg($what{$_}); + foreach my $key (sort(keys(%what))) { + my %content=&Apache::lonmsg::unpackagemsg($what{$key}); next if ($content{'senderdomain'} eq ''); $result.='
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( @@ -431,8 +727,8 @@ $content{'sendername'}.':'. ''. &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox'). '
'. - ''. - ''. + ''; } # Check to see if there were any messages. @@ -451,6 +747,7 @@ sub sortedmessages { my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_; 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; @@ -464,7 +761,7 @@ sub sortedmessages { } foreach my $msgid (@messages) { - my $esc_msgid=&Apache::lonnet::escape($msgid); + my $esc_msgid=&escape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)= &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef, \%status_cache); @@ -554,7 +851,7 @@ sub get_course_desc { if (defined($env{'course.'.$fromcid.'.description'})) { $description = $env{'course.'.$fromcid.'.description'}; } else { - my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'}; + my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'}; } $$descriptions{$fromcid} = $description; @@ -580,17 +877,15 @@ sub disnew { my @msgids = sort(&Apache::lonnet::getkeys('nohist_email')); my @newmsgs; my %setters = (); - my $startblock = 0; - my $endblock = 0; my %blocked = (); my $numblocked = 0; # Check for blocking of display because of scheduled online exams. - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); my %status_cache = &Apache::lonnet::get('email_status',\@msgids); my %descriptions; - foreach (@msgids) { - my $msgid=&Apache::lonnet::escape($_); + 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/) { @@ -599,17 +894,17 @@ sub disnew { $sendtime = &Apache::lonlocal::locallocaltime($sendtime); if ($status eq 'new') { if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) { - $blocked{$_} = 'ON'; + $blocked{$id} = 'ON'; $numblocked ++; } else { - push @newmsgs, { + push(@newmsgs, { msgid => $msgid, sendtime => $sendtime, shortsub => $shortsubj, from => $fromname, fromdom => $fromdom, - course => $description - } + course => $description, + }); } } } @@ -617,18 +912,18 @@ sub disnew { if ($#newmsgs >= 0) { $r->print(<$lt{'nm'} - +
 
TABLEHEAD foreach my $msg (@newmsgs) { $r->print(<<"ENDLINK"); - + ENDLINK - foreach ('sendtime','from','fromdom','shortsub','course') { - $r->print(""); + foreach my $item ('sendtime','from','fromdom','shortsub','course') { + $r->print(""); } - $r->print(""); + $r->print(""); } $r->print('
  $lt{'da'}$lt{'us'}$lt{'do'}$lt{'su'}$lt{'co'}
$lt{'op'}$lt{'op'}$msg->{$_}$msg->{$item}
'); } elsif ($numblocked == 0) { @@ -637,16 +932,10 @@ ENDLINK if ($numblocked > 0) { my $beginblock = &Apache::lonlocal::locallocaltime($startblock); my $finishblock = &Apache::lonlocal::locallocaltime($endblock); - if ($numblocked == 1) { - $r->print("

".&mt('You have').' '.$numblocked.' '.&mt('blocked unread message').".

"); - $r->print(&mt('This message is not viewable because').' '); - } else { - $r->print("

".&mt('You have').' '.$numblocked.' '.&mt('blocked unread messages').".

"); - $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because ')); - } - $r->print( -&mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.'); - &build_block_table($r,$startblock,$endblock,\%setters); + $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)); } } @@ -671,10 +960,8 @@ sub disfolder { my ($r,$folder)=@_; my %blocked = (); my %setters = (); - my $startblock; - my $endblock; my $numblocked = 0; - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); $r->print(< function checkall() { @@ -689,7 +976,7 @@ sub disfolder { function uncheckall() { for (i=0; i ENDDISHEADER my $fsqs='&folder='.$folder; - my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); + my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); my $totalnumber=$#temp+1; unless ($totalnumber>0) { $r->print('

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

'); @@ -714,7 +1001,7 @@ ENDDISHEADER if ($lastdis>$#temp) { $lastdis=$#temp; } $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber)); $r->print('
'. - '
 '); + ''); } else { @@ -773,7 +1060,7 @@ ENDDISHEADER $dis_name = join('
',@{$recv_name}); $dis_domain = join('
',@{$recv_domain}); } else { - my $msg_id = &Apache::lonnet::unescape($origID); + my $msg_id = &unescape($origID); my %message = &Apache::lonnet::get('nohist_email'.$suffix, [$msg_id]); my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id}); @@ -792,7 +1079,7 @@ ENDDISHEADER } elsif ($status eq 'deleted') { # purge my ($result,$msg) = - &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash'); + &movemsg(&unescape($origID),$folder,'trash'); } } @@ -805,20 +1092,23 @@ ENDDISHEADER '

'); } $r->print('

'); - my @allfolders=&Apache::lonnet::getkeys('email_folders'); - if ($allfolders[0]=~/^error:/) { @allfolders=(); } + my %gotfolders = &Apache::lonmsg::get_user_folders(); + my %userfolders; + foreach my $key (keys(%gotfolders)) { + $userfolders{$key} = $key; + } $r->print( &Apache::loncommon::select_form('','movetofolder', - ( map { $_ => $_ } @allfolders)) - ); + %userfolders)); my $postedstartdis=$startdis+1; $r->print(''); if ($numblocked > 0) { my $beginblock = &Apache::lonlocal::locallocaltime($startblock); my $finishblock = &Apache::lonlocal::locallocaltime($endblock); $r->print('

'. - $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.')); - &build_block_table($r,$startblock,$endblock,\%setters); + &mt('[_1,quant,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)); } } @@ -827,8 +1117,14 @@ ENDDISHEADER sub compout { my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_; my $suffix=&Apache::lonmsg::foldersuffix($folder); - - if ($broadcast eq 'individual') { + my ($cdom,$cnum,$group,$refarg); + if (exists($env{'form.group'})) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $group = $env{'form.group'}; + my $action = 'composing'; + $r->print(&groupmail_header($action,$group,$cdom,$cnum)); + } elsif ($broadcast eq 'individual') { &printheader($r,'/adm/email?compose=individual', 'Send a Message'); } elsif ($broadcast) { @@ -836,15 +1132,15 @@ sub compout { 'Broadcast Message'); } elsif ($forwarding) { &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/email?display=".&Apache::lonnet::escape($forwarding), + ({href=>"/adm/email?display=".&escape($forwarding), text=>"Display Message"}); - &printheader($r,'/adm/email?forward='.&Apache::lonnet::escape($forwarding), + &printheader($r,'/adm/email?forward='.&escape($forwarding), 'Forwarding a Message'); } elsif ($replying) { &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/email?display=".&Apache::lonnet::escape($replying), + ({href=>"/adm/email?display=".&escape($replying), text=>"Display Message"}); - &printheader($r,'/adm/email?replyto='.&Apache::lonnet::escape($replying), + &printheader($r,'/adm/email?replyto='.&escape($replying), 'Replying to a Message'); } elsif ($replycrit) { $r->print('

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

'); @@ -859,13 +1155,17 @@ sub compout { my $dismsg=''; my $disbase=''; my $func=&mt('Send New'); - my %lt=&Apache::lonlocal::texthash('us' => 'Username', - 'do' => 'Domain', - 'ad' => 'Additional Recipients', - 'sb' => 'Subject', - 'ca' => 'Cancel', - 'ma' => 'Mail'); - + my %lt=&Apache::lonlocal::texthash('us' => 'Username', + 'do' => 'Domain', + 'ad' => 'Additional Recipients', + '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', + ); if (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { @@ -894,7 +1194,7 @@ sub compout { $dismsg=&mt('Forwarded message from').' '. $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'}; if ($content{'baseurl'}) { - $disbase=''; + $disbase=''; } } if ($replying) { @@ -910,25 +1210,44 @@ sub compout { $dismsg=~s/\f/\n/g; $dismsg=~s/\n+/\n\> /g; if ($content{'baseurl'}) { - $disbase=''; + $disbase=''; if ($env{'user.adv'}) { $disbase.=''. + &escape($content{'baseurl'}).'" target="comments">'. &mt('Show re-usable messages').'
'; } } } my $citation=&displayresource(%content); + my ($can_grp_broadcast,$viewgrps,$editgrps); if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; } if ($env{'form.text'}) { $dismsg=$env{'form.text'}; } if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; } $r->print( ''."\n". - ''."\n". - '
 '); if ($env{'form.sortedby'} eq "revdate") { $r->print(''.&mt('Date').'
'); - unless (($broadcast eq 'group') || ($broadcast eq 'upload')) { + ''."\n"); + if ($broadcast eq 'group' && $env{'form.group'} ne '') { + $can_grp_broadcast = + &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'. + $group); + $viewgrps = + &Apache::lonnet::allowed('vcg',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); + $editgrps = + &Apache::lonnet::allowed('mdg',$env{'request.course.id'}. + ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); + if ($viewgrps || $editgrps || $can_grp_broadcast) { + $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps)); + } + } + $r->print('
'); + if (($broadcast eq 'group') && ($group ne '') && + (!$can_grp_broadcast && !$viewgrps && !$editgrps)) { + $r->print(&recipient_input_row($cdom,%lt)); + } + if (($broadcast ne 'group') && ($broadcast ne 'upload')) { if ($replying) { $r->print(''); } else { - my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); - my $selectlink=&Apache::loncommon::selectstudent_link - ('compemail','recuname','recdomain'); - $r->print(<<"ENDREC"); - - - -ENDREC + $r->print(&recipient_input_row($defdom,%lt)); } } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); - + + +ENDREC + return $output; +} + sub retrieve_instructor_comments { my ($user,$domain)=@_; my $target=$env{'form.grade_target'}; if (! $env{'request.course.id'}) { return; } - if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'}) - && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { return; } @@ -1022,8 +1363,8 @@ sub retrieve_instructor_comments { $env{'course.'.$env{'request.course.id'}.'.num'}, '%255b'.$user.'%253a'.$domain.'%255d'); my $result=''; - foreach (sort(keys(%records))) { - my %content=&Apache::lonmsg::unpackagemsg($records{$_}); + foreach my $key (sort(keys(%records))) { + my %content=&Apache::lonmsg::unpackagemsg($records{$key}); next if ($content{'senderdomain'} eq ''); next if ($content{'subject'} !~ /^Record/); # &Apache::lonfeedback::newline_to_br(\$content{'message'}); @@ -1039,10 +1380,10 @@ sub disfacetoface { my ($r,$user,$domain)=@_; my $target=$env{'form.grade_target'}; unless ($env{'request.course.id'}) { return; } - if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { - $r->print('Not allowed'); + $r->print(&mt('Not allowed')); return; } my %records=&Apache::lonnet::dump('nohist_email', @@ -1050,8 +1391,8 @@ sub disfacetoface { $env{'course.'.$env{'request.course.id'}.'.num'}, '%255b'.$user.'%253a'.$domain.'%255d'); my $result=''; - foreach (sort keys %records) { - my %content=&Apache::lonmsg::unpackagemsg($records{$_}); + foreach my $key (sort(keys(%records))) { + my %content=&Apache::lonmsg::unpackagemsg($records{$key}); next if ($content{'senderdomain'} eq ''); &Apache::lonfeedback::newline_to_br(\$content{'message'}); if ($content{'subject'}=~/^Record/) { @@ -1060,7 +1401,7 @@ sub disfacetoface { $result .='

'.&mt('Broadcast Message').'

'; if ($content{'subject'}=~/^Broadcast\./) { if (defined($content{'coursemsgid'})) { - my $crsmsgid = &Apache::lonnet::escape($content{'coursemsgid'}); + my $crsmsgid = &escape($content{'coursemsgid'}); my $broadcast_message = &general_message($crsmsgid); $content{'message'} = ''.&mt('Subject').': '.$content{'message'}.'
'.$broadcast_message; } else { @@ -1073,7 +1414,7 @@ sub disfacetoface { } else { $result.='

'.&mt('Critical Message').'

'; if (defined($content{'coursemsgid'})) { - my $crsmsgid=&Apache::lonnet::escape($content{'coursemsgid'}); + my $crsmsgid=&escape($content{'coursemsgid'}); my $critical_message = &general_message($crsmsgid); $content{'message'} = ''.&mt('Subject').': '.$content{'message'}.'
'.$critical_message; } else { @@ -1094,10 +1435,11 @@ $content{'sendername'}.':'. } # Check to see if there were any messages. if ($result eq '') { + my $lctype = lc(&Apache::loncommon::course_type()); if ($target ne 'tex') { - $r->print("

".&mt("No notes, face-to-face discussion records, critical messages, or broadcast messages in this course.")."

"); + $r->print("

".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)."

"); } else { - $r->print('\textbf{'.&mt("No notes, face-to-face discussion records, critical messages or broadcast messages in this course.").'}\\\\'); + $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\'); } } else { $r->print($result); @@ -1120,12 +1462,15 @@ sub general_message { sub facetoface { my ($r,$stage)=@_; - if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { - $r->print('Not allowed'); + $r->print(&mt('Not allowed')); return; } + my $crstype = &Apache::loncommon::course_type(); + my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders' + : 'faculty and staff'; &printheader($r, '/adm/email?recordftf=query', "User Notes, Face-to-Face, Critical Messages, Broadcast Messages"); @@ -1143,9 +1488,9 @@ sub facetoface { ('stdselect','recuname','recdomain'); my %lt=&Apache::lonlocal::texthash('user' => 'Username', 'dom' => 'Domain', - 'head' => 'User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in Course', + 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype", 'subm' => 'Retrieve discussion and message records', - 'newr' => 'New Record (record is visible to course faculty and staff)', + 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')', 'post' => 'Post this Record'); $r->print(<<"ENDTREC");

$lt{'head'}

@@ -1166,13 +1511,9 @@ ENDTREC ($env{'form.recdomain'}) && ($env{'form.recuname'})) { chomp($env{'form.newrecord'}); if ($env{'form.newrecord'}) { - my $recordtxt = $env{'form.newrecord'}; - &Apache::lonmsg::user_normal_msg_raw( - $env{'course.'.$env{'request.course.id'}.'.num'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - &mt('Record'). - ' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']', - $recordtxt); + &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'}, + $env{'form.recuname'}, + $env{'form.recdomain'}); } $r->print('

'.&Apache::loncommon::plainname($env{'form.recuname'}, $env{'form.recdomain'}).'

'); @@ -1198,24 +1539,28 @@ ENDBFORM sub examblock { my ($r,$action) = @_; unless ($env{'request.course.id'}) { return;} - if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { $r->print('Not allowed'); return; } + my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members' + : 'students'; my %lt=&Apache::lonlocal::texthash( 'comb' => 'Communication Blocking', 'cbds' => 'Communication blocking during scheduled exams', - 'desc' => 'You can use communication blocking to prevent students enrolled in this course from displaying LON-CAPA messages sent by other students during an online exam. As blocking of communication could potentially interrupt legitimate communication between students who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.', + 'desc' => "You can use communication blocking to prevent $usertype enrolled in this course from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.", 'mecb' => 'Modify existing communication blocking periods', - 'ncbc' => 'No communication blocks currently stored' + 'ncbc' => 'No communication blocks currently stored', + 'stor' => 'Store', ); my %ltext = &Apache::lonlocal::texthash( 'dura' => 'Duration', 'setb' => 'Set by', 'even' => 'Event', + 'blck' => 'Blocked?', 'actn' => 'Action', 'star' => 'Start', 'endd' => 'End' @@ -1247,7 +1592,7 @@ sub examblock { $r->print(<<"END");
- + $end_page END @@ -1258,10 +1603,6 @@ sub blockstore { my $r = shift; my %lt=&Apache::lonlocal::texthash( 'tfcm' => 'The following changes were made', - 'cbps' => 'communication blocking period(s)', - 'werm' => 'was/were removed', - 'wemo' => 'was/were modified', - 'wead' => 'was/were added', 'ncwm' => 'No changes were made.' ); my %adds = (); @@ -1272,35 +1613,40 @@ sub blockstore { my $addtotal = 0; my %blocking = (); $r->print('

'.$lt{'head'}.'

'); - foreach (keys %env) { - if ($_ =~ m/^form\.modify_(\w+)$/) { + foreach my $envkey (keys(%env)) { + if ($envkey =~ m/^form\.modify_(\d+)$/) { $adds{$1} = $1; $removals{$1} = $1; $modtotal ++; - } elsif ($_ =~ m/^form\.cancel_(\d+)$/) { + } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) { $cancels{$1} = $1; unless ( defined($removals{$1}) ) { $removals{$1} = $1; $canceltotal ++; } - } elsif ($_ =~ m/^form\.add_(\d+)$/) { + } elsif ($envkey =~ m/^form\.add_(\d+)$/) { $adds{$1} = $1; $addtotal ++; - } + } } - foreach (keys %removals) { - my $hashkey = $env{'form.key_'.$_}; + foreach my $key (keys(%removals)) { + my $hashkey = $env{'form.key_'.$key}; &Apache::lonnet::del('comm_block',["$hashkey"], $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'} ); } - foreach (keys %adds) { - unless ( defined($cancels{$_}) ) { - my ($newstart,$newend) = &get_dates_from_form($_); + foreach my $key (keys(%adds)) { + unless ( defined($cancels{$key}) ) { + my ($newstart,$newend) = &get_dates_from_form($key); my $newkey = $newstart.'____'.$newend; - $blocking{$newkey} = $env{'user.name'}.':'.$env{'user.domain'}.':'.$env{'form.title_'.$_}; + my $blocktypes = &get_block_choices($key); + $blocking{$newkey} = { + setter => $env{'user.name'}.':'.$env{'user.domain'}, + event => &escape($env{'form.title_'.$key}), + blocks => $blocktypes, + }; } } if ($addtotal + $modtotal > 0) { @@ -1313,13 +1659,13 @@ sub blockstore { if ($chgestotal > 0) { $r->print($lt{'tfcm'}.'
    '); if ($canceltotal > 0) { - $r->print('
  • '.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'
  • '); + $r->print('
  • '.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'
  • '); } if ($modtotal > 0) { - $r->print('
  • '.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'
  • '); + $r->print('
  • '.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'
  • '); } if ($addtotal > 0) { - $r->print('
  • '.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'
  • '); + $r->print('
  • '.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'
  • '); } $r->print('
'); } else { @@ -1351,6 +1697,20 @@ sub get_blockdates { } } +sub get_block_choices { + my $item = shift; + my $blocklist; + my ($typeorder,$types) = &blocktype_text(); + foreach my $type (@{$typeorder}) { + if ($env{'form.'.$type.'_'.$item}) { + $blocklist->{$type} = 'on'; + } else { + $blocklist->{$type} = 'off'; + } + } + return $blocklist; +} + sub display_blocker_status { my ($r,$records,$ltext) = @_; my $parmcount = 0; @@ -1359,13 +1719,15 @@ sub display_blocker_status { 'modi' => 'Modify', 'canc' => 'Cancel', ); + my ($typeorder,$types) = &blocktype_text(); $r->print(&Apache::loncommon::start_data_table()); $r->print(<<"END"); - - - - + + + + + END foreach my $record (sort(keys(%{$records}))) { @@ -1376,15 +1738,29 @@ END my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange); my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange); - my ($setuname,$setudom,$title) = - &parse_block_record($$records{$record}); + my ($setuname,$setudom,$title,$blocks) = + &Apache::loncommon::parse_block_record($$records{$record}); $title = &HTML::Entities::encode($title,'"<>&'); - my $settername = &Apache::loncommon::plainname($setuname,$setudom); + my $settername = + &Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($setuname,$setudom), + $setuname,$setudom); $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - + + - - - + + + + END - $r->print(&Apache::loncommon::start_data_table_row()); + $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - + + END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1447,86 +1819,17 @@ END return; } -sub blockcheck { - my ($setters,$startblock,$endblock) = @_; - # Retrieve active student roles and active course coordinator/instructor roles - my %live_courses = - map { $_ => 1} &Apache::loncommon::findallcourses(); - # FIXME should really probe for apriv, but ::allowed can only probe the - # currently active role - my %staff_of = - map { $_ => 1} &Apache::loncommon::findallcourses(['cc','in']); - - # Retrieve blocking times and identity of blocker for active courses - # for students. - return if (!%live_courses); - - foreach my $course (keys(%live_courses)) { - my $cdom = $env{'course.'.$course.'.domain'}; - my $cnum = $env{'course.'.$course.'.num'}; - - # if they are a staff member and are currently not playing student - next if ( $staff_of{$course} - && ($env{'request.role'} !~ m{^st\./$cdom/$cnum})); - - $setters->{$course} = {}; - $setters->{$course}{'staff'} = []; - $setters->{$course}{'times'} = []; - my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum); - foreach my $record (keys %records) { - my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/); - if ($start <= time && $end >= time) { - my ($staff_name,$staff_dom,$title) = - &parse_block_record($records{$record}); - push(@{$$setters{$course}{'staff'}}, [$staff_name,$staff_dom]); - push(@{$$setters{$course}{'times'}}, [$start,$end]); - if ( ($$startblock == 0) || ($$startblock > $1) ) { - $$startblock = $1; - } - if ( ($$endblock == 0) || ($$endblock < $2) ) { - $$endblock = $2; - } - } - } - } -} - -sub build_block_table { - my ($r,$startblock,$endblock,$setters) = @_; - my %lt = &Apache::lonlocal::texthash( - 'cacb' => 'Currently active communication blocks', - 'cour' => 'Course', - 'dura' => 'Duration', - 'blse' => 'Block set by' +sub blocktype_text { + my %types = &Apache::lonlocal::texthash( + 'com' => 'Messaging', + 'chat' => 'Chat', + 'boards' => 'Discussion', + 'port' => 'Portfolio', + 'groups' => 'Groups', + 'blogs' => 'Blogs', ); - $r->print(<<"END"); -

$lt{'cacb'}:

-END - $r->print(&Apache::loncommon::start_data_table()); - $r->print(<<"END"); - - - - - -END - foreach my $course (keys(%{$setters})) { - my %courseinfo=&Apache::lonnet::coursedescription($course); - for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) { - my ($uname,$udom) = @{$$setters{$course}{staff}[$i]}; - my $fullname = &Apache::loncommon::plainname($uname,$udom); - my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]}; - $openblock = &Apache::lonlocal::locallocaltime($openblock); - $closeblock= &Apache::lonlocal::locallocaltime($closeblock); - $r->print(&Apache::loncommon::start_data_table_row(). - ''. - ''. - ''. - &Apache::loncommon::end_data_table_row()); - } - } - $r->print(&Apache::loncommon::end_data_table()); + my $typeorder = ['com','chat','boards','port','groups','blogs']; + return ($typeorder,\%types); } # ----------------------------------------------------------- Display a message @@ -1536,11 +1839,11 @@ sub displaymessage { my $suffix=&Apache::lonmsg::foldersuffix($folder); my %blocked = (); my %setters = (); - my $startblock = 0; - my $endblock = 0; my $numblocked = 0; + my $crstype = &Apache::loncommon::course_type(); + # info to generate "next" and "previous" buttons and check if message is blocked - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); if ( $blocked{$msgid} eq 'ON' ) { &printheader($r,'/adm/email',&mt('Display a Message')); @@ -1554,7 +1857,7 @@ sub displaymessage { my $counter=0; $r->print('
');
-    my $escmsgid=&Apache::lonnet::escape($msgid);
+    my $escmsgid=&escape($msgid);
     foreach (@messages) {
 	if ($_->[5] eq $escmsgid){
 	    last;
@@ -1564,17 +1867,17 @@ sub displaymessage {
     $r->print('
'); my $number_of_messages = scalar(@messages); #subtract 1 for last index # start output - &printheader($r,'/adm/email?display='.&Apache::lonnet::escape($msgid),'Display a Message','',$content{'baseurl'}); + &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'}); my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'}); # Functions $r->print('
'.&mt('Replying to').' '. &Apache::loncommon::aboutmewrapper( @@ -939,20 +1258,13 @@ sub compout { ''. '
$lt{'us'}:$selectlink
$lt{'do'}:$domform
$lt{'ad'}
username\@domain,username\@domain, ... +
$lt{'ad'}:
username:domain,username:domain, ...
$lt{'sb'}: @@ -968,38 +1280,53 @@ $disbase
$citation ENDCOMP + if (exists($env{'form.ref'})) { + $r->print(''); + } + if (exists($env{'form.group'})) { + $r->print(''); + } } else { # $broadcast is 'upload' - $r->print(<print(< -

Generate messages from a file

+

$lt{'gen'}

Subject:

-

General message text
+

$lt{'gmt'}:

-The file format for the uploaded portion of the message is: -

-username1\@domain1: text
-username2\@domain2: text
-username3\@domain1: text
-
+$lt{'tff'}: +ENDBLOCK + $r->print(' +
'."\n".
+&mt('username1:domain1: text')."\n".
+&mt('username2:domain2: text')."\n".
+&mt('username3:domain1: text')."\n".
+'

-The messages will be assembled from all lines with the respective -username\@domain, and appended to the general message text.

+'.&mt('The messages will be assembled from all lines with the respective'."\n".'username:domain, and appended to the general message text.')); + $r->print(<

$dispcrit -

+

ENDUPLOAD } if ($broadcast eq 'group') { - &discourse($r); - my $studentsel = &discourse(); - $r->print($studentsel); + if ($group eq '') { + my $studentsel = &discourse(); + $r->print($studentsel); + } + } + if ($env{'form.displayedcrit'}) { + $r->print(''); } $r->print(''. &Apache::lonfeedback::generate_preview_button('compemail','message'). @@ -1008,12 +1335,26 @@ ENDUPLOAD # ---------------------------------------------------- Display all face to face +sub recipient_input_row { + my ($dom,%lt) = @_; + my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain'); + my $selectlink= + &Apache::loncommon::selectstudent_link('compemail','recuname', + 'recdomain'); + my $output = <<"ENDREC"; +
$lt{'us'}:$selectlink
$lt{'do'}:$domform
$$ltext{'dura'}$$ltext{'setb'}$$ltext{'even'}$$ltext{'actn'}?$ltext->{'dura'}$ltext->{'setb'}$ltext->{'even'}$ltext->{'blck'}$ltext->{'actn'}?
$$ltext{'star'}: $startform
$$ltext{'endd'}:  $endform
$ltext->{'star'}: $startform
$ltext->{'endd'}:  $endform
$settername +END + foreach my $block (@{$typeorder}) { + my $blockstatus = ''; + if ($blocks->{$block} eq 'on') { + $blockstatus = 'checked="true"'; + } + $r->print('
'); + } + $r->print(<<"END"); +

END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1398,19 +1774,6 @@ END return $parmcount; } -sub parse_block_record { - my ($record) = @_; - my ($setuname,$setudom,$title); - my @data = split(/:/,$record,3); - if (scalar(@data) eq 2) { - $title = $data[1]; - ($setuname,$setudom) = split(/@/,$data[0]); - } else { - ($setuname,$setudom,$title) = @data; - } - return ($setuname,$setudom,$title); -} - sub display_addblocker_table { my ($r,$parmcount,$ltext) = @_; my $start = time; @@ -1425,21 +1788,30 @@ sub display_addblocker_table { 'exam' => 'e.g., Exam 1', 'addn' => 'Add new communication blocking periods' ); + my ($typeorder,$types) = &blocktype_text(); $r->print(<<"END");

$lt{'addn'}

END $r->print(&Apache::loncommon::start_data_table()); $r->print(<<"END");
$$ltext{'dura'}$$ltext{'even'} $lt{'exam'}$$ltext{'actn'}?$ltext->{'dura'}$ltext->{'even'} $lt{'exam'}$ltext->{'blck'}$ltext->{'actn'}?
$$ltext{'star'}: $startform
$$ltext{'endd'}:  $endform
$ltext->{'star'}: $startform
$ltext->{'endd'}:  $endform
+END + foreach my $block (@{$typeorder}) { + $r->print('
'); + } + $r->print(<<"END"); +
$lt{'cour'}$lt{'dura'}$lt{'blse'}
'.$courseinfo{'description'}.''.$openblock.' to '.$closeblock.''.$fullname.' ('.$uname.':'.$udom. - ')
'. - ''. - ''. - ''. - ''. '
'.&mt('Functions').':'.&mt('Reply').''.&mt('Forward').''.&mt('Mark Unread').''.&mt('Delete').''. $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')':''). @@ -1673,13 +1976,12 @@ sub header { my $extra = &Apache::loncommon::studentbrowser_javascript(); if ($baseurl) { - $extra .= ""; + $extra .= ""; } $r->print(&Apache::loncommon::start_page('Communication and Messages', - $extra)); + $extra)); $r->print(&Apache::lonhtmlcommon::breadcrumbs - (($title?$title:'Communication and Messages'))); - + (($title?$title:'Communication and Messages'))); } # ---------------------------------------------------------------- Print header @@ -1698,27 +2000,27 @@ sub storecomment { my ($r)=@_; my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'}); my $cleanmsgtxt=''; - foreach (split(/[\n\r]/,$msgtxt)) { - unless ($_=~/^\s*(\>|\>\;)/) { - $cleanmsgtxt.=$_."\n"; + foreach my $line (split(/[\n\r]/,$msgtxt)) { + unless ($line=~/^\s*(\>|\>\;)/) { + $cleanmsgtxt.=$line."\n"; } } - my $key=&Apache::lonnet::escape($env{'form.baseurl'}).'___'.time; + my $key=&escape($env{'form.baseurl'}).'___'.time; &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt }); } sub storedcommentlisting { my ($r)=@_; my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef, - '^'.&Apache::lonnet::escape(&Apache::lonnet::escape($env{'form.showcommentbaseurl'}))); + '^'.&escape(&escape($env{'form.showcommentbaseurl'}))); $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef, {'onlybody' => 1})); if ((keys %msgs)[0]=~/^error\:/) { $r->print(&mt('No stored comments yet.')); } else { my $found=0; - foreach (sort keys %msgs) { - $r->print("\n".$msgs{$_}."
"); + foreach my $key (sort(keys(%msgs))) { + $r->print("\n".$msgs{$key}."
"); $found=1; } unless ($found) { @@ -1735,8 +2037,20 @@ sub sendoffmail { my $sendstatus=''; my %specialmsg_status; my $numspecial = 0; + my ($cdom,$cnum,$group); + if (exists($env{'form.group'})) { + $group = $env{'form.group'}; + } + if (exists($env{'request.course.id'})) { + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + } if ($env{'form.send'}) { - &printheader($r,'','Messages being sent.'); + if ($group eq '') { + &printheader($r,'','Messages being sent.'); + } else { + $r->print(&groupmail_header('sending',$group)); + } $r->rflush(); my %content=(); undef %content; @@ -1755,13 +2069,14 @@ sub sendoffmail { &statuschange($msgid,'replied',$folder); } - my $to = $env{'form.selectedusers.forminput'}; + my @to = + &Apache::loncommon::get_env_multiple('form.selectedusers_forminput'); my $mode = $env{'form.sendmode'}; my %toaddr; - if ($to) { - foreach my $dest (@$to) { - my ($user,$domain) = split /:/, $dest; + if (@to) { + foreach my $dest (@to) { + my ($user,$domain) = split(/:/, $dest); if (($user ne '') && ($domain ne '')) { my $address = $user.":".$domain; # How the code below expects it. $toaddr{$address} = ''; @@ -1777,9 +2092,10 @@ sub sendoffmail { } } elsif ($env{'form.sendmode'} eq 'upload') { foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) { - my ($rec,$txt)=split(/\s*\:\s*/,$line); + my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/); if ($txt) { - $rec=~s/\@/\:/; + $rec =~ s/^\s+//; + $rec =~ s/\s+$//; $toaddr{$rec}.=$txt."\n"; } } @@ -1789,8 +2105,8 @@ sub sendoffmail { } } if ($env{'form.additionalrec'}) { - foreach (split(/\,/,$env{'form.additionalrec'})) { - my ($auname,$audom)=split(/\@/,$_); + foreach my $rec (split(/\,/,$env{'form.additionalrec'})) { + my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { $toaddr{$auname.':'.$audom}=''; } @@ -1860,22 +2176,20 @@ sub sendoffmail { $subj_prefix = 'Broadcast.'; } my ($specialmsgid,$specialresult); - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $course_str = &Apache::lonnet::escape('['.$cnum.':'.$cdom.']'); + my $course_str = &escape('['.$cnum.':'.$cdom.']'); if ($numspecial) { $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix. ' '.$course_str,$savemsg,undef,undef,undef, undef,undef,\$specialmsgid); - $specialmsgid = &Apache::lonnet::unescape($specialmsgid); + $specialmsgid = &unescape($specialmsgid); } if ($specialresult eq 'ok') { my $record_sent; my @recusers; my @recudoms; my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) = - split(/\:/,&Apache::lonnet::unescape($specialmsgid)); + split(/\:/,&unescape($specialmsgid)); foreach my $recipient (sort(keys(%toaddr))) { if ($specialmsg_status{$recipient} eq 'ok') { @@ -1917,6 +2231,9 @@ sub sendoffmail { $r->print('
'.&mt('Completed.').''); if ($env{'form.displayedcrit'}) { &discrit($r); + } + if ($group ne '') { + $r->print(&groupmail_sent($group,$cdom,$cnum)); } else { &Apache::loncommunicate::menu($r); } @@ -1943,7 +2260,7 @@ sub handler { ['display','replyto','forward','markread','markdel','markunread', 'sendreply','compose','sendmail','critical','recname','recdom', 'recordftf','sortedby','block','folder','startdis','interdis', - 'showcommentbaseurl','dismode','group','subject','text']); + 'showcommentbaseurl','dismode','group','subject','text','ref']); $sqs='&sortedby='.$env{'form.sortedby'}; # ------------------------------------------------------ They checked for email @@ -1965,7 +2282,7 @@ sub handler { unless ($folder) { $folder=''; } else { - $sqs.='&folder='.&Apache::lonnet::escape($folder); + $sqs.='&folder='.&escape($folder); } # ------------------------------------------------------------ Get Display Mode @@ -1973,7 +2290,7 @@ sub handler { unless ($dismode) { $dismode=''; } else { - $sqs.='&dismode='.&Apache::lonnet::escape($dismode); + $sqs.='&dismode='.&escape($dismode); } # --------------------------------------------------------------------- Display @@ -2009,19 +2326,23 @@ sub handler { &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode); } elsif ($env{'form.confirm'}) { &printheader($r,'','Confirmed Receipt'); - foreach (keys %env) { - if ($_=~/^form\.rec\_(.*)$/) { + my $replying = 0; + foreach my $envkey (keys(%env)) { + if ($envkey=~/^form\.rec\_(.*)$/) { $r->print(''.&mt('Confirming Receipt').': '. &Apache::lonmsg::user_crit_received($1).'
'); } - if ($_=~/^form\.reprec\_(.*)$/) { + if ($envkey=~/^form\.reprec\_(.*)$/) { my $msgid=$1; $r->print(''.&mt('Confirming Receipt').': '. &Apache::lonmsg::user_crit_received($msgid).'
'); &compout($r,'','','',$msgid); + $replying = 1; } } - &discrit($r); + if (!$replying) { + &discrit($r); + } } elsif ($env{'form.critical'}) { &printheader($r,'','Displaying Critical Messages'); &discrit($r); @@ -2043,7 +2364,7 @@ sub handler { foreach my $key (keys(%env)) { if ($key=~/^form\.delmark_(.*)$/) { my ($result,$msg) = - &movemsg(&Apache::lonnet::unescape($1),$folder, + &movemsg(&unescape($1),$folder, $env{'form.movetofolder'}); if ($result) { $total++; @@ -2070,7 +2391,7 @@ sub handler { foreach my $key (keys(%env)) { if ($key=~/^form\.delmark_(.*)$/) { my ($result,$msg) = - &statuschange(&Apache::lonnet::unescape($1),'deleted', + &statuschange(&unescape($1),'deleted', $folder); if ($result) { $total++; @@ -2107,25 +2428,59 @@ sub handler { &sendoffmail($r,$folder); if ($env{'form.storebasecomment'}) { &storecomment($r); - } + } if (($env{'form.rsspost'}) && ($env{'request.course.id'})) { - &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'}, + &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, 'Course_Announcements', $env{'form.subject'}, $env{'form.message'},'/adm/communicate','public'); } - &disall($r,($folder?$folder:$dismode)); + if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) { + &disall($r,($folder?$folder:$dismode)); + } } elsif ($env{'form.newfolder'}) { &printheader($r,'','New Folder'); - &makefolder($env{'form.newfolder'}); - &Apache::loncommunicate::menu($r); - &disall($r,$env{'form.newfolder'}); + my $showfolder = $env{'form.newfolder'}; + my ($makeresult,$warning) = &makefolder($env{'form.newfolder'}); + if ($makeresult eq 'ok') { + $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'
'); + } else { + $r->print(&mt('Creation failed.').' '.$makeresult.'
'. + $warning); + $showfolder = $folder; + } + &Apache::loncommunicate::menu($r); + &disall($r,$showfolder); } elsif ($env{'form.showcommentbaseurl'}) { &storedcommentlisting($r); + } elsif ($env{'form.folderaction'} eq 'delete') { + &printheader($r,'','Deleted Folder'); + my $showfolder = ''; + my $delresult = &deletefolder($folder); + if ($delresult eq 'ok') { + $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'
'); + } else { + $r->print(&mt('Deletion failed.').' '.$delresult.'
'); + $showfolder = $folder; + } + &Apache::loncommunicate::menu($r); + &disall($r,$showfolder); + } elsif ($env{'form.folderaction'} eq 'rename') { + &printheader($r,'','Renamed Folder'); + my $showfolder = $env{'form.renamed'}; + my $renresult = &renamefolder($folder); + if ($renresult eq 'ok') { + $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'
'); + } else { + $r->print(&mt('Renaming failed.').' '.$renresult.'
'); + $showfolder = $folder; + } + &Apache::loncommunicate::menu($r); + &disall($r,$showfolder); } else { &printheader($r,'','Display All Messages'); - &Apache::loncommunicate::menu($r); + &Apache::loncommunicate::menu($r); &disall($r,($folder?$folder:$dismode)); } $r->print(&Apache::loncommon::end_page()); @@ -2143,9 +2498,3 @@ sub handler { __END__ - - - - - -