function globallink_dashboard_node_form in GlobalLink Connect for Drupal 7.5
Same name and namespace in other branches
- 7.7 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 502
Code
function globallink_dashboard_node_form() {
module_load_include('inc', 'globallink', 'globallink_node');
module_load_include('inc', 'globallink', 'globallink');
$default_checked_ids = array();
$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'),
);
$node_check = variable_get('globallink_implementation_type', 0);
$source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
$target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
$include_node_arr = array();
$query = db_select('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_core', 'tc');
$t_query
->condition('target', globallink_get_locale_code($tgt_lang), '=');
$t_query
->fields('tc');
$t_query
->orderBy('nid', 'ASC');
$results = $t_query
->execute();
foreach ($results as $item) {
if ($item->status == 'Sent for Translations' || $item->status == 'Error') {
$key = array_search($item->nid, $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($GLOBALS['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 ($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('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();
$active_subs = globallink_get_active_submission_rows_by_nid($include_node_arr);
$rows = array();
foreach ($results as $item) {
$count++;
$active = '';
if ($active_subs && array_key_exists($item->nid, $active_subs)) {
$sub_arr = $active_subs[$item->nid];
$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/node';
$l_options = array(
'query' => array(
'submission' => urlencode($sub_name),
),
);
$active .= l($l_title, $l_href, $l_options) . ' - ';
$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 . ', ';
}
}
}
}
$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,
);
}
}
}
}
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++;
$active_arr = globallink_get_active_submission_by_nid($item->nid);
$vid = $item->vid;
if ($revisioning) {
if ($status == 0) {
$vid = revisioning_get_latest_revision_id($item->nid);
}
}
$node = node_load($item->nid, $vid);
$active = '';
if ($active_arr) {
foreach ($active_arr as $sub_name => $tgt_arr) {
$l_title = globallink_format_display_string($sub_name);
$l_href = 'admin/globallink-translations/activeSubmissions/node';
$l_options = array(
'query' => array(
'submission' => urlencode($sub_name),
),
);
$active .= l($l_title, $l_href, $l_options) . ' - ';
if (count($tgt_arr) > 1) {
$t_count = 1;
foreach ($tgt_arr as $tgt => $_vid) {
$tgt_name = $locales[globallink_get_drupal_locale_code($tgt)];
if ($t_count == count($tgt_arr)) {
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version)<BR/> ';
}
else {
$active .= $tgt_name . ' <BR/> ';
}
}
else {
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version), ';
}
else {
$active .= $tgt_name . ', ';
}
}
$t_count++;
}
}
else {
foreach ($tgt_arr as $tgt => $_vid) {
$tgt_name = $locales[globallink_get_drupal_locale_code($tgt)];
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version) <BR/> ';
}
else {
$active .= $tgt_name . ' <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,
);
}
}
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++;
$active_arr = globallink_get_active_submission_by_nid($item->nid);
$vid = $item->vid;
if ($revisioning) {
$vid = revisioning_get_latest_revision_id($item->nid);
}
$node = node_load($item->nid, $vid);
$active = '';
if ($active_arr) {
foreach ($active_arr as $sub_name => $tgt_arr) {
$l_title = globallink_format_display_string($sub_name);
$l_href = 'admin/globallink-translations/activeSubmissions/node';
$l_options = array(
'query' => array(
'submission' => urlencode($sub_name),
),
);
$active .= l($l_title, $l_href, $l_options) . ' - ';
if (count($tgt_arr) > 1) {
$t_count = 1;
foreach ($tgt_arr as $tgt => $_vid) {
$tgt_name = $locales[globallink_get_drupal_locale_code($tgt)];
if ($t_count == count($tgt_arr)) {
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version)<BR/> ';
}
else {
$active .= $tgt_name . ' <BR/> ';
}
}
else {
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version), ';
}
else {
$active .= $tgt_name . ', ';
}
}
$t_count++;
}
}
else {
foreach ($tgt_arr as $tgt => $_vid) {
$tgt_name = $locales[globallink_get_drupal_locale_code($tgt)];
if ($_vid != $vid) {
$active .= $tgt_name . ' (Different version) <BR/> ';
}
else {
$active .= $tgt_name . ' <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,
);
$default_checked_ids = array(
$item->nid . '-' . $vid => TRUE,
);
}
}
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('No items available'),
'#default_value' => $default_checked_ids,
);
$form['#attributes']['class'][] = 'globallink-node-form-clear';
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) {
if ($modified == 0 && $redirect_nid == '') {
$form['clear_changed_flag'] = array(
'#type' => 'submit',
'#value' => t('Clear "Changed" Status'),
'#limit_validation_errors' => array(),
'#submit' => array(
'globallink_node_form_clear_submit',
),
'#access' => TRUE,
'#attributes' => array(
'class' => array(
'globallink-node-form-clear-submit',
),
),
);
}
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);
$submission_priorities = array(
'Low',
'Normal',
'High',
);
$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(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,
'#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'),
);
}
}
drupal_add_css($module_path . '/css/globallink.css');
}
}
return $form;
}