You are here

globallink_send_translations.inc in GlobalLink Connect for Drupal 7.7

File

globallink_send_translations.inc
View source
<?php

/**
 * @file
 */
$default_language = language_default();
$GLOBALS['globallink_source_locale'] = $default_language->language;

/**
 * Builds forms on GlobalLink send dashboard.
 *
 * @param string $type
 *   The type of task we are working on.
 *
 * @return array
 *   Array of forms for the GlobalLink send dashboard.
 */
function globallink_dashboard_page($type) {
  $default_date = format_date(REQUEST_TIME + 7 * 24 * 60 * 60, 'custom', 'm/d/Y');
  drupal_add_library('system', 'ui.datepicker');
  drupal_add_js('jQuery(function() {
    jQuery(document).ajaxComplete(function() {
      jQuery(".pickadate1").datepicker({
        dateFormat: "mm/dd/yy",
        defaultDate: "' . $default_date . '",
        minDate: 0
      });
    });
  });', array(
    'group' => CSS_THEME,
    'type' => 'inline',
    'scope' => 'header',
    'weight' => 80,
  ));
  $_SESSION['globallink_selected_type'] = $type;
  $array = array();
  $array[] = drupal_get_form('globallink_dashboard_node_filter_form');
  $array[] = drupal_get_form('globallink_dashboard_pager_form');
  $array[] = drupal_get_form('globallink_dashboard_node_form');
  return $array;
}

/**
 * Builds form to filter GlobalLink nodes to send for translation on dashboard.
 */
function globallink_dashboard_node_filter_form($form, &$form_state) {
  module_load_include('inc', 'globallink', 'globallink');
  $form = array();
  $redirect_nid = isset($_GET['rnid']) ? $_GET['rnid'] : '';
  if ($redirect_nid != '') {
    $_SESSION['globallink_source_locale'] = '';
    $_SESSION['globallink_dashboard_filter'] = array();
    $_SESSION['globallink_source_locale'] = globallink_get_node_source_languages($redirect_nid);
  }
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  $node_types = globallink_get_translatable_node_types(TRUE);
  if (isset($locales) && count($locales) > 1) {
    if (isset($node_types) && count($node_types) > 0) {
      $session = isset($_SESSION['globallink_dashboard_filter']) ? $_SESSION['globallink_dashboard_filter'] : array();
      $filters = globallink_build_filters(TRUE);
      $form['filters'] = array(
        '#type' => 'fieldset',
        '#title' => t('FILTER RECORDS'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $selected_arr = array();
      $selected_source_lang = '';
      foreach ($session as $filter) {
        list($type, $value) = $filter;
        $selected_arr[$type] = $value;
      }
      $form['filters']['status']['filters'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'style' => 'padding: 0px;',
        ),
      );
      $module_path = drupal_get_path('module', 'globallink');
      drupal_add_css($module_path . '/css/globallink.css');
      foreach ($filters as $key => $filter) {
        $disabled = FALSE;
        $default = '[Any]';
        if ($filter['form-type'] == 'select') {
          if ($key == 'language_name') {
            $default_language = language_default();
            $default = $default_language->language;
            if (isset($_SESSION['globallink_source_locale']) && $_SESSION['globallink_source_locale'] != '') {
              $default = $_SESSION['globallink_source_locale'];
            }
            $selected_source_lang = $default;
            $form['filters']['status']['filters'][$key] = array(
              '#type' => $filter['form-type'],
              '#options' => $filter['options'],
              '#title' => check_plain($filter['title']),
              '#default_value' => $default,
              '#disabled' => $disabled,
              '#attributes' => array(
                'style' => array(
                  'padding:5px;',
                ),
              ),
              '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
              '#field_prefix' => '</td><td>',
              '#ajax' => array(
                'event' => 'change',
                'callback' => 'globallink_dashboard_node_filter_target',
                'wrapper' => 'replace-target',
              ),
            );
            $form['filters']['status']['filters']['node_parent'] = array(
              '#type' => 'checkbox',
              '#return_value' => 1,
              '#default_value' => 1,
              '#prefix' => '<span style="display:block;padding-top:10px;">',
              '#suffix' => '</span></td></tr>',
              '#field_suffix' => 'Show Source Language Only</td>',
            );
          }
          else {
            if ($key == 'target_language') {
              if (isset($form_state['values']['language_name'])) {
                $form['filters']['status']['filters'][$key] = array(
                  '#type' => $filter['form-type'],
                  '#options' => globallink_get_target_options($form_state['values']['language_name']),
                  '#disabled' => $disabled,
                  '#default_value' => isset($form_state['values']['target_language']) ? $form_state['values']['target_language'] : '',
                  '#attributes' => array(
                    'style' => array(
                      'padding:0px;',
                    ),
                  ),
                  '#field_prefix' => '<td><div id="replace-target">',
                  '#field_suffix' => '</div></td>',
                );
              }
              else {
                $form['filters']['status']['filters'][$key] = array(
                  '#type' => $filter['form-type'],
                  '#options' => globallink_get_target_options($selected_source_lang),
                  '#title' => check_plain($filter['title']),
                  '#disabled' => $disabled,
                  '#default_value' => isset($form_state['values']['target_language']) ? $form_state['values']['target_language'] : '',
                  '#attributes' => array(
                    'style' => array(
                      'padding:0px;',
                    ),
                  ),
                  '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
                  '#suffix' => '</tr>',
                  '#field_prefix' => '</td><td><div id="replace-target">',
                  '#field_suffix' => '</div></td>',
                );
              }
            }
            else {
              if ($key == 'status' && module_exists('revisioning')) {
                $default = 'status-1';
              }
              $form['filters']['status']['filters'][$key] = array(
                '#type' => $filter['form-type'],
                '#options' => $filter['options'],
                '#title' => check_plain($filter['title']),
                '#disabled' => $disabled,
                '#default_value' => isset($selected_arr[$key]) ? $selected_arr[$key] : $default,
                '#attributes' => array(
                  'style' => array(
                    'padding:0px;',
                  ),
                ),
                '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
                '#suffix' => '</tr>',
                '#field_suffix' => '</td>',
                '#field_prefix' => '</td><td>',
              );
            }
          }
        }
        elseif ($key == 'modified-after') {
          drupal_add_library('system', 'ui.datepicker');
          drupal_add_js('jQuery(document).ready(function(){
          jQuery( ".pickadate" ).datepicker({
          dateFormat: "mm/dd/yy",
          maxDate: 0,
          autoSize: true,
          showOn: "button",
          buttonImage: "' . $GLOBALS['base_url'] . '/' . $module_path . '/css/icon-calendar.png",
          buttonImageOnly: true,
          buttonText: "Click to select date"
          });});', 'inline');
          $form['filters']['status']['filters'][$key] = array(
            '#type' => $filter['form-type'],
            '#title' => check_plain($filter['title']),
            '#disabled' => $disabled,
            '#attributes' => array(
              'class' => array(
                'pickadate',
              ),
              'style' => array(
                'padding:0px;',
              ),
            ),
            '#default_value' => isset($selected_arr[$key]) ? format_date($selected_arr[$key], 'custom', 'm/d/Y') : '',
            '#prefix' => "<tr><td style='text-align: left;width: 15%;vertical-align: middle;border: none;'>",
            '#suffix' => '</tr></table></div>',
            '#field_suffix' => '</td>',
            '#field_prefix' => '</td><td>',
          );
        }
        elseif ($key == 'modified') {
          $form['filters']['status']['filters'][$key] = array(
            '#type' => $filter['form-type'],
            '#title' => check_plain($filter['title']),
            '#options' => $filter['options'],
            '#disabled' => $disabled,
            '#default_value' => isset($selected_arr[$key]) ? $selected_arr[$key] : 0,
            '#attributes' => array(
              'class' => array(
                'container-inline',
              ),
              'style' => array(
                'padding:0px;',
              ),
            ),
            '#prefix' => '<div class="container-inline"><table><tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
            '#suffix' => '</tr>',
            '#field_suffix' => '</td>',
            '#field_prefix' => '</td><td>',
          );
        }
        elseif ($key == 'title') {
          $form['filters']['status']['filters'][$key] = array(
            '#type' => $filter['form-type'],
            '#title' => check_plain($filter['title']),
            '#disabled' => $disabled,
            '#default_value' => isset($selected_arr[$key]) ? $selected_arr[$key] : '',
            '#attributes' => array(
              'size' => 30,
            ),
            '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
            '#suffix' => '</tr>',
            '#field_suffix' => '</td>',
            '#field_prefix' => '</td><td>',
          );
        }
      }
      $form['filters']['status']['actions'] = array(
        '#type' => 'actions',
        '#attributes' => array(
          'class' => array(
            'container-inline',
          ),
        ),
      );
      $disable_submit = FALSE;
      if (isset($_SESSION['globallink_dashboard_filter'])) {
        if (count($_SESSION['globallink_dashboard_filter']) > 0) {
          $disable_submit = TRUE;
        }
      }
      $form['filters']['status']['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Filter'),
        '#disabled' => $disable_submit,
      );
      if (count($session)) {
        $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>',
        );
        $filters = globallink_build_filters(TRUE);
        foreach ($session as $filter) {
          list($type, $value) = $filter;
          $selected_arr[$type] = $value;
          $label = '';
          if ($type == 'node_parent') {
            continue;
          }
          if (isset($filters[$type]['options'])) {
            $label = $filters[$type]['options'][$value];
          }
          elseif ($filters[$type]['field'] == 'changed') {
            $label = format_date($value, 'custom', 'm/d/Y');
          }
          else {
            $label = $value;
          }
          $form['filter-search']['filter-markup'][] = array(
            '#markup' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;"><b>' . $filters[$type]['title'] . '</b>:&nbsp;</td><td style="text-align: left;width: 85%;vertical-align: middle;border: none;">' . str_replace('&nbsp;', '', $label) . '</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'),
        );
      }
    }
    else {
      $form['tpt_node_types']['no_type'] = array(
        '#type' => 'markup',
        '#prefix' => '<br/><b><i>',
        '#markup' => t('No Content types enabled for translation.'),
        '#suffix' => '</i></b>',
      );
    }
  }
  else {
    $form['locale_mapping']['no_mapping'] = array(
      '#type' => 'markup',
      '#prefix' => '<br/><b><i>',
      '#markup' => t('No GlobalLink locale mapping found.'),
      '#suffix' => '</i></b>',
    );
  }
  return $form;
}

