Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

draw_tree_node_table()

Description

Renders HTML for a tree node

Parameters

ColumnTypeDefaultDescription
$ref integer ID of the node
$resource_type_field integer ID of the metadata field
$name string Node name to be used (international)
$parent integer ID of the parent of this node
$order_by integer Value of the order in the list (e.g. 10)
$last_node boolean false Set to true to allow to insert new records after last node in each level
$use_count integer 0 Counter of how many resources use a particular node

Return

boolean

Location

include/node_functions.php lines 800 to 964

Definition

 
function draw_tree_node_table($ref$resource_type_field$name$parent$order_by$last_node false$use_count 0)
    {
    global 
$baseurl_short$lang$FIXED_LIST_FIELD_TYPES;

    static 
$resource_type_field_last 0;
    static 
$all_nodes = array();    

    if(
is_null($ref) || (trim($ref)==""))
        {
        return 
false;
        }

    
$fieldinfo  get_resource_type_field($resource_type_field);
    if(!
in_array($fieldinfo["type"],$FIXED_LIST_FIELD_TYPES))
        {
        return 
false;
        }

    
$toggle_node_mode '';
    
$spacer_filename  'sp.gif';
    
$onClick          '';
    
$node_index $order_by 10;

    if(
is_parent_node($ref))
        {
        
$toggle_node_mode 'unex';
        
$spacer_filename  'node_unex.gif';
        
$onClick          sprintf('ToggleTreeNode(%s, %s);'$ref$resource_type_field);
        }

    
// Determine Node depth
    
$node_depth_level get_tree_node_level($ref);

    
// Fetch all nodes on change of resource type field
    
if($resource_type_field !== $resource_type_field_last)
        {
        global 
$node_tree_data;
        if(!empty(
$node_tree_data))
            {
            
$all_nodes $node_tree_data;
            }
        else
            {
            
$all_nodes $node_tree_data get_nodes($resource_type_fieldnulltruenullnull''true);
            }
        
$resource_type_field_last $resource_type_field;    
        }

    
// We remove the current node from the list of parents for it( a node should not add to itself)
    
$nodes $all_nodes;
    
$nodes_index_to_remove array_search($refarray_column($nodes'ref'));
    
$node_info $nodes[$nodes_index_to_remove];
    unset(
$nodes[$nodes_index_to_remove]);
    
$nodes array_values($nodes);
    
$node_disabled_class $node_info['active'] === 'FieldDisabled' '';
    
$activation_action_label node_is_active($node_info)
        ? 
$lang['userpreference_disable_option']
        : 
$lang['userpreference_enable_option'];
    
?>
    <table id="node_ echo $ref?>" cellspacing="0" cellpadding="5" data-toggle-node-mode = " echo $toggle_node_mode?>">
        <tbody>
            <tr>
            
            
// Indent node to the correct depth level
            
$i $node_depth_level;
            while(
$i)
                {
                
$i--;
                
?>
                <td class="backline" width="10">
                    <img alt="" width="11" height="11" hspace="4" src=" echo $baseurl_short?>gfx/interface/sp.gif">
                </td>
                
                
}
                
?>
                <td class="backline" width="10">
                    <img alt="" id="node_ echo (int) $ref?>_toggle_button" width="11" height="11" hspace="4" src=" echo $baseurl_short?>gfx/interface/ echo $spacer_filename?>" onclick=" echo $onClick?>">
                </td>
                <td>
                    <input
                        type="text"
                        class=" echo escape($node_disabled_class); ?>"
                        name="option_name"
                        form="option_ echo (int) $ref?>"
                        value=" echo escape($name); ?>"
                    >
                </td>
                <td>
                    <select id="node_option_ echo $ref?>_parent_select" parent_node=" echo $parent?>" class="node_parent_chosen_selector" name="option_parent" form="option_ echo $ref?>">
                        <option value="">Select parent</option>
                    </select>
                </td>
                <td> echo $use_count ?></td>
                <td>
                    <div class="ListTools">
                        <form id="option_ echo $ref?>" method="post" action="/pages/admin/admin_manage_field_options.php?field= echo $resource_type_field?>">
                            <input type="hidden" name="option_order_by" value=" echo $order_by?>">
                            <input 
                                    type="number"
                                    name="node_order_by" 
                                    value=" echo $node_index?>
                                    id="option_ echo $ref?>_order_by" 
                                    readonly='true'
                                    min='1'
                                >
                            </td>
                            <td> <!-- Buttons for changing order -->
                                <button 
                                    type="button"
                                    id="option_ echo $ref?>_move_to"
                                    onclick="
                                        EnableMoveTo( echo $ref?>);
                                        
                                        return false;
                                    ">
                                     echo escape($lang['action-move-to']); ?>
                                </button>
                                <button 
                                    type="submit"
                                    id="option_ echo $ref?>_order_by_apply"
                                    onclick="
                                        ApplyMoveTo( echo $ref?>);
                                        return false;
                                    "
                                    style="display: none;"
                                >
                                 echo escape($lang['action-title_apply']); ?>
                                </button>
                                <button type="submit" onclick="ReorderNode( echo $ref?>, 'moveup'); return false;"> echo escape($lang['action-move-up']); ?></button>
                                <button type="submit" onclick="ReorderNode( echo $ref?>, 'movedown'); return false;"> echo escape($lang['action-move-down']); ?></button>
                            </td>
                        <td> <!-- Action buttons -->
                            <button type="submit" onclick="SaveNode( echo $ref?>); return false;"> echo escape($lang['save']); ?></button>
                            <button id="node_ echo escape($ref); ?>_toggle_active_btn" type="submit" onclick="ToggleNodeActivation( echo escape($ref); ?>); return false;"> echo escape($activation_action_label); ?></button>
                            
                            
if(!is_parent_node($ref))
                                {
?>
                            <button type="submit" onclick="DeleteNode( echo $ref?>); return false;"> echo escape($lang['action-delete']); ?></button>
                                 
                                
}
                            
?>
                        </td>
                            
                         generateFormToken("option_{$ref}"); ?>
                        </form>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
    <div id="node_ echo $ref?>_children"></div>

    
    
// Add a way of inserting new records after the last node of each level
    
if($last_node)
        {
        if(
trim((string) $parent)=="")
            {
            
$parent 0;
            }
        
render_new_node_record('/pages/admin/admin_manage_field_options.php?field=' $resource_type_fieldtrue$parent$node_depth_level$all_nodes);
        }

    return 
true;
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.