You are here

function globallink_interface_receive_form in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 globallink_interface/globallink_interface_receive.inc \globallink_interface_receive_form()

Builds form to receive an interface submission.

1 string reference to 'globallink_interface_receive_form'
globallink_interface_receive_submissions in globallink_interface/globallink_interface_receive.inc
Builds forms on interface receive dashboard.

File

globallink_interface/globallink_interface_receive.inc, line 272

Code

function globallink_interface_receive_form() {
  module_load_include('inc', 'globallink', 'globallink_settings');
  $form = array();
  if (!empty($_SESSION['transpefect_interface_receive_type'])) {
    $type = $_SESSION['transpefect_interface_receive_type'];
  }
  $globallink_arr = array();
  if (!empty($_SESSION['globallink_interface_globalLink_arr'])) {
    $globallink_arr = unserialize($_SESSION['globallink_interface_globalLink_arr']);
  }
  $page_count = isset($_SESSION['globallink_interface_receive_page_count']) ? $_SESSION['globallink_interface_receive_page_count'][0] : TPT_PAGER_LIMIT;
  $rows = array();
  $filter_lang = '[any]';
  if (!empty($_SESSION['globallink_interface_receive_filter_language'])) {
    $filter_lang = $_SESSION['globallink_interface_receive_filter_language'];
  }
  if (isset($globallink_arr) && is_array($globallink_arr)) {
    foreach ($globallink_arr as $key => &$globallink) {
      if ($filter_lang != '[any]' && $globallink->targetLocale != $filter_lang) {
        unset($globallink_arr[$key]);
      }
    }
  }
  if (isset($globallink_arr) && is_array($globallink_arr)) {
    $filter_status = '[any]';
    if (!empty($_SESSION['globallink_interface_receive_filter_status'])) {
      $filter_status = $_SESSION['globallink_interface_receive_filter_status'];
    }
    $header = array(
      'submissionName' => t('Submission'),
      'sourceLocale' => t('Source Language'),
      'targetLocale' => t('Target Language'),
      'source' => 'Source',
      'status' => t('Status'),
    );
    if (variable_get('globallink_enable_preview', 1)) {
      $header['preview'] = '';
    }
    $count = 1;
    $rid_arr = array();
    foreach ($globallink_arr as $key => &$globallink) {
      if ($globallink->type != 'interface') {
        continue;
      }
      $pd4 = globallink_get_project_director_details();
      $target_xml = '';
      try {
        $target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
      } catch (Exception $e) {
        form_set_error('', t('Error: @message', array(
          '@message' => $e
            ->getMessage(),
        )));
      }
      $interface_arr = globallink_interface_get_translated_items($target_xml);
      if (count($interface_arr) > 0) {
        $lid = $interface_arr['lid'];
        $title = '';
        $status = globallink_interface_get_translation_status($lid, $globallink->targetLocale, $title);
        if ($status == 'Source Deleted') {
          $globallink->sourceDeleted = TRUE;
        }
        if ($filter_status != '[any]' && $status != $filter_status) {
          unset($globallink_arr[$key]);
          continue;
        }
        $filter_submission = '[any]';
        if (!empty($_SESSION['globallink_interface_receive_filter_submission'])) {
          $filter_submission = $_SESSION['globallink_interface_receive_filter_submission'];
        }
        if ($filter_submission != '[any]' && $globallink->submissionName != $filter_submission) {
          unset($globallink_arr[$key]);
          continue;
        }
        if (variable_get('globallink_enable_preview', 1)) {
          if ($status != 'Source Deleted') {
            $tpt_row_id = globallink_interface_get_row_id_from_submission($globallink->submissionTicket, $globallink->documentTicket, $globallink->targetLocale);
            if ($tpt_row_id) {
              $rid_arr['tpt_content_div_' . $key] = $tpt_row_id;
            }
          }
        }
        $source_name = globallink_get_drupal_locale_name($globallink->sourceLocale);
        $target_name = globallink_get_drupal_locale_name($globallink->targetLocale);
        $rows[$key] = array(
          'submissionName' => $globallink->submissionName,
          'sourceLocale' => $source_name,
          'targetLocale' => $target_name,
          'source' => $title,
          'status' => $status,
        );
        if (variable_get('globallink_enable_preview', 1)) {
          $rows[$key]['preview'] = $status != 'Source Deleted' ? l(t('Preview Translations'), 'javascript:void(0)', array(
            'fragment' => '',
            'external' => TRUE,
            'attributes' => array(
              'id' => 'tpt_content_link_' . $key,
            ),
          )) : '';
        }
        $count++;
      }
    }
    $form['table'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => globallink_pager_array_splice($rows, $page_count),
      '#empty' => t('No items available'),
    );
    $form['pager'] = array(
      '#markup' => theme('pager'),
    );
    if (variable_get('globallink_enable_preview', 1)) {
      $lcount = 1;
      $div_arr = array();
      foreach ($rid_arr as $key => $rid) {
        if (isset($rid)) {
          $lcount = str_replace('tpt_content_div_', '', $key);
          $form['tpt_content_div_' . $lcount] = array(
            '#type' => 'markup',
            '#markup' => '',
            '#prefix' => '<div id="tpt_content_div_' . $lcount . '" style="display: none;">',
            '#suffix' => '</div>',
          );
          $div_arr['tpt_content_link_' . $lcount] = 'tpt_content_div_' . $lcount;
        }
      }
      drupal_add_js(array(
        'globallink' => array(
          'popup' => $div_arr,
          'previewpath' => base_path() . 'admin/globallink-translations/receiveTranslation/interface/preview',
          'rids' => $rid_arr,
        ),
      ), 'setting');
    }
    if ($count > 1) {
      $form['submit_update_selected'] = array(
        '#type' => 'submit',
        '#value' => t('Update Selected'),
      );
      $form['submit_update_all'] = array(
        '#type' => 'submit',
        '#value' => t('Update All'),
      );
      $form['submit_clear_deleted_hidden'] = array(
        '#type' => 'submit',
        '#value' => t('Clear Deleted Records'),
        '#attributes' => array(
          'style' => 'display:none;',
          'disabled' => 'true',
        ),
      );
      $form['submit_clear_deleted'] = array(
        '#type' => 'submit',
        '#value' => t('Clear Deleted Records'),
      );
    }
    $last_refreshed = '';
    if (isset($_SESSION['globallink_interface_globalLink_arr_last_refreshed'])) {
      $last_refreshed = $_SESSION['globallink_interface_globalLink_arr_last_refreshed'];
    }
    $form['submit_refresh_hidden'] = array(
      '#type' => 'submit',
      '#value' => t('Refresh Page'),
      '#prefix' => '<BR/>',
      '#attributes' => array(
        'style' => 'display:none;',
        'disabled' => 'true',
      ),
    );
    $form['submit_refresh'] = array(
      '#type' => 'submit',
      '#value' => t('Refresh Page'),
    );
    $form['markup'] = array(
      '#type' => 'markup',
      '#markup' => 'Last refreshed : ' . $last_refreshed,
    );
  }
  drupal_add_js('jQuery(document).ready(function(){jQuery("#edit-submit-clear-deleted").click(function(){jQuery("#edit-submit-clear-deleted").hide();jQuery("#edit-submit-clear-deleted-hidden").css("display","inline");});});', 'inline');
  drupal_add_js('jQuery(document).ready(function(){jQuery("#edit-submit-refresh").click(function(){jQuery("#edit-submit-refresh").hide();jQuery("#edit-submit-refresh-hidden").css("display","inline");});});', 'inline');
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_library('system', 'ui.dialog');
  drupal_add_css($module_path . '/css/globallink.css');
  drupal_add_js($module_path . '/globallink_interface/js/globallink_interface_receive.js');
  return $form;
}