File: tree_items.php

package info (click to toggle)
cacti 0.6.7-2.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,000 kB
  • ctags: 1,120
  • sloc: php: 5,059; sql: 922; sh: 302; perl: 81; makefile: 56
file content (165 lines) | stat: -rw-r--r-- 8,462 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?/* 
+-------------------------------------------------------------------------+
| Copyright (C) 2002 Ian Berry                                            |
|                                                                         |
| This program is free software; you can redistribute it and/or           |
| modify it under the terms of the GNU General Public License             |
| as published by the Free Software Foundation; either version 2          |
| of the License, or (at your option) any later version.                  |
|                                                                         |
| This program is distributed in the hope that it will be useful,         |
| but WITHOUT ANY WARRANTY; without even the implied warranty of          |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
| GNU General Public License for more details.                            |
+-------------------------------------------------------------------------+
| cacti: the rrdtool frontend [php-auth, php-tree, php-form]              |
+-------------------------------------------------------------------------+
| This code is currently maintained and debugged by Ian Berry, any        |
| questions or comments regarding this code should be directed to:        |
| - iberry@raxnet.net                                                     |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/                                       |
+-------------------------------------------------------------------------+
*/?>
<? 	$section = "Add/Edit Graphs"; include ('auth/include/auth.php');
	header("Cache-control: no-cache");
	include ('include/database.php');
	include ('include/config.php');
	include_once ('include/form.php');

