You are here

function globallink_webform_receive_form in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 globallink_webform/globallink_webform_receive.inc \globallink_webform_receive_form()

Builds form to receive a webform submission.

1 string reference to 'globallink_webform_receive_form'
globallink_webform_receive_submissions in globallink_webform/globallink_webform_receive.inc
Builds forms on webform receive dashboard.

File

globallink_webform/globallink_webform_receive.inc, line 269

Code

function globallink_webform_receive_form() {
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
  $form = array();
  if (!empty($_SESSION['globallink_webform_receive_type'])) {
    $type = $_SESSION['globallink_webform_receive_type'];
  }
  $globallink_arr = array();
  if (!empty($_SESSION['globallink_webform_globalLink_arr'])) {
    $globallink_arr = unserialize($_SESSION['globallink_webform_globalLink_arr']);
  }
  $page_count = isset($_SESSION['globallink_webform_receive_page_count']) ? $_SESSION['globallink_webform_receive_page_count'][0] : TPT_PAGER_LIMIT;
  $rows = array();
  $filter_lang = '[any]';
  if (!empty($_SESSION['globallink_webform_receive_filter_language'])) {
    $filter_lang = $_SESSION['globallink_webform_receive_filter_language'];
  }
  if (isset($globallink_arr) && is_array($globallink_arr)) {
    foreach ($globallink_arr as $key => &$globallink) {
      if ($filter_lang != '[any]' && $globallink->targetLocale != $filter_lang) {
        unset($globallink_arr[$key]);
      }
    }
  }
  if (isset($globallink_arr) && is_array($globallink_arr)) {
    $filter_status = '[any]';
    if (!empty($_SESSION['globallink_webform_receive_filter_status'])) {
      $filter_status = $_SESSION['globallink_webform_receive_filter_status'];
    }
    $header = array(
      'submissionName' => t('Submission'),
      'sourceLocale' => t('Source Language'),
      'targetLocale' => t('Target Language'),
      'source' => 'Source',
      'status' => t('Status'),
    );
    if (variable_get('globallink_enable_preview', 1)) {
      $header['preview'] = '';
    }
    $count = 1;
    $rid_arr = array();
    foreach ($globallink_arr as $key => &$globallink) {
      if ($globallink->type != 'webform') {
        continue;
      }
      $pd4 = globallink_get_project_director_details();
      $target_xml = '';
      $query = db_select('globallink_core_webform', 'gcw')
        ->fields('gcw')
        ->condition('submission_ticket', $globallink->submissionTicket, '=')
        ->condition('document_ticket', $globallink->documentTicket, '=')
        ->condition('parent_id', $globallink->otherObjectId, '=')
        ->condition('target', $globallink->targetLocale, '=');
      $active_submissions = $query
        ->execute();
      foreach ($active_submissions as $k => $value) {
        $lid = $value->object_id;
        $title = $value->title;
        $status = globallink_webform_get_translation_status($lid, $globallink->targetLocale, $title);
        if ($status == 'Source Deleted') {
          $globallink->sourceDeleted = TRUE;
        }
        if ($filter_status != '[any]' && $status != $filter_status) {
          unset($globallink_arr[$key]);
          continue;
        }
        $filter_submission = '[any]';
        if (!empty($_SESSION['globallink_webform_receive_filter_submission'])) {
          $filter_submission = $_SESSION['globallink_webform_receive_filter_submission'];
        }
        if ($filter_submission != '[any]' && $globallink->submissionName != $filter_submission) {
          unset($globallink_arr[$key]);
          continue;
        }
        if (variable_get('globallink_enable_preview', 1)) {
          if ($status != 'Source Deleted') {
            $tpt_row_id = globallink_webform_get_row_id_from_submission($globallink->submissionTicket, $globallink->documentTicket, $globallink->targetLocale);
            if ($tpt_row_id) {
              $rid_arr['tpt_content_div_' . $lid] = $tpt_row_id;
            }
          }
        }
        $source_name = globallink_get_drupal_locale_name($globallink->sourceLocale);
        $target_name = globallink_get_drupal_locale_name($globallink->targetLocale);
        $rows[$lid . '@@' . $key] = array(
          'submissionName' => $globallink->submissionName,
          'sourceLocale' => $source_name,
          'targetLocale' => $target_name,
          'source' => $title,
          'status' => $status,
        );
        if (variable_get('globallink_enable_preview', 1)) {
          $rows[$lid . '@@' . $key]['preview'] = $status != 'Source Deleted' ? l(t('Preview Translations'), 'javascript:void(0)', array(
            'fragment' => '',
            'external' => TRUE,
            'attributes' => array(
              'id' => 'tpt_content_link_' . $lid,
            ),
          )) : '';
        }
        $count++;
      }
    }
    $form['table'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => globallink_pager_array_splice($rows, $page_count),
      '#empty' => t('No items available'),
    );
    $form['pager'] = array(
      '#markup' => theme('pager'),
    );
    if (variable_get('globallink_enable_preview', 1)) {
      $lcount = 1;
      $div_arr = array();
      foreach ($rid_arr as $key => $rid) {
        if (isset($rid)) {
          $lcount = str_replace('tpt_content_div_', '', $key);
          $form['tpt_content_div_' . $lcount] = array(
            '#type' => 'markup',
            '#markup' => '',
            '#prefix' => '<div id="tpt_content_div_' . $lcount . '" style="display: none;">',
            '#suffix' => '</div>',
          );
          $div_arr['tpt_content_link_' . $lcount] = 'tpt_content_div_' . $lcount;
        }
      }
      drupal_add_js(array(
        'globallink' => array(
          'popup' => $div_arr,
          'previewpath' => base_path() . 'admin/globallink-translations/receiveTranslation/webform/preview',
          'rids' => $rid_arr,
        ),
      ), 'setting');
    }
    if ($count > 1) {
      $form['submit_update_selected'] = array(
        '#type' => 'submit',
        '#value' => t('Update Selected'),
      );
      $form['submit_update_all'] = array(
        '#type' => 'submit',
        '#value' => t('Update All'),
      );
      $form['submit_clear_deleted_hidden'] = array(
        '#type' => 'submit',
        '#value' => t('Clear Deleted Records'),
        '#attributes' => array(
          'style' => 'display:none;',
          'disabled' => 'true',
        ),
      );
      $form['submit_clear_deleted'] = array(
        '#type' => 'submit',
        '#value' => t('Clear Deleted Records'),
      );
    }
    $last_refreshed = '';
    if (isset($_SESSION['globallink_webform_globalLink_arr_last_refreshed'])) {
      $last_refreshed = $_SESSION['globallink_webform_globalLink_arr_last_refreshed'];
    }
    $form['submit_refresh_hidden'] = array(
      '#type' => 'submit',
      '#value' => t('Refresh Page'),
      '#prefix' => '<BR/>',
      '#attributes' => array(
        'style' => 'display:none;',
        'disabled' => 'true',
      ),
    );
    $form['submit_refresh'] = array(
      '#type' => 'submit',
      '#value' => t('Refresh Page'),
    );
    $form['markup'] = array(
      '#type' => 'markup',
      '#markup' => 'Last refreshed : ' . $last_refreshed,
    );
  }
  drupal_add_js('jQuery(document).ready(function(){jQuery("#edit-submit-clear-deleted").click(function(){jQuery("#edit-submit-clear-deleted").hide();jQuery("#edit-submit-clear-deleted-hidden").css("display","inline");});});', 'inline');
  drupal_add_js('jQuery(document).ready(function(){jQuery("#edit-submit-refresh").click(function(){jQuery("#edit-submit-refresh").hide();jQuery("#edit-submit-refresh-hidden").css("display","inline");});});', 'inline');
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_library('system', 'ui.dialog');
  drupal_add_css($module_path . '/css/globallink.css');
  drupal_add_js($module_path . '/globallink_webform/js/globallink_webform_receive.js');
  return $form;
}