function globallink_webform_dashboard_form in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_webform/globallink_webform_send.inc \globallink_webform_dashboard_form()
- 7.6 globallink_webform/globallink_webform_send.inc \globallink_webform_dashboard_form()
Builds form to create a webform submission.
1 string reference to 'globallink_webform_dashboard_form'
- globallink_webform_dashboard_page in globallink_webform/
globallink_webform_send.inc - Builds forms on webform send dashboard.
File
- globallink_webform/
globallink_webform_send.inc, line 261
Code
function globallink_webform_dashboard_form() {
module_load_include('inc', 'globallink_webform', 'globallink_webform');
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_WEBFORM,
'sessionKey' => 'wfids',
),
), 'setting');
drupal_add_css($module_path . '/css/globallink.css');
$form = array();
$default_checked = array();
if (isset($_SESSION['wfids'])) {
$default_checked = $_SESSION['wfids'];
}
$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_webform_page_count'])) {
$page_count = $_SESSION['globallink_webform_page_count'][0];
}
$default_language = language_default();
$default = $default_language->language;
if (!empty($_SESSION['globallink_selected_webform_language'])) {
$default = $_SESSION['globallink_selected_webform_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] = ' ' . $value . '<BR/>';
}
else {
$target_lang_arr[$key] = ' ' . $value . ' ';
}
}
if (!($query = globallink_webform_get_translate_filter_query())) {
$query = array(
'translation' => 'all',
'language' => 'all',
'string' => '',
);
}
$sql_query = db_select('locales_source', 's')
->extend('PagerDefault')
->limit($page_count);
$limit_language = NULL;
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');
}
$header = array(
'parent' => t('WEBFORM TITLE'),
'string' => array(
'data' => t('String'),
'field' => 's.location',
),
'languages' => $limit_language ? t('Language') : t('IN ACTIVE SUBMISSION'),
'preview' => t('Preview'),
);
$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.context', '%#%', 'LIKE');
$sql_query
->groupBy('lid')
->extend('TableSort');
$sort_order = isset($_GET['sort']) ? $_GET['sort'] : '';
if ($sort_order) {
$sql_query
->orderBy('source', $_GET['sort']);
}
$result = $sql_query
->execute();
$webform_results = array();
foreach ($result as $item) {
array_push($webform_results, $item);
}
$locales = globallink_get_mapped_drupal_locales(FALSE);
$rows = array();
$count = 0;
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;
}
$active = '';
$active_arr = globallink_webform_get_active_submission_by_id($webform->lid);
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) . ' - ' . $active_row->sub_target_lang_name . ' <BR/> ';
}
}
if (!isset($rows[$webform->lid])) {
$rows[$webform->lid] = array(
'parent' => $title,
'string' => check_plain(truncate_utf8($webform->source, 150, FALSE, TRUE)) . ' <br /> ',
'languages' => $active,
'nid' => $nid,
'preview' => globallink_webform_make_preview_link('Preview', $webform->lid),
);
}
$count++;
}
$cart_count = get_cart_count();
globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
if ($count > 0) {
$form['pager'] = array(
'#markup' => theme('pager'),
);
}
}
// Very important
form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
return $form;
}