--- troll-HEAD/troll.module	2007-03-04 19:54:32.845918598 -0800
+++ troll-HEAD-new/troll.module	2007-03-04 21:34:51.345751499 -0800
@@ -87,7 +87,7 @@ function troll_help($section = 'admin/he
   switch ($section) {
     case 'admin/settings/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/settings'))));
       }
       break;
   }
@@ -108,13 +108,13 @@ function troll_admin_settings() {
     '#title' => t('IP Address Banning'),
     '#default_value' => variable_get('troll_enable_ip_ban', 1),
     '#options' => array('1' => t('Enable banning by IP address'), '0' => t('Disable banning by IP address'))
-    );
+  );
   $form['ip_settings']['troll_ip_ban_redirect'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Ban Relocation Page'),
     '#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();
   $form['role_settings'] = array(
@@ -127,7 +127,7 @@ function troll_admin_settings() {
     '#default_value' => variable_get('troll_block_role', ''),
     '#options' => $roles,
     '#description' => t('Select the role to set users to when blocking from the troll adminstration screens')
-    );
+  );
 
   return system_settings_form($form);
 }
@@ -142,38 +142,48 @@ function troll_menu($may_cache) {
 
   $access = user_access('administer site configuration');
   if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/troll',
+    $items[] = array('path' => 'admin/settings/troll',
       'title' => t('Troll'),
       'description' => t('Manage visitor IP banning.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('troll_admin_settings'),
+      'callback' => 'troll_search_users',
       'access' => $access,
-      'type' => MENU_NORMAL_ITEM,
+      'weight' => '0'
     );
     $items[] = array('path' => 'admin/settings/troll/search',
       'title' => t('Search Users'),
       'callback' => 'troll_search_users',
+      'type' => MENU_DEFAULT_LOCAL_TASK,
       'access' => $access,
       'weight' => '0'
     );
     $items[] = array('path' => 'admin/settings/troll/ip_ban',
       'title' => t('IP Banning'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('troll_ip_ban_edit'),
+      'callback' => 'troll_ip_ban',
+      'type' => MENU_LOCAL_TASK,
       'access' => $access,
       'weight' => '1'
     );
     $items[] = array('path' => 'admin/settings/troll/ip_blacklist',
       'title' => t('Blacklists'),
       'callback' => 'troll_blacklist',
+      'type' => MENU_LOCAL_TASK,
       'access' => $access,
       'weight' => '2'
     );
+    $items[] = array(
+      'path' => 'admin/settings/troll/settings',
+      'title' => t('Settings'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('troll_admin_settings'),
+      'type' => MENU_LOCAL_TASK,
+      'access' => $access,
+      'weight' => '3'
+    );
     $items[] = array('path' => 'admin/settings/troll/ip_ban/edit',
       'title' => t('IP Ban Form'),
       'callback' => 'drupal_get_form',
       'callback arguments' => 'troll_ip_ban_form',
+      'type' => MENU_CALLBACK,
       'access' => $access
     );
   }
@@ -222,17 +232,17 @@ function troll_ip_ban($op = NULL, $iid =
       $form['banform'] = array(
         '#type' => 'fieldset',
         '#title' => t('Add IP Ban'),
-        '#value' => drupal_get_form('troll_ip_ban_edit'),
+        '#value' => drupal_get_form('troll_ip_ban_form'),
         '#weight' => -1,
         '#collapsible' => true
-        );
+      );
       $form['ipdisplay'] = array(
         '#type' => 'fieldset',
         '#title' => t('Banned IPs'),
         '#value' => troll_display_ip(),
         '#weight' => 0,
         '#collapsible' => true
-        );
+      );
       $output = drupal_render($form);
       break;
   }
@@ -284,14 +294,14 @@ function troll_blacklist($op = NULL, $ed
       drupal_goto('admin/settings/troll/ip_blacklist');
       break;
     case 'deletewhite':
-      $output = drupal_get_form('troll_confirm_delete_white_block', arg(5), arg(6));
+      $output = troll_confirm_delete_white_block(arg(5), arg(6));
       break;
     case t('Confirm Whitelist Removal'):
       troll_remove_whitelist($_POST['net'], $_POST['bcast']);
       drupal_goto('admin/settings/troll/ip_blacklist');
       break;
     case 'deleteblack':
-      $output = drupal_get_form('troll_confirm_delete_black_block', arg(5), arg(6));
+      $output = troll_confirm_delete_black_block(arg(5), arg(6));
       break;
     case t('Confirm Blacklist Removal'):
       troll_remove_blacklist($_POST['net'], $_POST['bcast']);
@@ -305,7 +315,7 @@ function troll_blacklist($op = NULL, $ed
         '#weight' => -4,
         '#collapsible' => true,
         '#collapsed' => false
-        );
+      );
       $form['blacklist_punishment'] = array(
         '#type' => 'fieldset',
         '#title' => t('Blacklist Visitor Punishment'),
@@ -313,7 +323,7 @@ function troll_blacklist($op = NULL, $ed
         '#weight' => -3,
         '#collapsible' => true,
         '#collapsed' => true
-        );
+      );
       $form['blacklist_import'] = array(
         '#type' => 'fieldset',
         '#title' => t('Import Blacklist'),
@@ -321,7 +331,7 @@ function troll_blacklist($op = NULL, $ed
         '#weight' => -2,
         '#collapsible' => true,
         '#collapsed' => true
-        );
+      );
       $form['search_blacklist'] = array(
         '#type' => 'fieldset',
         '#title' => t('Search Blacklisted IPs'),
@@ -329,7 +339,7 @@ function troll_blacklist($op = NULL, $ed
         '#weight' => 0,
         '#collapsible' => true,
         '#collapsed' => true
-        );
+      );
       $form['whitelist_form'] = array(
         '#type' => 'fieldset',
         '#title' => t('Whitelist IPs'),
@@ -338,7 +348,7 @@ function troll_blacklist($op = NULL, $ed
         '#weight' => 1,
         '#collapsible' => true,
         '#collapsed' => true
-        );
+      );
       $output = drupal_render($form);
       break;
   }
