You are here

globallink_workbench_all_active_submissions.inc in GlobalLink Connect for Drupal 7.7

File

globallink_workbench_all_active_submissions.inc
View source
<?php

function globallink_dashboard_active_submissions_page($type = GLOBALLINK_ENTITY_TYPE_NODE) {
  $_SESSION['transpefect_dashboard_active_type'] = $type;
  $_SESSION['transpefect_dashboard_receive_type'] = $type;
  $array = array();
  if (arg(6) == 'sync') {
    $sub_rid_sync = arg(4);
    $doc_id_sync = arg(7);
    $uri = request_uri();
    $ex_uri = explode(arg(6), $uri);
    $curr_uri = explode('admin', $ex_uri[0]);
    $doc_ids_sync = array(
      $doc_id_sync,
    );
    if ($sub_rid_sync != '') {
      module_load_include('inc', 'globallink', 'globallink_settings');
      $pd4 = globallink_get_project_director_details();
      if (module_exists('background_process') && module_exists('background_batch')) {
        $operations = array();
        $operations[] = array(
          'globallink_background_pull',
          array(
            $pd4,
            $sub_rid_sync,
            $doc_ids_sync,
            1,
          ),
        );
        $batch = array(
          'title' => t('Pulling Status'),
          'operations' => $operations,
          'error_message' => t('Sync has encountered an error.'),
          'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
        );
        batch_set($batch);
        $batch['progressive'] = FALSE;
        background_batch_process_batch('admin/globallink-translations/workbench');
        drupal_set_message('The submission(s) are being synced in the background. Please refresh the page for the progress.');
      }
      else {
        module_load_include('inc', 'globallink', 'globallink_background_jobs');
        globallink_background_pull($pd4, $sub_rid_sync, $doc_ids_sync, 1);
        drupal_set_message('The document has been synced with latest available status');
      }
      drupal_goto('admin' . $curr_uri[1]);
    }
  }
  if (arg(6) == 'import') {
    $sub_rid_import = arg(4);
    $doc_id_import = arg(7);
    $uri = request_uri();
    $ex_uri = explode(arg(6), $uri);
    $curr_uri = explode('admin', $ex_uri[0]);
    $doc_ids_import = array(
      $doc_id_import,
    );
    if ($sub_rid_import != '') {
      module_load_include('inc', 'globallink', 'globallink_settings');
      $pd4 = globallink_get_project_director_details();
      if (module_exists('background_process') && module_exists('background_bacth')) {
        $operations = array();
        $operations[] = array(
          'globallink_background_import',
          array(
            $pd4,
            $sub_rid_import,
            $doc_ids_import,
          ),
        );
        $batch = array(
          'title' => t('Importing'),
          'operations' => $operations,
          'error_message' => t('Import has encountered an error.'),
          'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
        );
        batch_set($batch);
        $batch['progressive'] = FALSE;
        background_batch_process_batch('admin/globallink-translations/workbench');
        drupal_set_message('The submission(s) are being imported in the background. Please refresh the page for the progress.');
      }
      else {
        module_load_include('inc', 'globallink', 'globallink_background_jobs');
        globallink_background_import($pd4, $sub_rid_import, $doc_ids_import);
        drupal_set_message('Document has been imported');
      }
      drupal_goto('admin' . $curr_uri[1]);
    }
  }
  $f1 = drupal_get_form('globallink_all_active_filter_form');
  $f2 = drupal_get_form('globallink_all_active_pager_form');
  $f3 = drupal_get_form('globallink_all_active_form');
  $html = drupal_render($f1);
  $html .= drupal_render($f2);
  $html .= drupal_render($f3);
  return $html;
}

/**
 * Builds forms on entity active submissions dashboard.
 *
 * @param string $type
 *   The type of task we are working on.
 *
 * @return array
 *   Array of forms for the entity active submissions dashboard.
 */
function globallink_all_active_submissions($type) {
  $_SESSION['transpefect_all_active_type'] = $type;
  $_SESSION['transpefect_entity_receive_type'] = $type;
  $array = array();
  $array[] = drupal_get_form('globallink_all_active_filter_form');
  $array[] = drupal_get_form('globallink_all_active_pager_form');

  //$array[] = drupal_get_form('globallink_upload_translation_all_form');
  $array[] = drupal_get_form('globallink_all_active_form');
  return $array;
}

/**
 * Builds form to filter GlobalLink submissions
 */
