'; $chosenjslink = ''; if (!$ajax) { $headerinsert .= $chosencsslink; $headerinsert .= $chosenjslink; } $new_node_record_form_action = generateURL("{$baseurl}/pages/admin/admin_manage_field_options.php", ['field' => $field]); $activation_action_label_for = fn(array $node): string => node_is_active($node) ? $lang['userpreference_disable_option'] : $lang['userpreference_enable_option']; // Process form requests if ($ajax === 'true' && trim($node_ref) != "" && 0 < $node_ref) { $option_name = trim(getval('option_name', '')); $option_parent = trim(getval('option_parent', '')); $option_new_index = getval('node_order_by', '', true); if ($option_new_index != "") { $option_new_index -= 1; } $node_action = getval('node_action', ''); // [Save Option] if ('save' === $node_action && enforcePostRequest($ajax)) { $response['refresh_page'] = false; $node_ref_data = array(); // If node baing saved has a parent and the parent changes then we need to reload $existing_parent = ""; if (get_node($node_ref, $node_ref_data)) { $existing_parent = $node_ref_data["parent"]; } if ($option_parent != '') { // Incoming parent is populated if ($option_parent == $existing_parent) { // Parent unchanged; no need to refresh } else { // Parent being changed; refresh $response['refresh_page'] = true; } } else { // Incoming parent is blank if ($option_parent == $existing_parent) { // No parent being established; no need to refresh } else { // Parent being removed; refresh $response['refresh_page'] = true; } } // Option order_by is not being sent because that can be asynchronously changed and we might not know about it, // thus this will be checked upon saving the data. If order_by is null / empty string, then we will use the current value set_node($node_ref, $field, $option_name, $option_parent, $option_new_index); // update value of corresponding fieldx update_fieldx($field); echo json_encode($response); clear_query_cache("schema"); exit(); } // [Move Option] if (('movedown' === $node_action || 'moveup' === $node_action || 'moveto' === $node_action) && enforcePostRequest($ajax)) { $response['error'] = null; $response['sibling'] = null; $response['refresh_page'] = false; $current_node = array(); if (!get_node($node_ref, $current_node)) { $response['error'] = 'No node found!'; exit(json_encode($response)); } // Locate current node position within its siblings $siblings = get_nodes($field, $current_node['parent']); $current_node_siblings_index = array_search($node_ref, array_column($siblings, 'ref')); $pre_sibling = 0; $post_sibling = 0; if ($option_new_index > count($siblings)) { $option_new_index = count($siblings); } $allow_reordering = false; $new_nodes_order = array(); $url_parameters = array('field' => $field, 'filter_by_name' => $filter_by_name); // Get pre & post siblings of current node // Note: these can be 0 if current node is either first/ last in the list if (1 < count($siblings) && isset($current_node_siblings_index)) { if (isset($siblings[$current_node_siblings_index - 1])) { $pre_sibling = $siblings[$current_node_siblings_index - 1]['ref']; } if (isset($siblings[$current_node_siblings_index + 1])) { $post_sibling = $siblings[$current_node_siblings_index + 1]['ref']; } } // Create the new order for nodes based on direction switch ($node_action) { case 'moveup': $response['sibling'] = $pre_sibling; move_array_element($siblings, $current_node_siblings_index, $current_node_siblings_index - 1); // This is the first node in the list so we can't reorder upwards if (0 < $pre_sibling) { $allow_reordering = true; } break; case 'movedown': $response['sibling'] = $post_sibling; move_array_element($siblings, $current_node_siblings_index, $current_node_siblings_index + 1); // This is the last node in the list so we can't reorder downwards if (0 < $post_sibling) { $allow_reordering = true; } break; case 'moveto': move_array_element($siblings, $current_node_siblings_index, $option_new_index); # issue here // This node is already in this position if ($current_node_siblings_index != $option_new_index) { $allow_reordering = true; $response['refresh_page'] = true; if ($field_data['type'] != 7) { // Not a category tree $per_page = (int) getval('per_page_list', $default_perpage_list, true); $move_to_page_offset = floor($option_new_index / $per_page) * $per_page; $url_parameters['offset'] = $move_to_page_offset; } } break; } $move_to_page_url = generateURL("{$baseurl_short}pages/admin/admin_manage_field_options.php", $url_parameters); $response['url'] = $move_to_page_url; // Create the new array of nodes order foreach ($siblings as $sibling) { $new_nodes_order[] = $sibling['ref']; } if ($allow_reordering) { reorder_node($new_nodes_order); } echo json_encode($response); exit(); } // [Delete Option] if ('delete' === $node_action && enforcePostRequest($ajax)) { delete_node($node_ref); } clear_query_cache("schema"); } // [Toggle tree node] if ('true' === $ajax && 'true' === getval('draw_tree_node_table', '') && 7 == $field_data['type']) { $nodes = get_nodes($field, $node_ref, false, null, null, '', true); $nodes_counter = count($nodes); $i = 0; $node_index = 0; foreach ($nodes as $node) { $last_node = false; $node_index++; if (++$i === $nodes_counter) { $last_node = true; } draw_tree_node_table($node['ref'], $node['resource_type_field'], $node['name'], $node['parent'], $node['order_by'], $last_node, $node['use_count']); } exit(); } // [New Option] $submit_new_option = getval('submit_new_option', ''); if ('true' === $ajax && '' != trim($submit_new_option) && 'add_new' === $submit_new_option && enforcePostRequest($ajax)) { $new_option_name = trim(getval('new_option_name', '')); $new_option_parent = getval('new_option_parent', ''); $new_option_order_by = get_node_order_by($field, 7 == $field_data['type'], $new_option_parent); $new_node_index = $new_option_order_by / 10; $new_record_ref = set_node(null, $field, $new_option_name, $new_option_parent, $new_option_order_by); clear_query_cache("schema"); if (getval("reload", "") == "") { if (isset($new_record_ref) && trim($new_record_ref) != "") { if (FIELD_TYPE_CATEGORY_TREE != $field_data['type'] && (trim($new_option_parent) == "")) { ?> 0
$lang["error"],"text" => $lang["invalidextension_mustbe"] . " .txt"); } $uploaded_tmp_filename = $_FILES['import_nodes']['tmp_name']; // Get each line from file into an array $file_handle = fopen($uploaded_tmp_filename, 'rb'); if ($file_handle) { $import_nodes = array(); while (($line = fgets($file_handle)) !== false) { if (trim($line) != "" && mb_check_encoding($line, 'UTF-8')) { $import_nodes[] = trim($line); } } fclose($file_handle); } else { // error opening the file. $error = true; $onload_message = array("title" => $lang["error"],"text" => $lang["invalidextension_mustbe"] . " .txt"); } if (count($import_nodes) > 0 && !$error) { // Setup needed vars for this process $import_options = getval('import_options', ''); $existing_nodes = get_nodes($field, $import_export_parent); // Phase 1 - add new nodes, without creating duplicates foreach ($import_nodes as $import_node_name) { $existing_node_key = array_search($import_node_name, array_column($existing_nodes, 'name')); // Node doesn't exist so we can create it now. if (false === $existing_node_key) { set_node(null, $field, $import_node_name, $import_export_parent, ''); log_activity("{$lang['import']} metadata field options - field {$field}", LOG_CODE_CREATED, $import_node_name, 'node', 'name'); } } // Phase 2 - Remove any nodes that don't exist in the imported file // Note: only for "Replace options" option $reorder_required = false; foreach ($existing_nodes as $existing_node) { if ('replace_nodes' != $import_options) { break; } if (!in_array($existing_node['name'], $import_nodes)) { delete_node($existing_node['ref']); log_activity("{$lang['import']} metadata field options - field {$field}", LOG_CODE_DELETED, null, 'node', 'name', $existing_node['ref'], null, $existing_node['name']); $reorder_required = true; } } if ($reorder_required) { $new_nodes_order = array(); foreach (get_nodes($field, $import_export_parent) as $node) { $new_nodes_order[] = $node['ref']; } reorder_node($new_nodes_order); } } clear_query_cache("schema"); } // [Export nodes] if ('true' === $ajax && 'export' === $action) { include_once '../../include/csv_export_functions.php'; generateNodesExport($field_data, $import_export_parent, true); exit(); } // [Paging functionality] $url = generateURL( "{$baseurl_short}pages/admin/admin_manage_field_options.php", array( 'field' => $field, 'filter_by_name' => $filter_by_name ) ); $offset = (int) getval('offset', 0, true); $per_page = (int) getval('per_page_list', $default_perpage_list, true); $count_nodes = get_nodes_count($field, $filter_by_name); $totalpages = ceil($count_nodes / $per_page); $curpage = floor($offset / $per_page) + 1; $jumpcount = 0; // URL used for redirect on JS - AddNode() when used in combination with the pager in order to add the node at the end of // the options list $last_page_offset = (($totalpages - 1) * $per_page); if ($last_page_offset < 0) { $last_page_offset = 0; } $last_page_url = generateURL( "{$baseurl_short}pages/admin/admin_manage_field_options.php", array( 'field' => $field, 'filter_by_name' => $filter_by_name, 'go' => 'page', 'offset' => $last_page_offset ) ); if ($offset > $count_nodes || $offset < 0) { $offset = 0; } include '../../include/header.php'; if ($ajax) { echo $chosencsslink; echo $chosenjslink; } ?>

