Collections functions
Encryption functions
General functions
Theme permission functions
Resource 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 676 to 827

Definition

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

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

    if(
is_null($ref) || (trim($ref)==""))
        {
        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)
        {
        
$all_nodes 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'));
    unset(
$nodes[$nodes_index_to_remove]);
    
$nodes array_values($nodes);
    
?>
    <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 width="11" height="11" hspace="4" src=" echo $baseurl_short?>gfx/interface/sp.gif">
                </td>
                
                
}
                
?>
                <td class="backline" width="10">
                    <img id="node_ echo $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" name="option_name" form="option_ echo $ref?>" value=" echo $name?>">
                </td>
                <td>
                    <select id="node_option_ echo $ref?>_parent_select" class="node_parent_chosen_selector" name="option_parent" form="option_ echo $ref?>">
                        <option value="">Select parent</option>
                    
                    
foreach($nodes as $node)
                        {
                        
$selected '';
                        if(!(
trim($parent)=="") && $node['ref'] == $parent)
                            {
                            
$selected ' selected';
                            }
                        
?>
                        <option value=" echo $node['ref']; ?>" echo $selected?>> echo htmlspecialchars($node['name']); ?></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 $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 $lang['action-title_apply']; ?>
                                </button>
                                <button type="submit" onclick="ReorderNode( echo $ref?>, 'moveup'); return false;"> echo $lang['action-move-up']; ?></button>
                                <button type="submit" onclick="ReorderNode( echo $ref?>, 'movedown'); return false;"> echo $lang['action-move-down']; ?></button>
                            </td>
                        <td> <!-- Action buttons -->
                            <button type="submit" onclick="SaveNode( echo $ref?>); return false;"> echo $lang['save']; ?></button>
                            
                            
if(!is_parent_node($ref))
                                {
?>
                            <button type="submit" onclick="DeleteNode( echo $ref?>); return false;"> echo $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($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 11th July 2020 03:35 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.