File: cdef_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 (154 lines) | stat: -rw-r--r-- 7,499 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
<?/* 
+-------------------------------------------------------------------------+
| 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 Data Sources"; 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');
		
		$max_sequence = GetSequence($id, "sequence", "rrd_ds_cdef_item", "cdefid", $gid);
		
		$sql_id = mysql_query("replace into rrd_ds_cdef_item (id,dsid,cdefid,custom,currentds,
			cdeffunctionid,type,sequence) values ($id,$dsid,$gid,\"$custom\",\"$currentds\",
			$cdeffunctionid,\"$type\",$max_sequence)",$cnn_id);
		
		header ("Location: cdef_items.php?id=$gid");
		break;
	case 'remove':
		mysql_query("delete from rrd_ds_cdef_item where id=$id",$cnn_id);
		
		header ("Location: cdef_items.php?id=$gid");
		break;
	case 'movedown':
		include_once ('include/functions.php');
		
		$next_item = GetNextItem($cnn_id,"rrd_ds_cdef_item","sequence",$id,"cdefid",$gid);
		
		$sql_id_id = mysql_query("select id from rrd_ds_cdef_item where sequence=$next_item and cdefid=$gid",$cnn_id);
		$sql_id_seq = mysql_query("select sequence from rrd_ds_cdef_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update rrd_ds_cdef_item set sequence=$next_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update rrd_ds_cdef_item set sequence=" . mysql_result($sql_id_seq, 0, "sequence") . " where id=" . mysql_result($sql_id_id, 0, "id"),$cnn_id);
		
		header ("Location: cdef_items.php?id=$gid");
		break;
	case 'moveup':
		include_once ('include/functions.php');
		
		$last_item = GetLastItem($cnn_id,"rrd_ds_cdef_item","sequence",$id,"cdefid",$gid);
		
		$sql_id_id = mysql_query("select id from rrd_ds_cdef_item where sequence=$last_item and cdefid=$gid",$cnn_id);
		$sql_id_seq = mysql_query("select sequence from rrd_ds_cdef_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update rrd_ds_cdef_item set sequence=$last_item where id=$id",$cnn_id);
		$sql_id = mysql_query("update rrd_ds_cdef_item set sequence=" . mysql_result($sql_id_seq, 0, "sequence") . " where id=" . mysql_result($sql_id_id, 0, "id"),$cnn_id);
		
		header ("Location: cdef_items.php?id=$gid");
		break;
	case 'edit':
		include_once ('include/top_header.php');
		
		if ($id != "") {
			$sql_id = mysql_query("select * from rrd_ds_cdef_item where id=$id", $cnn_id);
		}
		
		DrawFormHeader("rrdtool CDEF Configuration","",false);
		
		DrawFormItem("Data Source","Add a data source to this CDEF.");
		DrawFormItemRadioButton("type", $sql_id, "Data Source", "Add a Data Source.","Data Source");
		DrawFormItemDropdownFromSQL("dsid",$cnn_id,"select * from rrd_ds where isparent=0 order by name",
			"name","id",$sql_id,"None","");
		DrawFormItemCheckBox("currentds",$sql_id,"Use the current data source being used on the
			graph instead of a preset one.","");
		
		DrawFormItem("CDEF Function","Add a CDEF function to this CDEF.");
		DrawFormItemRadioButton("type", $sql_id, "CDEF Function", "Add a CDEF Function.","Data Source");
		DrawFormItemDropdownFromSQL("cdeffunctionid",$cnn_id,"select * from def_cdef order by name",
			"name","id",$sql_id,"","");
		
		DrawFormItem("Custom Entry","Add a custom entry to this CDEF.");
		DrawFormItemRadioButton("type", $sql_id, "Custom Entry", "Add a Custom Entry.","Data Source");
		DrawFormItemTextBox("custom",$sql_id,"","");
		
		DrawFormSaveButton();
		DrawFormItemHiddenIDField("id",$id);
		DrawFormItemHiddenIDField("gid",$gid);
		DrawFormFooter();
		
		include_once ("include/bottom_footer.php");
		
		break;
	default:
		include_once ('include/top_header.php');
		
		DrawMatrixTableBegin("97%");
		DrawMatrixRowBegin();
			DrawMatrixHeaderTop("Current Data Sources",$color_dark_bar,"","4");
			DrawMatrixHeaderAdd($color_dark_bar,"","cdef_items.php?action=edit&gid=$id");
		DrawMatrixRowEnd();
		
		DrawMatrixRowBegin();
			DrawMatrixHeaderItem("Item",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Type",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Item Value",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Sequence",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("",$color_panel,$color_panel_text);
		DrawMatrixRowEnd();
		
		$sql_id = mysql_query("select ds.name as dsname, cf.name as cfname, c.id, c.type, c.custom
			from rrd_ds_cdef_item c left join def_cdef cf on cf.id=c.cdeffunctionid left 
			join rrd_ds ds on ds.id=c.dsid where c.cdefid=$id order by c.sequence", $cnn_id);
		$rows = mysql_num_rows($sql_id); $i = 0;
		
		while ($i < $rows) { 
			DrawMatrixRowAlternateColorBegin($color_alternate,$color_light,$i);
				DrawMatrixLoopItem("Item #" . ($i+1),"","",html_boolean($config["vis_main_column_bold"]["value"]),"cdef_items.php?action=edit&gid=$id&id=" . mysql_result($sql_id, $i, "id"));
				DrawMatrixLoopItem($sql_id,"type",$i,false,"");
				
				switch (mysql_result($sql_id, $i, "type")) {
					case 'Data Source':
						$matrix_title = mysql_result($sql_id, $i, "dsname");
						break;
					case 'CDEF Function':
						$matrix_title = mysql_result($sql_id, $i, "cfname");
						break;
					case 'Custom Entry':
						$matrix_title = mysql_result($sql_id, $i, "custom");
						break;
				}
				
				DrawMatrixLoopItem($matrix_title,"","",false,"");
				DrawMatrixLoopItem("[<a href=\"cdef_items.php?action=movedown&id=" . mysql_result($sql_id, $i, "id") . "&gid=$id\">Down</a>], [<a href=\"cdef_items.php?action=moveup&id=" . mysql_result($sql_id, $i, "id") . "&gid=$id\">Up</a>]","","",false,"");
				DrawMatrixLoopItemAction("Remove",$color_panel,"",false,"cdef_items.php?action=remove&gid=$id&id=" . mysql_result($sql_id, $i, "id"));
			DrawMatrixRowEnd();
			$i++;
		}
		
		DrawMatrixTableEnd();
		include_once ("include/bottom_footer.php");
		
		break;
} ?>