--- D:/xampp/htdocs/drupal6/sites/all/modules/webserver_auth/webserver_auth.module	Thu Aug 07 11:38:49 2008
+++ Z:/www/drupal6test/sites/all/modules/webserver_auth/webserver_auth.module	Fri Aug 29 14:02:10 2008
@@ -17,43 +17,58 @@
 }
 
 /**
+ * Implementation of hook_menu_alter().
+ */
+function webserver_auth_menu_alter(&$items) {
+//
+  if (variable_get('webserver_auth_hide_logout', FALSE)) {
+    $items['logout']['type'] = MENU_CALLBACK;
+  }
+  else {
+    $items['logout']['type'] = MENU_NORMAL_ITEM;
+  }
+}
+
+/**
  * Implementation of hook_init().
  */
 function webserver_auth_init() {
   global $user;
 
   $authname = '';
-
-  // Make sure we get the remote user whichever way it is available.
-  if (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
-    $authname = $_SERVER['REDIRECT_REMOTE_USER'];
-  }
-  elseif (isset($_SERVER['REMOTE_USER'])) {
-    $authname = $_SERVER['REMOTE_USER'];
-  }
-
-  // Perform some cleanup so plaintext passwords aren't available under
-  // mod_auth_kerb.
-  unset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
-
-  // Retrieve user credentials
-  $result = db_query("SELECT uid FROM {authmap} WHERE authname = '%s' AND module = 'webserver_auth'", $authname);
-  $expected = db_fetch_array($result);
-
-  if (isset($user) && $user->uid === $expected['uid']) {
-    // Do nothing: user is already logged into Drupal with session data matching
-    // HTTP authentication.
-  }
-  else {
-    if (!empty($authname)) {
-      // User is logged into webserver via HTTP authentication.
-      // Try to log into Drupal. 
-      $user = user_external_load($authname);
-
-      if (!$user) {
-        // If unsuccessful, register the user. This will trigger
-        // webserver_auth_user() and any other _user() hooks.
-        user_external_login_register($authname, 'webserver_auth');
+  $q = $_GET['q'] ? $_GET['q'] : $_POST['q'];
+  if ((strcasecmp($q, 'logout') != 0) && (strcasecmp($q, 'user') != 0) && ($user->uid != 1)) {    
+    // Make sure we get the remote user whichever way it is available.
+    if (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
+      $authname = $_SERVER['REDIRECT_REMOTE_USER'];
+    }
+    elseif (isset($_SERVER['REMOTE_USER'])) {
+      $authname = $_SERVER['REMOTE_USER'];
+    }
+  
+    // Perform some cleanup so plaintext passwords aren't available under
+    // mod_auth_kerb.
+    unset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
+  
+    // Retrieve user credentials
+    $result = db_query("SELECT uid FROM {authmap} WHERE authname = '%s' AND module = 'webserver_auth'", $authname);
+    $expected = db_fetch_array($result);
+    
+    if (isset($user) && $user->uid === $expected['uid']) {
+      // Do nothing: user is already logged into Drupal with session data matching
+      // HTTP authentication.
+    }
+    else {
+      if (!empty($authname)) {
+        // User is logged into webserver via HTTP authentication.
+        // Try to log into Drupal. 
+        $user = user_external_load($authname);
+  
+        if (!$user) {
+          // If unsuccessful, register the user. This will trigger
+          // webserver_auth_user() and any other _user() hooks.
+          user_external_login_register($authname, 'webserver_auth');
+        }
       }
     }
   }
@@ -90,6 +105,7 @@
     global $base_url;
     // kick user out of a secure session so they aren't automatically logged back in
     $base_url = str_replace('https://', 'http://', $base_url);
+    drupal_goto('user');
   }
 }
 
@@ -105,6 +121,12 @@
     '#maxlength' => 55,
     '#description' => t('Append this domain name to each new user in order generate his email address.'),
   );
+  $form['webserver_auth_hide_logout'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Hide Log out menu'),
+    '#default_value' => variable_get('webserver_auth_hide_logout', FALSE),
+    '#description' => t("Hide the Log out menu item.  The url @url will still work.", array('@url' => url('logout', array('absolute' => TRUE)))),
+  );
   $form['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
@@ -129,5 +151,19 @@
       '#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code>&lt;?php</code> and <code>?&gt;</code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('insert',...)</a>. Changes to the user object must be explicitly saved to the database to be made permanent."),
     ),
   );
-  return system_settings_form($form);
+  // Add standard settings form elements
+  $form = system_settings_form($form);
+  // Remove submit element so the webserver_auth_settings_submit is used
+  unset($form['#submit']);
+  return $form;
 }
+
+/**
+ * Implementation of hook_settings_submit().
+ */
+function webserver_auth_settings_submit($form, &$form_state){
+  // Save all settings using the standard settings_form_submit function
+  system_settings_form_submit($form, $form_state);
+  // Rebuild the menu so the logout menu item setting is applied
+  menu_rebuild();
+}
\ No newline at end of file
