You are here

function globallink_interface_dashboard_form in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink_interface/globallink_interface_send.inc \globallink_interface_dashboard_form()
  2. 7.6 globallink_interface/globallink_interface_send.inc \globallink_interface_dashboard_form()

Builds form to create an interface submission.

1 string reference to 'globallink_interface_dashboard_form'
globallink_interface_dashboard_page in globallink_interface/globallink_interface_send.inc
Builds forms on interface send dashboard.

File

globallink_interface/globallink_interface_send.inc, line 238

Code

function globallink_interface_dashboard_form() {
  module_load_include('inc', 'globallink_interface', 'globallink_interface');
  module_load_include('inc', 'globallink', 'globallink');
  $form = array();
  $module_path = drupal_get_path('module', 'globallink');
  $locales = globallink_get_mapped_drupal_locales(FALSE);
  if (isset($locales) && count($locales) > 1) {
    $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $page_count = TPT_PAGER_LIMIT;
    if (isset($_SESSION['globallink_interface_page_count'])) {
      $page_count = $_SESSION['globallink_interface_page_count'][0];
    }
    $default_language = language_default();
    $default = $default_language->language;
    if (!empty($_SESSION['globallink_selected_interface_language'])) {
      $default = $_SESSION['globallink_selected_interface_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;';
      }
    }
    if (!($query = globallink_interface_get_translate_filter_query())) {
      $query = array(
        'translation' => 'all',
        'language' => 'all',
        'string' => '',
        'group' => 'all',
      );
    }
    $sql_query = db_select('locales_source', 's')
      ->extend('PagerDefault')
      ->limit($page_count);
    $limit_language = NULL;
    if (isset($query['language']) && $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');
    }
    $header = array(
      'textgroup' => array(
        'data' => t('Text Group'),
        'field' => 's.textgroup',
      ),
      'string' => array(
        'data' => t('String'),
        'field' => 's.location',
      ),
      'active' => t('In Active Submission'),
    );
    $sql_query
      ->fields('s', array(
      'source',
      'location',
      'context',
      'lid',
      'textgroup',
    ));
    $sql_query
      ->fields('t', array(
      'translation',
      'language',
    ));
    if (!isset($query['translation'])) {
      $query['translation'] = 'all';
    }
    if (!isset($query['language'])) {
      $query['language'] = 'all';
    }
    if (!isset($query['group'])) {
      $query['group'] = 'all';
    }
    if (!isset($query['string'])) {
      $query['string'] = '';
    }
    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;
    }
    if ($query['group'] != 'all') {
      $sql_query
        ->condition('s.textgroup', $query['group']);
    }
    $sql_query
      ->extend('TableSort')
      ->groupBy('lid')
      ->orderByHeader($header);
    $sort_order = isset($_GET['sort']) ? $_GET['sort'] : '';
    if ($sort_order) {
      $sql_query
        ->orderBy('source', $_GET['sort']);
    }
    $result = $sql_query
      ->execute();
    $interface_results = array();
    $lids = array();
    foreach ($result as $item) {
      array_push($lids, $item->lid);
      array_push($interface_results, $item);
    }
    $groups = module_invoke_all('locale', 'groups');
    $active_subs = globallink_interface_get_active_submission_rows_by_lid($lids);
    $locales = globallink_get_mapped_drupal_locales(FALSE);
    $rows = array();
    $count = 0;
    foreach ($interface_results as $interface) {
      $active = '';
      if ($active_subs && array_key_exists($interface->lid, $active_subs)) {
        $sub_arr = $active_subs[$interface->lid];
        $sub_name = '';
        $tgt_arr = array();
        foreach ($sub_arr as $sub_name => $tgt_arr) {
          $l_title = globallink_format_display_string($sub_name);
          $l_href = 'admin/globallink-translations/activeSubmissions/interface';
          $l_options = array(
            'query' => array(
              'submission' => urlencode($sub_name),
            ),
          );
          $active .= l($l_title, $l_href, $l_options) . '&nbsp;&nbsp;- &nbsp;&nbsp;';
          $t_count = 0;
          foreach ($tgt_arr as $tgt) {
            $t_count++;
            $tgt_name = $locales[globallink_get_drupal_locale_code($tgt)];
            if ($t_count == count($tgt_arr)) {
              $active .= $tgt_name . ' <BR/> ';
            }
            else {
              $active .= $tgt_name . ', &nbsp;&nbsp;';
            }
          }
        }
      }
      if (!isset($rows[$interface->lid])) {
        $rows[$interface->lid] = array(
          'textgroup' => $groups[$interface->textgroup],
          'string' => check_plain(truncate_utf8($interface->source, 150, FALSE, TRUE)) . '<br /><small>' . $interface->location . '</small>',
          'active' => $active,
        );
      }
      if (isset($interface->language)) {
        $rows[$interface->lid]['languages'][$interface->language] = $interface->translation;
      }
      $count++;
    }
    $form['table'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $rows,
      '#empty' => t('No strings available.'),
    );
    if ($count > 0) {
      $form['pager'] = array(
        '#markup' => theme('pager'),
      );
    }
    if (user_access(TPT_ROLE_DO_TRANSLATIONS) || user_access(TPT_ROLE_MANAGE_TRANSLATIONS)) {
      if ($count > 0) {
        drupal_add_css($module_path . '/css/globallink.css');
        $proj_arr = variable_get('globallink_pd_projects', array());
        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);
        $form['send_submission'] = array(
          '#type' => 'fieldset',
          '#title' => t('Create Submission'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form['send_submission']['submission_name'] = array(
          '#type' => 'textfield',
          '#title' => 'Submission Name',
          '#size' => 40,
          '#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',
          '#required' => TRUE,
          '#attributes' => array(
            'class' => array(
              'pickadate1',
            ),
            'style' => array(
              'padding:0px;',
            ),
          ),
          '#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' => '',
          '#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($default),
          '#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,
          '#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' => 40,
          '#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('Send for Translation'),
        );
      }
    }
  }
  return $form;
}