$lang["systemsetup"], 'href' => $baseurl_short . "pages/admin/admin_home.php", 'menu' => true ), array( 'title' => $lang["admin_resource_type_fields"], 'href' => $baseurl_short . "pages/admin/admin_resource_type_fields.php" ), array( 'title' => $lang["admin_resource_type_field"] . ": " . i18n_get_translated($field_data["title"]), 'href' => $baseurl_short . "pages/admin/admin_resource_type_field_edit.php?ref=" . $field ), array( 'title' => $lang['manage_metadata_field_options'] . (isset($field_data['title']) ? ': ' . i18n_get_translated($field_data['title']) : '') ) ); renderBreadcrumbs($links_trail); ?>

''); $level = 0; foreach (get_nodes($field, null, true) as $import_export_parent_node) { if (is_null($import_export_parent_node['parent'])) { $level = 0; } elseif (isset($lastnode["ref"]) && $lastnode["ref"] == $import_export_parent_node['parent']) { $level++; } elseif (isset($lastnode["ref"]) && $lastnode["parent"] != $import_export_parent_node['parent']) { $level--; } // Otherwise level stays the same $import_export_parent_nodes[$import_export_parent_node['ref']] = (str_repeat("-", $level)) . $import_export_parent_node['name']; $lastnode = $import_export_parent_node; } render_dropdown_question( $lang['property-parent'], 'import_export_parent', $import_export_parent_nodes, '', 'form="import_nodes_form"' ); } render_dropdown_question( $lang['manage_metadata_field_options_import_options'], 'import_options', array( 'append_nodes' => $lang['appendtext'], 'replace_nodes' => $lang['replacealltext'] ), '', 'form="import_nodes_form"' ); ?>