--- loncom/interface/lonmsgdisplay.pm 2007/04/22 13:41:22 1.70 +++ loncom/interface/lonmsgdisplay.pm 2007/05/01 18:40:57 1.71 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.70 2007/04/22 13:41:22 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.71 2007/05/01 18:40:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1229,14 +1229,16 @@ will be forwarded to the recipient(s) yo '

'; } - if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) || - &Apache::lonnet::allowed('dff',$env{'request.course.id'}. - '/'.$env{'request.course.sec'})) { - - $dispcrit.='

'; + if ($broadcast ne 'group') { + if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) || + &Apache::lonnet::allowed('dff',$env{'request.course.id'}. + '/'.$env{'request.course.sec'})) { + + $dispcrit.='

'; + } } my %message; @@ -2228,8 +2230,9 @@ sub sendoffmail { my ($r,$folder)=@_; my $suffix=&Apache::lonmsg::foldersuffix($folder); my $sendstatus=''; - my %specialmsg_status; - my $numspecial = 0; + my %msg_status; + my $numsent = 0; + my $nosentstore = 1; my ($cdom,$cnum,$group); if (exists($env{'form.group'})) { $group = $env{'form.group'}; @@ -2286,6 +2289,7 @@ sub sendoffmail { } } } elsif ($env{'form.sendmode'} eq 'upload') { + $nosentstore = 0; foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) { my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/); if ($txt) { @@ -2323,7 +2327,8 @@ sub sendoffmail { } else { $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'}); } - + my @recusers; + my @recudoms; foreach my $address (sort(keys(%toaddr))) { my ($recuname,$recdomain)=split(/\:/,$address); my $msgtxt = $savemsg; @@ -2337,7 +2342,8 @@ sub sendoffmail { $msgsubj,$msgtxt, $env{'form.sendbck'}, $env{'form.permanent'}, - \$sentmessage{$address}); + \$sentmessage{$address}, + $nosentstore); } else { $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': '); @thismsg= @@ -2346,101 +2352,93 @@ sub sendoffmail { $content{'citation'}, undef,undef, $env{'form.permanent'}, - \$sentmessage{$address}); - } - if (($env{'request.course.id'}) && - (($msgtype eq 'critical') || - ($env{'form.sendmode'} eq 'group') || - ($env{'form.courserecord'}))) { - $specialmsg_status{$recuname.':'.$recdomain} = - join(' ',@thismsg); - foreach my $result (@thismsg) { - if ($result eq 'ok' || $result eq 'con_delayed') { - $numspecial++; - } - } + \$sentmessage{$address}, + undef,undef,undef, + $nosentstore); + } + $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg); + if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) { + $numsent++; + push(@recusers,$recuname); + push(@recudoms,$recdomain); } $sendstatus.=' '.join(' ',@thismsg); } - if (($env{'request.course.id'}) && - (($env{'form.sendmode'} eq 'group') || - ($env{'form.courserecord'}) || - ($msgtype eq 'critical'))) { - my $subj_prefix; - if ($msgtype eq 'critical') { - $subj_prefix = 'Critical.'; - } elsif ($env{'form.sendmode'} eq 'group') { - $subj_prefix = 'Broadcast.'; - } else { - $subj_prefix = 'Archive'; - } - my ($specialmsgid,$specialresult); - my $course_str = &escape('['.$cnum.':'.$cdom.']'); + my $subj_prefix; + if ($numsent > 0) { + if (($env{'request.course.id'}) && + (($env{'form.sendmode'} eq 'group') || + ($env{'form.courserecord'}) || + ($msgtype eq 'critical'))) { + if ($msgtype eq 'critical') { + $subj_prefix = 'Critical.'; + } elsif ($env{'form.sendmode'} eq 'group') { + $subj_prefix = 'Broadcast.'; + } else { + $subj_prefix = 'Archive'; + } + my ($specialmsgid,$specialresult); + 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); + $specialresult = + &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom, + $subj_prefix.' '.$course_str,$savemsg,undef,undef, + undef,undef,undef,\$specialmsgid,undef,undef,undef, + undef,undef,1); $specialmsgid = &unescape($specialmsgid); - } - if ($specialresult eq 'ok') { - my $record_sent; - my @recusers; - my @recudoms; - my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) = - split(/\:/,&unescape($specialmsgid)); - - foreach my $recipient (sort(keys(%toaddr))) { - if ($specialmsg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) { - my $usersubj = $subj_prefix.'['.$recipient.']'; - my $usermsgid = - &Apache::lonmsg::buildmsgid($stamp,$usersubj, - $msgname,$msgdom, - $msgcount,$context, - $pid); - &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix. - ' ['.$recipient.']',$msgsubj,undef, - undef,undef,undef,$usermsgid,undef,undef,$specialmsgid); - my ($uname,$udom) = split(/:/,$recipient); - push(@recusers,$uname); - push(@recudoms,$udom); + if ($specialresult eq 'ok') { + my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) = + split(/\:/,&unescape($specialmsgid)); + + foreach my $recipient (sort(keys(%toaddr))) { + if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) { + my $usersubj = $subj_prefix.'['.$recipient.']'; + my $usermsgid = + &Apache::lonmsg::buildmsgid($stamp,$usersubj, + $msgname,$msgdom, + $msgcount,$context, + $pid); + &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom, + $subj_prefix.' ['.$recipient.']',$msgsubj, + undef,undef,undef,undef,$usermsgid,undef, + undef,$specialmsgid,undef,undef,undef,1); + } } - } - if (@recusers) { - my $specialmessage; - my $sentsubj = - $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj; - $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"'); - my $sentmsgid = - &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname, - $msgdom,$msgcount,$context, - $pid); - ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg, - undef,undef,undef,\@recusers,\@recudoms,$sentmsgid); - $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage); + if (($env{'form.sendmode'} ne 'upload') && (@recusers > 0)) { + &Apache::lonmsg::process_sent_mail($msgsubj, + $subj_prefix,$numsent,$stamp,$msgname,$msgdom, + $msgcount,$context,$pid,$savemsg,\@recusers, + \@recudoms); + } + } else { + &Apache::lonnet::logthis('Failed to create record of critical, broadcast or archived message in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated'); } } else { - &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated'); + my $stamp = time; + my $msgcount = &Apache::lonmsg::get_uniq(); + my $context = &Apache::lonmsg::get_course_context(); + &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix, + $numsent,$stamp,$env{'user.name'}, + $env{'user.domain'},$msgcount,$context, + $$,$savemsg,\@recusers,\@recudoms); } } - } else { - &printheader($r,'','No messages sent.'); - } - if (!$env{'form.multiforward'}) { - if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { - $r->print('
'.&mt('Completed.'). - ''); - if ($env{'form.displayedcrit'}) { - &discrit($r); + if (!$env{'form.multiforward'}) { + if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { + $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); + } + } else { + $r->print('

'.&mt('Could not deliver message').' '. + &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'

'); } - if ($group ne '') { - $r->print(&groupmail_sent($group,$cdom,$cnum)); - } else { - &Apache::loncommunicate::menu($r); - } - } else { - $r->print('

'.&mt('Could not deliver message').' '. - &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'

'); } } return $sendstatus;