--- loncom/interface/lonmsg.pm 2003/10/15 21:10:24 1.69 +++ loncom/interface/lonmsg.pm 2004/03/01 02:21:57 1.88 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.69 2003/10/15 21:10:24 www Exp $ +# $Id: lonmsg.pm,v 1.88 2004/03/01 02:21:57 www 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 @@ -154,6 +139,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.''. @@ -284,6 +270,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 { @@ -364,7 +397,7 @@ sub user_crit_received { my %contents=&unpackagemsg($message{$msgid},1); my $status='rec: '.($contents{'sendback'}? &user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, - &mt('Receipt').': '.$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".&mt('dated').' '. @@ -567,7 +600,9 @@ $content{'sendername'}.'@'. '
'.&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'). + '
'. ''. ''; @@ -833,6 +868,7 @@ ENDCOMP } else { # $broadcast is 'upload' $r->print(< +

Generate messages from a file

Subject: @@ -913,7 +949,13 @@ sub facetoface { unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { return; } + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>'/adm/dropadd?recordftf=query', + text=>"User Notes, Face-to-Face, Critical Messages", + faq=>12,bug=>'Communication Tools'}); + &header($r); # from query string + if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; } if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; } @@ -924,17 +966,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
@@ -946,7 +994,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'}, @@ -958,28 +1007,43 @@ ENDTREC ENDRHEAD $r->print(<New Record (record is visible to course faculty and staff)
+
$lt{'newr'}

- + ENDBFORM } } +# ================================================================== The Header + +sub header { + my ($r,$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,'Communication and Messages')); + +} + # ===================================================================== Handler sub handler { my $r=shift; # ----------------------------------------------------------- Set document type - - &Apache::loncommon::content_type($r,'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', @@ -987,204 +1051,221 @@ sub handler { '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}); + + 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}); # 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 + 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 - $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(''.&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'}.') '. - '
'.&mt('Time').': '.$content{'time'}.'

'. - ''. - ''. - ''. - ''. - ''. - ''); - 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').'

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

'.$content{'citation'}); - } elsif ($ENV{'form.replyto'}) { - &comprep($r,$ENV{'form.replyto'}); - } elsif ($ENV{'form.sendreply'}) { - if ($ENV{'form.send'}) { - 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(&mt('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(&mt('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'}) { - if ($ENV{'form.send'}) { - 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; - + $r->print('EMail and Messaging'); + $r->print(&Apache::loncommon::studentbrowser_javascript(). + ''. + &Apache::loncommon::bodytag('EMail and Messages'). + &Apache::loncommon::help_open_faq(12). + &Apache::loncommon::help_open_bug('Communication Tools')); + my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'}); + + $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'}.'

'. + ''. + ''. + ''. + ''. + ''. + ''); + 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').'

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

'.$content{'citation'}); + } elsif ($ENV{'form.replyto'}) { + &comprep($r,$ENV{'form.replyto'}); + } elsif ($ENV{'form.sendreply'}) { + if ($ENV{'form.send'}) { + 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(&mt('Sending critical message').': '. + &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(&mt('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 $sendstatus=''; + if ($ENV{'form.send'}) { + 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(&mt('Sending critical message').' ...'); + $sendstatus.=' '.&user_crit_msg($recuname,$recdomain, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + $msgtxt, + $ENV{'form.sendbck'}); + } else { + $r->print(&mt('Sending').' ...'); + $sendstatus.=' '.&user_normal_msg($recuname,$recdomain, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + $msgtxt, + $content{'citation'}); + } + $r->print('
'); + } + } + if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { + $r->print('
'.&mt('Completed.').''); + if ($ENV{'form.displayedcrit'}) { + &discrit($r); + } else { + &disall($r); + } + } else { + $r->print( + '

'.&mt('Could not deliver message').'

'. + &mt('Please use the browser "Back" button and correct the recipient addresses') + ); + } + } else { + &disall($r); + } + $r->print(''); + return OK; } # ================================================= Main program, reset counter