62e46de7247e1f18c6f7613ba56ede1a753355f4
[plewww.git] / planetlab / nodes / slivers.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 // Print header
11 require_once 'plc_drupal.php';
12 drupal_set_title('Sliver Tags');
13 include 'plc_header.php';
14
15 // Common functions
16 require_once 'plc_functions.php';
17 require_once 'table.php';
18 require_once 'toggle.php';
19 require_once 'form.php';
20
21
22 // if slice and node ids are passed display slivers and tags
23 if( $_GET['slice_id'] && $_GET['node_id'] ) {
24     $slice_id = $_GET['slice_id'];
25     $node_id = $_GET['node_id'];
26
27
28     // slice info
29     $slice = $api->GetSlices( array( intval( $slice_id ) ), array( "name" ) );
30     $slice = $slice[0];
31
32     // node info
33     $node = $api->GetNodes( array( intval( $node_id ) ), array( "hostname" ) );
34     $node = $node[0];
35
36     drupal_set_title("Sliver tags on node " . $node['hostname'] . " and slice " . $slice['name']);
37
38     $peer_id= $slice['peer_id'];
39     $local_peer = ! $peer_id;
40     $privileges = ( $local_peer && (plc_is_admin()  || plc_is_pi() || $am_in_slice));
41
42     // get the slivers for this node
43     $tags = $api->GetSliceTags( array( "node_id"=>intval( $node_id ), "slice_id"=>intval( $slice_id ) ),
44                                   array( "slice_tag_id", "tagname", "value", "min_role_id", "description" ) );
45
46     $toggle = new PlekitToggle ('sliver-tags',count_english_warning($tags,'tag'),
47                                 array('bubble'=>'Inspect and set tags on the sliver',
48                                       'visible'=>true));
49     $toggle->start();
50
51     $headers=array(
52         "Name"=>"string",
53         "Value"=>"string",
54         "Description"=>"string");
55     if ($privileges) $headers[plc_delete_icon()]="none";
56
57     $table_options = array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
58     $table = new PlekitTable("sliver_tags",$headers,'0',$table_options);
59     $form = new PlekitForm(l_actions(),array('slice_id'=>$slice_id, 'node_id'=>$node_id, 'sliver_action'=>true));
60     $form->start();
61     $table->start();
62
63     foreach ($tags as $tag) {
64         $table->row_start();
65         $table->cell($tag['tagname']);
66         $table->cell($tag['value']);
67         $table->cell($tag['description']);
68         $table->row_end();
69     }
70
71     if ($privileges) {
72         $table->tfoot_start();
73         $table->row_start();
74         $table->cell($form->submit_html ("delete-slice-tags","Remove selected"),
75                      array('hfill'=>true,'align'=>'right'));
76         $table->row_end();
77
78         $table->row_start();
79         function tag_selector ($tag) {
80             return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']);
81         }
82         $all_tags= $api->GetTagTypes( array ("category"=>"slice*"), array("tagname","tag_type_id"));
83         $selector_tag=array_map("tag_selector",$all_tags);
84
85         $table->cell($form->select_html("tag_type_id",$selector_tag,array('label'=>"Choose Tag")));
86         $table->cell($form->text_html("value","",array('width'=>8)));
87         $table->cell($form->submit_html("add-slice-tag","Set Tag"),array('columns'=>2,'align'=>'left'));
88         $table->row_end();
89     }
90
91     $form->end();
92     $table->end();
93     $toggle->end();
94 }
95
96 // Print footer
97 include 'plc_footer.php';
98
99 ?>