--- loncom/interface/lonmsg.pm 2003/07/25 13:13:43 1.59 +++ loncom/interface/lonmsg.pm 2004/05/07 12:03:53 1.99 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.59 2003/07/25 13:13:43 bowersj2 Exp $ +# $Id: lonmsg.pm,v 1.99 2004/05/07 12:03:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,23 +25,8 @@ # # http://www.lon-capa.org/ # -# -# (Routines to control the menu -# -# (TeX Conversion Module -# -# 05/29/00,05/30 Gerd Kortemeyer) -# -# 10/05 Gerd Kortemeyer) -# -# 10/19,10/20,10/30, -# 02/06/01 Gerd Kortemeyer -# 07/27 Guy Albertelli -# 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15, -# 10/1,11/5 Gerd Kortemeyer -# YEAR=2002 -# 1/1,3/18 Gerd Kortemeyer -# + + package Apache::lonmsg; =pod @@ -115,20 +100,25 @@ use Apache::loncommon(); use Apache::lontexconvert(); use HTML::Entities(); use Mail::Send; +use Apache::lonlocal; +use Apache::loncommunicate; + +# Querystring component with sorting type +my $sqs; # ===================================================================== Package sub packagemsg { my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_; - $message =&HTML::Entities::encode($message); - $citation=&HTML::Entities::encode($citation); - $subject =&HTML::Entities::encode($subject); + $message =&HTML::Entities::encode($message,'<>&"'); + $citation=&HTML::Entities::encode($citation,'<>&"'); + $subject =&HTML::Entities::encode($subject,'<>&"'); #remove machine specification $baseurl =~ s|^http://[^/]+/|/|; - $baseurl =&HTML::Entities::encode($baseurl); + $baseurl =&HTML::Entities::encode($baseurl,'<>&"'); #remove machine specification $attachmenturl =~ s|^http://[^/]+/|/|; - $attachmenturl =&HTML::Entities::encode($attachmenturl); + $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"'); my $now=time; $msgcount++; @@ -140,7 +130,7 @@ sub packagemsg { my $result=''.$ENV{'user.name'}.''. ''.$ENV{'user.domain'}.''. ''.$subject.''. - ''. + ''. ''.$ENV{'SERVER_NAME'}.''. ''.$ENV{'HTTP_HOST'}.''. ''.$ENV{'REMOTE_ADDR'}.''. @@ -150,6 +140,7 @@ sub packagemsg { ''.$ENV{'browser.mathml'}.''. ''.$ENV{'HTTP_USER_AGENT'}.''. ''.$ENV{'request.course.id'}.''. + ''.$ENV{'request.course.sec'}.''. ''.$ENV{'request.role'}.''. ''.$ENV{'request.filename'}.''. ''.$msgid.''. @@ -183,11 +174,13 @@ sub unpackagemsg { if ($content{'attachmenturl'}) { my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/); if ($notoken) { - $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; + $content{'message'}.='

'.&mt('Attachment').': '.$fname.'.'.$ft.''; } else { - $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; + &Apache::lonnet::allowuploaded('/adm/msg', + $content{'attachmenturl'}); + $content{'message'}.='

'.&mt('Attachment'). + ': '. + $fname.'.'.$ft.''; } } return %content; @@ -209,14 +202,15 @@ sub unpackmsgid { sub sendemail { my ($to,$subject,$body)=@_; $body= - "*** This is an automatic message generated by the LON-CAPA system.\n". - "*** Please do not reply to this address.\n\n".$body; + "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n". + "*** ".&mt('Please do not reply to this address.')."\n\n".$body; my $msg = new Mail::Send; $msg->to($to); $msg->subject('[LON-CAPA] '.$subject); - my $fh = $msg->open('smtp',Server => 'localhost'); - print $fh $body; - $fh->close; + if (my $fh = $msg->open()) { + print $fh $body; + $fh->close; + } } # ==================================================== Send notification emails @@ -279,6 +273,53 @@ sub author_res_msg { return 'no_host'; } +# =========================================== Retrieve author resource messages + +sub retrieve_author_res_msg { + my $url=shift; + $url=&Apache::lonnet::declutter($url); + my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//); + my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author); + my $msgs=''; + foreach (keys %errormsgs) { + if ($_=~/^\Q$url\E\_\d+$/) { + my %content=&unpackagemsg($errormsgs{$_}); + $msgs.='

