tweaks label for pending sites, as they might be disabled too
[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         $comon_url = "http://comon.cs.princeton.edu";
378         $comon_api_url = "status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
379
380         if (MYSLICE_COMON_URL != "")
381                 $comon_url = MYSLICE_COMON_URL;
382
383         $url = $comon_url."/".$comon_api_url.$requested_data."'";
384
385         //print ("Retrieving comon data for url ".$url);
386
387         $sPattern = '\', \'';
388         $sReplace = '|';
389
390         $str=file_get_contents($url);
391
392         if ($str === false)
393                 return '';
394
395         $result=preg_replace( $sPattern, $sReplace, $str );
396         $sPattern = '/\s+/';
397         $sReplace = ';';
398         $result=preg_replace( $sPattern, $sReplace, $result );
399
400         $comon_data = explode(";", $result);
401         $cl = array();
402         $comon_values = array();
403
404         foreach ($comon_data as $cd) {
405                 $cc = explode("|", $cd);
406                 if ($cc[0] == "name") {
407                         $cl = $cc;
408                 }
409                 $comon_values[$cc[0]] = array();
410                 $cindex=1;
411                 foreach ($cl as $cltag) {
412                         if ($cltag != "name")
413                                 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
414                 }
415         }
416
417         return $comon_values;
418 }
419
420
421 //Depending on the columns selected more data might need to be fetched from
422 //external sources
423
424 function fetch_live_data($all_nodes) {
425
426         //print("<p>fetching live data<p>");
427
428 //comon data
429         if ($this->comon_live_data != "") {
430         
431                 //print ("live data to be fetched =".$this->comon_live_data);
432                 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
433                 //print_r($this->ComonData);
434         }
435
436 //TopHat per_node data
437         if ($this->tophat_live_data != "")
438         {
439                 $dd = array();
440
441                 if ($all_nodes) foreach ($all_nodes as $n)
442                         $dd[] = $n['hostname'];
443
444                 //print("Calling tophat api for ".$this->tophat_live_data);
445                 $st = time() + microtime();
446                 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
447                 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
448                 //print_r($this->TopHatData);
449         }
450
451 //TopHat pairwise data
452
453         $this->HopCount = "";
454         $this->RTT = "";
455
456         if ($this->reference_nodes != "")
457         {
458                 //print_r($this->reference_nodes);
459
460                 $dd = array();
461
462                 if ($all_nodes) foreach ($all_nodes as $n)
463                         $dd[] = $n['hostname'];
464
465                 $st = time() + microtime();
466                 if ($this->headerIsVisible("HC"))
467                 {
468                         print("[NEW] Calling tophat api for HopCount with reference node = ".$this->reference_nodes['hopcount']);
469                         $this->HopCount = $this->getPairwise($this->reference_nodes['hopcount'], $dd, 'traceroute', 'hop_count');
470                 }
471                 else 
472
473                 if ($this->headerIsVisible("RTT"))
474                 {
475                         print("[NEW] Calling tophat api for RTT with reference node = ".$this->reference_nodes['rtt']);
476                         $this->RTT = $this->getPairwise($this->reference_nodes['rtt'], $dd, 'rtt','rtt');
477                 }
478
479                 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
480                 print_r($this->HopCount);
481         }
482 }
483
484
485 function excludeItems($value, $exclude_list, $hh) {
486
487         if ($value == "")
488                 $value = "n/a";
489
490         if ($exclude_list)
491         if (in_array($value, $exclude_list))
492                 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
493         else
494                 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
495
496         return array($value, array('name'=>$hh, 'display'=>'table-cell'));
497 }
498
499
500 function checkThreshold($value, $threshold, $hh) {
501
502         if ($value == "")
503                 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
504
505         if ($threshold)
506         if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
507                 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
508         else
509                 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
510
511         return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
512 }
513
514
515 function cells($table, $node) {
516
517 //$node_string = "";
518
519 foreach ($this->all_headers as $h) {
520
521 if (!$h['fixed']) { 
522
523 if ($h['visible'] != "") {
524
525 /*
526 if ($this->inTypeB($h['header']))
527 {
528         $value = $node[$h['tagname']];
529         $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
530         $table->cell($v[0],$v[1]);
531 }
532 else if ($this->inTypeA($h['header']))
533 {
534         $value = $node[$h['tagname']];
535         $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
536         $table->cell($v[0],$v[1]);
537 }
538 */
539 if ($h['source'] == "comon")
540 {
541         //print("<br>Searching for ".$h['tagname']."at ".$node);
542         if ($this->ComonData != "")
543                 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
544         else
545                 $value = "n/a";
546
547         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
548         //$node_string.= "\"".$value."\",";
549 }
550 else if ($h['source'] == "tophat")
551 {
552         //print("<br>Searching for ".$h['tagname']."at ".$node);
553         if ($h['tagname'] == "hopcount")
554         {
555                 //print "value = ".$this->HopCount[$node['hostname']];
556                 //$value = "hc";
557                 if ($this->HopCount != "")
558                         $value = $this->HopCount[$node['hostname']];
559                 else
560                         $value = "n/a";
561         }
562         else if ($h['tagname'] == "rtt")
563         {
564                 if ($this->RTT != "")
565                         if ($this->RTT[$node['hostname']] != "")
566                                 $value = $this->RTT[$node['hostname']];
567                         else
568                                 $value = "n/a";
569                 else
570                         $value = "n/a";
571         }       
572         else if ($h['tagname'] == "agents")
573         {
574                 if ($this->TopHatAgents != "")
575                         if ($this->TopHatAgents[$node['hostname']] != "")
576                                 $value = $this->TopHatAgents[$node['hostname']]['all'];
577                         else
578                                 $value = "n/a";
579                 else
580                         $value = "n/a";
581         }       
582         else if ($h['tagname'] == "agents_tdmi")
583         {
584                 if ($this->TopHatAgents != "")
585                         if ($this->TopHatAgents[$node['hostname']] != "")
586                                 $value = $this->TopHatAgents[$node['hostname']]['tdmi'];
587                         else
588                                 $value = "n/a";
589                 else
590                         $value = "n/a";
591         }       
592         else if ($h['tagname'] == "agents_sonoma")
593         {
594                 if ($this->TopHatAgents != "")
595                         if ($this->TopHatAgents[$node['hostname']] != "")
596                                 $value = $this->TopHatAgents[$node['hostname']]['sonoma'];
597                         else
598                                 $value = "n/a";
599                 else
600                         $value = "n/a";
601         }       
602         else
603         {
604                 if ($this->TopHatData != "")
605                         $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
606                 else
607                         $value = "n/a";
608         }
609
610         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
611         //$node_string.= "\"".$value."\",";
612 }
613 else
614 {
615         //$value = $node[$h['tagname']];
616         $value = $this->convert_data($node[$h['tagname']], $h['type']);
617         $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
618         //$node_string.= "\"".$value."\",";
619 }
620 }
621 else 
622         if ($node[$h['tagname']])
623         {
624                 $value = $this->convert_data($node[$h['tagname']], $h['type']);
625                 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
626         }
627         else
628                 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
629 }
630 }
631
632 //return $node_string;
633
634 }
635
636
637 /*
638
639 HTML
640
641 */
642
643
644 function javascript_init() {
645
646 $refnodes = $this->getTopHatRefNodes();
647 //$tophat_agents = $this->getTopHatAgents();
648 $ref_nodes = "";
649 foreach ($refnodes as $r)
650 {
651         if ($r['hostname'] == $this->reference_nodes['hopcount'])
652                 $selected = "selected=selected";
653         else
654                 $selected = "";
655
656         $ref_nodes = $ref_nodes."<option value=".$r['hostname']." ".$selected.">".$r['hostname']."</option>";
657 }
658
659 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_nodes['hopcount']."' />");
660
661 print("<script type='text/javascript'>");
662 print("highlightOption('AU');");
663 print("overrideTitles();");
664 print "var ref_nodes_select =\"Select reference node: <select id='refnodeHC' onChange='updateReferenceNode(this.id,this.value)'>".$ref_nodes."</select>\";";
665 print("</script>");
666
667 }
668
669 function quickselect_html() {
670
671 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
672 $prev_label="";
673 $optionclass = "out";
674 foreach ($this->all_headers as $h)
675 {
676         if ($h['header'] == "hostname" || $h['header'] == "ID")
677                 continue;
678
679         if ($h['fixed'])
680                 $disabled = "disabled=true";
681         else
682                 $disabled = "";
683
684         if ($this->headerIsVisible($h['label']))
685                 $optionclass = "in";
686         else
687                 $optionclass = "out";
688
689         if ($prev_label == $h['label'])
690                 continue;
691
692         $prev_label = $h['label'];
693
694         $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>:&nbsp;".$h['title']."</option>";
695
696 }
697
698 $quickselection.="</select>";
699
700 return $quickselection;
701
702 }
703
704
705 function configuration_panel_html($showDescription) {
706
707 if ($showDescription)
708         $table_width = 700;
709 else
710         $table_width = 350;
711
712 print("<table class='center' width='".$table_width."px'>");
713 print("<tr><th class='top'>Add/remove columns</th>");
714
715 if ($showDescription)
716         print("<th class='top'>Column description and configuration</th>");
717
718 print("</tr><tr><td class='top' width='300px'>");
719
720         print('<div id="scrolldiv">');
721 print ("<table>");
722         $prev_label="";
723         $optionclass = "out";
724         foreach ($this->all_headers as $h)
725         {
726                 if ($h['header'] == "hostname" || $h['header'] == "ID")
727                         continue;
728
729                 if ($h['fixed'])
730                         $disabled = "disabled=true";
731                 else
732                         $disabled = "";
733
734                 if ($this->headerIsVisible($h['label']))
735                 {
736                         $selected = "checked=true";
737                         $fetch = "true";
738                         //print("header ".$h['label']." checked!");
739                 }
740                 else
741                 {
742                         $selected = "";
743                         if ($h['fetched'])
744                                 $fetch = "true";
745                         else
746                                 $fetch = "false";
747                 }
748
749                 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
750
751                 if ($prev_label == $h['label'])
752                         continue;
753
754                 $prev_label = $h['label'];
755                 $period = $this->get_selected_period($h['label']);
756
757 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
758                 print ("<tr><td>
759 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
760 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
761 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
762 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
763                 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
764 <table class='columnlist' id='table".$h['label']."'><tr>
765 <td class='header'><span class='header'>".$h['label']."</span></td> 
766 <td align=left>&nbsp;<span class='short' id ='htitle".$h['label']."'>".$h['title']."</span>&nbsp;</td>
767 <td class='smallright'>&nbsp;<span class='short' id ='loading".$h['label']."'></span>&nbsp;</td>
768 <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>
769 </tr></table></div></td></tr>");
770         }
771
772         print("</table> </div></td>");
773
774 if ($showDescription)
775 {
776         print("<td class='top' width='400px'>");
777         print("<div id='selectdescr'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>");
778 }
779
780 print("</tr>");
781 //print("<tr><td align=center>");
782 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
783 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
784 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
785 //print("</td>");
786 //print("&nbsp;<input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
787 //print("&nbsp;<input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
788
789 if ($showDescription)
790         print("<td></td>");
791
792 print(" </tr> </table>");
793 }
794
795
796
797 function column_filter () {
798
799 echo <<< EOF
800
801 Highlight <select onChange="filterByType(this.value)">
802 <option value="none">None</option>
803 <option value="capabilities">Capabilities</option>
804 <option value="statistics">Statistics</option>
805 <option value="network">Network</option>
806 <option value="pairwise">Pairwise</option>
807 <option value="other">Other</option>
808 </select>
809 <p>
810
811 EOF;
812 }
813
814   function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
815
816         if ($visible) 
817                 $display = 'display:table-cell';
818         else 
819                 $display = 'color:red;display:none';
820
821     return "
822         <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
823         <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
824         </th>
825         ";
826   }
827
828   function column_fix_html ($colHeader, $colName, $colId) {
829
830         $display = 'display:table-cell';
831
832         $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
833                 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
834
835         return $res;
836   }
837
838
839 function graph_html($colHeader) {
840
841         return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
842
843         }
844
845 function threshold_html($colHeader) {
846
847         $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
848
849         $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>"; 
850
851         return $bublle;
852 }
853
854
855 /*
856
857 UTILS
858
859 */
860
861 //simple strings
862 function inTypeA($header_name) {
863         $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
864         return in_array($header_name, $typeA);
865 }
866
867 //integers
868 function inTypeB($header_name) {
869         $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
870         return in_array($header_name, $typeB);
871 }
872
873 //statistical values
874 function inTypeC($header_name) {
875         $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
876         return in_array($header_name, $typeC);
877 }
878
879 //tophat
880 function inTypeD($header_name) {
881         $typeD = array('HC');
882         return in_array($header_name, $typeD);
883 }
884
885
886 function removeDuration($header)
887 {
888         if ($this->inTypeC($header))
889                 return substr($header, 0, strlen($header)-1);
890         else
891                 return $header;
892 }
893
894 }
895
896 ?>
897
898