/**
 * Gets target options for GlobalLink node.
 *
 * @param string $selected
 *   The selected GlobalLink node.
 *
 * @return string
 *   The target options.
 */
function globallink_get_target_options($selected) {
  $lang_filter = array();
  $languages = globallink_get_mapped_drupal_locales(FALSE);
  foreach ($languages as $key => $lang) {
    $lang_filter[$key] = $lang;
  }
  if ($selected) {
    unset($lang_filter[$selected]);
  }
  $any = array(
    '[Any]' => t('Any'),
  );
  return $any + $lang_filter;
}

/**
 * Gets the target language as a filter item.
 *
 * @return string
 *   The target language.
 */
function globallink_dashboard_node_filter_target($form, &$form_state) {
  return $form['filters']['status']['filters']['target_language'];
}

/**
 * Handles submission of filter form.
 */
function globallink_dashboard_node_filter_form_submit($form, &$form_state) {
  module_load_include('inc', 'globallink', 'globallink');
  $op = $form_state['values']['op'];
  $filters = globallink_build_filters(TRUE);
  switch ($op) {
    case t('Filter'):
    case t('Refine'):

      // Apply every filter that has a choice selected other than 'any'.
      foreach ($filters as $filter => $options) {
        switch ($filter) {
          case 'modified-after':
            if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '') {
              list($month, $day, $year) = explode('/', $form_state['values'][$filter]);
              $time_stamp = mktime(0, 0, 0, $month, $day, $year);
              $_SESSION['globallink_dashboard_filter'][$filter] = array(
                $filter,
                $time_stamp,
              );
            }
            break;
          case 'modified':
            if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '') {
              $_SESSION['globallink_dashboard_filter'][$filter] = array(
                $filter,
                $form_state['values'][$filter],
              );
            }
            break;
          case 'title':
            if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '') {
              $_SESSION['globallink_dashboard_filter'][$filter] = array(
                $filter,
                $form_state['values'][$filter],
              );
            }
            break;
          case 'node_parent':
            if (isset($form_state['values']['node_parent']) && $form_state['values']['node_parent'] != '') {
              $_SESSION['globallink_dashboard_filter']['node_parent'] = array(
                'node_parent',
                $form_state['values']['node_parent'],
              );
            }
            break;
          default:
            if ($filter == 'language_name') {
              $_SESSION['globallink_source_locale'] = $form_state['values'][$filter];
            }
            if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {

              // Merge an array of arrays into one if necessary.
              $options = $filter == 'type' ? form_options_flatten($filters[$filter]['options']) : $filters[$filter]['options'];

              // Only accept valid selections offered on the dropdown, block bad input.
              if (isset($options[$form_state['values'][$filter]])) {
                if ($filter == 'status') {
                  $_SESSION['globallink_dashboard_filter'][$filter] = array(
                    $filter,
                    $form_state['values'][$filter],
                  );
                }
                else {
                  if (!isset($_SESSION['globallink_dashboard_filter'][$filter])) {
                    $_SESSION['globallink_dashboard_filter'][$filter] = array(
                      $filter,
                      $form_state['values'][$filter],
                    );
                  }
                }
              }
            }
        }
      }
      break;
    case t('Undo'):
      array_pop($_SESSION['globallink_dashboard_filter']);
      break;
    case t('Reset'):
      $_SESSION['globallink_source_locale'] = '';
      $_SESSION['globallink_dashboard_filter'] = array();
      break;
    case t('Update'):
      return;
  }
  $form_state['redirect'] = 'admin/globallink-translations/dashboard';
  return;
}

/**
 * Builds form to add pagination to GlobalLink send dashboard.
 */
function globallink_dashboard_pager_form() {
  $form = array();
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  if (isset($locales) && count($locales) > 1) {
    $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_send_page_count']) ? $_SESSION['globallink_send_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_form_pager_submit',
      ),
      '#access' => TRUE,
    );
  }
  return $form;
}

/**
 * Handles submission of pager form.
 */
function globallink_node_form_pager_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_send_page_count'] = array(
      $page_count,
    );
    return;
  }
}

/**
 * Builds form to create a GlobalLink submission.
 */