'. + $content{'time'}.': '.$content{'message'}. + '

'; + } + } + return $msgs; +} + + +# =============================== Delete all author messages related to one URL + +sub del_url_author_res_msg { + my $url=shift; + $url=&Apache::lonnet::declutter($url); + my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//); + my @delmsgs=(); + foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) { + if ($_=~/^\Q$url\E\_\d+$/) { + push (@delmsgs,$_); + } + } + return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author); +} + +# ================= Return hash with URLs for which there is a resource message + +sub all_url_author_res_msg { + my ($author,$domain)=@_; + my %returnhash=(); + foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) { + $_=~/^(.+)\_\d+/; + $returnhash{$1}=1; + } + return %returnhash; +} + # ================================================== Critical message to a user sub user_crit_msg_raw { @@ -359,10 +400,10 @@ sub user_crit_received { my %contents=&unpackagemsg($message{$msgid},1); my $status='rec: '.($contents{'sendback'}? &user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, - 'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, - 'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}. + &mt('Receipt').': '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}.', '.$contents{'subject'}, + &mt('User').' '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}. ' acknowledged receipt of message'."\n".' "'. - $contents{'subject'}.'"'."\n".'dated '. + $contents{'subject'}.'"'."\n".&mt('dated').' '. $contents{'time'}.".\n" ):'no msg req'); $status.=' trans: '. @@ -466,8 +507,11 @@ sub discourse { $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); my $now=time; + my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All', + 'cfs' => 'Check for Section/Group', + 'cfn' => 'Check for None'); $r->print(< + -  - -  - +  + +  +

