improvements
[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('Slivers');
13 include 'plc_header.php';
14
15 // Common functions
16 require_once 'plc_functions.php';
17
18 // find person roles
19 $_person= $plc->person;
20 $_roles= $_person['role_ids'];
21
22 //print_r( $_person );
23
24
25 // if add is set, diplay add sliver form
26 if( $_GET['add'] ) {
27   $node_id= $_GET['add'];
28   $slice_id= $_GET['slice'];
29
30   // slice info
31   $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name" ) );
32
33   // node info
34   $node_info= $api->GetNodes( array( intval( $node_id ) ), array( "hostname" ) );
35
36   // get tag types
37   $type_info= $api->GetTagTypes( NULL, array( "tag_type_id", "tagname" ) );
38   
39   // get the slivers for this node
40   $sliver_info= $api->GetSliceTags( array( "node_id"=>intval( $node_id ), "slice_id"=>intval( $slice_id ) ), array( "tag_type_id", "name" ) );
41
42     $types_left= $type_info;
43
44
45   // start form
46   echo "<form action='sliver_action.php' method=post>\n
47   <h2>Add a Sliver Tag to ". $slice_info[0]['name'] ." on node ". $node_info[0]['hostname'] ."</h2>\n
48   <table class='list_set' border=0 cellpadding=2><tbody>\n
49   <tr class='list_set'><th class='list_set'>Tag: </th><td class='list_set'><select name='sliver'>\n";
50
51   foreach( $types_left as $type ) {
52     echo "<option value='". $type['tag_type_id'] ."'>". $type['name'] ."</option>\n";
53
54   }
55
56   echo "</td><td class='list_set'></td></tr>\n
57   <tr class='list_set'><th class='list_set'>Value: </th><td class='list_set'><input type=text name='value'></td></tr>\n
58   </tbody></table>\n
59   <input type=hidden name='node_id' value='$node_id'><input type=hidden name='slice_id' value='$slice_id'>
60   <p><input type=submit name='add_sub' value='Add Sliver Tag'>\n";
61
62   echo "<p><a href='index.php?id=$node_id'>Back to Node</a>\n</form>\n";
63   
64 }
65
66
67 // if slice and node ids are passed display slivers and tags
68 if( $_GET['slice'] && $_GET['node'] ) {
69   $slice_id= $_GET['slice'];
70   $node_id= $_GET['node'];
71
72   // slice info
73   $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name" ) );
74
75   // node info
76   $node_info= $api->GetNodes( array( intval( $node_id ) ), array( "hostname" ) );
77
78   // get the slivers for this node
79   $sliver_info= $api->GetSliceTags( array( "node_id"=>intval( $node_id ), "slice_id"=>intval( $slice_id ) ), array( "slice_tag_id", "name", "value", "min_role_id", "description" ) );
80
81   // get the attrbibutes for this slice
82   $tag_info= $api->GetSliceTags( array( intval( $slice_id ) ), array( "slice_tag_id", "name", "value", "min_role_id", "description" ) );
83
84
85   // start form
86   echo "<form action='slivers.php' method=post>\n<h2>Sliver Details for slice ". $slice_info[0]['name'] ." on node ". $node_info[0]['hostname'] ."</h2>\n";
87
88   // sliver tags of slice
89   if( empty( $sliver_info ) )
90     // if no sliver exists tell user
91     echo "No sliver tag for this node/slice sliver combination.\n";
92   else {
93     echo "<p><table class='list_set' border=0 cellpadding=2>\n<caption class='list_set'>Slivers</caption>\n<thead><tr class='list_set'><th class='list_set'>Name</th><th class='list_set'>Value</th><th class='list_set'>Min Roll</th><th class='list_set'>Description</th>";
94     if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<th></th><th></th>";
95     echo "</tr></thead><tbody>\n";
96
97     foreach( $sliver_info AS $sliver ) {
98       echo "<tr><td>". $sliver['name'] ."</td><td>". $sliver['value'] ."</td><td>". $sliver['min_role_id'] ."</td><td>". $sliver['description'] ."</td>";
99       if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<td><a href='/db/slices/tags.php?type=slice&id=". $sliver['slice_tag_id'] ."'>Edit</a></td><td><a href='sliver_action.php?rem_id=". $sliver['slice_tag_id'] ."' onclick=\"javascript:return confirm('Are you sure you want to remove ". $sliver['name'] ." from node ". $node_info[0]['hostname'] ."?')\">Remove</a></td>";
100       echo "</tr>\n";
101
102
103     }
104
105     echo "</tbody></table>\n";
106
107   }
108   
109   if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<p><a href='slivers.php?add=$node_id&slice=$slice_id'>Add Sliver Tag</a>\n";
110
111   echo "<br /><hr />";
112
113   // regular tags of slice
114   if( empty( $tag_info ) )
115     // if no tags exist tell user
116     echo "No Tags for this slice.\n";
117   else {
118     echo "<p><table class='list_set' border=0 cellpadding=2>\n<caption class='list_set'>Tags</caption>\n<thead><tr class='list_set'><th class='list_set'>Name</th><th class='list_set'>Value</th><th class='list_set'>Min Roll</th><th class='list_set'>Description</th>";
119     if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<th></th>";
120     echo "</tr></thead><tbody>\n";
121
122     foreach( $tag_info AS $tag ) {
123       echo "<tr><td>". $tag['name'] ."</td><td>". $tag['value'] ."</td><td>". $tag['min_role_id'] ."</td><td>". $tag['description'] ."</td>";
124       if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<td><a href='tags.php?type=slice&id=". $tag['slice_tag_id'] ."'>Edit</a></td>";
125       echo "</tr>\n";
126
127
128     }
129
130     echo "</tbody></table>\n";
131
132   }
133
134
135   echo "<p><a href='index.php?id=$node_id'>Back to Node</a>\n</form>\n";
136
137 }
138
139
140 // Print footer
141 include 'plc_footer.php';
142
143 ?>