@@ -376,31 +386,31 @@ function troll_blacklist_punishment_form
     '#title' => t('Randomly stutter output'),
     '#default_value' => variable_get('troll_blacklist_stutter', 0),
     '#description' => t('While outputting content, the troll module will cause Drupal to "sleep" for random intervals of 1-5 seconds to delay output.')
-    );
+  );
   $form['mod_requests'] = array(
     '#type' => 'radios',
     '#title' => t('Page request modification'),
     '#options' => array(t('none'), 'silent_post_drop' => 'Silently drop form post submission data', 'notice_post_drop' => 'Drop form post submission data and give a notice'),
     '#default_value' => variable_get('troll_blacklist_mod_requests', '0'),
     '#description' => t('Modifies data sent by visitors from blacklisted IPs before Drupal even has a chance to process it.')
-    );
+  );
   $form['alt_page_output'] = array(
     '#type' => 'fieldset',
     '#title' => 'Alternate page output'
-    );
+  );
   $form['alt_page_output']['alt_page'] = array(
     '#type' => 'radios',
     '#title' => 'Alternate pages',
     '#options' => array(t('none'), 'blank' => t('Blank pages'), '404' => t('404 every page request'), 'redirect' => t('Redirect to alternate URL')),
     '#default_value' => variable_get('troll_blacklist_alt_page', '0'),
     '#description' => t('Sends alternate page output, whether the visitor hits a real URL or not.')
-    );
+  );
   $form['alt_page_output']['alt_url'] = array(
     '#type' => 'textfield',
     '#title' => t('Redirection URL'),
     '#default_value' => variable_get('troll_blacklist_alt_url', ''),
     '#description' => t('URL to redirect blacklisted visitors to if "Redirect to alternate URL" is selected. Start with the appropriate prefix (e.g. http://)')
-    );
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Update Blacklist Punishments'),
@@ -447,12 +457,12 @@ function troll_blacklist_import_form() {
     '#title' => t('Download and import'),
     '#options' => $options,
     '#description' => t('Downloads supported blacklist from the internet. Please select a mirror when possible.'),
-    );
+  );
   $form['custom_list'] = array(
     '#type' => 'textfield',
     '#title' => t('List URL'),
     '#description' => t('URL of a list to import. List files should have one address per line in Classless Internet Domain Routing CIDR format (x.x.x.x/x). Individual IPs should still have /32.'),
-    );
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Import List'),
@@ -586,7 +596,7 @@ function troll_blacklist_search_blacklis
     '#maxlength' => 15,
     '#description' => t('Address to search for in the database of imported IP blocks.'),
     '#required' => TRUE
