View source
<?php
module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
function globallink_taxonomy_dashboard($type) {
$default_date = format_date(REQUEST_TIME + 7 * 24 * 60 * 60, 'custom', 'm/d/Y');
drupal_add_library('system', 'ui.datepicker');
drupal_add_js('jQuery(function() {
jQuery(document).ajaxComplete(function() {
jQuery(".pickadate1").datepicker({
dateFormat: "mm/dd/yy",
defaultDate: "' . $default_date . '",
minDate: 0
});
});
});', array(
'group' => CSS_THEME,
'type' => 'inline',
'scope' => 'header',
'weight' => 80,
));
$_SESSION['globallink_selected_type'] = $type;
$array = array();
$array[] = drupal_get_form('globallink_taxonomy_dashboard_filter_form');
$array[] = drupal_get_form('globallink_taxonomy_dashboard_pager_form');
$array[] = drupal_get_form('globallink_taxonomy_dashboard_form');
return $array;
}
function globallink_taxonomy_dashboard_filter_form() {
module_load_include('inc', 'globallink', 'globallink');
module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
$form = array();
$locales = globallink_get_mapped_drupal_locales(FALSE);
if (isset($locales) && count($locales) > 1) {
$filter = FALSE;
$default_info = '';
if (!empty($_SESSION['globallink_selected_taxonomy_info'])) {
$default_info = $_SESSION['globallink_selected_taxonomy_info'];
$filter = TRUE;
}
$default_vocab = '[any]';
if (!empty($_SESSION['globallink_selected_taxonomy_vocab'])) {
$default_vocab = $_SESSION['globallink_selected_taxonomy_vocab'];
$filter = TRUE;
}
$vocab_arr = globallink_taxonomy_get_vocabulary_list();
$form['taxonomy_info_filter'] = array(
'#type' => 'fieldset',
'#title' => t('FILTER TERMS'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['taxonomy_info_filter']['filters'] = array(
'#type' => 'container',
);
$form['taxonomy_info_filter']['filters']['vocab'] = array(
'#type' => 'select',
'#title' => t('Vocabulary') . ': ',
'#options' => $vocab_arr,
'#default_value' => $default_vocab,
'#field_suffix' => ' ',
);
$form['taxonomy_info_filter']['filters']['info'] = array(
'#type' => 'textfield',
'#title' => t('Term Name') . ': ',
'#attributes' => array(
'size' => 30,
),
'#default_value' => $default_info,
'#field_suffix' => ' ',
);
$disable_submit = $filter ? TRUE : FALSE;
$form['taxonomy_info_filter']['filters']['filter'] = array(
'#type' => 'submit',
'#value' => t('Filter'),
'#disabled' => $disable_submit,
);
if ($filter) {
$form['filter-search'] = array(
'#type' => 'fieldset',
'#title' => t('FILTER CRITERIA'),
);
$form['filter-search']['filter-markup'] = array(
'#type' => 'container',
);
$form['filter-search']['filter-markup'][] = array(
'#markup' => '<table>',
);
if (!empty($default_vocab)) {
$form['filter-search']['filter-markup'][] = array(
'#markup' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;"><b>' . t('Vocabulary') . '</b>: </td><td style="text-align: left;width: 85%;vertical-align: middle;border: none;">' . $vocab_arr[$default_vocab] . '</td></tr>',
);
}
if (!empty($default_info)) {
$form['filter-search']['filter-markup'][] = array(
'#markup' => '<tr><td style="text-align: left;width: 15%;vertical-align: middle;border: none;"><b>' . t('Term Name') . '</b>: </td><td style="text-align: left;width: 85%;vertical-align: middle;border: none;">' . $default_info . '</td></tr>',
);
}
$form['filter-search']['filter-markup'][] = array(
'#markup' => '</table>',
);
$form['filter-search']['status']['actions'] = array(
'#type' => 'actions',
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$form['filter-search']['status']['actions']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
);
}
}
else {
$form['locale_mapping']['no_mapping'] = array(
'#type' => 'markup',
'#markup' => t('<br/><b><i>No GlobalLink locale mapping found.</i></b>'),
);
}
return $form;
}
function globallink_taxonomy_dashboard_filter_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
switch ($op) {
case t('Filter'):
$_SESSION['globallink_selected_taxonomy_vocab'] = $form_state['values']['vocab'];
$_SESSION['globallink_selected_taxonomy_info'] = $form_state['values']['info'];
break;
case t('Reset'):
$_SESSION['globallink_selected_taxonomy_info'] = '';
$_SESSION['globallink_selected_taxonomy_vocab'] = '';
break;
}
}
function globallink_taxonomy_dashboard_pager_form() {
$form = array();
$locales = globallink_get_mapped_drupal_locales(FALSE);
if (isset($locales) && count($locales) > 1) {
$form['page_counter']['markup'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'tpt-center',
),
),
);
$form['page_counter']['markup']['p_count'] = array(
'#type' => 'textfield',
'#size' => 5,
'#default_value' => isset($_SESSION['globallink_taxonomy_page_count']) ? $_SESSION['globallink_taxonomy_page_count'][0] : TPT_PAGER_LIMIT,
'#field_prefix' => t('Show') . ' ',
'#field_suffix' => ' ' . t('records') . ' ',
'#prefix' => '<div class="container-inline">',
);
$form['page_counter']['markup']['action'] = array(
'#type' => 'submit',
'#value' => t('Go'),
'#suffix' => '</div>',
'#limit_validation_errors' => array(),
'#submit' => array(
'globallink_taxonomy_pager_form_submit',
),
'#access' => TRUE,
);
}
return $form;
}
function globallink_taxonomy_pager_form_submit($form, &$form_state) {
$op = $form_state['values']['op'];
if ($op != t('Go')) {
return;
}
$page_count = $form_state['input']['p_count'];
if (!is_numeric($page_count) || $page_count < 1) {
form_set_error('', t('Invalid Page Count.'));
}
else {
$_SESSION['globallink_taxonomy_page_count'] = array(
$page_count,
);
return;
}
}
function globallink_taxonomy_dashboard_form() {
module_load_include('inc', 'globallink_taxonomy', 'globallink_taxonomy');
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_TAXONOMY,
'sessionKey' => 'tids',
),
), 'setting');
drupal_add_css($module_path . '/css/globallink.css');
$form = array();
$default_checked = array();
if (isset($_SESSION['tids'])) {
$default_checked = $_SESSION['tids'];
}
$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 = $target_lang_arr;
$default_info = '';
if (!empty($_SESSION['globallink_selected_taxonomy_info'])) {
$default_info = $_SESSION['globallink_selected_taxonomy_info'];
}
$default_vocab = '[any]';
if (!empty($_SESSION['globallink_selected_taxonomy_vocab'])) {
$default_vocab = $_SESSION['globallink_selected_taxonomy_vocab'];
}
$language = language_default();
$default_language = $language->language;
unset($target_lang_arr[globallink_get_locale_code($default_language)]);
$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 . ' ';
}
}
$page_count = TPT_PAGER_LIMIT;
if (isset($_SESSION['globallink_taxonomy_page_count'])) {
$page_count = $_SESSION['globallink_taxonomy_page_count'][0];
}
$header = array(
'vocab' => array(
'field' => 'v.name',
'data' => t('Vocabulary'),
),
'name' => array(
'field' => 't.name',
'data' => t('Term Name'),
),
'language' => array(
'field' => 't.language',
'data' => t('Language'),
),
'active' => t('In Active Submission'),
'preview' => t('Preview'),
);
$rows = array();
$query = db_select('taxonomy_term_data', 't')
->extend('PagerDefault')
->limit($page_count)
->extend('TableSort')
->orderByHeader($header);
$i18nmodes = array(
'0',
'2',
);
$query
->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
$query
->fields('t', array(
'tid',
'name',
'vid',
'language',
));
$query
->fields('v', array(
'name',
));
$query
->condition('v.i18n_mode', $i18nmodes, 'NOT IN');
if ($default_info != '') {
$query
->condition('t.name', '%' . $default_info . '%', 'LIKE');
}
if ($default_vocab != '[any]') {
$query
->condition('t.vid', array(
$default_vocab,
), 'IN');
}
$source_lang = language_default()->language;
$drupal_langs = globallink_get_mapped_drupal_locales(FALSE);
if (!empty($drupal_langs)) {
$drupal_langs['und'] = '';
$query
->condition('t.language', array(
$source_lang,
'und',
), 'IN');
}
$result = $query
->execute();
$count = 0;
foreach ($result as $item) {
$active = '';
$active_arr = globallink_taxonomy_get_active_submission_by_id($item->tid);
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->tid] = array(
'vocab' => $item->v_name,
'name' => $item->name,
'language' => $drupal_langs[$item->language],
'active' => $active,
'preview' => globallink_taxonomy_make_preview_link('Preview', $item->tid),
);
$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'),
);
}
}
form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
return $form;
}
function globallink_taxonomy_dashboard_form_validate($form, &$form_state) {
return;
}
function globallink_taxonomy_dashboard_form_submit($form, &$form_state) {
return;
}
function globallink_taxonomy_make_preview_link($link_text = '', $id) {
drupal_add_js(array(
'my-modal-style' => array(
'modalSize' => array(
'type' => 'fixed',
'width' => 700,
'height' => 400,
),
'animation' => 'fadeIn',
),
), 'setting');
if (empty($link_text)) {
$link_text = 'Preview';
}
return '<div id="preview-link" style="text-align: left;" title="Click to Preview">' . l($link_text, 'admin/globallink-translations/dashboard/taxonomy/preview/' . $id . '/nojs', array(
'attributes' => array(
'class' => 'ctools-use-modal ctools-modal-my-modal-style',
),
)) . '</div>';
}
function globallink_taxonomy_preview($ajax) {
if ($ajax) {
ctools_include('ajax');
ctools_include('modal');
$form_state = array(
'ajax' => TRUE,
'title' => t('Preview'),
);
$output = ctools_modal_form_wrapper('globallink_taxonomy_preview_content', $form_state);
if (!empty($form_state['ajax_commands'])) {
$output = $form_state['ajax_commands'];
}
print ajax_render($output);
drupal_exit();
}
else {
return drupal_get_form('globallink_taxonomy_preview_content');
}
}
function globallink_taxonomy_preview_content() {
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
module_load_include('inc', 'globallink', 'globallink');
$id = arg(5);
$output = "";
$taxo = taxonomy_term_load($id);
$info = entity_translation_taxonomy_term_enabled_vocabulary($taxo->vocabulary_machine_name);
$output .= "<table><tr><th>Fields</th><th>Source Contents</th></tr>";
if (!$info) {
$string = globallink_get_taxonomy_xml_for_I18N_MODE_LOCALIZE($taxo, NULL);
$xml = new SimpleXMLElement($string);
$elem = $xml->taxonomy
->count();
if ($elem > 0) {
foreach ($xml->taxonomy as $element) {
$tag = $element
->getName();
$value = (string) $element;
$label = (string) $element
->attributes()->label;
$output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
}
}
}
else {
$string = globallink_get_taxonomy_xml_for_I18N_MODE_ENTITY_TRANSLATE($taxo, NULL);
$xml = new SimpleXMLElement($string);
$elem = $xml->field
->count();
if ($elem > 0) {
foreach ($xml->field as $element) {
$tag = $element
->getName();
$value = (string) $element;
$label = (string) $element
->attributes()->label;
$output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
}
}
}
$output .= "</table>";
$form['preview'] = array(
'#markup' => $output,
);
return $form;
}