Index: emailpage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/emailpage/emailpage.module,v
retrieving revision 1.3
diff -u -F^function -r1.3 emailpage.module
--- emailpage.module	26 Oct 2004 10:08:05 -0000	1.3
+++ emailpage.module	1 May 2005 19:08:42 -0000
@@ -49,8 +49,6 @@ function emailpage_link($type, $node=0, 
 
 function emailpage_page() {
   global $base_url;
-
-
   // first we check to see if they have reached the emailpage_flood_control limit
   // which is set in the settings.
   if($_COOKIE['emailpage_flood_count'] >= variable_get('emailpage_flood_control', 10)) {
@@ -60,15 +58,18 @@ function emailpage_page() {
   }
 
   $host=parse_url($base_url);
-
+  $nidnode = node_load(array('nid'=>$_GET['nid']));
+  
   // Check we have the $node-nid needed to send the page
   // and the comment fragment if they email a comment
   if(!$_COOKIE['referer']) {
     if($_GET['nid']) {
       if($_GET['cid']) {  // this takes care of links to specific comments
-        $nodelink=$base_url.'/'.url('node/view/'.$_GET['nid']."#comment-".$_GET['cid']);
+        $returnlink = url('node/'.$_GET['nid']."#comment-".$_GET['cid']);
+        $nodelink = $base_url.'/'.$returnlink;        
       } else {
-        $nodelink=$base_url.'/'.url('node/view/'.$_GET['nid']);
+        $returnlink = url('node/'.$_GET['nid']);
+        $nodelink = $base_url.'/'.$returnlink;
       }
       // Set the refering page in a cookie
       // 5mins should be enuf for anyone to put in a valid email address ;-)
@@ -78,13 +79,17 @@ function emailpage_page() {
     }
   }
 
-
-
   //  we need to check if the form has been posted..
   if($_POST) {
     if(!user_validate_mail($_POST['edit']['emailpage_addy']) && $_POST['edit']['emailpage_sender'] && $_COOKIE['referer']) {  // all is well, so lets send it!
       $headers="Reply-To: ".variable_get('emailpage_sender_addy', "")."\r\nFrom: ".variable_get('emailpage_sender_addy', "")."\r\n";
-      mail($_POST['edit']['emailpage_addy'], $_POST['edit']['emailpage_sender']." ".variable_get('emailpage_subject_line', "thought you'd like to see this"), $_COOKIE['referer']."\n\n".$_POST['edit']['emailpage_sender']." ".wordwrap(variable_get('emailpage_message',"someone thought you would like this page\n"), 72), $headers);
+      $message = $_POST['edit']['emailpage_sender']." ".wordwrap(variable_get('emailpage_message', "someone thought you would like this page\n\n"), 72);
+      $message .= $_POST['edit']['emailpage_title'] . "\n";
+      $message .= $_COOKIE['referer']."\n\n";
+      if ($_POST['edit']['emailpage_note']) {
+        $message .= "Note: ------------------\n\n" . $_POST['edit']['emailpage_note'];
+      }
+      mail($_POST['edit']['emailpage_addy'], $_POST['edit']['emailpage_sender']." ".variable_get('emailpage_subject_line', "thought you'd like to see this"), $message, $headers);
 
       // Delete the cookie
       // If we dont do this, sending other pages becomes messy.
@@ -95,32 +100,40 @@ function emailpage_page() {
 
       $content=variable_get('emailpage_success_msg', "Success!");
       variable_set('emailpage_total', variable_get('emailpage_total', 0)+1);
-	drupal_goto();
+      drupal_set_message(t('Your message has been sent. Thank you.'));
+	    drupal_goto($_POST['edit']['emailpage_return']);
       return;
       
     } else {
     
       $error="<p class=\"error\">You must supply your name and a valid email address</p>";
+      $form.=form_hidden('emailpage_return',$_POST['edit']['emailpage_return'] ? $_POST['edit']['emailpage_return'] : $returnlink);
+      $form.=form_hidden('emailpage_title',$_POST['edit']['emailpage_title'] ? $_POST['edit']['emailpage_title'] : $nidnode->title);
+      $form.='<p>' . t('Send a link to the page entitled: ') . '<strong>' . $nidnode->title . '</strong></p>';
       $form.=form_textfield(t("Your Name"), "emailpage_sender", $_POST['edit']['emailpage_sender'], 20, 30);
       $form.=form_textfield(t("Address to send to"), "emailpage_addy", $_POST['edit']['emailpage_addy'], 20, 30);
+      $form.=form_textarea(t("Note for your message"), "emailpage_note", $_POST['edit']['emailpage_note'], 40, 5);
       $form.=form_submit("Send it Now!","");
       $content.=$error;
       $content.=form($form, "post", url("emailpage"));
       $content.="<h2>Example  Email</h2>\n";
-      $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>".$nodelink."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>";
+    $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>\n\n<p>".$nidnode->title."\n<br />".$nodelink."</p>\n\n<p>Note:<br />\n[your note]</p>";
       print theme("page", $content);
 
     }
   } 
 
   if(!$_POST) {
+    $form.=form_hidden('emailpage_return',$_POST['edit']['emailpage_return'] ? $_POST['edit']['emailpage_return'] : $returnlink);
+    $form.=form_hidden('emailpage_title',$_POST['edit']['emailpage_title'] ? $_POST['edit']['emailpage_title'] : $nidnode->title);
+    $form.='<p>' . t('Send a link to the page entitled: ') . '<strong>' . $nidnode->title . '</strong></p>';
     $form.=form_textfield(t("Your Name"), "emailpage_sender", $_POST['edit']['emailpage_sender'], 20, 30);
     $form.=form_textfield(t("Address to send to"), "emailpage_addy", $_POST['edit']['emailpage_addy'], 20, 30);
+    $form.=form_textarea(t("Note for your message"), "emailpage_note", $_POST['edit']['emailpage_note'], 40, 5);
     $form.=form_submit("Send it Now!","");
     $content.=form($form, "post", url("emailpage"));
     $content.="<h2>Example  Email</h2>\n";
-    $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>".$nodelink."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>";
-
+    $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>\n\n<p>".$nidnode->title."\n<br />".$nodelink."</p>\n\n<p>Note:<br />\n[your note]</p>";
     print theme("page", $content);
   }
 }
