Index: modr8.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.module,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 modr8.module
--- modr8.module	24 Aug 2006 05:46:57 -0000	1.1.2.2
+++ modr8.module	17 Nov 2006 15:22:45 -0000
@@ -52,15 +52,26 @@
 /**
  * Implementation of hook_settings().
  */
-function modr8_settings() {  
+function modr8_settings() {  
+  $modr8_options = array(
+      'approve' => t('approve'),
+	  'resubmit' => t('resubmit'),
+      'delete' => t('delete'),
+      'nada' => t('no action'),
+  );
+  $form['modr8_show_option'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Show the following moderation options'),
+    '#default_value' => variable_get('modr8_show_option', array()),
+    '#options' => $modr8_options,
+    '#description' => t('Which options do you want to provide to your site moderators?'),
+    
+  );
+	
   $form['modr8_default_option'] = array(
     '#type' => 'radios',
     '#title' => t('Which action option should be selected by default?'),
-    '#options' => array(
-      'approve' => t('approve'),
-      'delete' => t('delete'),
-      'nada' => t('no action'),
-    ),
+    '#options' => $modr8_options,
     '#default_value' => variable_get('modr8_default_option', 'nada'),
   );
 
@@ -97,7 +108,30 @@
     '#default_value' => variable_get('modr8_accepted_text', $accept_default),
   	'#description' => t('Replacement strings are: %macros', array('%macros' => $macros)),
   );
+
+  $form['text']['modr8_send_resubmit'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send resubmit messages (strongly recommended if you want the user to know why you rejected the message)'),
+    '#default_value' => variable_get('modr8_send_resubmit', TRUE),
+  );
+  
+  $form['text']['modr8_resubmit_subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Resubmission Email Subject'),
+    '#default_value' => variable_get('modr8_resubmit_subject', "[%site] %title has been sent back to you for editing"),
+  );
   
+  $macros = implode(', ', array_keys(modr8_replacements()));
+  
+  $resubmit_default = modr8_resubmit_default();
+  
+  $form['text']['modr8_resubmit_text'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Resubmission Email'),
+    '#default_value' => variable_get('modr8_resubmit_text', $resubmit_default),
+  	'#description' => t('Replacement strings are: %macros', array('%macros' => $macros)),
+  );
+
   $form['text']['modr8_send_deny'] = array(
     '#type' => 'checkbox',
     '#title' => t('Send denial messages'),
@@ -118,6 +152,14 @@
     '#default_value' => variable_get('modr8_denial_text', $denial_default),
   	'#description' => t('Replacement strings are: %macros', array('%macros' => $macros)),
   );
+
+  $form['text']['modr8_mail_copy'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Mail a copy of messages to this email address'),
+    '#default_value' => variable_get('modr8_mail_copy', ''),
+    '#description' => t('Have a copy of approval, resubmit and delete messages sent to this email address.  Leave blank if you do not want a copy.  This can only be a single email address.')
+  );
+  
   
   return $form;
 }
@@ -131,22 +173,22 @@
 	  switch ($op) {
 	    case 'view':
 	      if ($teaser) {
-	      	$node->teaser = theme('modr8_message', TRUE, $node->type, $op) . $node->teaser;
+	      	$node->teaser = theme('modr8_message', TRUE, $node->type, $op, $node->moderate) . $node->teaser;
 	      }
 	      else {
-	      	$node->body = theme('modr8_message', FALSE, $node->type, $op) . $node->body;
+	      	$node->body = theme('modr8_message', FALSE, $node->type, $op, $node->moderate) . $node->body;
 	      }
 	    	break;
 	    case 'update' :
 	    case 'insert' :
-          theme('modr8_message', FALSE, $node->type, $op);
+          theme('modr8_message', FALSE, $node->type, $op, $node->moderate);
 	  }
   }
   elseif($op == 'submit'){
 		// if not administrator, go BACK into moderation upon editing
 		if (!user_access('administer nodes') && in_array('moderate', variable_get('node_options_'. $node->type, array()))){
 			$node->moderate = TRUE;
-            theme('modr8_message', FALSE, $node->type, $op);
+            theme('modr8_message', FALSE, $node->type, $op, $node->moderate);
 		}
   }
 }