function globallink_all_active_filter_form() {
  $form = array();
  $filter = FALSE;
  $sub_rid = arg(4);
  $sub_sql = db_select('globallink_submission', 'gs');
  $sub_sql
    ->condition('rid', $sub_rid, '=');
  $sub_sql
    ->fields('gs');
  $sub_sql_result = $sub_sql
    ->execute()
    ->fetchAll();
  $submission_row = $sub_sql_result[0];
  if ($submission_row->status == 'Translation Imported') {
    $default_status = '[completed]';
    $status_arr = array(
      '[completed]' => t('All Completed'),
      GLOBALLINK_STATUS_TRANSLATION_IMPORTED => GLOBALLINK_STATUS_TRANSLATION_IMPORTED,
      GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
    );
  }
  else {
    $default_status = '[active]';
    $status_arr = array(
      '[active]' => t('Show Active Submissions Only'),
      GLOBALLINK_STATUS_TRANSLATION_SENT => GLOBALLINK_STATUS_TRANSLATION_SENT,
      GLOBALLINK_STATUS_TRANSLATION_COMPLETED => GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
    );
  }
  if (!empty($_SESSION['globallink_all_receive_filter_status'])) {
    $default_status = $_SESSION['globallink_all_receive_filter_status'];
    $filter = TRUE;
  }
  $default_submission = '';
  if (!empty($_SESSION['globallink_all_receive_filter_submission'])) {
    $default_submission = $_SESSION['globallink_all_receive_filter_submission'];
    $filter = TRUE;
  }
  $form['node_receive_filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('FILTER RECORDS'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['node_receive_filter']['filters'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $form['node_receive_filter']['filters'][] = array(
    '#markup' => '<table>',
  );
  $form['node_receive_filter']['filters']['status'] = array(
    '#type' => 'select',
    '#title' => t('Status'),
    '#options' => $status_arr,
    '#default_value' => $default_status,
    '#field_suffix' => '&nbsp;&nbsp;&nbsp;&nbsp;',
    '#prefix' => '<tr><td style="text-align: left;width: 16%;vertical-align: middle;border: none;">',
    '#suffix' => '</tr>',
    '#field_suffix' => '</td>',
    '#field_prefix' => '</td><td>',
  );
  $form['node_receive_filter']['filters']['submission'] = array(
    '#type' => 'textfield',
    '#title' => t('Submission Name Contains'),
    '#size' => 40,
    '#field_suffix' => '&nbsp;&nbsp;&nbsp;&nbsp;',
    '#prefix' => '<tr><td style="text-align: left;width: 16%;vertical-align: middle;border: none;">',
    '#suffix' => '</tr>',
    '#field_suffix' => '</td>',
    '#field_prefix' => '<BR/><div class="description">' . t('The filter is case sensitive.') . '</div></td><td>',
  );
  $form['node_receive_filter']['filters'][] = array(
    '#markup' => '</table>',
  );
  $disable_submit = $filter ? TRUE : FALSE;
  $form['node_receive_filter']['filters']['filter'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
    '#disabled' => $disable_submit,
  );
  if ($filter) {
    $form['filter-search'] = array(
      '#type' => 'fieldset',
      '#title' => t('FILTER CRITERIA'),
    );
    $form['filter-search']['filter-markup'] = array(
      '#type' => 'container',
    );
    $form['filter-search']['filter-markup'][] = array(
      '#markup' => '<table>',
    );
    $form['filter-search']['filter-markup'][] = array(
      '#prefix' => '<tr><td style="text-align: left;width: 16%;vertical-align: middle;border: none;"><b>',
      '#markup' => t('Status'),
      '#suffix' => '</b>:&nbsp;</td><td style="text-align: left;width: 84%;vertical-align: middle;border: none;">' . $status_arr[$default_status] . '</td></tr>',
    );
    $form['filter-search']['filter-markup'][] = array(
      '#prefix' => '<tr><td style="text-align: left;width: 16%;vertical-align: middle;border: none;"><b>',
      '#markup' => t('Submission Name Contains'),
      '#suffix' => '</b>:&nbsp;</td><td style="text-align: left;width: 84%;vertical-align: middle;border: none;">' . $default_submission . '</td></tr>',
    );
    $form['filter-search']['filter-markup'][] = array(
      '#markup' => '</table>',
    );
    $form['filter-search']['status']['actions'] = array(
      '#type' => 'actions',
      '#attributes' => array(
        'class' => array(
          'container-inline',
        ),
      ),
    );
    $form['filter-search']['status']['actions']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset'),
    );
  }
  return $form;
}

/**
 * Handles submission of filter form.
 */
function globallink_all_active_filter_form_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  switch ($op) {
    case t('Filter'):
      $_SESSION['globallink_all_receive_filter_status'] = $form_state['values']['status'];
      $_SESSION['globallink_all_receive_filter_submission'] = $form_state['values']['submission'];
      break;
    case t('Reset'):
      $_SESSION['globallink_all_receive_filter_status'] = '';
      $_SESSION['globallink_all_receive_filter_submission'] = '';
      break;
  }
}

/**
 * Builds form to add pagination to GlobalLink send dashboard.
 */
function globallink_node_active_pager_form() {
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_css($module_path . '/css/globallink_active_submissions.css');
  $form = array();
  $form['page_counter']['markup'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'tpt-center',
      ),
    ),
  );
  $form['page_counter']['markup']['p_count'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($_SESSION['globallink_node_active_page_count']) ? $_SESSION['globallink_node_active_page_count'][0] : TPT_PAGER_LIMIT,
    '#field_prefix' => t('Show') . '&nbsp;&nbsp;',
    '#field_suffix' => '&nbsp;&nbsp;' . t('records') . '&nbsp;&nbsp;&nbsp;&nbsp;',
    '#prefix' => '<div class="container-inline">',
  );
  $form['page_counter']['markup']['action'] = array(
    '#type' => 'submit',
    '#value' => t('Go'),
    '#suffix' => '</div>',
    '#limit_validation_errors' => array(),
    '#submit' => array(
      'globallink_node_active_pager_form_submit',
    ),
    '#access' => TRUE,
  );
  return $form;
}

/**
 * Builds form to add pagination to entity send dashboard.
 */
function globallink_all_active_pager_form() {
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_css($module_path . '/css/globallink_active_submissions.css');
  $form = array();
  $form['page_counter']['markup'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'tpt-center',
      ),
    ),
  );
  $form['page_counter']['markup']['p_count'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($_SESSION['globallink_all_active_page_count']) ? $_SESSION['globallink_all_active_page_count'][0] : TPT_PAGER_LIMIT,
    '#field_prefix' => t('Show') . '&nbsp;&nbsp;',
    '#field_suffix' => '&nbsp;&nbsp;' . t('records') . '&nbsp;&nbsp;&nbsp;&nbsp;',
    '#prefix' => '<div class="container-inline">',
  );
  $form['page_counter']['markup']['action'] = array(
    '#type' => 'submit',
    '#value' => t('Go'),
    '#suffix' => '</div>',
    '#limit_validation_errors' => array(),
    '#submit' => array(
      'globallink_all_active_pager_form_submit',
    ),
    '#access' => TRUE,
  );
  return $form;
}

