function drupalchat_settings_form_validate in DrupalChat 6.2
Same name and namespace in other branches
- 7.2 drupalchat.admin.inc \drupalchat_settings_form_validate()
- 7 drupalchat.admin.inc \drupalchat_settings_form_validate()
File
- ./
drupalchat.admin.inc, line 267 - Administrative functions to configure DrupalChat.
Code
function drupalchat_settings_form_validate($form, &$form_state) {
global $user;
if ($form_state['values']['drupalchat_polling_method'] == DRUPALCHAT_COMMERCIAL) {
$form_state['values']['drupalchat_app_id'] = trim($form_state['values']['drupalchat_app_id']);
$form_state['values']['drupalchat_external_api_key'] = trim($form_state['values']['drupalchat_external_api_key']);
$app_id = $form_state['values']['drupalchat_app_id'];
if (!(strlen($app_id) == 36 && $app_id[14] == '4')) {
form_set_error('drupalchat_app_id', "Invalid APP ID.");
}
if (!$form_state['values']['drupalchat_app_id']) {
form_set_error('drupalchat_app_id', t('Please enter APP ID.'));
}
if (!$form_state['values']['drupalchat_external_api_key']) {
form_set_error('drupalchat_external_api_key', t('Please enter API key.'));
}
$formValues = array(
'api_key' => $form_state['values']['drupalchat_external_api_key'],
'app_id' => $form_state['values']['drupalchat_app_id'],
);
$result = (array) _drupalchat_get_auth($user->name, $formValues);
if (!array_key_exists('key', $result)) {
form_set_error('drupalchat_external_api_key', "Unable to connect to iFlyChat server. Error code - " . $result['code'] . ". Error message - " . $result['error'] . ".");
}
}
if ($form_state['values']['drupalchat_rel'] == DRUPALCHAT_REL_UR) {
if (!$form_state['values']['drupalchat_ur_name']) {
form_set_error('drupalchat_ur_name', t('You must provide the user relationship name in the Drupal UR Settings section.'));
}
if ($form_state['values']['drupalchat_ur_name']) {
$array = drupal_explode_tags($form_state['values']['drupalchat_ur_name']);
$error = array();
foreach ($array as $key) {
$result = db_query("SELECT COUNT(*) as count FROM {user_relationship_types} WHERE name = '%s'", array(
$key,
));
while ($row = db_fetch_object($result)) {
if (!$row->count) {
$error[] = $key;
}
}
}
if (!empty($error)) {
form_set_error('drupalchat_ur_name', t('User Relationship type %type was not found.', array(
'%type' => drupal_implode_tags($error),
)));
}
}
}
}