You are here

function globallink_block_active_form in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_block/globallink_block_active_submissions.inc \globallink_block_active_form()

Builds form to show all active block submissions.

1 string reference to 'globallink_block_active_form'
globallink_block_active_submissions in globallink_block/globallink_block_active_submissions.inc
Builds forms on block active submissions dashboard.

File

globallink_block/globallink_block_active_submissions.inc, line 181

Code

function globallink_block_active_form() {
  module_load_include('inc', 'globallink', 'globallink');
  $form = array();
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_css($module_path . '/css/globallink.css');
  $redirect_submission = isset($_GET['submission']) ? urldecode($_GET['submission']) : '';
  $selected_value = '';
  if (empty($redirect_submission) && !empty($_SESSION['globallink_block_selected_submission'])) {
    $selected_value = $_SESSION['globallink_block_selected_submission'];
  }
  elseif (!empty($redirect_submission)) {
    $options = globallink_block_get_active_submission_names();
    $selected_value = array_search($redirect_submission, $options);
  }
  $page_count = TPT_PAGER_LIMIT;
  if (isset($_SESSION['globallink_block_active_page_count'])) {
    $page_count = $_SESSION['globallink_block_active_page_count'][0];
  }
  $projects = globallink_get_pd_projects();
  $header = array(
    'submission' => array(
      'field' => 'submission',
      'data' => t('Submission Name'),
    ),
    'info' => array(
      'field' => 'info',
      'data' => t('Block Info'),
    ),
    'project_code' => array(
      'field' => 'project_code',
      'data' => t('Project'),
    ),
    'source_name' => array(
      'field' => 'source_name',
      'data' => t('Source Language'),
    ),
    'target_name' => array(
      'field' => 'target_name',
      'data' => t('Target Language'),
    ),
    'status' => array(
      'field' => 'status',
      'data' => t('Status'),
    ),
    'timestamp' => array(
      'field' => 'timestamp',
      'data' => t('Last Updated'),
    ),
  );
  $query = db_select('globallink_core_block', 'tc')
    ->extend('PagerDefault')
    ->limit($page_count)
    ->extend('TableSort')
    ->orderByHeader($header);
  $query
    ->condition('status', array(
    'Sent for Translations',
    'Error',
    'Cancelled',
  ), 'IN');
  if ($selected_value != '') {
    $query
      ->condition('submission_ticket', $selected_value, '=');
  }
  $query
    ->join('globallink_locale', 'tl1', 'tc.source = tl1.locale_code');
  $query
    ->join('globallink_locale', 'tl2', 'tc.target = tl2.locale_code');
  $query
    ->fields('tc');
  $query
    ->addField('tl1', 'drupal_locale_desc', 'source_name');
  $query
    ->addField('tl2', 'drupal_locale_desc', 'target_name');
  $results = $query
    ->execute();
  $count = 0;
  $rows = array();
  foreach ($results as $item) {
    $count++;
    $block_info = globallink_block_load_data($item->object_id);
    $rows[$item->rid] = array(
      'submission' => $item->submission,
      'info' => $block_info[0]->info,
      'project_code' => isset($projects[$item->project_code]) ? $projects[$item->project_code] : '',
      'source_name' => $item->source_name,
      'target_name' => $item->target_name,
      'status' => $item->status,
      'timestamp' => format_date($item->timestamp, 'custom', 'Y-m-d H:i:s'),
    );
  }
  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No items available'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  if ($count > 0) {
    if (user_access(TPT_ROLE_MANAGE_TRANSLATIONS)) {
      $form['submit_cancel_document'] = array(
        '#type' => 'submit',
        '#value' => t('Cancel Selected Documents'),
      );
      $form['submit_clear_cancelled_documents'] = array(
        '#type' => 'submit',
        '#value' => t('Clear Cancelled Documents'),
      );
    }
  }
  return $form;
}