diff --git a/README.txt b/README.txt
index 5662d21..095bcd3 100644
--- a/README.txt
+++ b/README.txt
@@ -1,3 +1,4 @@
+$Id: README.txt,v 1.7.2.4 2009/10/01 18:55:12 kbahey Exp $
 
 Copyright 2005 http://2bits.com
 
diff --git a/customerror.info b/customerror.info
index fd64371..c0fa579 100644
--- a/customerror.info
+++ b/customerror.info
@@ -1,3 +1,16 @@
+; $Id: customerror.info,v 1.5 2008/05/21 23:29:37 kbahey Exp $
 name = Custom Error
 description = Enables the creation of custom error pages for 404 and 403 errors, as well as redirects for 404s.
-core=6.x
+core=7.x
+
+; Information added by drupal.org packaging script on 2010-11-26
+version = "7.x-1.x-dev"
+core = 7.x
+project = "customerror"
+datestamp = "1290773397"
+
+
+files[] = customerror.install
+files[] = customerror.module
+files[] = tests/accessdenied.test
+files[] = tests/pagenotfound.test
diff --git a/customerror.install b/customerror.install
index 6d5dddc..ac32ed8 100644
--- a/customerror.install
+++ b/customerror.install
@@ -1,9 +1,22 @@
 <?php
+// $Id: customerror.install,v 1.2.2.2 2008/09/13 02:56:30 kbahey Exp $
 
