--- loncom/interface/lonmsg.pm 2006/01/10 15:29:13 1.172 +++ loncom/interface/lonmsg.pm 2006/03/16 22:12:17 1.178 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.172 2006/01/10 15:29:13 albertel Exp $ +# $Id: lonmsg.pm,v 1.178 2006/03/16 22:12:17 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -137,7 +137,7 @@ my $interdis; sub packagemsg { my ($subject,$message,$citation,$baseurl,$attachmenturl, - $recuser,$recdomain,$msgid,$type)=@_; + $recuser,$recdomain,$msgid,$type,$crsmsgid)=@_; $message =&HTML::Entities::encode($message,'<>&"'); $citation=&HTML::Entities::encode($citation,'<>&"'); $subject =&HTML::Entities::encode($subject,'<>&"'); @@ -170,11 +170,19 @@ sub packagemsg { $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'}, $msgcount,$course_context,$$); } - my $result=''.$env{'user.name'}.''. + my $result = ''.$env{'user.name'}.''. ''.$env{'user.domain'}.''. ''.$subject.''. - ''. - ''.$ENV{'SERVER_NAME'}.''. + ''; + if (defined($crsmsgid)) { + $result.= ''.$course_context.''. + ''.$env{'request.course.sec'}.''. + ''.$msgid.''. + ''.$crsmsgid.''. + ''.$message.''; + return ($msgid,$result); + } + $result .= ''.$ENV{'SERVER_NAME'}.''. ''.$ENV{'HTTP_HOST'}.''. ''.$ENV{'REMOTE_ADDR'}.''. ''.$env{'browser.type'}.''. @@ -536,21 +544,24 @@ sub user_crit_received { sub user_normal_msg_raw { my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, - $toperm,$currid,$newid,$sentmessage)=@_; + $toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_; # Check if allowed missing - my $status=''; + my ($status,$packed_message); my $msgid='undefined'; my $text=$message; unless (($message)&&($user)&&($domain)) { $status='empty'; }; my $homeserver=&Apache::lonnet::homeserver($user,$domain); if ($homeserver ne 'no_host') { - ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl, - $attachmenturl,$user,$domain,$currid); + ($msgid,$packed_message)= + &packagemsg($subject,$message,$citation,$baseurl, + $attachmenturl,$user,$domain,$currid, + undef,$crsmsgid); + # Store in user folder $status=&Apache::lonnet::critical( 'put:'.$domain.':'.$user.':nohist_email:'. &Apache::lonnet::escape($msgid).'='. - &Apache::lonnet::escape($message),$homeserver); + &Apache::lonnet::escape($packed_message),$homeserver); # Save new message received time &Apache::lonnet::put ('email_status',{'recnewemail'=>time},$domain,$user); @@ -561,7 +572,12 @@ sub user_normal_msg_raw { (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})))) { - $status .= &store_sent_mail($msgid,$message); + (undef, my $packed_message_no_citation)= + &packagemsg($subject,$message,undef ,$baseurl, + $attachmenturl,$user,$domain,$currid, + undef,$crsmsgid); + + $status .= &store_sent_mail($msgid,$packed_message_no_citation); } } else { $status='no_host'; @@ -570,7 +586,7 @@ sub user_normal_msg_raw { $$newid = $msgid; } if (defined($sentmessage)) { - $$sentmessage = $message; + $$sentmessage = $packed_message; } # Notifications @@ -758,7 +774,7 @@ sub discourse { for (i=0; iprint(""); } - $r->print(''.&Apache::loncommon::endbodytag().''); + $r->print(''.&Apache::loncommon::end_page()); } elsif ($numblocked == 0) { $r->print("

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

"); } @@ -1243,8 +1259,9 @@ sub compout { &mt('and return receipt') . '' . $crithelp . '

'. -''; } +'

'; + } my %message; my %content; my $defdom=$env{'user.domain'}; @@ -1420,17 +1437,29 @@ sub disfacetoface { } elsif ($content{'subject'}=~/^Broadcast/) { $result .='

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

'; if ($content{'subject'}=~/^Broadcast\./) { - %content=&unpackagemsg($content{'message'}); - $content{'message'}= + if (defined($content{'coursemsgid'})) { + my $crsmsgid = &Apache::lonnet::escape($content{'coursemsgid'}); + my $broadcast_message = &general_message($crsmsgid); + $content{'message'} = ''.&mt('Subject').': '.$content{'message'}.'
'.$broadcast_message; + } else { + %content=&unpackagemsg($content{'message'}); + $content{'message'} = ''.&mt('Subject').': '.$content{'subject'}.'
'. $content{'message'}; + } } } else { $result.='

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

'; - %content=&unpackagemsg($content{'message'}); - $content{'message'}= + if (defined($content{'coursemsgid'})) { + my $crsmsgid=&Apache::lonnet::escape($content{'coursemsgid'}); + my $critical_message = &general_message($crsmsgid); + $content{'message'} = ''.&mt('Subject').': '.$content{'message'}.'
'.$critical_message; + } else { + %content=&unpackagemsg($content{'message'}); + $content{'message'}= ''.&mt('Subject').': '.$content{'subject'}.'
'. $content{'message'}; + } } $result.=&mt('By').': '. &Apache::loncommon::aboutmewrapper( @@ -1453,6 +1482,18 @@ $content{'sendername'}.'@'. } } +sub general_message { + my ($crsmsgid) = @_; + my %general_content; + if ($crsmsgid) { + my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid], + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + %general_content = &unpackagemsg($course_content{$crsmsgid}); + } + return $general_content{'message'}; +} + # ---------------------------------------------------------------- Face to face sub facetoface { @@ -1580,14 +1621,13 @@ sub examblock { $r->print($lt{'ncbc'}.'