/**
 * Handles submission of pager form.
 */
function globallink_all_active_pager_form_submit($form, &$form_state) {
  $op = $form_state['values']['op'];
  if ($op != t('Go')) {
    return;
  }
  $page_count = $form_state['input']['p_count'];
  if (!is_numeric($page_count) || $page_count < 1) {
    form_set_error('', t('Invalid Page Count.'));
  }
  else {
    $_SESSION['globallink_all_active_page_count'] = array(
      $page_count,
    );
    return;
  }
}

/**
 * Builds form to show all active entity submissions.
 */
function globallink_all_active_form() {
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink_entity', 'globallink_entity');
  module_load_include('inc', 'globallink_block', 'globallink_block');
  module_load_include('inc', 'globallink_fieldable_panels', 'globallink_fieldable_panels');
  module_load_include('inc', 'globallink_interface', 'globallink_interface');
  module_load_include('inc', 'globallink_menu', 'globallink_menu');
  module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
  module_load_include('inc', 'globallink_webform', 'globallink_webform');
  module_load_include('inc', 'globallink_beans', 'globallink_beans');
  module_load_include('inc', 'globallink_file_entity', 'globallink_file_entity');
  module_load_include('inc', 'globallink_commerce', 'globallink_commerce');
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
  ctools_include('ajax');
  ctools_include('modal');
  ctools_modal_add_js();
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_css($module_path . '/css/globallink_active_submissions.css');
  $sub_rid = arg(4);
  $sub_sql = db_select('globallink_submission', 'gs');
  $sub_sql
    ->condition('rid', $sub_rid, '=');
  $sub_sql
    ->fields('gs');
  $sub_sql_result = $sub_sql
    ->execute()
    ->fetchAll();
  $submission_row = $sub_sql_result[0];
  $form = array();
  $breadcrumb = array();
  $breadcrumb[] = l('Home', '');
  $breadcrumb[] = l('Administration', 'admin');
  $breadcrumb[] = l('Globallink', 'admin/globallink-translations');
  $breadcrumb[] = l('Submissions', 'admin/globallink-translations/workbench');
  $breadcrumb[] = $submission_row->submission;
  $breadcrumb[] = $submission_row->sub_target_lang_name;
  drupal_set_breadcrumb($breadcrumb);
  $back_link = str_replace('"', '\\"', l('WORKBENCH', 'admin/globallink-translations/workbench'));
  drupal_add_js('jQuery(document).ready(function() {jQuery("ul.tabs.secondary li").each(function() { console.log(jQuery(this).text());if((jQuery(this).text().indexOf("Active") >= 0 || jQuery(this).text().indexOf("Completed") >= 0)) { jQuery(this).css("display", "none");  } });  });', 'inline');
  drupal_add_js('jQuery(document).ready(function() {
      jQuery(".tabs-secondary").prepend( "<div style=\'width: 30%; float: left;\'>' . '<span><b>' . $back_link . ' » </b></span>' . '<b>' . $submission_row->submission . '</b></div>" );
    });', 'inline');
  $page_count = TPT_PAGER_LIMIT;
  if (isset($_SESSION['globallink_all_active_page_count'])) {
    $page_count = $_SESSION['globallink_all_active_page_count'][0];
  }
  $header = array(
    'sub_target_lang_name' => array(
      //'field' => 'submission',
      'data' => t('Target Language'),
    ),
    'entity_type' => array(
      'field' => 'entity_type_name',
      'data' => t('Entity Type'),
    ),
    'type' => array(
      'field' => 'object_type_name',
      'data' => t('Type'),
    ),
    'title' => array(
      'field' => 'object_title',
      'data' => t('Title'),
    ),
    'status' => array(
      'field' => 'target_status',
      'data' => t('Status'),
    ),
    'timestamp' => array(
      'field' => 'target_last_updated',
      'data' => t('Last Updated'),
    ),
    'operation' => array(
      'data' => t('Operations'),
    ),
  );
  if (variable_get('globallink_enable_preview', 1)) {
    $header['preview'] = t('Preview');
  }
  $filter_status = '[active]';
  if ($submission_row->status == 'Translation Imported') {
    $filter_status = '[completed]';
  }
  if (!empty($_SESSION['globallink_all_receive_filter_status'])) {
    $filter_status = $_SESSION['globallink_all_receive_filter_status'];
  }
  $status_arr = array();
  if ($filter_status == '[active]') {
    $status_arr = array(
      GLOBALLINK_STATUS_TRANSLATION_SENT,
      GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
      GLOBALLINK_STATUS_TRANSLATION_ERROR,
    );
  }
  elseif ($filter_status == '[completed]') {
    $status_arr = array(
      GLOBALLINK_STATUS_TRANSLATION_IMPORTED,
      GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
    );
  }
  else {
    $status_arr = array(
      $filter_status,
    );
  }
  $documents = array();
  $type = arg(3);
  $details = array();
  $details['sub_rid'] = arg(4);
  $details['type'] = $type;
  $details['target_lang'] = arg(5);
  if ($type == 'all') {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif ($type == GLOBALLINK_ENTITY_TYPE_NODE) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', 'Node', '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_block') && $type == GLOBALLINK_ENTITY_TYPE_BLOCK) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_BLOCK, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_entity') && $type == GLOBALLINK_ENTITY_TYPE_ENTITY) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_ENTITY, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_fieldable_panels') && $type == 'fieldable_panels') {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_FPP, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_interface') && $type == GLOBALLINK_ENTITY_TYPE_INTERFACE) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_INTERFACE, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_menu') && $type == GLOBALLINK_ENTITY_TYPE_MENU) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_MENU, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_taxonomy') && $type == GLOBALLINK_ENTITY_TYPE_TAXONOMY) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_TAXONOMY, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_webform') && $type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_WEBFORM, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_beans') && $type == GLOBALLINK_ENTITY_TYPE_BEAN) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_BEAN, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_commerce') && $type == 'commerce') {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_COM, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  elseif (module_exists('globallink_file_entity') && $type == GLOBALLINK_ENTITY_TYPE_FILE_ENTITY) {
    $query_doc = db_select('globallink_document', 'gd')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort')
      ->orderByHeader($header);
    $query_doc
      ->fields('gd');
    $query_doc
      ->condition('submission_rid', $submission_row->rid, '=');
    $query_doc
      ->condition('entity_type', GLOBALLINK_ENTITY_TYPE_FILE_ENTITY, '=');
    $query_doc
      ->condition('target_status', $status_arr, 'IN');
    $documents = $query_doc
      ->execute()
      ->fetchAll();
  }
  $rows = array();
  if (isset($documents) && count($documents) > 0) {
    foreach ($documents as $item) {
      $title = $item->object_title;
      if ($item->entity_type == GLOBALLINK_ENTITY_TYPE_NODE || $item->entity_type == GLOBALLINK_ENTITY_TYPE_ENTITY) {
        $title = l(globallink_format_display_string($item->object_title), 'node/' . $item->object_id);
      }
      $sync = '';
      $import = '';
      if ($item->target_status != GLOBALLINK_STATUS_TRANSLATION_IMPORTED && $item->target_status != GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED) {
        $import_variables = array(
          'path' => drupal_get_path('module', 'globallink') . '/css/import-sub16.png',
          'width' => '16px',
          'height' => '16px',
          'attributes' => array(
            'title' => 'Import',
            'class' => array(
              'gl-workbench-row-link',
            ),
          ),
        );
        $import_image_html = theme_image($import_variables);
        $import = '<span title="Imports translated content" style="display:inline-block; width: 16px;"></span>' . l('Import', request_path() . '/import/' . $item->rid, array(
          'html' => TRUE,
        ));
        $sync_variables = array(
          'path' => drupal_get_path('module', 'globallink') . '/css/if_refresh_293697.png',
          'width' => '16px',
          'height' => '16px',
          'attributes' => array(
            'title' => 'Sync',
            'class' => array(
              'gl-workbench-row-link',
            ),
          ),
        );
        $sync_image_html = theme_image($sync_variables);
        $sync = '<span title="Gets latest status" style="display:inline-block; width: 16px;"></span>' . l('Sync', request_path() . '/sync/' . $item->rid, array(
          'html' => TRUE,
        ));
      }
      elseif ($item->target_status == GLOBALLINK_STATUS_TRANSLATION_IMPORTED) {
        $import_variables = array(
          'path' => drupal_get_path('module', 'globallink') . '/css/import-sub16.png',
          'width' => '16px',
          'height' => '16px',
          'attributes' => array(
            'title' => 'Re-Import',
            'class' => array(
              'gl-workbench-row-link',
            ),
          ),
        );
        $import_image_html = theme_image($import_variables);
        $import = '<span title="Imports translated content" style="display:inline-block; width: 16px;"></span>' . l('Re - Import', request_path() . '/import/' . $item->rid, array(
          'html' => TRUE,
        ));
        $sync_variables = array(
          'path' => drupal_get_path('module', 'globallink') . '/css/archive16.png',
          'width' => '16px',
          'height' => '16px',
          'attributes' => array(
            'title' => 'Archive',
            'class' => array(
              'gl-workbench-row-link',
            ),
          ),
        );
        $sync_image_html = theme_image($sync_variables);
        $sync = '<span title="Gets latest status" style="display:inline-block; width: 16px;"></span>';
      }
      $link = '<div style="text-align: left;">' . $sync . $import . '</div>';
      unset($check_status);
      if ($submission_row->status === 'Translation Imported') {
        $check_status = TRUE;
      }
      $rows[$item->rid] = array(
        'sub_target_lang_name' => $submission_row->sub_target_lang_name,
        'entity_type' => $item->entity_type_name,
        'type' => isset($item->object_type) ? $item->object_type : '',
        'title' => isset($title) ? $title : $item->object_id,
        'status' => $item->target_status,
        'timestamp' => format_date($item->target_last_updated, 'custom', 'Y-m-d H:i:s'),
        'operation' => $link,
      );
      if (variable_get('globallink_enable_preview', 1)) {
        $rows[$item->rid]['preview'] = isset($check_status) ? t('Target imported') : globallink_make_preview_link('Preview', $details, $item->rid);
      }
    }
  }
  if ($submission_row->status != 'Translation Imported') {
    $form['submit_publish_submission'] = array(
      '#type' => 'submit',
      '#value' => t('Import'),
      '#prefix' => '<div class="form-operations">',
      '#attributes' => array(
        'title' => t('Import'),
        'class' => array(
          'globallink-edit-submit-publish-submission',
        ),
      ),
    );
    $form['submit_import_submission'] = array(
      '#type' => 'submit',
      '#value' => t('Sync'),
      '#suffix' => '</div>',
      '#attributes' => array(
        'title' => t('Sync Status'),
        'class' => array(
          'globallink-edit-submit-import-submission',
        ),
      ),
    );
  }
  else {
    $form['submit_publish_submission'] = array(
      '#type' => 'submit',
      '#value' => t('Re-Import'),
      '#prefix' => '<div class="form-operations">',
      '#attributes' => array(
        'title' => t('Import'),
        'class' => array(
          'globallink-edit-submit-publish-submission',
        ),
      ),
      '#suffix' => '</div>',
    );
  }
  if (arg(4) != "") {
    $form['table'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#empty' => t('No items available'),
      '#attributes' => array(),
    );
    $form['pager'] = array(
      '#markup' => theme('pager'),
    );
  }
  return $form;
}

