You are here

function globallink_entity_dashboard_form in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_entity/globallink_entity_send.inc \globallink_entity_dashboard_form()
  2. 7.6 globallink_entity/globallink_entity_send.inc \globallink_entity_dashboard_form()

Builds form to create an entity submission.

1 string reference to 'globallink_entity_dashboard_form'
globallink_entity_dashboard in globallink_entity/globallink_entity_send.inc
Builds forms on entity send dashboard.

File

globallink_entity/globallink_entity_send.inc, line 522

Code

function globallink_entity_dashboard_form() {
  module_load_include('inc', 'globallink_entity', 'globallink_entity');
  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_ENTITY,
      'sessionKey' => 'eids',
    ),
  ), 'setting');
  drupal_add_css($module_path . '/css/globallink.css');
  $default_checked = array();
  if (isset($_SESSION['eids'])) {
    $default_checked = $_SESSION['eids'];
  }
  $default_checked_ids = array();
  $form = array();
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  $node_types = globallink_get_translatable_node_types(FALSE);
  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_entity_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);
      $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
      $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_entity_filter'])) {
        $query
          ->condition('language', $GLOBALS['globallink_entity_source_locale'], '=');
      }
      else {
        $filter_arr = isset($_SESSION['globallink_entity_filter']) ? $_SESSION['globallink_entity_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_entity_filter']['modified'])) {
        $modified = $_SESSION['globallink_entity_filter']['modified'][1];
      }
      $tgt_lang = '';
      if (isset($_SESSION['globallink_entity_filter']['target_language'])) {
        $tgt_lang = $_SESSION['globallink_entity_filter']['target_language'][1];
      }
      $status = '';
      if (module_exists('revisioning')) {
        if (isset($_SESSION['globallink_entity_filter']['status'])) {
          list($key, $value) = explode('-', $_SESSION['globallink_entity_filter']['status'][1], 2);
          $status = $value;
        }
        else {
          $status = '1';
        }
      }
      $source_lang = empty($_SESSION['globallink_entity_source_locale']) ? $GLOBALS['globallink_entity_source_locale'] : $_SESSION['globallink_entity_source_locale'];
      $tpt_locale_code = globallink_get_locale_code($source_lang);
      $drupal_locale_desc = globallink_get_drupal_locale_name($tpt_locale_code);
      $t_count = 0;
      foreach ($target_lang_arr as $key => $value) {
        if ($key == $tpt_locale_code) {
          unset($target_lang_arr[$tpt_locale_code]);
          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;';
        }
      }
      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_COMPLETED || $item->target_status == GLOBALLINK_STATUS_TRANSLATION_ERROR) {
            $key = array_search($item->object_id, $include_node_arr);
            unset($include_node_arr[$key]);
          }
        }
      }
      if ($modified == 0) {

        // Show modified records only
        $t_query = db_select('globallink_core', 'tc');
        $t_query
          ->condition('source', $tpt_locale_code, '=');
        $t_query
          ->fields('tc');
        $t_query
          ->orderBy('nid', 'ASC');
        $results = $t_query
          ->execute()
          ->fetchAll();
        $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_entity_send_page_count'])) {
        $page_count = $_SESSION['globallink_entity_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) {

        // Hook implementation for dashboard
        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('node_type', 't', 't.type = n.type');
            $d_query
              ->fields('n', array(
              'nid',
              'vid',
              'title',
              'type',
              'changed',
            ));
            $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++;
              $node = node_load($item->nid);
              $active = '';
              $active_arr = globallink_entity_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/> ';
                }
              }
              if (module_exists('title') && isset($node->title_field[$source_lang])) {
                $title = l(globallink_format_display_string($node->title_field[$source_lang][0]['value']), 'node/' . $item->nid);
              }
              else {
                $title = l(globallink_format_display_string($node->title), 'node/' . $item->nid);
              }
              $rows[$item->nid . '-' . $item->vid] = array(
                'nid' => $item->nid,
                'title' => $title,
                'type' => $item->name,
                'language' => $drupal_locale_desc,
                'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
                'active' => $active,
                'preview' => globallink_entity_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('node_type', 't', 't.type = n.type');
          $d_query
            ->fields('n', array(
            'nid',
            'vid',
            'title',
            'type',
            'changed',
          ));
          $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 && $status == 0) {
              $vid = revisioning_get_latest_revision_id($item->nid);
            }
            $node = node_load($item->nid, $vid);
            $active = '';
            $active_arr = globallink_entity_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/> ';
              }
            }
            if (module_exists('title') && isset($node->title_field[$source_lang])) {
              $node_title = globallink_format_display_string($node->title_field[$source_lang][0]['value']);
            }
            else {
              $node_title = globallink_format_display_string($node->title);
            }
            if ($status) {
              $title = l($node_title, 'node/' . $item->nid . '/revisions/' . $node->vid . '/view');
            }
            else {
              $title = l($node_title, 'node/' . $item->nid);
            }
            $rows[$item->nid . '-' . $vid] = array(
              'nid' => $item->nid,
              'title' => $title,
              'type' => 'TEST',
              'type' => $item->name,
              'language' => $drupal_locale_desc,
              'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
              'active' => $active,
              'preview' => globallink_entity_make_preview_link('Preview', $item->nid),
            );
          }
        }
        else {

          // Request coming from translate tab
          $d_query
            ->condition('nid', $redirect_nid, '=');
          $d_query
            ->join('node_type', 't', 't.type = n.type');
          $d_query
            ->fields('n', array(
            'nid',
            'vid',
            'title',
            'type',
            'changed',
          ));
          $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_entity_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/> ';
              }
            }
            if (module_exists('title') && isset($node->title_field[$source_lang])) {
              $node_title = l(globallink_format_display_string($node->title_field[$source_lang][0]['value']), 'node/' . $item->nid);
            }
            else {
              $node_title = l(globallink_format_display_string($node->title), 'node/' . $item->nid);
            }
            $rows[$item->nid . '-' . $vid] = array(
              'nid' => $item->nid,
              'title' => $node_title,
              'type' => $item->name,
              'language' => $drupal_locale_desc,
              'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
              'active' => $active,
              'preview' => globallink_entity_make_preview_link('Preview', $item->nid),
            );
            $default_checked_ids = array(
              $item->nid . '-' . $vid => TRUE,
            );
          }
        }
      }
      $form['#attributes']['class'][] = 'globallink-entity-form-clear';
      $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;
}