function globallink_dashboard_node_form in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_send_translations.inc \globallink_dashboard_node_form()
- 7.6 globallink_send_translations.inc \globallink_dashboard_node_form()
Builds form to create a GlobalLink submission.
1 string reference to 'globallink_dashboard_node_form'
- globallink_dashboard_page in ./
globallink_send_translations.inc - Builds forms on GlobalLink send dashboard.
File
- ./
globallink_send_translations.inc, line 525
Code
function globallink_dashboard_node_form() {
module_load_include('inc', 'globallink', 'globallink_node');
module_load_include('inc', 'globallink', 'globallink');
drupal_add_library('system', 'drupal.ajax');
drupal_add_js(drupal_get_path('module', 'globallink') . '/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_NODE,
'sessionKey' => 'nids',
),
), 'setting');
$default_checked_ids = array();
$default_checked = array();
if (isset($_SESSION['nids'])) {
$default_checked = $_SESSION['nids'];
}
$module_path = drupal_get_path('module', 'globallink');
$form = array();
$locales = globallink_get_mapped_drupal_locales(FALSE);
$node_types = globallink_get_translatable_node_types(TRUE);
if (isset($locales) && count($locales) > 1) {
if (isset($node_types) && count($node_types) > 0) {
$redirect_nid = isset($_GET['rnid']) ? $_GET['rnid'] : '';
if ($redirect_nid != '') {
$_SESSION['globallink_dashboard_filter'] = array();
}
$sort_order = isset($_GET['order']) ? $_GET['order'] : '';
$header = array(
'title' => array(
'field' => 'title',
'data' => t('Content'),
),
'type' => array(
'field' => 't_name',
'data' => t('Content Type'),
),
'language' => array(
'field' => 'name',
'data' => t('Language'),
),
'changed' => array(
'field' => 'changed',
'data' => t('Last Modified'),
),
'active' => t('In Active Submission'),
'preview' => t('Preview'),
);
$node_check = variable_get('globallink_implementation_type', 0);
$target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
$include_node_arr = array();
$query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n');
if (empty($_SESSION['globallink_dashboard_filter'])) {
$query
->condition('language', $GLOBALS['globallink_source_locale'], '=');
}
else {
$filter_arr = isset($_SESSION['globallink_dashboard_filter']) ? $_SESSION['globallink_dashboard_filter'] : array();
globallink_build_filter_query($query, $filter_arr);
}
$query
->condition('type', $node_types, 'IN');
$query
->fields('n');
$results = $query
->execute();
foreach ($results as $item) {
array_push($include_node_arr, $item->nid);
}
$modified = 0;
if (isset($_SESSION['globallink_dashboard_filter']['modified'])) {
$modified = $_SESSION['globallink_dashboard_filter']['modified'][1];
}
$tgt_lang = '';
if (isset($_SESSION['globallink_dashboard_filter']['target_language'])) {
$tgt_lang = $_SESSION['globallink_dashboard_filter']['target_language'][1];
}
$status = '';
if (module_exists('revisioning')) {
if (isset($_SESSION['globallink_dashboard_filter']['status'])) {
list($key, $value) = explode('-', $_SESSION['globallink_dashboard_filter']['status'][1], 2);
$status = $value;
}
else {
$status = '1';
}
}
$t_count = 0;
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] = ' ' . $value . '<BR/>';
}
else {
$target_lang_arr[$key] = ' ' . $value . ' ';
}
}
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 ($tgt_lang != '' && $tgt_lang != '[Any]') {
$t_query = db_select('globallink_document', 'gd');
$t_query
->condition('gd.target_lang_code', globallink_get_locale_code($tgt_lang), '=');
$t_query
->condition('gd.target_status', array(
GLOBALLINK_STATUS_TRANSLATION_SENT,
GLOBALLINK_STATUS_TRANSLATION_ERROR,
GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
), 'IN');
$t_query
->condition(db_or()
->condition('gd.entity_type', GLOBALLINK_ENTITY_TYPE_NODE)
->condition('gd.entity_type', GLOBALLINK_ENTITY_TYPE_ENTITY));
$t_query
->fields('gd');
$t_query
->orderBy('object_id', 'ASC');
$results = $t_query
->execute();
foreach ($results as $item) {
if ($item->target_status == GLOBALLINK_STATUS_TRANSLATION_SENT || $item->target_status == GLOBALLINK_STATUS_TRANSLATION_ERROR || $item->target_status == GLOBALLINK_STATUS_TRANSLATION_COMPLETED) {
$key = array_search($item->object_id, $include_node_arr);
unset($include_node_arr[$key]);
}
}
}
if ($modified == 0) {
$t_query = db_select('globallink_core', 'tc');
$t_query
->condition('source', globallink_get_locale_code(empty($_SESSION['globallink_source_locale']) ? $GLOBALS['globallink_source_locale'] : $_SESSION['globallink_source_locale']), '=');
$t_query
->fields('tc');
$t_query
->orderBy('nid', 'ASC');
$results = $t_query
->execute();
$item_arr = array();
foreach ($results as $item) {
$key = array_search($item->nid, $include_node_arr);
if ($key !== FALSE) {
if (array_key_exists($item->nid, $item_arr)) {
array_push($item_arr[$item->nid], $item);
}
else {
$item_arr[$item->nid] = array(
$item,
);
}
}
}
$tgt_keys = array_keys($target_lang_arr);
foreach ($include_node_arr as $key => $nid) {
if (isset($item_arr[$nid])) {
$ncount = count($tgt_keys);
foreach ($item_arr[$nid] as $item) {
foreach ($tgt_keys as $target) {
if (!isset($item->target)) {
continue;
}
if ($target == $item->target) {
if ($item->changed == 0 || $item->changed == 2) {
$ncount--;
}
}
}
}
if ($ncount == 0) {
unset($include_node_arr[$key]);
}
}
}
}
$page_count = TPT_PAGER_LIMIT;
if (isset($_SESSION['globallink_send_page_count'])) {
$page_count = $_SESSION['globallink_send_page_count'][0];
}
$count = 0;
$rows = array();
$d_query = db_select(GLOBALLINK_ENTITY_TYPE_NODE, 'n')
->extend('PagerDefault')
->limit($page_count)
->extend('TableSort');
if ($node_check == 1) {
if ($redirect_nid == '' && count($include_node_arr) > 0) {
$selected_target_lang = NULL;
if ($tgt_lang != '' && $tgt_lang != '[Any]') {
$selected_target_lang = $tgt_lang;
}
foreach ($include_node_arr as $key => $nid) {
if (!globallink_is_node_translatable(node_load($nid), $selected_target_lang)) {
unset($include_node_arr[$key]);
}
}
if (count($include_node_arr) > 0) {
$d_query
->condition('nid', $include_node_arr, 'IN');
$d_query
->join('languages', 'l', 'l.language = n.language');
$d_query
->join('node_type', 't', 't.type = n.type');
$d_query
->fields('n', array(
'nid',
'vid',
'title',
'type',
'changed',
));
$d_query
->fields('l', array(
'name',
));
$d_query
->fields('t', array(
'name',
));
if ($sort_order == '') {
$d_query
->orderBy('nid', 'DESC');
}
else {
$d_query
->orderByHeader($header);
}
$results = $d_query
->execute();
$rows = array();
foreach ($results as $item) {
$count++;
$active = '';
$active_arr = globallink_get_active_submission_by_nid($item->nid);
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/> ';
}
}
$rows[$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' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
'active' => $active,
'preview' => _make_preview_link('Preview', $item->nid),
);
}
}
}
}
else {
$revisioning = FALSE;
if (module_exists('revisioning') && $status != '') {
if ($status == '1') {
$d_query
->condition('status', 1, '=');
}
else {
$revisioning = TRUE;
}
}
if ($redirect_nid == '' && count($include_node_arr) > 0) {
$d_query
->condition('nid', $include_node_arr, 'IN');
$d_query
->join('languages', 'l', 'l.language = n.language');
$d_query
->join('node_type', 't', 't.type = n.type');
$d_query
->fields('n', array(
'nid',
'vid',
'title',
'type',
'changed',
));
$d_query
->fields('l', array(
'name',
));
$d_query
->fields('t', array(
'name',
));
if ($sort_order == '') {
$d_query
->orderBy('nid', 'DESC');
}
else {
$d_query
->orderByHeader($header);
}
$results = $d_query
->execute();
$rows = array();
foreach ($results as $item) {
$count++;
$vid = $item->vid;
if ($revisioning) {
if ($status == 0) {
$vid = revisioning_get_latest_revision_id($item->nid);
}
}
$node = node_load($item->nid, $vid);
$active = '';
$active_arr = globallink_get_active_submission_by_nid($item->nid);
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;
if ($active_row->object_version_id != $vid) {
$active .= ' (Different version)<BR/>';
}
else {
$active .= ' <BR/> ';
}
}
}
if ($status) {
$title = l(globallink_format_display_string($node->title), 'node/' . $item->nid . '/revisions/' . $node->vid . '/view');
}
else {
$title = l(globallink_format_display_string($node->title), 'node/' . $item->nid);
}
$rows[$item->nid . '-' . $vid] = array(
'nid' => $item->nid,
'title' => $title,
'type' => $item->t_name,
'language' => $item->name,
'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
'active' => $active,
'preview' => _make_preview_link('Preview', $item->nid),
);
}
}
else {
$d_query
->condition('nid', $redirect_nid, '=');
$d_query
->join('languages', 'l', 'l.language = n.language');
$d_query
->join('node_type', 't', 't.type = n.type');
$d_query
->fields('n', array(
'nid',
'vid',
'title',
'type',
'changed',
));
$d_query
->fields('l', array(
'name',
));
$d_query
->fields('t', array(
'name',
));
if ($sort_order == '') {
$d_query
->orderBy('title', 'ASC');
}
else {
$d_query
->orderByHeader($header);
}
$results = $d_query
->execute();
$include_node_arr = array();
$include_node_arr[] = $redirect_nid;
$rows = array();
foreach ($results as $item) {
$count++;
$vid = $item->vid;
if ($revisioning) {
$vid = revisioning_get_latest_revision_id($item->nid);
}
$node = node_load($item->nid, $vid);
$active = '';
$active_arr = globallink_get_active_submission_by_nid($item->nid);
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;
if ($active_row->object_version_id != $vid) {
$active .= ' (Different version)<BR/>';
}
else {
$active .= ' <BR/> ';
}
}
}
$rows[$item->nid . '-' . $vid] = array(
'nid' => $item->nid,
'title' => l(globallink_format_display_string($item->title), 'node/' . $item->nid),
'type' => $item->t_name,
'language' => $item->name,
'changed' => format_date($item->changed, 'custom', 'Y-m-d H:i:s'),
'active' => $active,
'preview' => _make_preview_link('Preview', $item->nid),
);
$default_checked_ids = array(
$item->nid . '-' . $vid => TRUE,
);
}
}
}
$cart_count = get_cart_count();
globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
$form['#attributes']['class'][] = 'globallink-node-form-clear';
if ($count > 0) {
$form['pager'] = array(
'#markup' => theme('pager'),
);
}
drupal_add_css($module_path . '/css/globallink.css');
}
}
return $form;
}