ENDDISHEADER + my %coursepersonnel= + &Apache::lonnet::get_course_adv_roles(); + foreach my $role (sort keys %coursepersonnel) { + foreach (split(/\,/,$coursepersonnel{$role})) { + my ($puname,$pudom)=split(/\:/,$_); + $r->print( + '
'. + &Apache::loncommon::plainname($puname, + $pudom).' ('.$_.'), '.$role.''); + } + } + foreach (sort keys %courselist) { my ($end,$start)=split(/\:/,$courselist{$_}); my $active=1; @@ -529,7 +586,7 @@ ENDDISHEADER sub discrit { my $r=shift; - my $header = '

Critical Messages

'. + my $header = '

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

'. '
'. ''; my %what=&Apache::lonnet::dump('critical'); @@ -538,22 +595,25 @@ sub discrit { my %content=&unpackagemsg($what{$_}); next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\/g; - $result.='
From: '. + $result.='
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. $content{'senderdomain'}.') '.$content{'time'}. - '
Subject: '.$content{'subject'}. + '
'.&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'). + '
'. + ''. ''; + 'value="'.&mt('Confirm Receipt and Reply').'">'; } # Check to see if there were any messages. if ($result eq '') { - $result = "

You have no critical messages.

"; + $result = "

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

". + ''.&mt('Select a course').''; } else { $r->print($header); } @@ -561,42 +621,51 @@ $content{'sendername'}.'@'. $r->print(''); } -# =============================================================== Compose reply - -sub comprep { - my ($r,$msgid)=@_; - my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - my %content=&unpackagemsg($message{$msgid},1); - my $quotemsg='> '.$content{'message'}; - $quotemsg=~s/\r/\n/g; - $quotemsg=~s/\f/\n/g; - $quotemsg=~s/\n+/\n\> /g; - my $torepl=&Apache::loncommon::aboutmewrapper( - &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. -$content{'sendername'}.'@'. - $content{'senderdomain'}.')'; - my $subject='Re: '.$content{'subject'}; - my $dispcrit=''; - if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { - my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); - $dispcrit= - ' Send as critical message ' . $crithelp . - '
'. - ' Send as critical message ' . - ' and return receipt' . $crithelp . '

'; - } - $r->print(<<"ENDREPLY"); -

- -To: $torepl
-Subject:

-

-$dispcrit - -

-ENDREPLY +sub sortedmessages { + my @messages = &Apache::lonnet::getkeys('nohist_email'); + #unpack the varibles and repack into temp for sorting + my @temp; + foreach (@messages) { + my $msgid=&Apache::lonnet::escape($_); + my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= + &Apache::lonmsg::unpackmsgid($msgid); + my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, + $msgid); + push @temp ,\@temp1; + } + #default sort + @temp = sort {$a->[0] <=> $b->[0]} @temp; + if ($ENV{'form.sortedby'} eq "date"){ + @temp = sort {$a->[0] <=> $b->[0]} @temp; + } + if ($ENV{'form.sortedby'} eq "revdate"){ + @temp = sort {$b->[0] <=> $a->[0]} @temp; + } + if ($ENV{'form.sortedby'} eq "user"){ + @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp; + } + if ($ENV{'form.sortedby'} eq "revuser"){ + @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp; + } + if ($ENV{'form.sortedby'} eq "domain"){ + @temp = sort {$a->[3] cmp $b->[3]} @temp; + } + if ($ENV{'form.sortedby'} eq "revdomain"){ + @temp = sort {$b->[3] cmp $a->[3]} @temp; + } + if ($ENV{'form.sortedby'} eq "subject"){ + @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp; + } + if ($ENV{'form.sortedby'} eq "revsubject"){ + @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp; + } + if ($ENV{'form.sortedby'} eq "status"){ + @temp = sort {$a->[4] cmp $b->[4]} @temp; + } + if ($ENV{'form.sortedby'} eq "revstatus"){ + @temp = sort {$b->[4] cmp $a->[4]} @temp; + } + return @temp; } # ======================================================== Display all messages @@ -624,111 +693,198 @@ sub disall { } ENDDISHEADER - $r->print( - '

Display All Messages

'. - ''. - ''); - foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'. - $ENV{'user.domain'}.':'. - $ENV{'user.name'}.':nohist_email', - $ENV{'user.home'}))) { - my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= - &Apache::lonmsg::unpackmsgid($_); + $r->print('

'.&mt('Display All Messages').'

'. + '
 DateUsernameDomainSubjectStatus
'); + } else { + $r->print(''.&mt('Date').''); + } + $r->print(''); + } else { + $r->print(''.&mt('Status').''); + } + $r->print(''); + my @temp=sortedmessages(); + foreach (@temp){ + my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_; if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) { if ($status eq 'new') { $r->print(''); } elsif ($status eq 'read') { $r->print(''); } elsif ($status eq 'replied') { - $r->print(''); + $r->print(''); } else { $r->print(''); } - $r->print(''. - ''. + ''); } - } + } $r->print('
 '); + if ($ENV{'form.sortedby'} eq "revdate") { + $r->print(''.&mt('Date').''); + if ($ENV{'form.sortedby'} eq "revuser") { + $r->print(''.&mt('Username').''); + } else { + $r->print(''.&mt('Username').''); + } + $r->print(''); + if ($ENV{'form.sortedby'} eq "revdomain") { + $r->print(''.&mt('Domain').''); + } else { + $r->print(''.&mt('Domain').''); + } + $r->print(''); + if ($ENV{'form.sortedby'} eq "revsubject") { + $r->print(''.&mt('Subject').''); + } else { + $r->print(''.&mt('Subject').''); + } + $r->print(''); + if ($ENV{'form.sortedby'} eq "revstatus") { + $r->print(''.&mt('Status').'
OpenDelete'.localtime($sendtime).''. + $r->print(''.&mt('Open').''.&mt('Delete').''.&Apache::lonlocal::locallocaltime($sendtime).''. $fromname.''.$fromdomain.''. &Apache::lonnet::unescape($shortsubj).''. $status.'

'. - 'Check All '. - 'Uncheck All

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

'. + ''. + ''. '

'); } # ============================================================== Compose output sub compout { - my ($r,$forwarding,$broadcast)=@_; - my $dispcrit=''; + my ($r,$forwarding,$replying,$broadcast,$replycrit)=@_; + + if ($broadcast eq 'individual') { + &printheader($r,'/adm/email?compose=individual', + 'Send a Message'); + } elsif ($broadcast) { + &printheader($r,'/adm/email?compose=group', + 'Broadcast Message'); + } elsif ($forwarding) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/email?display=".&Apache::lonnet::escape($forwarding), + text=>"Display Message"}); + &printheader($r,'/adm/email?forward='.&Apache::lonnet::escape($forwarding), + 'Forwarding a Message'); + } elsif ($replying) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/email?display=".&Apache::lonnet::escape($replying), + text=>"Display Message"}); + &printheader($r,'/adm/email?replyto='.&Apache::lonnet::escape($replying), + 'Replying to a Message'); + } elsif ($replycrit) { + $r->print('

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

'); + $replying=$replycrit; + } else { + &printheader($r,'/adm/email?compose=upload', + 'Distribute from Uploaded File'); + } + + my $dispcrit=''; my $dissub=''; my $dismsg=''; - my $func='Send New'; - if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { + my $func=&mt('Send New'); + my %lt=&Apache::lonlocal::texthash('us' => 'Username', + 'do' => 'Domain', + 'ad' => 'Additional Recipients', + 'sb' => 'Subject', + 'ca' => 'Cancel', + 'ma' => 'Mail'); + + if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); $dispcrit= - ' Send as critical message ' . $crithelp . + ' '.&mt('Send as critical message').' ' . $crithelp . '
'. - ' Send as critical message ' . - ' and return receipt' . $crithelp . '

'; - } + ' '.&mt('Send as critical message').' ' . + &mt('and return receipt') . $crithelp . '

'; + } + my %message; + my %content; + my $defdom=$ENV{'user.domain'}; if ($forwarding) { - $dispcrit.=''; - $func='Forward'; - my %message=&Apache::lonnet::get('nohist_email',[$forwarding]); - my %content=&unpackagemsg($message{$forwarding}); - - $dissub='Forwarding: '.$content{'subject'}; - $dismsg='Forwarded message from '. - $content{'sendername'}.' at '.$content{'senderdomain'}; + %message=&Apache::lonnet::get('nohist_email',[$forwarding]); + %content=&unpackagemsg($message{$forwarding}); + $dispcrit.=''; + $func=&mt('Forward'); + + $dissub=&mt('Forwarding').': '.$content{'subject'}; + $dismsg=&mt('Forwarded message from').' '. + $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'}; + } + if ($replying) { + %message=&Apache::lonnet::get('nohist_email',[$replying]); + %content=&unpackagemsg($message{$replying}); + $dispcrit.=''; + $func=&mt('Replying to'); + + $dissub=&mt('Reply').': '.$content{'subject'}; + $dismsg='> '.$content{'message'}; + $dismsg=~s/\r/\n/g; + $dismsg=~s/\f/\n/g; + $dismsg=~s/\n+/\n\> /g; } - my $defdom=$ENV{'user.domain'}; if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; } $r->print( '

'."\n". - ''."\n". + ''."\n". ''); unless (($broadcast eq 'group') || ($broadcast eq 'upload')) { - my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); - my $selectlink=&Apache::loncommon::selectstudent_link + 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"); -
'.&mt('Replying to').' '. + &Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. + $content{'sendername'}.'@'. + $content{'senderdomain'}.')'. + ''. + ''. + '
- - + $r->print(<<"ENDREC"); + + ENDREC + } } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); - - +
Username:$selectlink
Domain:
$lt{'us'}:$selectlink
$lt{'do'}: $domform
Additional Recipients
username\@domain,username\@domain, ... +
$lt{'ad'}
username\@domain,username\@domain, ...
-
Subject: +
$lt{'sb'}:
$latexHelp -

