Index: notices.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/notices/notices.info,v
retrieving revision 1.7
diff -u -r1.7 notices.info
--- notices.info	21 Jul 2008 00:20:23 -0000	1.7
+++ notices.info	8 Oct 2008 19:42:27 -0000
@@ -1,8 +1,4 @@
 ; $Id: notices.info,v 1.7 2008/07/21 00:20:23 ptalindstrom Exp $
 name = Notices
-description = Provides a web based notice system for all emails sent to a user.
+description = Provides a web-based duplicate for all emails sent to a user.
 package = Mail
-version = 5.x-1.0
-#dependencies = 
-project = drupal
-
Index: notices.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/notices/notices.install,v
retrieving revision 1.7
diff -u -r1.7 notices.install
--- notices.install	21 Jul 2008 00:20:23 -0000	1.7
+++ notices.install	8 Oct 2008 19:42:27 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: notices.install,v 1.7 2008/07/21 00:20:23 ptalindstrom Exp $  
+// $Id: notices.install,v 1.7 2008/07/21 00:20:23 ptalindstrom Exp $
 
 /**
  * Implementation of hook_install().
@@ -16,7 +16,7 @@
       message text character set utf8,
       created int(11) default '0',
       PRIMARY KEY  (nid))
-      /*!40100 DEFAULT CHARACTER SET UTF8 */ "); 
+      /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
       break;
     case 'pgsql':
       // TBD
@@ -30,7 +30,7 @@
  */
 function notices_uninstall() {
   $query = db_query('DROP TABLE {notices}');
-  
+
   if ($query) {
     drupal_set_message('The notices module was successfully uninstalled.');
   }
@@ -38,4 +38,3 @@
     drupal_set_message('There was an error removing the notices table.', 'error');
   }
 }
-?>
Index: notices.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/notices/notices.module,v
retrieving revision 1.8
diff -u -r1.8 notices.module
--- notices.module	2 Oct 2008 19:04:46 -0000	1.8
+++ notices.module	8 Oct 2008 19:42:28 -0000
@@ -1,51 +1,45 @@
 <?php
-// $Id: notices.module,v 1.8 2008/10/02 19:04:46 ptalindstrom Exp $   
-      
+// $Id: notices.module,v 1.8 2008/10/02 19:04:46 ptalindstrom Exp $
+
 /**
- * Implementation of hook_help().
- */    
-function notices_help($section='') {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t("This module provides a web based 'duplicate' of any email that gets sent to a user. A block is provided to give
-      links to copies of the user emails. Once an email is viewed the notice expires.");
-  }
-}
+ * @file
+ * Save outgoing emails so users can view them through Drupal.
+ */
 