+/**
+ * @file
+ * Install, update and uninstall functions for the customerror module.
+ *
+ */
+
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function customerror_uninstall() {
-  db_query("DELETE FROM {variable} WHERE name LIKE 'customerror_%'");
+  db_delete('variable')
+  ->condition('name', 'customerror_%', 'LIKE')
+  ->execute();
 
-  foreach(_customerror_enum_errors() as $code => $desc) {
+  foreach (_customerror_enum_errors() as $code => $desc) {
     if (variable_get('site_' . $code, '') == 'customerror/' . $code) {
       variable_del('site_' . $code, '');
     }
diff --git a/customerror.module b/customerror.module
index e103cfe..d1d8814 100644
--- a/customerror.module
+++ b/customerror.module
@@ -1,5 +1,6 @@
 <?php
 
+//$Id: customerror.module,v 1.17.2.13 2010/11/26 00:18:08 kbahey Exp $
 
 // Copyright 2005 Khalid Baheyeldin http://2bits.com
 
@@ -15,9 +16,9 @@ function _customerror_enum_errors() {
   // stored. Add here as necessary.
   $errors = array(
     404 => t('requested page not found'),
-    403 => t('access denied')
+    403 => t('access denied'),
   );
-  
+
   // Sorting array here by keys so they are logically sorted on form
   ksort($errors);
 
@@ -40,28 +41,31 @@ function _customerror_fetch_error($error_code) {
 }
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function customerror_help($path, $arg) {
   $output = '';
   switch ($path) {
-    case 'admin/modules#description':
-    case 'admin/settings/customerr':
+    case 'admin/help#customerror':
+    case 'admin/config/system/customerror':
       $output = t('Enables the creation of custom error pages for 404 and 403 errors.');
       break;
   }
   return $output;
 }
 
-function customerror_admin_settings() {
+/**
+ * Display the module settings form.
+ */
+function customerror_admin_settings($form, &$form_state) {
   $form = array(
     'customerror_form_description' => array(
       '#type' => 'markup',
-      '#value' => t('Enter the error pages that will be seen by your visitors when they get the respective errors. You can enter any HTML text. You can point the users to the FAQ, inform them that you reorganized the site, ask them to report the error, login or register, ...etc.')
-    )
+      '#value' => t('Enter the error pages that will be seen by your visitors when they get the respective errors. You can enter any HTML text. You can point the users to the FAQ, inform them that you reorganized the site, ask them to report the error, login or register, ...etc.'),
+    ),
   );
 
-  $themes = system_theme_data();
+  $themes = system_rebuild_theme_data();
   ksort($themes);
   $theme_options[0] = t('System default');
   foreach ($themes as $theme) {
@@ -69,34 +73,34 @@ function customerror_admin_settings() {
   }
 
   $errors = _customerror_enum_errors();
-  foreach($errors as $code => $desc) {
+  foreach ($errors as $code => $desc) {
     if (variable_get('site_' . $code, '') != 'customerror/' . $code) {
-      drupal_set_message(t('Error reporting is not set for error !error. Please ensure that the default !error page is set to be customerror/!error on the !link.', array('!error' => $code, '!link' => l(t('Error reporting settings page'), 'admin/settings/error-reporting'))), 'error');
+      drupal_set_message(t('Error reporting is not set for error !error. Please ensure that the default !error page is set to be customerror/!error on the !link.', array('!error' => $code, '!link' => l(t('Site information settings page'), 'admin/config/system/site-information'))), 'error');
     }
   }
 
-  foreach($errors as $code => $desc) {
+  foreach ($errors as $code => $desc) {
     $group = 'customerror_' . $code . '_group';
     $form[$group] = array(
-      '#type'          => 'fieldset',
-      '#title'         => t('!code Error Settings', array('!code' => $code)),
-      '#collapsed'     => true,
-      '#collapsible'   => true,
+      '#type' => 'fieldset',
+      '#title' => t('!code Error Settings', array('!code' => $code)),
+      '#collapsed' => true,
+      '#collapsible' => true,
     );
     $form[$group]['customerror_' . $code . '_title'] = array(
-      '#type'          => 'textfield',
-      '#title'         => t('Title for @code', array('@code' => $code)),
+      '#type' => 'textfield',
+      '#title' => t('Title for @code', array('@code' => $code)),
       '#default_value' => variable_get('customerror_' . $code . '_title', $desc),
-      '#size'          => 70,
-      '#maxlength'     => 70,
-      '#description'   => t('Title of @code error page', array('@code' => $code . ' error page')),
+      '#size' => 70,
+      '#maxlength' => 70,
+      '#description' => t('Title of @code error page', array('@code' => $code . ' error page')),
     );
     $form[$group]['customerror_' . $code] = array(
-      '#type'          => 'textarea',
-      '#title'         => t('Description for ') . $code,
+      '#type' => 'textarea',
+      '#title' => t('Description for ') . $code,
       '#default_value' => variable_get('customerror_' . $code, $desc),
-      '#rows'          => 10,
-      '#description'   => t('This text will be displayed if a @code (@desc) error occurs.', array('@code' => $code, '@desc' => $desc)),
+      '#rows' => 10,
+      '#description' => t('This text will be displayed if a @code (@desc) error occurs.', array('@code' => $code, '@desc' => $desc)),
     );
     $form[$group]['customerror_' . $code . '_theme'] = array(
       '#type' => 'select',
@@ -106,80 +110,86 @@ function customerror_admin_settings() {
       '#default_value' => customerror_get_theme($code),
     );
     $form[$group]['customerror_' . $code . '_php'] = array(
-      '#type'          => 'checkbox',
-      '#title'         => t('Allow PHP code to be executed for @code', array( '@code' => $code)),
+      '#type' => 'checkbox',
+      '#title' => t('Allow PHP code to be executed for @code', array('@code' => $code)),
       '#default_value' => variable_get('customerror_' . $code . '_php', FALSE),
-      '#description'   => t('This allows you to include PHP code (enclosed in &lt;?php ?&gt; tags) for the @code (@desc) message. Note that this can be dangerous in some situations. Make sure that you are aware of the implications.', array('@code' => $code, '@desc' => $desc)),
+      '#description' => t('This allows you to include PHP code (enclosed in &lt;?php ?&gt; tags) for the @code (@desc) message. Note that this can be dangerous in some situations. Make sure that you are aware of the implications.', array('@code' => $code, '@desc' => $desc)),
     );
   }
 
   $form['redirects'] = array(
-    '#type'            => 'fieldset',
-    '#title'           => t('Redirects'),
-    '#collapsed'       => TRUE,
-    '#collapsible'     => TRUE,
+    '#type' => 'fieldset',
+    '#title' => t('Redirects'),
+    '#collapsed' => TRUE,
+    '#collapsible' => TRUE,
   );
   $form['redirects']['customerror_redirect'] = array(
-    '#type'            => 'textarea',
-    '#title'           => t('Redirect list'),
-    '#default_value'   => variable_get('customerror_redirect', ''),
-    '#rows'            => 10,
-    '#description'     => t('These are custom redirect pairs, one per line. Each pair requires a path to match (which is a regular expression) and a destination separated by a space. The keyword <em>&lt;front></em> is allowed as a destination. If you are unfamilar with regular expressions, a simple search string will work, but will match any part of the URl. For example <em>index.html &lt;front></em> will match both <em>http://example.com/index.html &amp; http://example.com/archive/index.html</em>.'),
+    '#type' => 'textarea',
+    '#title' => t('Redirect list'),
+    '#default_value' => variable_get('customerror_redirect', ''),
+    '#rows' => 10,
+    '#description' => t('These are custom redirect pairs, one per line. Each pair requires a path to match (which is a regular expression) and a destination separated by a space. The keyword <em>&lt;front></em> is allowed as a destination. If you are unfamilar with regular expressions, a simple search string will work, but will match any part of the URl. For example <em>index.html &lt;front></em> will match both <em>http://example.com/index.html &amp; http://example.com/archive/index.html</em>.'),
   );
 
   return system_settings_form($form);
 }
 
+/**
+ * Implements hook_menu().
+ */
 function customerror_menu() {
   $items = array();
 
-  $items['admin/settings/customerror'] = array(
-    'title'            => 'Custom error',
-    'description'      => 'Administer custom error.',
-    'page callback'    => 'drupal_get_form',
-    'page arguments'   => array('customerror_admin_settings'),
+  $items['admin/config/system/customerror'] = array(
+    'title' => 'Custom error',
+    'description' => 'Enables the creation of custom error pages for 404 and 403 errors.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('customerror_admin_settings'),
     'access arguments' => array('administer site configuration'),
-    'type'             => MENU_NORMAL_ITEM,
+    'type' => MENU_NORMAL_ITEM,
   );
 
   $items['customerror'] = array(
-    'title'           => 'customerror',
+    'title' => 'customerror',
     'access callback' => TRUE,
-    'page callback'   => 'customerror_page',
-    'type'            => MENU_CALLBACK,
+    'page callback' => 'customerror_page',
+    'type' => MENU_CALLBACK,
   );
 
   return $items;
 }
 
 /**
-* Implementation of hook_simpletest().
-*/
+ * Implements hook_simpletest().
+ */
 function customerror_simpletest() {
   return array_keys(file_scan_directory(
-    drupal_get_path('module', 'customerror') . '/tests', '\.test$'));
+    drupal_get_path('module', 'customerror') . '/tests', '/\.test$/'));
 }
 
+/**
+ * Display the 403 or 404 error page.
+ */
 function customerror_page() {
   $code = arg(1);
 
   // set custom theme for error_page if any has been selected, 0 => default
   $theme = customerror_get_theme($code);
-  if(!empty($theme)){
+  if (!empty($theme)) {
     global $custom_theme;
     $custom_theme = $theme;
   }
 
-  switch($code) {
+  switch ($code) {
     case 403:
       $internal_path = substr(request_uri(), strlen(base_path()));
       if ($internal_path) {
-        $_REQUEST['destination'] = $internal_path;
+        $_GET['destination'] = $internal_path;
       }
       else {
-        $_REQUEST['destination'] = variable_get('site_frontpage', 'node');
+        $_GET['destination'] = variable_get('site_frontpage', 'node');
       }
-      $_SESSION['destination'] = $_REQUEST['destination'];
+      $_SESSION['destination'] = $_GET['destination'];
     case 404:
     default: // Treat an unknown method as a 404
       // Check if we should redirect
@@ -190,44 +200,76 @@ function customerror_page() {
 
       module_invoke_all('customerror_pre_render', $code);
 
-      drupal_set_title(variable_get('customerror_'. $code .'_title', _customerror_fetch_error($code)));
-      $output = theme('customerror', $code, variable_get('customerror_' . $code, _customerror_fetch_error($code)));
-      $output = (variable_get('customerror_' . $code . '_php', FALSE)) ? drupal_eval($output) : $output;
+      drupal_set_title(variable_get('customerror_' . $code . '_title', _customerror_fetch_error($code)));
+      $output = theme('customerror', array('0' => $code, '1' => variable_get('customerror_' . $code, _customerror_fetch_error($code))));
+      if (module_exists('php')) {
+        $output = (variable_get('customerror_' . $code . '_php', FALSE)) ? php_eval($output) : $output;
+
+      }
       break;
   }
   return $output;
 }
 
+/**
+ * Set the http header depending on the error code (403 or 404).
+ *
+ * @param integer $code
+ *   The error code, either 403 or 404.
+ */
 function customerror_header($code) {
-  switch($code) {
+  switch ($code) {
     case 403:
-      drupal_set_header('HTTP/1.1 403 Forbidden');
+      drupal_add_http_header('Status', '403 Forbidden');
       break;
     case 404:
-      drupal_set_header('HTTP/1.1 404 Not Found');
+      drupal_add_http_header('Status', '404 Not Found');
       break;
   }
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function customerror_theme() {
   return array(
     'customerror' => array(
-      'arguments' => array('code', 'content')
+      'variables' => array('code', 'content'),
     ),
   );
 }
 
 /**
- * Themeable function 
+ * Themeable function
  */
-function theme_customerror($code, $content) {
+function theme_customerror($variables) {
+  $code = $variables['0'];
+  $content = $variables['1'];
   return $content;
 }
 
-function customerror_user($op, $edit, $user) {
+/**
+ * Implements hook_user_login().
+ */
+function customerror_user_login(&$edit, $account) {
+  // Check if we have a destination saved in the session
+  if (!empty($_SESSION['destination'])) {
+    // If there is one, then set the REQUEST destination to it
+    $_GET['destination'] = $_SESSION['destination'];
+    // And clear the one in the session
+    unset($_SESSION['destination']);
+    // user.module then does a drupal_goto() for us after we return from here
+  }
+}
+
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function customerror_user_OLD($op, $edit, $user) { 
+/*
+@todo Revise the following Drupal 6.x code for Drupal 7.x, if appropriate.
+
   switch($op) {
     case 'login':
       // Check if we have a destination saved in the session
@@ -239,28 +281,29 @@ function customerror_user($op, $edit, $user) {
         // user.module then does a drupal_goto() for us after we return from here
       }
   }
+
+*/
 }
 
 function customerror_check_redirect() {
-  $destination = $_REQUEST['destination'];
+  $destination = $_GET['destination'];
   if (empty($destination)) {
     return;
   }
 
   $list = explode("\n", variable_get('customerror_redirect', ''));
-  if (count($list) <= 1) {
+  if (count($list) < 1) {
     return;
   }
-
-  foreach($list as $item) {
+  foreach ($list as $item) {
     list($src, $dst) = explode(' ', $item);
     if (isset($src) && isset($dst)) {
       $src = str_replace("/", "\\/", $src);
       $dst = str_replace("\r", "", $dst);
       // In case there are spaces in the URL, we escape them
       $orig_dst = str_replace(" ", "%20", $destination);
-      if (preg_match('/'. $src .'/', $orig_dst)) {
-        $_REQUEST['destination'] = $dst;
+      if (preg_match('/' . $src . '/', $orig_dst)) {
+        $_GET['destination'] = $dst;
         drupal_goto($dst);
       }
     }
@@ -268,19 +311,23 @@ function customerror_check_redirect() {
 }
 
 /**
- * Implementation of hook_form_alter. We need this to be able to search from
+ * Implements hook_form_alter. We need this to be able to search from().
  * the error pages, otherwise the form POST's to the error page, bringing no
  * results page.
  */
 function customerror_form_alter($form_id, &$form) {
   switch ($form_id) {
     case 'search_theme_form':
-      if (arg(0) == 'customerror')
+      if (arg(0) == 'customerror') {
         $form['#action'] = url('search/node');
+      }
       break;
   }
 }
 
+/**
+ * Get the configured display theme for the given error code.
+ */
 function customerror_get_theme($code = 404) {
   $theme = 0;
 
@@ -290,4 +337,4 @@ function customerror_get_theme($code = 404) {
   }
 
   return $theme;
-}
\ No newline at end of file
+}