+


$dispcrit - + + ENDCOMP } else { # $broadcast is 'upload' $r->print(< + +

Generate messages from a file

-Subject: +Subject:

General message text
-

The file format for the uploaded portion of the message is: @@ -742,9 +898,9 @@ username3\@domain1: text The messages will be assembled from all lines with the respective username\@domain, and appended to the general message text.

-

+

$dispcrit - +

ENDUPLOAD } if ($broadcast eq 'group') { @@ -757,6 +913,7 @@ ENDUPLOAD sub disfacetoface { my ($r,$user,$domain)=@_; + my $target=$ENV{'form.grade_target'}; unless ($ENV{'request.course.id'}) { return; } unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { return; @@ -771,26 +928,30 @@ sub disfacetoface { next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\/g; if ($content{'subject'}=~/^Record/) { - $result.='

Record

'; + $result.='

'.&mt('Record').'

'; } else { - $result.='

Sent Message

'; + $result.='

'.&mt('Sent Message').'

'; %content=&unpackagemsg($content{'message'}); $content{'message'}= - 'Subject: '.$content{'subject'}.'
'. + ''.&mt('Subject').': '.$content{'subject'}.'
'. $content{'message'}; } - $result.='By: '. + $result.=&mt('By').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. $content{'senderdomain'}.') '.$content{'time'}. - '
'. + '
'. &Apache::lontexconvert::msgtexconverted($content{'message'}). '
'; } # Check to see if there were any messages. if ($result eq '') { - $r->print("

No notes, face-to-face discussion records, or critical messages in this course.

"); + if ($target ne 'tex') { + $r->print("

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

"); + } else { + $r->print('\textbf{'.&mt("No notes, face-to-face discussion records, or critical messages in this course.").'}\\\\'); + } } else { $r->print($result); } @@ -803,7 +964,11 @@ sub facetoface { unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { return; } + &printheader($r, + '/adm/email?recordftf=query', + "User Notes, Face-to-Face, Critical Messages"); # from query string + if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; } if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; } @@ -814,17 +979,23 @@ sub facetoface { my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); my $stdbrws = &Apache::loncommon::selectstudent_link ('stdselect','recuname','recdomain'); + my %lt=&Apache::lonlocal::texthash('user' => 'Username', + 'dom' => 'Domain', + 'head' => 'User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course', + 'subm' => 'Retrieve discussion and message records', + 'newr' => 'New Record (record is visible to course faculty and staff)', + 'post' => 'Post this Record'); $r->print(<<"ENDTREC"); -

User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course

+

$lt{'head'}

- + + - +
Username:
$lt{'user'}: $stdbrws -
Domain:
$lt{'dom'}: $domform
@@ -836,7 +1007,8 @@ ENDTREC &user_normal_msg_raw( $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - 'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']', + &mt('Record'). + ' ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']', $ENV{'form.newrecord'}); } $r->print('

'.&Apache::loncommon::plainname($ENV{'form.recuname'}, @@ -848,206 +1020,265 @@ ENDTREC ENDRHEAD $r->print(<New Record (record is visible to course faculty and staff)
+
$lt{'newr'}

- + ENDBFORM } } +# ----------------------------------------------------------- Display a message + +sub displaymessage { + my ($r,$msgid)=@_; + &statuschange($msgid,'read'); + my %message=&Apache::lonnet::get('nohist_email',[$msgid]); + my %content=&unpackagemsg($message{$msgid}); +# info to generate "next" and "previous" buttons + my @messages=&sortedmessages(); + my $counter=0; + $r->print('
');
+    my $escmsgid=&Apache::lonnet::escape($msgid);
+    foreach (@messages) {
+	if ($_->[5] eq $escmsgid){
+	    last;
+	}
+	$counter++;
+    }
+    $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'}); + my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'}); +# Functions + $r->print(''. + ''. + ''. + ''. + ''. + ''); + if ($counter > 0){ + $r->print(''); + } + if ($counter < $number_of_messages - 1){ + $r->print(''); + } + $r->print('
'.&mt('Functions').':'.&mt('Reply').''.&mt('Forward').''.&mt('Mark Unread').'Delete'.&mt('Display all Messages').''.&mt('Previous').''.&mt('Next').'
'); + $r->print('
'.&mt('Subject').': '.$content{'subject'}. + '
'.&mt('From').': '. + &Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}), + $content{'sendername'},$content{'senderdomain'}).' ('. + $content{'sendername'}.' at '. + $content{'senderdomain'}.') '. + ($content{'courseid'}?'
'.&mt('Course').': '.$courseinfo{'description'}. + ($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):''). + '
'.&mt('Time').': '.$content{'time'}. + '

