You are here

function globallink_interface_dashboard_form in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_interface/globallink_interface_send.inc \globallink_interface_dashboard_form()
  2. 7.6 globallink_interface/globallink_interface_send.inc \globallink_interface_dashboard_form()

Builds form to create an interface submission.

1 string reference to 'globallink_interface_dashboard_form'
globallink_interface_dashboard_page in globallink_interface/globallink_interface_send.inc
Builds forms on interface send dashboard.

File

globallink_interface/globallink_interface_send.inc, line 254

Code

function globallink_interface_dashboard_form() {
  module_load_include('inc', 'globallink_interface', 'globallink_interface');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_send_translations');
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_js($module_path . '/js/globallink_send_translations.js');
  drupal_add_js(array(
    'globallinkSendTranslations' => array(
      'selectAll' => base_path() . globallink_get_root_menu('create-submission/select_all_js'),
      'selectedPath' => base_path() . globallink_get_root_menu('create-submission/select_id_js'),
      'selectedType' => GLOBALLINK_ENTITY_TYPE_INTERFACE,
      'sessionKey' => 'int_ids',
    ),
  ), 'setting');
  drupal_add_css($module_path . '/css/globallink.css');
  $form = array();
  $default_checked = array();
  if (isset($_SESSION['int_ids'])) {
    $default_checked = $_SESSION['int_ids'];
  }
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  if (isset($locales) && count($locales) > 1) {
    $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $page_count = TPT_PAGER_LIMIT;
    if (isset($_SESSION['globallink_interface_page_count'])) {
      $page_count = $_SESSION['globallink_interface_page_count'][0];
    }
    $default_language = language_default();
    $default = $default_language->language;
    if (!empty($_SESSION['globallink_selected_interface_language'])) {
      $default = $_SESSION['globallink_selected_interface_language'];
    }
    unset($target_lang_arr[globallink_get_locale_code($default)]);
    $t_count = 0;
    foreach ($target_lang_arr as $key => $value) {
      $t_count++;
      if ($t_count % 2 === 0) {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '<BR/>';
      }
      else {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '&nbsp;&nbsp;&nbsp;&nbsp;';
      }
    }
    if (!($query = globallink_interface_get_translate_filter_query())) {
      $query = array(
        'translation' => 'all',
        'language' => 'all',
        'string' => '',
        'group' => 'all',
      );
    }
    $sql_query = db_select('locales_source', 's')
      ->extend('PagerDefault')
      ->limit($page_count);
    $limit_language = NULL;
    if (isset($query['language']) && $query['language'] != 'en' && $query['language'] != 'all') {
      $sql_query
        ->leftJoin('locales_target', 't', 't.lid = s.lid AND t.language = :langcode', array(
        ':langcode' => $query['language'],
      ));
      $limit_language = $query['language'];
    }
    else {
      $sql_query
        ->leftJoin('locales_target', 't', 't.lid = s.lid');
    }
    $header = array(
      'textgroup' => array(
        'data' => t('Text Group'),
        'field' => 's.textgroup',
      ),
      'string' => array(
        'data' => t('String'),
        'field' => 's.location',
      ),
      'active' => t('In Active Submission'),
      'preview' => t('Preview'),
    );
    $sql_query
      ->fields('s', array(
      'source',
      'location',
      'context',
      'lid',
      'textgroup',
    ));
    $sql_query
      ->fields('t', array(
      'translation',
      'language',
    ));
    if (!isset($query['translation'])) {
      $query['translation'] = 'all';
    }
    if (!isset($query['language'])) {
      $query['language'] = 'all';
    }
    if (!isset($query['group'])) {
      $query['group'] = 'all';
    }
    if (!isset($query['string'])) {
      $query['string'] = '';
    }
    switch ($query['translation']) {
      case 'translated':
        $sql_query
          ->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE');
        break;
      case 'untranslated':
        $sql_query
          ->condition(db_and()
          ->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE')
          ->isNull('t.translation'));
        break;
      case 'all':
      default:
        $condition = db_or()
          ->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE');
        if ($query['language'] != 'en') {
          $condition
            ->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE');
        }
        $sql_query
          ->condition($condition);
        break;
    }
    if ($query['group'] != 'all') {
      $sql_query
        ->condition('s.textgroup', $query['group']);
    }
    $sql_query
      ->extend('TableSort')
      ->groupBy('lid')
      ->orderByHeader($header);
    $sort_order = isset($_GET['sort']) ? $_GET['sort'] : '';
    if ($sort_order) {
      $sql_query
        ->orderBy('source', $_GET['sort']);
    }
    $result = $sql_query
      ->execute();
    $interface_results = array();
    $lids = array();
    foreach ($result as $item) {
      array_push($lids, $item->lid);
      array_push($interface_results, $item);
    }
    $groups = module_invoke_all('locale', 'groups');
    $locales = globallink_get_mapped_drupal_locales(FALSE);
    $rows = array();
    $count = 0;
    foreach ($interface_results as $interface) {
      $active = '';
      $active_arr = globallink_interface_get_active_submission_by_id($interface->lid);
      if (!empty($active_arr)) {
        foreach ($active_arr as $active_row) {
          $l_title = globallink_format_display_string($active_row->submission);
          $l_href = 'admin/globallink-translations/workbench/all/' . $active_row->submission_rid . '/' . $active_row->target_lang_code;
          $l_options = array();
          $active .= l($l_title, $l_href, $l_options) . '&nbsp;&nbsp;- &nbsp;&nbsp;' . $active_row->sub_target_lang_name . ' <BR/> ';
        }
      }
      if (!isset($rows[$interface->lid])) {
        $rows[$interface->lid] = array(
          'textgroup' => $groups[$interface->textgroup],
          'string' => check_plain(truncate_utf8($interface->source, 150, FALSE, TRUE)) . '<br /><small>' . $interface->location . '</small>',
          'active' => $active,
          'preview' => globallink_interface_make_preview_link('Preview', $interface->lid),
        );
      }
      if (isset($interface->language)) {
        $rows[$interface->lid]['languages'][$interface->language] = $interface->translation;
      }
      $count++;
    }
    $cart_count = get_cart_count();
    globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
    if ($count > 0) {
      $form['pager'] = array(
        '#markup' => theme('pager'),
      );
    }
  }

  // Very important
  form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
  return $form;
}