--- troll/troll.module	2006-05-22 02:35:52.000000000 -0700
+++ troll-new/troll.module	2007-03-03 22:30:40.056480228 -0800
@@ -59,7 +59,8 @@ function troll_init() {
     if($ban->ip_address) {
       global $base_url;
       watchdog('troll', 'IP Ban: '. $_SERVER['REMOTE_ADDR'], l(t('administer'), 'admin/troll/ip_ban/'), WATCHDOG_NOTICE);
-      $page = variable_get('troll_ip_ban_redirect', 'modules/troll/blocked.html');
+      $troll_ip_ban_redirect = variable_get('troll_ip_ban_redirect', '');
+      $page = (empty($troll_ip_ban_redirect) ? drupal_get_path('module', 'troll') .'/blocked.html' : $troll_ip_ban_redirect);
       header('location: '. $base_url .'/'. $page);
       die();
     }
@@ -71,12 +72,9 @@ function troll_init() {
  */
 function troll_help($section = 'admin/help#legal') {
   switch ($section) {
-    case 'admin/modules#description':
-      return t('Troll management tools');
-      break;
     case 'admin/troll/ip_ban':
       if(!variable_get('troll_enable_ip_ban', FALSE)) {
-        return theme('error', t('IP banning is currently disabled, you can enable it in the %settings page', array('%settings' => l(t('settings'), 'admin/settings/troll'))));
+        return theme('error', t('IP banning is currently disabled, you can enable it in the !settings page', array('!settings' => l(t('settings'), 'admin/settings/troll'))));
       }
       break;
   }
@@ -92,7 +90,7 @@ function troll_perm() {
 /**
  * Implementation of hook_settings().
  */
-function troll_settings() {
+function troll_admin_settings() {
   $form['ip_settings'] = array(
     '#type' => 'fieldset',
     '#title' => 'IP Address Banning',
@@ -106,8 +104,8 @@ function troll_settings() {
   $form['ip_settings']['troll_ip_ban_redirect'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Ban Relocation Page'),
-    '#default_value' => variable_get('troll_ip_ban_redirect', 'modules/troll/blocked.html'),
-    '#description' => t('Page for relocating users banned based on their IP address or domain name. Do not use a drupal path here! You will cause a loop since IP banning completely blocks all access to the site! Edit the blocked.html file, or redirect to http://localhost.'),
+    '#default_value' => variable_get('troll_ip_ban_redirect', ''),
+    '#description' => t("Page for relocating users banned based on their IP address or domain name.  If left blank, users will be redirected to blocked.html in the troll module's directory. Do not use a drupal path here! You will cause a loop since IP banning completely blocks all access to the site! Edit the blocked.html file, or redirect to http://localhost."),
     );
 
   $roles = user_roles();
@@ -123,7 +121,7 @@ function troll_settings() {
     '#description' => t('Select the role to set users to when blocking from the troll adminstration screens'),
     );
 
-  return $form;
+  return system_settings_form($form);
 }
 
 /**
@@ -133,6 +131,14 @@ function troll_menu($may_cache) {
   $items = array();
 
   if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/troll',
+      'title' => t('Troll settings'),
+      'description' => t('Configure IP banning.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'troll_admin_settings',
+      'access' => user_access('administer site configuration'),
+    );
     $items[] = array('path' => 'admin/troll',
       'title' => t('troll'),
       'callback' => 'troll_search_users',
@@ -161,7 +167,7 @@ function troll_menu($may_cache) {
       );
     $items[] = array('path' => 'admin/troll/ip_ban/edit',
       'title' => t('IP Ban Form'),
-      'callback' => 'troll_ip_ban_form',
+      'callback' => 'troll_ip_ban_edit',
       'type' => MENU_CALLBACK,
       'access' => user_access('administer trolls')
       );
@@ -180,7 +186,7 @@ function troll_menu($may_cache) {
  */
 function troll_ip_ban($op = NULL, $iid = NULL) {
   $op   = $_POST['op'] ? $_POST['op'] : $op;
-  $edit = $_POST['edit'] ? $_POST['edit'] : $edit;
+  $edit = $_POST ? $_POST : $edit;
 
   switch ($op) {
     case 'user':
@@ -218,7 +224,7 @@ function troll_ip_ban($op = NULL, $iid =
       $form['banform'] = array(
         '#type' => 'fieldset',
         '#title' => t('Add IP Ban'),
-        '#value' => troll_ip_ban_form(),
+        '#value' => troll_ip_ban_edit(),
         '#weight' => -1,
         '#collapsible' => true
         );
@@ -229,7 +235,7 @@ function troll_ip_ban($op = NULL, $iid =
         '#weight' => 0,
         '#collapsible' => true
         );
-      $output = form_render($form);
+      $output = drupal_render($form);
       break;
   }
   return $output;
@@ -245,7 +251,7 @@ function troll_ip_ban($op = NULL, $iid =
  */
 function troll_blacklist($op = NULL, $edit = NULL) {
   $op   = $_POST['op'] ? $_POST['op'] : $op;
-  $edit = $_POST['edit'] ? $_POST['edit'] : $edit;
+  $edit = $_POST ? $_POST : $edit;
 
   switch ($op) {
     case t('Update Blacklist Punishments'):
@@ -309,7 +315,7 @@ function troll_blacklist($op = NULL, $ed
       $form['blacklist_punishment'] = array(
         '#type' => 'fieldset',
         '#title' => t('Blacklist Visitor Punishment'),
-        '#value' => troll_blacklist_punishment_form(),
+        '#value' => drupal_get_form('troll_blacklist_punishment_form'),
         '#weight' => -3,
         '#collapsible' => true,
         '#collapsed' => true
@@ -317,7 +323,7 @@ function troll_blacklist($op = NULL, $ed
       $form['blacklist_import'] = array(
         '#type' => 'fieldset',
         '#title' => t('Import Blacklist'),
-        '#value' => troll_blacklist_import_form(),
+        '#value' => drupal_get_form('troll_blacklist_import_form'),
         '#weight' => -2,
         '#collapsible' => true,
         '#collapsed' => true
@@ -325,7 +331,7 @@ function troll_blacklist($op = NULL, $ed
       $form['search_blacklist'] = array(
         '#type' => 'fieldset',
         '#title' => t('Search Blacklisted IPs'),
-        '#value' => troll_blacklist_search_form(),
+        '#value' => drupal_get_form('troll_blacklist_search_form'),
         '#weight' => 0,
         '#collapsible' => true,
         '#collapsed' => false
@@ -333,13 +339,13 @@ function troll_blacklist($op = NULL, $ed
       $form['whitelist_form'] = array(
         '#type' => 'fieldset',
         '#title' => t('Whitelist IPs'),
-        '#value' => troll_whitelist_form(),
+        '#value' => troll_whitelist_form_and_table(),
         '#description' => t('Whitelisted IPs override the blacklist. Does not apply to the IP Ban feature.'),
         '#weight' => 1,
         '#collapsible' => true,
         '#collapsed' => false
         );
-      $output = form_render($form);
+      $output = drupal_render($form);
       break;
   }
   return $output;
@@ -396,7 +402,7 @@ function troll_blacklist_punishment_form
     '#value' => t('Update Blacklist Punishments'),
     '#weight' => 1,
   );
-  return drupal_get_form('troll_blacklist', $form);
+  return $form;
 }
 
 /**
@@ -450,7 +456,7 @@ function troll_blacklist_import_form() {
     '#value' => t('Import List'),
     '#weight' => 1,
   );
-  return drupal_get_form('troll_blacklist', $form);
+  return $form;
 }
 
 /**
@@ -596,7 +602,7 @@ function troll_blacklist_search_form() {
     '#value' => t('Search Blacklisted IPs'),
     '#weight' => 1,
   );
-  return drupal_get_form('troll_blacklist', $form);
+  return $form;
 }
 
 /**
@@ -611,14 +617,14 @@ function troll_blacklist_search($edit) {
   $longip = _troll_longip($edit['ip_address']);
   $sql = "SELECT net, bcast FROM {troll_blacklist} WHERE net <= $longip AND bcast >= $longip";
 
-	$headers = array(
-		array('data' => t('Network Address'), 'field' => 'net', 'sort' => 'asc'),
-		array('data' => t('Broadcast Address'), 'field' => 'bcast'),
+  $headers = array(
+    array('data' => t('Network Address'), 'field' => 'net', 'sort' => 'asc'),
+    array('data' => t('Broadcast Address'), 'field' => 'bcast'),
     array('data' => t('Actions'), 'field' => 'delete')
-	);
+  );
 
-	$sql .= tablesort_sql($headers);
-	$result = pager_query($sql, 25);
+  $sql .= tablesort_sql($headers);
+  $result = pager_query($sql, 25);
   if(db_num_rows($result) == 0) {
     drupal_set_message(t('No matches found in blacklist search.'));
     drupal_goto('admin/troll/ip_blacklist');
@@ -630,10 +636,10 @@ function troll_blacklist_search($edit) {
     $rows[] = array($printnet, $printbcast, $action);
   }
 
-	$pager = theme('pager', NULL, 25, 0);
-	if (!empty($pager)) {
-		$rows[] = array(array('data' => $pager, 'colspan' => 3));
-	}
+  $pager = theme('pager', NULL, 25, 0);
+  if (!empty($pager)) {
+    $rows[] = array(array('data' => $pager, 'colspan' => 3));
+  }
 
   return theme('table', $headers, $rows);
 }
@@ -645,7 +651,40 @@ function troll_blacklist_search($edit) {
  * @param string $bcast Not used, here for later implementation of whitelist editing
  * @return string
  */
-function troll_whitelist_form($net = NULL, $bcast = NULL) {
+function troll_whitelist_form_and_table($net = NULL, $bcast = NULL) {
+  $sql = 'SELECT net, bcast FROM {troll_whitelist}';
+
+  $headers = array(
+    array('data' => t('Start/Network Address'), 'field' => 'net', 'sort' => 'asc'),
+    array('data' => t('End/Broadcast Address'), 'field' => 'bcast'),
+    array('data' => t('Actions'), 'field' => 'delete'),
+  );
+
+  $sql .= tablesort_sql($headers);
+  $result = pager_query($sql, 25);
+  while($row = db_fetch_object($result)) {
+    $printnet = long2ip($row->net);
+    $printbcast = long2ip($row->bcast);
+    $action = l(t('remove'), "admin/troll/ip_blacklist/deletewhite/{$row->net}/{$row->bcast}");
+    $rows[] = array($printnet, $printbcast, $action);
+  }
+
+  $pager = theme('pager', NULL, 25, 0);
+  if (!empty($pager)) {
+    $rows[] = array(array('data' => $pager, 'colspan' => 3));
+  }
+
+  return drupal_get_form('troll_whitelist_form', $net, $bcast) . theme('table', $headers, $rows);
+}
+
+/**
+ * Form for creating new whitelist block
+ *
+ * @param string $net Not used, here for later implementation of whitelist editing
+ * @param string $bcast Not used, here for later implementation of whitelist editing
+ * @return array $form
+ */
+function troll_whitelist_form($net, $bcast) {
   $form['whitelist_addr1'] = array(
     '#type' => 'textfield',
     '#title' => t('Starting IP Address'),
@@ -670,30 +709,7 @@ function troll_whitelist_form($net = NUL
     '#weight' => 1,
   );
   $form['#action'] = url('admin/troll/ip_blacklist');
-
-  $sql = 'SELECT net, bcast FROM {troll_whitelist}';
-
-	$headers = array(
-		array('data' => t('Start/Network Address'), 'field' => 'net', 'sort' => 'asc'),
-		array('data' => t('End/Broadcast Address'), 'field' => 'bcast'),
-    array('data' => t('Actions'), 'field' => 'delete')
-	);
-
-	$sql .= tablesort_sql($headers);
-	$result = pager_query($sql, 25);
-  while($row = db_fetch_object($result)) {
-    $printnet = long2ip($row->net);
-    $printbcast = long2ip($row->bcast);
-    $action = l(t('remove'), "admin/troll/ip_blacklist/deletewhite/{$row->net}/{$row->bcast}");
-    $rows[] = array($printnet, $printbcast, $action);
-  }
-
-	$pager = theme('pager', NULL, 25, 0);
-	if (!empty($pager)) {
-		$rows[] = array(array('data' => $pager, 'colspan' => 3));
-	}
-
-  return drupal_get_form('troll_blacklist', $form) . theme('table', $headers, $rows);
+  return $form;
 }
 
 /**
@@ -733,8 +749,7 @@ function _troll_longip($ip) {
  * User search page callback function.
  */
 function troll_search_users($op = NULL, $uid = NULL) {
-  global $form_values;
-
+  $edit = $_POST;
   switch($op) {
     case 'view':
       $output = troll_search_user_detail($uid);
@@ -744,47 +759,45 @@ function troll_search_users($op = NULL, 
       drupal_goto('admin/troll');
       break;
     default:
-      $output = troll_search_form();
-      $output .= troll_list_users($form_values);
+      $output = drupal_get_form('troll_search_form');
+      $output .= troll_list_users($edit);
       break;
   }
   return $output;
 }
 
-/**
- *
- * FORM FUNCTIONS
- *
-**/
+function troll_ip_ban_edit($iid = NULL) {
+  return drupal_get_form('troll_ip_ban_form', $iid);
+}
 
 /**
  * IP banning form.
  */
-function troll_ip_ban_form($iid = NULL) {
+function troll_ip_ban_form($iid) {
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => ($iid) ? t('Update Banned IP') : t('Ban IP'),
     '#weight' => 1,
-    );
+  );
 
   $ip = db_fetch_object(db_query("SELECT * FROM {troll_ip_ban} WHERE iid = %d", $iid));
   $form['iid'] = array(
     '#type' => 'hidden',
     '#value' => $ip->iid,
-    );
+  );
   $form['ip_address'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Address'),
     '#default_value' => $ip->ip_address,
     '#description' => t('The IP address to ban.'),
     '#required' => TRUE,
-    );
+  );
   $form['domain_name'] = array(
     '#type' => 'textfield',
     '#title' => t('Domain Name'),
     '#default_value' => ($ip->domain_name ? $ip->domain_name : ($ip->ip_address ? gethostbyaddr($ip->ip_address) : '')),
     '#description' => t('The Domain Name of the IP address to ban - for reference only.'),
-    );
+  );
 
   $timestamp = ($ip->expires ? $ip->expires : time());
 
@@ -803,29 +816,29 @@ function troll_ip_ban_form($iid = NULL) 
     '#prefix' => '<div class="container-inline"><div class="day">',
     '#suffix' => '</div></div>',
     '#description' => t('The ban will be removed after this day.'),
-    );
+  );
   $form['timestamp']['expires'] = array(
     '#type' => 'checkbox',
     '#default_value' => ($ip->expires ? TRUE : FALSE),
-    );
+  );
   $form['timestamp']['month'] = array(
     '#type' => 'select',
     '#default_value' => date('n', $timestamp),
     '#options' => $months,
-    );
+  );
   $form['timestamp']['day'] = array(
     '#type' => 'select',
     '#default_value' => date('j', $timestamp),
     '#options' => $days,
-    );
+  );
   $form['timestamp']['year'] = array(
     '#type' => 'select',
     '#default_value' => date('Y', $timestamp),
     '#options' => $years,
-    );
+  );
 
   $form['#action'] = url('admin/troll/ip_ban');
-  return drupal_get_form('troll_ip_ban', $form);
+  return $form;
 }
 
 /**
@@ -856,15 +869,15 @@ function troll_display_ip() {
 
   $sql = 'SELECT iid, ip_address, domain_name, expires, uid FROM {troll_ip_ban}';
 
-	$headers = array(
-		array('data' => t('IP Address'), 'field' => 'ip_address'),
-		array('data' => t('Domain Name'), 'field' => 'domain_name'),
+  $headers = array(
+    array('data' => t('IP Address'), 'field' => 'ip_address'),
+    array('data' => t('Domain Name'), 'field' => 'domain_name'),
     array('data' => t('Expires'), 'field' => 'expires', 'sort' => 'desc'),
     array('data' => t('Actions'), 'field' => 'delete')
-	);
+  );
 
-	$sql .= tablesort_sql($headers);
-	$result = pager_query($sql, 25);
+  $sql .= tablesort_sql($headers);
+  $result = pager_query($sql, 25);
   while($row = db_fetch_object($result)) {
     $thisip = l($row->ip_address, 'admin/troll/ip_ban/edit/'. $row->iid);
     $thisdom = l(($row->domain_name ? $row->domain_name : gethostbyname($row->ip_address)), 'admin/troll/ip_ban/edit/'. $row->iid);
@@ -873,20 +886,27 @@ function troll_display_ip() {
     $rows[] = array($thisip, $thisdom, $expires, $action);
   }
 
-	$pager = theme('pager', NULL, 25, 0);
-	if (!empty($pager)) {
-		$rows[] = array(array('data' => $pager, 'colspan' => 5));
-	}
+  $pager = theme('pager', NULL, 25, 0);
+  if (!empty($pager)) {
+    $rows[] = array(array('data' => $pager, 'colspan' => 5));
+  }
 
   return theme("table", $headers, $rows);
 }
 
 /**
- * IP ban delete confirmation form.
+ * IP ban delete confirmation.
  */
 function troll_confirm_delete_ip($iid) {
+  return drupal_get_form('troll_confirm_delete_ip_form', $iid);
+}
+
+/**
+ * IP ban delete confirmation form.
+ */
+function troll_confirm_delete_ip_form($iid) {
   $ip = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE iid = %d', $iid));
-  return confirm_form('troll_confirm_delete_ip', array(), t('Remove Ban for IP %ip?', array('%ip' => $ip->ip_address)), 'admin/troll/ip_ban'. $edit['field_id'], t('Are you sure you want to remove the ban on this IP?'));
+  return confirm_form(array(), t('Remove Ban for IP %ip?', array('%ip' => $ip->ip_address)), 'admin/troll/ip_ban'. $edit['field_id'], t('Are you sure you want to remove the ban on this IP?'));
 }
 
 /**
@@ -902,8 +922,14 @@ function troll_confirm_delete_black_bloc
     drupal_set_message(t('No such IP range found in the database.'));
     drupal_goto('admin/troll/ip_blacklist');
   }
-  return confirm_form('troll_confirm_delete_blacklist_block',
-                      array(
+  return drupal_get_form('troll_confirm_delete_black_block_form', $net, $bcast);
+}
+
+/**
+ * Confirmation form for deleting a blacklist IP block
+ */
+function troll_confirm_delete_black_block_form($net, $bcast) {
+  return confirm_form(array(
                         'net' => array(
                             '#type' => 'hidden',
                             '#value' => $net),
@@ -930,8 +956,14 @@ function troll_confirm_delete_white_bloc
     drupal_set_message(t('No such IP range found in the database.'));
     drupal_goto('admin/troll/ip_blacklist');
   }
-  return confirm_form('troll_confirm_delete_whitelist_block',
-                      array(
+  return drupal_get_form('troll_confirm_delete_white_block_form', $net, $bcast);
+}
+  
+/**
+ * Confirmation form for deleting a whitelist IP block
+ */
+function troll_confirm_delete_white_block_form($net, $bcast) {
+  return confirm_form(array(
                         'net' => array(
                             '#type' => 'hidden',
                             '#value' => $net),
@@ -949,43 +981,41 @@ function troll_confirm_delete_white_bloc
  * User search form.
  */
 function troll_search_form() {
-  $form['#action'] = url('admin/troll/search');
+  $form['#redirect'] = FALSE;
   $form['search'] = array(
     '#type' => 'fieldset',
     '#title' => t('Search Users'),
     '#collapsible' => true
-    );
+  );
   $form['search']['username'] = array(
     '#type' => 'textfield',
     '#title' => t('Username'),
     '#description' => t('You can use % for wildcard, so to get all usernames with \'A\' in them, use %A%'),
-    );
+  );
   $form['search']['mail'] = array(
     '#type' => 'textfield',
     '#title' => t('Email'),
-    );
+  );
   $form['search']['ip_address'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Address'),
-    );
+  );
   $form['search']['date_created'] = array(
     '#type' => 'textfield',
     '#title' => t('Account Date Created'),
     '#description' => t('Enter date in mm/dd/yyyy format. Returns all users created after the date entered.'),
-    );
+  );
   $form['search']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Search Users'),
-    );
-
-  return drupal_get_form('troll_search_form', $form);
+  );
+  return $form;
 }
 
 /**
  * User list form.
  */
 function troll_list_users($edit) {
-
   $where[] = 'u.uid != 0';
 
   if(strlen($edit['username']) > 0) {
@@ -1005,15 +1035,15 @@ function troll_list_users($edit) {
 
   $sql .= ' WHERE '. implode(' AND ', $where);
 
-	$headers = array(
-		array('data' => t('Username'), 'field' => 'u.name'),
+  $headers = array(
+    array('data' => t('Username'), 'field' => 'u.name'),
     array('data' => t('Email'), 'field' => 'u.mail'),
-		array('data' => t('Status'), 'field' => 'u.status'),
+    array('data' => t('Status'), 'field' => 'u.status'),
     array('data' => t('IP Address'), 'field' => 't.ip_address'),
-		array('data' => t('Last Access'), 'field' => 't.created'),
+    array('data' => t('Last Access'), 'field' => 't.created'),
     array('data' => t('Account Created'), 'field' => 'u.created'),
     array('data' => t('Actions'), 'field' => 'actions')
-	);
+  );
 
   $sql .= ' GROUP BY u.uid';
   $sql .= tablesort_sql($headers);
@@ -1031,95 +1061,35 @@ function troll_list_users($edit) {
     $actions = array();
 
     if(!$user->status) {
-      $actions[] = l(t('Edit User'), "user/{$user->uid}/edit");
+      $actions[] = array('title' => t('Edit User'), 'href' => "user/{$user->uid}/edit");
     }
     elseif(variable_get('troll_block_role', NULL)) {
-      $actions[] = l(t('Block User'), 'admin/troll/block/'. $user->uid);
+      $actions[] = array('title' => t('Block User'), 'href' => 'admin/troll/block/'. $user->uid);
     }
     else {
-      $actions[] = l(t('Setup Block Role'), 'admin/settings/troll');
+      $actions[] = array('title' => t('Setup Block Role'), 'href' => 'admin/settings/troll');
     }
     if($user->ip_address) {
-      $actions[] = l(t('Ban IP'), 'admin/troll/ip_ban/user/'. $user->uid);
+      $actions[] = array('title' => t('Ban IP'), 'href' => 'admin/troll/ip_ban/user/'. $user->uid);
     }
     $action = theme('links', $actions);
     $rows[] = array($name, $email, $status, $ip, $recorded, $created, $action);
   }
 
-	$pager = theme('pager', NULL, 25, 0, $edit);
+  $pager = theme('pager', NULL, 25, 0, $edit);
 
-	if (!empty($pager)) {
-		$rows[] = array(array('data' => $pager, 'colspan' => 7));
-	}
+  if (!empty($pager)) {
+    $rows[] = array(array('data' => $pager, 'colspan' => 7));
+  }
 
   return theme('table', $headers, $rows);
 }
 
 /**
- * User detail form.
+ * User detail form and other info.
  */
 function troll_search_user_detail($uid) {
-  $u = user_load(array('uid' => $uid));
-  $u->ip = db_fetch_object(db_query("SELECT t.ip_address FROM {troll_ip_track} t WHERE t.uid = %d GROUP BY t.uid", $uid));
-
-  $roles = $u->roles;
-
-  $form['details'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Account Details for %username', array('%username' => $user->name)),
-    );
-
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('User Name'),
-    '#value' => $u->name,
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('Email'),
-    '#value' => $u->mail,
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('User ID'),
-    '#value' => $uid,
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('Account Created'),
-    '#value' => format_date($u->created, 'long'),
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('Last Access'),
-    '#value' => format_date($u->changed, 'long'),
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('Status'),
-    '#value' => ($u->status ? t('Active') : t('Blocked')),
-  );
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('User Roles'),
-    '#value' => implode(', ', $u->roles),
-  );
-  if($u->status) {
-    $links[] = l(t('Block User'), "admin/troll/block/$uid");
-  }
-  else {
-    $links[] = l(t('Edit User'), "user/$uid/edit");
-  }
-  if($u->ip->ip_address) {
-    $links[] = l(t('Ban IP'), "admin/troll/ip_ban/user/$uid");
-  }
-  $form['details'][] = array(
-    '#type' => 'item',
-    '#title' => t('Actions'),
-    '#value' => theme('links', $links),
-  );
-
-  $content = drupal_get_form('troll_search_user_detail', $form);
+  $content = drupal_get_form('troll_search_user_detail_form', $uid);
 
   // get IP history
   $results = db_query('SELECT * FROM {troll_ip_track} WHERE uid = %d ORDER BY created DESC', $uid);
@@ -1180,6 +1150,69 @@ function troll_search_user_detail($uid) 
 }
 
 /**
+ * User detail form.
+ */
+function troll_search_user_detail_form($uid) {
+  $u = user_load(array('uid' => $uid));
+  $u->ip = db_fetch_object(db_query("SELECT t.ip_address FROM {troll_ip_track} t WHERE t.uid = %d GROUP BY t.uid", $uid));
+
+  $form['details'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Account Details for %username', array('%username' => $user->name)),
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('User Name'),
+    '#value' => $u->name,
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('Email'),
+    '#value' => $u->mail,
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('User ID'),
+    '#value' => $uid,
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('Account Created'),
+    '#value' => format_date($u->created, 'long'),
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('Last Access'),
+    '#value' => format_date($u->changed, 'long'),
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('Status'),
+    '#value' => ($u->status ? t('Active') : t('Blocked')),
+  );
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('User Roles'),
+    '#value' => implode(', ', $u->roles),
+  );
+  if($u->status) {
+    $links[] = array('title' => t('Block User'), 'href' => "admin/troll/block/$uid");
+  }
+  else {
+    $links[] = array('title' => t('Edit User'), 'href' => "user/$uid/edit");
+  }
+  if($u->ip->ip_address) {
+    $links[] = array('title' => t('Ban IP'), 'href' => "admin/troll/ip_ban/user/$uid");
+  }
+  $form['details'][] = array(
+    '#type' => 'item',
+    '#title' => t('Actions'),
+    '#value' => theme('links', $links),
+  );
+  return $form;
+}
+
+/**
  *
  * DATABASE FUNCTIONS
  *
@@ -1298,7 +1331,7 @@ function troll_block_user($uid) {
   if(variable_get('troll_block_role', NULL)) {
     db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $uid, variable_get('troll_block_role', '0'));
   }
-  drupal_set_message(t('Blocked user %link', array('%link' => l($uid, "admin/troll/view/$uid"))));
+  drupal_set_message(t('Blocked user !link', array('!link' => l($uid, "admin/troll/view/$uid"))));
 }
 
 /**