-    );
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Search Blacklisted IPs'),
@@ -744,7 +754,7 @@ function _troll_longip($ip) {
  * @return string
  */
 function troll_search_users($op = NULL, $uid = NULL) {
-  global $form_values;
+  $form_values = $_POST;
 
   $output = '';
   switch($op) {
@@ -753,7 +763,7 @@ function troll_search_users($op = NULL, 
       break;
     case 'block':
       troll_block_user($uid);
-      drupal_goto('admin/settings/troll');
+      drupal_goto('admin/settings/troll/search');
       break;
     default:
       $output = troll_search();
@@ -888,20 +898,25 @@ function troll_display_ip() {
 }
 
 /**
- * IP ban delete confirmation form.
- *
- * @param $iid int
+ * 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/settings/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/settings/troll/ip_ban'. $edit['field_id'], t('Are you sure you want to remove the ban on this IP?'));
 }
 
 /**
  * Confirmation before deleting a blacklist IP block
  *
- * @param $net int IP in long format
- * @param $bcast int IP in long format
+ * @param integer $net IP in long format
+ * @param integer $bcast IP in long format
  * @return string
  */
 function troll_confirm_delete_black_block($net, $bcast) {
@@ -910,27 +925,32 @@ function troll_confirm_delete_black_bloc
     drupal_set_message(t('No such IP range found in the database.'));
     drupal_goto('admin/settings/troll/ip_blacklist');
   }
+  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),
-      'bcast' => array(
-        '#type' => 'hidden',
-        '#value' => $bcast)
-      ),
-      t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))
-    ),
-    'admin/settings/troll/ip_blacklist',
-    t('Are you sure you want to remove this IP block from the blacklist?'),
-    t('Confirm Blacklist Removal')
-  );
+                        'net' => array(
+                            '#type' => 'hidden',
+                            '#value' => $net),
+                        'bcast' => array(
+                            '#type' => 'hidden',
+                            '#value' => $bcast)
+                      ),
+                      t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))),
+                      'admin/settings/troll/ip_blacklist',
+                      t('Are you sure you want to remove this IP block from the blacklist?'),
+                      t('Confirm Blacklist Removal'));
 }
 
 /**
  * Confirmation before deleting a whitelist IP block
  *
- * @param $net integer IP in long format
- * @param $bcast integer IP in long format
+ * @param integer $net IP in long format
+ * @param integer $bcast IP in long format
  * @return string
  */
 function troll_confirm_delete_white_block($net, $bcast) {
@@ -939,19 +959,25 @@ function troll_confirm_delete_white_bloc
     drupal_set_message(t('No such IP range found in the database.'));
     drupal_goto('admin/settings/troll/ip_blacklist');
   }
