? log_modr8_1.diff
? log_modr8_2.diff
? log_modr8_3.diff
? log_modr8_4.diff
Index: modr8.install
===================================================================
RCS file: modr8.install
diff -N modr8.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modr8.install	13 Jan 2007 17:33:45 -0000
@@ -0,0 +1,95 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function modr8_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE {modr8_log} (
+        modid int NOT NULL auto_increment,
+        nid int unsigned NOT NULL default '0',
+        uid int NOT NULL default '0',
+        author_uid int NOT NULL default '0',
+        action varchar(16) NOT NULL default '',
+        title varchar(128) NOT NULL default '',
+        message longtext NOT NULL,
+        teaser longtext NOT NULL,
+        timestamp int NOT NULL default '0',
+        PRIMARY KEY (modid),
+        KEY nid_time (nid, mpdid),
+        KEY action (action)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {modr8_log} (
+        modid serial,
+        nid int_unsigned NOT NULL default '0',
+        uid int NOT NULL default '0',
+        author_uid int NOT NULL default '0',
+        action varchar(16) NOT NULL default '',
+        title varchar(128) NOT NULL default '',
+        message text NOT NULL,
+        teaser text NOT NULL,
+        timestamp int NOT NULL default '0',
+        PRIMARY KEY (modid)
+      )");
+      db_query("CREATE INDEX {modr8_log}_nid_time ON {modr8_log} (nid, modid)");
+      db_query("CREATE INDEX {modr8_log}_act_idx ON {modr8_log} (action)");
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function modr8_uninstall() {
+  db_query('DROP TABLE {modr8_log}');
+}
+
+
+/**
+ * Update table definitions.
+ */
+function modr8_update_1000() {
+  $ret = array();
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {modr8_log} (
+        modid int NOT NULL auto_increment,
+        nid int unsigned NOT NULL default '0',
+        uid int NOT NULL default '0',
+        author_uid int NOT NULL default '0',
+        action varchar(16) NOT NULL default '',
+        title varchar(128) NOT NULL default '',
+        message longtext NOT NULL,
+        teaser longtext NOT NULL,
+        timestamp int NOT NULL default '0',
+        PRIMARY KEY (modid),
+        KEY nid_time (nid, modid),
+        KEY action (action)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {modr8_log} (
+        modid serial,
+        nid int_unsigned NOT NULL default '0',
+        uid int NOT NULL default '0',
+        author_uid int NOT NULL default '0',
+        action varchar(16) NOT NULL default '',
+        title varchar(128) NOT NULL default '',
+        message text NOT NULL,
+        teaser text NOT NULL,
+        timestamp int NOT NULL default '0',
+        PRIMARY KEY (modid)
+      )");
+      $ret[] = update_sql("CREATE INDEX {modr8_log}_nid_time ON {modr8_log} (nid, modid)");
+      $ret[] = update_sql("CREATE INDEX {modr8_log}_act_idx ON {modr8_log} (action)");
+      break;
+  }
+  return $ret;
+}
Index: modr8.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.module,v
retrieving revision 1.11
diff -u -p -r1.11 modr8.module
--- modr8.module	7 Jan 2007 17:39:45 -0000	1.11
+++ modr8.module	13 Jan 2007 17:33:46 -0000
@@ -33,12 +33,33 @@ function modr8_menu($may_cache) {
       'callback' => 'modr8_page',
     );
     $items[] = array(
-       'path' => 'admin/settings/modr8',
-       'title' => t('Modr8 settings'),
-       'description' => t('Configure content moderation.'),
-       'callback' => 'modr8_settings',
-       'access' => user_access('administer site configuration'), 
-      );
+      'path' => 'admin/logs/modr8',
+      'title' => t('Modr8 moderation log'),
+      'description' => t('Show log of actions on moderated content.'),
+      'access' => user_access('moderate content'),
+      'callback' => 'modr8_log_view',
+    );
+    $items[] = array(
+      'path' => 'admin/logs/modr8/view',
+      'access' => user_access('moderate content'),
+      'callback' => 'modr8_log_view',
+      'callback arguments' => array('view', arg(5)),
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'admin/logs/modr8/node',
+      'access' => user_access('moderate content'),
+      'callback' => 'modr8_log_view',
+      'callback arguments' => array('node', arg(5)),
+      'type' => MENU_CALLBACK,
+    );    
+    $items[] = array(
+      'path' => 'admin/settings/modr8',
+      'title' => t('Modr8 settings'),
+      'description' => t('Configure content moderation.'),
+      'callback' => 'modr8_settings',
+      'access' => user_access('administer site configuration'), 
+    );
   }
 
   return $items;
