function globallink_beans_receive_form_submit in GlobalLink Connect for Drupal 7.6
Handles beans form submission.
File
- globallink_beans/
globallink_beans_receive.inc, line 526
Code
function globallink_beans_receive_form_submit($form, &$form_state) {
$type = $_SESSION['globallink_beans_receive_type'];
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
$pd4 = globallink_get_project_director_details();
switch ($op) {
case t('Update All'):
try {
$globallink_arr = unserialize($_SESSION['globallink_beans_globalLink_arr']);
$count = globallink_beans_get_translated($pd4, $globallink_arr);
$error = FALSE;
$delete_records_selected = FALSE;
foreach ($globallink_arr as $updated) {
if ($updated->sourceDeleted == TRUE) {
$delete_records_selected = TRUE;
}
if ($updated->status == 'Error') {
$error = TRUE;
}
}
$status = 'status';
if ($error) {
drupal_set_message(t('There was some error while updating the records. Please check logs for more details.'), 'warning', NULL);
$status = 'warning';
}
drupal_set_message(check_plain($count . ' record(s) updated successfully.'), $status, NULL);
if ($delete_records_selected) {
drupal_set_message(t('Source Deleted record(s) cannot be updated.'), 'warning', NULL);
}
} catch (Exception $e) {
watchdog('GlobalLink', '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(),
)));
}
$_SESSION['globallink_beans_globalLink_arr'] = array();
$_SESSION['globallink_beans_selected_submission'] = array();
unset($_SESSION['globallink_beans_globalLink_arr_last_refreshed']);
break;
case t('Clear Deleted Records'):
try {
$globallink_arr = unserialize($_SESSION['globallink_beans_globalLink_arr']);
$success = FALSE;
$count = 0;
foreach ($globallink_arr as $globallink) {
if ($globallink->sourceDeleted == TRUE) {
$success = globallink_beans_update_deleted_records($pd4, $globallink);
$count++;
}
}
if ($count == 0) {
drupal_set_message(t('No source record(s) deleted.'), 'warning', NULL);
}
else {
$_SESSION['globallink_beans_globalLink_arr'] = array();
$_SESSION['globallink_beans_selected_submission'] = array();
unset($_SESSION['globallink_beans_globalLink_arr_last_refreshed']);
}
if ($success) {
drupal_set_message(check_plain($count . ' Source Deleted record(s) cleared successfully.'), 'status', NULL);
}
} catch (Exception $e) {
watchdog('GlobalLink', '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(),
)));
}
break;
case t('Update Selected'):
try {
$globallink_arr = unserialize($_SESSION['globallink_beans_globalLink_arr']);
$updated_globalLink_arr = array();
$rids = array_filter($form_state['values']['table']);
foreach ($rids as $rid) {
array_push($updated_globalLink_arr, $globallink_arr[$rid]);
}
$count = globallink_beans_get_translated($pd4, $updated_globalLink_arr);
$error = FALSE;
$delete_records_selected = FALSE;
foreach ($globallink_arr as $updated) {
if ($updated->sourceDeleted == TRUE) {
$delete_records_selected = TRUE;
}
if ($updated->status == 'Error') {
$error = TRUE;
}
}
$status = 'status';
if ($error) {
drupal_set_message(t('There was some error while updating the records. Please check logs for more details.'), 'warning', NULL);
$status = 'warning';
}
drupal_set_message(check_plain($count . ' record(s) updated successfully.'), $status, NULL);
if ($delete_records_selected) {
drupal_set_message(t('Source Deleted record(s) cannot be updated.'), 'warning', NULL);
}
} catch (Exception $e) {
watchdog('GlobalLink', '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(),
)));
}
$_SESSION['globallink_beans_globalLink_arr'] = array();
$_SESSION['globallink_beans_selected_submission'] = array();
unset($_SESSION['globallink_beans_globalLink_arr_last_refreshed']);
break;
case t('Refresh Page'):
sleep(2);
$pd4 = globallink_get_project_director_details();
//Get all the active submission tickets.
$query = db_select('globallink_core_beans', 'gcb')
->fields('gcb')
->condition('status', array(
'Sent for Translations',
'Error',
), 'IN');
$results = $query
->execute();
$submission_tickets = array();
foreach ($results as $result) {
if (!in_array($result->submission_ticket, $submission_tickets)) {
$submission_tickets[] = $result->submission_ticket;
}
}
try {
$globallink_arr = globallink_get_ready_translations_details_from_pd($pd4, $type, $submission_tickets);
} catch (SoapFault $se) {
watchdog('GlobalLink', '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', '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(),
)));
}
if (sizeof($globallink_arr) > 0) {
$_SESSION['globallink_beans_globalLink_arr'] = serialize($globallink_arr);
$_SESSION['globallink_beans_globalLink_arr_last_refreshed'] = format_date(REQUEST_TIME, 'custom', 'D M j, Y G:i:s');
}
else {
$_SESSION['globallink_beans_globalLink_arr'] = array();
unset($_SESSION['globallink_beans_globalLink_arr_last_refreshed']);
}
break;
}
}