@@ -177,17 +219,22 @@
     $teaser = node_view($node, TRUE, FALSE, FALSE);
     $form[$node->nid] = array(
       '#tree' => TRUE,
-    );
+    );
+    
+    $modr8_show_option = variable_get('modr8_show_option', array());
+    $modr8_ops = array();
+    foreach($modr8_show_option as $key => $value) {
+    	if($modr8_show_option[$key] == true) {	
+    		$modr8_ops[$key] = $key == 'nada' ? t('no action') : t($key);
+    	}
+    }
+    
     $form[$node->nid]['ops'] = array(
       '#type' => 'radios',
-      '#options' => array(
-        'approve' => t('approve'),
-        'delete' => t('delete'),
-        'nada' => t('no action'),
-      ),
+      '#options' => $modr8_ops,
       '#default_value' => variable_get('modr8_default_option', 'nada'),
     );
-    if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) {
+    if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE) ||  variable_get('modr8_send_resubmit', FALSE)) {
       $form[$node->nid]['note'] = array(
         '#type' => 'textarea',
         '#title' => t('note to author'),
@@ -262,6 +309,17 @@
         db_query('UPDATE {node} SET moderate = 0 WHERE nid = %d', $nid);
         drupal_set_message(t('The %type %title has been approved.', array('%title' => theme('placeholder', $values['title']), '%type' => $values['type'])));
         break;
+	  // Send the node back to the submitter for refinements.
+      case 'resubmit':
+      	// A moderation value of 2 means it was resubmitted for moderation.  This
+      	// causes no conflict in core, but it may impact some contributed modules.  Assess
+      	// carefully as part of contributing back this patch.  We need a way to remove
+      	// resubmitted nodes from the modr8 screen.  
+        db_query('UPDATE {node} SET moderate = 2 WHERE nid = %d', $nid);
+      	if(variable_get('modr8_send_resubmit', TRUE)) {
+        	modr8_usermail('resubmit', $nid, $values);
+        }
+        break;
       case 'delete':
         if(variable_get('modr8_send_deny', FALSE)){
           modr8_usermail('deny', $nid, $values);
@@ -289,6 +347,11 @@
         $message = variable_get('modr8_denial_text', modr8_denial_default());
         $optype = t('denial');
         break;
+      case 'resubmit':
+        $subject = variable_get('modr8_resubmit_subject', '[%site] %title has been sent back for editing');
+        $message = variable_get('modr8_resubmit_text', modr8_resubmit_default());
+        $optype = t('resubmission');
+        break;
     }
     
     // get the user info for author
@@ -318,7 +381,18 @@
     }
     else {
       drupal_set_message(t('There was a problem sending the %type message to %username', array('%type' => $optype, '%username' => $account->name)), 'error');
-    }
+    }
+    
+	// If the settings are configured to send a copy to a moderator email address then send one
+    if(trim(variable_get('modr8_mail_copy', '')) != '') {
+	    // send the email
+	    if (user_mail(variable_get('modr8_mail_copy', ''), $subject, $message, $header)) {
+	      drupal_set_message(t('A copy of the %type message was sent to %modemail', array('%type' => $optype, '%modemail' => variable_get('modr8_mail_copy', ''))));
+	    } else {
+	      drupal_set_message(t('There was a problem sending the %type message to %modemail', array('%type' => $optype, '%modemail' => variable_get('modr8_mail_copy', ''))), 'error');
+	    }
+    	
+    }
   }
   else {
     drupal_set_message(t('An error occurred when trying to load this content.')); // this probably won't ever get called
@@ -347,6 +421,16 @@
 The %site team');
 }
 
+function modr8_resubmit_default() {
+  return t(
+'Your %type entry entitled "%title" has been sent back to you by our content moderator for refinement.
+
+%note
+
+Regards,
+The %site team');
+}
+
 function modr8_replacements(){
   return array(
     '%title' => '$node->title',
@@ -373,12 +457,21 @@
   return $note;
 }
 
-function theme_modr8_message($teaser = FALSE, $nodetype = 'page', $op = 'view') {
-  if ($teaser) {
-    return ' <div class="marker">'. t('pending moderation') .'</div>';
-  }
-  else {
-    drupal_set_message('The post has been submitted for moderation and won\'t be accessible until it has been approved.');
+function theme_modr8_message($teaser = FALSE, $nodetype = 'page', $op = 'view', $nodemoderate=1) {
+  if ($teaser) {
+  	if($nodemoderate == 2) {
+  		$output = '<div class="marker">'. t('pending contributor review') .'</div>';
+  	} else {
+  		$output = '<div class="marker">'. t('pending moderation') .'</div>';
+  	}
+    return $output;
+  }
+  else {
+  	if($nodemoderate == 2) {
+  	    drupal_set_message('The post has been rejected by the moderators and returned to the submitter for changes.  It won\'t be accessible until it has been updated and approved');
+  	} else {
+	    drupal_set_message('The post has been submitted for moderation and won\'t be accessible until it has been approved.');
+  	}    
     return '';
   }
 }
\ No newline at end of file