switch ($action) {
	case 'save':
		include_once ('include/functions.php');
		
		if ($graphid != "0") { $type = "Graph"; }
		
		$max_sequence = GetSequence($id, "sequence", "graph_hierarchy_items", "parent", "$parent and treeid=$gid");
		
		$sql_id = mysql_query("replace into graph_hierarchy_items (id,treeid,graphid,rraid,title,type,parent,sequence) 
			values ($id,$gid,$graphid,$rraid,\"$title\",\"$type\",$parent,$max_sequence)",$cnn_id);
		
		header ("Location: tree_items.php?id=$gid");
		break;
	case 'movedown':
		include_once ('include/functions.php');
		
		$next_item = GetNextItem($cnn_id,"graph_hierarchy_items","sequence",$id,"parent","$gid and treeid=$tid");
		
		$sql_id_id = mysql_query("select id from graph_hierarchy_items where sequence=$next_item and parent=$gid",$cnn_id);
		$sql_id_seq = mysql_query("select sequence from graph_hierarchy_items where id=$id",$cnn_id);
		$sql_id = mysql_query("update graph_hierarchy_items set sequence=$next_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update graph_hierarchy_items set sequence=" . mysql_result($sql_id_seq, 0, "sequence") . " where id=" . mysql_result($sql_id_id, 0, "id"),$cnn_id);
		
		header ("Location: tree_items.php?id=$tid");
		break;
	case 'moveup':
		include_once ('include/functions.php');
		
		$last_item = GetLastItem($cnn_id,"graph_hierarchy_items","sequence",$id,"parent","$gid and treeid=$tid");
		
		$sql_id_id = mysql_query("select id from graph_hierarchy_items where sequence=$last_item and parent=$gid",$cnn_id);
		$sql_id_seq = mysql_query("select sequence from graph_hierarchy_items where id=$id",$cnn_id);
		$sql_id = mysql_query("update graph_hierarchy_items set sequence=$last_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update graph_hierarchy_items set sequence=" . mysql_result($sql_id_seq, 0, "sequence") . " where id=" . mysql_result($sql_id_id, 0, "id"),$cnn_id);
		
		header ("Location: tree_items.php?id=$tid");
		break;
	case 'remove':
		include_once ('include/tree_functions.php');
		
		$array_tree["options"]["sql_string"] = 'select h.id,h.type,h.title,h.parent,g.title as 
			gtitle,r.name as rname from graph_hierarchy_items h left join rrd_graph g on h.graphid=g.id 
			left join rrd_rra r on h.rraid=r.id where h.parent=$branch and h.treeid=' . $gid . ' 
			 order by h.sequence';
		$array_tree["options"]["sql_connection_id"] = $cnn_id;
		$array_tree["options"]["sql_delete_table_name"] = "graph_hierarchy_items";
		$array_tree["options"]["tree_id"] = $gid;
		$array_tree["remove"]["remove_branch"] = true;
		$array_tree["remove"]["branch_to_remove"] = $id;
		
		GrowTree($array_tree);
		
		header ("Location: tree_items.php?id=$gid");
		break;
	case 'edit':
		include_once ("include/top_header.php");
		
		/* get current tree name for the header text */
		$sql_id_title = mysql_query("select name from graph_hierarchy where id=$gid", $cnn_id);
		$tree_title = mysql_result($sql_id_title, 0, "name");
		
		if ($id != "") {
			$sql_id = mysql_query("select * from graph_hierarchy_items where id=$id", $cnn_id);
		}
		
		DrawFormHeader("Graph Hierarchy Item Configuration: $tree_title",true,"");
		
		DrawFormItem("Heading","");
		DrawFormItemRadioButton("type", $sql_id, "Heading", "This Item is a Heading.","Heading");
		DrawFormItemTextBox("title",$sql_id,"","");
		
		DrawFormItem("Graph","");
		DrawFormItemRadioButton("type", $sql_id, "Graph", "This Item is a Graph.","Heading");
		DrawFormItemDropdownFromSQL("graphid",$cnn_id,"select * from rrd_graph order by title",
			"title","id",$sql_id,"None","");
		DrawFormItemDropdownFromSQL("rraid",$cnn_id,"select * from rrd_rra order by name",
			"name","id",$sql_id,"","");
		
		DrawFormSaveButton();
		DrawFormItemHiddenIDField("id",$id);
		DrawFormItemHiddenTextBox("parent",$sql_id,$parent);
		DrawFormItemHiddenIDField("gid",$gid);
		DrawFormFooter();
		
		include_once ("include/bottom_footer.php");
		break;
	default:
		include_once ('include/tree_functions.php');
		include_once ('include/top_header.php');
		
		/* get current tree name for the header text */
		$sql_id_title = mysql_query("select name from graph_hierarchy where id=$id", $cnn_id);
		$tree_title = mysql_result($sql_id_title, 0, "name");
		
		DrawMatrixTableBegin("97%");
		DrawMatrixRowBegin();
			DrawMatrixHeaderTop("Graph Hierarchy: $tree_title",$color_dark_bar,"","2");
			DrawMatrixHeaderAdd($color_dark_bar,"","tree_items.php?action=edit&parent=0&gid=$id");
		DrawMatrixRowEnd();
		
		DrawMatrixRowBegin();
			DrawMatrixHeaderItem("Tree Item",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Sequence",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("",$color_panel,$color_panel_text);
		DrawMatrixRowEnd();
		
		$array_tree["options"]["sql_type_column"] = "type";
		$array_tree["options"]["sql_string"] = 'select h.id,h.type,h.title,h.parent,g.title as 
			gtitle,r.name as rname from graph_hierarchy_items h left join rrd_graph g on h.graphid=g.id 
			left join rrd_rra r on h.rraid=r.id where h.parent=$branch and h.treeid=' . $id . ' 
			 order by h.sequence';
		$array_tree["options"]["sql_connection_id"] = $cnn_id;
		$array_tree["options"]["indent"] = "&nbsp;";
		$array_tree["options"]["alternating_row_colors"] = true;
		$array_tree["options"]["tree_id"] = $id;
		$array_tree["options"]["remove_action"] = 'tree_items.php?action=remove&gid=' . $id . '&id=" . mysql_result($sql_id, $i, "id") . "';
		$array_tree["options"]["moveup_action"] = 'tree_items.php?action=moveup&tid=' . $id . '&id=" . mysql_result($sql_id, $i, "id") . "&gid=" . mysql_result($sql_id, $i, "parent") . "';
		$array_tree["options"]["movedown_action"] = 'tree_items.php?action=movedown&tid=' . $id . '&id=" . mysql_result($sql_id, $i, "id") . "&gid=" . mysql_result($sql_id, $i, "parent") . "';
		
		$array_tree["item_action"]["Heading"] = '<strong><a href=\"tree_items.php?action=edit&gid=' . $id . '&id=" . mysql_result($sql_id, $i, "id")
			. "\">" . mysql_result($sql_id, $i, "title") . "</a> [<a href=\"
			tree_items.php?action=edit&gid=' . $id . '&parent=" . mysql_result($sql_id, $i, "id") . 
			"\">add</a>]</strong>';
		
		$array_tree["item_action"]["Graph"] = '<a href=\"tree_items.php?action=edit&gid=' . $id . '&id=" . mysql_result($sql_id, $i, "id")
			. "\">GRAPH: " . mysql_result($sql_id, $i, "gtitle") . " - " . 
			mysql_result($sql_id, $i, "rname") . "</a>';
		
		GrowTree($array_tree);
		
		print "</td></tr>";
		DrawMatrixTableEnd();
		
		include_once ("include/bottom_footer.php");
		break;
} ?>