/**
 * Handles submission of active entity form.
 */
function globallink_all_active_form_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  $pd4 = globallink_get_project_director_details();

  //$rids = array_filter($form_state['values']['table']);
  module_load_include('inc', 'globallink', 'globallink_entity');
  $submission_rid = arg(4);
  $target_locale = arg(5);
  $entity_type = arg(3);
  $select_qry = db_select('globallink_submission', 'gs');
  $select_qry
    ->fields('gs', array(
    'status',
  ));
  $select_qry
    ->condition('rid', $submission_rid, '=');
  $result_set = $select_qry
    ->execute();
  foreach ($result_set as $res) {
    $submission_status = $res->status;
  }
  $query = db_select('globallink_document', 'gd');
  $query
    ->fields('gd', array(
    'rid',
  ));
  $query
    ->condition('submission_rid', $submission_rid, '=');
  $query
    ->condition('target_lang_code', $target_locale, '=');
  if ($submission_status == 'Translation Imported') {
    $query
      ->condition('target_status', array(
      GLOBALLINK_STATUS_TRANSLATION_IMPORTED,
      GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
      GLOBALLINK_STATUS_TRANSLATION_ERROR,
    ), 'IN');
  }
  else {
    $query
      ->condition('target_status', array(
      GLOBALLINK_STATUS_TRANSLATION_SENT,
      GLOBALLINK_STATUS_TRANSLATION_ERROR,
      GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
    ), 'IN');
  }
  if ($entity_type != 'all') {
    $query
      ->condition('entity_type', $entity_type, '=');
  }
  $results = $query
    ->execute();
  if (!$results
    ->rowCount()) {
    drupal_set_message("No Results available");
  }
  else {
    foreach ($results as $value) {
      $document_rids[] = $value->rid;
    }
    switch ($op) {
      case t('Re-Import'):
      case t('Import'):

        //will work as background process if module available, else regular form submit
        try {
          if (module_exists('background_process') && module_exists('background_batch')) {
            $operations[] = array(
              'globallink_background_import',
              array(
                $pd4,
                $submission_rid,
                $document_rids,
              ),
            );
            $batch = array(
              'title' => t('Importing ' . $submission_rid . ' for locale ' . $target_locale),
              'operations' => $operations,
              'error_message' => t('Import has encountered an error for ' . $submission_rid . ' for locale ' . $target_locale),
              'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
            );
            $batch['progressive'] = FALSE;
            batch_set($batch);
            background_batch_process_batch('admin/globallink-translations/workbench');
            drupal_set_message('Translated files are being imported in the background. Please refresh the page for the progress. For more information check watchdog.');
          }
          else {
            module_load_include('inc', 'globallink', 'globallink_background_jobs');
            globallink_background_import($pd4, $submission_rid, $document_rids);
            drupal_set_message('The translated files have been imported');
          }
        } 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(),
          )));
        }
        break;
      case t('Sync'):

        //will be a background process if module background process available.
        try {
          if (module_exists('background_process') && module_exists('background_batch')) {
            $operations[] = array(
              'globallink_background_pull',
              array(
                $pd4,
                $submission_rid,
                $document_rids,
              ),
            );
            $batch = array(
              'title' => t('Sync translations'),
              'operations' => $operations,
              'error_message' => t('Sync has encountered an error'),
              'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
            );
            batch_set($batch);
            $batch['progressive'] = FALSE;
            background_batch_process_batch('admin/globallink-translations/workbench');
            drupal_set_message('Translated files are being synced in the background. Please refresh the page for the progress.');
          }
          else {
            module_load_include('inc', 'globallink', 'globallink_background_jobs');
            globallink_background_pull($pd4, $submission_rid, $document_rids);
            drupal_set_message('Documents have been synced to the latest available status');
          }
        } 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(),
          )));
        }
        break;
    }
  }
}
function globallink_upload_translation_all_form() {
  $form['translation_file'] = array(
    '#type' => 'file',
    '#name' => 'files[]',
    '#title' => t('Select Translation File'),
    '#attributes' => array(
      'multiple' => 'multiple',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Upload'),
  );
  return $form;
}
function globallink_upload_translation_all_form_validate($form, &$form_state) {
  if (!empty($_SESSION['globallink_globalLink_arr'])) {
    $globallink_arr = unserialize($_SESSION['globallink_globalLink_arr']);
  }
  else {
    $globallink_arr = array();
  }
  $num_files = count($_FILES['files']['name']);
  for ($i = 0; $i < $num_files; $i++) {
    $attr = '';
    $attr_val = '';
    $data = array();
    $file = file_save_upload($i, array(
      'file_validate_extensions' => array(
        'xml',
      ),
      FILE_EXISTS_RENAME,
    ));
    if ($file) {
      $file->status = 1;
      $xml = file_get_contents($file->uri);
      $dom = new DomDocument();
      $dom->preserveWhiteSpace = FALSE;
      $dom
        ->loadXML($xml);
      $contents = $dom
        ->getElementsByTagName('content');
      foreach ($contents as $content) {
        foreach ($content->attributes as $attr_name => $attr_node) {
          if ($attr_name == 'nid' || $attr_name == 'bid' || $attr_name == 'fpid' || $attr_name == 'lid' || $attr_name == 'mlid' || $attr_name == 'pid') {
            $attr = $attr_name;
            $attr_val = $attr_node->value;
          }
        }
      }
      $tbl_record = validate_submission($attr, $attr_val);
      if (!empty($tbl_record)) {
        $data[] = $tbl_record[1];
        $form_state['values']['upload_data'][$i]['type'] = $tbl_record[0];
        $form_state['values']['upload_data'][$i]['data'] = $tbl_record[1];
        $form_state['values']['upload_data'][$i]['file'] = $file;
        foreach ($data as $val) {
          if ($val->status == GLOBALLINK_STATUS_TRANSLATION_IMPORTED) {
            form_set_error('', $file->filename . t(' file can not upload. Translation is already published.'));
          }
        }
      }
      else {
        drupal_set_message(t($file->filename . ' file is not a part of this submission.'), 'warning');
      }
    }
    else {
      form_set_error('translation_file', t('No file was uploaded.'));
    }
  }
}
function globallink_upload_translation_all_form_submit($form, &$form_state) {
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink_entity', 'globallink_entity');
  module_load_include('inc', 'globallink', 'globallink');
  $num_files = '';
  if (isset($form_state['values']['upload_data'])) {
    $num_files = count($form_state['values']['upload_data']);
  }
  for ($i = 0; $i < $num_files; $i++) {
    $globallink = array();
    $type = $form_state['values']['upload_data'][$i]['type'];
    $file_path = $form_state['values']['upload_data'][$i]['file']->uri;
    $file_name = $form_state['values']['upload_data'][$i]['file']->filename;
    $contents = file_get_contents($file_path);
    $globallink = $form_state['values']['upload_data'][$i]['data'];
    $globallink->targetXML = $contents;
    if ($type == GLOBALLINK_ENTITY_TYPE_NODE) {
      globallink_import_node($globallink);
      globallink_update_status($globallink);
      drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
    }
    else {
      if ($type == GLOBALLINK_ENTITY_TYPE_ENTITY) {
        globallink_entity_update_entity($globallink);
        globallink_entity_update_status($globallink);
        drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
      }
      else {
        if ($type == GLOBALLINK_ENTITY_TYPE_BLOCK) {
          module_load_include('inc', 'globallink_block', 'globallink_block');
          publish_block($globallink);
          drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
        }
        else {
          if ($type == GLOBALLINK_ENTITY_TYPE_FPP) {
            module_load_include('inc', 'globallink_fieldable_panels', 'globallink_fieldable_panels');
            publish_fpanels($globallink);
            drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
          }
          else {
            if ($type == GLOBALLINK_ENTITY_TYPE_INTERFACE) {
              module_load_include('inc', 'globallink_interface', 'globallink_interface');
              publish_interface($globallink);
              drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
            }
            else {
              if ($type == GLOBALLINK_ENTITY_TYPE_MENU) {
                module_load_include('inc', 'globallink_menu', 'globallink_menu');
                publish_menu($globallink);
                drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
              }
              else {
                if ($type == GLOBALLINK_ENTITY_TYPE_TAXONOMY) {
                  module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
                  publish_taxonomy($globallink);
                  drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
                }
                else {
                  if ($type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
                    module_load_include('inc', 'globallink_webform', 'globallink_webform');
                    publish_webform($globallink);
                    drupal_set_message(t($file_name . ' file uploaded and published successfully.'));
                  }
                  else {
                    if ($type == GLOBALLINK_ENTITY_TYPE_BEAN) {
                      module_load_include('inc', 'globallink_beans', 'globallink_beans');
                      publish_bean($globallink);
                      drupal_set_message(t($file_name . 'file uploaded and published successfully'));
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
function validate_submission($attr, $attr_val) {
  $output = array();
  if ($attr == 'nid') {
    $query = db_select('globallink_core', 'gc');
    $query
      ->addField('gc', 'source', 'sourceLocale');
    $query
      ->addField('gc', 'target', 'targetLocale');
    $query = $query
      ->fields('gc', array(
      'nid',
      'vid',
      'status',
      'submission',
    ))
      ->condition('nid', $attr_val, '=');
    $result = $query
      ->execute()
      ->fetchAll();
    if (count($result) > 0) {
      foreach ($result as $val) {
        if ($val->submission == arg(4) && $val->targetLocale == arg(5)) {
          $output[] = "node";
          $output[] = $val;
        }
      }
    }
    else {
      $query = db_select('globallink_core_entity', 'gce');
      $query
        ->addField('gce', 'source', 'sourceLocale');
      $query
        ->addField('gce', 'target', 'targetLocale');
      $query = $query
        ->fields('gce', array(
        'nid',
        'vid',
        'status',
        'submission',
      ))
        ->condition('nid', $attr_val, '=');
      $result = $query
        ->execute()
        ->fetchAll();
      if (count($result) > 0) {
        foreach ($result as $val) {
          if ($val->submission == arg(4) && $val->targetLocale == arg(5)) {
            $output[] = "entity";
            $output[] = $val;
          }
        }
      }
    }
  }
  else {
    if ($attr == 'bid') {
      $query = db_select('globallink_core_block', 'gcb');
      $query
        ->addField('gcb', 'source', 'sourceLocale');
      $query
        ->addField('gcb', 'target', 'targetLocale');
      $query
        ->addField('gcb', 'submission', 'submissionName');
      $query
        ->addField('gcb', 'document_ticket', 'documentTicket');
      $query = $query
        ->fields('gcb', array(
        'status',
      ))
        ->condition('object_id', $attr_val, '=');
      $result = $query
        ->execute()
        ->fetchAll();
      if (count($result) > 0) {
        foreach ($result as $val) {
          if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
            $output[] = "block";
            $output[] = $val;
          }
        }
      }
      else {
        $query = db_select('globallink_core_taxonomy', 'gct');
        $query
          ->addField('gct', 'source', 'sourceLocale');
        $query
          ->addField('gct', 'target', 'targetLocale');
        $query
          ->addField('gct', 'submission', 'submissionName');
        $query
          ->addField('gct', 'document_ticket', 'documentTicket');
        $query = $query
          ->fields('gct', array(
          'status',
        ))
          ->condition('object_id', $attr_val, '=');
        $result = $query
          ->execute()
          ->fetchAll();
        if (count($result) > 0) {
          foreach ($result as $val) {
            if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
              $output[] = "taxonomy";
              $output[] = $val;
            }
          }
        }
      }
    }
    else {
      if ($attr == 'fpid') {
        $query = db_select('globallink_core_fieldable_panels', 'gcfp');
        $query
          ->addField('gcfp', 'source', 'sourceLocale');
        $query
          ->addField('gcfp', 'target', 'targetLocale');
        $query
          ->addField('gcfp', 'submission', 'submissionName');
        $query
          ->addField('gcfp', 'document_ticket', 'documentTicket');
        $query = $query
          ->fields('gcfp', array(
          'status',
        ))
          ->condition('fpid', $attr_val, '=');
        $result = $query
          ->execute()
          ->fetchAll();
        if (count($result) > 0) {
          foreach ($result as $val) {
            if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
              $output[] = "fieldable_panels";
              $output[] = $val;
            }
          }
        }
      }
      else {
        if ($attr == 'lid') {
          $query = db_select('globallink_core_interface', 'gci');
          $query
            ->addField('gci', 'source', 'sourceLocale');
          $query
            ->addField('gci', 'target', 'targetLocale');
          $query
            ->addField('gci', 'submission', 'submissionName');
          $query
            ->addField('gci', 'document_ticket', 'documentTicket');
          $query = $query
            ->fields('gci', array(
            'status',
          ))
            ->condition('object_id', $attr_val, '=');
          $result = $query
            ->execute()
            ->fetchAll();
          if (count($result) > 0) {
            foreach ($result as $val) {
              if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
                $output[] = "interface";
                $output[] = $val;
              }
            }
          }
        }
        else {
          if ($attr == 'mlid') {
            $query = db_select('globallink_core_menu', 'gcm');
            $query
              ->addField('gcm', 'source', 'sourceLocale');
            $query
              ->addField('gcm', 'target', 'targetLocale');
            $query
              ->addField('gcm', 'submission', 'submissionName');
            $query
              ->addField('gcm', 'document_ticket', 'documentTicket');
            $query = $query
              ->fields('gcm', array(
              'status',
            ))
              ->condition('object_id', $attr_val, '=');
            $result = $query
              ->execute()
              ->fetchAll();
            if (count($result) > 0) {
              foreach ($result as $val) {
                if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
                  $output[] = "menu";
                  $output[] = $val;
                }
              }
            }
          }
          else {
            if ($attr == 'pid') {
              $query = db_select('globallink_core_webform', 'gcw');
              $query
                ->addField('gcw', 'source', 'sourceLocale');
              $query
                ->addField('gcw', 'target', 'targetLocale');
              $query
                ->addField('gcw', 'submission', 'submissionName');
              $query
                ->addField('gcw', 'document_ticket', 'documentTicket');
              $query = $query
                ->fields('gcw', array(
                'status',
              ))
                ->condition('parent_id', $attr_val, '=');
              $result = $query
                ->execute()
                ->fetchAll();
              if (count($result) > 0) {
                foreach ($result as $val) {
                  if ($val->submissionName == arg(4) && $val->targetLocale == arg(5)) {
                    $output[] = "webform";
                    $output[] = $val;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return $output;
}

/**
 * Function to create Preview link
 */
function globallink_make_preview_link($link_text = '', $details, $id) {
  $sub_rid = $details['sub_rid'];
  $type = $details['type'];
  $target_lang = $details['target_lang'];
  drupal_add_js(array(
    'my-modal-style' => array(
      'modalSize' => array(
        'type' => 'fixed',
        'width' => 700,
        'height' => 400,
      ),
      'animation' => 'fadeIn',
    ),
  ), 'setting');

  // Set a default value if no text in supplied.
  if (empty($link_text)) {
    $link_text = 'Preview';
  }
  return '<div id="preview-link" style="text-align: left;" title="Click to Preview">' . l($link_text, 'admin/globallink-translations/workbench/' . $type . '/' . $sub_rid . '/' . $target_lang . '/preview/' . $id . '/nojs', array(
    'attributes' => array(
      'class' => 'ctools-use-modal ctools-modal-my-modal-style',
    ),
  )) . '</div>';
}

/**
 * Helper function
 */
function globallink_preview($ajax) {
  if ($ajax) {
    ctools_include('ajax');
    ctools_include('modal');
    $form_state = array(
      'ajax' => TRUE,
      'title' => t('Preview'),
    );

    // Use ctools to generate ajax instructions for the browser to create a form in a modal popup.
    $output = ctools_modal_form_wrapper('globallink_content_preview_content', $form_state);

    // If the form has been submitted, there may be additional instructions such as dismissing the modal popup.
    if (!empty($form_state['ajax_commands'])) {
      $output = $form_state['ajax_commands'];
    }

    // Return the ajax instructions to the browser via ajax_render().
    print ajax_render($output);
    drupal_exit();
  }
  else {
    return drupal_get_form('globallink_content_preview_content');
  }
}

/**
 * Helper function
 */
function globallink_content_preview_content() {
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_settings');
  $pd4 = globallink_get_project_director_details();
  $type = '';
  $name = '';
  $doc_id = arg(7);
  $sub_rid = arg(4);
  $target_locale = arg(5);
  $output = "";
  $output .= "<table><tr><th>Fields</th><th>Translated Contents</th></tr>";
  $sub_sql = db_select('globallink_submission', 'gs');
  $sub_sql
    ->condition('rid', $sub_rid, '=');
  $sub_sql
    ->fields('gs');
  $sub_sql_result = $sub_sql
    ->execute()
    ->fetchAll();
  $submission_row = $sub_sql_result[0];
  $submission_ticket = $submission_row->submission_ticket;
  if (!check_if_submission_cancelled_or_deleted($pd4, $submission_ticket)) {
    $sql = db_select('globallink_document', 'gd');
    $sql
      ->fields('gd');
    $sql
      ->condition('gd.rid', $doc_id, '=');
    $sql_results = $sql
      ->execute()
      ->fetchAll();
    foreach ($sql_results as $row) {
      $document_tickets[] = $row->document_ticket;
    }
    $globallink_arr = globallink_get_ready_translations_for_documents($pd4, $document_tickets);
    if (count($globallink_arr) == 0) {
      drupal_set_message("No completed targets were found. Please try again after some time.");
      return;
    }
    foreach ($globallink_arr as $globallink) {
      if ($globallink->targetLocale == $target_locale) {
        $globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
        $xml = new SimpleXMLElement($globallink->targetXML);
        $entity_type = $globallink->type;
        $name = 'name';
        $type = 'field';
        $metatag = 'metatag';
        $title = 'title';
        $image = 'field_image';
        switch ($entity_type) {
          case GLOBALLINK_ENTITY_TYPE_WEBFORM:
            $type = 'webform';
            break;
          case GLOBALLINK_ENTITY_TYPE_MENU:
            $type = 'menu';
            break;
          case GLOBALLINK_ENTITY_TYPE_INTERFACE:
            $type = 'interface';
            break;
          case GLOBALLINK_ENTITY_TYPE_BLOCK:
            $type = 'block';
            break;
          case GLOBALLINK_ENTITY_TYPE_FPP:
            $name = 'field';
            break;
          case GLOBALLINK_ENTITY_TYPE_BEAN:
            $name = 'field_name';
            break;
          case GLOBALLINK_ENTITY_TYPE_FILE_ENTITY:
            $name = 'field';
            break;
          case GLOBALLINK_ENTITY_TYPE_COM:
            $name = 'field_name';
            break;
          default:
            $name = 'label';
            break;
        }
        $title_cnt = $xml->{$title}
          ->count();
        if ($title_cnt > 0) {
          foreach ($xml->title as $e) {
            $title_value = (string) $e;
            $title_label = 'title';
            $output .= "<tr><td><strong>" . ucfirst($title_label) . "</strong></td><td>" . $title_value . "</td></tr>";
          }
        }
        $elem = $xml->{$type}
          ->count();
        if ($elem > 0) {
          foreach ($xml->{$type} as $element) {
            $value = (string) $element;
            $label = (string) $element
              ->attributes()->{$name};
            $output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
          }
        }
        $metatag_cnt = $xml->{$metatag}
          ->count();
        if ($metatag_cnt > 0) {
          foreach ($xml->{$metatag} as $element) {
            $name = 'label';
            $value = (string) $element;
            $label = (string) $element
              ->attributes()->{$name};
            $output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
          }
        }
        if ($metatag_cnt == 0 && $elem == 0) {
          drupal_set_message("No content available");
        }
        $image_cnt = $xml->{$image}
          ->count();
        if ($image_cnt > 0) {
          foreach ($xml->{$image} as $element) {
            $type = (string) $element
              ->attributes()->type;
            $value = (string) $element;
            if ($type == 'alt') {
              $type = 'alternate text';
            }
            $name = (string) $element
              ->attributes()->field_name;
            $label = $name . '-' . $type;
            $output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
          }
        }
      }
    }
  }
  $output .= "</table>";
  $form['preview'] = array(
    '#markup' => $output,
  );
  return $form;
}

Functions

Namesort descending Description
globallink_all_active_filter_form Builds form to filter GlobalLink submissions
globallink_all_active_filter_form_submit Handles submission of filter form.
globallink_all_active_form Builds form to show all active entity submissions.
globallink_all_active_form_submit Handles submission of active entity form.
globallink_all_active_pager_form Builds form to add pagination to entity send dashboard.
globallink_all_active_pager_form_submit Handles submission of pager form.
globallink_all_active_submissions Builds forms on entity active submissions dashboard.
globallink_content_preview_content Helper function
globallink_dashboard_active_submissions_page
globallink_make_preview_link Function to create Preview link
globallink_node_active_pager_form Builds form to add pagination to GlobalLink send dashboard.
globallink_preview Helper function
globallink_upload_translation_all_form
globallink_upload_translation_all_form_submit
globallink_upload_translation_all_form_validate
validate_submission