function ldap_api_edit_server_form_submit in Lightweight Directory Access Protocol (LDAP) 6
Submit hook for the LDAP server form.
File
- ./
ldap_server.admin.inc, line 252
Code
function ldap_api_edit_server_form_submit($form, &$form_state) {
$op = $form_state['clicked_button']['#value'];
$values = $form_state['values'];
switch ($op) {
case t('Save configuration'):
if (!isset($values['sid'])) {
db_query("INSERT INTO {ldap_servers} (name, active, address, port, tls, basedn, binddn, bindpw) VALUES ('%s', %d, '%s', %d, %d, '%s', '%s', '%s')", $values['name'], 1, $values['address'], $values['port'], $values['tls'], $values['basedn'], $values['binddn'], $values['bindpw']);
drupal_set_message(t('LDAP configuration %name has been added.', array(
'%name' => $values['name'],
)));
watchdog('LDAP', 'LDAP configuration %name has been added.', array(
'%name' => $values['name'],
));
}
else {
db_query("UPDATE {ldap_servers} SET name = '%s', address = '%s', port = %d, tls = %d, basedn = '%s', binddn = '%s', bindpw = '%s' WHERE sid = %d", $values['name'], $values['address'], $values['port'], $values['tls'], $values['basedn'], $values['binddn'], $values['bindpw'], $values['sid']);
drupal_set_message(t('LDAP Configuration %name has been updated.', array(
'%name' => $values['name'],
)));
watchdog('ldap_servers', 'LDAP Configuration %name has been updated.', array(
'%name' => $values['name'],
));
}
$form_state['redirect'] = 'admin/settings/ldap/servers/list';
break;
case t('Test'):
// global $_ldap_servers_ldap;
if (isset($values['sid']) && _ldap_servers_init($values['sid'])) {
// Try to authenticate.
$dn = $_ldap_servers_ldap
->getOption('binddn');
$pass = $_ldap_servers_ldap
->getOption('bindpw');
if (!$_ldap_servers_ldap
->connect($dn, $pass)) {
drupal_set_message(t('Authentication with the LDAP server for the dn %dn and saved password failed.', array(
'%dn' => $dn,
)), 'error');
}
else {
drupal_set_message(t('Authentication with the LDAP server for the dn %dn and saved password succeeded.', array(
'%dn' => $dn,
)));
}
}
else {
drupal_set_message(t('Cannot load server settings. Please save configuration first.'), 'error');
}
break;
}
}