function globallink_pd_settings_validate in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_settings.inc \globallink_pd_settings_validate()
- 7.6 globallink_settings.inc \globallink_pd_settings_validate()
Handles validation of globallink_pd_settings form.
File
- ./
globallink_settings.inc, line 135
Code
function globallink_pd_settings_validate(&$form, &$form_state) {
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_common');
$project_short_code_char_arr = str_split(str_replace(' ', '', $form_state['values']['globallink_pd_projectid']));
foreach ($project_short_code_char_arr as $val) {
if (!preg_match('/[a-zA-Z0-9\\,_]/', $val)) {
form_set_error('', t('Only enter comma seperated GlobalLink Project Short Code.'));
return FALSE;
}
if ($val === strtolower($val) && !is_numeric($val) && $val != ',' && $val != '_' && $val != '') {
form_set_error('', t('GlobalLink Project Short Code is in lowercase.'));
return FALSE;
}
}
$project_short_code_arr = explode(',', str_replace(' ', '', $form_state['values']['globallink_pd_projectid']));
foreach ($project_short_code_arr as $val) {
if (count(array_keys($project_short_code_arr, $val)) > 1) {
form_set_error('', t('GlobalLink Project Short Code has duplicates.'));
return FALSE;
}
}
$value = $form_state['values']['globallink_pd_max_target'];
if (!is_numeric($value)) {
form_set_error('globallink_pd_max_target', t('Max Target Count is not a number.'));
return FALSE;
}
elseif ($value < 1) {
form_set_error('globallink_pd_max_target', t('Max Target Count should be greater than 1.'));
return FALSE;
}
$max_batch = $form_state['values']['globallink_batch'];
if (!is_numeric($max_batch)) {
form_set_error('globallink_batch', t('Max documents before submission is not a number'));
return FALSE;
}
elseif ($max_batch < 1) {
form_set_error('globallink_batch', t('Max documents before submission should be greater than 1'));
return FALSE;
}
$prefix_len = strlen($form_state['values']['globallink_pd_submissionprefix']);
if ($prefix_len > 118) {
form_set_error('globallink_pd_max_target', t('Submission Name cannot be longer than 118 characters. Currently ' . $prefix_len . ' characters long.'));
return FALSE;
}
if (isset($form_state['values']['globallink_pd_password']) && $form_state['values']['globallink_pd_password'] != '') {
try {
$pd_obj = new ProjectDirector();
$url = strrev($form_state['values']['globallink_pd_url']);
if (ord($url) == 47) {
$url = substr($url, 1);
}
$r_url = strrev($url);
$pd_obj->url = $r_url;
$pd_obj->username = $form_state['values']['globallink_pd_username'];
$pd_obj->password = $form_state['values']['globallink_pd_password'];
$pd_obj->projectShortCode = $form_state['values']['globallink_pd_projectid'];
$pd_obj->submissionPrefix = $form_state['values']['globallink_pd_submissionprefix'];
$pd_obj->classifier = $form_state['values']['globallink_pd_classifier'];
$pd_obj->maxTargetCount = $form_state['values']['globallink_pd_max_target'];
$pd_obj->userAgent = $form_state['values']['globallink_unique_identifier'];
$success = globallink_test_pd_connectivity($pd_obj);
if (!is_bool($success)) {
form_set_error('', t($success));
}
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
form_set_error('', t('Web Services Error: @faultcode - @faultstring', array(
'@faultcode' => $se->faultcode,
'@faultstring' => $se->faultstring,
)));
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
form_set_error('', t('Error: @message', array(
'@message' => $e
->getMessage(),
)));
}
}
}