ffc41ced5d06b651457626ff8c86dbc692ccc5ce
[plewww.git] / plekit / php / columns.php
1 <?php
2
3 require_once 'tophat_api.php';
4
5 drupal_set_html_head('
6 <script type="text/javascript" src="/plekit/table/columns.js"></script>
7 ');
8
9 class PlekitColumns {
10
11 var $column_configuration = "";
12 var $reference_nodes = array();
13 var $first_time = false;
14
15 var $all_headers = array();
16 var $this_table_headers = array();
17 var $visible_headers = array();
18
19 var $fix_columns = array();
20 var $tag_columns = array();
21 var $extra_columns = array();
22
23 var $comon_live_data = "";
24 var $tophat_live_data = "";
25 var $ComonData = array();
26 var $TopHatData = array();
27 var $TopHatAgents = array();
28
29 var $table_ids;
30
31 var $HopCount = array();
32 var $RTT = array();
33
34 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
35
36         if ($column_configuration != NULL) {
37         $this->fix_columns = $fix_columns;
38         $this->tag_columns = $tag_columns;
39         $this->extra_columns = $extra_columns;
40
41         $this->prepare_headers();
42         $this->parse_configuration($column_configuration);
43
44         $this->visible_headers = $this->get_visible();
45         }
46 }
47
48
49
50 /*
51
52 INFO/HEADERS
53
54 */
55
56 function prepare_headers() {
57
58 foreach ($this->fix_columns as $column) {
59 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fixed'=>true, 'visible'=>false, 'source'=>'myplc');
60 }
61
62 $tmp_headers = array();
63
64 if ($this->extra_columns)
65 foreach ($this->extra_columns as $column) {
66 $tmp_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fetched'=>$column['fetched'], 'visible'=>false, 'source'=>$column['source']);
67
68 }
69
70 if ($this->tag_columns)
71 foreach ($this->tag_columns as $column) {
72
73 if ($column['headerId'] != "")
74         $headerId = $column['headerId'];
75 else
76         $headerId = $column['header'];
77
78 $tmp_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false, 'source'=>'myplc');
79 }
80
81 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
82
83 foreach ($tmp_headers as $t) 
84 $this->all_headers[$t['header']] = $t;
85
86 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
87
88 //print($this->print_headers());
89
90 return $this->all_headers;
91
92 }
93
94
95 function get_headers() {
96
97 return $this->all_headers;
98
99 }
100
101 function get_selected_period($label) {
102
103 if ($this->all_headers[$label."w"]['visible'])
104         return "w";
105 else if ($this->all_headers[$label."m"]['visible'])
106         return "m";
107 else if ($this->all_headers[$label."y"]['visible'])
108         return "y";
109 else if ($this->all_headers[$label]['visible'])
110         return "";
111         
112 return "";
113 }
114
115 function node_tags() {
116
117         $fetched_tags = array('node_id','hostname');    
118
119         foreach ($this->all_headers as $h)
120         {
121                 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
122                         $fetched_tags[] = $h['tagname'];
123         }
124
125         return $fetched_tags;
126 }
127
128 function print_headers() {
129
130         $headers = "";  
131
132         foreach ($this->all_headers as $l => $h)
133         {
134                 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
135         }
136         return $headers;
137 }
138
139 function get_visible() {
140
141         $visibleHeaders = array();      
142
143         foreach ($this->all_headers as $h)
144         {
145                 if ($h['visible'] == true)
146                         $visibleHeaders[] = $h['header'];
147         }
148         return $visibleHeaders;
149 }
150
151 function headerIsVisible($header_name) {
152
153 $headersToShow = $this->visible_headers;
154
155 if (in_array($header_name, $headersToShow))
156         return true;
157
158 if ($this->inTypeC($header_name."w"))
159         return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
160 }
161
162
163
164
165 /*
166
167 CONFIGURATION
168
169 */
170
171
172 function parse_configuration($column_configuration) {
173
174         $this->column_configuration = $column_configuration;
175         $columns_conf = explode("|", $column_configuration);
176
177
178         foreach ($columns_conf as $c)
179         {
180                 $conf = explode(":",$c);
181
182                 if ($conf[0] == "default")
183                         continue;
184
185                 if (!$this->all_headers[$conf[0]])
186                         continue;
187
188                 $this->all_headers[$conf[0]]['visible']=true;
189
190                 if ($this->all_headers[$conf[0]]['source'] == "comon")
191                         $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
192
193                 if ($this->all_headers[$conf[0]]['source'] == "tophat")
194                 {
195                         if ($this->all_headers[$conf[0]]['tagname'] == 'hopcount')
196                         {
197                                 $this->reference_nodes['hopcount'] = $conf[1];
198                                 //print ("ref node in configuration = ".$conf[1]);
199                                 $this->all_headers[$conf[0]]['refnode']=$this->reference_nodes['hopcount'];
200                         }
201                         else if (strpos($this->all_headers[$conf[0]]['tagname'],"agents") === false)
202                                 $this->tophat_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
203                         //$threshold = explode(",",$conf[1]);
204                         //$this->all_headers[$conf[0]]['threshold']=$threshold;
205                 }
206
207                 //print_r($this->all_headers[$conf[0]]);
208
209 /*
210                 else if ($this->inTypeC($conf[0]))
211                 {
212                         $threshold = explode(",",$conf[1]);
213                         $this->all_headers[$conf[0]]['threshold']=$threshold;
214                 }
215                 else if ($this->inTypeA($conf[0]))
216                 {
217                         $exclude_list = explode(",",$conf[1]);
218                         $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
219                 }
220 */
221         }
222
223 }
224
225
226                 
227
228
229 /*
230
231 CELLS
232
233 */
234
235 function convert_data($value, $data_type) {
236
237         //print "converting ".$value." as ".$data_type;
238
239         if ($value == "" || $value == null || $value == "n/a" || $value == "None")
240                 return "n/a";
241
242         if ($data_type == "string")
243                 return $value;
244
245         if ($data_type == "date") 
246                 return date("Y-m-d", $value);
247
248         if ($data_type == "uptime") 
249                 return (int)((int) $value / 86400);
250
251         if (is_numeric($value))
252                 return ((int) ($value * 10))/10;
253         
254         return $value;
255
256 }
257
258 function getTopHatAgents() {
259
260         $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
261         $tophat_api = new TopHatAPI($tophat_auth);
262
263         //print ("Requesting tophat agents...");
264         //print_r($r);
265
266         $values = $tophat_api->Get('agents', 'latest', array('colocated.platform_name' => array('SONoMA', 'DIMES', 'ETOMIC', 'TDMI'), 'platform_name'=> 'TDMI'), array('hostname', 'colocated.peer_name', 'colocated.platform_name'));
267
268         $result = array();
269
270         if ($values) foreach ($values as $t) {
271                 //print_r($t);
272                 //print("<hr>");
273                 $result[$t['hostname']] = "";
274                 foreach ($t['colocated'] as $ll) {
275
276                         if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) {
277                                 if ($result[$t['hostname']]['all'] != "")
278                                         $result[$t['hostname']]['all'] .= ",";
279                                 $result[$t['hostname']]['all'] .= $ll['platform_name'];
280                         }
281
282                         if ($ll['platform_name'] == 'SONoMA') {
283                         if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) {
284                                         if ($result[$t['hostname']]['sonoma'] != "")
285                                                 $result[$t['hostname']]['sonoma'] .= ",";
286                                         $result[$t['hostname']]['sonoma'] .= $ll['peer_name'];
287                         }
288                         }
289
290                         if ($ll['platform_name'] == 'TDMI') {
291                         if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) {
292                                 if ($result[$t['hostname']]['tdmi'] != "")
293                                         $result[$t['hostname']]['tdmi'] .= ",";
294                                 $result[$t['hostname']]['tdmi'] .= $ll['peer_name'];
295                         }
296                         }
297                 }
298         }
299
300         $this->TopHatAgents = $result;
301
302         //print_r($this->TopHatAgents);
303
304         return $result;
305 }
306
307 function getTopHatData($data, $planetlab_nodes) {
308
309         $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
310         $tophat_api = new TopHatAPI($tophat_auth);
311
312         $requested_data = explode(",", $data);
313
314         $r = array ('hostname');
315         
316         foreach ($requested_data as $rd)
317                 if ($rd) $r[] = $rd;
318
319         //print ("Requesting data from TopHat ...");
320         //print_r($r);
321
322         $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r );
323
324         $result = array();
325
326         if ($values) foreach ($values as $t)
327                 foreach ($requested_data as $rd)
328                         if ($rd) $result[$t['hostname']][$rd] = $t[$rd];
329
330         //print_r($result);
331
332         return $result;
333 }
334
335 function getTopHatRefNodes() {
336
337         $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
338         $tophat_api = new TopHatAPI($tophat_auth);
339
340         //print "calling tophat for agents";
341
342         $agents = $tophat_api->Get('agents', 'latest', array('peer_name'=>array('PLC', 'PLE'), 'agent_status'=> 'OK'),  array('hostname'));
343
344         //print_r($agents);
345
346         return $agents;
347
348 }
349
350 function getPairwise($ref_node, $planetlab_nodes, $command, $data) {
351
352         $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
353         $tophat_api = new TopHatAPI($tophat_auth);
354
355         $traceroute = $tophat_api->Get($command, 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', $data) );
356
357         print "Got result: ".$traceroute;
358
359         $hopcount = array();
360
361         if ($traceroute) 
362         {
363                 foreach ($traceroute as $t)
364                 {
365                         $hopcount[$t['dst_hostname']]=$t[$data];
366                         //print "  current: ".$t['dst_hostname'].":".$t['hop_count'];
367                 }
368
369                 return $hopcount;
370         }
371         else
372                 return "";
373 }
374
375 function comon_query_nodes($requested_data) {
376
377         $base_url = "http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
378
379         $url = $base_url.$requested_data."'";
380
381         //print ("Retrieving comon data for url ".$url);
382
383         $sPattern = '\', \'';
384         $sReplace = '|';
385
386         $str=file_get_contents($url);
387
388         if ($str === false)
389                 return '';
390
391         $result=preg_replace( $sPattern, $sReplace, $str );
392         $sPattern = '/\s+/';
393         $sReplace = ';';
394         $result=preg_replace( $sPattern, $sReplace, $result );
395
396         $comon_data = explode(";", $result);
397         $cl = array();
398         $comon_values = array();
399
400         foreach ($comon_data as $cd) {
401                 $cc = explode("|", $cd);
402                 if ($cc[0] == "name") {
403                         $cl = $cc;
404                 }
405                 $comon_values[$cc[0]] = array();
406                 $cindex=1;
407                 foreach ($cl as $cltag) {
408                         if ($cltag != "name")
409                                 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
410                 }
411         }
412
413         return $comon_values;
414 }
415
416
417 //Depending on the columns selected more data might need to be fetched from
418 //external sources
419
420 function fetch_live_data($all_nodes) {
421
422         //print("<p>fetching live data<p>");
423
424 //comon data
425         if ($this->comon_live_data != "") {
426         
427                 //print ("live data to be fetched =".$this->comon_live_data);
428                 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
429                 //print_r($this->ComonData);
430         }
431
432 //TopHat per_node data
433         if ($this->tophat_live_data != "")
434         {
435                 $dd = array();
436
437                 if ($all_nodes) foreach ($all_nodes as $n)
438                         $dd[] = $n['hostname'];
439
440                 //print("Calling tophat api for ".$this->tophat_live_data);
441                 $st = time() + microtime();
442                 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
443                 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
444                 //print_r($this->TopHatData);
445         }
446
447 //TopHat pairwise data
448
449         $this->HopCount = "";
450         $this->RTT = "";
451
452         if ($this->reference_nodes != "")
453         {
454                 //print_r($this->reference_nodes);
455
456                 $dd = array();
457
458                 if ($all_nodes) foreach ($all_nodes as $n)
459                         $dd[] = $n['hostname'];
460
461                 $st = time() + microtime();
462                 if ($this->headerIsVisible("HC"))
463                 {
464                         print("[NEW] Calling tophat api for HopCount with reference node = ".$this->reference_nodes['hopcount']);
465                         $this->HopCount = $this->getPairwise($this->reference_nodes['hopcount'], $dd, 'traceroute', 'hop_count');
466                 }
467                 else 
468
469                 if ($this->headerIsVisible("RTT"))
470                 {
471                         print("[NEW] Calling tophat api for RTT with reference node = ".$this->reference_nodes['rtt']);
472                         $this->RTT = $this->getPairwise($this->reference_nodes['rtt'], $dd, 'rtt','rtt');
473                 }
474
475                 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
476                 print_r($this->HopCount);
477         }
478 }
479
480
481 function excludeItems($value, $exclude_list, $hh) {
482
483         if ($value == "")
484                 $value = "n/a";
485
486         if ($exclude_list)
487         if (in_array($value, $exclude_list))
488                 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
489         else
490                 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
491
492         return array($value, array('name'=>$hh, 'display'=>'table-cell'));
493 }
494
495
496 function checkThreshold($value, $threshold, $hh) {
497
498         if ($value == "")
499                 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
500
501         if ($threshold)
502         if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
503                 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
504         else
505                 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
506
507         return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
508 }
509
510
511 function cells($table, $node) {
512
513 //$node_string = "";
514
515 foreach ($this->all_headers as $h) {
516
517 if (!$h['fixed']) { 
518
519 if ($h['visible'] != "") {
520
521 /*
522 if ($this->inTypeB($h['header']))
523 {
524         $value = $node[$h['tagname']];
525         $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
526         $table->cell($v[0],$v[1]);
527 }
528 else if ($this->inTypeA($h['header']))
529 {
530         $value = $node[$h['tagname']];
531         $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
532         $table->cell($v[0],$v[1]);
533 }
534 */
535 if ($h['source'] == "comon")
536 {
537         //print("<br>Searching for ".$h['tagname']."at ".$node);
538         if ($this->ComonData != "")
539                 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
540         else
541                 $value = "n/a";
542
543         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
544         //$node_string.= "\"".$value."\",";
545 }
546 else if ($h['source'] == "tophat")
547 {
548         //print("<br>Searching for ".$h['tagname']."at ".$node);
549         if ($h['tagname'] == "hopcount")
550         {
551                 //print "value = ".$this->HopCount[$node['hostname']];
552                 //$value = "hc";
553                 if ($this->HopCount != "")
554                         $value = $this->HopCount[$node['hostname']];
555                 else
556                         $value = "n/a";
557         }
558         else if ($h['tagname'] == "rtt")
559         {
560                 if ($this->RTT != "")
561                         if ($this->RTT[$node['hostname']] != "")
562                                 $value = $this->RTT[$node['hostname']];
563                         else
564                                 $value = "n/a";
565                 else
566                         $value = "n/a";
567         }       
568         else if ($h['tagname'] == "agents")
569         {
570                 if ($this->TopHatAgents != "")
571                         if ($this->TopHatAgents[$node['hostname']] != "")
572                                 $value = $this->TopHatAgents[$node['hostname']]['all'];
573                         else
574                                 $value = "n/a";
575                 else
576                         $value = "n/a";
577         }       
578         else if ($h['tagname'] == "agents_tdmi")
579         {
580                 if ($this->TopHatAgents != "")
581                         if ($this->TopHatAgents[$node['hostname']] != "")
582                                 $value = $this->TopHatAgents[$node['hostname']]['tdmi'];
583                         else
584                                 $value = "n/a";
585                 else
586                         $value = "n/a";
587         }       
588         else if ($h['tagname'] == "agents_sonoma")
589         {
590                 if ($this->TopHatAgents != "")
591                         if ($this->TopHatAgents[$node['hostname']] != "")
592                                 $value = $this->TopHatAgents[$node['hostname']]['sonoma'];
593                         else
594                                 $value = "n/a";
595                 else
596                         $value = "n/a";
597         }       
598         else
599         {
600                 if ($this->TopHatData != "")
601                         $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
602                 else
603                         $value = "n/a";
604         }
605
606         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
607         //$node_string.= "\"".$value."\",";
608 }
609 else
610 {
611         //$value = $node[$h['tagname']];
612         $value = $this->convert_data($node[$h['tagname']], $h['type']);
613         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
614         //$node_string.= "\"".$value."\",";
615 }
616 }
617 else 
618         if ($node[$h['tagname']])
619         {
620                 $value = $this->convert_data($node[$h['tagname']], $h['type']);
621                 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
622         }
623         else
624                 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
625 }
626 }
627
628 //return $node_string;
629
630 }
631
632
633 /*
634
635 HTML
636
637 */
638
639
640 function javascript_init() {
641
642 $refnodes = $this->getTopHatRefNodes();
643 //$tophat_agents = $this->getTopHatAgents();
644 $ref_nodes = "";
645 foreach ($refnodes as $r)
646 {
647         if ($r['hostname'] == $this->reference_nodes['hopcount'])
648                 $selected = "selected=selected";
649         else
650                 $selected = "";
651
652         $ref_nodes = $ref_nodes."<option value=".$r['hostname']." ".$selected.">".$r['hostname']."</option>";
653 }
654
655 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_nodes['hopcount']."' />");
656
657 print("<script type='text/javascript'>");
658 print("highlightOption('AU');");
659 print("overrideTitles();");
660 print "var ref_nodes_select =\"Select reference node: <select id='refnodeHC' onChange='updateReferenceNode(this.id,this.value)'>".$ref_nodes."</select>\";";
661 print("</script>");
662
663 }
664
665 function quickselect_html() {
666
667 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
668 $prev_label="";
669 $optionclass = "out";
670 foreach ($this->all_headers as $h)
671 {
672         if ($h['header'] == "hostname" || $h['header'] == "ID")
673                 continue;
674
675         if ($h['fixed'])
676                 $disabled = "disabled=true";
677         else
678                 $disabled = "";
679
680         if ($this->headerIsVisible($h['label']))
681                 $optionclass = "in";
682         else
683                 $optionclass = "out";
684
685         if ($prev_label == $h['label'])
686                 continue;
687
688         $prev_label = $h['label'];
689
690         $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>:&nbsp;".$h['title']."</option>";
691
692 }
693
694 $quickselection.="</select>";
695
696 return $quickselection;
697
698 }
699
700
701 function configuration_panel_html($showDescription) {
702
703 if ($showDescription)
704         $table_width = 700;
705 else
706         $table_width = 350;
707
708 print("<table class='center' width='".$table_width."px'>");
709 print("<tr><th class='top'>Add/remove columns</th>");
710
711 if ($showDescription)
712         print("<th class='top'>Column description and configuration</th>");
713
714 print("</tr><tr><td class='top' width='300px'>");
715
716         print('<div id="scrolldiv">');
717 print ("<table>");
718         $prev_label="";
719         $optionclass = "out";
720         foreach ($this->all_headers as $h)
721         {
722                 if ($h['header'] == "hostname" || $h['header'] == "ID")
723                         continue;
724
725                 if ($h['fixed'])
726                         $disabled = "disabled=true";
727                 else
728                         $disabled = "";
729
730                 if ($this->headerIsVisible($h['label']))
731                 {
732                         $selected = "checked=true";
733                         $fetch = "true";
734                         //print("header ".$h['label']." checked!");
735                 }
736                 else
737                 {
738                         $selected = "";
739                         if ($h['fetched'])
740                                 $fetch = "true";
741                         else
742                                 $fetch = "false";
743                 }
744
745                 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
746
747                 if ($prev_label == $h['label'])
748                         continue;
749
750                 $prev_label = $h['label'];
751                 $period = $this->get_selected_period($h['label']);
752
753 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
754                 print ("<tr><td>
755 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
756 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
757 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
758 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
759                 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
760 <table class='columnlist' id='table".$h['label']."'><tr>
761 <td class='header'><span class='header'>".$h['label']."</span></td> 
762 <td align=left>&nbsp;<span class='short' id ='htitle".$h['label']."'>".$h['title']."</span>&nbsp;</td>
763 <td class='smallright'>&nbsp;<span class='short' id ='loading".$h['label']."'></span>&nbsp;</td>
764 <td class='smallright'><input id='check".$h['label']."' name='".$h['tagname']."' type='checkbox' ".$selected." ".$disabled." autocomplete='off' value='".$h['label']."' onclick='changeCheckStatus(this.id)'></input></td>
765 </tr></table></div></td></tr>");
766         }
767
768         print("</table> </div></td>");
769
770 if ($showDescription)
771 {
772         print("<td class='top' width='400px'>");
773         print("<div id='selectdescr'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>");
774 }
775
776 print("</tr>");
777 //print("<tr><td align=center>");
778 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
779 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
780 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
781 //print("</td>");
782 //print("&nbsp;<input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
783 //print("&nbsp;<input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
784
785 if ($showDescription)
786         print("<td></td>");
787
788 print(" </tr> </table>");
789 }
790
791
792
793 function column_filter () {
794
795 echo <<< EOF
796
797 Highlight <select onChange="filterByType(this.value)">
798 <option value="none">None</option>
799 <option value="capabilities">Capabilities</option>
800 <option value="statistics">Statistics</option>
801 <option value="network">Network</option>
802 <option value="pairwise">Pairwise</option>
803 <option value="other">Other</option>
804 </select>
805 <p>
806
807 EOF;
808 }
809
810   function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
811
812         if ($visible) 
813                 $display = 'display:table-cell';
814         else 
815                 $display = 'color:red;display:none';
816
817     return "
818         <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
819         <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
820         </th>
821         ";
822   }
823
824   function column_fix_html ($colHeader, $colName, $colId) {
825
826         $display = 'display:table-cell';
827
828         $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
829                 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
830
831         return $res;
832   }
833
834
835 function graph_html($colHeader) {
836
837         return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
838
839         }
840
841 function threshold_html($colHeader) {
842
843         $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
844
845         $bubble="<b>Grey-out values between</b>  <input type='text' id='min".$colHeader."' size='2' value='5'> (low) and <input type='text' id='max".$colHeader."' size='2' value='90'> (high) <input type='submit' value='Update' onclick=".$updatecall.">&nbsp;</input>"; 
846
847         return $bublle;
848 }
849
850
851 /*
852
853 UTILS
854
855 */
856
857 //simple strings
858 function inTypeA($header_name) {
859         $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
860         return in_array($header_name, $typeA);
861 }
862
863 //integers
864 function inTypeB($header_name) {
865         $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
866         return in_array($header_name, $typeB);
867 }
868
869 //statistical values
870 function inTypeC($header_name) {
871         $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
872         return in_array($header_name, $typeC);
873 }
874
875 //tophat
876 function inTypeD($header_name) {
877         $typeD = array('HC');
878         return in_array($header_name, $typeD);
879 }
880
881
882 function removeDuration($header)
883 {
884         if ($this->inTypeC($header))
885                 return substr($header, 0, strlen($header)-1);
886         else
887                 return $header;
888 }
889
890 }
891
892 ?>
893
894