+  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),
-      'bcast' => array(
-        '#type' => 'hidden',
-        '#value' => $bcast)
-    ),
-    t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))),
-    'admin/settings/troll/ip_blacklist',
-    t('Are you sure you want to remove this IP block from the whitelist?'),
-    t('Confirm Whitelist Removal')
-  );
+                        'net' => array(
+                            '#type' => 'hidden',
+                            '#value' => $net),
+                        'bcast' => array(
+                            '#type' => 'hidden',
+                            '#value' => $bcast)
+                      ),
+                      t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))),
+                      'admin/settings/troll/ip_blacklist',
+                      t('Are you sure you want to remove this IP block from the whitelist?'),
+                      t('Confirm Whitelist Removal'));
 }
 
 /**
@@ -971,6 +997,7 @@ function troll_search() {
  */
 function troll_search_form() {
   $form['#action'] = url('admin/settings/troll/search');
+  $form['#redirect'] = FALSE;
   $form['search'] = array(
     '#type' => 'fieldset',
     '#title' => t('Search Users'),
@@ -1044,10 +1071,10 @@ function troll_list_users($edit) {
   $result = pager_query($sql, 25);
 
   while($user = db_fetch_object($result)) {
-    $name = l($user->name, 'admin/settings/troll/view/'. $user->uid, array('title' => t('View detailed user information')));
+    $name = l($user->name, 'admin/settings/troll/search/view/'. $user->uid, array('title' => t('View detailed user information')));
     $email = $user->mail;
     $status = ($user->status ? t('Active') : t('Blocked'));
-    $ip = ($user->ip_address ? l($user->ip_address, 'admin/settings/troll/view/'. $user->uid, array('title' => t('View detailed user information'))) : t('none'));
+    $ip = ($user->ip_address ? l($user->ip_address, 'admin/settings/troll/search/view/'. $user->uid, array('title' => t('View detailed user information'))) : t('none'));
     $recorded = ($user->recorded ? date('M d, Y', $user->recorded) : t('none recorded'));
     $created = date('M d, Y', $user->created);
     $actions = array();
@@ -1056,10 +1083,10 @@ function troll_list_users($edit) {
       $actions[] = array('title' => t('Edit User'), 'href' => "user/{$user->uid}/edit");
     }
     elseif(variable_get('troll_block_role', NULL)) {
-      $actions[] = array('title' => t('Block User'), 'href' => 'admin/settings/troll/block/'. $user->uid);
+      $actions[] = array('title' => t('Block User'), 'href' => 'admin/settings/troll/search/block/'. $user->uid);
     }
     else {
-      $actions[] = array('title' => t('Setup Block Role'), 'href' => 'admin/settings/troll');
+      $actions[] = array('title' => t('Setup Block Role'), 'href' => 'admin/settings/troll/settings');
     }
     if($user->ip_address) {
       $actions[] = array('title' => t('Ban IP'), 'href' => 'admin/settings/troll/ip_ban/user/'. $user->uid);
@@ -1130,13 +1157,13 @@ function troll_search_user_detail($uid) 
     '#value' => implode(', ', $u->roles)
   );
   if($u->status) {
-    $links[] = array('title' => t('Block User'), 'title' => "admin/settings/troll/block/$uid");
+    $links[] = array('title' => t('Block User'), 'href' => "admin/settings/troll/search/block/$uid");
   }
   else {
-    $links[] = array('title' => t('Edit User'), 'title' => "user/$uid/edit");
+    $links[] = array('title' => t('Edit User'), 'href' => "user/$uid/edit");
   }
   if($u->ip->ip_address) {
-    $links[] = array('title' => t('Ban IP'), 'title' => "admin/settings/troll/ip_ban/user/$uid");
+    $links[] = array('title' => t('Ban IP'), 'href' => "admin/settings/troll/ip_ban/user/$uid");
   }
   $form['details'][] = array(
     '#type' => 'item',
@@ -1329,7 +1356,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/settings/troll/view/$uid"))));
+  drupal_set_message(t('Blocked user !link', array('!link' => l($uid, "admin/settings/troll/search/view/$uid"))));
 }
 
 /**
