You are here

function globallink_dashboard_node_form_validate in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_send_translations.inc \globallink_dashboard_node_form_validate()

Validates form actions for GlobalLink submissions.

File

./globallink_send_translations.inc, line 1230

Code

function globallink_dashboard_node_form_validate($form, &$form_state) {
  module_load_include('inc', 'globallink', 'globallink_settings');
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  $pd4 = globallink_get_project_director_details();
  globallink_validate_project_director_details($pd4);
  $source_locale = $form_state['values']['submission_source_locale'];
  $target_locale_arr = $form_state['values']['submission_target_locale'];
  if ($op != t('Send for Translation')) {
    return;
  }
  $nids = array_filter($form_state['values']['table']);
  if (count($nids) == 0) {
    form_set_error('', t('No items selected.'));
  }
  if (!empty($form_state['values']['submission_due_date'])) {
    $due_date = globallink_convert_date_to_timestamp($form_state['values']['submission_due_date']) / 1000;
    if ($due_date < REQUEST_TIME) {
      form_set_error('', t('The specified date is in past.'));
    }
  }
  if (count($nids) == 0) {
    return;
  }
  if (!isset($source_locale) || !isset($target_locale_arr)) {
    return;
  }
  foreach ($target_locale_arr as $key => $target) {
    if ($target == FALSE) {
      unset($target_locale_arr[$key]);
    }
  }
  $message = FALSE;
  if (count($target_locale_arr) == 0) {
    return;
  }
  foreach ($nids as $nid) {
    list($nid, $vid) = explode('-', $nid, 2);
    $node = node_load($nid, $vid);
    if ($node->tnid != 0 && $node->tnid != $node->nid) {
      $nid = $node->tnid;
    }
    $rows = globallink_get_sent_rows_by_nid($nid);
    foreach ($rows as $row) {
      if ($row->source == $source_locale && array_search($row->target, $target_locale_arr)) {
        $message = TRUE;
      }
    }
  }
  if ($message) {
    drupal_set_message(t('Ignored record(s) that has already been sent out for translation.'), 'warning');
  }
}