'.
+	      &Apache::lontexconvert::msgtexconverted($content{'message'},1).
+	      '

'.$content{'citation'}.'

'); + return; +} + +# ================================================================== The Header + +sub header { + my ($r,$title,$baseurl)=@_; + $r->print('Communication and Messages'); + if ($baseurl) { + $r->print(""); + } + $r->print(&Apache::loncommon::studentbrowser_javascript().''. + &Apache::loncommon::bodytag('Communication and Messages')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs + (undef,($title?$title:'Communication and Messages'))); + +} + +# ---------------------------------------------------------------- Print header + +sub printheader { + my ($r,$url,$desc,$title,$baseurl)=@_; + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>$url, + text=>$desc}); + &header($r,$title,$baseurl); +} + + # ===================================================================== Handler sub handler { my $r=shift; # ----------------------------------------------------------- Set document type - - $r->content_type('text/html'); - $r->send_http_header; - - return OK if $r->header_only; - + + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + + return OK if $r->header_only; + # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['display','replyto','forward','markread','markdel','markunread', 'sendreply','compose','sendmail','critical','recname','recdom', - 'recordftf']); - + 'recordftf','sortedby']); + $sqs='&sortedby='.$ENV{'form.sortedby'}; # ------------------------------------------------------ They checked for email - &Apache::lonnet::put('email_status',{'recnewemail'=>0}); + &Apache::lonnet::put('email_status',{'recnewemail'=>0}); + +# ----------------------------------------------------------------- Breadcrumbs + + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/communicate", + text=>"Communication/Messages", + faq=>12,bug=>'Communication Tools',}); + # --------------------------------------------------------------- Render Output - if (!$ENV{'form.display'}) { - $r->print('EMail and Messaging'. - &Apache::loncommon::studentbrowser_javascript().''. - &Apache::loncommon::bodytag('EMail and Messages')); - } - if ($ENV{'form.display'}) { - my $msgid=$ENV{'form.display'}; - &statuschange($msgid,'read'); - my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - my %content=&unpackagemsg($message{$msgid}); - $r->print('EMail and Messaging'); - if (defined($content{'baseurl'})) { - $r->print(""); - } - $r->print(&Apache::loncommon::studentbrowser_javascript(). - ''. - &Apache::loncommon::bodytag('EMail and Messages')); - $r->print('Subject: '.$content{'subject'}. - '
From: '. -&Apache::loncommon::aboutmewrapper( -&Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}), -$content{'sendername'},$content{'senderdomain'}).' ('. - $content{'sendername'}.' at '. - $content{'senderdomain'}.') '. - '
Time: '.$content{'time'}.'