function globallink_dashboard_node_form() {
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink');
  drupal_add_library('system', 'drupal.ajax');
  drupal_add_js(drupal_get_path('module', 'globallink') . '/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_NODE,
      'sessionKey' => 'nids',
    ),
  ), 'setting');
  $default_checked_ids = array();
  $default_checked = array();
  if (isset($_SESSION['nids'])) {
    $default_checked = $_SESSION['nids'];
  }
  $module_path = drupal_get_path('module', 'globallink');
  $form = array();
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  $node_types = globallink_get_translatable_node_types(TRUE);
  if (isset($locales) && count($locales) > 1) {
    if (isset($node_types) && count($node_types) > 0) {
      $redirect_nid = isset($_GET['rnid']) ? $_GET['rnid'] : '';
      if ($redirect_nid != '') {
        $_SESSION['globallink_dashboard_filter'] = array();
      }
      $sort_order = isset($_GET['order']) ? $_GET['order'] : '';
      $header = array(
        'title' => array(
          'field' => 'title',
          'data' => t('Content'),
        ),
        'type' => array(
          'field' => 't_name',
          'data' => t('Content Type'),
        ),
        'language' => array(
          'field' => 'name',
          'data' => t('Language'),
        ),
        'changed' => array(
          'field' => 'changed',
          'data' => t('Last Modified'),
        ),
        'active' => t('In Active Submission'),
        'preview' => t('Preview'),
      );
      $node_check = variable_get('globallink_implementation_type', 0);
      $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
      $include_node_arr = array();
      $query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
      if (empty($_SESSION['globallink_dashboard_filter'])) {
        $query
          ->condition('language', $GLOBALS['globallink_source_locale'], '=');
      }
      else {
        $filter_arr = isset($_SESSION['globallink_dashboard_filter']) ? $_SESSION['globallink_dashboard_filter'] : array();
        globallink_build_filter_query($query, $filter_arr);
      }
      $query
        ->condition('type', $node_types, 'IN');
      $query
        ->fields('n');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        array_push($include_node_arr, $item->nid);
      }
      $modified = 0;
      if (isset($_SESSION['globallink_dashboard_filter']['modified'])) {
        $modified = $_SESSION['globallink_dashboard_filter']['modified'][1];
      }
      $tgt_lang = '';
      if (isset($_SESSION['globallink_dashboard_filter']['target_language'])) {
        $tgt_lang = $_SESSION['globallink_dashboard_filter']['target_language'][1];
      }
      $status = '';
      if (module_exists('revisioning')) {
        if (isset($_SESSION['globallink_dashboard_filter']['status'])) {
          list($key, $value) = explode('-', $_SESSION['globallink_dashboard_filter']['status'][1], 2);
          $status = $value;
        }
        else {
          $status = '1';
        }
      }
      $t_count = 0;
      foreach ($target_lang_arr as $key => $value) {
        if ($key == globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])) {
          continue;
        }
        $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;';
        }
      }
      unset($target_lang_arr[globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])]);
      if ($tgt_lang != '' && $tgt_lang != '[Any]') {
        $target_lang_arr_keys = array_keys($target_lang_arr);
        foreach ($target_lang_arr_keys as $t_key) {
          if (globallink_get_locale_code($tgt_lang) != $t_key) {
            unset($target_lang_arr[$t_key]);
          }
        }
      }
      if ($tgt_lang != '' && $tgt_lang != '[Any]') {
        $t_query = db_select('globallink_document', 'gd');
        $t_query
          ->condition('gd.target_lang_code', globallink_get_locale_code($tgt_lang), '=');
        $t_query
          ->condition('gd.target_status', array(
          GLOBALLINK_STATUS_TRANSLATION_SENT,
          GLOBALLINK_STATUS_TRANSLATION_ERROR,
          GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
        ), 'IN');
        $t_query
          ->condition(db_or()
          ->condition('gd.entity_type', GLOBALLINK_ENTITY_TYPE_NODE)
          ->condition('gd.entity_type', GLOBALLINK_ENTITY_TYPE_ENTITY));
        $t_query
          ->fields('gd');
        $t_query
          ->orderBy('object_id', 'ASC');
        $results = $t_query
          ->execute();
        foreach ($results as $item) {
          if ($item->target_status == GLOBALLINK_STATUS_TRANSLATION_SENT || $item->target_status == GLOBALLINK_STATUS_TRANSLATION_ERROR || $item->target_status == GLOBALLINK_STATUS_TRANSLATION_COMPLETED) {
            $key = array_search($item->object_id, $include_node_arr);
            unset($include_node_arr[$key]);
          }
        }
      }
      if ($modified == 0) {
        $t_query = db_select('globallink_core', 'tc');
        $t_query
          ->condition('source', globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale']), '=');
        $t_query
          ->fields('tc');
        $t_query
          ->orderBy('nid', 'ASC');
        $results = $t_query
          ->execute();
        $item_arr = array();
        foreach ($results as $item) {
          $key = array_search($item->nid, $include_node_arr);
          if ($key !== FALSE) {
            if (array_key_exists($item->nid, $item_arr)) {
              array_push($item_arr[$item->nid], $item);
            }
            else {
              $item_arr[$item->nid] = array(
                $item,
              );
            }
          }
        }
        $tgt_keys = array_keys($target_lang_arr);
        foreach ($include_node_arr as $key => $nid) {
          if (isset($item_arr[$nid])) {
            $ncount = count($tgt_keys);
            foreach ($item_arr[$nid] as $item) {
              foreach ($tgt_keys as $target) {
                if (!isset($item->target)) {
                  continue;
                }
                if ($target == $item->target) {
                  if ($item->changed == 0 || $item->changed == 2) {
                    $ncount--;
                  }
                }
              }
            }
            if ($ncount == 0) {
              unset($include_node_arr[$key]);
            }
          }
        }
      }
      $page_count = TPT_PAGER_LIMIT;
      if (isset($_SESSION['globallink_send_page_count'])) {
        $page_count = $_SESSION['globallink_send_page_count'][0];
      }
      $count = 0;
      $rows = array();
      $d_query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n')
        ->extend('PagerDefault')
        ->limit($page_count)
        ->extend('TableSort');
      if ($node_check == 1) {
        if ($redirect_nid == '' && count($include_node_arr) > 0) {
          $selected_target_lang = NULL;
          if ($tgt_lang != '' && $tgt_lang != '[Any]') {
            $selected_target_lang = $tgt_lang;
          }
          foreach ($include_node_arr as $key => $nid) {
            if (!globallink_is_node_translatable(node_load($nid), $selected_target_lang)) {
              unset($include_node_arr[$key]);
            }
          }
          if (count($include_node_arr) > 0) {
            $d_query
              ->condition('nid', $include_node_arr, 'IN');
            $d_query
              ->join('languages', 'l', 'l.language = n.language');
            $d_query
              ->join('node_type', 't', 't.type = n.type');
            $d_query
              ->fields('n', array(
              'nid',
              'vid',
              'title',
              'type',
              'changed',
            ));
            $d_query
              ->fields('l', array(
              'name',
            ));
            $d_query
              ->fields('t', array(
              'name',
            ));
            if ($sort_order == '') {
              $d_query
                ->orderBy('nid', 'DESC');
            }
            else {
              $d_query
                ->orderByHeader($header);
            }
            $results = $d_query
              ->execute();
            $rows = array();
            foreach ($results as $item) {
              $count++;
              $active = '';
              $active_arr = globallink_get_active_submission_by_nid($item->nid);
              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/> ';
                }
              }
              $rows[$item->nid . '-' . $item->vid] = array(
                'nid' => $item->nid,
                'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
                'type' => $item->t_name,
                'language' => $item->name,
                'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
                'active' => $active,
                'preview' => _make_preview_link('Preview', $item->nid),
              );
            }
          }
        }
      }
      else {
        $revisioning = FALSE;
        if (module_exists('revisioning') && $status != '') {
          if ($status == '1') {
            $d_query
              ->condition('status', 1, '=');
          }
          else {
            $revisioning = TRUE;
          }
        }
        if ($redirect_nid == '' && count($include_node_arr) > 0) {
          $d_query
            ->condition('nid', $include_node_arr, 'IN');
          $d_query
            ->join('languages', 'l', 'l.language = n.language');
          $d_query
            ->join('node_type', 't', 't.type = n.type');
          $d_query
            ->fields('n', array(
            'nid',
            'vid',
            'title',
            'type',
            'changed',
          ));
          $d_query
            ->fields('l', array(
            'name',
          ));
          $d_query
            ->fields('t', array(
            'name',
          ));
          if ($sort_order == '') {
            $d_query
              ->orderBy('nid', 'DESC');
          }
          else {
            $d_query
              ->orderByHeader($header);
          }
          $results = $d_query
            ->execute();
          $rows = array();
          foreach ($results as $item) {
            $count++;
            $vid = $item->vid;
            if ($revisioning) {
              if ($status == 0) {
                $vid = revisioning_get_latest_revision_id($item->nid);
              }
            }
            $node = node_load($item->nid, $vid);
            $active = '';
            $active_arr = globallink_get_active_submission_by_nid($item->nid);
            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;
                if ($active_row->object_version_id != $vid) {
                  $active .= ' (Different version)<BR/>';
                }
                else {
                  $active .= ' <BR/> ';
                }
              }
            }
            if ($status) {
              $title = l(globallink_format_display_string($node->title), 'node/' . $item->nid . '/revisions/' . $node->vid . '/view');
            }
            else {
              $title = l(globallink_format_display_string($node->title), 'node/' . $item->nid);
            }
            $rows[$item->nid . '-' . $vid] = array(
              'nid' => $item->nid,
              'title' => $title,
              'type' => $item->t_name,
              'language' => $item->name,
              'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
              'active' => $active,
              'preview' => _make_preview_link('Preview', $item->nid),
            );
          }
        }
        else {
          $d_query
            ->condition('nid', $redirect_nid, '=');
          $d_query
            ->join('languages', 'l', 'l.language = n.language');
          $d_query
            ->join('node_type', 't', 't.type = n.type');
          $d_query
            ->fields('n', array(
            'nid',
            'vid',
            'title',
            'type',
            'changed',
          ));
          $d_query
            ->fields('l', array(
            'name',
          ));
          $d_query
            ->fields('t', array(
            'name',
          ));
          if ($sort_order == '') {
            $d_query
              ->orderBy('title', 'ASC');
          }
          else {
            $d_query
              ->orderByHeader($header);
          }
          $results = $d_query
            ->execute();
          $include_node_arr = array();
          $include_node_arr[] = $redirect_nid;
          $rows = array();
          foreach ($results as $item) {
            $count++;
            $vid = $item->vid;
            if ($revisioning) {
              $vid = revisioning_get_latest_revision_id($item->nid);
            }
            $node = node_load($item->nid, $vid);
            $active = '';
            $active_arr = globallink_get_active_submission_by_nid($item->nid);
            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;
                if ($active_row->object_version_id != $vid) {
                  $active .= ' (Different version)<BR/>';
                }
                else {
                  $active .= ' <BR/> ';
                }
              }
            }
            $rows[$item->nid . '-' . $vid] = array(
              'nid' => $item->nid,
              'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
              'type' => $item->t_name,
              'language' => $item->name,
              'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
              'active' => $active,
              'preview' => _make_preview_link('Preview', $item->nid),
            );
            $default_checked_ids = array(
              $item->nid . '-' . $vid => TRUE,
            );
          }
        }
      }
      $cart_count = get_cart_count();
      globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
      $form['#attributes']['class'][] = 'globallink-node-form-clear';
      if ($count > 0) {
        $form['pager'] = array(
          '#markup' => theme('pager'),
        );
      }
      drupal_add_css($module_path . '/css/globallink.css');
    }
  }
  return $form;
}

