You are here

function globallink_all_active_form in GlobalLink Connect for Drupal 7.7

Builds form to show all active entity submissions.

2 string references to 'globallink_all_active_form'
globallink_all_active_submissions in ./globallink_workbench_all_active_submissions.inc
Builds forms on entity active submissions dashboard.
globallink_dashboard_active_submissions_page in ./globallink_workbench_all_active_submissions.inc

File

./globallink_workbench_all_active_submissions.inc, line 349

Code

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