diff --exclude=.svn -urN ldap_integration.orig/ldapauth.info ldap_integration/ldapauth.info
--- ldap_integration.orig/ldapauth.info	2008-05-10 14:04:37.000000000 +0200
+++ ldap_integration/ldapauth.info	2008-06-26 17:46:35.000000000 +0200
@@ -1,10 +1,11 @@
-; $Id: ldapauth.info,v 1.1.2.3 2008/04/17 04:32:12 scafmac Exp $
+; $Id: ldapauth.info,v 1.2 2007/01/28 20:38:03 kreaper Exp $
 name = ldapauth
 description = "Implements LDAP Authentication"
 package = Administration
+core = 6.x
 
-; Information added by drupal.org packaging script on 2008-05-10
-version = "5.x-1.x-dev"
+version = "6.x-1.x-dev"
 project = "ldap_integration"
 datestamp = "1210421077"
 
+
diff --exclude=.svn -urN ldap_integration.orig/ldapauth.install ldap_integration/ldapauth.install
--- ldap_integration.orig/ldapauth.install	2008-04-17 06:32:12.000000000 +0200
+++ ldap_integration/ldapauth.install	2008-07-10 10:23:57.000000000 +0200
@@ -1,57 +1,98 @@
 <?php
-//$Id: ldapauth.install,v 1.1.2.4 2008/04/17 04:32:12 scafmac Exp $
+// $Id$
+
+/**
+ * @file
+ * File with install instructions for ldapauth module
+ */
+
 /**
  * Implementation of hook_install().
  */
 function ldapauth_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE {ldapauth} (
-        sid int NOT NULL auto_increment,
-        name varchar(255) NOT NULL default '',
-        status int NOT NULL default '0',
-        server varchar(255) NOT NULL default '',
-        port int(10) NOT NULL default '389',
-        tls int NOT NULL default '0',
-        encrypted int NOT NULL default '0',
-        basedn text NOT NULL,
-        user_attr varchar(255) NOT NULL default '',
-        mail_attr VARCHAR(255) NOT NULL DEFAULT '',
-        binddn varchar(255) NOT NULL default '',
-        bindpw varchar(255) NOT NULL default '',
-        bindpw_clear varchar(255) NOT NULL default '',
-        PRIMARY KEY (name),
-        KEY sid (sid)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      break;
-    case 'pgsql':
-      db_query("CREATE TABLE {ldapauth} (
-        sid SERIAL,
-        name VARCHAR(255) NOT NULL DEFAULT '',
-        status INTEGER NOT NULL DEFAULT 0,
-        server VARCHAR(255) NOT NULL DEFAULT '',
-        port INTEGER NOT NULL DEFAULT 389,
-        tls INTEGER NOT NULL DEFAULT 0,
-        encrypted INTEGER NOT NULL DEFAULT 0,
-        basedn text NOT NULL,
-        user_attr VARCHAR(255) NOT NULL DEFAULT '',
-        mail_attr VARCHAR(255) NOT NULL DEFAULT '',
-        binddn VARCHAR(255) NOT NULL DEFAULT '',
-        bindpw VARCHAR(255) NOT NULL DEFAULT '',
-        bindpw_clear VARCHAR(255) NOT NULL DEFAULT '',
-        PRIMARY KEY (name)
-      )"); 
-      db_query("CREATE INDEX {ldapauth}_sid_idx ON {ldapauth} (sid)");
-      break;
-  }
+  drupal_install_schema('ldapauth');
+}
+
+function ldapauth_schema() {
+  $schema['ldapauth'] = array(
+    'fields' => array(
+      'sid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'status' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0),
+      'server' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'port' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 389),
+      'tls' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 389),
+      'encrypted' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 389),
+      'basedn' => array(
+        'type' => 'text',
+        'not null' => TRUE),
+      'user_attr' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'mail_attr' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'binddn' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'bindpw' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+      'bindpw_clear' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''),
+    ),
+    'indexes' => array(
+      'sid' => array('sid')
+    ),
+    'primary key' => array('name')
+  );
+
+  return $schema;
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function ldapauth_uninstall() {
-  db_query('DROP TABLE {ldapauth}');
+  drupal_uninstall_schema('ldapauth');
   variable_del('ldap_forget_passwords');
   variable_del('ldap_login_process');
   variable_del('ldap_disable_request_new_password');
@@ -64,7 +105,7 @@
 }
 
 /**
- * Implementation of hook_update_N()
+ * Implementation of hook_update_N().
  */
 
 function ldapauth_update_1() {
@@ -73,16 +114,15 @@
 
 function ldapauth_update_2() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {ldapauth} ADD mail_attr VARCHAR(255) NOT NULL default '' AFTER user_attr ");
-      $ret[] = update_sql("ALTER TABLE {ldapauth} MODIFY basedn TEXT NOT NULL ");
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("ALTER TABLE {ldapauth} ADD mail_attr VARCHAR(255) NOT NULL default '' AFTER user_attr ");
-      $ret[] = update_sql("ALTER TABLE {ldapauth} MODIFY basedn TEXT NOT NULL ");
-      break;
-  }
+  db_add_field($ret, 'ldapauth', 'mail_attr', array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'basedn', array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''));
   return $ret;
-}
\ No newline at end of file
+}
diff --exclude=.svn -urN ldap_integration.orig/ldapauth.module ldap_integration/ldapauth.module
--- ldap_integration.orig/ldapauth.module	2008-04-17 06:32:12.000000000 +0200
+++ ldap_integration/ldapauth.module	2008-07-13 07:51:00.000000000 +0200
@@ -1,5 +1,10 @@
 <?php
-// $Id: ldapauth.module,v 1.1.4.14.2.5 2008/04/17 04:32:12 scafmac Exp $
+// $Id: ldapauth.module,v 1.28 2007/08/22 23:55:21 kreaper Exp $
+
+/**
+ * @file
+ * ldapdauth module file
+ */
 
 include_once('ldap_integration/ldapauth.conf.php');
 include_once('ldap_integration/libdebug.php');
@@ -15,7 +20,7 @@
 define('LDAP_EMAIL_FIELD_NO', 0);
 define('LDAP_EMAIL_FIELD_REMOVE', 1);
 define('LDAP_EMAIL_FIELD_DISABLE', 2);
-    
+
 // Private constants (default values). Do not touch either
 define('LDAP_DEFAULT_ORG', 'LDAP Directory');
 define('LDAP_DEFAULT_BASE_DN', 'ou=Users,dc=drupal,dc=org');
@@ -26,13 +31,13 @@
 
 /*********************************
  *       1. Drupal hooks         *
- *********************************/
-/** 
-* Implements hook_help()
-**/
-function ldapauth_help($section) {
+ * ***************************** */
+/**
+ * Implements hook_help()
+ */
+function ldapauth_help($path, $arg) {
   $output = '';
-  switch ($section) {
+  switch ($path) {
     case 'admin/modules#name':
       $output = 'ldapauth';
       break;
@@ -47,116 +52,89 @@
   return $output;
 }
 
-/** 
-* Implements hook_info()
-* required for authentication modules
-**/
-
-function ldapauth_info($field = 0) {
-  $info['name'] = 'LDAP authentication';
-  $info['protocol'] = 'LDAP';
-
-  if ($field) {
-    return $info[$field];
-  }
-  else {
-    return $info;
-  }
-}
-
-/** 
-* Implements hook_menu()
-**/
-
-function ldapauth_menu($may_cache) {
+/**
+ * Implements hook_menu()
+ */
+function ldapauth_menu() {
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array( 
-      'path' => 'admin/settings/ldapauth', 
-      'title' => t('LDAP Integration'),
-      'callback' => 'ldapauth_admin_list',
-      'access' => user_access('administer ldap modules'),
-      'description' => t('Configure LDAP settings'),
-      );
-
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/list',
-      'title' => t('List'),
-      'callback' => 'ldapauth_admin_list',
-      'access' => user_access('administer ldap modules'),
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      );  
-
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/add',
-      'title' => t('Configure LDAP Server'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_form'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 1,
-      'access' => user_access('administer ldap modules'),
-      );
-    
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/options',
-      'title' => t('System Wide Options'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_options'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 2,
-      'access' => user_access('administer ldap modules'),
-      );
-    
-      $items[] = array(
-      'path' => 'admin/settings/ldapauth/edit',
-      'title' => t('Configure LDAP Server'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_form'),
-      'type' => MENU_CALLBACK,
-      'access' => user_access('administer ldap modules'),
-      );
-    
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/delete',
-      'title' => t('Delete LDAP Server'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_delete'),
-      'type' => MENU_CALLBACK,
-      'access' => user_access('administer ldap modules'),
-      );
-
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/activate',
-      'title' => t('Activate LDAP Source'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_activate'),
-      'type' => MENU_CALLBACK,
-      'access' => user_access('administer ldap modules'),
-      );
+  $items['admin/settings/ldapauth'] = array(
+    'title' => 'LDAP Integration',
+    'page callback' => 'ldapauth_admin_list',
+    'access arguments' => array('administer ldap modules'),
+    'description' => 'Configure LDAP settings',
+  );
+
+  $items['admin/settings/ldapauth/list'] = array(
+    'title' => 'List',
+    'page callback' => 'ldapauth_admin_list',
+    'access arguments' => array('administer ldap modules'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+
+  $items['admin/settings/ldapauth/add'] = array(
+    'title' => 'Configure LDAP Server',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_form'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 1,
+    'access arguments' => array('administer ldap modules'),
+  );
+
+  $items['admin/settings/ldapauth/options'] = array(
+    'title' => 'System Wide Options',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_options'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+    'access arguments' => array('administer ldap modules'),
+  );
+
+  $items['admin/settings/ldapauth/edit'] = array(
+    'title' => 'Configure LDAP Server',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_form', 3, 4),
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer ldap modules'),
+  );
+
+  $items['admin/settings/ldapauth/delete'] = array(
+    'title' => 'Delete LDAP Server',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_delete', 4),
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer ldap modules'),
+  );
+
+  $items['admin/settings/ldapauth/activate'] = array(
+    'title' => 'Activate LDAP Source',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_activate'),
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer ldap modules'),
+  );
+
+  $items['admin/settings/ldapauth/deactivate'] = array(
+    'title' => 'De-Activate LDAP Source',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ldapauth_admin_deactivate'),
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer ldap modules'),
+  );
 
-    $items[] = array(
-      'path' => 'admin/settings/ldapauth/deactivate',
-      'title' => t('De-Activate LDAP Source'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapauth_admin_deactivate'),
-      'type' => MENU_CALLBACK,
-      'access' => user_access('administer ldap modules'),
-      );        
-  }
   return $items;
 }
 
-/** 
-* Implements hook_perm()
-**/
+/**
+ * Implements hook_perm()
+ */
 function ldapauth_perm() {
   return array('administer ldap modules');
 }
 
-/** 
-* Implements hook_cron()
-**/
+/**
+ * Implements hook_cron()
+ */
 function ldapauth_cron() {
   cache_clear_all(NULL, 'cache_filter');
 }
@@ -176,18 +154,18 @@
       $link_comp = "activate";
     }
     $rows[] = array(
-      $row->name, 
-      l(t('edit'), 'admin/settings/ldapauth/edit/'.$row->name), 
-      l(t('!link_text', array('!link_text' => $link_text)), 'admin/settings/ldapauth/'.$link_comp.'/'.$row->name),
-      l(t('delete'), 'admin/settings/ldapauth/delete/'.$row->name)
-      ); 
+      $row->name,
+      l(t('edit'), 'admin/settings/ldapauth/edit/'. $row->name),
+      l(t('!link_text', array('!link_text' => $link_text)), 'admin/settings/ldapauth/'. $link_comp .'/'. $row->name),
+      l(t('delete'), 'admin/settings/ldapauth/delete/'. $row->name)
+      );
   }
   $header = array(
-    t('LDAP Config'), 
+    t('LDAP Config'),
     array(
       'data' => t('Operations'),
       'colspan' => '3'
-      ) 
+      )
     );
   return theme('table', $header, $rows);
 }
@@ -197,7 +175,7 @@
   // de-activate the config
   db_query("UPDATE {ldapauth} SET status = '%s'WHERE name = '%s'", "", $ldap_name);
   drupal_set_message(t('LDAP Configuration %config has been de-activated.', array('%config' => $ldap_name)));
-  watchdog('ldap', t('ldapauth: ldap config %config de-activated.', array('%config' => $ldap_name)));
+  watchdog('ldap', 'ldapauth: ldap config %config de-activated.', array('%config' => $ldap_name));
   drupal_goto('admin/settings/ldapauth');
 }
 
@@ -207,136 +185,133 @@
   // activate the config
   db_query("UPDATE {ldapauth} SET status = '%d'WHERE name = '%s'", "1", $ldap_name);
   drupal_set_message(t('LDAP Configuration %config has been activated.', array('%config' => $ldap_name)));
-  watchdog('ldap', t('ldapauth: ldap config %config activated.', array('%config' => $ldap_name)));
-  drupal_goto('admin/settings/ldapauth'); 
+  watchdog('ldap', 'ldapauth: ldap config %config activated.', array('%config' => $ldap_name));
+  drupal_goto('admin/settings/ldapauth');
 }
 
