Added proper css-based html code, took into account failure of
[plewww.git] / plekit / php / updateColumn.php
1
2 <?php
3
4 // Require login
5 require_once 'plc_login.php';
6
7 // Get session and API handles
8 require_once 'plc_session.php';
9 global $plc, $api;
10
11 //print header
12 require_once 'plc_drupal.php';
13
14 // Common functions
15 require_once 'plc_functions.php';
16
17 require_once 'columns.php';
18
19
20 $slice_id=$_GET["slice_id"];
21 $tagN=$_GET["tagName"];
22 $data_source=$_GET["data_source"];
23 $data_type=$_GET["data_type"];
24
25 //print "getting column data for ".$slice_id." with ".$tagN." - ".$data_source." - ".$data_type;
26 $nodetags = array('node_id');
27 $extratags = explode("|", $tagN);
28
29
30 if ($slice_id == "nodes") {
31
32 if ($data_source == "comon") {
33
34         $comontags = $extratags;
35         $extratags = array ('hostname');
36         $nodes=$api->GetNodes(NULL, array_merge($nodetags, $extratags));
37         $ColumnsConfigure = new PlekitColumns(NULL, NULL, NULL);
38         $comon_data = $ColumnsConfigure->comon_query_nodes(",".$tagN);
39
40         //print ("comon tags = ".$comontags);
41         
42         if ($comon_data != "")
43         {
44         echo "---attached---";
45         if ($nodes) foreach ($nodes as $node) {
46                 echo "|".$node['node_id'];
47                 foreach ($comontags as $t)
48                         echo ":".$ColumnsConfigure->convert_data($comon_data[$node['hostname']][$t], $data_type);
49         }
50         }
51 }
52 else if ($data_source == "tophat") {
53
54         $ColumnsConfigure = new PlekitColumns(NULL, NULL, NULL);
55
56         $extratags = array ('hostname');
57         $nodes=$api->GetNodes(NULL, array_merge($nodetags, $extratags));
58
59         $dd = array();
60         if ($nodes) foreach ($nodes as $n)
61                 $dd[] = $n['hostname'];
62
63         if ($tagN == "hopcount") 
64         {
65                 $ref_node=$_GET["ref_node"];
66                 //print("getting hop count with ref node = ".$ref_node);
67                 $tophat_data = $ColumnsConfigure->getPairwise($ref_node, $dd, "traceroute", "hop_count");
68         }
69         else
70                 $tophat_data = $ColumnsConfigure->getTopHatData($tagN, $dd);
71
72         //print_r($tophat_data);
73
74         if ($tophat_data != "") {
75         echo "---attached---";
76         if ($nodes) foreach ($nodes as $node) {
77                 echo "|".$node['node_id'];
78                 echo ":".$ColumnsConfigure->convert_data($tophat_data[$node['hostname']][$tagN], $data_type);
79         }
80         }
81 }
82 else //MyPLC API
83 {
84
85         $nodes=$api->GetNodes(NULL, array_merge($nodetags, $extratags));
86
87         if ($nodes) {
88         echo "---attached---";
89
90         foreach ($nodes as $node) {
91                 echo "|".$node['node_id'];
92                 foreach ($extratags as $t)
93                         echo ":".$node[$t];
94         }
95         }
96 }
97
98
99
100 }
101 // in slices view
102 else
103 {
104
105 $slices= $api->GetSlices( array(intval($slice_id)));
106 if (empty($slices)) {
107   drupal_set_message ("Slice " . $slice_id . " not found");
108 }
109
110 $slice=$slices[0];
111
112 if ($data_source == "comon") {
113
114         $comontags = $extratags;
115         $extratags = array ('hostname');
116
117         $nodes=$api->GetNodes(array('node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
118         $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
119
120         $ColumnsConfigure = new PlekitColumns(NULL, NULL, NULL);
121         $comon_data = $ColumnsConfigure->comon_query_nodes(",".$tagN);
122
123         //print ("comon tags = ".$comontags);
124
125         if ($comon_data != "") {
126         echo "---attached---";
127         if ($nodes) foreach ($nodes as $node) {
128                 echo "|".$node['node_id'];
129                 foreach ($comontags as $t)
130                         echo ":".$ColumnsConfigure->convert_data($comon_data[$node['hostname']][$t], $data_type);
131         }
132         echo "|---potential---";
133         if ($potential_nodes) foreach ($potential_nodes as $potential_node) {
134                 echo "|".$potential_node['node_id'];
135                 foreach ($comontags as $t)
136                         echo ":".$ColumnsConfigure->convert_data($comon_data[$potential_node['hostname']][$t], $data_type);
137         }
138         }
139 }
140 else if ($data_source == "tophat") {
141
142         $ColumnsConfigure = new PlekitColumns(NULL, NULL, NULL);
143
144         $extratags = array ('hostname');
145         $nodes=$api->GetNodes(array('node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
146         $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
147         
148         $dd = array();
149         if ($nodes) foreach ($nodes as $n)
150                 $dd[] = $n['hostname'];
151         if ($potential_nodes) foreach ($potential_nodes as $n)
152                 $dd[] = $n['hostname'];
153         
154         if ($tagN == "hopcount") 
155         {
156                 $ref_node=$_GET["ref_node"];
157                 print("getting hop count with ref node = ".$ref_node);
158                 $tophat_data = $ColumnsConfigure->getPairwise($ref_node, $dd, "hop_count");
159         }
160         else
161                 $tophat_data = $ColumnsConfigure->getTopHatData($tagN, $dd);
162
163         if ($tophat_data != "") {
164         echo "---attached---";
165         if ($nodes) foreach ($nodes as $node) {
166                 echo "|".$node['node_id'];
167                 echo ":".$ColumnsConfigure->convert_data($tophat_data[$node['hostname']][$tagN], $data_type);
168         }
169
170         echo "|---potential---";
171         if ($potential_nodes) foreach ($potential_nodes as $potential_node) {
172                 echo "|".$potential_node['node_id'];
173                 echo ":".$ColumnsConfigure->convert_data($tophat_data[$potential_node['hostname']][$tagN], $data_type);
174         }
175         }
176 }
177 else //MyPLC API
178 {
179
180         $nodes=$api->GetNodes(array('node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
181         $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),array_merge($nodetags, $extratags));
182         
183         if ($nodes) {
184         echo "---attached---";
185         foreach ($nodes as $node) {
186                 echo "|".$node['node_id'];
187                 foreach ($extratags as $t)
188                         echo ":".$node[$t];
189         }
190         }
191         if ($potential_nodes) {
192         echo "|---potential---";
193         foreach ($potential_nodes as $potential_node) {
194                 echo "|".$potential_node['node_id'];
195                 foreach ($extratags as $t)
196                         echo ":".$potential_node[$t];
197         }
198         }
199 }
200 }
201 ?> 
202