diff --git a/php_errors.info b/php_errors.info
index cceaf9c..c74d8f1 100644
--- a/php_errors.info
+++ b/php_errors.info
@@ -1,22 +1,10 @@
-; $Id: php_errors.info,v 1.8 2010/07/07 18:26:56 ptalindstrom Exp $
 name = PHP Errors
 description = Admin tool to help monitor PHP errors which occur on the site.
 package = Administration
-version = 6.x-1.0
+version = 7.x-1.x-dev
 dependencies[] = token
 dependencies[] = cronplus
 
-core = 6.x
-; Information added by drupal.org packaging script on 2010-02-17
-version = "6.x-1.0"
-core = "6.x"
-project = "php_errors"
-datestamp = "1266446708"
-
-
-; Information added by drupal.org packaging script on 2010-11-08
-version = "6.x-1.3"
-core = "6.x"
-project = "php_errors"
-datestamp = "1289187946"
+files[] = php_errors.module
 
+core = 7.x
\ No newline at end of file
diff --git a/php_errors.install b/php_errors.install
index 449fe7c..55eda4f 100644
--- a/php_errors.install
+++ b/php_errors.install
@@ -1,28 +1,30 @@
 <?php
-// $Id: php_errors.install,v 1.6 2010/02/17 22:41:24 ptalindstrom Exp $  
-
+/**
+ * @file
+ * Provide installation data for php_errors.module
+ */
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function php_errors_schema() {
   $schema['php_errors_archive'] = array(
-    'description' => t("Stores archived PHP Error reports"),
+    'description' => "Stores archived PHP Error reports",
     'fields' => array(
       'rid' => array(
         'type' => 'serial',
         'unsigned' => TRUE,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'report' => array(
         'type' => 'text',
         'not null' => TRUE,
-        'size' => 'big'
+        'size' => 'big',
       ),
       'created' => array(
-        'type'        => 'int',
-        'length'      => 11,
-        'not null'    => TRUE,
+        'type' => 'int',
+        'length' => 11,
+        'not null' => TRUE,
       ),
     ),
     'primary key' => array('rid'),
@@ -31,30 +33,25 @@ function php_errors_schema() {
 }
 
 /**
- * Implementation of hook_install().
+ * Implements hook_install().
  */
 function php_errors_install() {
-  // Create tables.
-  drupal_install_schema('php_errors');
-  drupal_set_message(t('The table for the PHP Errors archive has been created successfully.'));
+ drupal_set_message(st('The table for the PHP Errors archive has been created successfully.'));
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function php_errors_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('php_errors');
-
   // remove variables
-  $result = update_sql("DELETE FROM {variable} WHERE name like 'php_errors_%'");
+  $result = db_delete('sms_carriers')
+    ->condition('name', 'php_errors_%')
+    ->execute();
 
-  
-  if ($result['success']) {
-    drupal_set_message('The PHP Errors module was successfully uninstalled.');
-  }
-  else {
-    drupal_set_message('There was an error removing the php_errors_archive table.', 'error');
-  }
+ if ($result['success']) {
+   drupal_set_message(t('The PHP Errors module was successfully uninstalled.'));
+ }
+ else {
+   drupal_set_message(t('There was an error removing the php_errors_archive table.'), 'error');
+ }
 }
-
diff --git a/php_errors.module b/php_errors.module
index aa4da37..2b15a7f 100644
--- a/php_errors.module
+++ b/php_errors.module
@@ -1,79 +1,88 @@
 <?php
-// $Id: php_errors.module,v 1.9 2010/11/08 03:43:06 ptalindstrom Exp $   
-                                                                                                     
 
 /**
- * Implementation of hook_help().
- */    
-function php_errors_help($path='', $arg) {
+ * Implements hook_help().
+ */
+function php_errors_help($path = '', $arg) {
   switch ($path) {
     case 'admin/modules#description':
-      return t("This module helps to manage your site's PHP Errors. It performs 3 functions: it provides a summary page of the 
-      watchdog's PHP errors, it archive's this summary and it may be set to email a summary report to specific email addresses 
-      or roles.");
+      return t("This module helps to notife you of your site's PHP Errors. It performs 3 functions: it provides a summary page
+      of the watchdog's PHP errors, it archive's this summary and it may be set to email a summary report to specific email
+      addresses or roles.");
+      break;
   }
 }
 
 /**
-* Implementation of hook_menu()
-*/
+ * Implements hook_menu().
+ */
 function php_errors_menu() {
   $items = array();
-    
+
   // Various Sub-tabs for PHP Error report formats and archive listing
   $items['admin/reports/php_errors'] = array(
-    'title' => 'PHP Errors',
+    'title' => 'PHP Errors report',
+    'description' => 'View PHP Errors.',
     'page callback' => '_php_errors_show',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM,
-  );        
+  );
   $items['admin/reports/php_errors/summary'] = array(
     'title' => 'Detail',
     'weight' => -5,
     'access arguments' => array('administer site configuration'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
-  );        
+  );
   $items['admin/reports/php_errors/links'] = array(
     'title' => 'Links Only',
+    'description' => 'View PHP Error page links only.',
     'weight' => -4,
     'page callback' => '_php_errors_show',
     'page arguments' => array('links'),
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
-  );      
+  );
   $items['admin/reports/php_errors/archive'] = array(
     'title' => 'Archive',
+    'description' => 'View the available PHP Errors archives.',
     'weight' => -3,
     'page callback' => '_php_errors_show_archive',
-    //'page arguments' => array('links'),
+    //    'page arguments' => array('links'),
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
   );
-  
-  // Admin settings
-  $items['admin/settings/php_errors'] = array(
-    'title' => 'PHP Errors',
-    'description' => 'Settings for PHP Errors module.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('php_errors_admin_settings'),
-    'access arguments' => array('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM,
-  );
 
-  $items['admin/reports/php_errors/archive/%php_errors_archive_id'] = array(
+  $items['admin/reports/php_errors/archive/%'] = array(
     'title' => 'Archive',
-    'page callback' => '_php_errors_archive_view',   
-    'page arguments' => array('php_errors_archive_id', 4),  
+    'description' => 'View the PHP Errors archive.',
+    'page callback' => 'php_errors_archive_view',
+    'page arguments' => array(5),
+//    'page arguments' => array('php_errors_archive_id', 4),
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
+//    'type' => MENU_CALLBACK,
+  );
+
+  // Admin settings
+  $items['admin/config/development/php_errors'] = array(
+    'title' => 'PHP Errors settings',
+    'description' => 'Configure the PHP errors report recipients and frequency.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('php_errors_admin_settings_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
   );
 
   return $items;
 }
 
 
-function php_errors_admin_settings() {
-  // system settings     
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function php_errors_admin_settings_form($form, &$form_state) {
+  // system settings
   $form['php_errors_notify_addresses'] = array(
     '#type' => 'textfield',
     '#title' => t('Admin Notification Email Addresses'),
@@ -81,39 +90,54 @@ function php_errors_admin_settings() {
     '#description' => t("Comma separated list of email addresses to send PHP Error summary report to."),
   );
   $form['php_errors_notify_roles'] = array(
-    '#type' => 'checkboxes', 
+    '#type' => 'checkboxes',
     '#title' => t('Notification Role'),
     '#options' => user_roles(true),
     '#default_value' => variable_get('php_errors_notify_roles', array()),
     '#description' => t("Defines roles which will be sent the PHP Error summary report."),
-  );          
+  );
   $form['php_errors_notify_frequency'] = array(
-    '#type' => 'radios',   
+    '#type' => 'radios',
     '#title' => t('Frequency of Notification'),
-    '#options' => array(0 => 'never', 1 => 'daily', 2 => 'weekly', 3 => 'monthly'),
-    '#default_value' => variable_get('php_errors_notify_frequency', 2),
+    '#options' => array(
+      0 => 'never',
+      1 => 'on demand',
+      2 => 'hourly',
+      3 => 'daily',
+      4 => 'weekly',
+      5 => 'monthly',
+    ),
+    '#default_value' => variable_get('php_errors_notify_frequency', 4),
     '#description' => t("Select how often email error reports will be sent. NOTE: archiving is done weekly, regardless of this setting."),
-  ); 
+  );
 
   return system_settings_form($form);
 }
 
-function _php_errors_show($type = null) {
+function _php_errors_show($type = NULL) {
   $rows = array();
-  $results = db_query("SELECT count(1) cnt, timestamp ts, message ms, variables v, location 
-    FROM watchdog WHERE type = 'php'
-    GROUP by MID(v, 62, 30) ORDER BY timestamp DESC, cnt DESC");
+
+  $query = db_select('watchdog', 'w');
+  $query->addExpression('COUNT(1)', 'count');
+  $query->fields('w', array('type', 'timestamp', 'message', 'variables', 'link')); // SELECT the fields from watchdog
+  $query = $query
+    ->condition('w.type', 'php')
+    ->groupBy('message')
+    ->groupBy('variables')
+    ->orderBy('timestamp', 'DESC') //ORDER BY timestamp
+    ->orderBy('count', 'DESC'); //ORDER BY count
+  $results = $query->execute();
   
   // and if results - lets print them out in a nice table
-  if ($type == 'links') {        
+  if ($type == 'links') {
     $header = array(
-       array('data' => t('Count')),
-       array('data' => t('Location')),
-    );         
-    while ($result = db_fetch_object($results)) {           
+      array('data' => t('Count')),
+      array('data' => t('Location')),
+    );
+    foreach ($results as $result) {
       $row = array();
-      $row[] = $result->cnt;
-      $row[] = $result->location;
+      $row[] = $result->count;
+      $row[] = l($result->location, $result->location);
       $rows[] = $row;
     }
   }
@@ -123,135 +147,198 @@ function _php_errors_show($type = null) {
       array('data' => t('Date')),
       array('data' => t('Error')),
       array('data' => t('Location')),
-    );    
-    while ($result = db_fetch_object($results)) {           
-      $variables = unserialize($result->v);
-      $error = str_replace(array('%message', '%file', '%line'), array($variables['%message'], $variables['%file'], $variables['%line']), "%message in %file on line %line.");   
+    );
+
+    foreach ($results as $result) {
+      $variables = unserialize($result->variables);
+       dpm($result);
+     $error = str_replace(array('!message', '%file', '%line'),
+     array($variables['!message'], $variables['%file'], $variables['%line']),
+     "!message in %file on line %line.");
       $row = array();
-      $row[] = $result->cnt;
-      $row[] = date("m-d-Y", $result->ts);
-      $row[] = wordwrap(html_entity_decode($error), 60, "<br>", 1);
-      $row[] = $result->location;
+      $row[] = $result->count;
+      $row[] = format_date($result->timestamp, 'short');
+      $row[] = wordwrap(html_entity_decode($error), 60, "<br />", 1);
+      $row[] = l($result->location, $result->location);
       $rows[] = $row;
     }
+    
   }
 
-  return theme('table', $header, $rows);
+  return theme('table', array('header' => $header, 'rows' => $rows));
 }
 
 function _php_errors_email() {
-  $results = db_query("SELECT count(1) cnt, timestamp ts, message ms, location 
-    FROM watchdog WHERE type = 'php'
-    GROUP by LEFT(ms, 30) ORDER BY timestamp DESC, cnt DESC");
-  
+  $query = db_select('watchdog', 'w');
+  $query->addExpression('COUNT(1)', 'count');
+  $query->fields('w', array('type', 'timestamp', 'message', 'variables', 'link')); // SELECT the fields from watchdog
+  $query = $query
+    ->condition('w.type', 'php')
+    ->groupBy('message')
+    ->groupBy('variables')
+    ->orderBy('timestamp', 'DESC') //ORDER BY timestamp
+    ->orderBy('count', 'DESC'); //ORDER BY count
+  $results = $query->execute();
+
   // and if results - lets format them as a table for a txt email
-  $header = sprintf("\n\n%-10s %-20s %-55s \n", t('Count'), t('Date'), t('Location')) .t('Error'); 
+  $header = sprintf("\n\n%-10s %-20s %-55s \n", t('Count'), t('Date'), t('Location')) . t('Error');
   $header .= "\n--------------------------------------------------------------------------------\n\n";
 
   $rows = "";
-  while ($result = db_fetch_object($results)) {           
-    $rows .= sprintf("%-10s %-20s %-55s \n", 
-      $result->cnt, 
-      date("m-d-Y", $result->ts), 
+  foreach ($results as $result) {
+    $rows .= sprintf("%-10s %-20s %-55s \n",
+      $result->count,
+      format_date($result->timestamp, "short"),
       $result->location
     );
-    $rows .= strip_tags(html_entity_decode($result->ms, ENT_QUOTES)) ."\n\n";
+    $rows .= strip_tags(html_entity_decode($result->timestamp, ENT_QUOTES)) . "\n\n";
   }
-  
-  $preamble = "The following is this weeks PHP Error Summary Report.\n\nRegards,\n\n" . variable_get('site_name', 'Your Site'); 
-  
+
+  $preamble = "The following is this weeks PHP Error Summary Report.\n\nRegards,\n\n" . variable_get('site_name', 'Your Site');
+
   return $preamble . $header . $rows;
 }
 
 function _php_errors_show_archive() {
-  $results = db_query("SELECT * FROM {php_errors_archive} ORDER BY created DESC");
-  
+  $results = db_query("SELECT rid, report, created FROM {php_errors_archive} ORDER BY created DESC");
+
   $header = array(
     array('data' => t('Archived Reports')),
-    array(''=>""),
-    array(''=>""),
-    array(''=>"")
-  ); 
-  
-  $row = 1; $col = 1;
-  while ($report = db_fetch_object($results)) {
+    array('' => ""),
+    array('' => ""),
+    array('' => ""),
+  );
+
+  $row = 1;
+  $col = 1;
+  foreach ($results as $report) {
     if ($col > 4) {
       $col = 1;
       $row++;
     }
-    $reports[$row][$col] = l(date("M d, Y", $report->created), "admin/reports/php_errors/archive/". $report->rid);
+    $reports[$row][$col] = l(format_date($report->created, 'short'), 'admin/reports/php_errors/archive/' . $report->rid);
     $col++;
   }
-  
+
   // fill out other columns with blanks to improve look
   for ($c = $col; $c < 5; $c++) {
     $reports[$row][$c] = "";
   }
-  
-  return theme('table', $header, $reports);
+
+  return theme('table', array('header' => $header, 'rows' => $reports));
 }
 
 // Show an archived report
-function _php_errors_archive_view($rid) {
-  $report =  db_fetch_object(db_query("SELECT * FROM {php_errors_archive} WHERE rid = %d", $rid));  
-  
-  drupal_set_title(t("PHP Errors") ." - <em>Archived Report for: ". date("M d, Y", $report->created) ."</em>");
-  
-  $output = '<input onclick="location.href=\''. url("admin/reports/php_errors/archive") .'\'" type="submit" class="form-submit" value="Return to Archive" id="edit-submit"/>';
-  $output .= "<br><br>". $report->report;
-  
-  return $output;
+function php_errors_archive_view($rid = 1) {
+$rid = 1;
+  $report = db_query("SELECT rid, report, created FROM {php_errors_archive} WHERE rid = :rid", array(':rid' => $rid))->fetchObject();
+  drupal_set_title(t("PHP Errors - Archived Report for: ") . format_date($report->created, 'short'));
+
+ $output = '<input onclick="location.href=\'' . url("admin/reports/php_errors/archive") . '\'" type="submit" class="form-submit" value="Return to Archive" id="edit-submit"/>';
+ $output .= "<br /><br />". $report->report;
+
+ return $output;
 }
 
-/* Uses CronPLUS module to do a couple weekly tasks:
-*     - send email notifications to selected users (frequency based on frequency setting)
-*     - archive the error report (weekly)
-*/
+/* Uses Cronplus module to do a couple tasks:
+ * - send email notifications to selected users (based on frequency setting)
+ * - archive the error report (weekly)
+ */
+
+/**
+ * Uses cronplus module to send the notificaiton if on demand is selected.
+ */
+function php_errors_cronplus_on_demand($now, $last_cron, $last_this) {
+  if (variable_get('php_errors_notify_frequency', 0) == 1) {
+    _php_errors_send_notifications();
+  }
+}
+
+/**
+ * Uses cronplus module to send the notificaiton if hourly is selected.
+ */
+function php_errors_cronplus_hourly($now, $last_cron, $last_this) {
+  if (variable_get('php_errors_notify_frequency', 0) == 2) {
+    _php_errors_send_notifications();
+  }
+}
+
+/**
+ * Uses cronplus module to send the notificaiton if daily is selected.
+ */
 function php_errors_cronplus_daily($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 0) == 1) _php_errors_send_notifications();
+  if (variable_get('php_errors_notify_frequency', 0) == 3) {
+    _php_errors_send_notifications();
+  }
 }
+
+/**
+ * Archives the report weekly.
+ *
+ * Uses cronplus module to send the notificaiton if weekly is selected.
+ */
 function php_errors_cronplus_weekly($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 2) == 2) _php_errors_send_notifications();    // default to weekly if not set
-  
+  if (variable_get('php_errors_notify_frequency', 4) == 4) {
+    _php_errors_send_notifications(); // default to weekly if not set
+  }
   // archive the report
   $report = _php_errors_show();
-  db_query("INSERT INTO {php_errors_archive} (report, created) VALUES ('%s', %d)", $report, time()); 
-}   
+  $id = db_insert('php_errors_archive')
+    ->fields(array(
+      'report' => $report,
+      'created' => REQUEST_TIME,
+    ))
+    ->execute();
+}
+
+/**
+ * Uses cronplus module to send the notificaiton if monthly is selected.
+ */
 function php_errors_cronplus_monthly($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 0) == 3) _php_errors_send_notifications();
+  if (variable_get('php_errors_notify_frequency', 0) == 5) {
+    _php_errors_send_notifications();
+  }
 }
 
-// email summary report to selected users 
+/**
+ * Emails the summary report to the selected users.
+ */
 function _php_errors_send_notifications() {
   $site_name = variable_get('site_name', 'Your Site');
-  $params['from'] = "$site_name <". variable_get('site_mail', ini_get('sendmail_from')) .'>';;
-  
+  $from = "$site_name <" . variable_get('site_mail', ini_get('sendmail_from')) . '>';
+
   // pull list of all user in selected roles
   $users = _php_errors_get_roles_emails();
-  
+
   // and add individual csv list of addresses
   // if there are any individual emails address; lets use those
   // if none; lets at least send to site admin
-  if (!$ind_emails = variable_get('php_errors_notify_addresses', '')) $ind_emails = variable_get('site_mail', '');
+  if (!$ind_emails = variable_get('php_errors_notify_addresses', '')) {
+    $ind_emails = variable_get('site_mail', '');
+  }
   $single_emails = split(",", $ind_emails);
   if (count($single_emails)) {
     foreach ($single_emails as $single) {
-      if (valid_email_address(trim($single))) $users[trim($single)] = trim($single);
+      if (valid_email_address(trim($single))) {
+        $users[trim($single)] = trim($single);
+      }
     }
   }
   $users = array_unique($users);
-  if (!count($users)) break;
-  
+  if (!count($users)) {
+    break;
+  }
+
   // create single CSV list of addresses
-  foreach ($users as $name => $email) {      
-    $emails[] = $name . " <". $email .">";
+  foreach ($users as $name => $email) {
+    $emails[] = $name . " <" . $email . ">";
   }
   $recipients = join(",", $emails);
-  
-  $params['subject'] = t("PHP Error Summary Report");
-  $params['body'] = _php_errors_email();
 
-  if (drupal_mail('php_errors', 'php_error_report', $recipients, language_default(), $params)) {
+  // build the message for sending
+  $message = drupal_mail('php_errors', 'php_error_report', $recipients, language_default(), $params, $from);
+  // send the confirmation mail
+  if ($message['result']) {
     watchdog('action', 'Sent email to %recipients', array('%recipients' => $recipients));
   }
   else {
@@ -259,26 +346,48 @@ function _php_errors_send_notifications() {
   }
 }
 
-// get array of all email addresses for each user in selected roles
+/**
+ * Builds the message subject and body.
+ */
+function php_errors_mail($key, &$message, $params) {
+  $message['subject'] = t("PHP Error Summary Report");
+  $message['body'] = _php_errors_email();
+}
+
+/**
+ * Get array of all email addresses for each user in selected roles.
+ */
 function _php_errors_get_roles_emails() {
   $emails = array();
-  
+
   $roles = variable_get('php_errors_notify_roles', 0);
-  if (!$roles) return;
-  
+  if (!$roles) {
+    return;
+  }
+
   $included = array_filter($roles);
-  
+
   if (count($included) > 1) {
-    foreach ($included as $role) $rolesql[] = " ur.rid = $role ";
-    $roles_where = join(" OR ", $rolesql);
+    foreach ($included as $role) {
+      $rolesql[] = " r.rid = $role ";
+    }
+    $roles_where = implode(" OR ", $rolesql);
   }
-  else $roles_where = " ur.rid = ". current($included); 
-  
-  $result = db_query("SELECT u.uid, u.name, u.mail, u.status FROM {users} u
-    INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE $roles_where AND u.status = 1");
-  
-  while ($u = db_fetch_object($result)) $emails[$u->name] = $u->mail;
-  
-  return $emails;
-}
+  else {
+    $roles_where = " r.rid = " . current($included);
+  }
+
+  $query = db_select('users', 'u');
+  $query->join('users_roles', 'r', 'u.uid = r.uid'); // JOIN users with users_roles
+  $query->fields('u', array('uid', 'name', 'mail', 'status')); // SELECT the fields from users
+  $query->fields('r', array('rid')); // SELECT the fields from users_roles
+  $query->condition('r.uid', $roles_where, '='); // WHERE rid is $roles_where
+  $query->condition('r.status', 1, '='); // WHERE status is 1
+  $result = $query->execute();
 
+  foreach($result as $u) {
+    $emails[$u->name] = $u->mail;
+  }
+
+  return $emails;
+}