-/*
-* Implementation of hook_perm().
-*/
+/**
+ * Implementation of hook_perm().
+ */
 function notices_perm() {
-  return array('receive notices');  
+  return array('receive notices');
 }
 
 /**
-* Implementation of hook_menu()
-*/
+ * Implementation of hook_menu().
+ */
 function notices_menu($may_cache) {
   global $user;
-  
+
   // - set msg type as 'notices' so it is easier to check if it has already been set
   // - add css so that by default msg type shows green (status); but can be rethemed if preferred
-  
+
   if (user_access('receive notices', $user)) {
     // if admin set to show notice indication on HOME page - do it here
-    if (drupal_is_front_page() && variable_get('notices_message_type', false) === '0' 
+    if (drupal_is_front_page() && variable_get('notices_message_type', FALSE) === '0'
       && _notices_user_has_notices($user->uid) && !count(drupal_get_messages('notices'))) {
-        drupal_add_css(drupal_get_path('module', 'notices') . "/notices.css"); 
-        drupal_set_message("You have notices. You can check them out ". l("here", "user/". $user->uid . "/notices"), 'notices');
+        drupal_add_css(drupal_get_path('module', 'notices') ."/notices.css");
+        drupal_set_message(l(t('You have notices.'), "user/". $user->uid ."/notices"), 'status');
     }
-    
+
     // if admin set to show notice indication on EVERY page - do it here
-    elseif (variable_get('notices_message_type', false) === '2' 
+    elseif (variable_get('notices_message_type', FALSE) === '2'
       && _notices_user_has_notices($user->uid) && !count(drupal_get_messages('notices'))) {
-        drupal_add_css(drupal_get_path('module', 'notices') . "/notices.css"); 
-        drupal_set_message("You have notices. You can check them out ". l("here", "user/". $user->uid . "/notices"), 'notices');
+        drupal_add_css(drupal_get_path('module', 'notices') ."/notices.css");
+        drupal_set_message(l(t('You have notices.'), "user/". $user->uid ."/notices"), 'status');
     }
   }
-    
+
   // if admin set to show notice indication on LOGIN page - do it in _user hook
-    
+
   $items = array();
   if ($may_cache) {
     $items[] = array(
@@ -55,28 +49,28 @@
       'callback' => 'drupal_get_form',
       'callback arguments' => array('notices_admin_settings'),
       'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
+      'type' => MENU_NORMAL_ITEM
     );
-  }                 
+  }
   else {
     //user tab to show notices
     $items[] = array(
-      'path'                => 'user/' .arg(1). '/notices',
-      'title'               => t('Notices'),
-      'callback'            => '_notices_user_show_page',
-      'callback arguments'  => array(arg(1)),
-      'access'              => user_access('receive notices') && ($user->uid == arg(1) || user_access('administer site configuration')) ? 1 : 0,
-      'type'                => MENU_LOCAL_TASK,
-    );           
-    
+      'path' => 'user/'. arg(1) .'/notices',
+      'title' => t('Notices'),
+      'callback' => '_notices_user_show_page',
+      'callback arguments' => array(arg(1)),
+      'access' => user_access('receive notices') && ($user->uid == arg(1) || user_access('administer site configuration')) ? 1 : 0,
+      'type' => MENU_LOCAL_TASK
+    );
+
     // and a page to show the actual message
     $items[] = array(
-      'path'                => 'user/' .arg(1). '/notices/' . arg(3),
-      'title'               => t('Notices'),
-      'callback'            => '_notices_user_show_notice',
-      'callback arguments'  => array(arg(3)),
-      'access'              => user_access('receive notices') && ($user->uid == arg(1) || user_access('administer site configuration')) ? 1 : 0,
-      'type'                => MENU_LOCAL_TASK,
+      'path' => 'user/'. arg(1) .'/notices/'. arg(3),
+      'title' => t('Notices'),
+      'callback' => '_notices_user_show_notice',
+      'callback arguments' => array(arg(3)),
+      'access' => user_access('receive notices') && ($user->uid == arg(1) || user_access('administer site configuration')) ? 1 : 0,
+      'type' => MENU_LOCAL_TASK
     );
   }
 
@@ -85,7 +79,7 @@
 
 // System Admin Form - callback for menu item listed above
 function notices_admin_settings() {
-  // system settings     
+  // system settings
   $options = array(
     0 => "Home page only",
     1 => "Only when logging in",
@@ -97,14 +91,14 @@
     '#title' => t('Message indictation type'),
     '#default_value' => variable_get('notices_message_type', 0),
     '#description' => t("Set how it is indicated to users that they have notices."),
-  );       
+  );
   $form['notices_expiry'] = array(
     '#type' => 'select',
     '#options' => range(0, 52),
     '#title' => t('Expiry time'),
     '#default_value' => variable_get('notices_expiry', 0),
     '#description' => t("Enter the number of weeks until notices auto-expire. Enter 0 for no expiry."),
-  );    
+  );
   $form['notices_block_display'] = array(
     '#type' => 'radios',
     '#options' => array(0 => "Show empty block", 1 => "Hide empty block"),
@@ -117,32 +111,34 @@
 }
 
 /**
- * Implementation of hook_user()
- *  
+ * Implementation of hook_user().
+ *
  *  - if our admin setting is set to show notice indication only on login: do it here.
  */
 function notices_user($op, &$edit, &$account, $category = NULL) {
-  if ($account->uid && !user_access('receive notices', $account)) return;
-  
-  switch ($op) {    
+  if ($account->uid && !user_access('receive notices', $account)) {
+    return;
+  }
+
+  switch ($op) {
     case 'categories':
       return array(array('name' => 'notices', 'title' => 'Notices'));
       break;
-    
+
     case 'login':
-      if (_notices_user_has_notices($account->uid) && variable_get('notices_message_type', false) === '1'
+      if (_notices_user_has_notices($account->uid) && variable_get('notices_message_type', FALSE) === '1'
         && !count(drupal_get_messages('notices'))) {
-          drupal_add_css(drupal_get_path('module', 'notices') . "/notices.css");
-          drupal_set_message("You have notices. You can check them out ". l("here", "user/". $account->uid . "/notices"), 'notices');
+          drupal_add_css(drupal_get_path('module', 'notices') ."/notices.css");
+          drupal_set_message(l(t('You have notices.'), "user/". $account->uid ."/notices"), 'status');
       }
       break;
-  
+
     case 'form':
       if ($category != "notices") return;
       $form['notices_preferences'] = array(
         '#type' => 'fieldset',
-        '#title' => t('Notices - User preferences for the Notices module'), 
-        '#collapsible' => false, 
+        '#title' => t('Notices - User preferences for the Notices module'),
+        '#collapsible' => FALSE,
         '#weight' => 10
       );
       $form['notices_preferences']['notices_delete_on_read'] = array(
@@ -152,18 +148,18 @@
       );
       break;
   }
-  
+
   return $form;
 }
 
 /**
- * Implementation of hook_block.
+ * Implementation of hook_block().
  *
  *    provide list of user's most recent notices
  */
 function notices_block($op = 'list', $delta = 0) {
   global $user;
-  
+
   switch ($op) {
     case 'list':
       $block[0]['info'] = t('Latest Notices');
@@ -181,11 +177,11 @@
  * Page view of users messages.
  */
 function _notices_user_show_page($uid) {
-  $account = user_load(array('uid'=>arg(1)));
-  drupal_set_title($account->name);                                          
-  
-  $output = "<br>The following email have been previously sent to ". $account->mail .".";
-  
+  $account = user_load(array('uid' => arg(1)));
+  drupal_set_title($account->name);
+
+  $output = "<br />The following emails have been previously sent to {$account->mail}.";
+
   // Call the form first, to allow for the form_values array to be populated.
   $output .= drupal_get_form('_notices_page_form', $uid);
 
@@ -193,18 +189,18 @@
 }
 
 function _notices_page_form($uid) {
-  $result = pager_query("SELECT * FROM {notices} WHERE uid = $uid ORDER BY created DESC", 50);    
-  
+  $result = pager_query("SELECT * FROM {notices} WHERE uid = %d ORDER BY created DESC", 50, NULL, NULL, $uid);
+
   $form['submit'] = array('#type' => 'submit', '#value' => t('Mark as Read'));
-  
+
   $destination = drupal_get_destination();
   while ($notice = db_fetch_object($result)) {
     $notices[$notice->nid] = '';
-    $form['title'][$notice->nid] = array('#value' => l($notice->subject, "user/$uid/notices/". $notice->nid, array(), $destination)); 
-    $form['message'][$notice->nid] = array('#value' => wordwrap(substr(strip_tags($notice->message), 0, 160), 80, "<br>"));
+    $form['title'][$notice->nid] = array('#value' => l($notice->subject, "user/$uid/notices/". $notice->nid, array(), $destination));
+    $form['message'][$notice->nid] = array('#value' => wordwrap(substr(strip_tags($notice->message), 0, 160), 80, "<br />"));
     $form['date'][$notice->nid] =  array('#value' => date("m-d-Y", $notice->created));
   }
-  $form['nodes'] = array('#type' => 'checkboxes', '#options' => $notices);
+  $form['notices'] = array('#type' => 'checkboxes', '#options' => $notices);
   $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
   return $form;
 }
@@ -214,20 +210,20 @@
  */
 function theme__notices_page_form($form) {
   // Overview table:
-  $header = array(theme('table_select_header_cell'), t('Subject'), t('Message'),t('Date'));
-  
+  $header = array(theme('table_select_header_cell'), t('Subject'), t('Message'), t('Date'));
+
   $output = drupal_render($form['submit']);
   if (isset($form['title']) && is_array($form['title'])) {
     foreach (element_children($form['title']) as $key) {
       $row = array();
-      $row[] = drupal_render($form['nodes'][$key]);
+      $row[] = drupal_render($form['notices'][$key]);
       $row[] = drupal_render($form['title'][$key]);
-      $row[] = drupal_render($form['message'][$key]); 
+      $row[] = drupal_render($form['message'][$key]);
       $row[] = drupal_render($form['date'][$key]);
       $rows[] = $row;
     }
   }
-  else  {
+  else {
     $rows[] = array(array('data' => t('You have no unread messages.'), 'colspan' => '3'));
   }
 
@@ -239,105 +235,128 @@
   $output .= drupal_render($form);
 
   return $output;
-} 
+}
+
+/**
+ * Make sure some notice IDs are being passed to the remover.
+ */
+function _notices_page_form_validate($form_id, $form_values) {
+  // Filter out unchecked nodes
+  $notices = array_filter($form_values['notices']);
+
+  if (!$notices) {
+    form_set_error('notices', t('You need to mark 1 or more messages.'));
+  }
+}
 
 /**
  * Submit the node administration update form.
  */
 function _notices_page_form_submit($form_id, $form_values) {
   // Filter out unchecked nodes
-  $notices = array_filter($form_values['nodes']);
-  
-  if ($notices) {
-    foreach ($notices as $notice) $where[] = " nid = $notice ";
-    $where_str = join(" OR ", $where);  
-    db_query("DELETE FROM {notices} WHERE $where_str");
-    
-    drupal_set_message(t('Messages have been marked as read.'));
+  $notices = array_filter($form_values['notices']);
+
+  foreach ($notices as $notice) {
+    $where[] = " nid = $notice ";
   }
-  else drupal_set_message(t('You need to mark 1 or more messages.')); 
-}       
+  $where_str = join(" OR ", $where);
+  db_query("DELETE FROM {notices} WHERE $where_str");
+
+  drupal_set_message(t('Messages have been marked as read.'));
+}
 
 function _notices_user_show_block() {
   global $user;
-  $results = db_query("SELECT * FROM {notices} WHERE uid = %d ORDER BY created DESC LIMIT 5", $user->uid);
+  $results = db_query_range("SELECT * FROM {notices} WHERE uid = %d ORDER BY created DESC", $user->uid, 0, 5);
 
-  while ($result = db_fetch_object($results)) $list[] = l($result->subject, "user/$user->uid/notices/". $result->nid);
-  
-  if (count($list)) return theme('item_list', $list) .'<div style="text-align:right">'. l(t("more"), "user/". $user->uid . "/notices") .'</div>';
+  while ($result = db_fetch_object($results)) {
+    $list[] = l($result->subject, "user/$user->uid/notices/". $result->nid);
+  }
+
+  if (count($list)) {
+    return theme('item_list', $list) .'<div style="text-align:right">'. l(t("more"), "user/". $user->uid ."/notices") .'</div>';
+  }
   else {
-    if (variable_get('notices_block_display', 1)) return false; 
-    else return t("<p>You have no notices.</p>");
+    if (variable_get('notices_block_display', 1)) {
+      return FALSE;
+    }
+    else {
+      return t("<p>You have no notices.</p>");
+    }
   }
-  
+
 }
 
-/* 
-*  Display a single notice
-*     - if this is users msg then mark it as read
-*/
+/**
+ * Display a single notice
+ *   - if this is users msg then mark it as read
+ */
 function _notices_user_show_notice($nid) {
   global $user;
-  
-  $account = user_load(array('uid'=>arg(1)));
+
+  $account = user_load(array('uid' => arg(1)));
   drupal_set_title($account->name);
-    
+
   $notice = db_fetch_object(db_query("SELECT * FROM {notices} WHERE nid = %d", $nid));
-  
-  $output = "<br>The following email has been previously sent to ". $account->mail . ".<br><br>";
-     
-  $output .= '<input onclick="location.href=\''. url("user/". arg(1). "/notices") .'\'" type="submit" class="form-submit" value="Return" id="edit-submit" /><p>';
-  $output .= "<strong>Subject: </strong>". $notice->subject ."<br><br>";
-  $output .= "<strong>From: </strong>". $notice->sender ."<br><br>";    
-  $output .= "<strong>Date: </strong>". date("M d, Y", $notice->created) ."<br><br>";
-  $output .= "<strong>Message: </strong>". _filter_autop($notice->message) ."<br><br>";    
-  
+
+  $output = "<br />The following email has been previously sent to {$account->mail}.<br /><br />";
+
+  $output .= '<input onclick="location.href=\''. url("user/". arg(1) ."/notices") .'\'" type="submit" class="form-submit" value="Return" id="edit-submit" /><p>';
+  $output .= "<strong>Subject: </strong>". $notice->subject ."<br /><br />";
+  $output .= "<strong>From: </strong>". $notice->sender ."<br /><br />";
+  $output .= "<strong>Date: </strong>". date("M d, Y", $notice->created) ."<br /><br />";
+  $output .= "<strong>Message: </strong>". _filter_autop($notice->message) ."<br /><br />";
+
   // if we are reading our own msg (i.e. not admin doing it) then lets mark it as read by deleting from db
   //    - unless our user pref is set not to "delete on read"
   if (arg(1) == $user->uid && (!isset($account->notices_delete_on_read) || $account->notices_delete_on_read)) {
-    db_query("DELETE FROM {notices} WHERE nid = ". arg(3));
-    drupal_set_message("This message has now been marked as read."); 
+    db_query("DELETE FROM {notices} WHERE nid = %d", arg(3));
+    drupal_set_message("This message has now been marked as read.");
   }
-  
+
   return $output;
 }
 
 
-/* 
-*  Capture any mail that is being sent and log it as a Notice for that user 
-*/
+/**
+ *  Capture any mail that is being sent and log it as a Notice for that user
+ */
 function notices_mail_alter($mailkey, $to, $subject, $body, $from, $headers) {
   // load the user that is getting this email
   $user = user_load(array('mail' => $to));
-  
+
   // if this email address does not match with a user in our system; do nothing
-  if (!$user->uid || !user_access('receive notices', $user)) return; 
-  
+  if (!$user->uid || !user_access('receive notices', $user)) return;
+
   $subject = htmlentities($subject);
   $from = htmlentities($from);
   $message = stristr($body, "<HTML>") ? $body : htmlentities($body);
-  
+
   db_query("INSERT INTO {notices} (uid, subject, sender, message, created) VALUES (%d, '%s', '%s', '%s', %d)", $user->uid, $subject, $from, $message, time());
 }
 
 // helper function to check if a user has notices
 function _notices_user_has_notices($uid) {
-  $result = db_query("SELECT * FROM {notices} WHERE uid = $uid");
-  
-  if (db_num_rows($result)) return true;
-  else return false;
+  $result = db_query("SELECT * FROM {notices} WHERE uid = %d", $uid);
+
+  if (db_num_rows($result)) {
+    return TRUE;
+  }
+  else {
+    return FALSE;
+  }
 }
 
 // cron hook to auto-expire notices
 function notices_cron() {
   $expire = variable_get('notices_expiry', 0);
-  
+
   if (!$expire) return;
-  
+
   db_query("DELETE FROM {notices} WHERE %d > created", time() - ($expire * 60*60*24*7));
 
-  return; 
+  return;
 }
-  
+
 
 