/**
 *
 */
function globallink_add_cart_form_elements(&$form, $header, $rows, $default_checked, $cart_count) {
  ctools_include('modal');
  ctools_modal_add_js();
  $disabled = FALSE;
  if ($cart_count == 0) {
    $disabled = TRUE;
  }
  $form['url'] = array(
    '#type' => 'hidden',
    // Workaround for button instead of link
    // The name of the class is the #id of ajax button with "-url" suffix.
    '#attributes' => array(
      'class' => array(
        'gl-add-to-cart-url',
      ),
    ),
    '#value' => url('admin/create-submission/nojs'),
  );
  $form['add-to-cart'] = array(
    '#type' => 'submit',
    '#value' => t('Create Submission'),
    '#prefix' => '<div class="form-operations">',
    '#suffix' => '<div id="update-cart-count">' . $cart_count . '</div>',
    '#attributes' => array(
      'title' => t('Create a GlobalLink Submission'),
      'class' => array(
        'globallink-cart-button',
        'ctools-use-modal',
      ),
    ),
    '#id' => 'gl-add-to-cart',
    '#disabled' => $disabled,
  );
  $form['remove-from-cart'] = array(
    '#type' => 'button',
    '#value' => t('Clear'),
    '#suffix' => '</div>',
    '#attributes' => array(
      'title' => t('Clear Submission'),
      'class' => array(
        'globallink-cart-clear-button',
      ),
    ),
    '#ajax' => array(
      'callback' => 'globallink_dashboard_node_form_ajax_empty_cart',
    ),
    '#id' => 'gl-remove-from-cart',
    '#disabled' => $disabled,
  );
  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No items available'),
    '#default_value' => $default_checked,
    '#attributes' => array(
      'class' => array(
        'globallink-send-page-row',
      ),
    ),
  );
}

/**
 *
 */
function globallink_select_id_callback() {
  module_load_include('inc', 'globallink', 'globallink');
  $payload = json_decode($_POST['payload']);
  $val = $payload->id;
  $key = $payload->sessionKey;
  if ($payload->checked) {
    if (isset($_SESSION[$key])) {
      if (!in_array($val, $_SESSION[$key])) {
        $_SESSION[$key][$val] = $val;
      }
    }
    else {
      $_SESSION[$key] = [
        $val => $val,
      ];
    }
  }
  else {
    if (isset($_SESSION[$key])) {
      if (in_array($val, $_SESSION[$key])) {
        unset($_SESSION[$key][$val]);
      }
    }
  }
  $count = get_cart_count();
  return drupal_json_output(array(
    'count' => $count,
  ));
}

/**
 *
 */
function globallink_select_all_callback() {
  module_load_include('inc', 'globallink', 'globallink');
  $payload = json_decode($_POST['payload']);
  $key = $payload->sessionKey;
  $ids = $payload->ids;
  if ($payload->checked) {
    if (isset($_SESSION[$key])) {
      foreach ($ids as $val) {
        if (!in_array($val, $_SESSION[$key])) {
          $_SESSION[$key][$val] = $val;
        }
      }
    }
    else {
      $_SESSION[$key] = array();
      foreach ($ids as $val) {
        $_SESSION[$key][$val] = $val;
      }
    }
  }
  else {
    if (isset($_SESSION[$key])) {
      foreach ($ids as $val) {
        if (in_array($val, $_SESSION[$key])) {
          unset($_SESSION[$key][$val]);
        }
      }
    }
  }
  $count = get_cart_count();
  return drupal_json_output(array(
    'count' => $count,
  ));
}

