You are here

function globallink_block_dashboard_form in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_block/globallink_block_send.inc \globallink_block_dashboard_form()
  2. 7.6 globallink_block/globallink_block_send.inc \globallink_block_dashboard_form()

Builds form to create a block submission.

1 string reference to 'globallink_block_dashboard_form'
globallink_block_dashboard in globallink_block/globallink_block_send.inc
Builds forms on block send dashboard.

File

globallink_block/globallink_block_send.inc, line 202

Code

function globallink_block_dashboard_form() {
  module_load_include('inc', 'globallink_block', 'globallink_block');
  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_BLOCK,
      'sessionKey' => 'bids',
    ),
  ), 'setting');
  drupal_add_css($module_path . '/css/globallink.css');
  $form = array();
  $default_checked = array();
  if (isset($_SESSION['bids'])) {
    $default_checked = $_SESSION['bids'];
  }
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  if (isset($locales) && count($locales) > 1) {
    $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $default_info = '';
    if (!empty($_SESSION['globallink_selected_block_info'])) {
      $default_info = $_SESSION['globallink_selected_block_info'];
    }
    $default_language = language_default();
    $default = $default_language->language;
    unset($target_lang_arr[globallink_get_locale_code($default)]);
    $t_count = 0;
    foreach ($target_lang_arr as $key => $value) {
      $t_count++;
      if ($t_count % 2 === 0) {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '<BR/>';
      }
      else {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '&nbsp;&nbsp;&nbsp;&nbsp;';
      }
    }
    $query = db_select('i18n_string', 'i18n')
      ->condition('textgroup', 'blocks', '=')
      ->fields('i18n', array(
      'objectid',
    ))
      ->distinct();
    $result = $query
      ->execute();
    $block_ids = array();
    foreach ($result as $row) {
      $block_ids[] = $row->objectid;
    }
    $page_count = TPT_PAGER_LIMIT;
    if (isset($_SESSION['globallink_block_page_count'])) {
      $page_count = $_SESSION['globallink_block_page_count'][0];
    }
    $header = array(
      'info' => array(
        'field' => 'bc.info',
        'data' => t('Block Info'),
      ),
      'active' => t('In Active Submission'),
      'preview' => t('Preview'),
    );
    $rows = array();
    $count = 0;
    if (count($block_ids) > 0) {
      $query = db_select('block_custom', 'bc')
        ->condition('bid', $block_ids, 'IN')
        ->fields('bc')
        ->extend('PagerDefault')
        ->limit($page_count)
        ->extend('TableSort')
        ->orderByHeader($header);
      if ($default_info != '') {
        $query
          ->condition('info', '%' . $default_info . '%', 'LIKE');
      }
      $result = $query
        ->execute();
      foreach ($result as $item) {
        $active = '';
        $active_arr = globallink_block_get_active_submission_by_id($item->bid);
        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->bid] = array(
          'info' => $item->info,
          'active' => $active,
          'preview' => globallink_block_make_preview_link('Preview', $item->bid),
        );
        $count++;
      }
    }
    $cart_count = get_cart_count();
    globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
    if ($count > 0) {
      $form['pager'] = [
        '#markup' => theme('pager'),
      ];
    }
  }

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