[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm lonmsg.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 18 Feb 2003 15:47:40 -0000


albertel		Tue Feb 18 10:47:40 2003 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm lonfeedback.pm 
  Log:
  -Fixes BUG#1255, sets the base url of email messages that contain forwars of a problems view, thus relative links will work.
  
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.48 loncom/interface/lonmsg.pm:1.49
--- loncom/interface/lonmsg.pm:1.48	Mon Feb 17 12:39:53 2003
+++ loncom/interface/lonmsg.pm	Tue Feb 18 10:47:40 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.48 2003/02/17 17:39:53 albertel Exp $
+# $Id: lonmsg.pm,v 1.49 2003/02/18 15:47:40 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,10 +56,14 @@
 # ===================================================================== Package
 
 sub packagemsg {
-    my ($subject,$message,$citation)=@_;
+    my ($subject,$message,$citation,$baseurl)=@_;
+    &Apache::lonnet::logthis("base is $baseurl");
     $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);
     my $now=time;
     $msgcount++;
     my $partsubj=$subject;
@@ -67,8 +71,7 @@
     my $msgid=&Apache::lonnet::escape(
            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
-    return $msgid,
-           '<sendername>'.$ENV{'user.name'}.'</sendername>'.
+    my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
            '<subject>'.$subject.'</subject>'.
 	   '<time>'.localtime($now).'</time>'.
@@ -84,8 +87,14 @@
 	   '<role>'.$ENV{'request.role'}.'</role>'.
 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
            '<msgid>'.$msgid.'</msgid>'.
-	   '<message>'.$message.'</message>'.
-	   '<citation>'.$citation.'</citation>';
+	   '<message>'.$message.'</message>';
+    if (defined($citation)) {
+	$result.='<citation>'.$citation.'</citation>';
+    }
+    if (defined($baseurl)) {
+	$result.= '<baseurl>'.$baseurl.'</baseurl>';
+    }
+    return $msgid,$result;
 }
 
 # ================================================== Unpack message into a hash
@@ -100,6 +109,8 @@
 	   my $entry=$token->[1];
            my $value=$parser->get_text('/'.$entry);
            $content{$entry}=$value;
+	   &Apache::lonnet::logthis("setting $entry to $value");
+
        }
     }
     return %content;
@@ -234,14 +245,15 @@
 # ======================================================== Normal communication
 
 sub user_normal_msg_raw {
-    my ($user,$domain,$subject,$message,$citation)=@_;
+    my ($user,$domain,$subject,$message,$citation,$baseurl)=@_;
 # Check if allowed missing
     my $status='';
     my $msgid='undefined';
     unless (($message)&&($user)&&($domain)) { $status='empty'; };
     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
     if ($homeserver ne 'no_host') {
-       ($msgid,$message)=&packagemsg($subject,$message,$citation);
+    &Apache::lonnet::logthis("baseraw is $baseurl");
+       ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl);
        $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':nohist_email:'.
            &Apache::lonnet::escape($msgid).'='.
@@ -260,7 +272,7 @@
 # New routine that respects "forward" and calls old routine
 
 sub user_normal_msg {
-    my ($user,$domain,$subject,$message,$citation)=@_;
+    my ($user,$domain,$subject,$message,$citation,$baseurl)=@_;
     my $status='';
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -270,11 +282,11 @@
 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
          $status.=
 	  &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
-                                                             $citation).' ';
+			       $citation,$baseurl).' ';
        }
     } else { 
-	$status=
-          &user_normal_msg_raw($user,$domain,$subject,$message,$citation);
+	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
+				     $citation,$baseurl);
     }
     return $status;
 }
@@ -711,15 +723,23 @@
 # ------------------------------------------------------ They checked for email
   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
 # --------------------------------------------------------------- Render Output
-  
-  $r->print('<html><head><title>EMail and Messaging</title>'.
-            &Apache::loncommon::studentbrowser_javascript().'</head>'.
-            &Apache::loncommon::bodytag('EMail and Messages'));
+  if (!$ENV{'form.display'}) {
+      $r->print('<html><head><title>EMail and Messaging</title>'.
+		&Apache::loncommon::studentbrowser_javascript().'</head>'.
+		&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('<html><head><title>EMail and Messaging</title>');
+      if (defined($content{'baseurl'})) {
+	  $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
+      }
+      $r->print(&Apache::loncommon::studentbrowser_javascript().
+		'</head>'.
+		&Apache::loncommon::bodytag('EMail and Messages'));
       $r->print('<b>Subject:</b> '.$content{'subject'}.
              '<br><b>From:</b> '.
 &Apache::loncommon::aboutmewrapper(
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.40 loncom/interface/lonfeedback.pm:1.41
--- loncom/interface/lonfeedback.pm:1.40	Mon Feb 17 12:09:27 2003
+++ loncom/interface/lonfeedback.pm	Tue Feb 18 10:47:40 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.40 2003/02/17 17:09:27 albertel Exp $
+# $Id: lonfeedback.pm,v 1.41 2003/02/18 15:47:40 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -342,7 +342,7 @@
     if ($_) {
       my $declutter=&Apache::lonnet::declutter($feedurl);
       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
-               'Feedback ['.$declutter.']',$email,$citations)=~/ok/) {
+               'Feedback ['.$declutter.']',$email,$citations,$feedurl)=~/ok/) {
 	$status.='<br>Error sending message to '.$_.'<br>';
       } else {
 	$sendsomething++;