Example #1
0
function tree_edit()
{
    $menu_items = array("remove" => "Remove");
    $_graph_tree_id = get_get_var_number("id");
    if (empty($_graph_tree_id)) {
        $header_label = "[new]";
    } else {
        $graph_tree = api_graph_tree_get($_graph_tree_id);
        $header_label = "[edit: " . $graph_tree["name"] . "]";
    }
    form_start("graph_trees.php", "form_graph_tree");
    html_start_box("<strong>" . _("Graph Trees") . "</strong> {$header_label}", "");
    _graph_tree_field__name("name", isset($graph_tree["name"]) ? $graph_tree["name"] : "", empty($_graph_tree_id) ? 0 : $_graph_tree_id);
    _graph_tree_field__sort_type("sort_type", isset($graph_tree["sort_type"]) ? $graph_tree["sort_type"] : "", empty($_graph_tree_id) ? 0 : $_graph_tree_id);
    html_end_box();
    form_hidden_box("id", $_graph_tree_id);
    form_hidden_box("action_post", "graph_tree_edit");
    form_save_button("graph_trees.php");
    if (!empty($_graph_tree_id)) {
        echo "<br />\n";
        form_start("graph_trees_items.php", "form_graph_tree_item");
        $box_id = "1";
        html_start_box("<strong>" . _("Tree Items") . "</strong>", "graph_trees_items.php?action=edit&tree_id=" . $_graph_tree_id . "&parent_id=0");
        html_header_checkbox(array(_("Item"), _("Type"), ""), $box_id, "1");
        /* get a sorted list of all graph items inside of this tree */
        $tree_items = api_graph_tree_item_list($_graph_tree_id);
        /* get a list of available types (header, host, graph, etc) */
        $tree_item_types = api_graph_tree_item_type_list();
        if (is_array($tree_items) > 0 && sizeof($tree_items) > 0) {
            foreach ($tree_items as $tree_item) {
                $current_depth = api_graph_tree_item_depth_get($tree_item["order_key"]);
                /* keep track of the current item's sort type so we know whether to display sort
                 * arrays for items children or not */
                $sort_cache[$current_depth] = $tree_item["sort_children_type"];
                $transparent_indent = "";
                if ($tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) {
                    $item_text = $tree_item["graph_title"];
                } else {
                    if ($tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) {
                        $item_text = "<strong>" . $tree_item["item_value"] . "</strong></a> (<a href='graph_trees_items.php?action=edit&tree_id=" . $_graph_tree_id . "&parent_id=" . $tree_item["id"] . "'>Add</a>)";
                    } else {
                        if ($tree_item["item_type"] == TREE_ITEM_TYPE_HOST) {
                            $item_text = "<strong>Device:</strong> " . $tree_item["host_hostname"];
                        }
                    }
                }
                ?>
				<tr class="item" id="box-<?php 
                echo $box_id;
                ?>
-row-<?php 
                echo $tree_item["id"];
                ?>
" onClick="display_row_select('<?php 
                echo $box_id;
                ?>
',document.forms[1],'box-<?php 
                echo $box_id;
                ?>
-row-<?php 
                echo $tree_item["id"];
                ?>
', 'box-<?php 
                echo $box_id;
                ?>
-chk-<?php 
                echo $tree_item["id"];
                ?>
')" onMouseOver="display_row_hover('box-<?php 
                echo $box_id;
                ?>
-row-<?php 
                echo $tree_item["id"];
                ?>
')" onMouseOut="display_row_clear('box-<?php 
                echo $box_id;
                ?>
-row-<?php 
                echo $tree_item["id"];
                ?>
')">
					<td class="title">
						<img width="<?php 
                echo ($current_depth - 1) * 20;
                ?>
" height="1" align="middle" alt="">&nbsp;<a onClick="display_row_block('box-<?php 
                echo $box_id;
                ?>
-row-<?php 
                echo $tree_item["id"];
                ?>
')" href="graph_trees_items.php?action=edit&tree_id=<?php 
                echo $_graph_tree_id;
                ?>
&id=<?php 
                echo $tree_item["id"];
                ?>
"><span id="box-<?php 
                echo $box_id;
                ?>
-text-<?php 
                echo $tree_item["id"];
                ?>
"><?php 
                echo html_highlight_words(get_get_var("search_filter"), $item_text);
                ?>
</span></a>
					</td>
					<td>
						<?php 
                echo $tree_item_types[$tree_item["item_type"]];
                ?>
					</td>
					<?php 
                if (isset($sort_cache[$current_depth - 1]) && $sort_cache[$current_depth - 1] != TREE_ORDERING_NONE || $graph_tree["sort_type"] != TREE_ORDERING_NONE) {
                    ?>
					<td width="80">
						&nbsp;
					</td>
					<?php 
                } else {
                    ?>
					<td width="80" align="center">
						<a href="graph_trees_items.php?action=movedown&id=<?php 
                    echo $tree_item["id"];
                    ?>
&graph_tree_id=<?php 
                    echo $_graph_tree_id;
                    ?>
"><img src="<?php 
                    echo html_get_theme_images_path("move_down.gif");
                    ?>
" border="0" alt="Move Down"></a>
						<a href="graph_trees_items.php?action=moveup&id=<?php 
                    echo $tree_item["id"];
                    ?>
&graph_tree_id=<?php 
                    echo $_graph_tree_id;
                    ?>
"><img src="<?php 
                    echo html_get_theme_images_path("move_up.gif");
                    ?>
" border="0" alt="Move Up"></a>
					</td>
					<?php 
                }
                ?>

					<td class="checkbox" align="center">
						<input type='checkbox' name='box-<?php 
                echo $box_id;
                ?>
-chk-<?php 
                echo $tree_item["id"];
                ?>
' id='box-<?php 
                echo $box_id;
                ?>
-chk-<?php 
                echo $tree_item["id"];
                ?>
' title="<?php 
                echo strip_tags($item_text);
                ?>
">
					</td>
				</tr>
				<?php 
            }
        } else {
            ?>
			<tr class="empty">
				<td colspan="6">
					No graph tree items found.
				</td>
			</tr>
			<?php 
        }
        html_box_toolbar_draw($box_id, "1", "3", HTML_BOX_SEARCH_NONE);
        html_end_box(false);
        html_box_actions_menu_draw($box_id, "1", $menu_items);
        form_hidden_box("graph_tree_id", $_graph_tree_id);
        form_hidden_box("action", "save");
        form_hidden_box("action_post", "graph_tree_item_list");
        form_end();
        ?>
		<script language="JavaScript">
		<!--
		function action_area_handle_type(box_id, type, parent_div, parent_form) {
			if (type == 'remove') {
				parent_div.appendChild(document.createTextNode('Are you sure you want to remove these graph tree items?'));
				parent_div.appendChild(action_area_generate_selected_rows(box_id));

				action_area_update_header_caption(box_id, 'Remove Graph Tree Item');
				action_area_update_submit_caption(box_id, 'Remove');
				action_area_update_selected_rows(box_id, parent_form);
			}
		}
		-->
		</script>
		<?php 
    }
}
Example #2
0
function _graph_tree_item_field__item_type($field_name, $field_value = "", $field_id = 0) {
	require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php");
	require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

	?>
	<tr class="<?php echo field_get_row_style();?>">
		<td width="50%" class="field-row">
			<span class="textEditTitle"><?php echo _("Tree Item Type");?></span><br>
			<?php echo _("Choose whether this tree item is to represent a branch header, a device, or an individual graph.");?>
		</td>
		<td class="field-row" colspan="2">
			<?php form_dropdown($field_name, api_graph_tree_item_type_list(), "", "", $field_value, "", 1, "", "", "update_graph_item_type_function(this.value, $field_id)");?>
		</td>
	</tr>
	<script language="JavaScript">
	<!--
	function update_graph_item_type_function(graph_tree_item_type, row_id) {
		if (graph_tree_item_type == <?php echo TREE_ITEM_TYPE_HEADER;?>) {
			document.getElementById('row_field_title_' + row_id).style.display = 'table-row';
			document.getElementById('row_field_sort_children_type_' + row_id).style.display = 'table-row';
			document.getElementById('row_field_propagate_changes_' + row_id).style.display = 'table-row';
			document.getElementById('row_field_graph_' + row_id).style.display = 'none';
			document.getElementById('row_field_device_' + row_id).style.display = 'none';
			document.getElementById('row_field_device_grouping_type_' + row_id).style.display = 'none';
		}else if (graph_tree_item_type == <?php echo TREE_ITEM_TYPE_GRAPH;?>) {
			document.getElementById('row_field_title_' + row_id).style.display = 'none';
			document.getElementById('row_field_sort_children_type_' + row_id).style.display = 'none';
			document.getElementById('row_field_propagate_changes_' + row_id).style.display = 'none';
			document.getElementById('row_field_graph_' + row_id).style.display = 'table-row';
			document.getElementById('row_field_device_' + row_id).style.display = 'none';
			document.getElementById('row_field_device_grouping_type_' + row_id).style.display = 'none';
		}else if (graph_tree_item_type == <?php echo TREE_ITEM_TYPE_HOST;?>) {
			document.getElementById('row_field_title_' + row_id).style.display = 'none';
			document.getElementById('row_field_sort_children_type_' + row_id).style.display = 'none';
			document.getElementById('row_field_propagate_changes_' + row_id).style.display = 'none';
			document.getElementById('row_field_graph_' + row_id).style.display = 'none';
			document.getElementById('row_field_device_' + row_id).style.display = 'table-row';
			document.getElementById('row_field_device_grouping_type_' + row_id).style.display = 'table-row';
		}
	}
	-->
	</script>
	<?php
}