--- abuse.module	2007-04-24 12:55:09.000000000 -0700
+++ abuseNew.module	2007-08-05 03:31:48.000000000 -0700
@@ -95,6 +95,15 @@ function abuse_menu($may_cache) {
       'access' => $admin_abuse_access,
       'type' => MENU_NORMAL_ITEM,
     );
+    $items[] = array(
+      'path' => 'admin/settings/abuse/messages',
+      'title' => t('Abuse alerter messages'),
+      'description' => t('Define messages sent to alerters upon action'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('abuse_alerter_messages_form'),
+      'access' => $admin_abuse_access,
+      'type' => MENU_NORMAL_ITEM,
+    );
     
     $pending = _abuse_get_pending_count();
     $hidden = _abuse_get_hidden_count();
@@ -297,6 +306,129 @@ function abuse_admin_configure_reasons_s
   }
 }
 
+
+/**
+ * Provide an interface to manage the messages sent to alerters when
+ * action has been performed on the pice of content that they flagged.
+ */
+
+function abuse_alerter_messages_form(){
+  $form['description'] = array(
+    '#value' => t('Edit the message(s)/email(s) sent to the alerter after action has been taken.'),
+  );
+  
+  $form['allow'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Allow'),
+    '#description' => t('Allowed variables are !name, !reason, !report, !link, !date.')
+  );
+  $form['allow']['allow_subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#default_value' => variable_get('abuse_alerter_allow_subject', ''),
+  );
+  $form['allow']['allow_body'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Body'),
+    '#default_value' => variable_get('abuse_alerter_allow_body', ''),
+  );
+  
+  $form['remove'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Remove'),
+    '#description' => t('Allowed variables are !name, !reason, !report, !link, !date.')
+  );
+  $form['remove']['remove_subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#default_value' => variable_get('abuse_alerter_remove_subject', ''),    
+  );
+  $form['remove']['remove_body'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Body'),
+    '#default_value' => variable_get('abuse_alerter_remove_body', ''),
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save Messages'),
+  );
+  return $form;
+}
+
+/**
+ * Form Submit handler for the follow up messages
+ */
+function abuse_alerter_messages_form_submit($form_id, $form_values){
+  variable_set('abuse_alerter_allow_subject', check_plain($form_values['allow_subject']));
+  variable_set('abuse_alerter_allow_body', check_plain($form_values['allow_body']));
+  variable_set('abuse_alerter_remove_subject', check_plain($form_values['remove_subject']));
+  variable_set('abuse_alerter_remove_body', check_plain($form_values['remove_body']));
+
+  drupal_set_message('Messages Saved.');
+}
+
+/**
+ * Function sends out a follow up message to the person who reported the content
+ *
+ * @param $report: A report object that has been associated with a flagged item
+ * @param $action: The action being performed, either 'allow' or 'remove'
+ */
+function abuse_alerter_message($report, $action){
+  if($report->valid == 0){
+    
+    // Build a link to the content that was reported
+    if($report->type == 'node'){
+      $link = url('node/'. $report->oid, null, null, true);
+    }
+    else{
+      $query = db_query("SELECT nid FROM {comments} WHERE cid = %d", $report->oid);
+      $result = db_result($query);
+      $link = url('node/'. $result, null, 'comment-'. $report->oid, true);
+    }
+    
+    // Grab the reason why the content was reported for inclusion in message
+    $query = db_query("SELECT reason FROM {abuse_reasons} WHERE arid = %d", $report->reason);
+    $reason = db_result($query);
+    
+    // Variables array to translate data for the custom emails
+    $vars = array(
+      '!name' => $report->name,
+      '!link' => $link,
+      '!date' => format_date($report->created),
+      '!report' => $report->body,
+      '!reason' => $reason,
+    );
+    // build the email subject and body based on action performed
+    switch($action){
+      case 'allow':
+        $subject = variable_get('abuse_alerter_allow_subject', '');
+        $subject = strtr($subject, $vars);
+        $body = variable_get('abuse_alerter_allow_body', '');
+        $body = strtr($body, $vars);    
+        break;
+      case 'remove':
+        $subject = variable_get('abuse_alerter_remove_subject', '');
+        $subject = strtr($subject, $vars);
+        $body = variable_get('abuse_alerter_remove_body', '');
+        $body = strtr($body, $vars);  
+        break;
+    }
+    // send either a privatemsg to logged in users or an email to anonymous
+    if($report->uid && module_exists('privatemsg') && function_exists('privatemsg_send_privatemsg')){
+      $recipient = user_load(array('uid' => $report->uid));
+      privatemsg_send_privatemsg($recipient, $subject, $body);
+      drupal_set_message('User notified of status update via private message.');
+    }
+    else {
+      $recipient = $report->mail;
+      drupal_mail('abuse_alerter_message', $recipient, $subject, $body);
+      drupal_set_message('Visiter notified of status update via email.');
+    }
+  }
+}
+
+
 /**
  * Implementation of hook_nodeapi
  */
@@ -945,6 +1077,9 @@ function _abuse_load_reports($type, $oid
 
 function _abuse_allow($type, $oid) {
   $object = _abuse_load($type, $oid);
+  foreach($object->reports as $report){
+    abuse_alerter_message($report, 'allow');
+  }
   $account = user_load(array('uid' => $object->uid, 'status' => 1));
   if ($account->uid) {
     db_query("UPDATE {abuse} SET valid=-1 WHERE type='%s' AND oid=%d", $type, $oid);
@@ -974,6 +1109,10 @@ function _abuse_set_user_content_remove(
 }
 
 function _abuse_remove($type, $oid) {
+  $object = _abuse_load($type, $oid);
+  foreach($object->reports as $report){
+    abuse_alerter_message($report, 'remove');
+  }
   db_query("UPDATE {abuse} SET valid=1 WHERE type='%s' AND oid=%d", $type, $oid);
   switch ($type) {
     case 'node':