/**
 * Handles clearing the globallink cart contents.
 */
function globallink_dashboard_node_form_ajax_empty_cart($form, $form_state) {
  ctools_include('ajax');
  ctools_include('modal');
  $commands = array();
  $commands[] = ajax_command_alert('All content removed from Submission.');
  $cart_count = 0;
  if (isset($_SESSION['nids'])) {
    unset($_SESSION['nids']);
  }
  if (isset($_SESSION['eids'])) {
    unset($_SESSION['eids']);
  }
  if (isset($_SESSION['bids'])) {
    unset($_SESSION['bids']);
  }
  if (isset($_SESSION['fpids'])) {
    unset($_SESSION['fpids']);
  }
  if (isset($_SESSION['int_ids'])) {
    unset($_SESSION['int_ids']);
  }
  if (isset($_SESSION['mids'])) {
    unset($_SESSION['mids']);
  }
  if (isset($_SESSION['tids'])) {
    unset($_SESSION['tids']);
  }
  if (isset($_SESSION['wfids'])) {
    unset($_SESSION['wfids']);
  }
  if (isset($_SESSION['bnids'])) {
    unset($_SESSION['bnids']);
  }
  if (isset($_SESSION['fids'])) {
    unset($_SESSION['fids']);
  }
  if (isset($_SESSION['pids'])) {
    unset($_SESSION['pids']);
  }
  if (isset($_SESSION['eck'])) {
    unset($_SESSION['eck']);
  }
  $commands[] = ajax_command_html('#update-cart-count', $cart_count);
  $commands[] = ajax_command_invoke(NULL, 'globallink_js_clear_cart');
  $commands[] = ctools_ajax_command_reload();
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}

/**
 *
 */