'); } &display_addblocker_table($r,$parmcount,\%ltext); - my $endbody=&Apache::loncommon::endbodytag(); + my $end_page=&Apache::loncommon::end_page(); $r->print(<<"END");
-$endbody - +$end_page END return; } @@ -2031,26 +2071,25 @@ sub displayresource { $content{'sendername'}, $content{'senderdomain'}, $content{'courseid'}); - } else { + } elsif ($env{'user.adv'}) { return $content{'citation'}; } + return ''; } # ================================================================== The Header sub header { my ($r,$title,$baseurl)=@_; - $r->print(&Apache::lonxml::xmlbegin(). - ''.&Apache::lonxml::fontsettings(). - 'Communication and Messages'. - &Apache::lonhtmlcommon::htmlareaheaders()); + + my $extra = &Apache::loncommon::studentbrowser_javascript(); if ($baseurl) { - $r->print(""); + $extra .= ""; } - $r->print(&Apache::loncommon::studentbrowser_javascript().''. - &Apache::loncommon::bodytag('Communication and Messages')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs - (undef,($title?$title:'Communication and Messages'))); + $r->print(&Apache::loncommon::start_page('Communication and Messages', + $extra)); + $r->print(&Apache::lonhtmlcommon::breadcrumbs + (undef,($title?$title:'Communication and Messages'))); } @@ -2083,8 +2122,8 @@ sub storedcommentlisting { my ($r)=@_; my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef, '^'.&Apache::lonnet::escape(&Apache::lonnet::escape($env{'form.showcommentbaseurl'}))); - $r->print(&Apache::lonxml::xmlbegin().''. - &Apache::lonxml::fontsettings().''); + $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 { @@ -2155,6 +2194,7 @@ sub sendoffmail { my $savemsg; my $msgtype; my %sentmessage; + my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'}); if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. @@ -2176,15 +2216,12 @@ sub sendoffmail { || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. '/'.$env{'request.course.sec'}))) { $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': '); - $thismsg=&user_crit_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($env{'form.subject'}), - $msgtxt, - $env{'form.sendbck'},$env{'form.permanent'},\$sentmessage{$_}); + $thismsg=&user_crit_msg($recuname,$recdomain,$msgsubj,$msgtxt, + $env{'form.sendbck'},$env{'form.permanent'}, + \$sentmessage{$_}); } else { $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': '); - $thismsg=&user_normal_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($env{'form.subject'}), - $msgtxt, + $thismsg=&user_normal_msg($recuname,$recdomain,$msgsubj,$msgtxt, $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_}); } if (($env{'request.course.id'}) && (($msgtype eq 'critical') || @@ -2220,7 +2257,7 @@ sub sendoffmail { my $record_sent; my @recusers = (); my @recudoms = (); - my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) = + my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) = split(/\:/,&Apache::lonnet::unescape($specialmsgid)); foreach my $recipient (sort(keys(%toaddr))) { if ($specialmsg_status{$recipient} eq 'ok') { @@ -2228,8 +2265,8 @@ sub sendoffmail { my $usermsgid = &buildmsgid($stamp,$usersubj,$msgname, $msgdom,$msgcount,$context,$pid); &user_normal_msg_raw($cnum,$cdom,$subj_prefix. - ' ['.$recipient.']',$sentmessage{$recipient}, - undef,undef,undef,undef,$usermsgid); + ' ['.$recipient.']',$msgsubj,undef, + undef,undef,undef,$usermsgid,undef,undef,$specialmsgid); my ($uname,$udom) = split/:/,$recipient; push(@recusers,$uname); push(@recudoms,$udom); @@ -2238,14 +2275,12 @@ sub sendoffmail { if (@recusers) { my $specialmessage; my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '. - &Apache::lonfeedback::clear_out_html($env{'form.subject'}); + $msgsubj; $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"'); my $sentmsgid = &buildmsgid($stamp,$sentsubj,$msgname, $msgdom,$msgcount,$context,$pid); - ($specialmsgid,$specialmessage) = - &packagemsg(&Apache::lonfeedback::clear_out_html( - $env{'form.subject'}),$savemsg,undef,undef,undef, - \@recusers,\@recudoms,$sentmsgid); + ($specialmsgid,$specialmessage) = &packagemsg($msgsubj,$savemsg, + undef,undef,undef,\@recusers,\@recudoms,$sentmsgid); $record_sent = &store_sent_mail($specialmsgid,$specialmessage); } } else { @@ -2437,7 +2472,7 @@ sub handler { &Apache::loncommunicate::menu($r); &disall($r,($folder?$folder:$dismode)); } - $r->print(&Apache::loncommon::endbodytag().''); + $r->print(&Apache::loncommon::end_page()); return OK; } # ================================================= Main program, reset counter