You are here

function globallink_create_submission_form in GlobalLink Connect for Drupal 7.7

1 string reference to 'globallink_create_submission_form'
globallink_submission_callback in ./globallink_send_translations.inc

File

./globallink_send_translations.inc, line 1225

Code

function globallink_create_submission_form($form, &$form_state) {
  form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink_entity', 'globallink_entity');
  module_load_include('inc', 'globallink_block', 'globallink_block');
  module_load_include('inc', 'globallink_menu', 'globallink_menu');
  module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
  module_load_include('inc', 'globallink_interface', 'globallink_interface');
  module_load_include('inc', 'globallink_fieldable_panels', 'globallink_fieldable_panels');
  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');
  $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
  $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
  $module_path = drupal_get_path('module', 'globallink');
  $languages = globallink_get_mapped_drupal_locales(FALSE);
  $groups = module_invoke_all('locale', 'groups');
  if (user_access(TPT_ROLE_DO_TRANSLATIONS) || user_access(TPT_ROLE_MANAGE_TRANSLATIONS)) {
    drupal_add_css($module_path . '/css/globallink.css');
    $proj_arr = variable_get('globallink_pd_projects', array());
    $tgt_lang = '';
    $t_count = 0;
    if (isset($_SESSION['globallink_dashboard_filter']['target_language'])) {
      $tgt_lang = $_SESSION['globallink_dashboard_filter']['target_language'][1];
    }
    foreach ($target_lang_arr as $key => $value) {
      if ($key == globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])) {
        continue;
      }
      $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;';
      }
    }
    unset($target_lang_arr[globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale'])]);
    if ($tgt_lang != '' && $tgt_lang != '[Any]') {
      $target_lang_arr_keys = array_keys($target_lang_arr);
      foreach ($target_lang_arr_keys as $t_key) {
        if (globallink_get_locale_code($tgt_lang) != $t_key) {
          unset($target_lang_arr[$t_key]);
        }
      }
    }
    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);
    $submission_priorities = array(
      1 => 'Regular',
      2 => 'Urgent',
    );
    $form['send_submission']['submission_name'] = array(
      '#type' => 'textfield',
      '#title' => 'Submission Name',
      '#size' => 20,
      '#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',
      '#size' => 10,
      '#required' => TRUE,
      '#attributes' => array(
        'class' => array(
          'pickadate1',
        ),
      ),
      '#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' => 1,
      '#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(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale']),
      '#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,
      '#attributes' => array(
        'class' => array(
          'globallink-create-sub-target-locale-checkboxes',
        ),
      ),
      '#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' => 10,
      '#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('Request Translation'),
    );
    $form['remove-selected'] = array(
      '#type' => 'button',
      '#value' => t('Remove Selected'),
      '#limit_validation_errors' => array(),
      '#ajax' => array(
        'callback' => 'globallink_dashboard_node_form_ajax_remove_selected',
      ),
    );
  }

  // Showing contents in popup table.
  if (get_cart_count() > 0) {
    $header = array(
      'title' => array(
        'field' => 'title',
        'data' => t('Title'),
      ),
      'type' => array(
        'field' => 't_name',
        'data' => t('Type'),
      ),
      'language' => array(
        'field' => 'name',
        'data' => t('Language'),
      ),
      'changed' => array(
        'field' => 'changed',
        'data' => t('Last Modified'),
      ),
      'entity_type' => t('Entity Type'),
    );
    $rows = array();
    if (isset($_SESSION['nids']) && count($_SESSION['nids']) > 0) {
      $nodes = array();
      foreach ($_SESSION['nids'] as $val) {
        $tmp_nid = explode('-', $val);
        $nodes[] = $tmp_nid[0];
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
      $query
        ->join('languages', 'l', 'l.language = n.language');
      $query
        ->join('node_type', 't', 't.type = n.type');
      $query
        ->fields('n', array(
        'nid',
        'vid',
        'title',
        'type',
        'changed',
      ));
      $query
        ->fields('l', array(
        'name',
      ));
      $query
        ->fields('t', array(
        'name',
      ));
      $query
        ->condition('nid', $nodes, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['nids|' . $item->nid . '-' . $item->vid] = array(
          'nid' => $item->nid,
          'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
          'type' => $item->t_name,
          'language' => $item->name,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Node'),
          '#attributes' => array(
            'class' => array(
              'cart-row-nids-' . $item->nid . '-' . $item->vid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['eids']) && count($_SESSION['eids']) > 0) {
      $entity_ids = array();
      foreach ($_SESSION['eids'] as $val) {
        $tmp_nid = explode('-', $val);
        $entity_ids[] = $tmp_nid[0];
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
      $query
        ->join('languages', 'l', 'l.language = n.language');
      $query
        ->join('node_type', 't', 't.type = n.type');
      $query
        ->fields('n', array(
        'nid',
        'vid',
        'title',
        'type',
        'changed',
      ));
      $query
        ->fields('l', array(
        'name',
      ));
      $query
        ->fields('t', array(
        'name',
      ));
      $query
        ->condition('nid', $entity_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['eids|' . $item->nid . '-' . $item->vid] = array(
          'nid' => $item->nid,
          'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
          'type' => $item->t_name,
          'language' => $item->name,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Entity'),
          '#attributes' => array(
            'class' => array(
              'cart-row-eids-' . $item->nid . '-' . $item->vid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['bids']) && count($_SESSION['bids']) > 0) {
      $block_ids = array();
      foreach ($_SESSION['bids'] as $val) {
        $block_ids[] = $val;
      }
      $query = db_select('block_custom', 'bc');
      $query
        ->fields('bc');
      $query
        ->condition('bid', $block_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['bids|' . $item->bid] = array(
          'nid' => $item->bid,
          'title' => $item->info,
          'type' => 'Block',
          'language' => '',
          'changed' => '',
          'entity_type' => t('Block'),
          '#attributes' => array(
            'class' => array(
              'cart-row-bids-' . $item->bid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['fpids']) && count($_SESSION['fpids']) > 0) {
      $fpids = array();
      foreach ($_SESSION['fpids'] as $val) {
        $fpids[] = $val;
      }
      $query = db_select(GLOBALLINK_ENTITY_TYPE_FPP, 'fpp');
      $query
        ->fields('fpp');
      $query
        ->condition('fpp.fpid', $fpids, 'IN');
      $results = $query
        ->execute();
      $fpp_info = entity_get_info('fieldable_panels_pane');
      foreach ($results as $item) {
        $bundles = $fpp_info['bundles'];
        $bundle = $item->bundle;
        $bundle_label = '';
        if (isset($bundles) && isset($bundles[$bundle]) && isset($bundles[$bundle]['label'])) {
          $bundle_label = $bundles[$bundle]['label'];
        }
        $rows['fpids|' . $item->fpid] = array(
          'nid' => '',
          'title' => l($item->title, 'admin/structure/fieldable-panels-panes/view/' . $item->fpid . '/edit', array(
            'attributes' => array(
              'target' => '_blank',
            ),
          )),
          'type' => 'Fieldable Panel',
          'lang' => $languages[$item->language],
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Fieldable Panel'),
          '#attributes' => array(
            'class' => array(
              'cart-row-fpids-' . $item->fpid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['int_ids']) && count($_SESSION['int_ids']) > 0) {
      $int_ids = array();
      foreach ($_SESSION['int_ids'] as $val) {
        $int_ids[] = $val;
      }
      $query = db_select('locales_source', 'ls');
      $query
        ->fields('ls');
      $query
        ->condition('ls.lid', $int_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['int_ids|' . $item->lid] = array(
          'nid' => $item->lid,
          'title' => check_plain(truncate_utf8($item->source, 150, FALSE, TRUE)) . '<br /><small>' . $item->location . '</small>',
          'type' => $groups[$item->textgroup],
          'language' => '',
          'changed' => '',
          'entity_type' => t('Interface'),
          '#attributes' => array(
            'class' => array(
              'cart-row-int_ids-' . $item->lid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['mids']) && count($_SESSION['mids']) > 0) {
      $menu_types = menu_get_menus(TRUE);
      $menu_ids = array();
      foreach ($_SESSION['mids'] as $val) {
        $menu_ids[] = $val;
      }
      $query = db_select('menu_links', 'ml');
      $query
        ->fields('ml');
      $query
        ->condition('mlid', $menu_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['mids|' . $item->mlid] = array(
          'nid' => $item->mlid,
          'title' => l($item->link_title, $item->link_path),
          'type' => 'Menu',
          'language' => $languages[$item->language],
          'changed' => '',
          'entity_type' => t('Menu'),
          '#attributes' => array(
            'class' => array(
              'cart-row-mids-' . $item->mlid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['tids']) && count($_SESSION['tids']) > 0) {
      $taxo_ids = array();
      foreach ($_SESSION['tids'] as $val) {
        $taxo_ids[] = $val;
      }
      $query = db_select('taxonomy_term_data', 't');
      $query
        ->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
      $query
        ->fields('t', array(
        'tid',
        'name',
        'vid',
        'language',
      ));
      $query
        ->fields('v', array(
        'name',
      ));
      $query
        ->condition('t.tid', $taxo_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['tids|' . $item->tid] = array(
          'nid' => $item->tid,
          'title' => $item->v_name . ': ' . $item->name,
          'type' => 'Taxonomy',
          'language' => $languages[$item->language],
          'changed' => '',
          'entity_type' => t('Taxonomy'),
          '#attributes' => array(
            'class' => array(
              'cart-row-tids-' . $item->tid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['wfids']) && count($_SESSION['wfids']) > 0) {
      $wfids = array();
      foreach ($_SESSION['wfids'] as $val) {
        $wfids[] = $val;
      }
      if (!($query = globallink_webform_get_translate_filter_query())) {
        $query = array(
          'translation' => 'all',
          'language' => 'all',
          'string' => '',
        );
      }
      $sql_query = db_select('locales_source', 's');
      if ($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');
      }
      $sql_query
        ->fields('s', array(
        'source',
        'location',
        'context',
        'lid',
        'textgroup',
      ));
      $sql_query
        ->fields('t', array(
        'translation',
        'language',
      ));
      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;
      }
      $sql_query
        ->condition('s.textgroup', GLOBALLINK_ENTITY_TYPE_WEBFORM);
      $sql_query
        ->condition('s.context', '%email%', 'NOT LIKE');
      $sql_query
        ->condition('s.lid', $wfids, 'IN');
      $result = $sql_query
        ->execute();
      $webform_results = array();
      foreach ($result as $item) {
        array_push($webform_results, $item);
      }
      foreach ($webform_results as $webform) {
        $title = $webform->source;
        $results = db_select('webform_component', 'wc')
          ->fields('wc')
          ->condition('name', $title, '=')
          ->execute();
        foreach ($results as $result) {
          $nid = $result->nid;
        }
        $results_p = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n')
          ->fields('n')
          ->condition('nid', $nid, '=')
          ->execute();
        foreach ($results_p as $result_p) {
          $title = $result_p->title;
        }
        if (!isset($rows[$webform->lid])) {
          $rows['wfids|' . $webform->lid] = array(
            'title' => $title . ':' . check_plain(truncate_utf8($webform->source, 150, FALSE, TRUE)) . ' <br /> ',
            'language' => '',
            'type' => 'Webform',
            'nid' => $nid,
            'changed' => '',
            'entity_type' => t('Webform'),
            '#attributes' => array(
              'class' => array(
                'cart-row-wfids-' . $item->lid,
              ),
            ),
          );
        }
      }
    }
    if (isset($_SESSION['bnids']) && count($_SESSION['bnids']) > 0) {
      $bean_ids = array();
      foreach ($_SESSION['bnids'] as $val) {
        $bean_ids[] = $val;
      }
      $query = db_select('bean', 'bn');
      $query
        ->fields('bn');
      $query
        ->condition('bn.bid', $bean_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['bnids|' . $item->bid] = array(
          'bnid' => $item->bid,
          'title' => $item->title,
          'type' => $item->type,
          // 'language' => $languages[$item->language],.
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Bean'),
          '#attributes' => array(
            'class' => array(
              'cart-row-bnids-' . $item->bid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['fids']) && count($_SESSION['fids']) > 0) {
      $fe_ids = array();
      foreach ($_SESSION['fids'] as $fe) {
        $fe_ids[] = $fe;
      }
      $query = db_select('file_managed', 'fm');
      $query
        ->fields('fm');
      $query
        ->condition('fm.fid', $fe_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['fids|' . $item->fid] = array(
          'fid' => $item->fid,
          'title' => $item->filename,
          'type' => $item->type,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('File Enity'),
          '#attributes' => array(
            'class' => array(
              'cart-row-fids-' . $item->fid,
            ),
          ),
        );
      }
    }
    if (isset($_SESSION['pids']) && count($_SESSION['pids']) > 0) {
      $cp_ids = array();
      foreach ($_SESSION['pids'] as $cp) {
        $cp_ids[] = $cp;
      }
      $query = db_select('commerce_product', 'cp');
      $query
        ->fields('cp');
      $query
        ->condition('cp.product_id', $cp_ids, 'IN');
      $results = $query
        ->execute();
      foreach ($results as $item) {
        $rows['pids|' . $item->product_id] = array(
          'title' => $item->title,
          'type' => $item->type,
          'language' => $languages[$item->language],
          'sku' => $item->sku,
          'changed' => date('Y-m-d H:i:s', $item->changed),
          'entity_type' => t('Commerce Product'),
          '#attributes' => array(
            'class' => array(
              'cart-row-pids-' . $item->product_id,
            ),
          ),
        );
      }
    }
    $form['table-content'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => globallink_pager_array_splice($rows, 10),
      '#empty' => t('No items available'),
    );
    $form['pager'] = array(
      '#theme' => 'pager',
    );
  }
  return $form;
}