6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'details.php';
22 require_once 'toggle.php';
24 // --------------------
25 // recognized URL arguments
26 $slice_id=intval($_GET['id']);
27 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
29 function renew_area ($slice,$site) {
32 $week= 7 * 24 * 60 * 60; // seconds
33 $max_renewal_length= 8; // weeks from today
34 $max_expiration= mktime() + ($max_renewal_length * $week); // seconds since epoch
35 $max_expiration_date= gmstrftime("%A %b-%d-%y %T %Z", $max_expiration);
38 // xxx some extra code needed to enable this area only if the slice description is OK:
39 // description and url must be non void
40 $toggle=new PlekitToggle('renew',"Renew this slice",
41 array("trigger-bubble"=>"Enter this zone if you wish to renew your slice",
42 'start-visible'=>true));
45 // xxx message could take roles into account
46 if ($site['max_slices']<=0) {
48 <p>Slice creation and renewal have been temporarily disabled for your
49 site. This may have occurred because your site's nodes have been down
50 or unreachable for several weeks, and multiple attempts to contact
51 your site's PI(s) and Technical Contact(s) have all failed. If so,
52 contact your site's PI(s) and Technical Contact(s) and ask them to
53 bring up your site's nodes. Please visit your <a
54 href='/db/sites/index.php?id=$site_id'>site details</a> page to find
55 out more about your site's nodes, and how to contact your site's PI(s)
56 and Technical Contact(s).</p>
61 // xxx this is a rough cut and paste from the former UI
62 // Showing a datepicker view could be considered as well with some extra work
63 // Calculate possible extension lengths
64 $renewal_lengths = array();
65 foreach ( array ( 1 => "One more week",
66 2 => "Two more weeks",
67 4 => "One more month" ) as $weeks => $text ) {
68 if (($slice [ 'expires' ] + ($weeks * $week)) < $max_expiration) {
69 $renewal_lengths [ $weeks ] = "$text (" .
70 gmstrftime( "%A %b-%d-%y %T %Z", $slice [ 'expires' ] + ( $weeks * $week ) )
75 if ( empty( $renewal_lengths ) ) {
76 plc_warning("Slice cannot be renewed any further into the future, try again closer to expiration date.");
79 $expiration_date = gmstrftime( "%A %b-%d-%y %T %Z", $slice [ 'expires' ] );
80 echo '<p> area under construction </a>';
83 // echo "<form action='/db/slices/renew_slice.php' method='post'>\n";
84 // echo "<input type=hidden name='id' value='$slice_id'><input type=hidden name='expires' value='". $slice['expires'] ."'>\n";
87 // <p>You must provide a short description as well as a link to a project website before renewing it.
88 // Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against your slice
89 // and PlanetLab Operations is unable to determine what the normal behavior of your slice is,
90 // your slice may be deleted to resolve the complaint.</p>
94 // echo "<p><span class='bold'>NOTE:</span>
95 // Slices cannot be renewed beyond $max_renewal_length weeks of today ($max_expiration_date).</p>\n";
97 // echo "<table cellpadding=2><tbody>\n";
99 // echo "<tr><th>Name:</th><td colspan=2>". $slice['name'] ."</td></tr>\n";
101 // if( $error['url'] )
102 // $url_style= " style='border: 1px solid red;'";
103 // echo "<tr><th$url_style>URL: </th><td$url_style><input size=50 name='url' value='". $slice['url'] ."' /></td><td$url_style><font color=red>". $error['url'] ."</font></td></tr>\n";
105 // if( $error['description'] )
106 // $desc_style= " style='border: 1px solid red;'";
107 // echo "<tr><th$desc_style>Description: </th><td$desc_style><textarea name='description' rows=5 cols=40>". $slice['description'] ."</textarea></td><td$desc_style><font color=red>". $error['description'] ."</font></td></tr>\n";
109 // echo "<tr><th>Expiration Date: </th><td colspan=2>$expiration_date</td></tr>\n";
111 // echo "<tr><th>Renewal Length: </th><td colspan=2><select name='expire_len'>";
113 // // create drop down of lengths to choose
114 // foreach ($renewal_lengths as $weeks => $text) {
115 // echo "<option value='$weeks'";
116 // if( $weeks == $expire_len )
118 // echo ">$text</option>\n";
121 // echo "</select></td></tr>\n<tr><td colspan=3 align=center><input type=submit value='Renew Slice' name='submitted'></td></tr>\n</tbody></table>\n";
131 // Get all columns as we focus on only one entry
132 $slices= $api->GetSlices( array($slice_id));
134 if (empty($slices)) {
135 drupal_set_message ("Slice " . $slice_id . " not found");
141 // pull all node info to vars
142 $name= $slice['name'];
143 $expires = date( "d/m/Y", $slice['expires'] );
144 $site_id= $slice['site_id'];
146 //$node_ids=$slice['node_ids'];
147 $person_ids=$slice['person_ids'];
148 //$slice_tag_ids= $slice['slice_tag_ids'];
151 $peer_id= $slice['peer_id'];
152 $peers=new Peers ($api);
155 $sites= $api->GetSites( array( $site_id ) );
157 $site_name= $site['name'];
158 $max_slices = $site['max_slices'];
160 // get all persons info
161 if (!empty($person_ids))
162 $persons=$api->GetPersons($person_ids,array('email','enabled'));
165 drupal_set_title("Details for slice " . $name);
166 $local_peer= ! $peer_id;
168 $am_in_slice = in_array(plc_my_person_id(),$person_ids);
170 $privileges = (plc_is_admin() || $am_in_slice);
173 $tabs [] = tab_nodes_slice($slice_id);
174 $tabs [] = tab_site($site_id);
176 // are these the right privileges for deletion ?
178 $tabs ['Delete']= array('url'=>l_actions(),
180 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id),
181 'bubble'=>"Delete slice $name",
182 'confirm'=>'Are you sure to delete $name');
184 $tabs["Events"]=array_merge(tablook_event(),
185 array('url'=>l_event("Slice","slice",$slice_id),
186 'bubble'=>"Events for slice $name"));
187 $tabs["Comon"]=array_merge(tablook_comon(),
188 array('url'=>l_comon("slice_id",$slice_id),
189 'bubble'=>"Comon page about slice $name"));
192 plekit_linetabs($tabs);
194 ////////////////////////////////////////
195 $peers->block_start($peer_id);
197 $toggle = new PlekitToggle ('slice',"Details",
198 array('trigger-bubble'=>'Display and modify details for that slice'));
201 $details=new PlekitDetails($privileges);
202 $details->form_start(l_actions(),array('action'=>'update-slice','slice_id'=>$slice_id));
206 $details->th_td("Peer",$peers->peer_link($peer_id));
211 $details->th_td('Name',$slice['name']);
212 $details->th_td('Description',$slice['description'],'description',
213 array('input_type'=>'textarea',
214 'width'=>50,'height'=>5));
215 $details->th_td('URL',$slice['url'],'url',array('width'=>50));
216 $details->th_td('Expires',$expires);
217 $details->th_td('Instantiation',$slice['instantiation']);
218 $details->th_td('Site',l_site_obj($site));
221 $details->form_end();
224 renew_area ($slice,$site);
226 $peers->block_end($peer_id);
228 //////////////////// users
230 //////////////////// nodes
232 //////////////////// tags
235 include 'plc_footer.php';
254 // gets all persons from site_id
256 if( !empty( $person_ids ) )
257 $persons= $api->GetPersons( $site_info[0]['person_ids'] , array( "person_id", "role_ids", "first_name", "last_name", "email" ) );
260 // gets site contacts pis stores in dict
261 foreach( $persons as $person )
262 if( in_array( "20", $person['role_ids'] ) ) {
263 $pis[]= array( "email" => $person['email'], "first_name" => $person['first_name'], "last_name" => $person['last_name'], "person_id" => $person['person_id'] );
267 sort_persons( $pis );
272 if( !empty( $slice_tag_ids ) )
273 $slice_attibs= $api->GetSliceTags( $slice_tag_ids,
274 array( "slice_tag_id", "tag_type_id", "value", "description", "min_role_id", "node_id" ) );
276 // gets tag type info and combines it to form all tag info array
277 if( $slice_attibs ) {
278 foreach( $slice_attibs as $slice_attib ) {
279 $tag_type= $api->GetTagTypes( array( $slice_attib['tag_type_id'] ),
280 array( "tag_type_id", "tagname", "description" ) );
282 $tags[]= array( "slice_tag_id" => $slice_attib['slice_tag_id'],
283 "tag_type_id" => $slice_attib['tag_type_id'],
284 "tagname" => $tag_type[0]['tagname'],
285 "value" => $slice_attib['value'],
286 "description" => $slice_attib['description'],
287 "min_role_id" => $slice_attib['min_role_id'],
288 "node_id" => $slice_attib['node_id'] );
293 drupal_set_title("Slice details for " . $name);
297 echo "<div class='plc-foreign'>\n";
303 $actions= array( ''=>'Choose Action' );
305 if( in_array( 10, $_roles )
306 || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) )
307 || in_array( $slice_id, $_person['slice_ids'] ) ) {
308 $actions['renew']= "Renew $name";
309 $actions['nodes']= "Manage Nodes";
311 if ( in_array( 10, $_roles )
312 || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) {
313 $actions['users']= "Manage Users";
314 $actions['delete']= "Delete $name";
317 echo "<table><tr><td>\n";
318 if (in_array( 10, $_roles )) {
319 echo plc_event_button("slices","slice",$slice_id);
322 echo plc_comon_button("slice_id",$slice_id);
325 echo "<form action='/db/slices/slice_action.php' method='post'>\n";
326 echo "<input type=hidden name=slice_id value=$slice_id>\n";
328 echo "<select name='actions' onChange=\"submit();\">\n";
329 foreach( $actions as $key => $val ) {
330 echo "<option value='$key'";
332 if( $key == $_POST['actions'] )
338 echo "</select><br />\n";
341 echo "</td></tr></table>\n";
344 echo "<table cellpadding=3><tbody>\n
345 <tr><th>Slice Name: </th><td> $name </td></tr>\n
346 <tr><th>Description: </th><td> $description </td></tr>\n
347 <tr><th>URL: </th><td> <a href='$url'>$url</a> </td></tr>\n";
349 if( gmmktime() > $slice['expires'] ) {
350 $class1= ' style="color:red;"';
351 $msg1= '(slice is expired)';
353 echo "<tr><th$class1>Expiration: </th><td$class1> $expires $msg1</td></tr>\n";
354 echo "<tr><th>Instantiation: </th><td><select name='instantiation' onChange=\"submit();\"\n";
355 echo "<option value='delegated'";
356 if( $instantiation == 'delegated' ) echo " selected";
357 echo ">delegated</option>";
358 echo "<option value='plc-instantiated'";
359 if( $instantiation == 'plc-instantiated' ) echo " selected";
360 echo ">plc-instantiated</option>";
361 echo "<option value='not-instantiated'";
362 if( $instantiation == 'not-instantiated' ) echo " selected";
363 echo ">not-instantiated</option>";
367 echo "<tr><th>Site: </th><td> <a href='/db/sites/index.php?id=$site_id'>". $site_info[0]['name'] ."</a></td></tr>\n";
368 $href="'/db/nodes/index.php?slice_id=" . $slice_id . "'";
369 printf ("<tr><th> <a href=%s># Nodes</a></th><td><a href=%s>Total %d nodes</a></td>\n",$href,$href,count($node_ids));
370 $href="'/db/persons/index.php?slice_id=" . $slice_id . "'";
371 printf ("<tr><th> <a href=%s># Users</a></th><td><a href=%s>Total %d users</a></td>\n",$href,$href,count($person_ids));
372 echo "</tbody></table>\n";
374 if ( (!$class1) && in_array( $slice_id, $_person['slice_ids'] ) && (! $peer_id) )
375 echo "<p><a href='update_slice.php?id=$slice_id'>Update Information</a>\n";
377 echo "<br /><hr />\n";
383 // builds 2 arrays, one for tags, one for slivers
384 foreach( $tags as $tag ) {
385 if( empty( $tag['node_id'] ) ) {
390 $sliver_nodes[]= $tag['node_id'];
395 // Get node info for those slivers
396 $sliver_node_info= $api->GetNodes( $sliver_nodes, array( "node_id", "hostname" ) );
398 if( $sliver_node_info ) {
399 foreach( $sliver_node_info as $sliv_node ) {
400 $new_sliver_node_info[$sliv_node['node_id']]= $sliv_node;
405 echo "<br /></div>\n";
409 $is_admin=in_array( 10, $_roles );
410 $is_in_slice=in_array( $slice_id, $_person['slice_ids'] );
411 $is_pi=in_array( 20, $_roles );
413 echo "<table cellpadding=3><caption class='list_set'>Slice Tags</caption>";
417 echo "<th>Tag</th><th>Value</th><th>Description</th>";
418 echo "</tr></thead><tbody>\n";
420 foreach( $tags as $tag ) {
421 // ignore sliver tags at this stage
422 if( empty( $tag['node_id'] ) ) {
426 sprintf($label,"\\n [ %s = %s] \\n from %s",$tag['tagname'],$tag['value'],$name);
427 // xxx this is deprecated
428 echo plc_delete_link_button ('tag_action.php?rem_id=' . $tag['slice_tag_id'],
432 if( $is_admin || ($is_pi && $is_in_slice) ) {
433 printf ("<td><a href='tags.php?type=slice?id=%s'>%s</a></td>",
434 $tag['slice_tag_id'],$tag['tagname']);
436 printf("<td>%s</td>",$tag['tagname']);
438 printf("<td align=center>%s</td><td>%s</td>",
439 $tag['value'],$tag['description']);
445 echo "</tbody></table>\n";
448 if( $is_admin || ($is_pi && $is_in_slice) )
449 echo "<a href='tags.php?type=slice&add=$slice_id'>Add a Slice Tag</a>\n";
455 echo "<table cellpadding=3><caption class='list_set'>Sliver Tags</caption>";
459 echo "<th>Tag</th><th>Value</th><th>Description</th><th>Node</th>";
460 echo "</tr></thead><tbody>\n";
462 foreach( $tags as $tag ) {
463 $nodename=$new_sliver_node_info[$tag['node_id']]['hostname'];
464 // consider only sliver tags at this stage
465 if( !empty( $tag['node_id'] ) ) {
469 $label=sprintf("\\n [ %s = %s ] \\n from %s \\n on node %s",
470 $tag['tagname'],$tag['value'],$name,$nodename);
471 echo plc_delete_link_label('/db/nodes/sliver_action.php?rem_id=' . $tag['slice_tag_id'],
476 printf("<td><a href='tags.php?type=slice&id=%s'>%s</a></td>",$tag['slice_tag_id'],$tag['tagname']);
478 printf("<td>%s</td>",$tag['tagname']);
480 printf("<td align=center>%s</td><td>%s</td><td><a href='/db/nodes/index.php?id=%s'>%s</a></td>",
481 $tag['value'],$tag['description'],$tag['node_id'],$nodename);
487 echo "</tbody></table>\n";
491 echo "<br /><hr />\n";
493 if( $pis && !$peer_id ) {
495 echo "<h5>Contacts</h5>\n";
497 $pi_rows= count( $pis );
498 $tech_rows= count( $techs );
501 echo "<table cellpadding=2><tbody>";
503 echo "<tr><td rowspan=$pi_rows><strong>PI's:</strong> </td>\n";
505 foreach( $pis as $pi ) {
506 if( $table_row != 0 )
508 printf("<td><a href='/db/persons/index.php?id=%s'>%s %s</td><td><a href='mailto:%s'>%s</a></td></tr>\n",
509 $pi['person_id'],$pi['first_name'],$pi['last_name'],$pi['email'],$pi['email']);
515 echo "</table>\n<br /><hr />\n";
520 echo "<p><a href='index.php'>Back to slice list</a></div>\n";