'. - ''. - ''. - ''. - ''. - ''. - ''. - '
Functions:ReplyForwardMark UnreadDeleteDisplay all Messages

'.
-             &Apache::lontexconvert::msgtexconverted($content{'message'}).
-             '

'.$content{'citation'}); - } elsif ($ENV{'form.replyto'}) { - &comprep($r,$ENV{'form.replyto'}); - } elsif ($ENV{'form.sendreply'}) { - my $msgid=$ENV{'form.sendreply'}; - my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - my %content=&unpackagemsg($message{$msgid},1); - &statuschange($msgid,'replied'); - if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - $r->print('Sending critical: '. - &user_crit_msg($content{'sendername'}, - $content{'senderdomain'}, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - &Apache::lonfeedback::clear_out_html($ENV{'form.message'}), - $ENV{'form.sendbck'})); - } else { - $r->print('Sending: '.&user_normal_msg($content{'sendername'}, - $content{'senderdomain'}, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - &Apache::lonfeedback::clear_out_html($ENV{'form.message'}))); - } - if ($ENV{'form.displayedcrit'}) { - &discrit($r); - } else { - &disall($r); - } - } elsif ($ENV{'form.confirm'}) { - foreach (keys %ENV) { - if ($_=~/^form\.rec\_(.*)$/) { - $r->print('Confirming Receipt: '. - &user_crit_received($1).'
'); - } - if ($_=~/^form\.reprec\_(.*)$/) { - my $msgid=$1; - $r->print('Confirming Receipt: '. - &user_crit_received($msgid).'
'); - &comprep($r,$msgid); - } - } - &discrit($r); - } elsif ($ENV{'form.critical'}) { - &discrit($r); - } elsif ($ENV{'form.forward'}) { - &compout($r,$ENV{'form.forward'}); - } elsif ($ENV{'form.markread'}) { - } elsif ($ENV{'form.markdel'}) { - &statuschange($ENV{'form.markdel'},'deleted'); - &disall($r); - } elsif ($ENV{'form.markeddel'}) { - my $total=0; - foreach (keys %ENV) { - if ($_=~/^form\.delmark_(.*)$/) { - &statuschange(&Apache::lonnet::unescape($1),'deleted'); - $total++; - } - } - $r->print('Deleted '.$total.' message(s)

