--- loncom/interface/lonmsg.pm 2003/03/17 16:55:06 1.42.2.1 +++ loncom/interface/lonmsg.pm 2003/04/02 00:50:46 1.53 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.42.2.1 2003/03/17 16:55:06 albertel Exp $ +# $Id: lonmsg.pm,v 1.53 2003/04/02 00:50:46 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,18 +52,22 @@ use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::lontexconvert(); use HTML::Entities(); +use Mail::Send; # ===================================================================== Package sub packagemsg { - my ($subject,$message,$citation)=@_; -# $message=~s/\/\>\;/g; + my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_; $message =&HTML::Entities::encode($message); $citation=&HTML::Entities::encode($citation); $subject =&HTML::Entities::encode($subject); -# $subject=~s/\/\>\;/g; + #remove machine specification + $baseurl =~ s|^http://[^/]+/|/|; + $baseurl =&HTML::Entities::encode($baseurl); + #remove machine specification + $attachmenturl =~ s|^http://[^/]+/|/|; + $attachmenturl =&HTML::Entities::encode($attachmenturl); + my $now=time; $msgcount++; my $partsubj=$subject; @@ -71,8 +75,7 @@ sub packagemsg { my $msgid=&Apache::lonnet::escape( $now.':'.$partsubj.':'.$ENV{'user.name'}.':'. $ENV{'user.domain'}.':'.$msgcount.':'.$$); - return $msgid, - ''.$ENV{'user.name'}.''. + my $result=''.$ENV{'user.name'}.''. ''.$ENV{'user.domain'}.''. ''.$subject.''. ''. @@ -88,14 +91,23 @@ sub packagemsg { ''.$ENV{'request.role'}.''. ''.$ENV{'request.filename'}.''. ''.$msgid.''. - ''.$message.''. - ''.$citation.''; + ''.$message.''; + if (defined($citation)) { + $result.=''.$citation.''; + } + if (defined($baseurl)) { + $result.= ''.$baseurl.''; + } + if (defined($attachmenturl)) { + $result.= ''.$attachmenturl.''; + } + return $msgid,$result; } # ================================================== Unpack message into a hash sub unpackagemsg { - my $message=shift; + my ($message,$notoken)=@_; my %content=(); my $parser=HTML::TokeParser->new(\$message); my $token; @@ -106,6 +118,16 @@ sub unpackagemsg { $content{$entry}=$value; } } + if ($content{'attachmenturl'}) { + my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/); + if ($notoken) { + $content{'message'}.='

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

Attachment: '.$fname.'.'.$ft.''; + } + } return %content; } @@ -121,6 +143,42 @@ sub unpackmsgid { return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid}); } + +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; + 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; +} + +# ==================================================== Send notification emails + +sub sendnotification { + my ($to,$touname,$toudom,$subj,$crit)=@_; + my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'}; + my $critical=($crit?' critical':''); + my $url='http://'. + $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}. + '/adm/login&username='.$touname.'&domain='.$toudom; + my $body=(<'); unless (($broadcast eq 'group') || ($broadcast eq 'upload')) { my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); - + my $selectlink=&Apache::loncommon::selectstudent_link + ('compemail','recuname','recdomain'); $r->print(<<"ENDREC"); - + ENDREC @@ -581,6 +661,111 @@ ENDUPLOAD $r->print(''); } +# ---------------------------------------------------- Display all face to face + +sub disfacetoface { + my ($r,$user,$domain)=@_; + unless ($ENV{'request.course.id'}) { return; } + unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { + return; + } + my %records=&Apache::lonnet::dump('nohist_email', + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, + '%255b'.$user.'%253a'.$domain.'%255d'); + my $result=''; + foreach (sort keys %records) { + my %content=&unpackagemsg($records{$_}); + next if ($content{'senderdomain'} eq ''); + $content{'message'}=~s/\n/\/g; + if ($content{'subject'}=~/^Record/) { + $result.='

Record

'; + } else { + $result.='

Sent Message

'; + %content=&unpackagemsg($content{'message'}); + $content{'message'}= + 'Subject: '.$content{'subject'}.'
'. + $content{'message'}; + } + $result.='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.

"); + } else { + $r->print($result); + } +} + +# ---------------------------------------------------------------- Face to face + +sub facetoface { + my ($r,$stage)=@_; + unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { + return; + } +# from query string + if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; } + if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; } + + my $defdom=$ENV{'user.domain'}; +# already filled in + if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; } +# generate output + my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain'); + my $stdbrws = &Apache::loncommon::selectstudent_link + ('stdselect','recuname','recdomain'); + $r->print(<<"ENDTREC"); +

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

+
+ +
Username:
Username:$selectlink
Domain: $domform
+ + + + + +
Username: +$stdbrws +
Domain:$domform
+ +ENDTREC + if (($stage ne 'query') && + ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) { + chomp($ENV{'form.newrecord'}); + if ($ENV{'form.newrecord'}) { + &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'}.']', + $ENV{'form.newrecord'}); + } + $r->print('

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

'); + &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'}); + $r->print(< + + +ENDRHEAD + $r->print(<New Record (record is visible to course faculty and staff)
+ +
+ + + +ENDBFORM + } +} + # ===================================================================== Handler sub handler { @@ -596,19 +781,29 @@ sub handler { # --------------------------- 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']); + 'sendreply','compose','sendmail','critical','recname','recdom', + 'recordftf']); # ------------------------------------------------------ They checked for email &Apache::lonnet::put('email_status',{'recnewemail'=>0}); # --------------------------------------------------------------- Render Output - - $r->print('EMail and Messaging'. - &Apache::loncommon::bodytag('EMail and Messages')); + 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( @@ -624,6 +819,8 @@ $content{'sendername'},$content{'senderd '">Forward'. 'Mark Unread'. + 'Delete'. 'Display all Messages'. '

'.
              &Apache::lontexconvert::msgtexconverted($content{'message'}).
@@ -633,7 +830,7 @@ $content{'sendername'},$content{'senderd
   } elsif ($ENV{'form.sendreply'}) {
       my $msgid=$ENV{'form.sendreply'};
       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
-      my %content=&unpackagemsg($message{$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'}))) {
@@ -691,13 +888,15 @@ $content{'sendername'},$content{'senderd
       &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});
+        %content=&unpackagemsg($message{$msgid},1);
         &statuschange($msgid,'forwarded');
         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
 	                       $content{'message'};