',
);
//switch operations
if ($vid1 != $vid2) {
$form['double-tree']['operations']['move_right']['#value'] = 'Switch right';
$form['double-tree']['operations']['move_right']['#attributes']['title'] = t('Switch selected terms and its children to the right voc');
$form['double-tree']['operations']['move_left']['#value'] = 'Switch left';
$form['double-tree']['operations']['move_left']['#attributes']['title'] = t('Switch selected terms and its children to the left voc');
}
else if (isset($language)) {
$form['double-tree']['operations']['add_translation'] = array(
'#type' => 'image_button',
'#value' => 'translation',
'#attributes' => array('title' => t('Add Translation')),
'#src' => $module_path ."images/connect.png",
//'#executes_submit_callback' => FALSE,
'#prefix' => '
',
'#suffix' => '
',
);
}
return $form;
}
function taxonomy_manager_toolbar_forms() {
/*$params = $_GET;
$form = array();
$form_state = array('submitted' => FALSE);
$form = form_get_cache($params['form_build_id'], $form_state);
$form += taxonomy_manager_confirm_delete($form['vid']);
$form = form_builder($param['form_id'], $form, $form_state);
drupal_prepare_form($param['form_id'], $form, $form_state);
$form = form_builder($param['form_id'], $form, $form_state);
form_set_cache($params['form_build_id'], $form, $form_state);
$output = drupal_render($form['delete']);
print drupal_to_js(array('status' => TRUE, 'data' => $output));
exit;*/
}
/**
* confirmation form for deleting selected terms
*/
function taxonomy_manager_confirm_delete($voc) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-delete-confirm',
'hide_button' => 'edit-delete-cancel',
'div' => 'del-confirm-form')), 'setting');
$form = array();
$form['delete'] = array(
'#type' => 'fieldset',
'#attributes' => array('id' => 'del-confirm-form', 'style' => 'display:none;'),
'#tree' => TRUE,
'#title' => t('Confirmation'),
);
$question = t('Are you sure you want to delete all selected terms? ');
$info = t('Remember all term specific data will be lost. This action cannot be undone.');
$form['delete']['text'] = array('#value' => "". $question ." ". $info);
$options = array(
'delete_orphans' => t('Delete children of selected terms, if there are any'),
);
$form['delete']['options'] = array(
'#type' => 'checkboxes',
'#title' => t('Options'),
'#options' => $options,
);
$form['delete']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#attributes' => array('class' => 'taxonomy-manager-buttons delete'),
'#submit' => array('taxonomy_manager_form_delete_submit'),
'#validate' => array('taxonomy_manager_form_delete_validate'),
);
$form['delete']['cancel'] = array(
'#type' => 'button',
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
'#value' => t('Cancel'),
'#theme' => 'no_submit_button',
);
return $form;
}
/**
* form for adding terms
*/
function taxonomy_manager_add_form($voc, $hide_form = TRUE) {
if ($hide_form) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-add-show',
'hide_button' => 'edit-add-cancel',
'div' => 'add-form')), 'setting');
$attributes = array('id' => 'add-form', 'style' => 'display:none;');
}
else {
$attributes = array('id' => 'add-form');
}
$form = array();
$description = "";
$description = t("If you have selected one or more terms in the tree view, the new terms are automatically children of those.");
$form['add'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#attributes' => $attributes,
'#title' => t('Add new terms'),
'#description' => $description,
);
for ($i=0; $i<6; $i++) {
$form['add']['term'][$i] = array(
'#type' => 'textfield',
);
}
$form['add']['mass'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Mass term import (with textarea)'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['add']['mass']['mass_add'] = array(
'#type' => 'textarea',
'#title' => t('Terms'),
'#description' => t('One term per line'),
'#rows' => 10,
);
$form['add']['add'] = array(
'#type' => 'submit',
'#attributes' => array('class' => 'taxonomy-manager-buttons add'),
'#value' => t('Add'),
'#validate' => array('taxonomy_manager_form_add_validate'),
'#submit' => array('taxonomy_manager_form_add_submit'),
);
$form['add']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#theme' => 'no_submit_button',
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
);
return $form;
}
/**
* form for merging terms
*/
function taxonomy_manager_merge_form($voc) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-merge-show',
'hide_button' => 'edit-merge-cancel',
'div' => 'merge-form')), 'setting');
$form = array();
$description .= t("The selected terms get merged into one term.
This resulting merged term can either be an exisiting term or a completely new term.
The selected terms will automatically get synomyms of the merged term and will be deleted afterwards.");
$form['merge'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#attributes' => array('id' => 'merge-form', 'style' => 'display:none;'),
'#title' => t('Merging of terms'),
'#description' => $description,
);
$form['merge']['main_term'] = array(
'#type' => 'textfield',
'#title' => t('Resulting merged term'),
'#required' => FALSE,
'#autocomplete_path' => 'taxonomy_manager/autocomplete/'. $voc->vid,
);
$options = array();
$options['collect_parents'] = t('Collect all parents of selected terms an add it to the merged term');
$options['collect_children'] = t('Collect all children of selected terms an add it to the merged term');
$options['collect_relations'] = t('Collect all relations of selected terms an add it to the merged term');
if (count($options) > 0) {
$form['merge']['options'] = array(
'#type' => 'checkboxes',
'#title' => t('Options'),
'#options' => $options,
);
}
$form['merge']['submit'] = array(
'#type' => 'submit',
'#value' => t('Merge'),
'#attributes' => array('class' => 'taxonomy-manager-buttons merge'),
'#validate' => array('taxonomy_manager_form_merge_validate'),
'#submit' => array('taxonomy_manager_form_merge_submit'),
);
$form['merge']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
'#theme' => 'no_submit_button',
);
return $form;
}
/**
* form for moving terms in hierarchies
*/
function taxonomy_manager_move_form($voc) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-move-show',
'hide_button' => 'edit-move-cancel',
'div' => 'move-form')), 'setting');
$form = array();
$description = t("You can change the parent of one or more selected terms.
If you leave the autocomplete field empty, the term will be a root term.");
$form['move'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#attributes' => array('id' => 'move-form', 'style' => 'display:none;'),
'#title' => t('Moving of terms'),
'#description' => $description,
);
if ($voc->hierarchy == 2) {
$auto_description .= t("Separate parent terms with a comma. ");
}
$form['move']['parents'] = array(
'#type' => 'textfield',
'#title' => t('Parent term(s)'),
'#description' => $auto_description,
'#required' => FALSE,
'#autocomplete_path' => 'taxonomy_manager/autocomplete/'. $voc->vid,
);
$options = array();
$options['keep_old_parents'] = t('Keep old parents and add new ones (multi-parent). Otherwise old parents get replaced.');
$form['move']['options'] = array(
'#type' => 'checkboxes',
'#title' => t('Options'),
'#options' => $options,
);
$form['move']['submit'] = array(
'#type' => 'submit',
'#attributes' => array('class' => 'taxonomy-manager-buttons move'),
'#value' => t('Move'),
'#validate' => array('taxonomy_manager_form_move_validate'),
'#submit' => array('taxonomy_manager_form_move_submit'),
);
$form['move']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
'#theme' => 'no_submit_button',
);
return $form;
}
/**
* form for exporting terms
*/
function taxonomy_manager_export_form($voc) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-export-show',
'hide_button' => 'edit-export-cancel',
'div' => 'export-form')), 'setting');
$module_path = drupal_get_path('module', 'taxonomy_manager') .'/';
drupal_add_js($module_path .'js/csv_export.js');
drupal_add_js(array('exportCSV' => array('url' => url("admin/content/taxonomy_manager/export"))), 'setting');
$form = array();
$form['export'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#attributes' => array('id' => 'export-form', 'style' => 'display:none;'),
'#title' => t('CSV Export'),
'#description' => $description,
);
$form['export']['delimiter'] = array(
'#type' => 'textfield',
'#title' => t('Delimiter for CSV File'),
'#required' => FALSE,
'#default_value' => ";",
);
$options['whole_voc'] = t('Whole Vocabulary');
$options['children'] = t('Child terms of a selected term');
$options['root_terms'] = t('Root level terms only');
$form['export']['options'] = array(
'#type' => 'radios',
'#title' => t('Terms to export'),
'#options' => $options,
'#default_value' => 'whole_voc',
'#prefix' => '
',
'#suffix' => '
',
);
$form['export']['depth'] = array(
'#type' => 'textfield',
'#title' => t('Depth of tree'),
'#description' => t('The number of levels of the tree to export. Leave empty to return all levels.'),
);
$form['export']['csv'] = array(
'#type' => 'textarea',
'#title' => t('Exported CSV'),
'#description' => t('The generated code will appear here (per AJAX). You can copy and paste the code into a .csv file. The csv has following columns: voc id | term id | term name | description | parent id 1 | ... | parent id n'),
'#rows' => 8,
);
$form['export']['submit'] = array(
'#type' => 'submit',
'#attributes' => array('class' => 'taxonomy-manager-buttons export'),
'#value' => t('Export now'),
'#theme' => 'no_submit_button',
);
$form['export']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
'#theme' => 'no_submit_button',
);
return $form;
}
function taxonomy_manager_double_tree_settings_form($voc) {
drupal_add_js(array('hideForm' => array(
'show_button' => 'edit-double-tree-show',
'hide_button' => 'edit-double-tree-cancel',
'div' => 'double-tree-settings-form')), 'setting');
$form = array();
$form['double_tree'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#attributes' => array('id' => 'double-tree-settings-form', 'style' => 'display:none;'),
'#title' => t('Double Tree Settings'),
'#description' => t('Specify settings for second tree. Choose the same vocabulary if you want to move terms in the hierarchy or if you want to add new translations within a multilingual vocabulary. Choose a different vocabulary if you want to switch terms among these vocabularies.'),
);
$options = array();
$vocs = taxonomy_get_vocabularies();
foreach ($vocs as $v) {
$options[$v->vid] = $v->name;
}
$form['double_tree']['voc2'] = array(
'#type' => 'select',
'#title' => t('Vocabulary for second tree'),
'#options' => $options,
'#default_value' => $voc->vid,
);
$form['double_tree']['submit'] = array(
'#type' => 'submit',
'#attributes' => array('class' => 'taxonomy-manager-buttons double-tree'),
'#value' => t('Enable Double Tree'),
'#submit' => array('taxonomy_manager_form_double_tree_submit'),
);
if (arg(3) == "double-tree") {
$form['double_tree']['disable'] = array(
'#type' => 'submit',
'#attributes' => array('class' => 'taxonomy-manager-buttons double-tree-disable'),
'#value' => t('Disable Double Tree'),
'#submit' => array('taxonomy_manager_form_double_tree_disable_submit'),
);
}
$form['double_tree']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('class' => 'taxonomy-manager-buttons cancel'),
'#theme' => 'no_submit_button',
);
return $form;
}
/**
* menu callback for displaying term data form
*
* if this function gets called by ahah, then the term data form gets
* generated, rendered and return
* otherwise, if no ahah call, redirect to original form with $vid and $tid as parameters
*
* @param $vid
* @param $tid
* @param $ahah if true, return rendered form, else redirect
*/
function taxonomy_manager_update_term_data_form($vid, $tid, $ahah = FALSE, $print = TRUE, $msg = "", $is_error_msg = FALSE) {
if (!$ahah) {
drupal_goto('admin/content/taxonomy_manager/voc/'. $vid .'/'. $tid);
}
$GLOBALS['devel_shutdown'] = FALSE; //prevent devel queries footprint
$params = $_GET;
//actually we don not need do use the caching because the saving only happens through a AJAX callback
//and it's a bit faster, cache loading, form building and cache saving needs some time else.
/*$form_state = array('submitted' => FALSE);
$form = form_get_cache($params['form_build_id'], $form_state);
unset($form['term_data']);
$form = form_builder($param['form_id'], $form, $form_state);*/
$term_form = taxonomy_manager_form_term_data($tid);
$term_form['term_data']['save'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
'#submit' => array(''),
'#attributes' => array('class' => 'taxonomy-manager-buttons save'),
'#ahah' => array(
'path' => 'admin/content/taxonomy_manager/termdata/edit',
'method' => 'replace',
'event' => 'click',
'wrapper' => 'taxonomy-term-data',
'progress' => array('type' => ''),
),
'#weight' => 20,
);
if ($msg != "") {
$term_form['term_data']['msg'] = array(
'#type' => 'markup',
'#prefix' => '
',
'#suffix' => '
',
'#value' => $msg,
'#weight' => -20,
);
if ($is_error_msg) {
$term_form['term_data']['msg']['#value'] = t("Error! Your last operation couldn't be performed because of following problem:") ." ". $msg;
$term_form['term_data']['msg']['#prefix'] = '
';
}
}
$form = $term_form;
drupal_prepare_form('taxonomy_manager_form', $form, $form_state);
$form = form_builder('taxonomy_manager_form', $form, $form_state);
//form_set_cache($params['form_build_id'], $form, $form_state);
$output = drupal_render($form['term_data']);
if ($print) {
print $output;
exit();
}
return $output;
}
/**
* term data editing form
*
* @param $tid
*/
function taxonomy_manager_form_term_data($tid) {
$term = taxonomy_get_term($tid);
$module_path = drupal_get_path('module', 'taxonomy_manager') .'/';
$vocabulary = taxonomy_vocabulary_load($term->vid);
//prevent that title of the fieldset is too long
$title = $term->name;
if (drupal_strlen($title) >= 33) {
$title = drupal_substr($title, 0, 33) ."...";
}
$title .= " (". $term->tid .")";
$title = check_plain($title);
$form['term_data'] = array(
'#type' => 'fieldset',
'#title' => $title,
'#attributes' => array('id' => 'taxonomy-term-data-fieldset'),
'#tree' => TRUE,
);
$form['term_data']['close'] = array(
'#value' => '