You are here

public function LdapServerAdmin::drupalForm in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServerAdmin.class.php \LdapServerAdmin::drupalForm()
  2. 7 ldap_servers/LdapServerAdmin.class.php \LdapServerAdmin::drupalForm()

File

ldap_servers/LdapServerAdmin.class.php, line 223

Class

LdapServerAdmin

Code

public function drupalForm($op) {
  $form['server'] = [
    '#type' => 'fieldset',
    '#title' => t('Connection settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['bind_method'] = [
    '#type' => 'fieldset',
    '#title' => t('Binding Method'),
    '#description' => t('How the Drupal system is authenticated by the LDAP server.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['users'] = [
    '#type' => 'fieldset',
    '#title' => t('LDAP User to Drupal User Relationship'),
    '#description' => t('How are LDAP user entries found based on Drupal username or email?  And vice-versa?
       Needed for LDAP Authentication and Authorization functionality.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['groups'] = [
    '#type' => 'fieldset',
    '#title' => t('LDAP Group Configuration'),
    '#description' => t('How are groups defined on your LDAP server?  This varies slightly from one LDAP implementation to another
      such as Active Directory, Novell, OpenLDAP, etc. Check everything that is true and enter all the values you know.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $supports = ldap_servers_php_supports_pagination() ? t('support pagination!') : t('NOT support pagination.');
  $form['pagination'] = [
    '#type' => 'fieldset',
    '#title' => t('LDAP Pagination'),
    '#description' => t('In PHP 5.4, pagination is supported in ldap queries.
      A patch to earlier versions of PHP also supports this.') . ' <strong>' . t('This PHP installation appears to') . ' ' . $supports . '</strong> ' . '<p>' . t('The advantage to pagination support is that if an ldap server is setup to return only
      1000 entries at a time,
      you can use page through 1000 records at a time;
      without pagination you would never see more than the first 1000 entries.
      Pagination is most useful when large queries for batch creating or
      synching accounts are used.  If you are not using this server for such
      tasks, its recommended to leave pagination disabled.') . '</p>',
    '#collapsible' => TRUE,
    '#collapsed' => !ldap_servers_php_supports_pagination(),
  ];
  $field_to_prop_maps = $this
    ->field_to_properties_map();
  foreach ($this
    ->fields() as $field_id => $field) {
    if (isset($field['form'])) {
      if (!isset($field['form']['required']) && isset($field['schema']['not null']) && $field['form']['#type'] != 'checkbox') {
        $field['form']['#required'] = (bool) $field['schema']['not null'];
      }
      if (isset($field['schema']['length']) && !isset($field['form']['#maxlength'])) {
        $field['form']['#maxlength'] = $field['schema']['length'];
      }
      if (isset($field_to_prop_maps[$field_id])) {
        $field['form']['#default_value'] = $this->{$field_to_prop_maps[$field_id]};
      }
      $fieldset = @$field['form']['fieldset'];
      if ($fieldset) {
        unset($field['form']['fieldset']);
        $form[$fieldset][$field_id] = $field['form'];
      }
      else {
        $form[$field_id] = $field['form'];
      }
    }
  }
  $form['server']['sid']['#disabled'] = $op == 'edit';
  if (!function_exists('ldap_set_rebind_proc')) {
    $form['server']['followrefs']['#disabled'] = TRUE;
    $form['server']['followrefs']['#description'] = t('This functionality is disabled because the function ldap_set_rebind_proc can not be found on this server.  Perhaps your version of php does not have this function.  See php.net/manual/en/function.ldap-set-rebind-proc.php') . $form['server']['followrefs']['#description'];
  }
  $form['server']['tls']['#required'] = FALSE;
  $form['server']['followrefs']['#required'] = FALSE;
  $form['bind_method']['bind_method']['#default_value'] = $this->bind_method ? $this->bind_method : LDAP_SERVERS_BIND_METHOD_DEFAULT;
  $form['users']['basedn']['#default_value'] = $this
    ->arrayToLines($this->basedn);
  if ($this->bindpw) {
    $pwd_directions = t('You currently have a password stored in the database.
      Leave password field empty to leave password unchanged.  Enter a new password
      to replace the current password.  Check the checkbox below to simply
      remove it from the database.');
    $pwd_class = 'ldap-pwd-present';
  }
  else {
    $pwd_directions = t('No password is currently stored in the database.
      If you are using a service account, enter one.');
    if ($this->bind_method == LDAP_SERVERS_BIND_METHOD_SERVICE_ACCT) {
      $pwd_class = 'ldap-pwd-abscent';
    }
    else {
      $pwd_class = 'ldap-pwd-not-applicable';
    }
  }
  $action = $op == 'add' ? 'Add' : 'Update';
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $action,
    '#weight' => 100,
  ];
  return $form;
}