function globallink_submission_callback($ajax) {
  module_load_include('inc', 'globallink', 'globallink_send_translations');
  if ($ajax) {
    ctools_include('ajax');
    ctools_include('modal');
    $form_state = array(
      'ajax' => TRUE,
      'title' => t('Create a Submission for GlobalLink'),
    );

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

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

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

/**
 *
 */
function globallink_dashboard_node_form_ajax_remove_selected($form, $form_state) {
  ctools_include('ajax');
  ctools_include('modal');
  $commands = array();
  $nids = array_filter($form_state['values']['table-content']);
  if (count($nids) == 0) {
    $commands[] = ajax_command_alert('No content selected.');
    return array(
      '#type' => 'ajax',
      '#commands' => $commands,
    );
  }
  else {
    $ids = array();
    foreach ($nids as $nid) {
      $value = explode('|', $nid);
      $ids[] = $value[1];
      unset($_SESSION[$value[0]][$value[1]]);
      $commands[] = ajax_command_remove('.cart-row-' . $value[0] . '-' . $value[1]);
    }
    $commands[] = ajax_command_alert('Content removed from submission.');
    $cart_count = get_cart_count();
    $commands[] = ajax_command_html('#update-cart-count', $cart_count);
    if ($cart_count == 0) {
      $commands[] = ajax_command_invoke(NULL, 'globallink_js_clear_cart');
      $commands[] = ctools_ajax_command_reload();
      $commands[] = ctools_modal_command_dismiss();
    }
    else {
      $commands[] = ajax_command_invoke(NULL, 'globallink_js_clear_ids', array(
        implode(',', $ids),
      ));
    }
  }
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}

/**
 *
 */
function globallink_create_submission_form($form, &$form_state) {
  form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink_entity', 'globallink_entity');
  module_load_include('inc', 'globallink_block', 'globallink_block');
  module_load_include('inc', 'globallink_menu', 'globallink_menu');
  module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
  module_load_include('inc', 'globallink_interface', 'globallink_interface');
  module_load_include('inc', 'globallink_fieldable_panels', 'globallink_fieldable_panels');
  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');
  $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
  $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
  $module_path = drupal_get_path('module', 'globallink');
  $languages = globallink_get_mapped_drupal_locales(FALSE);
  $groups = module_invoke_all('locale', 'groups');
  if (user_access(TPT_ROLE_DO_TRANSLATIONS) || user_access(TPT_ROLE_MANAGE_TRANSLATIONS)) {
    drupal_add_css($module_path . '/css/globallink.css');
    $proj_arr = variable_get('globallink_pd_projects', array());
    $tgt_lang = '';
    $t_count = 0;
    if (isset($_SESSION['globallink_dashboard_filter']['target_language'])) {
      $tgt_lang = $_SESSION['globallink_dashboard_filter']['target_language'][1];
    }
    foreach ($target_lang_arr as $key => $value) {
      if ($key == globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])) {
        continue;
      }
      $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;';
      }
    }
    unset($target_lang_arr[globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])]);
    if ($tgt_lang != '' && $tgt_lang != '[Any]') {
      $target_lang_arr_keys = array_keys($target_lang_arr);
      foreach ($target_lang_arr_keys as $t_key) {
        if (globallink_get_locale_code($tgt_lang) != $t_key) {
          unset($target_lang_arr[$t_key]);
        }
      }
    }
    if (count($proj_arr) > 0) {
      $projects = variable_get('globallink_pd_projectid');
      if (!empty($projects)) {
        $arr = explode(',', $projects);
        foreach ($arr as $value) {
          if (isset($proj_arr[$value])) {
            $proj_arr[$value] = $proj_arr[$value];
          }
          else {
            $proj_arr[$value] = $value;
          }
        }
      }
    }
    $p_key = '';
    if (count($proj_arr) == 1) {
      $p_key = key($proj_arr);
    }
    $proj_arr[''] = ' -- Select a Project -- ';
    $r_proj_arr = array_reverse($proj_arr);
    $submission_priorities = array(
      1 => 'Regular',
      2 => 'Urgent',
    );
    $form['send_submission']['submission_name'] = array(
      '#type' => 'textfield',
      '#title' => 'Submission Name',
      '#size' => 20,
      '#required' => TRUE,
      '#default_value' => variable_get('globallink_pd_submissionprefix', 'DRU_') . REQUEST_TIME,
      '#prefix' => '<div class="container-inline"><table><tr><td style="text-align: left;width: 20%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Name for this new Submission.') . '</div></td><td>',
    );
    $default_date = format_date(REQUEST_TIME + 7 * 24 * 60 * 60, 'custom', 'm/d/Y');
    drupal_add_library('system', 'ui.datepicker');
    drupal_add_js('jQuery(document).ready(function(){
      jQuery( ".pickadate1" ).datepicker({
      dateFormat: "mm/dd/yy",
      defaultDate: "' . $default_date . '",
      minDate: 0,
      autoSize: true,
      showOn: "button",
      buttonImage: "' . $GLOBALS['base_url'] . '/' . $module_path . '/css/icon-calendar.png",
      buttonImageOnly: true,
      buttonText: "Click to select date"
    });});', 'inline');
    $form['send_submission']['submission_due_date'] = array(
      '#type' => 'textfield',
      '#title' => 'Submission Due Date',
      '#size' => 10,
      '#required' => TRUE,
      '#attributes' => array(
        'class' => array(
          'pickadate1',
        ),
      ),
      '#default_value' => $default_date,
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Expected Completion Date for this Submission.') . '</div></td><td>',
    );
    $form['send_submission']['submission_pd_project'] = array(
      '#type' => 'select',
      '#title' => t('Project Name'),
      '#required' => TRUE,
      '#options' => $r_proj_arr,
      '#default_value' => $p_key,
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('GlobalLink Project Name for this Submission') . '</div></td><td>',
    );
    $form['send_submission']['submission_pd_priority'] = array(
      '#type' => 'select',
      '#title' => t('Submission priority'),
      '#required' => TRUE,
      '#options' => $submission_priorities,
      '#default_value' => 1,
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Select the priority for this Submission') . '</div></td><td>',
    );
    $form['send_submission']['submission_source_locale'] = array(
      '#type' => 'select',
      '#title' => t('Source Language'),
      '#required' => TRUE,
      '#options' => $source_lang_arr,
      '#default_value' => globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale']),
      '#disabled' => TRUE,
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Source language for this Submission.') . '</div></td><td>',
    );
    $form['send_submission']['submission_target_locale'] = array(
      '#type' => 'checkboxes',
      '#options' => $target_lang_arr,
      '#title' => t('Target Language(s)'),
      '#required' => TRUE,
      '#attributes' => array(
        'class' => array(
          'globallink-create-sub-target-locale-checkboxes',
        ),
      ),
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Target language(s) for this Submission.') . '</div></td><td>',
    );
    global $user;
    $form['send_submission']['submission_submitter'] = array(
      '#type' => 'textfield',
      '#title' => 'Submitter',
      '#size' => 10,
      '#required' => TRUE,
      '#default_value' => check_plain($user->name),
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr>',
      '#field_suffix' => '</td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Username for this new Submission.') . '</div></td><td>',
    );
    $form['send_submission']['submission_instructions'] = array(
      '#type' => 'textarea',
      '#title' => t('Instructions'),
      '#attributes' => array(
        'style' => 'width: 275px;resize: none;',
      ),
      '#rows' => 3,
      '#resizable' => FALSE,
      '#prefix' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;">',
      '#suffix' => '</tr></table></div>',
      '#field_suffix' => '</div></td>',
      '#field_prefix' => '<BR/><div class="description">' . t('Other instructions for this Submission.') . '</div></td><td>',
    );
    $form['send_submission']['submit_pd_send'] = array(
      '#type' => 'submit',
      '#value' => t('Request Translation'),
    );
    $form['remove-selected'] = array(
      '#type' => 'button',
      '#value' => t('Remove Selected'),
      '#limit_validation_errors' => array(),
      '#ajax' => array(
        'callback' => 'globallink_dashboard_node_form_ajax_remove_selected',
      ),
    );
  }

  // Showing contents in popup table.
  if (get_cart_count() > 0) {
    $header = array(
      'title' => array(
        'field' => 'title',
        'data' => t('Title'),
      ),
      'type' => array(
        'field' => 't_name',
        'data' => t('Type'),
      ),
      'language' => array(
        'field' => 'name',
        'data' => t('Language'),
      ),
      'changed' => array(
        'field' => 'changed',
        'data' => t('Last Modified'),
      ),
      'entity_type' => t('Entity Type'),
    );
    $rows = array();
    if (isset($_SESSION['nids']) && count($_SESSION['nids']) > 0) {
      $nodes = array();
      foreach ($_SESSION['nids'] as $val) {
        $tmp_nid = explode('-', $val);
        $nodes[] = $tmp_nid[0];
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
      $query
        ->join('languages', 'l', 'l.language = n.language');
      $query
        ->join('node_type', 't', 't.type = n.type');
      $query
        ->fields('n', array(
        'nid',
        'vid',
        'title',
        'type',
        'changed',
      ));
      $query
        ->fields('l', array(
        'name',
      ));
      $query
        ->fields('t', array(
        'name',
      ));
      $query
        ->condition('nid', $nodes, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['nids|' . $item->nid . '-' . $item->vid] = array(
          'nid' => $item->nid,
          'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
          'type' => $item->t_name,
          'language' => $item->name,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Node'),
          '#attributes' => array(
            'class' => array(
              'cart-row-nids-' . $item->nid . '-' . $item->vid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['eids']) && count($_SESSION['eids']) > 0) {
      $entity_ids = array();
      foreach ($_SESSION['eids'] as $val) {
        $tmp_nid = explode('-', $val);
        $entity_ids[] = $tmp_nid[0];
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
      $query
        ->join('languages', 'l', 'l.language = n.language');
      $query
        ->join('node_type', 't', 't.type = n.type');
      $query
        ->fields('n', array(
        'nid',
        'vid',
        'title',
        'type',
        'changed',
      ));
      $query
        ->fields('l', array(
        'name',
      ));
      $query
        ->fields('t', array(
        'name',
      ));
      $query
        ->condition('nid', $entity_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['eids|' . $item->nid . '-' . $item->vid] = array(
          'nid' => $item->nid,
          'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
          'type' => $item->t_name,
          'language' => $item->name,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Entity'),
          '#attributes' => array(
            'class' => array(
              'cart-row-eids-' . $item->nid . '-' . $item->vid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['bids']) && count($_SESSION['bids']) > 0) {
      $block_ids = array();
      foreach ($_SESSION['bids'] as $val) {
        $block_ids[] = $val;
      }
      $query = db_select('block_custom', 'bc');
      $query
        ->fields('bc');
      $query
        ->condition('bid', $block_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['bids|' . $item->bid] = array(
          'nid' => $item->bid,
          'title' => $item->info,
          'type' => 'Block',
          'language' => '',
          'changed' => '',
          'entity_type' => t('Block'),
          '#attributes' => array(
            'class' => array(
              'cart-row-bids-' . $item->bid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['fpids']) && count($_SESSION['fpids']) > 0) {
      $fpids = array();
      foreach ($_SESSION['fpids'] as $val) {
        $fpids[] = $val;
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_FPP, 'fpp');
      $query
        ->fields('fpp');
      $query
        ->condition('fpp.fpid', $fpids, 'IN');
      $results = $query
        ->execute();
      $fpp_info = entity_get_info('fieldable_panels_pane');
      foreach ($results as $item) {
        $bundles = $fpp_info['bundles'];
        $bundle = $item->bundle;
        $bundle_label = '';
        if (isset($bundles) && isset($bundles[$bundle]) && isset($bundles[$bundle]['label'])) {
          $bundle_label = $bundles[$bundle]['label'];
        }
        $rows['fpids|' . $item->fpid] = array(
          'nid' => '',
          'title' => l($item->title, 'admin/structure/fieldable-panels-panes/view/' . $item->fpid . '/edit', array(
            'attributes' => array(
              'target' => '_blank',
            ),
          )),
          'type' => 'Fieldable Panel',
          'lang' => $languages[$item->language],
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Fieldable Panel'),
          '#attributes' => array(
            'class' => array(
              'cart-row-fpids-' . $item->fpid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['int_ids']) && count($_SESSION['int_ids']) > 0) {
      $int_ids = array();
      foreach ($_SESSION['int_ids'] as $val) {
        $int_ids[] = $val;
      }
      $query = db_select('locales_source', 'ls');
      $query
        ->fields('ls');
      $query
        ->condition('ls.lid', $int_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['int_ids|' . $item->lid] = array(
          'nid' => $item->lid,
          'title' => check_plain(truncate_utf8($item->source, 150, FALSE, TRUE)) . '<br /><small>' . $item->location . '</small>',
          'type' => $groups[$item->textgroup],
          'language' => '',
          'changed' => '',
          'entity_type' => t('Interface'),
          '#attributes' => array(
            'class' => array(
              'cart-row-int_ids-' . $item->lid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['mids']) && count($_SESSION['mids']) > 0) {
      $menu_types = menu_get_menus(TRUE);
      $menu_ids = array();
      foreach ($_SESSION['mids'] as $val) {
        $menu_ids[] = $val;
      }
      $query = db_select('menu_links', 'ml');
      $query
        ->fields('ml');
      $query
        ->condition('mlid', $menu_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['mids|' . $item->mlid] = array(
          'nid' => $item->mlid,
          'title' => l($item->link_title, $item->link_path),
          'type' => 'Menu',
          'language' => $languages[$item->language],
          'changed' => '',
          'entity_type' => t('Menu'),
          '#attributes' => array(
            'class' => array(
              'cart-row-mids-' . $item->mlid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['tids']) && count($_SESSION['tids']) > 0) {
      $taxo_ids = array();
      foreach ($_SESSION['tids'] as $val) {
        $taxo_ids[] = $val;
      }
      $query = db_select('taxonomy_term_data', 't');
      $query
        ->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
      $query
        ->fields('t', array(
        'tid',
        'name',
        'vid',
        'language',
      ));
      $query
        ->fields('v', array(
        'name',
      ));
      $query
        ->condition('t.tid', $taxo_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['tids|' . $item->tid] = array(
          'nid' => $item->tid,
          'title' => $item->v_name . ': ' . $item->name,
          'type' => 'Taxonomy',
          'language' => $languages[$item->language],
          'changed' => '',
          'entity_type' => t('Taxonomy'),
          '#attributes' => array(
            'class' => array(
              'cart-row-tids-' . $item->tid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['wfids']) && count($_SESSION['wfids']) > 0) {
      $wfids = array();
      foreach ($_SESSION['wfids'] as $val) {
        $wfids[] = $val;
      }
      if (!($query = globallink_webform_get_translate_filter_query())) {
        $query = array(
          'translation' => 'all',
          'language' => 'all',
          'string' => '',
        );
      }
      $sql_query = db_select('locales_source', 's');
      if ($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');
      }
      $sql_query
        ->fields('s', array(
        'source',
        'location',
        'context',
        'lid',
        'textgroup',
      ));
      $sql_query
        ->fields('t', array(
        'translation',
        'language',
      ));
      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;
      }
      $sql_query
        ->condition('s.textgroup', GLOBALLINK_ENTITY_TYPE_WEBFORM);
      $sql_query
        ->condition('s.context', '%email%', 'NOT LIKE');
      $sql_query
        ->condition('s.lid', $wfids, 'IN');
      $result = $sql_query
        ->execute();
      $webform_results = array();
      foreach ($result as $item) {
        array_push($webform_results, $item);
      }
      foreach ($webform_results as $webform) {
        $title = $webform->source;
        $results = db_select('webform_component', 'wc')
          ->fields('wc')
          ->condition('name', $title, '=')
          ->execute();
        foreach ($results as $result) {
          $nid = $result->nid;
        }
        $results_p = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n')
          ->fields('n')
          ->condition('nid', $nid, '=')
          ->execute();
        foreach ($results_p as $result_p) {
          $title = $result_p->title;
        }
        if (!isset($rows[$webform->lid])) {
          $rows['wfids|' . $webform->lid] = array(
            'title' => $title . ':' . check_plain(truncate_utf8($webform->source, 150, FALSE, TRUE)) . ' <br /> ',
            'language' => '',
            'type' => 'Webform',
            'nid' => $nid,
            'changed' => '',
            'entity_type' => t('Webform'),
            '#attributes' => array(
              'class' => array(
                'cart-row-wfids-' . $item->lid,
              ),
            ),
          );
        }
      }
    }
    if (isset($_SESSION['bnids']) && count($_SESSION['bnids']) > 0) {
      $bean_ids = array();
      foreach ($_SESSION['bnids'] as $val) {
        $bean_ids[] = $val;
      }
      $query = db_select('bean', 'bn');
      $query
        ->fields('bn');
      $query
        ->condition('bn.bid', $bean_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['bnids|' . $item->bid] = array(
          'bnid' => $item->bid,
          'title' => $item->title,
          'type' => $item->type,
          // 'language' => $languages[$item->language],.
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Bean'),
          '#attributes' => array(
            'class' => array(
              'cart-row-bnids-' . $item->bid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['fids']) && count($_SESSION['fids']) > 0) {
      $fe_ids = array();
      foreach ($_SESSION['fids'] as $fe) {
        $fe_ids[] = $fe;
      }
      $query = db_select('file_managed', 'fm');
      $query
        ->fields('fm');
      $query
        ->condition('fm.fid', $fe_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['fids|' . $item->fid] = array(
          'fid' => $item->fid,
          'title' => $item->filename,
          'type' => $item->type,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('File Enity'),
          '#attributes' => array(
            'class' => array(
              'cart-row-fids-' . $item->fid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['pids']) && count($_SESSION['pids']) > 0) {
      $cp_ids = array();
      foreach ($_SESSION['pids'] as $cp) {
        $cp_ids[] = $cp;
      }
      $query = db_select('commerce_product', 'cp');
      $query
        ->fields('cp');
      $query
        ->condition('cp.product_id', $cp_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['pids|' . $item->product_id] = array(
          'title' => $item->title,
          'type' => $item->type,
          'language' => $languages[$item->language],
          'sku' => $item->sku,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Commerce Product'),
          '#attributes' => array(
            'class' => array(
              'cart-row-pids-' . $item->product_id,
            ),
          ),
        );
      }
    }
    $form['table-content'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => globallink_pager_array_splice($rows, 10),
      '#empty' => t('No items available'),
    );
    $form['pager'] = array(
      '#theme' => 'pager',
    );
  }
  return $form;
}

/**
 * Validates form actions for GlobalLink submissions.
 */
function globallink_create_submission_form_validate($form, &$form_state) {
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'globallink');
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op != t('Request Translation')) {
    return;
  }
  $pd4 = globallink_get_project_director_details();
  if (!globallink_validate_project_director_details($pd4)) {
    return;
  }
  $source_locale = $form_state['values']['submission_source_locale'];
  $target_locale_arr = $form_state['values']['submission_target_locale'];
  $cart_count = get_cart_count();
  if ($cart_count == 0) {
    form_set_error('', t('No items in Submission. Cannot create translation job.'));
  }
  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 (!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;
  }
}

/**
 * Handles GlobalLink form submission.
 */
function globallink_create_submission_form_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink_settings');
  $submission_details = array();
  $pd4 = globallink_get_project_director_details();
  if ($op != t('Request Translation')) {
    return;
  }
  try {
    $content_ty = array();
    if (isset($_SESSION['nids'])) {
      $content_ty['nids'] = $_SESSION['nids'];
    }
    if (isset($_SESSION['eids'])) {
      $content_ty['eids'] = $_SESSION['eids'];
    }
    if (isset($_SESSION['bids'])) {
      $content_ty['bids'] = $_SESSION['bids'];
    }
    if (isset($_SESSION['int_ids'])) {
      $content_ty['int_ids'] = $_SESSION['int_ids'];
    }
    if (isset($_SESSION['fpids'])) {
      $content_ty['fpids'] = $_SESSION['fpids'];
    }
    if (isset($_SESSION['mids'])) {
      $content_ty['mids'] = $_SESSION['mids'];
    }
    if (isset($_SESSION['tids'])) {
      $content_ty['tids'] = $_SESSION['tids'];
    }
    if (isset($_SESSION['wfids'])) {
      $content_ty['wfids'] = $_SESSION['wfids'];
    }
    if (isset($_SESSION['bnids'])) {
      $content_ty['bnids'] = $_SESSION['bnids'];
    }
    if (isset($_SESSION['fids'])) {
      $content_ty['fids'] = $_SESSION['fids'];
    }
    if (isset($_SESSION['pids'])) {
      $content_ty['pids'] = $_SESSION['pids'];
    }
    $parents = array();
    if (isset($_SESSION['wfids'])) {
      $wfids = $_SESSION['wfids'];
      if (count($wfids) > 0) {
        foreach ($wfids as $value) {
          $key = $form_state['complete form']['table-content']['#options']['wfids|' . $value]['nid'];
          if (isset($parents[$key])) {
            $l_arr = $parents[$key];
            array_push($l_arr, $value);
            $parents[$key] = $l_arr;
          }
          else {
            $l_arr = array();
            array_push($l_arr, $value);
            $parents[$key] = $l_arr;
          }
        }
      }
    }
    $submission_name = $form_state['values']['submission_name'];
    $source_locale = $form_state['values']['submission_source_locale'];
    $target_locale_arr = $form_state['values']['submission_target_locale'];
    $submission_details['instructions'] = $form_state['values']['submission_instructions'];
    $submission_details['submitter'] = $form_state['values']['submission_submitter'];
    $submission_priority = $form_state['values']['submission_pd_priority'];
    foreach ($target_locale_arr as $key => $target) {
      if ($target == FALSE) {
        unset($target_locale_arr[$key]);
      }
    }
    watchdog(GLOBALLINK_MODULE, 'Processing User submission - %submission_name', array(
      '%submission_name' => $submission_name,
    ), WATCHDOG_INFO);
    $due_date = globallink_convert_date_to_timestamp($form_state['values']['submission_due_date']);
    $project_code = $form_state['values']['submission_pd_project'];
    $globallink_arr = array();
    foreach ($content_ty as $content => $val) {
      if (isset($val) && is_array($val)) {
        foreach ($val as $value) {
          $globallink = new stdClass();
          $globallink->id = $value;
          $globallink->type = $content;
          $globallink_arr[] = $globallink;
        }
      }
    }
    $items = array();
    $numberOfitems = variable_get('globallink_batch', 1000);
    $chunked_arr = array_chunk($globallink_arr, $numberOfitems);
    $chunked_count = count($chunked_arr);
    $suffix = 1;
    $name = $submission_name;
    foreach ($chunked_arr as $gl_arr) {
      foreach ($gl_arr as $globallink) {
        $items[$globallink->type][] = $globallink->id;
      }
      if ($chunked_count > 1) {
        $submission_name = $name . '_' . $suffix;
        $suffix++;
      }
      if (module_exists('background_process') && module_exists('background_batch')) {
        $operations[] = array(
          'globallink_background_send',
          array(
            $items,
            $pd4,
            $submission_name,
            $due_date,
            $project_code,
            $source_locale,
            $target_locale_arr,
            $submission_details,
            $submission_priority,
            $parents,
          ),
        );
      }
      else {
        module_load_include('inc', 'globallink', 'globallink_background_jobs');
        globallink_background_send($items, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $parents);
        drupal_set_message(t('Content has been successfully sent for translations.'));
      }
    }
    if (isset($operations)) {
      $batch = array(
        'title' => t('Sending GlobalLink submissions for translation'),
        'operations' => $operations,
        'error_message' => t('GlobalLink Error.'),
        'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
      );
      batch_set($batch);
      $batch['progressive'] = FALSE;
      background_batch_process_batch('admin/globallink-translations/activeSubmissions');
      drupal_set_message('The submissions are being sent. The status will be updated on the dashboard, once they are sent out. For more information check watchdog');
    }
    unset($_SESSION['nids']);
    unset($_SESSION['eids']);
    unset($_SESSION['bids']);
    unset($_SESSION['int_ids']);
    unset($_SESSION['fpids']);
    unset($_SESSION['mids']);
    unset($_SESSION['tids']);
    unset($_SESSION['wfids']);
    unset($_SESSION['bnids']);
    unset($_SESSION['fids']);
    unset($_SESSION['pids']);
    unset($_SESSION['eck']);
    if (isset($_GET['rnid'])) {
      unset($_GET['rnid']);
    }
    ctools_include('ajax');
    ctools_include('modal');
    if (!empty($form_state['submitted'])) {
      $commands[] = ctools_modal_command_dismiss();
      $commands[] = ctools_ajax_command_reload();
      print ajax_render($commands);
      drupal_exit();
    }
  } 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(),
    )));
  }
}

/**
 *
 */
function _make_preview_link($link_text = '', $id) {
  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/dashboard/node/preview/' . $id . '/nojs', array(
    'attributes' => array(
      'class' => 'ctools-use-modal ctools-modal-my-modal-style',
    ),
  )) . '</div>';
}

/**
 *
 */
function globallink_node_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_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_preview_content');
  }
}

/**
 *
 */
function globallink_preview_content() {
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink');
  $id = arg(5);
  $output = "";
  $node = node_load($id);
  $string = globallink_generate_xml_document($node, NULL);
  $xml = new SimpleXMLElement($string);
  $title = $xml->title
    ->count();
  $elem = $xml->field
    ->count();
  $output .= "<table><tr><th>Fields</th><th>Source Contents</th></tr>";
  if ($title > 0) {
    foreach ($xml->title as $e) {
      $title_value = (string) $e;
      $label = 'title';
      $output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $title_value . "</td></tr>";
    }
  }
  if ($elem > 0) {
    foreach ($xml->field as $element) {
      $tag = $element
        ->getName();
      $value = (string) $element;
      $label = (string) $element
        ->attributes()->label;
      $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_add_cart_form_elements
globallink_create_submission_form
globallink_create_submission_form_submit Handles GlobalLink form submission.
globallink_create_submission_form_validate Validates form actions for GlobalLink submissions.
globallink_dashboard_node_filter_form Builds form to filter GlobalLink nodes to send for translation on dashboard.
globallink_dashboard_node_filter_form_submit Handles submission of filter form.
globallink_dashboard_node_filter_target Gets the target language as a filter item.
globallink_dashboard_node_form Builds form to create a GlobalLink submission.
globallink_dashboard_node_form_ajax_empty_cart Handles clearing the globallink cart contents.
globallink_dashboard_node_form_ajax_remove_selected
globallink_dashboard_page Builds forms on GlobalLink send dashboard.
globallink_dashboard_pager_form Builds form to add pagination to GlobalLink send dashboard.
globallink_get_target_options Gets target options for GlobalLink node.
globallink_node_form_pager_submit Handles submission of pager form.
globallink_node_preview
globallink_preview_content
globallink_select_all_callback
globallink_select_id_callback
globallink_submission_callback
_make_preview_link