-function ldapauth_admin_options() {  
-  $options_login_process = array( 
+function ldapauth_admin_options() {
+  $options_login_process = array(
     LDAP_FIRST_DRUPAL => t('Drupal\'s DB first, then LDAP directory'),
     //LDAP_OR_DRUPAL => t('If LDAP user, LDAP only; otherwise Drupal DB'),
     LDAP_FIRST_LDAP => t('LDAP directory only')
   );
-  
-  $form['system-options'] = array( 
-    '#type' => 'fieldset', 
+
+  $form['system-options'] = array(
+    '#type' => 'fieldset',
     '#title' => t('Authentication mode'),
-    '#description' => t('<p><strong>NOTE:</strong> These settings have no effect on Drupal user with uid 1. The admin account never uses LDAP.</p>'), 
-    '#collapsible' => TRUE, 
+    '#description' => t('<p><strong>NOTE:</strong> These settings have no effect on Drupal user with uid 1. The admin account never uses LDAP.<strong></p>'),
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
 
-  $form['system-options']['ldap_login_process'] = array( 
-    '#type' => 'radios', 
+  $form['system-options']['ldap_login_process'] = array(
+    '#type' => 'radios',
     '#title' => t('Choose authentication mode'),
-    '#description' => t('<p>Pick the mode based on the types of user accounts and other configuration decisions...</p>'), 
+    '#description' => t('<p>Pick the mode based on the types of user accounts and other configuration decisions...</p>'),
     '#default_value' => variable_get('ldap_login_process', LDAP_FIRST_DRUPAL),
-    '#options' => $options_login_process, 
+    '#options' => $options_login_process,
     '#required' => true,
   );
 
-  $form['security-options'] = array( 
+  $form['security-options'] = array(
     '#type' => 'fieldset',
     '#title' => t('Security Options'),
-    '#collapsible' => TRUE, 
+    '#collapsible' => TRUE,
     '#description' => t('<p>If you use the <strong>ldapdata</strong> module and want to allow users to modify their LDAP attributes, you have two options:</p><ul><li>Setup a special ldap manager DN that has (limited) permissions to edit the requisite LDAP records - using this method means Drupal\'s built in password reset will work;</li> <li>or allow this module to store the user\'s LDAP password, in clear text, during the session;</li></ul><p>Physically, these passwords are stored in the Drupal\'s session table in clear text. This is not ideal and is not the recomended configuration.</p><p>Unless you need to use the latter configuration, leave this checked.</p>'),
     '#collapsed' => TRUE,
   );
-  
+
   $form['security-options']['ldap_forget_passwords'] = array(
-    '#type' => 'checkbox', 
-    '#title' => t('Do not store users\' passwords during sessions'), 
-    '#return_value' => true, 
+    '#type' => 'checkbox',
+    '#title' => t('Do not store users\' passwords during sessions'),
+    '#return_value' => TRUE,
     '#default_value' => variable_get('ldap_forget_passwords', true),
   );
 
-  $form['anonymous-ui'] = array( 
-    '#type' => 'fieldset', 
+  $form['anonymous-ui'] = array(
+    '#type' => 'fieldset',
     '#title' => t('Anonymous UI Options'),
-    '#description' => t('<p>Effects the interface for all non-authenticated users.</p>'), 
-    '#collapsible' => TRUE, 
+    '#description' => t('<p>Effects the interface for all non-authenticated users.</p>'),
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
-  
+
   $form['anonymous-ui']['ldap_disable_request_new_password'] = array(
-    '#type' => 'checkbox', 
+    '#type' => 'checkbox',
     '#title' => t('Remove <em>Request new password</em> link from login block'),
-    '#return_value' => TRUE, 
+    '#return_value' => TRUE,
     '#default_value' => variable_get('ldap_disable_request_new_password', FALSE),
   );
 
-  $options_reset_form = array( 
+  $options_reset_form = array(
     LDAP_RESET_FORM_NO => t('Do nothing'),
     LDAP_RESET_FORM_OVERWRITE => t('Overwrite form with HTML in textfield'),
     LDAP_RESET_FORM_MERGE => t('Prepend HTML to form')
   );
-  
+
   $form['anonymous-ui']['ldap_alter_reset_form'] = array(
-    '#type' => 'radios', 
+    '#type' => 'radios',
     '#title' => t('Alter <em>Request New Password</em> form'),
     '#default_value' => variable_get('ldap_alter_reset_form', LDAP_RESET_FORM_NO),
-    '#options' => $options_reset_form, 
+    '#options' => $options_reset_form,
     '#required' => true,
   );
-  
-  $form['anonymous-ui']['ldap_user_pass_form'] = array( 
-    '#type' => 'textarea', 
-    '#title' => t('New password reset message'), 
-    '#default_value' => variable_get('ldap_user_pass_form','<h2>Form disabled by administrator.<h2>'),
-    '#cols' => 45, 
+
+  $form['anonymous-ui']['ldap_user_pass_form'] = array(
+    '#type' => 'textarea',
+    '#title' => t('New password reset message'),
+    '#default_value' => variable_get('ldap_user_pass_form', '<h2>Form disabled by administrator.<h2>'),
+    '#cols' => 45,
     '#rows' => 3,
     '#maxlength' => 250,
     '#disabled' => (variable_get('ldap_alter_reset_form', LDAP_RESET_FORM_NO) == LDAP_RESET_FORM_NO ? TRUE : FALSE),
     '#description' => t('<p>The <em>Request New Password</em> form cannot be removed, but it can be altered. Pick the mode based on the types of user accounts and other configuration decisions.</p>'),
-    ); 
+    );
 
-  $form['ldap-ui'] = array( 
-    '#type' => 'fieldset', 
+  $form['ldap-ui'] = array(
+    '#type' => 'fieldset',
     '#title' => t('LDAP UI Options'),
-    '#description' => t('<p>Alters LDAP users\' interface only, though admin accounts can still access email and password fields of LDAP users regardless of selections. Does not effect non-LDAP authenticated accounts. </p>'), 
-    '#collapsible' => TRUE, 
+    '#description' => t('<p>Alters LDAP users\' interface only, though admin accounts can still access email and password fields of LDAP users regardless of selections. Does not effect non-LDAP authenticated accounts. </p>'),
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
-    
-  $form['ldap-ui']['ldap_disable_user_request_password'] = array( 
+
+  $form['ldap-ui']['ldap_disable_user_request_password'] = array(
     '#type' => 'checkbox',
     '#title' => t('Remove password change fields from user edit form'),
-    '#default_value' => variable_get('ldap_disable_user_request_password',FALSE),
+    '#default_value' => variable_get('ldap_disable_user_request_password', FALSE),
   );
 
-  $options_email_field = array( 
+  $options_email_field = array(
     LDAP_EMAIL_FIELD_NO => t('Do nothing'),
     LDAP_EMAIL_FIELD_REMOVE => t('Remove email field from form'),
     LDAP_EMAIL_FIELD_DISABLE => t('Disable email field on form')
   );
-  
+
   $form['ldap-ui']['ldap_alter_email_field'] = array(
-    '#type' => 'radios', 
+    '#type' => 'radios',
     '#title' => t('Alter email field on user edit form'),
-    '#description' => t('<p>Remove or disable email field from user edit form for LDAP authenticated users.</p>'), 
+    '#description' => t('<p>Remove or disable email field from user edit form for LDAP authenticated users.</p>'),
     '#default_value' => variable_get('ldap_alter_email_field', LDAP_EMAIL_FIELD_NO),
-    '#options' => $options_email_field, 
+    '#options' => $options_email_field,
     '#required' => true,
   );
-  
-  
-  $form['ldap_restore_defaults'] = array( 
+
+  $form['ldap_restore_defaults'] = array(
     '#type' => 'checkbox',
     '#title' => t('Reset to default values'),
-    '#default_value' => variable_get('ldap_restore_defaults',FALSE),
+    '#default_value' => variable_get('ldap_restore_defaults', FALSE),
   );
-  
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Save configuration'
   );
-
   return $form;
 }
 
-function ldapauth_admin_options_submit($form_id, $form_values) {
-  
-  if ($form_values['ldap_restore_defaults']) {
+function ldapauth_admin_options_submit($form, &$form_state) {
+  if ($form_state['values']['ldap_restore_defaults']) {
     variable_del('ldap_disable_request_new_password');
     variable_del('ldap_alter_reset_form');
     variable_del('ldap_alter_email_field');
@@ -345,24 +320,24 @@
     variable_del('ldap_forget_passwords');
     variable_del('ldap_login_process');
     $msg = 'System wide LDAP settings reset to defaults';
-  } else {
-    variable_set('ldap_user_pass_form', $form_values['ldap_user_pass_form']);
-    variable_set('ldap_disable_request_new_password', $form_values['ldap_disable_request_new_password']);
-    variable_set('ldap_forget_passwords', $form_values['ldap_forget_passwords']);
-    variable_set('ldap_login_process', $form_values['ldap_login_process']);
-    variable_set('ldap_disable_user_request_password', $form_values['ldap_disable_user_request_password']);
-    variable_set('ldap_alter_reset_form', $form_values['ldap_alter_reset_form']);
-    variable_set('ldap_alter_email_field', $form_values['ldap_alter_email_field']);
+  }
+  else {
+    variable_set('ldap_user_pass_form', $form_state['values']['ldap_user_pass_form']);
+    variable_set('ldap_disable_request_new_password', $form_state['values']['ldap_disable_request_new_password']);
+    variable_set('ldap_forget_passwords', $form_state['values']['ldap_forget_passwords']);
+    variable_set('ldap_login_process', $form_state['values']['ldap_login_process']);
+    variable_set('ldap_disable_user_request_password', $form_state['values']['ldap_disable_user_request_password']);
+    variable_set('ldap_alter_reset_form', $form_state['values']['ldap_alter_reset_form']);
+    variable_set('ldap_alter_email_field', $form_state['values']['ldap_alter_email_field']);
     $msg = 'System wide LDAP settings saved';
   }
   drupal_set_message($msg);
-  return 'admin/settings/ldapauth/options';
+  $form_state['redirect'] = 'admin/settings/ldapauth/options';
 }
 
-function ldapauth_admin_form() {
+function ldapauth_admin_form(&$form_state, $edit_action = false, $ldap_name = null) {
 
-  $ldap_name = arg(4);
-  if ((arg(3) == "edit") && ($ldap_name != NULL)) {
+  if ($edit_action && ($ldap_name != NULL)) {
     $edit = db_fetch_array(db_query("SELECT * FROM {ldapauth} WHERE name = '%s'", $ldap_name));
     $form['old-name'] = array(
       '#type' => 'hidden',
@@ -370,37 +345,46 @@
       );
   }
 
-  $form['server-settings'] = array( 
-    '#type' => 'fieldset', 
-    '#title' => t('Server settings'), 
-    '#collapsible' => TRUE, 
+  $form['action'] = array(
+    '#type' => 'value',
+    '#value' => $edit_action ? 'edit' : 'add',
+  );
+
+  $form['server-settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Server settings'),
+    '#collapsible' => TRUE,
     '#collapsed' => FALSE,
     );
 
   $form['server-settings']['name'] = array(
-    '#type' => 'textfield', 
-    '#title' => t('Name'), 
-    '#default_value' => $edit['name'],
+    '#type' => 'textfield',
+    '#title' => t('Name'),
+    '#default_value' => $edit_action ? $edit['name'] : '',
     '#description' => t('Choose a <em><strong>unique</strong></em> name for this server configuration.'),
-    '#size' => 50, 
-    '#maxlength' => 255, 
+    '#size' => 50,
+    '#maxlength' => 255,
     '#required' => TRUE,
     );
 
-  $form['server-settings']['server'] = array( 
-    '#type' => 'textfield', 
-    '#title' => t('LDAP server'), 
-    '#default_value' => $edit['server'],
-    '#size' => 50, 
-    '#maxlength' => 255, 
+  $form['server-settings']['server'] = array(
+    '#type' => 'textfield',
+    '#title' => t('LDAP server'),
+    '#default_value' => $edit_action ? $edit['server'] : '',
+    '#size' => 50,
+    '#maxlength' => 255,
     '#description' => t('<p>The domain name or IP address of your LDAP Server.</p>'),
     '#required' => TRUE,
-    ); 
-  
-  // workaround for a db schema screwup. If port is left blank, then next time the config is edited, 
+    );
+
+  // workaround for a db schema screwup. If port is left blank, then next time the config is edited,
   // it will stick a 0 in it. -- not good.
-  $_port = ($edit['port'] == '0') ? "389" : $edit['port'];
-  $form['server-settings']['port'] = array( 
+  if ($edit_action) {
+    $_port = ($edit['port'] == '0') ? "389" : $edit['port'];
+  } else {
+    $_port = '389';
+  }
+  $form['server-settings']['port'] = array(
     '#type' => 'textfield',
     '#title' => t('LDAP port'),
     '#default_value' => $_port,
@@ -410,89 +394,93 @@
     );
 
   $form['server-settings']['tls'] = array(
-    '#type' => 'checkbox', 
-    '#title' => t('Use Start-TLS'), 
-    '#return_value' => 1, 
-    '#default_value' => $edit['tls'],
+    '#type' => 'checkbox',
+    '#title' => t('Use Start-TLS'),
+    '#return_value' => 1,
+    '#default_value' => $edit_action ? $edit['tls'] : '',
     '#description' => t('<p>Secure the connection between the Drupal and the LDAP servers using TLS.<br /><em>Note: To use START-TLS, you must set the LDAP Port to 389.</em></p>'),
-  ); 
+  );
 
   $form['server-settings']['encrypted'] = array(
-    '#type' => 'checkbox', 
-    '#title' => t('Store passwords in encrypted form'), 
-    '#return_value' => 1, 
-    '#default_value' => $edit['encrypted'],
+    '#type' => 'checkbox',
+    '#title' => t('Store passwords in encrypted form'),
+    '#return_value' => 1,
+    '#default_value' => $edit_action ? $edit['encrypted'] : '',
     '#description' => t('<p>Secure the password in LDAP by storing it MD5 encrypted (use with care, as some LDAP directories may do this automatically, what would cause logins problems).</p>'),
     );
 
   $form['login-procedure'] = array(
-    '#type' => 'fieldset', 
-    '#title' => 'Login procedure', 
-    '#collapsible' => TRUE, 
+    '#type' => 'fieldset',
+    '#title' => 'Login procedure',
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     );
 
- $form['login-procedure']['basedn'] = array(
-    '#type' => 'textarea', 
-    '#title' => t('Base DNs'), 
-    '#default_value' => $edit['basedn'],
-    '#cols' => 50, 
-  '#rows' => 6, 
-  '#description' => t('<p>Base DNs for users. Enter one per line in case you need several of them.</p>')
+  $form['login-procedure']['basedn'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Base DNs'),
+    '#default_value' => $edit_action ? $edit['basedn'] : '',
+    '#cols' => 50,
+    '#rows' => 6,
+    '#description' => t('<p>Base DNs for users. Enter one per line in case you need several of them.</p>')
   );
 
-  $form['login-procedure']['user_attr'] = array( 
-    '#type' => 'textfield', 
-    '#title' => t('UserName attribute'), 
-    '#default_value' => $edit['user_attr'],
-    '#size' => 50, 
-    '#maxlength' => 255, 
+  $form['login-procedure']['user_attr'] = array(
+    '#type' => 'textfield',
+    '#title' => t('UserName attribute'),
+    '#default_value' => $edit_action ? $edit['user_attr'] : '',
+    '#size' => 50,
+    '#maxlength' => 255,
     '#description' => t('<p>The attribute that holds the users\' login name. (eg. <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">cn</em> for eDir or <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">sAMAccountName</em> for Active Directory).</p>'),
   );
 
-  $form['login-procedure']['mail_attr'] = array( 
-    '#type' => 'textfield', 
-    '#title' => t('Email attribute'), 
-    '#default_value' => $edit['mail_attr'],
-    '#size' => 50, 
-    '#maxlength' => 255, 
+  $form['login-procedure']['mail_attr'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Email attribute'),
+    '#default_value' => $edit_action ? $edit['mail_attr'] : '',
+    '#size' => 50,
+    '#maxlength' => 255,
     '#description' => t('<p>The attribute that holds the users\' email address. (eg. <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">mail</em>).</p>'),
   );
-  
-  $form['advanced'] = array( 
-    '#type' => 'fieldset', 
-    '#title' => 'Advanced configuration', 
-    '#collapsible' => TRUE, 
+
+  $form['advanced'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Advanced configuration',
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE
   );
 
-  $form['advanced']['ldap-note'] = array( 
+  $form['advanced']['ldap-note'] = array(
     '#value' => '<p>The process of authentication starts by establishing an anonymous connection to the LDAP directory and looking up for the user on it. Once this user is found, LDAP authentication is performed on them.</p><p>However, some LDAP configurations (specially common in <strong>Active Directory</strong> setups) restrict anonymous searches.</p><p>If your LDAP setup does not allow anonymous searches, or these are restricted in such a way that login names for users cannot be retrieved as a result of them, then you have to specify here a DN//password pair that will be used for these searches.</p><p>For security reasons, this pair should belong to an LDAP account with stripped down permissions.</p>'
   );
 
-  $form['advanced']['binddn'] =  array( 
-    '#type' => 'textfield', 
-    '#title' => t('DN for non-anonymous search'), 
-    '#default_value' => $edit['binddn'],
-    '#size' => 50, 
+  $form['advanced']['binddn'] =  array(
+    '#type' => 'textfield',
+    '#title' => t('DN for non-anonymous search'),
+    '#default_value' => $edit_action ? $edit['binddn'] : '',
+    '#size' => 50,
     '#maxlength' => 255,
   );
 
-  if ($edit['bindpw_clear'] ||  !$edit['bindpw']) {
-    $form['advanced']['bindpw'] = array( 
-      '#type' => 'password', 
-      '#title' => t('Password for non-anonymous search'), 
-      '#size' => 50, 
+  // show the pw field:
+  //  - new server
+  //  - edit server and (clear has been set or no pw has been configured)
+  if (!$edit_action || ($edit_action && ($edit['bindpw_clear'] ||  !$edit['bindpw']))) {
+    $form['advanced']['bindpw'] = array(
+      '#type' => 'password',
+      '#title' => t('Password for non-anonymous search'),
+      '#size' => 50,
       '#maxlength' => 255,
-      );
+    );
+    $form['advanced']['bindpw_clear'] = array('#type' => 'value', '#value' => false);
   }
   else {
     // give an option to clear the password
-    $form['advanced']['bindpw_clear'] = array( 
-      '#type' => 'checkbox', 
-      '#title' => t('Clear current password'), 
+    $form['advanced']['bindpw_clear'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Clear current password'),
       '#default_value' => false,
-      );
+    );
   }
 
   $form['submit'] = array(
@@ -503,52 +491,48 @@
   return $form;
 }
 
-/** 
-  * Submit the contact category page for submission
-**/
-
-function ldapauth_admin_form_submit($form_id, $form_values) {
-
+/**
+ * Submit the contact category page for submission
+ */
+function ldapauth_admin_form_submit($form, &$form_state) {
   // set the checking order
-  if ((arg(3) == 'add')) {
-    if (db_fetch_object(db_query("SELECT name FROM {ldapauth} WHERE name = '%s'", $form_values['name']))) {
+  if ($form_state['values']['action'] == 'add') {
+    if (db_fetch_object(db_query("SELECT name FROM {ldapauth} WHERE name = '%s'", $form_state['values']['name']))) {
       form_set_error( 'name', t('An LDAP config with that name already exists.'));
     }
 
-    db_query("INSERT INTO {ldapauth} (name, status, server, port, tls, encrypted, basedn, user_attr, mail_attr, binddn, bindpw) VALUES ('%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s')", $form_values['name'], 1, $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['encrypted'], $form_values['basedn'], trim($form_values['user_attr']), trim($form_values['mail_attr']), $form_values['binddn'], $form_values['bindpw']);
-    drupal_set_message(t('LDAP Configuration %config has been added.', array('%config' => $form_values['name'])));
-    watchdog('ldap', t('ldapauth: ldap config %config added.', array('%config' => $form_values['name'])));
+    db_query("INSERT INTO {ldapauth} (name, status, server, port, tls, encrypted, basedn, user_attr, mail_attr, binddn, bindpw) VALUES ('%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s')", $form_state['values']['name'], 1, $form_state['values']['server'], $form_state['values']['port'], $form_state['values']['tls'], $form_state['values']['encrypted'], $form_state['values']['basedn'], trim($form_state['values']['user_attr']), trim($form_state['values']['mail_attr']), $form_state['values']['binddn'], $form_state['values']['bindpw']);
+    drupal_set_message(t('LDAP Configuration %config has been added.', array('%config' => $form_state['values']['name'])));
+    watchdog('ldap', 'ldapauth: ldap config %config added.', array('%config' => $form_state['values']['name']));
   }
   else {
-    if ( !$form_values['bindpw_clear'] && $form_values['bindpw']) {
-      db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = '%d', tls = '%d', encrypted = '%d', basedn = '%s', user_attr = '%s', mail_attr = '%s', binddn = '%s', bindpw = '%s', bindpw_clear = '%d' WHERE name = '%s'", $form_values['name'], $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['encrypted'], $form_values['basedn'], trim($form_values['user_attr']), trim($form_values['mail_attr']), $form_values['binddn'], $form_values['bindpw'], $form_values['bindpw_clear'], $form_values['old-name']);
+    if ( !$form_state['values']['bindpw_clear'] && $form_state['values']['bindpw']) {
+      // set the password
+      db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = '%d', tls = '%d', encrypted = '%d', basedn = '%s', user_attr = '%s', mail_attr = '%s', binddn = '%s', bindpw = '%s', bindpw_clear = '%d' WHERE name = '%s'", $form_state['values']['name'], $form_state['values']['server'], $form_state['values']['port'], $form_state['values']['tls'], $form_state['values']['encrypted'], $form_state['values']['basedn'], trim($form_state['values']['user_attr']), trim($form_state['values']['mail_attr']), $form_state['values']['binddn'], $form_state['values']['bindpw'], $form_state['values']['bindpw_clear'], $form_state['values']['old-name']);
     }
     else {
       // set the clear password switch
-      db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = '%d', tls = '%d', encrypted = '%d', basedn = '%s', user_attr = '%s', mail_attr = '%s', binddn = '%s', bindpw_clear = '%d' WHERE name = '%s'", $form_values['name'], $form_values['server'], $form_values['port'], $form_values['tls'], $form_values['encrypted'], $form_values['basedn'], trim($form_values['user_attr']), trim($form_values['mail_attr']), $form_values['binddn'], $form_values['bindpw_clear'], $form_values['old-name']);
+      db_query("UPDATE {ldapauth} SET name = '%s', server = '%s', port = '%d', tls = '%d', encrypted = '%d', basedn = '%s', user_attr = '%s', mail_attr = '%s', binddn = '%s', bindpw_clear = '%d' WHERE name = '%s'", $form_state['values']['name'], $form_state['values']['server'], $form_state['values']['port'], $form_state['values']['tls'], $form_state['values']['encrypted'], $form_state['values']['basedn'], trim($form_state['values']['user_attr']), trim($form_state['values']['mail_attr']), $form_state['values']['binddn'], $form_state['values']['bindpw_clear'], $form_state['values']['old-name']);
     }
-    drupal_set_message(t('LDAP Configuration %config has been updated.', array('%config' => $form_values['name'])));
-    watchdog('ldap', t('ldapauth: ldap config %config updated.', array('%config' => $form_values['name'])));
+    drupal_set_message(t('LDAP Configuration %config has been updated.', array('%config' => $form_state['values']['name'])));
+    watchdog('ldap', 'ldapauth: ldap config %config updated.', array('%config' => $form_state['values']['name']));
   }
-  
-  return 'admin/settings/ldapauth';
-}
-
-function ldapauth_admin_delete() {
 
-  $ldap_name = arg(4);
+  $form_state['redirect'] = 'admin/settings/ldapauth';
+}
 
-  if (!$ldap_name) { 
-    drupal_goto('admin/settings/ldapauth'); 
+function ldapauth_admin_delete(&$form_state, $ldap_name) {
+  if (!$ldap_name) {
+    drupal_goto('admin/settings/ldapauth');
   }
   if ($result = db_fetch_object(db_query("SELECT name FROM {ldapauth} WHERE name = '%s'", $ldap_name))) {
-    return confirm_form(
-    array(),
-    t('Are you sure you want to delete the ldap configration named <em><strong>%server</strong></em>?', array('%server'=>$ldap_name)), 
-    'admin/settings/ldapauth',
-    t('<p>This action cannot be undone.</p>'),
-    t('Delete'), 
-    t('Cancel')
+    $form = array('name' => array('#type' => 'value', '#value' => $ldap_name));
+    return confirm_form($form,
+      t('Are you sure you want to delete the ldap configration named <em><strong>%server</strong></em>?', array('%server' => $ldap_name)),
+      'admin/settings/ldapauth',
+      t('<p>This action cannot be undone.</p>'),
+      t('Delete'),
+      t('Cancel')
     );
   }
   else {
@@ -557,17 +541,17 @@
   }
 }
 
-function ldapauth_admin_delete_submit($form_id, $form_values) {
-  if ($form_values['confirm']) {
-    db_query("DELETE FROM {ldapauth} WHERE name = '%s'", arg(4));
-  drupal_set_message(t('LDAP Configuration %config has been deleted.', array('%config' => $form_values['name'])));
-  watchdog('ldap', t('ldapauth: ldap config %config deleted.', array('%config' => $form_values['name'])));
+function ldapauth_admin_delete_submit($form, &$form_state) {
+  if ($form_state['values']['confirm']) {
+    db_query("DELETE FROM {ldapauth} WHERE name = '%s'", $form_state['values']['name']);
+    drupal_set_message(t('LDAP Configuration %config has been deleted.', array('%config' => $form_state['values']['name'])));
+    watchdog('ldap', 'ldapauth: ldap config %config deleted.', array('%config' => $form_state['values']['name']));
   }
-  return 'admin/settings/ldapauth';
+  $form_state['redirect'] = 'admin/settings/ldapauth';
 }
 
 function ldapauth_auth($name, $pass, $server) {
-  global $ldapauth_ldap;
+  global $_ldapauth_ldap;
 
   // Don't allow empty passwords because they cause problems on some setups
   // http://drupal.org/node/87831
@@ -575,7 +559,7 @@
     return false;
   }
 
-  $login_name = $server ? $name . '@' . $server : $name;
+  $login_name = $server ? $name .'@'. $server : $name;
   if (function_exists('ldapauth_transform_login_name')) {
     $login_name = call_user_func('ldapauth_transform_login_name', $login_name);
   }
@@ -592,11 +576,11 @@
       continue;
     }
     // Try to authenticate
-    if (!$ldapauth_ldap->connect($dn, $pass)) {
+    if (!$_ldapauth_ldap->connect($dn, $pass)) {
       continue;
     }
     if (function_exists('ldapauth_user_filter')
-        && !call_user_func('ldapauth_user_filter', $ldapauth_ldap->retrieveAttributes($dn))) {
+        && !call_user_func('ldapauth_user_filter', $_ldapauth_ldap->retrieveAttributes($dn))) {
       continue;
     }
     return true;
@@ -614,8 +598,8 @@
 
 function ldapauth_user($op, &$edit, &$edit_user, $category = NULL) {
   global $user;
-  
-  switch ($op) {    
+
+  switch ($op) {
     case 'login':
       // This is to convert from old ldap_integration to new ldapauth
       if ($user->ldap_authentified) {
@@ -629,19 +613,19 @@
           '#type' => 'fieldset',
           '#title' => 'LDAP authentication settings',
           '#collapsible' => TRUE,
-          );         
+          );
         $form['ldap_settings']['ldap_authentified'] = array(
           '#type' => 'checkbox',
           '#title' => 'Authenticate via LDAP',
           '#default_value' => $edit_user->ldap_authentified,
           );
-        
+
         $form['ldap_settings']['ldap_dn'] = array(
           '#type' => 'textfield',
           '#title' => 'LDAP User DN',
           '#default_value' => $edit_user->ldap_dn,
           );
-          
+
         return $form;
       }
       break;
@@ -651,28 +635,28 @@
 
 /*********************************
  *    3. Auxiliary functions     *
- *********************************/
+ * ***************************** */
 
 function _ldapauth_init($config) {
-  global $ldapauth_ldap;  
+  global $_ldapauth_ldap;
 
-  $row = db_fetch_object(db_query("SELECT * FROM {ldapauth} WHERE name = '%s'", $config)); 
+  $row = db_fetch_object(db_query("SELECT * FROM {ldapauth} WHERE name = '%s'", $config));
 
-  // $ldapauth_ldap = new LDAPInterface();
-  $ldapauth_ldap->setOption('name', $row->name);
-  $ldapauth_ldap->setOption('server', $row->server);
-  $ldapauth_ldap->setOption('port', $row->port);
-  $ldapauth_ldap->setOption('tls', $row->tls);
-  $ldapauth_ldap->setOption('encrypted', $row->encrypted);
-  $ldapauth_ldap->setOption('basedn', $row->basedn);
-  $ldapauth_ldap->setOption('user_attr', $row->user_attr);
-  $ldapauth_ldap->setOption('mail_attr', $row->mail_attr);
+  $_ldapauth_ldap = new LDAPInterface();
+  $_ldapauth_ldap->setOption('name', $row->name);
+  $_ldapauth_ldap->setOption('server', $row->server);
+  $_ldapauth_ldap->setOption('port', $row->port);
+  $_ldapauth_ldap->setOption('tls', $row->tls);
+  $_ldapauth_ldap->setOption('encrypted', $row->encrypted);
+  $_ldapauth_ldap->setOption('basedn', $row->basedn);
+  $_ldapauth_ldap->setOption('user_attr', $row->user_attr);
+  $_ldapauth_ldap->setOption('mail_attr', $row->mail_attr);
   return;
 }
 
 
 function _ldapauth_login2dn($login) {
-  global $ldapauth_ldap;
+  global $_ldapauth_ldap;
 
   $ret = '';
 
@@ -684,33 +668,33 @@
 }
 
 function _ldapauth_user_lookup($name) {
-  global $ldapauth_ldap;
+  global $_ldapauth_ldap;
   $ret = null;
 
-  if (! $ldapauth_ldap) {
+  if (! $_ldapauth_ldap) {
     return;
   }
 
-  $row = db_fetch_object(db_query("SELECT binddn, bindpw FROM {ldapauth} WHERE name = '%s'", $ldapauth_ldap->getOption('name')));
+  $row = db_fetch_object(db_query("SELECT binddn, bindpw FROM {ldapauth} WHERE name = '%s'", $_ldapauth_ldap->getOption('name')));
   $dn = $row->binddn;
   $pass = $row->bindpw;
   // If there is no BINDDN and BINDPW -- the connect will be an anonymous connect
-  $ldapauth_ldap->connect($dn, $pass);
-  $possible_base_dns = explode("\r\n", $ldapauth_ldap->getOption('basedn'));
+  $_ldapauth_ldap->connect($dn, $pass);
+  $possible_base_dns = explode("\r\n", $_ldapauth_ldap->getOption('basedn'));
   foreach ($possible_base_dns as $base_dn) {
-    if( ! $base_dn) {
+    if (!$base_dn) {
       continue;
     }
-    $name_attr = $ldapauth_ldap->getOption('user_attr') ? $ldapauth_ldap->getOption('user_attr') : LDAP_DEFAULT_USER_ATTRIBUTE;
+    $name_attr = $_ldapauth_ldap->getOption('user_attr') ? $_ldapauth_ldap->getOption('user_attr') : LDAP_DEFAULT_USER_ATTRIBUTE;
     $filter = "$name_attr=$name";
-    $result = $ldapauth_ldap->search($base_dn, $filter);
+    $result = $_ldapauth_ldap->search($base_dn, $filter);
     if ( ! $result) {
       continue;
     }
     $num_matches = $result['count'];
-    // must find exactly one user for authentication to 
+    // must find exactly one user for authentication to
     if ($num_matches != 1) {
-      watchdog('user', "Error: $num_matches users found with $filter under $base_dn", WATCHDOG_ERROR);
+      watchdog('user', "Error: %num users found with %filter under %base_dn", array('%num' => $num_matches, '%filter' => $filter, '%base_dn' => $base_dn), WATCHDOG_ERROR);
       continue;
     }
     $match = $result[0];
@@ -721,7 +705,7 @@
     // This was contributed by Dan "Gribnif" Wilga, and described
     // here: http://drupal.org/node/87833
     if ( ! isset($match[$name_attr][0]) ) {
-      $name_attr = strtolower($name_attr);
+      $name_attr = drupal_strtolower($name_attr);
       if ( ! isset($match[$name_attr][0]) ) {
         continue;
       }
@@ -736,7 +720,7 @@
     // loop through all possible options.
     $ok = false;
     foreach ($match[$name_attr] as $value) {
-      if (strtolower($value) == strtolower($name)) {
+      if (strcasecmp($value, $name) == 0) {
         $ok = true;
         break;
       }
@@ -753,16 +737,21 @@
 
 /*********************************
  *    4. Login process hacks     *
- *********************************/
- function ldapauth_form_alter($form_id, &$form) {
-   global $user;
+ * ***************************** */
+function ldapauth_form_alter(&$form, $form_state, $form_id) {
+  global $user;
 
-   if (isset($form['#validate']['user_login_validate'])) {
-    $form['#validate'] = array('ldapauth_login_validate' => array());
+  // replace the drupal authenticate function is it's used as validation 
+  if (isset($form['#validate']) && is_array($form['#validate']) && in_array('user_login_authenticate_validate', $form['#validate'])) {
+    for ($i = 0; $i < count($form['#validate']); $i++) {
+      if ($form['#validate'][$i] == "user_login_authenticate_validate") {
+        $form['#validate'][$i] = 'ldapauth_login_validate';
+      }
+    }
   }
 
   // Rewrite forms regarding user administration
-  switch($form_id) {
+  switch ($form_id) {
     case 'user_login_block':
       // Since form only available when not logged in, no need to check for admin?
       if (variable_get('ldap_disable_request_new_password', FALSE)) {
@@ -772,11 +761,12 @@
     case 'user_pass':
       $opt = variable_get('ldap_alter_reset_form', LDAP_RESET_FORM_NO);
       if ($opt <> LDAP_RESET_FORM_NO && variable_get('ldap_user_pass_form', FALSE)) {
-        if ($opt == LDAP_RESET_FORM_OVERWRITE){
+        if ($opt == LDAP_RESET_FORM_OVERWRITE) {
           $form = array(
             '#value' => t(variable_get('ldap_user_pass_form', '<h2>Form disabled by administrator.</h2>')),
           );
-        }else{
+        }
+        else{
           $form_stub = array(
             array(
               '#value' => t(variable_get('ldap_user_pass_form', '<h2>Form disabled by administrator.</h2>'))
@@ -794,24 +784,25 @@
         }
         $opt = variable_get('ldap_alter_email_field', LDAP_EMAIL_FIELD_NO);
         if ($opt <> LDAP_EMAIL_FIELD_NO) {
-          if ($opt == LDAP_EMAIL_FIELD_REMOVE){
+          if ($opt == LDAP_EMAIL_FIELD_REMOVE) {
             // Cannot just remove field because is built into Drupal as required
-            $form['account']['mail']['#type'] = 'hidden';  
+            $form['account']['mail']['#type'] = 'hidden';
             $form['account']['mail']['#attributes']['READONLY'] = 'READONLY';
-            $form['account']['mail']['#value'] = $form['account']['mail']['#default_value'];                
-          }else{
+            $form['account']['mail']['#value'] = $form['account']['mail']['#default_value'];
+          }
+          else {
             // To prevent a user from getting stuck if they have no ldap email, switching
             // to readonly which is similar to 'DISABLED' except the default value will be submitted
-            $form['account']['mail']['#attributes']['READONLY'] = 'READONLY';      
+            $form['account']['mail']['#attributes']['READONLY'] = 'READONLY';
           }
         }
         // Remove fieldset if empty
-        if (key_exists('account', $form) && !key_exists('pass', $form['account']) && 
+        if (key_exists('account', $form) && !key_exists('pass', $form['account']) &&
           key_exists('mail', $form['account']) && $form['account']['mail']['#type'] == 'hidden') {
-          // First make sure no one else added any unexpected form fields 
+          // First make sure no one else added any unexpected form fields
           foreach ($form['account'] as $key => $value) {
-            if ((substr($key, 0, 1) <> '#') && !($key == 'mail' ||  $key == 'pass')) {
-              // A key that isn't an attribute, 'mail', or 'pass' found; break to avoid removing fieldset 
+            if ((drupal_substr($key, 0, 1) <> '#') && !($key == 'mail' ||  $key == 'pass')) {
+              // A key that isn't an attribute, 'mail', or 'pass' found; break to avoid removing fieldset
               break;
             }
           }
@@ -819,89 +810,75 @@
           $form['mail'] = $form['account']['mail'];
           unset($form['account']);
         }
-      } 
+      }
       break;
   }
-  
-}
 
-function ldapauth_login_validate($form_id, $form_values) {
-  global $user;
-  
+}
 
-  if (isset($form_values['name'])) {
-    if (user_is_blocked($form_values['name'])) {
-      // blocked in user administration
-      form_set_error('login', t('The username %name has been blocked.', array('%name' => $form_values['name'])));
-    }
-    else if (drupal_is_denied('user', $form_values['name'])) {
-      // denied by access controls
-      form_set_error('login', t('The name %name is a reserved username.', array('%name' => $form_values['name'])));
-    }
-    else if ($form_values['pass']) {
-      // === HACK STARTS ===
-      // --- New code starts
-      $user = _ldapauth_user_authenticate($form_values['name'], trim($form_values['pass']));
-      // --- New code ends
-
-      // --- Drupal's original code starts
-      // $user = user_authenticate($form_values['name'], trim($form_values['pass']));
-      // --- Drupal's original code ends
-      // === HACK ENDS ===
-
-      if (!$user->uid) {
-        form_set_error('login', t('Sorry. Unrecognized username or password.') .' '. l(t('Have you forgotten your password?'), 'user/password'));
-        watchdog('user', t('Login attempt failed for %user: %error.', array('%user' => theme('placeholder', $form_values['name']))));
-      }
-    }
+function ldapauth_login_validate($form, &$form_state) {
+  if (!empty($form_state['values']['name']) && !empty($form_state['values']['pass'])) {
+    _ldapauth_user_authenticate($form_state['values']);
   }
 }
 
-function _ldapauth_user_authenticate($name, $pass) {  
-  global $user, $ldapauth_ldap;
+function _ldapauth_user_authenticate($values) {
+  global $_ldapauth_ldap;
   // (Design decision) uid=1 (admin user) must always authenticate to local database
   // this user is critical for all drupal admin and upgrade operations so it is best
   // left with drupal's native authentication
 
+  $name = $values['name'];
+  $pass = trim($values['pass']);
+  
   $result = db_query("SELECT uid FROM {users} WHERE name = '%s'", $name);
   if (($_user = db_fetch_object($result)) && ($_user->uid == 1)) {
-    $user = user_authenticate($name, $pass);
-  }  
-  else { 
+    // load user is done by drupal authentication
+    user_authenticate($values);
+  }
+  else {
     // http://drupal.org/node/113884
     if (variable_get('ldap_login_process', LDAP_FIRST_DRUPAL) <> LDAP_FIRST_LDAP) {
       // authenticate local users first
       $result = db_query("SELECT name,data FROM {users} WHERE name='%s'", $name);
-      $local_user_count = db_num_rows($result);
       $data = db_fetch_array($result);
       $data = unserialize($data['data']);
-      if ($local_user_count > 0 && (!isset($data['ldap_authentified']) || $data['ldap_authentified']==0)) {
+      if ($data && (!isset($data['ldap_authentified']) || $data['ldap_authentified'] == 0)) {
         // a local user with same name exists -- authenticate that user
         // nullify global ldap resource for good measure
-        $ldapauth_ldap = "";
-        $user = user_authenticate($name, $pass);
+        $_ldapauth_ldap = "";
+
+        // load user is done by drupal authentication
+        user_authenticate($values);
       }
       else {
-        // no such local user - check ldap     
-        if (ldapauth_auth($name, $pass, null)) {
-          // login successful - user exists in LDAP - if not registered in LDAP, register; set cookie
-          $user = _ldapauth_save_user($name, $pass);
-        }
+        // no such local user - check ldap
+        _ldapauth_do_login($values); 
       }
     }
     else {
       // direct ldap authentication - check with ldap
-      if (ldapauth_auth($name, $pass, null)) {
-        // login successful - user exists in LDAP - if not registered in LDAP, register; set cookie
-        $user = _ldapauth_save_user($name, $pass);
-      }
+      _ldapauth_do_login($values); 
+    }
+  }
+}
+
+function _ldapauth_do_login($values) {
+  global $user;
+
+  if (ldapauth_auth($values['name'], $values['pass'], null)) {
+    // login successful - user exists in LDAP - if not registered in LDAP, register; set cookie
+    $account = _ldapauth_save_user($values['name'], $values['pass']);
+    if ($account != null) {
+      $user = $account;
+      user_authenticate_finalize($values);
     }
   }
   return $user;
 }
 
 function _ldapauth_save_user($login_string, $pass) {
-  global $user, $ldapauth_ldap;
+  global $_ldapauth_ldap;
   $account = user_load(array('name' => $login_string));
   //$dn = _ldapauth_login2dn($login_string);
   $ldap_user = _ldapauth_user_lookup($login_string);
@@ -924,48 +901,45 @@
     //                we just write anything as e-mail address. If
     //                ldapdata module is enabled, it will write the
     //                right value upon login
-    
-    if (key_exists(($ldapauth_ldap->getOption('mail_attr') ? $ldapauth_ldap->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE), $ldap_user)) {
-      $mail = $ldap_user[$ldapauth_ldap->getOption('mail_attr')][0];
-    } else {
+
+    if (key_exists(($_ldapauth_ldap->getOption('mail_attr') ? $_ldapauth_ldap->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE), $ldap_user)) {
+      $mail = $ldap_user[$_ldapauth_ldap->getOption('mail_attr')][0];
+    }
+    else {
       $mail = "";
     }
     //   3. 'init' => same. BTW: what's the use of this field?
     $init = $mail;
     //   4. 'ldap_authentified' => TRUE . There is a need to mark
     //      people as externally authentified.
-      
-    // Here ldap_dn should not be set (as it was in the 4.7- versions). 
+
+    // Here ldap_dn should not be set (as it was in the 4.7- versions).
     // The DN should be determined by the specific LDAP repo that is being used at login time
-    $userinfo = array('name' => $login_string, 'pass' => $pass, 'mail' => $mail, 'init' => $init, 'status' => 1, 'authname_ldapauth' => $login_string, 'ldap_authentified' => TRUE, 'ldap_dn' => $dn);        
-    $user = user_save('', $userinfo);
-    watchdog('user', t('New external user - ldapauth: %user using module %module.', array('%user' => theme('placeholder', $login_string), '%module' => theme('placeholder', 'ldapauth'))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
+    $userinfo = array('name' => $login_string, 'pass' => $pass, 'mail' => $mail, 'init' => $init, 'status' => 1, 'authname_ldapauth' => $login_string, 'ldap_authentified' => TRUE, 'ldap_dn' => $dn);
+    $account = user_save('', $userinfo);
+    watchdog('user', 'New external user - ldapauth: %user using module %module.', array('%user' => theme('placeholder', $login_string), '%module' => theme('placeholder', 'ldapauth')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit'));
   }
   else if (!$account->ldap_authentified) {
     drupal_set_message(t('Another user already exists in this system with the same login name. You should contact the system\'s administrator in order to solve this conflict.'), 'error');
-    watchdog('user', t('LDAP user with DN %dn has a naming conflict with non-LDAP user %account', array('%dn' => theme('placeholder', $dn), '%account' => theme('placeholder', $account->name))), WATCHDOG_ERROR);    
-    module_invoke_all('user', 'logout', NULL, $user);
-  }
-  else {
-    $user = $account;
+    watchdog('user', 'LDAP user with DN %dn has a naming conflict with non-LDAP user %account', array('%dn' => theme('placeholder', $dn), '%account' => theme('placeholder', $account->name)), WATCHDOG_ERROR);
+    return null;
   }
+
   // setup the cookies et al
   // We save the config that was used to authenticate the user in the user object.
   // This will be used by ldapdata and other ldapXXX modules.
-  
-  if (key_exists(($ldapauth_ldap->getOption('mail_attr') ? $ldapauth_ldap->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE), $ldap_user)) {
-    $mail = $ldap_user[$ldapauth_ldap->getOption('mail_attr')][0];
+  if (key_exists(($_ldapauth_ldap->getOption('mail_attr') ? $_ldapauth_ldap->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE), $ldap_user)) {
+    $mail = $ldap_user[$_ldapauth_ldap->getOption('mail_attr')][0];
   }
-  
-  $config_name = $ldapauth_ldap->getOption('name');
+
+  $config_name = $_ldapauth_ldap->getOption('name');
   $userinfo = array('mail' => $mail, 'ldap_dn' => $dn, 'ldap_config' => $config_name);
-  $user = user_save($user, $userinfo);
-    
-  // obtain the DN for this user in this specific LDAP repository  
+  $account = user_save($account, $userinfo);
+
+  // obtain the DN for this user in this specific LDAP repository
   $_SESSION['ldap_login']['dn'] = $dn;
   $_SESSION['ldap_login']['pass'] = $pass;
-  
-  return $user;
+
+  return $account;
 }
 
-?>
Binary files ldap_integration.orig/.ldapauth.module.swp and ldap_integration/.ldapauth.module.swp differ
diff --exclude=.svn -urN ldap_integration.orig/ldapdata.info ldap_integration/ldapdata.info
--- ldap_integration.orig/ldapdata.info	2008-05-10 14:04:37.000000000 +0200
+++ ldap_integration/ldapdata.info	2008-06-26 17:48:00.000000000 +0200
@@ -2,9 +2,10 @@
 name = ldapdata
 description = "Permits reading and editing of own's LDAP data for users authenticated via ldapauth module."
 package = Administration
-dependencies = ldapauth profile
+dependencies[] = ldapauth 
+dependencies[] = profile
 ; Information added by drupal.org packaging script on 2008-05-10
-version = "5.x-1.x-dev"
+version = "6.x-1.x-dev"
 project = "ldap_integration"
 datestamp = "1210421077"
-
+core = 6.x
diff --exclude=.svn -urN ldap_integration.orig/ldapdata.install ldap_integration/ldapdata.install
--- ldap_integration.orig/ldapdata.install	2007-07-23 04:50:28.000000000 +0200
+++ ldap_integration/ldapdata.install	2008-07-10 10:28:34.000000000 +0200
@@ -1,42 +1,55 @@
 <?php
 // $Id: ldapdata.install,v 1.2 2007/07/23 02:50:28 kreaper Exp $
+
+/**
+ * @file
+ * File with install instructions for ldapdata module
+ */
+
 /**
  * Implementation of hook_install().
  */
 function ldapdata_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("ALTER TABLE {ldapauth} ADD (
-        ldapdata_binddn VARCHAR(255) NOT NULL default '',
-        ldapdata_bindpw VARCHAR(255) NOT NULL default '',
-        ldapdata_bindpw_clear VARCHAR(2) NOT NULL default '',
-        ldapdata_rwattrs LONGTEXT NOT NULL default '', 
-      	ldapdata_roattrs LONGTEXT NOT NULL default '', 
-        ldapdata_mappings LONGTEXT NOT NULL default ''
-      )");
-      break;
-    case 'pgsql':
-      db_query("ALTER TABLE {ldapauth} ADD (
-        ldapdata_binddn VARCHAR(255) NOT NULL default '',
-        ldapdata_bindpw VARCHAR(255) NOT NULL default '',
-        ldapdata_bindpw_clear VARCHAR(2) NOT NULL default '',
-        ldapdata_rwattrs TEXT NOT NULL, 
-        ldapdata_roattrs TEXT NOT NULL, 
-        ldapdata_mappings TEXT NOT NULL
-      )"); 
-      break;
-  }
+  $ret = array();
+  db_add_field($ret, 'ldapauth', 'ldapdata_binddn', array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldapdata_bindpw', array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldapdata_bindpw_clear', array(
+        'type' => 'varchar',
+        'length' => '2',
+        'not null' => TRUE,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldapdata_rwattrs', array(
+        'type' => 'text',
+        'not null' => TRUE));
+  db_add_field($ret, 'ldapauth', 'ldapdata_roattrs', array(
+        'type' => 'text',
+        'not null' => TRUE));
+  db_add_field($ret, 'ldapauth', 'ldapdata_mappings', array(
+        'type' => 'text',
+        'not null' => TRUE));
+
+  return $ret;
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function ldapdata_uninstall() {
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_binddn");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_bindpw");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_bindpw_clear");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_rwattrs");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_roattrs");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldapdata_mappings");
-}
\ No newline at end of file
+  $ret = array();
+  db_drop_field($ret, 'ldapauth', 'ldapdata_binddn');
+  db_drop_field($ret, 'ldapauth', 'ldapdata_bindpw');
+  db_drop_field($ret, 'ldapauth', 'ldapdata_bindpw_clear');
+  db_drop_field($ret, 'ldapauth', 'ldapdata_rwattrs');
+  db_drop_field($ret, 'ldapauth', 'ldapdata_roattrs');
+  db_drop_field($ret, 'ldapauth', 'ldapdata_mappings');
+
+  return $ret;
+}
diff --exclude=.svn -urN ldap_integration.orig/ldapdata.module ldap_integration/ldapdata.module
--- ldap_integration.orig/ldapdata.module	2008-04-17 06:32:12.000000000 +0200
+++ ldap_integration/ldapdata.module	2008-07-10 12:00:09.000000000 +0200
@@ -1,6 +1,12 @@
 <?php
 
 // $Id: ldapdata.module,v 1.1.4.10.2.2 2008/04/17 04:32:12 scafmac Exp $
+
+/**
+ * @file
+ * Ldapdata module
+ */
+
 include_once('ldap_integration/ldapdata.conf.php');
 include_once('ldap_integration/libdebug.php');
 include_once('ldap_integration/LDAPInterface.php');
@@ -23,16 +29,16 @@
 
 
 /***************************
-*     Drupal Hooks         *
-***************************/
+ *     Drupal Hooks        *
+ * *********************** */
 
 /**
-* Implements hook_help()
-**/
-function ldapdata_help($section) {
+ * Implements hook_help()
+ */
+function ldapdata_help($path, $arg) {
   $output = '';
-  
-  switch ($section) {
+
+  switch ($path) {
     case 'admin/modules#name':
       $output = 'ldapdata';
       break;
@@ -42,18 +48,18 @@
       break;
     case 'user/help#ldapauth':
       $output = t('Edit LDAP account info');
-      break;   
+      break;
   }
 
   return $output;
 }
 
 /**
-* Implements hook_user()
-**/
+ * Implements hook_user()
+ */
 
 function ldapdata_user($op, &$edit, &$user, $category = NULL) {
-  switch($op) {
+  switch ($op) {
     case 'categories':
       return ldapdata_user_categories($user);
     case 'form':
@@ -72,53 +78,59 @@
   }
 }
 /**
-* Implements hook_menu()
-**/
+ * Implements hook_menu()
+ */
 function ldapdata_menu() {
   $items = array();
 
-    $items[] = array(
-      'path' => 'admin/settings/ldapdata',
-      'title' => t('LDAP Data'),
-      'description' => t('Configure LDAP Data'), 
-      'callback' => 'ldapdata_admin_list',
-      'access' => user_access('administer ldap modules'),
-      );
-    $items[] = array( 
-      'path' => 'admin/settings/ldapdata/edit',
-      'title' => t('LDAP DATA'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapdata_admin_edit'),
+  $items['admin/settings/ldapdata'] = array(
+      'title' => 'LDAP Data',
+      'description' => 'Configure LDAP Data',
+      'page callback' => 'ldapdata_admin_list',
+      'access arguments' => array('administer ldap modules'),
+      );
+  $items['admin/settings/ldapdata/edit'] = array(
+      'title' => 'LDAP DATA',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('ldapdata_admin_edit', 3),
       'type' => MENU_CALLBACK,
       'weight' => 1,
-      'access' => user_access('administer ldap modules'),
+      'access arguments' => array('administer ldap modules'),
       );
-    $items[] = array( 
-      'path' => 'admin/settings/ldapdata/reset', 
-      'title' => t('LDAP Data'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapdata_admin_edit'),
+  $items['admin/settings/ldapdata/reset'] = array(
+      'title' => 'LDAP Data',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('ldapdata_admin_edit', 3),
       'type' => MENU_CALLBACK,
       'weight' => 1,
-      'access' => user_access('administer ldap modules'),
+      'access arguments' => array('administer ldap modules'),
       );
-    $items[] = array( 
-      'path' => 'admin/settings/ldapdata/list', 
-      'title' => t('LDAP Data'),
-      'callback' => 'ldapdata_admin_list',
+  $items['admin/settings/ldapdata/list'] = array(
+      'title' => 'LDAP Data',
+      'page callback' => 'ldapdata_admin_list',
       'type' => MENU_DEFAULT_LOCAL_TASK,
       'weight' => 1,
-      'access' => user_access('administer ldap modules'),
-      );       
+      'access arguments' => array('administer ldap modules'),
+      );
   return $items;
-  
+}
+
+function ldapdata_theme() {
+  return array(
+    'ldapdata_admin_edit' => array(
+      'arguments' => array('form' => NULL),
+    ),
+    'ldapdata_ldap_attribute' => array(
+      'arguments' => array('value' => NULL, 'type' => NULL),
+    ),
+  );
 }
 
 function ldapdata_admin_list() {
   $result = db_query("SELECT sid, name FROM {ldapauth} WHERE status = '%s' ORDER BY sid", 1);
   $rows = array();
   while ($row = db_fetch_object($result)) {
-    $rows[] = array($row->name, l(t('edit'), 'admin/settings/ldapdata/edit/'.$row->name), l(t('reset'), 'admin/settings/ldapdata/reset/'.$row->name));
+    $rows[] = array($row->name, l(t('edit'), 'admin/settings/ldapdata/edit/'. $row->name), l(t('reset'), 'admin/settings/ldapdata/reset/'. $row->name));
   }
 
   $header = array(
@@ -127,14 +139,14 @@
       'data' => t('Operations'),
       'colspan' => 2
     )
-  );  
+  );
   return theme('table', $header, $rows);
 }
 
-function ldapdata_admin_edit($ldap_name) {
-  global $ldap_attributes;
-  
-  if ((arg(3) == "reset") && ($ldap_name)) {
+function ldapdata_admin_edit(&$form_state, $action, $ldap_name) {
+  global $_ldap_attributes;
+
+  if (($action == "reset") && ($ldap_name)) {
     $form['reset_ldap'] = array(
       '#type' => 'value',
       '#value' => $ldap_name,
@@ -142,13 +154,13 @@
     return confirm_form(
       $form,
       t('Are you sure you want to reset the groups mapping to defaults ?'),
-      'admin/settings/ldapdata', 
-      t('<em>This action cannot be undone.</p>'), 
-      t('Reset'), 
+      'admin/settings/ldapdata',
+      t('<em>This action cannot be undone.</p>'),
+      t('Reset'),
       t('Cancel')
     );
   }
-  elseif ((arg(3) == "edit") && ($ldap_name)) {
+  elseif (($action == "edit") && ($ldap_name)) {
 
     $result = db_fetch_array(db_query("SELECT ldapdata_mappings, ldapdata_roattrs, ldapdata_rwattrs, ldapdata_binddn, ldapdata_bindpw, ldapdata_bindpw_clear FROM {ldapauth} WHERE name = '%s'", $ldap_name));
 
@@ -156,9 +168,9 @@
     $roattrs = unserialize($result['ldapdata_roattrs']);
     $rwattrs = unserialize($result['ldapdata_rwattrs']);
     $ldapdata_binddn = $result['ldapdata_binddn'];
-    $ldapdata_bindpw = $result['ldapdata_bindpw']; 
-    $ldapdata_bindpw_clear = $result['ldapdata_bindpw_clear'];       
-    
+    $ldapdata_bindpw = $result['ldapdata_bindpw'];
+    $ldapdata_bindpw_clear = $result['ldapdata_bindpw_clear'];
+
     // ATTRIBUTE MAPPING
     $output = "";
     $form['ldap_attribute_mapping'] = array(
@@ -181,7 +193,7 @@
         LDAP_MAP_ATTRIBUTES_READ_ONLY => t('Same, but read-only mode.'),
         LDAP_MAP_NOTHING => t('No attribute mapping will be done at all (<strong><em>Clears any existing mappings</em></strong>)'),
         ),
-       );
+    );
 
     $profile_fields = _ldapdata_retrieve_profile_fields();
     $standard_fields = _ldapdata_retrieve_standard_user_fields();
@@ -192,7 +204,7 @@
 
     $ldap_drupal_reverse_mappings = _ldapdata_reverse_mappings($ldap_name);
     foreach ($drupal_fields as $key => $field) {
-      $field_tmp = "ldap_amap-".$key;
+      $field_tmp = "ldap_amap-". $key;
       $_prefix = "<tr><td><label for=\"edit[$field_tmp]\">$field</label></td><td>";
       $form['ldap_attribute_mapping'][$field_tmp] = array(
         '#type' => 'textfield',
@@ -203,13 +215,13 @@
         '#suffix' => '</td>',
         );
     }
-   
+
     $form['ldap_attribute_mapping']['ldap_drupal_reverse_mappings_post'] = array(
       '#value' => '</tbody></table></div>',
-      ); 
-      
-      
-    // ATTRIBUTE ACCESS CONTROL      
+      );
+
+
+    // ATTRIBUTE ACCESS CONTROL
 
     $form["ldap_editable_attributes"] = array(
       '#type' => 'fieldset',
@@ -217,34 +229,36 @@
       '#collapsible' => TRUE,
       '#tree' => true,
       );
-      
+
     $form["ldap_editable_attributes"]["ldap_message"] = array(
-      '#value' => t('<p>Users may be able to view their LDAP attributes\' values, as well as edit them. You can configure this feature here.</p>'), 
-      );            
-    
-    foreach ($ldap_attributes as $key => $field) {
+      '#value' => t('<p>Users may be able to view their LDAP attributes\' values, as well as edit them. You can configure this feature here.</p>'),
+      );
+
+    foreach ($_ldap_attributes as $key => $field) {
       $fields[$key] = $field[2];
     }
 
-    foreach ($fields as $attr => $attr_name) { 
-      
-      $ro_options[$attr]  = '';
-      $rw_options[$attr]  = ''; 
-      
+    $i = 0;
+    foreach ($fields as $attr => $attr_name) {
+      $ro_options[$attr]  = $attr_name;
+      $rw_options[$attr]  = $attr_name;
+      $ro_status[$i] = false;
+      $rw_status[$i] = false;
+
       if (!empty($roattrs) && (in_array($attr, $roattrs))) {
-        $ro_status[] = $attr;
+        $ro_status[$i] = $attr;
       }
       if (!empty($rwattrs) && (in_array($attr, $rwattrs))) {
-        $rw_status[] = $attr;
-      }     
-              
+        $rw_status[$i] = $attr;
+      }
+
       $form['ldap_editable_attributes']['ldap_attr_table'][$attr] = array(
-        //'#type' => 'markup',
+        '#type' => 'markup',
         '#value' => $attr_name,
         );
-
+      $i++;
     }
-       
+
     $form['ldap_editable_attributes']['ro_status'] = array(
       '#type' => 'checkboxes',
       '#options' => $ro_options,
@@ -255,7 +269,7 @@
       '#type' => 'checkboxes',
       '#options' => $rw_options,
       '#default_value' => $rw_status,
-      );  
+      );
 
     $form['ldap_editable_attributes']['header'] = array(
       '#type' => 'value',
@@ -265,7 +279,7 @@
         array('data' => 'Editable by User?'),
         ));
 
-    // ADVANCED CONFIGURATION        
+    // ADVANCED CONFIGURATION
 
       $form['advanced'] = array(
         '#type' => 'fieldset',
@@ -273,11 +287,11 @@
         '#collapsible' => TRUE,
         '#collapsed' => TRUE
         );
-        
+
       $form['advanced']['ldap-note'] = array(
         '#value' => t('<p>When reading/editing attributes, this module logs on to the LDAP directory using the user\'s DN//pass pair. However, many LDAP setups do not allow their users to edit attributes.</p><p>If this is your case, but still you want users to edit their LDAP attributes via Drupal, you should set up an special user on your directory, with special access to edit your users\' attributes. Then this module will use it to log on and edit data.</p>')
-        );  
-      
+        );
+
       $form['advanced']['ldapdata_binddn'] = array(
         '#type' => 'textfield',
         '#title' => t('DN for reading/editing attributes'),
@@ -285,8 +299,8 @@
         '#size' => 50,
         '#maxlength' => 255,
         );
-        
-      if ($ldapdata_bindpw_clear || !ldapdata_bindpw) {     
+
+      if ($ldapdata_bindpw_clear || !ldapdata_bindpw) {
         $form['advanced']['ldapdata_bindpw'] = array(
           '#type' => 'password',
           '#title' => t('Password for reading/editing attributes'),
@@ -300,29 +314,29 @@
           '#type' => 'checkbox',
           '#default_value' => false,
           '#title' => t('Clear current password'),
-          );  
+          );
       }
 
     // SUBMIT
     $form['config_name'] = array(
       '#type' => 'hidden',
       '#value' => $ldap_name,
-      );   
-      
+      );
+
     $form['buttons']['submit'] = array(
       '#type' => 'submit',
       '#value' => 'Update'
       );
-           
-    return $form; 
+
+    return $form;
   }
   else {
-    drupal_goto('admin/settings/ldapdata');
+    $form_state['redirect'] = 'admin/settings/ldapdata';
   }
-} 
+}
 
 function theme_ldapdata_admin_edit($form) {
-  
+
   $output = '';
   $rows = array();
   foreach (element_children($form) as $element) {
@@ -330,13 +344,13 @@
       foreach (element_children($form['ldap_editable_attributes']['ldap_attr_table']) as $key) {
         $row = array();
         $row[] = drupal_render($form['ldap_editable_attributes']['ldap_attr_table'][$key]);
-        $row[] = drupal_render($form['ldap_editable_attributes']['ro_status'][$key]);    
-        $row[] = drupal_render($form['ldap_editable_attributes']['rw_status'][$key]);        
-        $rows[] = $row;     
+        $row[] = drupal_render($form['ldap_editable_attributes']['ro_status'][$key]);
+        $row[] = drupal_render($form['ldap_editable_attributes']['rw_status'][$key]);
+        $rows[] = $row;
       }
-      $form['ldap_editable_attributes']['#children'] .= drupal_render($form['ldap_editable_attributes']['ldap_message']);      
+      $form['ldap_editable_attributes']['#children'] .= drupal_render($form['ldap_editable_attributes']['ldap_message']);
       $form['ldap_editable_attributes']['#children'] .= theme('table', $form['ldap_editable_attributes']['header']['#value'], $rows);
-      $output .= drupal_render($form['ldap_editable_attributes']);            
+      $output .= drupal_render($form['ldap_editable_attributes']);
     }
     else {
       $output .= drupal_render($form[$element]);
@@ -344,103 +358,104 @@
   }
 
   $output .= drupal_render($form);
-  
+
   return $output;
-    
-}
 
-function ldapdata_admin_edit_submit($form_id, $form_values) {
+}
 
-  $config_name = $form_values['config_name'];    
+function ldapdata_admin_edit_submit($form, &$form_state) {
+  $config_name = $form_state['values']['config_name'];
   // Attribute Mapping
-  $attr_mapping_access = $form_values['ldap_attr_mapping'];
-  
+  $attr_mapping_access = $form_state['values']['ldap_attr_mapping'];
+
   $attr_mappings['access'] = $attr_mapping_access;
-  
-  if ($attr_mapping_access >=4 ) {   
-    foreach (element_children($form_values) as $attr) {
-      if (preg_match("/ldap_amap/", $attr) && $form_values[$attr]) {
+
+  if ($attr_mapping_access >=4 ) {
+    foreach (element_children($form_state['values']) as $attr) {
+      if (preg_match("/ldap_amap/", $attr) && $form_state['values'][$attr]) {
         // match found
-        $attr_mappings[$attr] = $form_values[$attr];
+        $attr_mappings[$attr] = $form_state['values'][$attr];
       }
-    }  
+    }
   }
   $serialized_data = serialize($attr_mappings);
   // Attribute Access Control
-  $ro_tmp = array_filter($form_values['ldap_editable_attributes']['ro_status']);
- 
+  $ro_tmp = array_filter($form_state['values']['ldap_editable_attributes']['ro_status']);
+
   if (!empty($ro_tmp)) {
     foreach ($ro_tmp as $ro_attr) {
       $ro_attrs[] = $ro_attr;
     }
     $serialized_ro_attrs = serialize($ro_attrs);
   }
-  
-  $rw_tmp = array_filter($form_values['ldap_editable_attributes']['rw_status']);  
+
+  $rw_tmp = array_filter($form_state['values']['ldap_editable_attributes']['rw_status']);
   if (!empty($rw_tmp)) {
     foreach ($rw_tmp as $rw_attr) {
       $rw_attrs[] = $rw_attr;
     }
     $serialized_rw_attrs = serialize($rw_attrs);
   }
-  
-  if ( !$form_values['ldapdata_bindpw_clear'] && $form_values['ldapdata_bindpw']) {
-    db_query("UPDATE {ldapauth} SET ldapdata_mappings = '%s', ldapdata_roattrs = '%s', ldapdata_rwattrs = '%s', ldapdata_binddn = '%s', ldapdata_bindpw = '%s', ldapdata_bindpw_clear = '%d' WHERE name = '%s'", $serialized_data, $serialized_ro_attrs, $serialized_rw_attrs, $form_values['ldapdata_binddn'], $form_values['ldapdata_bindpw'], $form_values['ldapdata_bindpw_clear'], $config_name);   
+
+  if ( !$form_state['values']['ldapdata_bindpw_clear'] && $form_state['values']['ldapdata_bindpw']) {
+    db_query("UPDATE {ldapauth} SET ldapdata_mappings = '%s', ldapdata_roattrs = '%s', ldapdata_rwattrs = '%s', ldapdata_binddn = '%s', ldapdata_bindpw = '%s', ldapdata_bindpw_clear = '%d' WHERE name = '%s'", $serialized_data, $serialized_ro_attrs, $serialized_rw_attrs, $form_state['values']['ldapdata_binddn'], $form_state['values']['ldapdata_bindpw'], $form_state['values']['ldapdata_bindpw_clear'], $config_name);
   }
   else {
     // set the clear password switch
-    db_query("UPDATE {ldapauth} SET ldapdata_mappings = '%s', ldapdata_roattrs = '%s', ldapdata_rwattrs = '%s', ldapdata_binddn = '%s', ldapdata_bindpw_clear = '%d' WHERE name = '%s'", $serialized_data, $serialized_ro_attrs, $serialized_rw_attrs, $form_values['ldapdata_binddn'], $form_values['ldapdata_bindpw_clear'], $config_name);   
+    db_query("UPDATE {ldapauth} SET ldapdata_mappings = '%s', ldapdata_roattrs = '%s', ldapdata_rwattrs = '%s', ldapdata_binddn = '%s', ldapdata_bindpw_clear = '%d' WHERE name = '%s'", $serialized_data, $serialized_ro_attrs, $serialized_rw_attrs, $form_state['values']['ldapdata_binddn'], $form_state['values']['ldapdata_bindpw_clear'], $config_name);
   }
-    
-  return 'admin/settings/ldapdata/edit/'.$config_name;
-}  
+
+  return 'admin/settings/ldapdata/edit/'. $config_name;
+}
 /**
  * Implements hook_categories();
  */
 function ldapdata_user_categories(&$user) {
   $ret = null;
 
-  // we do this as opposed to calling _ldapdata_ldap_info() to save on the multiple sql queries
-  $result = db_fetch_array(db_query("SELECT ldapdata_mappings, ldapdata_rwattrs FROM {ldapauth} WHERE name = '%s'", $user->ldap_config));
-  $mappings = unserialize($result['ldapdata_mappings']);
-  $mapping_type = $mappings['access'];
- 
-  $rwattrs = $result['ldapdata_rwattrs']; 
-  
-  if (($mapping_type == LDAP_MAP_ATTRIBUTES) && (!empty($rwattrs)) && arg(2) == 'edit') {
-    $ret = array(
-      array(
-        'name' => LDAP_CATEGORY_USER_DATA,
-        'title' => LDAP_USER_DATA_EDIT_TAB,
-        'weight' => 50
-        )
-      );
+  if (property_exists($user, 'ldap_config')) {
+    // we do this as opposed to calling _ldapdata_ldap_info() to save on the multiple sql queries
+    $result = db_fetch_array(db_query("SELECT ldapdata_mappings, ldapdata_rwattrs FROM {ldapauth} WHERE name = '%s'", $user->ldap_config));
+    $mappings = unserialize($result['ldapdata_mappings']);
+    $mapping_type = $mappings['access'];
+
+    $rwattrs = $result['ldapdata_rwattrs'];
+
+    if (($mapping_type == LDAP_MAP_ATTRIBUTES) && (!empty($rwattrs)) && arg(2) == 'edit') {
+      $ret = array(
+        array(
+          'name' => LDAP_CATEGORY_USER_DATA,
+          'title' => LDAP_USER_DATA_EDIT_TAB,
+          'weight' => 50
+          )
+        );
+    }
   }
-  return $ret;      
+  return $ret;
 }
 
 /**
  * Only used for editable LDAP attributes with no Drupal equivalents
  */
 function ldapdata_user_form(&$user, $category) {
-  global $ldap_attributes, $ldapdata_ldap;
+  global $_ldap_attributes, $_ldapdata_ldap;
   $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
   $attributes = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
 
-  if ((!$user->ldap_dn) || 
+  if ((!$user->ldap_dn) ||
       ($category != LDAP_CATEGORY_USER_DATA) ||
-      ($mapping_type != LDAP_MAP_ATTRIBUTES) || 
+      ($mapping_type != LDAP_MAP_ATTRIBUTES) ||
       (!$attributes)) {
-    return null;   
+    return null;
   }
-  
-  $bind_info = _ldapdata_edition($user);  
-  if (!$ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
-    watchdog('user', "User form: user $user->name's data could not be read in the LDAP directory", WATCHDOG_WARNING);
+
+  $bind_info = _ldapdata_edition($user);
+  if (!$_ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
+    watchdog('user', "User form: user @user data could not be read in the LDAP directory", array('@user' => $user->name), WATCHDOG_WARNING);
     return;
   }
-  
-  $entry = $ldapdata_ldap->retrieveAttributes($user->ldap_dn);
+
+  $entry = $_ldapdata_ldap->retrieveAttributes($user->ldap_dn);
 
   $output = '';
   $form['ldap_attributes'] = array(
@@ -450,72 +465,70 @@
 
   foreach ($attributes as $attribute) {
 
-    $attr_info = $ldap_attributes[$attribute];
+    $attr_info = $_ldap_attributes[$attribute];
     if ($attr_info) {
       array_shift($attr_info);
       $value = $entry[strtolower($attribute)][0];
       $form['ldap_attributes'][$attribute] = _ldapdata_attribute_form($attribute, $value, $attr_info);
     }
   }
-  
-  $ldapdata_ldap->disconnect();
-  
-  return $form; 
+
+  $_ldapdata_ldap->disconnect();
+
+  return $form;
 }
 
 function ldapdata_user_load(&$user) {
-  global $ldapdata_ldap;
-  
+  global $_ldapdata_ldap;
+
   // setup the global $ldapdata_ldap object
   if (!_ldapdata_ldap_init($user)) {
     return;
   }
-  
+
   $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
 
   // See http://drupal.org/node/91786 about user_node()
   // User can be edited by the user or by other authorized users.
-  
+
   if ((!$user->ldap_authentified) || ($mapping_type == LDAP_MAP_NOTHING)) {
     return;
   }
-  
-  $bind_info = _ldapdata_edition($user);  
-  if (!$ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
-    watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory", WATCHDOG_WARNING);
+
+  $bind_info = _ldapdata_edition($user);
+  if (!$_ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
+    watchdog('user', "User load: user @user data could not be read in the LDAP directory", array('@user' => $user->name), WATCHDOG_WARNING);
     return;
   }
 
-  $entry = $ldapdata_ldap->retrieveAttributes($user->ldap_dn);
-   if ($entry) {
+  $entry = $_ldapdata_ldap->retrieveAttributes($user->ldap_dn);
+  if ($entry) {
     $ldap_drupal_mappings = array_flip(_ldapdata_reverse_mappings($user->ldap_config));
     foreach ($ldap_drupal_mappings as $ldap_attr => $drupal_field) {
-       if (isset($user->$drupal_field) && $ldap_attr && $drupal_field != 'access') {
+      if (isset($user->$drupal_field) && $ldap_attr && $drupal_field != 'access') {
         if ($drupal_field != 'pass') {
           $user->$drupal_field = $entry[strtolower($ldap_attr)][0];
         }
       }
     }
-    ldapdata_user_profile_load($user);    
+    ldapdata_user_profile_load($user);
   }
 
-  $ldapdata_ldap->disconnect();
+  $_ldapdata_ldap->disconnect();
 
 }
 
-
-
 function ldapdata_user_profile_load(&$user) {
-  global $ldapdata_ldap;  
+  global $_ldapdata_ldap;
   $ldap_drupal_reverse_mappings = _ldapdata_reverse_mappings($user->ldap_config);
-  $ldap_drupal_mappings = array_flip($ldap_drupal_reverse_mappings);  
+  $ldap_drupal_mappings = array_flip($ldap_drupal_reverse_mappings);
 
   // Retrieve profile fields list
   $profile_fields = _ldapdata_retrieve_profile_fields();
 
   // compare against mapped fields list
   $writeout = array();
-  $entry = $ldapdata_ldap->retrieveAttributes($user->ldap_dn);
+  $entry = $_ldapdata_ldap->retrieveAttributes($user->ldap_dn);
   foreach ($profile_fields as $key => $field ) {
     if (in_array($key, $ldap_drupal_mappings)) {
       $writeout[$field] = $entry[strtolower($ldap_drupal_reverse_mappings[$key])][0];
@@ -538,32 +551,32 @@
 }
 
 function ldapdata_user_login(&$user) {
-  global $ldapdata_ldap;
-  
+  global $_ldapdata_ldap;
+
   // The whole point of implementing this hook is getting the
   // e-mail address written to the DB as soon as possible.
   // This is because it could not be written along with the rest
   // of the user info when the user was first created in
   // _ldapauth_ldap_login at the ldapauth module
- 
-  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');   
-  if ((!$user->ldap_authentified) || ($mapping_type = LDAP_MAP_NOTHING)) { 
+
+  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
+  if ((!$user->ldap_authentified) || ($mapping_type = LDAP_MAP_NOTHING)) {
     return;
-  } 
+  }
 
-  $bind_info = _ldapdata_edition($user);  
-  if (!$ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
-    watchdog('user', "User login: user $user->name's data could not be read in the LDAP directory", WATCHDOG_WARNING);
+  $bind_info = _ldapdata_edition($user);
+  if (!$_ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
+    watchdog('user', "User login: user @user data could not be read in the LDAP directory", array('@user' => $user->name), WATCHDOG_WARNING);
     return;
   }
 
-  $entry = $ldapdata_ldap->retrieveAttributes($user->ldap_dn);
-  $ldapdata_ldap->disconnect();
+  $entry = $_ldapdata_ldap->retrieveAttributes($user->ldap_dn);
+  $_ldapdata_ldap->disconnect();
 
   $d2l_mappings = _ldapdata_reverse_mappings($user->ldap_config);
 
   if (isset($d2l_mappings['mail'])) {
-    $mail_attr = strtolower($d2l_mappings['mail']);
+    $mail_attr = drupal_strtolower($d2l_mappings['mail']);
     $mail = $entry[$mail_attr][0];
     if ($mail != $user->mail) {
       user_save($user, array('mail' => $mail));
@@ -572,8 +585,8 @@
 }
 
 function ldapdata_user_update(&$edit, &$user, $category) {
-  global $ldapdata_ldap;
-  
+  global $_ldapdata_ldap;
+
   if (!$user->ldap_authentified) {
     return;
   }
@@ -586,7 +599,7 @@
   $writeout = array();
 
   // So, case 1
-  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');  
+  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
   if ($category == LDAP_CATEGORY_USER_DATA && $editables) {
     $writeout = array_merge($writeout, ldapdata_user_update_ldap_attributes($edit, $user));
   }
@@ -598,24 +611,23 @@
   // And now, case 4
   $writeout = array_merge($writeout, ldapdata_user_update_profile($edit, $user));
   if ($writeout) {
-    $bind_info = _ldapdata_edition($user);  
-    if (!$ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
-      watchdog('user', "User update: user $user->name's data could not be updated in the LDAP directory", WATCHDOG_NOTICE);
+    $bind_info = _ldapdata_edition($user);
+    if (!$_ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
+      watchdog('user', "User update: user @user data could not be updated in the LDAP directory", array('@user' => $user->name), WATCHDOG_NOTICE);
       return;
     }
-    
-    $ldapdata_ldap->writeAttributes($user->ldap_dn, $writeout);
-  }
 
-  $ldapdata_ldap->disconnect();
+    $_ldapdata_ldap->writeAttributes($user->ldap_dn, $writeout);
+    $_ldapdata_ldap->disconnect();
+  }
 }
 
 function ldapdata_user_update_ldap_attributes(&$edit, &$user) {
-  global $ldapdata_ldap;
+  global $_ldapdata_ldap;
   $writeout = array();
-  
-  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');  
-  
+
+  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
+
   foreach ($edit as $edit_attr => $edit_val) {
     // Preventing a POST data injection: we check allowance to write value.
     if (array_search($edit_attr, $editables) !== FALSE) {
@@ -629,13 +641,13 @@
 
 function ldapdata_user_update_drupal_account(&$edit, &$user) {
   $ldap_config_name = $user->ldap_config;
-  
+
   // we do this as opposed to calling _ldapdata_ldap_info() to save on the multiple sql queries
   $result = db_fetch_array(db_query("SELECT ldapdata_mappings, encrypted FROM {ldapauth} WHERE name = '%s'", $ldap_config_name));
   $mappings = unserialize($result['ldapdata_mappings']);
   $mapping_type = $mappings['access'];
   $encr = $result['encrypted'];
-  
+
   $account_updated_in_ldap = ($mapping_type == LDAP_MAP_ATTRIBUTES);
 
   $writeout = array();
@@ -647,7 +659,7 @@
       if ($ldap_attr) {
         if ($key == 'pass') {
           if ($value) {
-            $pw = $encr ? '{md5}' . base64_encode(pack('H*', md5($value))) : $value;
+            $pw = $encr ? '{md5}'. base64_encode(pack('H*', md5($value))) : $value;
             $writeout[$ldap_attr] = $pw;
           }
 
@@ -657,7 +669,8 @@
           if (variable_get('ldap_login_process', LDAP_FIRST_LDAP) == LDAP_FIRST_LDAP) {
             $edit['pass'] = null;
           }
-        } else {
+        }
+        else {
           $writeout[$ldap_attr] = $value;
         }
       }
@@ -667,7 +680,7 @@
 }
 
 function ldapdata_user_update_profile(&$edit, &$user) {
-  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');  
+  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
   if ($mapping_type != LDAP_MAP_ATTRIBUTES) {
     return array();
   }
@@ -688,33 +701,33 @@
 }
 
 function ldapdata_user_view(&$user) {
-  global $ldapdata_ldap, $ldap_attributes;
+  global $_ldapdata_ldap, $_ldap_attributes;
   if (!$user->ldap_authentified) {
     return;
   }
 
-  $bind_info = _ldapdata_edition($user);  
-  if (!$ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
-    watchdog('user', "User view: user $user->name's data could not be read in the LDAP directory", WATCHDOG_WARNING);
+  $bind_info = _ldapdata_edition($user);
+  if (!$_ldapdata_ldap->connect($bind_info[0], $bind_info[1])) {
+    watchdog('user', "User view: user @user data could not be read in the LDAP directory", array('@user' => $user->name), WATCHDOG_WARNING);
     return;
   }
 
-  $entry = $ldapdata_ldap->retrieveAttributes($user->ldap_dn);
+  $entry = $_ldapdata_ldap->retrieveAttributes($user->ldap_dn);
   $ret = array();
-  
+
   $allowed_attrs = _ldapdata_ldap_info($user, 'ldapdata_roattrs');
 
   if ($allowed_attrs) {
-    foreach($allowed_attrs as $attribute) {
+    foreach ($allowed_attrs as $attribute) {
       $item = array();
-      $item['title'] = $ldap_attributes[$attribute][2];
-      $item['value'] = theme('ldapdata_ldap_attribute', $entry[strtolower($attribute)][0], $ldap_attributes[$attribute][0]);
+      $item['title'] = $_ldap_attributes[$attribute][2];
+      $item['value'] = theme('ldapdata_ldap_attribute', $entry[strtolower($attribute)][0], $_ldap_attributes[$attribute][0]);
       $item['class'] = 'attribute';
       $ret[LDAP_SETTINGS_GROUP_STRING][] = $item;
     }
   }
 
-  $ldapdata_ldap->disconnect();
+  $_ldapdata_ldap->disconnect();
 
   return $ret;
 }
@@ -722,12 +735,12 @@
 
 /*********************************
  *    3. Auxiliary functions     *
- *********************************/
+ * ***************************** */
 
-function _ldapdata_attribute_form($attrname, $value, $info) {  
+function _ldapdata_attribute_form($attrname, $value, $info) {
   $type = array_shift($info);
 
-  switch($type) {
+  switch ($type) {
     case 'textfield':
       $form = array(
         '#type' => 'textfield',
@@ -768,12 +781,12 @@
 
 function _ldapdata_retrieve_standard_user_fields() {
 
-  // pablom - 
+  // pablom -
   //    This commented code below would return all possible values,
   //  but maybe that's not appropriate.
   //
   //   $result = db_query('SHOW COLUMNS FROM {users}');
-  // 
+  //
   //   $fields = array();
   //   while ($row = db_fetch_object($result)) {
   //     $fields[] = $row->Field;
@@ -785,15 +798,15 @@
   $fields['pass'] = 'pass';
   $fields['signature'] = 'signature';
 
-  return $fields;   
+  return $fields;
 }
 
 function _ldapdata_reverse_mappings($config) {
-  
+
   $ret = array();
   $result = db_fetch_array(db_query("SELECT ldapdata_mappings FROM {ldapauth} WHERE name = '%s'", $config));
   $mappings = unserialize($result['ldapdata_mappings']);
-  
+
   if (is_array($mappings)) {
     foreach ($mappings as $key => $value) {
       $drupal_key = preg_replace('/^ldap_amap-(.*)$/', '$1', $key);
@@ -807,14 +820,14 @@
 }
 
 
-function _ldapdata_edition(&$user) {  
+function _ldapdata_edition(&$user) {
   $ldap_config_name = $user->ldap_config;
-  $ret[] = array('','');
-  
+  $ret[] = array('', '');
+
   $result = db_fetch_array(db_query("SELECT ldapdata_binddn, ldapdata_bindpw FROM {ldapauth} WHERE name = '%s'", $ldap_config_name));
   $dn = $result['ldapdata_binddn'];
   $pass = $result['ldapdata_bindpw'];
-    
+
   if ($dn) {
     $ret[0] = $dn;
   }
@@ -826,24 +839,24 @@
     $ret[1] = $pass;
   }
   else {
-    $ret[1] = isset($_SESSION['ldap_login']['pass']) ? $_SESSION['ldap_login']['pass'] : '';  
+    $ret[1] = isset($_SESSION['ldap_login']['pass']) ? $_SESSION['ldap_login']['pass'] : '';
   }
-   
-  return $ret;  
-  
+
+  return $ret;
+
 }
 
 function _ldapdata_ldap_info(&$user, $req ) {
 
   $ldap_config_name = $user->ldap_config;
   $ret = null;
-  
+
   if (!$ldap_config_name) {
     $ret = null;
   }
 
-  $result = db_fetch_array(db_query("SELECT * FROM {ldapauth} WHERE name = '%s'", $ldap_config_name));  
- 
+  $result = db_fetch_array(db_query("SELECT * FROM {ldapauth} WHERE name = '%s'", $ldap_config_name));
+
   switch ($req) {
     case 'mapping_type':
       $mappings = unserialize($result['ldapdata_mappings']);
@@ -859,7 +872,7 @@
       $ret = $result['ldapdata_binddn'];
       break;
     case 'ldapdata_bindpw':
-      $ret = $result['ldapdata_bindpw']; 
+      $ret = $result['ldapdata_bindpw'];
       break;
     case 'encrypted':
       $ret = $result['encrypted'];
@@ -868,36 +881,37 @@
       $ret = null;
       break;
   }
-  
+
   return $ret;
 }
 
 function _ldapdata_ldap_init(&$user) {
-  global $ldapdata_ldap;
-  if ($row = db_fetch_object(db_query("SELECT * FROM {ldapauth} WHERE status = '%s' AND name = '%s'", 1, $user->ldap_config))) {
-    $ldapdata_ldap = new LDAPInterface();
-    $ldapdata_ldap->setOption('name', $row->name);
-    $ldapdata_ldap->setOption('server', $row->server);
-    $ldapdata_ldap->setOption('port', $row->port);
-    $ldapdata_ldap->setOption('tls', $row->tls);
-    $ldapdata_ldap->setOption('encrypted', $row->encrypted);
-    $ldapdata_ldap->setOption('basedn', $row->basedn);
-    $ldapdata_ldap->setOption('user_attr', $row->user_attr);
-    return $ldapdata_ldap;
+  global $_ldapdata_ldap;
+  if (property_exists($user, "ldap_config") && 
+        $row = db_fetch_object(db_query("SELECT * FROM {ldapauth} WHERE status = '%s' AND name = '%s'", 1, $user->ldap_config))) {
+    $_ldapdata_ldap = new LDAPInterface();
+    $_ldapdata_ldap->setOption('name', $row->name);
+    $_ldapdata_ldap->setOption('server', $row->server);
+    $_ldapdata_ldap->setOption('port', $row->port);
+    $_ldapdata_ldap->setOption('tls', $row->tls);
+    $_ldapdata_ldap->setOption('encrypted', $row->encrypted);
+    $_ldapdata_ldap->setOption('basedn', $row->basedn);
+    $_ldapdata_ldap->setOption('user_attr', $row->user_attr);
+    return $_ldapdata_ldap;
   }
   else {
     return;
-  }  
+  }
 }
 
 
 
 /*********************************
  *          4. Themes            *
- *********************************/
+ * ***************************** */
 
 function theme_ldapdata_ldap_attribute($value, $type) {
-  switch($type) {
+  switch ($type) {
     case 'url':
       $ret = strpos($value, '://') ? $value : "http://$value";
       $ret = "<a href=\"$ret\">$ret</a>";
@@ -911,5 +925,3 @@
   return $ret;
 }
 
-
-?>
\ No newline at end of file
diff --exclude=.svn -urN ldap_integration.orig/ldapgroups.info ldap_integration/ldapgroups.info
--- ldap_integration.orig/ldapgroups.info	2008-05-10 14:04:37.000000000 +0200
+++ ldap_integration/ldapgroups.info	2008-06-27 07:53:18.000000000 +0200
@@ -1,11 +1,12 @@
-; $Id: ldapgroups.info,v 1.1.2.3 2008/04/17 04:32:13 scafmac Exp $
+; $Id: ldapgroups.info,v 1.3 2007/02/11 01:28:03 kreaper Exp $
 name = ldapgroups
 description = "Integrated LDAP Groups with Drupal Roles"
 package = Administration
-dependencies = ldapauth
+dependencies[] = ldapauth
+core = 6.x
 
-; Information added by drupal.org packaging script on 2008-05-10
-version = "5.x-1.x-dev"
+; Information added by drupal.org packaging script on 2007-08-23
+version = "6.x-1.x-dev"
 project = "ldap_integration"
-datestamp = "1210421077"
+datestamp = "1187828108"
 
diff --exclude=.svn -urN ldap_integration.orig/ldapgroups.install ldap_integration/ldapgroups.install
--- ldap_integration.orig/ldapgroups.install	2007-05-20 03:28:25.000000000 +0200
+++ ldap_integration/ldapgroups.install	2008-06-27 08:43:39.000000000 +0200
@@ -1,48 +1,67 @@
 <?php
 // $Id: ldapgroups.install,v 1.1 2007/05/20 01:28:25 kreaper Exp $
 /**
+ * @file
+ * Installation code for ldapgroups
+ */
+
+/**
  * Implementation of hook_install().
  */
 function ldapgroups_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("ALTER TABLE {ldapauth} ADD (
-        ldap_groups_in_dn int NOT NULL default '0',
-        ldap_groups_in_dn_desc int NOT NULL default '0',
-        ldap_group_dn_attribute varchar(255) default '',
-        ldap_group_attr varchar(255) default '',
-        ldap_groups_in_attr int NOT NULL default '0',
-        ldap_groups_as_entries int NOT NULL default '0',
-        ldap_group_entries varchar(255) default '',
-        ldap_group_entries_attribute varchar(255) default ''
-      )");
-      break;
-    case 'pgsql':
-      db_query("ALTER TABLE {ldapauth} ADD (
-        ldap_groups_in_dn INTEGER NOT NULL DEFAULT 0,
-        ldap_groups_in_dn_desc INTEGER NOT NULL DEFAULT 0,
-        ldap_group_dn_attribute VARCHAR(255) DEFAULT '',
-        ldap_group_attr VARCHAR(255) DEFAULT '',
-        ldap_groups_in_attr INTEGER NOT NULL DEFAULT 0,
-        ldap_groups_as_entries INTEGER NOT NULL DEFAULT 0,
-        ldap_group_entries VARCHAR(255) DEFAULT '',
-        ldap_group_entries_attribute VARCHAR(255) DEFAULT ''
-      )"); 
-      break;
-  }
+  $ret = array();
+  db_add_field($ret, 'ldapauth', 'ldap_groups_in_dn', array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => '0'));
+  db_add_field($ret, 'ldapauth', 'ldap_groups_in_dn_desc', array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => '0'));
+  db_add_field($ret, 'ldapauth', 'ldap_group_dn_attribute', array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldap_group_attr', array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldap_groups_in_attr', array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => '0'));
+  db_add_field($ret, 'ldapauth', 'ldap_groups_as_entries', array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => '0'));
+  db_add_field($ret, 'ldapauth', 'ldap_group_entries', array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => ''));
+  db_add_field($ret, 'ldapauth', 'ldap_group_entries_attribute', array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => ''));
+
+  return $ret;
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function ldapgroups_uninstall() {
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_groups_in_dn");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_groups_in_dn_desc");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_group_dn_attribute");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_group_attr");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_groups_in_attr");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_groups_as_entries");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_group_entries");
-  db_query("ALTER TABLE {ldapauth} DROP COLUMN ldap_group_entries_attribute");
-}
\ No newline at end of file
+  $ret = array();
+  db_drop_field($ret, 'ldapauth', 'ldap_groups_in_dn');
+  db_drop_field($ret, 'ldapauth', 'ldap_groups_in_dn_desc');
+  db_drop_field($ret, 'ldapauth', 'ldap_group_dn_attribute');
+  db_drop_field($ret, 'ldapauth', 'ldap_group_attr');
+  db_drop_field($ret, 'ldapauth', 'ldap_groups_in_attr');
+  db_drop_field($ret, 'ldapauth', 'ldap_groups_as_entries');
+  db_drop_field($ret, 'ldapauth', 'ldap_group_entries');
+  db_drop_field($ret, 'ldapauth', 'ldap_group_entries_attribute');
+  return $ret;
+}
diff --exclude=.svn -urN ldap_integration.orig/ldapgroups.module ldap_integration/ldapgroups.module
--- ldap_integration.orig/ldapgroups.module	2008-05-10 04:19:53.000000000 +0200
+++ ldap_integration/ldapgroups.module	2008-07-10 10:55:30.000000000 +0200
@@ -1,5 +1,10 @@
 <?php
-// $Id: ldapgroups.module,v 1.1.4.6.2.6 2008/05/10 02:19:53 scafmac Exp $
+// $Id: ldapgroups.module,v 1.24 2007/07/22 20:04:25 kreaper Exp $
+
+/**
+ * @file
+ * Ldapgroups module
+ */
 
 include_once('ldap_integration/ldapgroups.conf.php');
 include_once('ldap_integration/libdebug.php');
@@ -16,20 +21,19 @@
 define('LDAP_DEFAULT_GROUP_ENTRIES', 'cn=Group,dc=example,dc=com');
 define('LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE', 'memberUid');
 
-$GLOBALS['ldapgroups_ldap'] = new LDAPInterface();
+$GLOBALS['_ldapgroups_ldap'] = new LDAPInterface();
 
 /*********************************
  *       1. Drupal hooks         *
- *********************************/
+ * ***************************** */
 
- /** 
-  * Implementation of hook_help()
-  */
-
-function ldapgroups_help($section) {
+/**
+ * Implementation of hook_help().
+ */
+function ldapgroups_help($path, $arg) {
   $output = '';
 
-  switch ($section) {
+  switch ($path) {
     case 'admin/modules#ldapgroups':
     $output = t('LDAP Groups');
     case 'admin/help#ldapgroups':
@@ -47,49 +51,41 @@
   return $output;
 }
 
-/** 
- * Implementation of hook_menu() 
+/**
+ * Implementation of hook_menu().
  */
-
-function ldapgroups_menu($may_cache) {  
+function ldapgroups_menu() {
   $items = array();
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/ldapgroups',
-      'title' => t('LDAP Groups'),
-      'description' => t('Configure LDAP Groups Settings'), 
-      'callback' => 'ldapgroups_admin_list',
-      'access' => user_access('administer ldap modules'),
-      );
-    $items[] = array( 
-      'path' => 'admin/settings/ldapgroups/edit',
-      'title' => t('LDAP Groups'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapgroups_admin_edit'),
+  $items['admin/settings/ldapgroups'] = array(
+      'title' => 'LDAP Groups',
+      'description' => 'Configure LDAP Groups Settings',
+      'page callback' => 'ldapgroups_admin_list',
+      'access arguments' => array('administer ldap modules'),
+      );
+  $items['admin/settings/ldapgroups/edit'] = array(
+      'title' => 'LDAP Groups',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('ldapgroups_admin_edit', 3),
       'type' => MENU_CALLBACK,
       'weight' => 1,
-      'access' => user_access('administer ldap modules'),
+      'access arguments' => array('administer ldap modules'),
       );
-    $items[] = array( 
-      'path' => 'admin/settings/ldapgroups/reset', 
-      'title' => t('LDAP Groups'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('ldapgroups_admin_edit'),
+  $items['admin/settings/ldapgroups/reset'] = array(
+      'title' => 'LDAP Groups',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('ldapgroups_admin_edit', 3),
       'type' => MENU_CALLBACK,
       'weight' => 1,
-      'access' => user_access('administer ldap modules'),
+      'access arguments' => array('administer ldap modules'),
       );
-  }
   return $items;
 }
 
-// ldapgroups admin pages 
-
 function ldapgroups_admin_list() {
   $result = db_query("SELECT sid, name FROM {ldapauth} WHERE status = '%s' ORDER BY sid", 1);
   $rows = array();
   while ($row = db_fetch_object($result)) {
-    $rows[] = array($row->name, l(t('edit'), 'admin/settings/ldapgroups/edit/'.$row->name), l(t('reset'), 'admin/settings/ldapgroups/reset/'.$row->name));
+    $rows[] = array($row->name, l(t('edit'), 'admin/settings/ldapgroups/edit/'. $row->name), l(t('reset'), 'admin/settings/ldapgroups/reset/'. $row->name));
   }
 
   $header = array(
@@ -98,12 +94,12 @@
       'data' => t('Operations'),
       'colspan' => 2
     )
-  );  
+  );
   return theme('table', $header, $rows);
 }
 
-function ldapgroups_admin_edit($ldap_name) {
-  if ((arg(3) == 'reset') && ($ldap_name != NULL)) {
+function ldapgroups_admin_edit($state, $action, $ldap_name) {
+  if (($action == 'reset') && ($ldap_name != NULL)) {
     $form['reset_ldap'] = array(
       '#type' => 'value',
       '#value' => $ldap_name,
@@ -111,80 +107,80 @@
     return confirm_form(
       $form,
       t('Are you sure you want to reset the groups mapping to defaults ?'),
-      'admin/settings/ldapgroups', 
-      t('<em>This action cannot be undone.</p>'), 
-      t('Reset'), 
+      'admin/settings/ldapgroups',
+      t('<em>This action cannot be undone.</p>'),
+      t('Reset'),
       t('Cancel')
     );
   }
-  elseif ((arg(3) == 'edit') && ($ldap_name != NULL)) {
+  elseif (($action == 'edit') && ($ldap_name != NULL)) {
     $edit = db_fetch_array(db_query("SELECT ldap_groups_in_dn, ldap_groups_in_dn_desc, ldap_group_dn_attribute, ldap_groups_in_attr, ldap_group_attr, ldap_groups_as_entries, ldap_group_entries, ldap_group_entries_attribute FROM {ldapauth} WHERE name = '%s'", $ldap_name));
-    $form['server-settings']['ldap_groups_in_dn'] = array( 
-      '#type' => 'checkbox', 
-      '#title' => t('Group is specified in user\'s DN'), 
+    $form['server-settings']['ldap_groups_in_dn'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Group is specified in user\'s DN'),
       '#default_value' => $edit['ldap_groups_in_dn'],
-      '#prefix' => '<fieldset><legend>', 
+      '#prefix' => '<fieldset><legend>',
       '#suffix' => '</legend>'
       );
 
-    $form['server-settings']['ldap_groups_in_dn_desc'] = array( 
+    $form['server-settings']['ldap_groups_in_dn_desc'] = array(
       '#value' => '<p>Check this option if your users\' DNs look like <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">cn=jdoe,<strong>ou=Group1</strong>,cn=example,cn=com</em> and <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">Group1</em> turns out to be the group you want.</p>'
       );
 
-    $form['server-settings']['ldap_group_dn_attribute'] = array( 
-      '#type' => 'textfield', 
-      '#title' => t('Attribute of the DN which contains the group name'), 
+    $form['server-settings']['ldap_group_dn_attribute'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Attribute of the DN which contains the group name'),
       '#default_value' => $edit['ldap_group_dn_attribute'],
-      '#size' => 50, 
-      '#maxlength' => 255, 
-      '#description' => t('The name of the attribute which contains the group name. In the example above, it would be <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">ou</em>, as the DN contains the string <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">ou=Group1</em> and <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">Group1</em> happens to be the desired group name.'), 
+      '#size' => 50,
+      '#maxlength' => 255,
+      '#description' => t('The name of the attribute which contains the group name. In the example above, it would be <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">ou</em>, as the DN contains the string <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">ou=Group1</em> and <em style="font-style: normal; padding: 1px 3px; border: 1px solid #8888CC; background-color: #DDDDFF">Group1</em> happens to be the desired group name.'),
       '#suffix' => '</fieldset>'
       );
 
-    $form['server-settings']['ldap_groups_in_attr'] = array( 
-      '#type' => 'checkbox', 
-      '#title' => t('Groups are specified by LDAP attributes'), 
+    $form['server-settings']['ldap_groups_in_attr'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Groups are specified by LDAP attributes'),
       '#default_value' => $edit['ldap_groups_in_attr'],
-      '#prefix' => '<fieldset><legend>', 
+      '#prefix' => '<fieldset><legend>',
       '#suffix' => '</legend>'
       );
 
-    $form['server-settings']['ldap_group_attr'] = array( 
-      '#type' => 'textarea', 
-      '#title' => t('Attribute names (one per line)'), 
+    $form['server-settings']['ldap_group_attr'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Attribute names (one per line)'),
       '#default_value' => $edit['ldap_group_attr'],
-      '#cols' => 50, 
-      '#rows' => 6, 
-      '#description' => t('If the groups are stored in the user entries, along with the rest of their data, then enter here a list of attributes which may contain them.'), 
+      '#cols' => 50,
+      '#rows' => 6,
+      '#description' => t('If the groups are stored in the user entries, along with the rest of their data, then enter here a list of attributes which may contain them.'),
       '#suffix' => '</fieldset>'
       );
 
-    $form['server-settings']['ldap_groups_as_entries'] = array( 
-      '#type' => 'checkbox', 
-      '#title' => t('Groups exist as LDAP entries where a multivalued attribute contains the members\' CNs'), 
+    $form['server-settings']['ldap_groups_as_entries'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Groups exist as LDAP entries where a multivalued attribute contains the members\' CNs'),
       '#default_value' => $edit['ldap_groups_as_entries'],
-      '#prefix' => '<fieldset><legend>', 
+      '#prefix' => '<fieldset><legend>',
       '#suffix' => '</legend>'
       );
 
-    $form['server-settings']['ldap_group_entries'] = array( 
-      '#type' => 'textarea', 
-      '#title' => t('Nodes containing groups (one per line)'), 
+    $form['server-settings']['ldap_group_entries'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Nodes containing groups (one per line)'),
       '#default_value' => $edit['ldap_group_entries'],
-      '#cols' => 50, 
-      '#rows' => 6, 
+      '#cols' => 50,
+      '#rows' => 6,
       '#description' => t('Enter here a list of nodes from where groups should be searched for. The module will look them up recursively from the given nodes.'),
       );
 
-    $form['server-settings']['ldap_group_entries_attribute'] = array( 
-      '#type' => 'textfield', 
-      '#title' => t('Attribute holding group members'), 
+    $form['server-settings']['ldap_group_entries_attribute'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Attribute holding group members'),
       '#default_value' => $edit['ldap_group_entries_attribute'],
-      '#size' => 50, 
-      '#maxlength' => 255, 
+      '#size' => 50,
+      '#maxlength' => 255,
       '#description' => t('Name of the multivalued attribute which holds the CNs of group members, for example: !attr', array('!attr' => theme('placeholder', LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE))),
       );
-            
+
     $form['config_name'] = array(
       '#type' => 'hidden',
       '#value' => $ldap_name,
@@ -198,42 +194,40 @@
   return $form;
 }
 
-function ldapgroups_admin_edit_submit($form_id, $form_values) {
-  if ($form_values['confirm']) {
+function ldapgroups_admin_edit_submit($form, &$form_state) {
+  if ($form_state['values']['confirm']) {
     // reset the ldapgroups config to default values - in effect, deactivate this config
-    db_query("UPDATE {ldapauth} SET ldap_groups_in_dn = '%d', ldap_groups_in_dn_desc = '%d', ldap_group_dn_attribute = '%s', ldap_groups_in_attr = '%d', ldap_group_attr = '%s', ldap_groups_as_entries = '%d', ldap_group_entries = '%s', ldap_group_entries_attribute = '%s'  WHERE name = '%s'", '0', '0', '', '0', '', '0', '', '', $form_values['reset_ldap']);
-    watchdog('ldap', t('ldapgroups: ldap config %config updated.' ,array('%config' => $form_values['reset_ldap'])));
+    db_query("UPDATE {ldapauth} SET ldap_groups_in_dn = '%d', ldap_groups_in_dn_desc = '%d', ldap_group_dn_attribute = '%s', ldap_groups_in_attr = '%d', ldap_group_attr = '%s', ldap_groups_as_entries = '%d', ldap_group_entries = '%s', ldap_group_entries_attribute = '%s'  WHERE name = '%s'", '0', '0', '', '0', '', '0', '', '', $form_state['values']['reset_ldap']);
+    watchdog('ldap', 'ldapgroups: ldap config %config updated.', array('%config' => $form_state['values']['reset_ldap']));
   }
   else {
     // update the ldapgroups configuration
-    db_query("UPDATE {ldapauth} SET ldap_groups_in_dn = '%d', ldap_groups_in_dn_desc = '%d', ldap_group_dn_attribute = '%s', ldap_groups_in_attr = '%d', ldap_group_attr = '%s', ldap_groups_as_entries = '%d', ldap_group_entries = '%s', ldap_group_entries_attribute = '%s'  WHERE name = '%s'", $form_values['ldap_groups_in_dn'], $form_values['ldap_groups_in_dn_desc'], $form_values['ldap_group_dn_attribute'], $form_values['ldap_groups_in_attr'], $form_values['ldap_group_attr'], $form_values['ldap_groups_as_entries'], $form_values['ldap_group_entries'], $form_values['ldap_group_entries_attribute'], $form_values['config_name']);
-    watchdog('ldap', t('ldapgroups: ldap config %config updated.' ,array('%config' => $form_values['config_name'])));
+    db_query("UPDATE {ldapauth} SET ldap_groups_in_dn = '%d', ldap_groups_in_dn_desc = '%d', ldap_group_dn_attribute = '%s', ldap_groups_in_attr = '%d', ldap_group_attr = '%s', ldap_groups_as_entries = '%d', ldap_group_entries = '%s', ldap_group_entries_attribute = '%s'  WHERE name = '%s'", $form_state['values']['ldap_groups_in_dn'], $form_state['values']['ldap_groups_in_dn_desc'], $form_state['values']['ldap_group_dn_attribute'], $form_state['values']['ldap_groups_in_attr'], $form_state['values']['ldap_group_attr'], $form_state['values']['ldap_groups_as_entries'], $form_state['values']['ldap_group_entries'], $form_state['values']['ldap_group_entries_attribute'], $form_state['values']['config_name']);
+    watchdog('ldap', 'ldapgroups: ldap config %config updated.', array('%config' => $form_state['values']['config_name']));
   }
-  return 'admin/settings/ldapgroups';
 
+  $form_state['redirect'] = 'admin/settings/ldapgroups';
 }
 
-/** 
- * Implementation of hook_user()
- */
 function ldapgroups_user($op, &$edit, &$user, $category = NULL) {
-  switch($op) {
+  switch ($op) {
     case 'login':
       ldapgroups_user_login($user);
       break;
   }
 }
 
-
 /*********************************
  *     2. Delegate functions     *
- *********************************/
+ * ***************************** */
 
 function ldapgroups_user_login(&$user) {
+  global $_ldap_group_role_mappings;
+
   if (!$user->ldap_authentified) {
     return true;
   }
-  
+
   // setup the global $ldapdata_ldap object
   if (!_ldapgroups_ldap_init($user)) {
     return;
@@ -242,10 +236,8 @@
   // First, we take every mapped role from the user, later below
   // we'll grant back those deserved.
 
-  //dsm($user);
   $user->ldap_drupal_roles = isset($user->ldap_drupal_roles) ? $user->ldap_drupal_roles : array();
   foreach ($user->ldap_drupal_roles as $role) {
-    //dsm($role);
     _ldapgroups_deny_role($user, $role);
   }
 
@@ -262,7 +254,7 @@
   }
   else {
     // grant all the roles
-    $roles = $groups;    
+    $roles = $groups;
   }
 
   // At this point, the roles are in the full DN format
@@ -272,7 +264,15 @@
   //need to check for empty roles
   if ($roles) {
     foreach ($roles as $role) {
-      $friendly_role = _ldapgroups_translate_role($role);
+      if ($friendly_role = $_ldap_group_role_mappings[$role]) {
+        // Just that
+      }
+      else if (preg_match('/^[^=]*=([^,]*),.*$/', $role, $matches)) {
+        $friendly_role = $matches[1];
+      }
+      else {
+        $friendly_role = $role;
+      }
       _ldapgroups_create_role($friendly_role);
       _ldapgroups_grant_role($user, $friendly_role);
     }
@@ -286,34 +286,15 @@
 
 /*********************************
  *    3. Auxiliary functions     *
- *********************************/
-
-/**
- * Depending on ldap schema, converts ldap group to drupal role
- */
-function _ldapgroups_translate_role($ldap_role) {
-  global $ldap_group_role_mappings;
-
-  if ($friendly_role = $ldap_group_role_mappings[$ldap_role]) {
-      // Just that
-  }
-  else if (preg_match('/^[^=]*=([^,]*),.*$/', $ldap_role, $matches)) {
-    $friendly_role = $matches[1];
-  }
-  else {
-    $friendly_role = $ldap_role;
-  }
-
-  return $friendly_role;
-}
+ * ***************************** */
 
 function _ldapgroups_detect_groups($user) {
-  global $ldapgroups_ldap;
+  global $_ldapgroups_ldap;
 
   // Nothing to do if the user is not LDAP authentified
   // or there are no groups configured
 
-  $row = db_fetch_object(db_query("SELECT ldap_groups_in_dn, ldap_groups_in_attr, ldap_groups_as_entries, ldap_group_dn_attribute, ldap_group_attr, ldap_group_entries, ldap_group_entries_attribute FROM {ldapauth} WHERE name = '%s'", $ldapgroups_ldap->getOption('name')));
+  $row = db_fetch_object(db_query("SELECT ldap_groups_in_dn, ldap_groups_in_attr, ldap_groups_as_entries, ldap_group_dn_attribute, ldap_group_attr, ldap_group_entries, ldap_group_entries_attribute FROM {ldapauth} WHERE name = '%s'", $_ldapgroups_ldap->getOption('name')));
   $groups_in_dn = $row->ldap_groups_in_dn;
   $groups_in_attr = $row->ldap_groups_in_attr;
   $groups_as_entries = $row->ldap_groups_as_entries;
@@ -328,20 +309,20 @@
 
   // first try to connect with the stored user's DN and password
   // If unsuccessful, connect with the BINDDN and BINDPW stored in the database for this config
-  
+
   $dn = isset($_SESSION['ldap_login']['dn']) ? $_SESSION['ldap_login']['dn'] : '';
   $pass = isset($_SESSION['ldap_login']['pass']) ? $_SESSION['ldap_login']['pass'] : '';
 
-  if (!$ldapgroups_ldap->connect($dn, $pass)) {
-    $row2 = db_fetch_object(db_query("SELECT binddn, bindpw FROM {ldapauth} WHERE name = '%s'", $ldapgroups_ldap->getOption('name')));
+  if (!$_ldapgroups_ldap->connect($dn, $pass)) {
+    $row2 = db_fetch_object(db_query("SELECT binddn, bindpw FROM {ldapauth} WHERE name = '%s'", $_ldapgroups_ldap->getOption('name')));
     $dn = $row2->binddn;
     $pass = $row2->bindpw;
-    if (!$ldapgroups_ldap->connect($dn,$pass)) {
-      watchdog('user', "User login: user $user->name's data could not be read in the LDAP directory", WATCHDOG_WARNING);
+    if (!$_ldapgroups_ldap->connect($dn, $pass)) {
+      watchdog('user', "User login: user @user data could not be read in the LDAP directory", array('@user' => $user->name), WATCHDOG_WARNING);
       return false;
-    }      
+    }
   }
-  
+
   // Strategy 1: group extracted from user's DN
   $dn_groups = array();
   if ($groups_in_dn && $dn_group_attr = $group_dn_attribute) {
@@ -349,7 +330,7 @@
 
     foreach ($pairs as $p) {
       $pair = explode('=', $p);
-      if (strtoupper(trim($pair[0])) == strtoupper($dn_group_attr)) {
+      if (trim($pair[0]) == $dn_group_attr) {
         $dn_groups[] = trim($pair[1]);
       }
     }
@@ -360,11 +341,11 @@
   if ($groups_in_attr && $attributes = $group_attr) {
     $attributes_array = explode("\r\n", $attributes);
     foreach ($attributes_array as $attribute) {
-      $tmp = $ldapgroups_ldap->retrieveMultiAttribute($user->ldap_dn, $attribute);
+      $tmp = $_ldapgroups_ldap->retrieveMultiAttribute($user->ldap_dn, $attribute);
       $attrib_groups = array_merge($attrib_groups, $tmp);
     }
   }
-  
+
 
   // Strategy 3: groups as entries
   $entries_groups = array();
@@ -372,9 +353,9 @@
     $branches_array = explode("\r\n", $branches);
     $group_attr = ($row->ldap_group_entries_attribute ? $row->ldap_group_entries_attribute : LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE);
     foreach ($branches_array as $branch) {
-      $entries = $ldapgroups_ldap->search($branch,  "$group_attr=$user->ldap_dn", array($group_attr));
+      $entries = $_ldapgroups_ldap->search($branch,  "$group_attr=$user->ldap_dn", array($group_attr));
       if ($entries['count'] == 0) {
-        $entries = $ldapgroups_ldap->search($branch,  "$group_attr=$user->name", array($group_attr));
+        $entries = $_ldapgroups_ldap->search($branch,  "$group_attr=$user->name", array($group_attr));
       }
       foreach ($entries as $entry) {
         if (isset($entry['dn'])) {
@@ -384,64 +365,62 @@
     }
   }
 
-  $ldapgroups_ldap->disconnect();
+  $_ldapgroups_ldap->disconnect();
   return array_merge($dn_groups, $attrib_groups, $entries_groups);
 }
 
 function _ldapgroups_grant_role($user, $rolename) {
-  $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
-  $role_exists = db_num_rows($result);
+  $result = db_query("SELECT * FROM {role} WHERE name = '%s'", $rolename);
 
-  if ($role_exists) {
+  if ($result) {
     $role = db_fetch_object($result);
-    $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
-    $role_already_given = db_num_rows($result);
-    if (!$role_already_given) {
-     db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, $role->rid);
+
+    if ($role) {
+      $role_already_given = db_result(db_query("SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d", $user->uid, $role->rid));
+      if (!$role_already_given) {
+        db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, $role->rid);
+      }
     }
   }
 }
 
 function _ldapgroups_deny_role($user, $rolename) {
-  $drupal_role = _ldapgroups_translate_role($rolename);
-  $result = db_query("SELECT * FROM {role} WHERE name = '$drupal_role'");
-  $role_exists = db_num_rows($result);
+  $result = db_query("SELECT * FROM {role} WHERE name = '%s'", $rolename);
 
-  if ($role_exists) {
+  if ($result) {
     $role = db_fetch_object($result);
-    $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
-    $role_present = db_num_rows($result);
-    if ($role_present) {
-      db_query("DELETE FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+    if ($role) {
+      $role_present = db_result(db_query("SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d", $user->uid, $role->rid));
+      if ($role_present) {
+        db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $user->uid, $role->rid);
+      }
     }
   }
 }
 
 function _ldapgroups_create_role($rolename) {
-  $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
-  $role_exists = db_num_rows($result);
+  $role_exists = db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s'", $rolename));
 
   if (!$role_exists) {
-     db_query("INSERT INTO {role} (name) VALUES ('%s')", $rolename);
+    db_query("INSERT INTO {role} (name) VALUES ('%s')", $rolename);
   }
 }
 
 function _ldapgroups_ldap_init(&$user) {
-  global $ldapgroups_ldap;
+  global $_ldapgroups_ldap;
   if ($row = db_fetch_object(db_query("SELECT * FROM {ldapauth} WHERE status = '%s' AND name = '%s'", 1, $user->ldap_config))) {
-    $ldapgroups_ldap = new LDAPInterface();
-    $ldapgroups_ldap->setOption('name', $row->name);
-    $ldapgroups_ldap->setOption('server', $row->server);
-    $ldapgroups_ldap->setOption('port', $row->port);
-    $ldapgroups_ldap->setOption('tls', $row->tls);
-    $ldapgroups_ldap->setOption('encrypted', $row->encrypted);
-    $ldapgroups_ldap->setOption('basedn', $row->basedn);
-    $ldapgroups_ldap->setOption('user_attr', $row->user_attr);
-    return $ldapgroups_ldap;
+    $_ldapgroups_ldap = new LDAPInterface();
+    $_ldapgroups_ldap->setOption('name', $row->name);
+    $_ldapgroups_ldap->setOption('server', $row->server);
+    $_ldapgroups_ldap->setOption('port', $row->port);
+    $_ldapgroups_ldap->setOption('tls', $row->tls);
+    $_ldapgroups_ldap->setOption('encrypted', $row->encrypted);
+    $_ldapgroups_ldap->setOption('basedn', $row->basedn);
+    $_ldapgroups_ldap->setOption('user_attr', $row->user_attr);
+    return $_ldapgroups_ldap;
   }
   else {
     return;
-  }  
+  }
 }
 
-?>
diff --exclude=.svn -urN ldap_integration.orig/ldap_integration/ldapauth.conf.php ldap_integration/ldap_integration/ldapauth.conf.php
--- ldap_integration.orig/ldap_integration/ldapauth.conf.php	2008-04-17 06:32:13.000000000 +0200
+++ ldap_integration/ldap_integration/ldapauth.conf.php	2008-06-27 08:45:16.000000000 +0200
@@ -1,6 +1,10 @@
 <?php
-// $Id: ldapauth.conf.php,v 1.1.4.3.2.3 2008/04/17 04:32:13 scafmac Exp $
+// $Id: ldapauth.conf.php,v 1.2 2007/01/28 20:38:03 kreaper Exp $
 
+/**
+ * @file
+ * Configuration for ldapauth module
+ */
 
 // Transform the login name to something understood by the server
 function ldapauth_transform_login_name($login_name) {
@@ -20,4 +24,3 @@
   return true;
 }
 
-?>
\ No newline at end of file
diff --exclude=.svn -urN ldap_integration.orig/ldap_integration/ldapdata.conf.php ldap_integration/ldap_integration/ldapdata.conf.php
--- ldap_integration.orig/ldap_integration/ldapdata.conf.php	2008-04-17 06:32:13.000000000 +0200
+++ ldap_integration/ldap_integration/ldapdata.conf.php	2008-07-02 19:11:09.000000000 +0200
@@ -1,5 +1,10 @@
 <?php
-// $Id: ldapdata.conf.php,v 1.1.4.3.2.3 2008/04/17 04:32:13 scafmac Exp $
+// $Id: ldapdata.conf.php,v 1.5 2007/03/20 00:20:52 scafmac Exp $
+
+/**
+ * @file
+ * Configuration for ldapdata module
+ */
 
 // WARNING: if you change this, then you WANT to set attribute mapping
 // to read-only. Otherwise, odd stuff WILL happen. Seriously!!!!!!
@@ -24,12 +29,11 @@
 //
 // The 1st right hand elements in the array determine how the attribute and
 // its value are displayed. The first element may be 'text' or 'url'.
-$GLOBALS['ldap_attributes'] = array(
-  'givenName'			=> array('text', 'textfield', t('First Name'), 64, 64),
-  'sn'				=> array('text', 'textfield', t('Last Name'), 64, 64), //aka Surname
-  'cn'            => array('text', 'textfield', t('Common Name'), 64, 64),
+$GLOBALS['_ldap_attributes'] = array(
+  'givenName'   => array('text', 'textfield', t('First Name'), 64, 64),
+  'sn'          => array('text', 'textfield', t('Last Name'), 64, 64), //aka Surname
+  'cn'          => array('text', 'textfield', t('Common Name'), 64, 64),
 //  'homePage'      => array('url', 'textfield', t('Other web pages'), 64, 64),
-  'mail'          => array('text', 'textfield', t('Email'), 64, 64)
+  'mail'        => array('text', 'textfield', t('Email'), 64, 64)
 );
 
-?>
diff --exclude=.svn -urN ldap_integration.orig/ldap_integration/ldapgroups.conf.php ldap_integration/ldap_integration/ldapgroups.conf.php
--- ldap_integration.orig/ldap_integration/ldapgroups.conf.php	2008-04-17 06:32:13.000000000 +0200
+++ ldap_integration/ldap_integration/ldapgroups.conf.php	2008-06-27 08:44:28.000000000 +0200
@@ -1,5 +1,10 @@
 <?php
-// $Id: ldapgroups.conf.php,v 1.1.4.2.2.4 2008/04/17 04:32:13 scafmac Exp $
+// $Id: ldapgroups.conf.php,v 1.9 2007/07/22 20:04:25 kreaper Exp $
+//
+/**
+ * @file
+ * Configuration for ldapgroups module
+ */
 
 // Interesting constants that admins would want to mess with
 
@@ -13,24 +18,24 @@
 
 $GLOBALS['ldap_group_role_mappings'] = array(
   // LDAP group => Drupal role
-  
+
   // make sure the last group->role mapping does NOT have a trailing comma (,)
   //'cn=admin,ou=Group,dc=example,dc=com' => 'IT'
-  
+
 );
 
-// Note: Uncommenting this function will limit the groups -> roles conversion to ONLY those groups that are 
-// specified in the function. 
+// Note: Uncommenting this function will limit the groups -> roles conversion to ONLY those groups that are
+// specified in the function.
 /*
-function ldapgroups_roles_filter($groups) { 
-  global $ldap_group_role_mappings; 
-  $roles = array(); 
-  // this should take the roles array, pass it thru the filters and send a NEW set of roles back the filter 
-  foreach ( $groups as $group ) { 
+function ldapgroups_roles_filter($groups) {
+  global $ldap_group_role_mappings;
+  $roles = array();
+  // this should take the roles array, pass it thru the filters and send a NEW set of roles back the filter
+  foreach ( $groups as $group ) {
     foreach ($ldap_group_role_mappings as $approved_group => $approved_role) {
        // must strip spaces ?
        $group_stripped = preg_replace('/\s+/', '', $group);
-       $approved_group_stripped = preg_replace('/\s+/', '', $approved_group);       
+       $approved_group_stripped = preg_replace('/\s+/', '', $approved_group);
       if (strcasecmp($approved_group_stripped, $group_stripped) == 0) {
         // this role is specified -- grant
 	   $roles[] = $approved_role;
@@ -39,6 +44,5 @@
   }
   return $roles;
 }
-*/
+ */
 
-?>
diff --exclude=.svn -urN ldap_integration.orig/ldap_integration/LDAPInterface.php ldap_integration/ldap_integration/LDAPInterface.php
--- ldap_integration.orig/ldap_integration/LDAPInterface.php	2008-04-17 06:32:13.000000000 +0200
+++ ldap_integration/ldap_integration/LDAPInterface.php	2008-07-10 10:49:48.000000000 +0200
@@ -1,5 +1,10 @@
 <?php
-// $Id: LDAPInterface.php,v 1.2.2.6.2.3 2008/04/17 04:32:13 scafmac Exp $
+// $Id: LDAPInterface.php,v 1.10 2007/08/23 00:05:42 kreaper Exp $
+
+/**
+ * @file
+ * Ldap interface class
+ */
 
 class LDAPInterface {
 
@@ -14,10 +19,10 @@
   }
 
   var $connection;
-	var $server;
-	var $port;
-	var $tls;
-	var $attr_filter;
+  var $server;
+  var $port;
+  var $tls;
+  var $attr_filter;
 
   // This should be static, but that's not supported in PHP4
   function __empty_attr_filter($x) {
@@ -25,75 +30,75 @@
   }
 
   function setOption($option, $value) {
-		switch($option) {
-			case 'name':
-				$this->name = $value;
-				break;
-			case 'server':
-				$this->server = $value;
-				break;
-			case 'port':
-				$this->port = $value;
-				break;
-			case 'tls':
-				$this->tls = $value;
-				break;
-			case 'encrypted':
-				$this->encrypted = $value;
-				break;
-			case 'user_attr':
-				$this->user_attr = $value;
-				break;
-			case 'attr_filter':
-				$this->attr_filter = $value;
-				break;
-			case 'basedn':
-				$this->basedn = $value;
-				break;
-			case 'mail_attr':
-			  $this->mail_attr = $value;
-			  break;
-		}
+    switch ($option) {
+      case 'name':
+        $this->name = $value;
+        break;
+      case 'server':
+        $this->server = $value;
+        break;
+      case 'port':
+        $this->port = $value;
+        break;
+      case 'tls':
+        $this->tls = $value;
+        break;
+      case 'encrypted':
+        $this->encrypted = $value;
+        break;
+      case 'user_attr':
+        $this->user_attr = $value;
+        break;
+      case 'attr_filter':
+        $this->attr_filter = $value;
+        break;
+      case 'basedn':
+        $this->basedn = $value;
+        break;
+      case 'mail_attr':
+        $this->mail_attr = $value;
+        break;
+    }
   }
 
   function getOption($option) {
-		$ret = '';
-		switch($option) {
-			case 'version':
-				$ret = -1;
-				ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $ret);
-				break;
-			case 'name':
-				$ret = $this->name;
-				break;
-			case 'port':
-				$ret = $this->port;
-				break;
-			case 'tls':
-				$ret = $this->tls;
-				break;
-			case 'encrypted':
-				$ret = $this->encrypted;
-				break;
-			case 'user_attr':
-				$ret = $this->user_attr;
-				break;
-			case 'attr_filter':
-				$ret = $this->attr_filter;
-				break;
-			case 'basedn':
-				$ret = $this->basedn;
-				break;
-			case 'mail_attr':
-			  $ret = $this->mail_attr;
-			  break;
-		}
-		return $ret;
+    $ret = '';
+    switch ($option) {
+      case 'version':
+        $ret = -1;
+        ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $ret);
+        break;
+      case 'name':
+        $ret = $this->name;
+        break;
+      case 'port':
+        $ret = $this->port;
+        break;
+      case 'tls':
+        $ret = $this->tls;
+        break;
+      case 'encrypted':
+        $ret = $this->encrypted;
+        break;
+      case 'user_attr':
+        $ret = $this->user_attr;
+        break;
+      case 'attr_filter':
+        $ret = $this->attr_filter;
+        break;
+      case 'basedn':
+        $ret = $this->basedn;
+        break;
+      case 'mail_attr':
+        $ret = $this->mail_attr;
+        break;
+    }
+    return $ret;
   }
 
   function connect($dn = '', $pass = '') {
     $ret = FALSE;
-	// http://drupal.org/node/164049
+  // http://drupal.org/node/164049
     // If a connection already exists, it should be terminated
     $this->disconnect();
 
@@ -106,13 +111,13 @@
 
   function initConnection() {
     if (!$con = ldap_connect($this->server, $this->port)) {
-      watchdog('user', 'LDAP Connect failure to ' . $this->server . ':' . $this->port);
+      watchdog('user', 'LDAP Connect failure to %server:%port', array('%server' => $this->server, '%port' => $this->port));
       return NULL;
     }
 
     $this->connection = $con;
     ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
-    ldap_set_option($con, LDAP_OPT_REFERRALS, 0);   
+    ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
     // TLS encryption contributed by sfrancis@drupal.org
     if ($this->tls) {
       $vers = $this->getOption('version');
@@ -137,7 +142,7 @@
 
     $con = $this->connection;
     if (!$this->bind($dn, $pass)) {
-      watchdog('user', t('LDAP Bind failure for user %user. Error %errno: %error', array('%user' => $dn,'%errno' => ldap_errno($con), '%error' => ldap_error($con))));
+      watchdog('user', 'LDAP Bind failure for user %user. Error %errno: %error', array('%user' => $dn, '%errno' => ldap_errno($con), '%error' => ldap_error($con)));
       return NULL;
     }
 
@@ -216,8 +221,9 @@
       if (is_array ($cur_val)) {
         foreach ($cur_val as $mv_key => $mv_cur_val) {
           if ($mv_cur_val == '') {
-            unset ($attributes[$key][$mv_key]);
-          } else {
+            unset($attributes[$key][$mv_key]);
+          }
+          else {
             $attributes[$key][$mv_key] = $mv_cur_val;
           }
         }
@@ -233,4 +239,3 @@
   }
 }
 
-?>
diff --exclude=.svn -urN ldap_integration.orig/ldap_integration/libdebug.php ldap_integration/ldap_integration/libdebug.php
--- ldap_integration.orig/ldap_integration/libdebug.php	2008-04-17 06:32:13.000000000 +0200
+++ ldap_integration/ldap_integration/libdebug.php	2008-06-27 08:44:48.000000000 +0200
@@ -1,5 +1,9 @@
 <?php
-// $Id: libdebug.php,v 1.1.4.3.2.3 2008/04/17 04:32:13 scafmac Exp $
+// $Id: libdebug.php,v 1.2 2007/01/28 20:38:03 kreaper Exp $
+/**
+ * @file
+ * Debug function for ldap modules
+ */
 
 function msg($string) {
   drupal_set_message("<pre style=\"border: 0; margin: 0; padding: 0;\">$string</pre>");
@@ -9,4 +13,3 @@
   msg(print_r($object, true));
 }
 
-?>
diff --exclude=.svn -urN ldap_integration.orig/README.txt ldap_integration/README.txt
--- ldap_integration.orig/README.txt	2008-04-17 06:32:12.000000000 +0200
+++ ldap_integration/README.txt	2008-06-26 17:08:42.000000000 +0200
@@ -1,4 +1,4 @@
-$Id: README.txt,v 1.3.2.2.2.2 2008/04/17 04:32:12 scafmac Exp $
+$Id: README.txt,v 1.6 2007/07/22 20:04:25 kreaper Exp $
 
 Basic Info
 ==========
