You are here

function ldapgroups_admin_edit_validate in LDAP integration 6

Validate hook for the settings form.

File

./ldapgroups.admin.inc, line 269
Module admin page callbacks.

Code

function ldapgroups_admin_edit_validate($form, &$form_state) {
  $op = $form_state['clicked_button']['#value'];
  $values = $form_state['values'];
  switch ($op) {
    case t('Update'):
      if ($values['ldapgroups_in_dn'] && !trim($values['ldapgroups_dn_attribute'])) {
        form_set_error('ldapgroups_dn_attribute', t('DN attribute is missing.'));
      }
      if ($values['ldapgroups_in_attr'] && !trim($values['ldapgroups_attr'])) {
        form_set_error('ldapgroups_attr', t('Attribute names are missing.'));
      }
      if ($values['ldapgroups_as_entries'] && !trim($values['ldapgroups_entries'])) {
        form_set_error('ldapgroups_entries', t('Nodes are missing.'));
      }
      if ($values['ldapgroups_as_entries'] && !trim($values['ldapgroups_entries_attribute'])) {
        form_set_error('ldapgroups_entries_attribute', t('Attribute is missing.'));
      }
      $form_state['ldapgroups_attr'] = array();
      foreach (trim($values['ldapgroups_attr']) ? explode("\n", trim($values['ldapgroups_attr'])) : array() as $line) {
        if (trim($line)) {
          $form_state['ldapgroups_attr'][] = trim($line);
        }
      }
      $form_state['ldapgroups_attr'] = !empty($form_state['ldapgroups_attr']) ? serialize($form_state['ldapgroups_attr']) : '';
      $form_state['ldapgroups_entries'] = array();
      foreach (trim($values['ldapgroups_entries']) ? explode("\n", trim($values['ldapgroups_entries'])) : array() as $line) {
        if (trim($line)) {
          $form_state['ldapgroups_entries'][] = trim($line);
        }
      }
      $form_state['ldapgroups_entries'] = !empty($form_state['ldapgroups_entries']) ? serialize($form_state['ldapgroups_entries']) : '';
      $form_state['ldapgroups_mappings'] = array();
      $ldapgroups_role_mappings = TRUE;
      foreach (trim($values['ldapgroups_mappings']) ? explode("\n", trim($values['ldapgroups_mappings'])) : array() as $line) {
        if (count($mapping = explode('|', trim($line))) == 2) {
          $form_state['ldapgroups_mappings'] += array(
            trim($mapping[0]) => trim($mapping[1]),
          );
        }
        else {
          $ldapgroups_role_mappings = FALSE;
        }
      }
      $form_state['ldapgroups_mappings'] = !empty($form_state['ldapgroups_mappings']) ? serialize($form_state['ldapgroups_mappings']) : '';
      if (!$ldapgroups_role_mappings) {
        form_set_error('ldapgroups_mappings', t('Bad mapping syntax.'));
      }
      if ($values['ldapgroups_mappings_filter'] == LDAPGROUPS_ROLE_MODE_USE_MAP && !trim($values['ldapgroups_mappings'])) {
        form_set_error('ldapgroups_mappings', t('Mappings are missing.'));
      }
      $form_state['ldapgroups_groups'] = array();
      foreach (trim($values['ldapgroups_groups']) ? explode("\n", trim($values['ldapgroups_groups'])) : array() as $line) {
        if (trim($line)) {
          $form_state['ldapgroups_groups'][] = trim($line);
        }
      }
      $form_state['ldapgroups_groups'] = !empty($form_state['ldapgroups_groups']) ? serialize($form_state['ldapgroups_groups']) : '';
      break;
  }
}