'); - &disall($r); - } elsif ($ENV{'form.markunread'}) { - &statuschange($ENV{'form.markunread'},'new'); - &disall($r); - } elsif ($ENV{'form.compose'}) { - &compout($r,'',$ENV{'form.compose'}); - } elsif ($ENV{'form.recordftf'}) { - &facetoface($r,$ENV{'form.recordftf'}); - } elsif ($ENV{'form.sendmail'}) { - my %content=(); - undef %content; - if ($ENV{'form.forwid'}) { - my $msgid=$ENV{'form.forwid'}; - my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - %content=&unpackagemsg($message{$msgid},1); - &statuschange($msgid,'forwarded'); - $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n". - $content{'message'}; - } - my %toaddr=(); - undef %toaddr; - if ($ENV{'form.sendmode'} eq 'group') { - foreach (keys %ENV) { - if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) { - $toaddr{$1}=''; - } - } - } elsif ($ENV{'form.sendmode'} eq 'upload') { - foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) { - my ($rec,$txt)=split(/\s*\:\s*/,$_); - if ($txt) { - $rec=~s/\@/\:/; - $toaddr{$rec}.=$txt."\n"; - } - } - } else { - $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}=''; - } - if ($ENV{'form.additionalrec'}) { - foreach (split(/\,/,$ENV{'form.additionalrec'})) { - my ($auname,$audom)=split(/\@/,$_); - $toaddr{$auname.':'.$audom}=''; - } - } - foreach (keys %toaddr) { - my ($recuname,$recdomain)=split(/\:/,$_); - my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'}); - if ($toaddr{$_}) { $msgtxt.='


'.$toaddr{$_}; } - if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - $r->print('Sending critical: '. - &user_crit_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - $msgtxt, - $ENV{'form.sendbck'})); - } else { - $r->print('Sending: '.&user_normal_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - $msgtxt, - $content{'citation'})); - } - $r->print('
'); - } - if ($ENV{'form.displayedcrit'}) { - &discrit($r); - } else { - &disall($r); - } - } else { - &disall($r); - } - $r->print(''); - return OK; + if ($ENV{'form.display'}) { + &displaymessage($r,$ENV{'form.display'}); + } elsif ($ENV{'form.replyto'}) { + &compout($r,'',$ENV{'form.replyto'}); + } elsif ($ENV{'form.confirm'}) { + &printheader($r,'','Confirmed Receipt'); + foreach (keys %ENV) { + if ($_=~/^form\.rec\_(.*)$/) { + $r->print(''.&mt('Confirming Receipt').': '. + &user_crit_received($1).'
'); + } + if ($_=~/^form\.reprec\_(.*)$/) { + my $msgid=$1; + $r->print(''.&mt('Confirming Receipt').': '. + &user_crit_received($msgid).'
'); + &compout($r,'','','',$msgid); + } + } + &discrit($r); + } elsif ($ENV{'form.critical'}) { + &printheader($r,'','Displaying Critical Messages'); + &discrit($r); + } elsif ($ENV{'form.forward'}) { + &compout($r,$ENV{'form.forward'}); + } elsif ($ENV{'form.markdel'}) { + &printheader($r,'','Deleted Message'); + &statuschange($ENV{'form.markdel'},'deleted'); + &disall($r); + } elsif ($ENV{'form.markeddel'}) { + my $total=0; + foreach (keys %ENV) { + if ($_=~/^form\.delmark_(.*)$/) { + &statuschange(&Apache::lonnet::unescape($1),'deleted'); + $total++; + } + } + &printheader($r,'','Deleted Messages'); + $r->print('Deleted '.$total.' message(s)

'); + &disall($r); + } elsif ($ENV{'form.markunread'}) { + &printheader($r,'','Marked Message as Unread'); + &statuschange($ENV{'form.markunread'},'new'); + &disall($r); + } elsif ($ENV{'form.compose'}) { + &compout($r,'','',$ENV{'form.compose'}); + } elsif ($ENV{'form.recordftf'}) { + &facetoface($r,$ENV{'form.recordftf'}); + } elsif ($ENV{'form.sendmail'}) { + my $sendstatus=''; + if ($ENV{'form.send'}) { + &printheader($r,'','Messages being sent.'); + $r->rflush(); + my %content=(); + undef %content; + if ($ENV{'form.forwid'}) { + my $msgid=$ENV{'form.forwid'}; + my %message=&Apache::lonnet::get('nohist_email',[$msgid]); + %content=&unpackagemsg($message{$msgid},1); + &statuschange($msgid,'forwarded'); + $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n". + $content{'message'}; + } + my %toaddr=(); + undef %toaddr; + if ($ENV{'form.sendmode'} eq 'group') { + foreach (keys %ENV) { + if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) { + $toaddr{$1}=''; + } + } + } elsif ($ENV{'form.sendmode'} eq 'upload') { + foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) { + my ($rec,$txt)=split(/\s*\:\s*/,$_); + if ($txt) { + $rec=~s/\@/\:/; + $toaddr{$rec}.=$txt."\n"; + } + } + } else { + $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}=''; + } + if ($ENV{'form.additionalrec'}) { + foreach (split(/\,/,$ENV{'form.additionalrec'})) { + my ($auname,$audom)=split(/\@/,$_); + $toaddr{$auname.':'.$audom}=''; + } + } + + foreach (keys %toaddr) { + my ($recuname,$recdomain)=split(/\:/,$_); + my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'}); + if ($toaddr{$_}) { $msgtxt.='


'.$toaddr{$_}; } + my $thismsg; + if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && + (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { + $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'}); + } else { + $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': '); + $thismsg=&user_normal_msg($recuname,$recdomain, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + $msgtxt, + $content{'citation'}); + } + $r->print($thismsg.'
'); + $sendstatus.=' '.$thismsg; + } + } else { + &printheader($r,'','No messages sent.'); + } + if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { + $r->print('
'.&mt('Completed.').''); + if ($ENV{'form.displayedcrit'}) { + &discrit($r); + } 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') + ); + } + } else { + &printheader($r,'','Display All Messages'); + &disall($r); + } + $r->print(''); + return OK; } # ================================================= Main program, reset counter