@@ -51,6 +72,25 @@ function modr8_perm() {
   return array('moderate content');  
 }
 
+
+/**
+ * menu callback for moderation log.
+ */
+function modr8_log_view($op = 'overview', $id = 0) {  
+  
+  require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc';
+  
+  switch ($op) {
+    case 'overview':
+      return modr8_log_overview();
+    case 'view':
+      return modr8_log_event($id);
+    case 'node':
+      return modr8_log_overview($id);
+  }
+}
+
+
 /**
  * menu callback for settings form.
  */
Index: modr8_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8_admin.inc,v
retrieving revision 1.7
diff -u -p -r1.7 modr8_admin.inc
--- modr8_admin.inc	6 Jan 2007 18:10:08 -0000	1.7
+++ modr8_admin.inc	13 Jan 2007 17:33:46 -0000
@@ -126,8 +126,12 @@ function modr8_form($result = NULL) {
       );
     }
     $form[$node->nid]['preview'] = array(
-      '#type' => 'markup',
-      '#value' => $teaser
+      '#type' => 'value',
+      '#value' => $teaser,
+    );
+    $form[$node->nid]['author_uid'] = array(
+      '#type' => 'value',
+      '#value' => $node->uid,
     );
     $form[$node->nid]['title'] = array(
       '#type' => 'value',
@@ -167,7 +171,7 @@ function theme_modr8_form(&$form) {
         'style' => 'vertical-align:top;'
       );
       $row[] = array(
-        'data' => drupal_render($form[$key]['preview']),
+        'data' => $form[$key]['preview']['#value'],
         'style' => 'vertical-align:top;',
       );
       $rows[] = $row;
@@ -184,30 +188,41 @@ function theme_modr8_form(&$form) {
  */
 function modr8_form_submit($form_id, $form_values) {
   foreach ($form_values as $nid => $values) {
+    $message = '';   
     switch ($values['ops']) {
       case 'approve':
         if(variable_get('modr8_send_approve', FALSE)){
-          modr8_usermail('approve', $nid, $values);
+          $message = modr8_usermail('approve', $nid, $values);
         }
         db_query('UPDATE {node} SET moderate = 0 WHERE nid = %d', $nid);
         drupal_set_message(t('The %type with title %title has been approved.', array('%title' => $values['title'], '%type' => $values['type'])));
         cache_clear_all();
+        modr8_log_action('approve', $nid, $values, $message);
         break;
       case 'delete':
         if(variable_get('modr8_send_deny', FALSE)){
-          modr8_usermail('deny', $nid, $values);
+          $message = modr8_usermail('deny', $nid, $values);
         }
         node_delete($nid);
         // drupal does its own message
+        modr8_log_action('delete', $nid, $values, $message);
         break;
       case 'nada':
         if(variable_get('modr8_send_noact', FALSE) && !empty($values['note'])){
-          modr8_usermail('nada', $nid, $values);
+          $message = modr8_usermail('nada', $nid, $values);
+          modr8_log_action('nada', $nid, $values, $message);
         }    
     }
   }
 }
 
+function modr8_log_action($op, $nid, $values, $message) {
+  global $user;
+  $actions = array('approve' => 'Approve','delete' => 'Delete','nada' => 'No action');
+  
+  db_query("INSERT INTO {modr8_log} (nid, uid, author_uid, action, title, message, teaser, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %d)", $nid, $user->uid, $values['author_uid'], $actions[$op], $values['title'], $message, $values['preview'], time()); 
+}
+
 function modr8_usermail($op, $nid, $values){
   $node = node_load($nid);
   
@@ -254,14 +269,18 @@ function modr8_usermail($op, $nid, $valu
     // send the email
     if (drupal_mail('modr8_usermail',$account->mail, $subject, $message, $site_mail)) {
       drupal_set_message(t('%type message was sent to %username', array('%type' => $optype, '%username' => $account->name)));
+      $message = filter_filter('process', 2, -1, $message); // Return e-mail with HTML breaks added.
     }
     else {
-      drupal_set_message(t('There was a problem sending the %type message to %username', array('%type' => $optype, '%username' => $account->name)), 'error');
+      $message = t('There was a problem sending the %type message to %username', array('%type' => $optype, '%username' => $account->name));
+      drupal_set_message($message, 'error');
     }
   }
   else {
-    drupal_set_message(t('An error occurred when trying to load this content.')); // this probably won't ever get called
+    $message = t('An error occurred when trying to load this content.');
+    drupal_set_message($message); // this probably won't ever get called
   }
+  return $message;
 }
 
 function theme_modr8_note($note){
@@ -324,3 +343,71 @@ Regards,
 The %site team');
 }
 
+
+function modr8_log_overview($nid = 0) {
+
+  $header = array(
+    array('data' => t('Action'), ),
+    array('data' => t('Date'), 'field' => 'ml.modid', 'sort' => 'desc'),
+    array('data' => t('Author'),),
+    array('data' => t('Title'),),
+  );
+  $tablesort = tablesort_sql($header);
+
+  $count_sql = "SELECT COUNT(*) FROM {modr8_log} ml";  
+  $pager_sql = "SELECT ml.modid, ml.action, ml.title, ml.timestamp, u.name, u.uid FROM {modr8_log} ml LEFT JOIN {users} u ON u.uid = ml.author_uid";
+  if ($nid) {
+    drupal_set_title(t("One post's moderation log"));
+    $count_sql .= " WHERE ml.nid = %d";
+    $pager_sql .= " WHERE ml.nid = %d";
+  }
+  $count_sql = db_rewrite_sql($count_sql, 'ml');
+  $pager_sql = db_rewrite_sql($pager_sql, 'ml');
+  $result = pager_query($pager_sql . $tablesort, 50, 0, $count_sql, $nid);
+  
+  $rows = array();
+  
+  while ($event = db_fetch_object($result)) {
+    $rows[] = array(t($event->action),  format_date($event->timestamp, 'small'), theme('username', $event), 
+    l(truncate_utf8($event->title, 50, TRUE, TRUE), 'admin/logs/modr8/view/'. $event->modid, array(), NULL, NULL, FALSE, TRUE)
+    );
+  }
+  
+  
+  if (!$rows) {
+    $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 4));
+  }
+
+  $output .= theme('table', $header, $rows);
+  $output .= theme('pager', NULL, 50, 0);
+
+  return $output;
+}
+
+function modr8_log_event($modid) {
+  
+  if (is_numeric($modid)) {
+  
+    $sql = db_rewrite_sql("SELECT ml.*, u.name FROM {modr8_log} ml LEFT JOIN {users} u ON u.uid = ml.uid", 'ml');
+    $event = db_fetch_object(db_query($sql));
+    if ($event) {
+      $event->author = db_fetch_object(db_query("SELECT * from {users} u WHERE u.uid = %d", $event->author_uid));
+      drupal_set_title(t('Moderation log event'));
+      return theme('moderation_event', $event);
+    }
+  }
+  
+  drupal_not_found();
+}
+
+function theme_moderation_event($event) {
+  //drupal_set_message(print_r($event, TRUE));
+  $rows[] = array(t('Action:'), t($event->action));
+  $rows[] = array(t('Date:'), format_date($event->timestamp, 'small'));
+  $rows[] = array(t('Moderator:'), theme('username', $event));
+  $rows[] = array('data' => array(t('E-mail message:'), $event->message), 'style' => 'vertical-align:top;');
+  $rows[] = array(t('Author:'), theme('username', $event->author));
+  $rows[] = array('data' => array(t('Teaser (as reviewed):'), $event->teaser), 'style' => 'vertical-align:top;');
+  
+  return theme('table', NULL, $rows);
+}
