--- forward_46/forward.module	2006-02-23 17:19:56.000000000 -0600
+++ forward_47_ryans_version_that_im_fixing/forward.module	2006-03-09 13:52:55.000000000 -0600
@@ -20,386 +20,673 @@
  * Permissions
  */
 function forward_perm() {
-  return array("access forward", "administer forward");
+	return array("access forward", "administer forward");
 }
 
 function forward_help($section) {
-  if ($section == "admin/modules#description") {
-    return t("Enables users to forward pages to friends.");
-  }
+	if ($section == "admin/modules#description") {
+		return t("Enables users to forward pages to friends.");
+	}
 }
 
 /**
  * Form
  */
 function _forward_page() {
-  if (!user_access('access forward')) {
-    return message_access();
-  }
-
-  $nid = arg(1);
-  global $base_url, $user;
-  $host=parse_url($base_url);
-
-  if (arg(2) == 'email_ref'){
-    db_query("INSERT INTO {forward_log} (nid, type, timestamp) VALUES ('%d', '%s', %d)", $nid, "REF", time());
-    drupal_goto(drupal_get_path_alias('node/'.$nid));
-  }
-
-  if ($_POST && flood_is_allowed('forward_node', variable_get('forward_flood_control', 10))) {
-    $yemail     = $_POST['edit']['yemail'];
-    $recipients = $_POST['edit']['recipients'];
-    $subject    = $_POST['edit']['subject'];
-    $message    = $_POST['edit']['message'];
-    $nid        = $_POST['edit']['nid'];
-    $url        = $base_url.'/node/'.$nid;
-
-    // normalize address entries
-    $recipients = trim($recipients);
-    $recipients = str_replace(array("\r\n", "\n", "\r"), ', ', $recipients);
-    $recipients = str_replace(',', ', ', $recipients);
-    $recipients = str_replace(',  ', ', ', $recipients);
-
-    // convert addresses to an array
-    $recipient_addresses = explode(', ', $recipients);
-
-    $invalid = FALSE;
-    $badstr = FALSE;
-    $reason = '';
-    $badaddress = '';
-    
-    $arBadStr = array("Content-Type:", "MIME-Version:", "Content-Transfer-Encoding:", "bcc:", "cc:");
-    foreach($arBadStr as $tStr){
-      if (eregi($tStr, $yemail) || eregi($tStr, $subject)) {
-        $badstr = true;
-      }
-    }
-    if (strpos($yemail, "\r") !== false || strpos($yemail, "\n") !== false || $badstr == true) {
-      $reason .= '<li>'.t('Header injection attempt detected.  Do not enter line feed characters into the from field!').'</li>';
-      $invalid = TRUE;
-    }
-    if (user_validate_mail($yemail)){
-      $reason .= '<li>'.t('Your Email address is invalid.').'</li>';
-      $invalid = TRUE;
-    }
-    if ($recipients == '') {
-      $invalid = TRUE;
-      $reason .= '<li>'.t('You did not enter any recipients.').'</li>';
-    }
-    else {
-      foreach ($recipient_addresses as $address) {
-        if ((user_validate_mail($address)) && ($address != '')) {
-          $invalid = TRUE;
-          $reason .= '<li>'.t('One of your Recipient addresses is invalid.').'</li>';
-          $badaddress .= "$address\n";
-        }
-      }
-    }
-
-    if ($invalid == FALSE) {
-
-      //Get article information.
-      $content_query = 'SELECT n.title, n.teaser, n.created, n.format, u.name FROM {node} n INNER JOIN {users} u ON (n.uid=u.uid) WHERE n.nid='.$nid;
-      $content = db_fetch_object(db_query($content_query));
-
-      //If selected assemble dynamic footer block.
-      switch (variable_get('forward_dynamic_block','')) {
-        case 'node':
-    		  $dynamic_content = '<h3>'.t('Recent blog posts').'</h3>';
-    		  $query = "SELECT n.nid, n.title FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC";
-    		  $dynamic_content .= forward_top5_list($query, $base_url,'blog');
-    		  break;
-        case 'user':
-          $dynamic_content = '<h3>'.t('Who\'s new').'</h3>';
-		      $query = 'SELECT u.uid, u.name FROM {users} u WHERE status != 0 ORDER BY uid DESC';
-          $dynamic_content .= forward_top5_list($query, $base_url,'user');
-          break;
-        case 'comment':
-          $dynamic_content = '<h3>'.t('Recent comments').'</h3>';
-          $query = 'SELECT c.nid, c.cid, c.subject FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC';
-     	    $dynamic_content .= forward_top5_list($query, $base_url, 'comment');
-          break;
-        case 'popular':
-          $dynamic_content = '<h3>'.t('Most Popular Content').'</h3>';
-          $query = "SELECT n.nid, n.title FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid WHERE s.timestamp <> '0' AND n.status = 1 ORDER BY s.timestamp DESC";
-   		    $dynamic_content .= forward_top5_list($query, $base_url,'blog');
-          break;
-      }
-
-      $vars = array(
-	      'forward_header_image' => variable_get('forward_header_image', ''),
-	      'site_name' => variable_get('site_name', 'Drupal'),
-	      'yemail' => $yemail,
-	      'forward_message' => variable_get('forward_message', ''),
-	      'message' => $message,
-	      'base_url' => $base_url,
-	      'nid' => $nid,
-	      'title' => $content->title,
-	      'name' => $content->name,
-	      'teaser' => check_output($content->teaser, $content->format),
-	      'dynamic_content' => $dynamic_content,
-	      'forward_ad_footer' => variable_get('forward_ad_footer', ''),
-	      'forward_footer' => variable_get('forward_footer', '')
-      );
-      
-      $body = theme('forward_email', $vars);
-
-      if (variable_get('forward_prependsubject', 1) == 1) {
-        $subject = $yname.' '.$subject;
-      }
-
-  	  $headers = "From: $yemail\n";
-  	  $headers .= "MIME-Version: 1.0\n";
-  	  $headers .= "Content-type: text/html; charset=iso-8859-1\n";
-
-      mail("$recipients","$subject","$body", "$headers");
-      // insert record into db to record nid, type and timestamp of send
-      db_query("INSERT INTO {forward_log} (nid, type, timestamp) VALUES ('%d', '%s', %d)", $nid, "SENT", time());
-      variable_set('forward_total', variable_get('forward_total', 0) +1);
-      variable_set('forward_recipients', variable_get('forward_recipients', 0) + count($recipient_addresses));
-      
-      flood_register_event('forward_node');
-
-      drupal_set_message(variable_get('forward_thankyou', t('Thank you for your help in spreading the word about').' '.variable_get('site_name', 'drupal').'. '.t('We appreciate your help.')), 'status');
-	    drupal_goto(drupal_get_path_alias('node/'.$nid));
-    }
-    else {
-      $url     = $base_url.'/node/'.$nid;
-      drupal_set_message(t("Your submission has the following problem(s):").'<ul>'.$reason.'</ul>', 'error');
-      // May want to also show specific bad addresses using "$recipient_addresses"
-
-      $forward_form  = form_textfield(t('Your Email'), 'yemail', $yemail, 58, $user->email, NULL, NULL, TRUE);
-      $forward_form .= form_textarea(t('Send To'), 'recipients', str_replace(', ', '\n', $recipients), 50, 5, t('Enter multiple addresses on separate lines or separate them with commas.'), NULL, TRUE);
-      $forward_form .= form_item('Page Being Sent', $base_url.'/'.drupal_get_path_alias('node/'.$nid.''));
-      if (variable_get('forward_prependsubject', 1)) {
-        $prepend_text = t('Your name will appear at the beginning of the subject line.');
-      }
-      else {
-        $prepend_text = '';
-      }
-      $forward_form .= form_textfield(t('Message Subject'), 'subject', $subject, 58, NULL, $prepend_text, NULL, TRUE);
-      $forward_form .= form_item(t('Message Body'), variable_get('forward_message', ''));
-      $forward_form .= form_textarea(t('Your Personal Message'), 'message', $message, 50, 10, '', NULL, TRUE);
-      $forward_form .= form_hidden('nid', $nid);
-      $forward_form .= form_hidden('forward_footer', variable_get('forward_footer', ''));
-      $forward_form .= form_submit(t('Send Message'));
-
-      $form .= form_group(t('Message to Send'), $forward_form, '');
-
-      $output .= form($form, 'post');
-    }
-  }
-  elseif (! (flood_is_allowed('forward_node', variable_get('forward_flood_control', 10)))) {
-    $output = variable_get('forward_flood_error_msg', t('Sorry, you have reached the maximum number of emails allowed per user. Please try later'));
-  }
-  else {
-    $url    = $base_url.'/node/'.$nid;
-    $output = variable_get('forward_instructions', '<p>'.t('Thank you for your interest in spreading the word on').' '.variable_get('site_name', 'drupal').'.</p><p>'.t('NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.').'</p>');
-
-    $forward_form  = form_textfield(t('Your Email'), 'yemail', '', 58, $user->email, NULL, NULL, TRUE);
-    $forward_form .= form_textarea(t('Send To'), 'recipients', '', 50, 5, t('Enter multiple addresses on separate lines or separate them with commas.'), NULL, TRUE);
-    $forward_form .= form_item(t('Page Being Sent'), $base_url.'/'.drupal_get_path_alias('node/'.$nid.''));
-    if (variable_get('forward_prependsubject', 1)) {
-      $prepend_text = t('Your name will appear at the beginning of the subject line.');
-    }
-    else {
-      $prepend_text = '';
-    }
-    $forward_form .= form_textfield(t('Message Subject'), 'subject', variable_get('forward_subject_line', ''), 58, NULL, $prepend_text, NULL, TRUE);
-    $forward_form .= form_item(t('Message Body'), '<i>'.t('Your Name').'</i> '.variable_get('forward_message', ''));
-    $forward_form .= form_textarea(t('Your Personal Message'), 'message', '', 50, 10, '', NULL, TRUE);
-    $forward_form .= form_hidden('nid', $nid);
-    $forward_form .= form_submit(t('Send Message'));
-
-    $form .= form_group(t('Message to Send'), $forward_form, '');
-
-    $output .= form($form, 'post');
-  }
-  print theme("page", $output);
+	if (!user_access('access forward')) {
+		return drupal_access_denied;
+	}
+
+	$nid = arg(1);
+	global $base_url, $user;
+	$host=parse_url($base_url);
+
+	if (arg(2) == 'email_ref'){
+		db_query("INSERT INTO {forward_log} (nid, type, timestamp) VALUES ('%d', '%s', %d)", $nid, "REF", time());
+		drupal_goto(drupal_get_path_alias('node/'.$nid));
+	}
+
+	if ($_POST && flood_is_allowed('forward_node', variable_get('forward_flood_control', 10))) {
+		$yemail		 = $_POST['edit']['yemail'];
+		$recipients = $_POST['edit']['recipients'];
+		$subject		= $_POST['edit']['subject'];
+		$message		= $_POST['edit']['message'];
+		$nid				= $_POST['edit']['nid'];
+		$url				= $base_url.'/node/'.$nid;
+
+		// normalize address entries
+		$recipients = trim($recipients);
+		$recipients = str_replace(array("\r\n", "\n", "\r"), ', ', $recipients);
+		$recipients = str_replace(',', ', ', $recipients);
+		$recipients = str_replace(',	', ', ', $recipients);
+
+		// convert addresses to an array
+		$recipient_addresses = explode(', ', $recipients);
+
+		$invalid = FALSE;
+		$badstr = FALSE;
+		$reason = '';
+		$badaddress = '';
+		
+		$arBadStr = array("Content-Type:", "MIME-Version:", "Content-Transfer-Encoding:", "bcc:", "cc:");
+		foreach($arBadStr as $tStr){
+			if (eregi($tStr, $yemail) || eregi($tStr, $subject)) {
+				$badstr = true;
+			}
+		}
+		if (strpos($yemail, "\r") !== false || strpos($yemail, "\n") !== false || $badstr == true) {
+			$reason .= '<li>'.t('Header injection attempt detected.	Do not enter line feed characters into the from field!').'</li>';
+			$invalid = TRUE;
+		}
+		if (user_validate_mail($yemail)){
+			$reason .= '<li>'.t('Your Email address is invalid.').'</li>';
+			$invalid = TRUE;
+		}
+		if ($recipients == '') {
+			$invalid = TRUE;
+			$reason .= '<li>'.t('You did not enter any recipients.').'</li>';
+		}
+		else {
+			foreach ($recipient_addresses as $address) {
+				if ((user_validate_mail($address)) && ($address != '')) {
+					$invalid = TRUE;
+					$reason .= '<li>'.t('One of your Recipient addresses is invalid.').'</li>';
+					$badaddress .= "$address\n";
+				}
+			}
+		}
+
+		if ($invalid == FALSE) {
+
+			//Get article information.
+			$content_query = 'SELECT n.title, n.teaser, n.created, n.format, u.name FROM {node} n INNER JOIN {users} u ON (n.uid=u.uid) WHERE n.nid='.$nid;
+			$content = db_fetch_object(db_query($content_query));
+
+			//If selected assemble dynamic footer block.
+			switch (variable_get('forward_dynamic_block','')) {
+				case 'node':
+					$dynamic_content = '<h3>'.t('Recent blog posts').'</h3>';
+					$query = "SELECT n.nid, n.title FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC";
+					$dynamic_content .= forward_top5_list($query, $base_url,'blog');
+					break;
+				case 'user':
+					$dynamic_content = '<h3>'.t('Who\'s new').'</h3>';
+					$query = 'SELECT u.uid, u.name FROM {users} u WHERE status != 0 ORDER BY uid DESC';
+					$dynamic_content .= forward_top5_list($query, $base_url,'user');
+					break;
+				case 'comment':
+					$dynamic_content = '<h3>'.t('Recent comments').'</h3>';
+					$query = 'SELECT c.nid, c.cid, c.subject FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC';
+					$dynamic_content .= forward_top5_list($query, $base_url, 'comment');
+					break;
+				case 'popular':
+					$dynamic_content = '<h3>'.t('Most Popular Content').'</h3>';
+					$query = "SELECT n.nid, n.title FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid WHERE s.timestamp <> '0' AND n.status = 1 ORDER BY s.timestamp DESC";
+					$dynamic_content .= forward_top5_list($query, $base_url,'blog');
+					break;
+			}
+
+			$vars = array(
+				'forward_header_image' => variable_get('forward_header_image', ''),
+				'site_name' => variable_get('site_name', 'Drupal'),
+				'yemail' => $yemail,
+				'forward_message' => variable_get('forward_message', ''),
+				'message' => $message,
+				'base_url' => $base_url,
+				'nid' => $nid,
+				'title' => $content->title,
+				'name' => $content->name,
+				'teaser' => check_markup($content->teaser, $content->format),
+				'dynamic_content' => $dynamic_content,
+				'forward_ad_footer' => variable_get('forward_ad_footer', ''),
+				'forward_footer' => variable_get('forward_footer', '')
+			);
+			
+			$body = theme('forward_email', $vars);
+
+			if (variable_get('forward_prependsubject', 1) == 1) {
+				$subject = $yname.' '.$subject;
+			}
+
+			$headers = "From: $yemail\n";
+			$headers .= "MIME-Version: 1.0\n";
+			$headers .= "Content-type: text/html; charset=iso-8859-1\n";
+
+			mail("$recipients","$subject","$body", "$headers");
+			// insert record into db to record nid, type and timestamp of send
+			db_query("INSERT INTO {forward_log} (nid, type, timestamp) VALUES ('%d', '%s', %d)", $nid, "SENT", time());
+			variable_set('forward_total', variable_get('forward_total', 0) +1);
+			variable_set('forward_recipients', variable_get('forward_recipients', 0) + count($recipient_addresses));
+			
+			flood_register_event('forward_node');
+
+			drupal_set_message(variable_get('forward_thankyou', t('Thank you for your help in spreading the word about').' '.variable_get('site_name', 'drupal').'. '.t('We appreciate your help.')), 'status');
+			drupal_goto(drupal_get_path_alias('node/'.$nid));
+		}
+		else {
+			$url		 = $base_url.'/node/'.$nid;
+			drupal_set_message(t("Your submission has the following problem(s):").'<ul>'.$reason.'</ul>', 'error');
+			// May want to also show specific bad addresses using "$recipient_addresses"
+
+			$form['forward_form'] = array(
+				'#title' => t('Message to Send'),
+				'#type' => 'fieldset',
+				'#collapsible' => false,
+				'#collapsed' => false,
+			);
+			$form['forward_form']['yemail'] = array(
+				'#type' => 'textfield',
+				'#title' => t('Your Email'),
+				'#default_value' => $yemail,
+				'#size' => 58,
+				'#maxlength' => $user->email,
+				'#description' => NULL,
+				'#attributes' => NULL,
+				'#required' => TRUE,
+			);
+			$form['forward_form']['recipients'] = array(
+				'#type' => 'textarea',
+				'#title' => t('Send To'),
+				'#default_value' => str_replace(', ', '\n', $recipients),
+				'#cols' => 50,
+				'#rows' => 5,
+				'#description' => t('Enter multiple addresses on separate lines or separate them with commas.'),
+				'#attributes' => NULL,
+				'#required' => TRUE,
+			);
+			$form['forward_form'][] = array(
+			'#type' => 'item',
+			'#title' => 'Page Being Sent',
+			'#default_value' => $base_url.'/'.drupal_get_path_alias('node/'.$nid.''),
+			);
+			
+			if (variable_get('forward_prependsubject', 1)) {
+				$prepend_text = t('Your name will appear at the beginning of the subject line.');
+			}
+			else {
+				$prepend_text = '';
+			}
+			
+			$form['forward_form']['subject'] = array(
+				'#type' => 'textfield',
+				'#title' => t('Message Subject'),
+				'#default_value' => $subject,
+				'#size' => 58,
+				'#maxlength' => NULL,
+				'#description' => $prepend_text,
+				'#attributes' => NULL,
+				'#required' => TRUE,
+			);
+			$form['forward_form'][] = array(
+				'#type' => 'item',
+				'#title' => t('Message Body'),
+				'#default_value' => variable_get('forward_message', ''),
+			);
+			$form['forward_form']['message'] = array(
+				'#type' => 'textarea',
+				'#title' => t('Your Personal Message'),
+				'#default_value' => $message,
+				'#cols' => 50,
+				'#rows' => 10,
+				'#description' => '',
+				'#attributes' => NULL,
+				'#required' => TRUE,
+			);
+			$form['forward_form']['nid'] = array(
+				'#type' => 'hidden',
+				'#value' => $nid,
+			);
+			$form['forward_form']['forward_footer'] = array(
+				'#type' => 'hidden',
+				'#value' => variable_get('forward_footer', ''),
+			);
+			$form['forward_form'][] = array(
+				'#type' => 'submit',
+				'#value' => t('Send Message'),
+			);
+			$form['#method'] = 'post';
+			$output = drupal_get_form('_forward_page', $form);
+		}
+	}
+	elseif (! (flood_is_allowed('forward_node', variable_get('forward_flood_control', 10)))) {
+		$output = variable_get('forward_flood_error_msg', t('Sorry, you have reached the maximum number of emails allowed per user. Please try later'));
+	}
+	else {
+		$url = $base_url.'/node/'.$nid;
+		$output = variable_get('forward_instructions', '<p>'.t('Thank you for your interest in spreading the word on').' '.variable_get('site_name', 'drupal').'.</p><p>'.t('NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.').'</p>');
+
+		$form['forward_form'] = array(
+			'#title' => t('Message to Send'),
+			'#type' => 'fieldset',
+			'#collapsible' => false,
+			'#collapsed' => false,
+		);
+		$form['forward_form']['yemail'] = array(
+			'#type' => 'textfield',
+			'#title' => t('Your Email'),
+			'#default_value' => '',
+			'#size' => 58,
+			'#maxlength' => $user->email,
+			'#description' => NULL,
+			'#attributes' => NULL,
+			'#required' => TRUE,
+		);
+		$form['forward_form']['recipients'] = array(
+			'#type' => 'textarea',
+			'#title' => t('Send To'),
+			'#default_value' => '',
+			'#cols' => 50,
+			'#rows' => 5,
+			'#description' => t('Enter multiple addresses on separate lines or separate them with commas.'),
+			'#attributes' => NULL,
+			'#required' => TRUE,
+		);
+		$form['forward_form'][] = array(
+			'#type' => 'item',
+			'#title' => t('Page Being Sent'),
+			'#default_value' => $base_url.'/'.drupal_get_path_alias('node/'.$nid.''),
+		);
+		
+		if (variable_get('forward_prependsubject', 1)) {
+			$prepend_text = t('Your name will appear at the beginning of the subject line.');
+		}
+		else {
+			$prepend_text = '';
+		}
+		
+		$form['forward_form']['subject'] = array(
+			'#type' => 'textfield',
+			'#title' => t('Message Subject'),
+			'#default_value' => variable_get('forward_subject_line', ''),
+			'#size' => 58,
+			'#maxlength' => NULL,
+			'#description' => $prepend_text,
+			'#attributes' => NULL,
+			'#required' => TRUE,
+		);
+		$form['forward_form'][] = array(
+			'#type' => 'item',
+			'#title' => t('Message Body'),
+			'#default_value' => '<i>'.t('Your Name').'</i> '.variable_get('forward_message', ''),
+		);
+		$form['forward_form']['message'] = array(
+			'#type' => 'textarea',
+			'#title' => t('Your Personal Message'),
+			'#default_value' => '',
+			'#cols' => 50,
+			'#rows' => 10,
+			'#description' => '',
+			'#attributes' => NULL,
+			'#required' => TRUE,
+		);
+		$form['forward_form']['nid'] = array(
+			'#type' => 'hidden',
+			'#value' => $nid,
+		);
+		$form['forward_form'][] = array(
+			'#type' => 'submit',
+			'#value' => t('Send Message'),
+		);
+				
+		$form['#method'] = 'post';
+		$output = drupal_get_form('_forward_page', $form);
+	}
+	return $output;
 }
 
 /**
  * Generate links for pages
  */
 function forward_link($type, $node=0, $main=0) {
-  if (user_access('access forward') && (variable_get('forward_form_type', 'link') == "link")){
-    $links=array();
-    if (($type == 'system')) {
-    // URL, page title, func called for page content, arg, 1 = don't disp menu
-      menu('forward', t('email this page'), 'forward_page', 1, 1);
-    }
-
-    // This var is set in the settings section under the admin/modules/forward section
-    // It shows 'email this $nodetype' or 'email this page'
-    $forward_link_type = variable_get('forward_link_type', 0);
-    if ($forward_link_type) {
-      if ($type == 'comment') {
-        $forward_link_type = 'comment';
-        $links[] = l(t("email this $forward_link_type"), "forward/$node->nid&cid=$node->cid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
-        return $links;
-      }
-      $forward_link_type = $node->type;
-    }
-    else $forward_link_type = 'page';
-
-    if ($main) {  // not on an index page
-      if (variable_get('forward_show_on_main', 0)) {
-        $links[] = l(t("email this $forward_link_type"), "forward/$node->nid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
-        return $links;
-      }
-    }
-    else { // not on a main page
-      $links[] = l(t("email this $forward_link_type"), "forward/$node->nid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
-      return $links;
-    }
-  }
+	if (user_access('access forward') && (variable_get('forward_form_type', 'link') == "link")){
+		$links=array();
+		if (($type == 'system')) {
+		// URL, page title, func called for page content, arg, 1 = don't disp menu
+			menu('forward', t('email this page'), 'forward_page', 1, 1);
+		}
+
+		// This var is set in the settings section under the admin/modules/forward section
+		// It shows 'email this $nodetype' or 'email this page'
+		$forward_link_type = variable_get('forward_link_type', 0);
+		if ($forward_link_type) {
+			if ($type == 'comment') {
+				$forward_link_type = 'comment';
+				$links[] = l(t("email this $forward_link_type"), "forward/$node->nid&cid=$node->cid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
+				return $links;
+			}
+			$forward_link_type = $node->type;
+		}
+		else $forward_link_type = 'page';
+
+		if ($main) {	// not on an index page
+			if (variable_get('forward_show_on_main', 0)) {
+				$links[] = l(t("email this $forward_link_type"), "forward/$node->nid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
+				return $links;
+			}
+		}
+		else { // not on a main page
+			$links[] = l(t("email this $forward_link_type"), "forward/$node->nid", array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
+			return $links;
+		}
+	}
 }
 
 /**
  * Generate nodeapi integration, foward signup
  */
 function forward_nodeapi(&$node, $op, $arg = 0){
-  if (variable_get('forward_form_type', 'link') == "form"){
-    switch ($op) {
-      case 'view':
-        //$url    = $base_url.'/node/'.$nid;
-        //$output = variable_get('forward_instructions', "<p>Thank you for your interest in spreading the word on ".variable_get('site_name', 'drupal').".</p><p>NOTE: We only request an email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email addresses.</p>");
-
-        $forward_form = form_textfield(t('Your Email'), 'yemail', '', 58, $user->email, NULL, NULL, TRUE);
-        $forward_form .= form_textarea(t('Send To'), 'recipients', '', 50, 2, 'Enter multiple addresses on separate lines or separate them with commas.', NULL, TRUE);
-        //$forward_form .= form_item('Page Being Sent', $base_url.'/'.drupal_get_path_alias('node/'.$nid.''));
-        if (variable_get('forward_prependsubject', 1)) {
-          $prepend_text = t('Your name will appear at the beginning of the subject line.');
-        }
-        else {
-          $prepend_text = '';
-        }
-        $forward_form .= form_textfield(t('Message Subject'), 'subject', variable_get('forward_subject_line', ''), 58, NULL, $prepend_text, NULL, TRUE);
-        //$forward_form .= form_item(t('Message Body'), '<i>'.t('Your Name').'</i> '.variable_get('forward_message', ''));
-        $forward_form .= form_textarea(t('Your Personal Message'), 'message', '', 50, 4, '', NULL, TRUE);
-        $forward_form .= form_hidden('nid', $node->nid);
-        $forward_form .= form_submit(t('Send Message'));
-
-        $attrib = array("class" => "foward_box");
-        $form = form($forward_form, 'post', url('forward/'.$node->nid));
-        $output = form_group(t('Tell a friend'), $form, '');
-
-        $node->body .= $output;
-      break;
-    }
-  }
+	if (variable_get('forward_form_type', 'link') == "form"){
+		switch ($op) {
+			case 'view':
+				//$url		= $base_url.'/node/'.$nid;
+				//$output = variable_get('forward_instructions', "<p>Thank you for your interest in spreading the word on ".variable_get('site_name', 'drupal').".</p><p>NOTE: We only request an email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email addresses.</p>");
+
+				$form['forward_api_form'] = array(
+					'#type' => 'fieldset',
+					'#title' => t('Tell a friend'),
+					'#description' => '',
+					'#collapsible' => false,
+					'#collapsed' => false,
+				);
+				
+				$form['forward_api_form']['yemail'] = array(
+					'#type' => 'textfield',
+					'#title' => t('Your Email'),
+					'#default_value' => '',
+					'#size' => 58,
+					'#maxlength' => $user->email,
+					'#description' => NULL,
+					'#attributes' => NULL,
+					'#required' => TRUE,
+				);
+				$form['forward_api_form']['recipients'] = array(
+					'#type' => 'textarea',
+					'#title' => t('Send To'),
+					'#default_value' => '',
+					'#cols' => 50,
+					'#rows' => 2,
+					'#description' => 'Enter multiple addresses on separate lines or separate them with commas.',
+					'#attributes' => NULL,
+					'#required' => TRUE,
+				);
+
+				if (variable_get('forward_prependsubject', 1)) {
+					$prepend_text = t('Your name will appear at the beginning of the subject line.');
+				}
+				else {
+					$prepend_text = '';
+				}
+				
+				$form['forward_api_form']['subject'] = array(
+					'#type' => 'textfield',
+					'#title' => t('Message Subject'),
+					'#default_value' => variable_get('forward_subject_line', ''),
+					'#size' => 58,
+					'#maxlength' => NULL,
+					'#description' => $prepend_text,
+					'#attributes' => NULL,
+					'#required' => TRUE,
+				);
+				$form['forward_api_form']['message'] = array(
+					'#type' => 'textarea',
+					'#title' => t('Your Personal Message'),
+					'#default_value' => '',
+					'#cols' => 50,
+					'#rows' => 4,
+					'#description' => '',
+					'#attributes' => NULL,
+					'#required' => TRUE,
+				);
+				$form['forward_api_form']['nid'] = array(
+					'#type' => 'hidden',
+					'#value' => $node->nid,
+				);
+				$form['forward_api_form'][] = array(
+					'#type' => 'submit',
+					'#value' => t('Send Message'),
+				);
+
+				/*$forward_form .= form_textfield(t('Message Subject'), 'subject', variable_get('forward_subject_line', ''), 58, NULL, $prepend_text, NULL, TRUE);
+				$forward_form .= form_textarea(t('Your Personal Message'), 'message', '', 50, 4, '', NULL, TRUE);
+				$forward_form .= form_hidden('nid', $node->nid);
+				$forward_form .= form_submit(t('Send Message'));*/
+
+				$attrib = array("class" => "foward_box");
+				$form['forward_api_form']['#method'] = 'post';
+				$form['forward_api_form']['#action'] = url('forward/'.$node->nid);
+				$output = drupal_get_form('forward_nodeapi', $form);
+				
+				$node->body .= $output;
+			break;
+		}
+	}
 }
 
 /**
  * Menu Hooks
  */
 function forward_menu($may_cache) {
-  $items = array();
+	$items = array();
 
-  //if ($may_cache) {
-    $items[] = array(
-      'path'     => 'forward',
-      'title'    => t('forward this page'),
-      'callback' => '_forward_page',
-      'access'   => (user_access('access content')),
-      'type'     => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path'     => 'admin/forward',
-      'title'    => t('forward tracking'),
-      'callback' => 'forward_tracking',
-      'access'   => (user_access('administer forward')),
-    );
-  //}
-  return $items;
+	//if ($may_cache) {
+		$items[] = array(
+			'path'		 => 'forward',
+			'title'		=> t('forward this page'),
+			'callback' => '_forward_page',
+			'access'	 => (user_access('access content')),
+			'type'		 => MENU_CALLBACK
+		);
+		$items[] = array(
+			'path'		 => 'admin/forward',
+			'title'		=> t('forward tracking'),
+			'callback' => 'forward_tracking',
+			'access'	 => (user_access('administer forward')),
+		);
+	//}
+	return $items;
 }
 
 /**
  * Administration Page
  */
 function forward_settings() {
-  global $base_url;
+	global $base_url;
 
-  $dyn_options = array(
-    'node' => t('Latest Blog Articles'),
-    'user' => t('Latest Users'),
-    'comment' => t('Latest Comments'),
-    'popular' => t('Most Popular Content'),
-    ' ' => t('None')
-    );
-
-  // Permission Check
-  if (!user_access('administer forward')) {
-    return message_access();
-  }
-
-  $host=parse_url($base_url);
-
-  $output = '<p><strong>'.variable_get('forward_total', 0).'</strong> '.t('emails sent to').' <strong>'.variable_get('forward_recipients', 0).'</strong> '.t('recipients').'</p>';
-  
-  // Administrative Options
-  $forward_settings .= form_checkbox(t('Reset Total Counter'), 'forward_total', 0, 0);
-  $forward_settings .= form_checkbox(t('Reset Recipient Counter'), 'forward_recipients', 0, 0);
-  $forward_settings .= form_checkbox(t('Use Node Type in Link'), 'forward_link_type', 1, variable_get('forward_link_type', FALSE), t('If checked, the link will read &quot;email this <em>nodetype</em>&quot;; if not, it will just read &quot;email this page&quot;'));
-  //$forward_settings .= form_select(t('Form Type'), 'forward_form_type', variable_get('forward_link_type', "link"), array("link" => "link", "form" => "form"), 'Select link for a forward this page link, or form to use a collapsible forwarding form.');
-  $forward_settings .= form_select(t('Flood Control'), 'forward_flood_control', variable_get('forward_flood_control', 10), array(1 => "1", 5 => "5", 10 => "10", 15 => "15", 20 => "20", 25 => "25", 30 => "30", 35 => "35", 40 => "40", 50 => "50"), "How many times a user can use the form in a one hour period. This will help prevent the forward module from being used for spamming.");
-  $forward_settings .= form_textarea(t('Flood Control Error'), 'forward_flood_error', variable_get('forward_flood_error_msg', t('In order to prevent spamming, we limit the number of messages you can send in a one hour period.  Please retry later.')), 40, 10, 'This text appears if a user exceeds the flood control limit.');
-
-  // Page Text Values
-  $forward_pagetext .= form_textarea(t('Forward Instructions'), 'forward_instructions', variable_get('forward_instructions', '<p>'.t('Thank you for your interest in spreading the word on').' '.variable_get('site_name', 'drupal').'.</p><p>'.t('NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.').'</p>'), 40, 10, 'This message will be displayed above the form.');
-  $forward_pagetext .= form_textarea(t('Thank You Message'), 'forward_thankyou', variable_get('forward_thankyou', t('Thank you for your help in spreading the word about').' '.variable_get('site_name', 'drupal').'. '.t('We appreciate your help.')), 40, 10, 'This message will be displayed after the user successfully submits the form.');
-
-  // Form Default Values
-  $forward_defaults .= form_textfield(t('From Address'), 'forward_sender_addy', variable_get('forward_sender_addy', "NoReply@".$host['host']), 30, 40, t('The address to send from.  Should be a functioning email address.'));
-  $forward_defaults .= form_textfield(t('Header Image for Email'), 'forward_header_image', variable_get('forward_header_image',''), 40, 100, t('Enter the URL of the image to as a logo at the top of forwarded pages.'), FALSE);
-  $forward_defaults .= form_checkbox(t('Prepend Subject With Sender\'s Name'), 'forward_prependsubject', 1, variable_get('forward_prependsubject', TRUE), t('If checked, the subject line in the email will being with the sender\'s name.  Be sure to edit the default value of the subject field accordingly.'));
-  $forward_defaults .= form_textfield(t('Message Subject'), 'forward_subject_line', variable_get('forward_subject_line', t('thought you\'d like to see this')), 30, 40, "Default subject line");
-  $forward_defaults .= form_textarea(t('Message Body'), 'forward_message', variable_get('forward_message', ' '.t('thought you would like to see this page:')), 40, 10, 'This message will be prepended with the sender\'s full name.  The sender will be able to add their own message after this.');
-  $forward_defaults .= form_textarea(t('Oranization Ad'), 'forward_ad_footer', variable_get('forward_ad_footer', " "), 40, 10, t('This message will be just above the footer message in the email.'));
-  $forward_defaults .= form_textarea(t('Footer Message'), 'forward_footer', variable_get('forward_footer', " "), 40, 4, t('This message will be postpended as a footer message to the email.')); //not new
-  $forward_defaults .= form_radios(t('Dynamic Block'), 'forward_dynamic_block', variable_get('forward_dynamic_block', " "), $dyn_options, t('Choose the dynamic block to send with these emails'), TRUE, NULL );
-
-  $output .= form_group(t('Administrative Options'), $forward_settings, '');
-  $output .= form_group(t('Page Text Values'), $forward_pagetext, '');
-  $output .= form_group(t('Form Default Values'), $forward_defaults, '');
-
-  return $output;
+	$dyn_options = array(
+		'node' => t('Latest Blog Articles'),
+		'user' => t('Latest Users'),
+		'comment' => t('Latest Comments'),
+		'popular' => t('Most Popular Content'),
+		' ' => t('None')
+		);
+
+	// Permission Check
+	if (!user_access('administer forward')) {
+		return drupal_access_denied;
+	}
+
+	$host=parse_url($base_url);
+
+	//$output = '<p><strong>'.variable_get('forward_total', 0).'</strong> '.t('emails sent to').' <strong>'.variable_get('forward_recipients', 0).'</strong> '.t('recipients').'</p>';
+	
+	// Administrative Options
+	$form['admin_options'] = array(
+		'#type' => 'fieldset',
+		'#title' => t('Administrative Options'),
+		'#description' => '',
+		'#collapsible' => true,
+		'#collapsed' => false,
+	);
+	$form['admin_options']['forward_total'] = array(
+		'#type' => 'checkbox',
+		'#title' => t('Reset Total Counter'),
+		'#return_value' => 0,
+		'#default_value' => 0,
+	);
+	$form['admin_options']['forward_recipients'] = array(
+		'#type' => 'checkbox',
+		'#title' => t('Reset Recipient Counter'),
+		'#return_value' => 0,
+		'#default_value' => 0,
+	);
+	$form['admin_options']['forward_link_type'] = array(
+		'#type' => 'checkbox',
+		'#title' => t('Use Node Type in Link'),
+		'#return_value' => 1,
+		'#default_value' => variable_get('forward_link_type', FALSE),
+		'#description' => t('If checked, the link will read &quot;email this <em>nodetype</em>&quot;; if not, it will just read &quot;email this page&quot;'),
+	);
+	$form['admin_options']['forward_flood_control'] = array(
+		'#type' => 'select',
+		'#title' => t('Flood Control'),
+		'#default_value' => variable_get('forward_flood_control', 10),
+		'#options' => array(1 => "1", 5 => "5", 10 => "10", 15 => "15", 20 => "20", 25 => "25", 30 => "30", 35 => "35", 40 => "40", 50 => "50"),
+		'#description' => "How many times a user can use the form in a one hour period. This will help prevent the forward module from being used for spamming.",
+	);
+	$form['admin_options']['forward_flood_error'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Flood Control Error'),
+		'#default_value' => variable_get('forward_flood_error_msg', t('In order to prevent spamming, we limit the number of messages you can send in a one hour period.	Please retry later.')),
+		'#cols' => 40,
+		'#rows' => 10,
+		'#description' => 'This text appears if a user exceeds the flood control limit.',
+	);
+
+	// Page Text Values
+	$form['page_options'] = array(
+		'#type' => 'fieldset',
+		'#title' => t('Page Text Values'),
+		'#description' => '',
+		'#collapsible' => true,
+		'#collapsed' => true,
+	);
+	$form['page_options']['forward_instructions'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Forward Instructions'),
+		'#default_value' => variable_get('forward_instructions', '<p>'.t('Thank you for your interest in spreading the word on').' '.variable_get('site_name', 'drupal').'.</p><p>'.t('NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.').'</p>'),
+		'#cols' => 40,
+		'#rows' => 10,
+		'#description' => 'This message will be displayed above the form.',
+	);
+	$form['page_options']['forward_thankyou'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Thank You Message'),
+		'#default_value' => variable_get('forward_thankyou', t('Thank you for your help in spreading the word about').' '.variable_get('site_name', 'drupal').'. '.t('We appreciate your help.')),
+		'#cols' => 40,
+		'#rows' => 10,
+		'#description' => 'This message will be displayed after the user successfully submits the form.',
+	);
+
+	// Form Default Values
+	$form['form_options'] = array(
+		'#type' => 'fieldset',
+		'#title' => t('Form Default Values'),
+		'#description' => '',
+		'#collapsible' => true,
+		'#collapsed' => true,
+	);
+	$form['form_options']['forward_sender_addy'] = array(
+		'#type' => 'textfield',
+		'#title' => t('From Address'),
+		'#default_value' => variable_get('forward_sender_addy', "NoReply@".$host['host']),
+		'#size' => 30,
+		'#maxlength' => 40,
+		'#description' => t('The address to send from.	Should be a functioning email address.'),
+	);
+	$form['form_options']['forward_header_image'] = array(
+		'#type' => 'textfield',
+		'#title' => t('Header Image for Email'),
+		'#default_value' => variable_get('forward_header_image',''),
+		'#size' => 40,
+		'#maxlength' => 100,
+		'#description' => t('Enter the URL of the image to as a logo at the top of forwarded pages.'),
+		'#attributes' => FALSE,
+	);
+	$form['form_options']['forward_prependsubject'] = array(
+		'#type' => 'checkbox',
+		'#title' => t('Prepend Subject With Sender\'s Name'),
+		'#return_value' => 1,
+		'#default_value' => variable_get('forward_prependsubject', TRUE),
+		'#description' => t('If checked, the subject line in the email will being with the sender\'s name.	Be sure to edit the default value of the subject field accordingly.'),
+	);
+	$form['form_options']['forward_subject_line'] = array(
+		'#type' => 'textfield',
+		'#title' => t('Message Subject'),
+		'#default_value' => variable_get('forward_subject_line', t('thought you\'d like to see this')),
+		'#size' => 30,
+		'#maxlength' => 40,
+		'#description' => "Default subject line",
+	);
+	$form['form_options']['forward_message'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Message Body'),
+		'#default_value' => variable_get('forward_message', ' '.t('thought you would like to see this page:')),
+		'#cols' => 40,
+		'#rows' => 10,
+		'#description' => 'This message will be prepended with the sender\'s full name.	The sender will be able to add their own message after this.',
+	);
+	$form['form_options']['forward_ad_footer'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Oranization Ad'),
+		'#default_value' => variable_get('forward_ad_footer', " "),
+		'#cols' => 40,
+		'#rows' => 10,
+		'#description' => t('This message will be just above the footer message in the email.'),
+	);
+	$form['form_options']['forward_footer'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Footer Message'),
+		'#default_value' => variable_get('forward_footer', " "),
+		'#cols' => 40,
+		'#rows' => 4,
+		'#description' => t('This message will be postpended as a footer message to the email.'),
+	);
+	$form['form_options']['forward_dynamic_block'] = array(
+		'#type' => 'radios',
+		'#title' => t('Dynamic Block'),
+		'#default_value' => variable_get('forward_dynamic_block', " "),
+		'#options' => $dyn_options,
+		'#description' => t('Choose the dynamic block to send with these emails'),
+		'#required' => TRUE,
+		'#attributes' => NULL,
+	);
+	
+	return $form;
 }
 
 /**
  * Forward Tracking Page
  */
 function forward_tracking() {
-  $header = array(
-    array('data' => t('Time'), 'field' => 'f.timestamp', 'sort' => 'desc'),
-    array('data' => t('Type'), 'field' => 'f.type'),
-    array('data' => t('Path')),
-    array('data' => t('Title'), 'field' => 'n.title')
-  );
-
-  $result = pager_query('SELECT f.*, n.title FROM {forward_log} f LEFT JOIN {node} n ON f.nid = n.nid'. tablesort_sql($header), 30, 0, NULL);
-  if ($access = db_fetch_object($result)) {
-    while ($log = db_fetch_object($result)) {
-      $_path = drupal_get_path_alias('node/'.$log->nid);
-      $rows[] = array(
-        array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
-        $log->type,
-        l($_path, $_path),
-        l(_forward_column_width($log->title), $_path));
-    }
-    if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
-      $rows[] = array(array('data' => $pager, 'colspan' => '4'));
-    }
-
-    $output = '<p><strong>'.variable_get('forward_total', 0).'</strong> '.t('emails sent to').' <strong>'.variable_get('forward_recipients', 0).'</strong> '.t('recipients').'</p>';
-    $output .= theme('table', $header, $rows);
-    print theme("page", $output);
-  }
-  else {
-    $output = '<p>'.t('No one has used Forward yet.').'</p>';
-  }
-  print theme("page", $output);
-  drupal_set_title(t('Forward Tracking'));
+	$header = array(
+		array('data' => t('Time'), 'field' => 'f.timestamp', 'sort' => 'desc'),
+		array('data' => t('Type'), 'field' => 'f.type'),
+		array('data' => t('Path')),
+		array('data' => t('Title'), 'field' => 'n.title')
+	);
+
+	$result = pager_query('SELECT f.*, n.title FROM {forward_log} f LEFT JOIN {node} n ON f.nid = n.nid'. tablesort_sql($header), 30, 0, NULL);
+	if ($access = db_fetch_object($result)) {
+		while ($log = db_fetch_object($result)) {
+			$_path = drupal_get_path_alias('node/'.$log->nid);
+			$rows[] = array(
+				array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+				$log->type,
+				l($_path, $_path),
+				l(_forward_column_width($log->title), $_path));
+		}
+		if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+			$rows[] = array(array('data' => $pager, 'colspan' => '4'));
+		}
+
+		$output = '<p><strong>'.variable_get('forward_total', 0).'</strong> '.t('emails sent to').' <strong>'.variable_get('forward_recipients', 0).'</strong> '.t('recipients').'</p>';
+		$output .= theme('table', $header, $rows);
+	}
+	else {
+		$output = '<p>'.t('No one has used Forward yet.').'</p>';
+	}
+	return $output;
+	drupal_set_title(t('Forward Tracking'));
 }
 
 
@@ -407,66 +694,73 @@
  * Implementation of hook_block().
  */
 function forward_block($op = 'list', $delta = 0, $edit = array()) {
-  switch ($op) {
-    case 'list':
-      $blocks[0]['info'] = t('Most Emailed');
-      return $blocks;
-    case 'configure':
-      $block_options = array (
-        'today' => t('Most Emailed Today'),
-        'week' => t('Most Emailed This Week'),
-        'allTime' => t('Most Emailed of All Time'),
-        'recent' => t('Most Recently Emailed')
-      );
-	    $output = form_radios(t('Block Type'), 'forward_block_type', variable_get('forward_block_type', " "), $block_options, t('Choose the block type'), NULL, TRUE	);
-      return $output;
-    case 'save':
-      variable_set('forward_block_type', $edit['forward_block_type']);
-      break;
-    case 'view':
-      if (user_access('access content')) {
-        switch (variable_get('forward_block_type','allTime')) {
-          case 'today':
-            $pastday = time()-(24 * 60 * 60);
-      			$query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastday.' GROUP BY n.nid DESC';
-      			$block['content'] = node_title_list(db_query_range($query, 0, 5), t("Today's Most Emailed"));
-            break;
-          case 'week':
-            $pastweek = time()-(7 * 24 * 60 * 60);
-      			$query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastweek.' GROUP BY n.nid DESC';
-      			$block['content'] = node_title_list(db_query_range($query, 0, 5), t("This Week's Most Emailed"));
-            break;
-          case 'allTime':
-			      $query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" GROUP BY n.nid DESC';
-		        $block['content'] = node_title_list(db_query_range($query, 0, 5), t("Most Emalied"));
-            break;
-          case 'recent':
-            $query="SELECT DISTINCT n.nid, n.title FROM {node} n LEFT JOIN {forward_log} s ON s.nid = n.nid WHERE s.timestamp <> '0' AND s.type='SENT' AND n.status = 1 ORDER BY s.timestamp DESC";
-		        $block['content'] = node_title_list(db_query_range($query, 0, 5), t("Most Recently Emailed"));
-            break;
-        }
-        return $block;
-      }
-  }
+	switch ($op) {
+		case 'list':
+			$blocks[0]['info'] = t('Most Emailed');
+			return $blocks;
+		case 'configure':
+			$block_options = array (
+				'today' => t('Most Emailed Today'),
+				'week' => t('Most Emailed This Week'),
+				'allTime' => t('Most Emailed of All Time'),
+				'recent' => t('Most Recently Emailed')
+			);
+			$form['forward_block_type'] = array(
+				'#type' => 'radios',
+				'#title' => t('Block Type'),
+				'#default_value' =>  variable_get('forward_block_type', " "),
+				'#options' => $block_options,
+				'#description' => t('Choose the block type'),
+			);
+			return $form;
+			
+		case 'save':
+			variable_set('forward_block_type', $edit['forward_block_type']);
+			break;
+		case 'view':
+			if (user_access('access content')) {
+				switch (variable_get('forward_block_type','allTime')) {
+					case 'today':
+						$pastday = time()-(24 * 60 * 60);
+						$query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastday.' GROUP BY n.nid DESC';
+						$block['content'] = node_title_list(db_query_range($query, 0, 5), t("Today's Most Emailed"));
+						break;
+					case 'week':
+						$pastweek = time()-(7 * 24 * 60 * 60);
+						$query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastweek.' GROUP BY n.nid DESC';
+						$block['content'] = node_title_list(db_query_range($query, 0, 5), t("This Week's Most Emailed"));
+						break;
+					case 'allTime':
+						$query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" GROUP BY n.nid DESC';
+						$block['content'] = node_title_list(db_query_range($query, 0, 5), t("Most Emalied"));
+						break;
+					case 'recent':
+						$query="SELECT DISTINCT n.nid, n.title FROM {node} n LEFT JOIN {forward_log} s ON s.nid = n.nid WHERE s.timestamp <> '0' AND s.type='SENT' AND n.status = 1 ORDER BY s.timestamp DESC";
+						$block['content'] = node_title_list(db_query_range($query, 0, 5), t("Most Recently Emailed"));
+						break;
+				}
+				return $block;
+			}
+	}
 }
 
-//  this function supports the dynamic footer generation
+//	this function supports the dynamic footer generation
 function forward_top5_list($query, $base_url, $type) {
-  $items = '<ol>';
-  $result = db_query_range($query, 0, 5);
-  while ($lineitem = db_fetch_array($result)) {
-   if ($type == 'user'){
-       $items .= '<li><a href="'.$base_url.'/user/'.current($lineitem).'">'. next($lineitem).'</a></li>';
-    } elseif ($type == 'comment'){
-       $items .= '<li><a href="'.$base_url.'/node/'.current($lineitem).'#comment-'.next($lineitem).'">'. next($lineitem).'</a/</li>';
-    } else {
-       $items .= '<li><a href="'.$base_url.'/node/'.current($lineitem).'">'. next($lineitem).'</a></li>';
-    }
-  }
-  return $items.'</ol>';
+	$items = '<ol>';
+	$result = db_query_range($query, 0, 5);
+	while ($lineitem = db_fetch_array($result)) {
+	 if ($type == 'user'){
+			 $items .= '<li><a href="'.$base_url.'/user/'.current($lineitem).'">'. next($lineitem).'</a></li>';
+		} elseif ($type == 'comment'){
+			 $items .= '<li><a href="'.$base_url.'/node/'.current($lineitem).'#comment-'.next($lineitem).'">'. next($lineitem).'</a/</li>';
+		} else {
+			 $items .= '<li><a href="'.$base_url.'/node/'.current($lineitem).'">'. next($lineitem).'</a></li>';
+		}
+	}
+	return $items.'</ol>';
 }
 
 function _forward_column_width($column, $width = 35) {
-  return (strlen($column) > $width ? substr($column, 0, $width) . '...' : $column);
+	return (drupal_strlen($column) > $width ? drupal_substr($column, 0, $width) . '...' : $column);
 }
 ?>
\ No newline at end of file
