resa view uses GET params to select start and duration
[plewww.git] / planetlab / slices / slice.php
1 <?php
2
3 // $Id$
4
5 // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'plc_peers.php';
19 require_once 'plc_objects.php';
20 require_once 'plc_visibletags.php';
21 require_once 'linetabs.php';
22 require_once 'table.php';
23 require_once 'details.php';
24 require_once 'toggle.php';
25 require_once 'form.php';
26 require_once 'raphael.php';
27
28 // keep css separate for now
29 drupal_set_html_head('
30 <link href="/planetlab/css/my_slice.css" rel="stylesheet" type="text/css" />
31 <script src="/planetlab/slices/leases.js" type="text/javascript" charset="utf-8"></script>
32 ');
33
34 // -------------------- admins potentially need to get full list of users
35 ini_set('memory_limit','32M');
36
37 // -------------------- 
38 // recognized URL arguments
39 $slice_id=intval($_GET['id']);
40 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
41
42 ////////////////////
43 // have to name columns b/c we need the non-native 'omf_control' column
44 $slice_columns=array('slice_id','name','peer_id','site_id','person_ids','node_ids','expires',
45                      'url','description','instantiation','omf_control');
46 $slices= $api->GetSlices( array($slice_id), $slice_columns);
47
48 if (empty($slices)) {
49   drupal_set_message ("Slice " . $slice_id . " not found");
50   return;
51  }
52
53 $slice=$slices[0];
54
55 // pull all node info to vars
56 $name= $slice['name'];
57 $expires = date( "d/m/Y", $slice['expires'] );
58 $site_id= $slice['site_id'];
59
60 $person_ids=$slice['person_ids'];
61
62 // get peers
63 $peer_id= $slice['peer_id'];
64 $peers=new Peers ($api);
65 $local_peer = ! $peer_id;
66
67 // gets site info
68 $sites= $api->GetSites( array( $site_id ) );
69 $site=$sites[0];
70 $site_name= $site['name'];
71 $max_slices = $site['max_slices'];
72
73 //////////////////////////////////////// building blocks for the renew area
74 // Constants
75 global $DAY;            $DAY = 24*60*60;
76 global $WEEK;           $WEEK = 7 * $DAY; 
77 global $MAX_WEEKS;      $MAX_WEEKS= 8;          // weeks from today
78 global $GRACE_DAYS;     $GRACE_DAYS=10;         // days for renewal promoted on top
79 global $NOW;            $NOW=mktime();
80
81 ////////////////////////////////////////////////////////////
82 // make the renew area on top and open if the expiration time is less than 10 days from now
83 function renew_needed ($slice) {
84   global $DAY, $NOW, $GRACE_DAYS;
85   $current_exp=$slice['expires'];
86
87   $time_left = $current_exp - $NOW;
88   $visible = $time_left/$DAY <= $GRACE_DAYS;
89   return $visible;
90 }
91
92 function renew_area ($slice,$site,$visible) {
93   global $DAY, $WEEK, $MAX_WEEKS, $GRACE_DAYS, $NOW;
94  
95   $current_exp=$slice['expires'];
96   $current_text = gmstrftime("%A %b-%d-%y %T %Z", $current_exp);
97   $max_exp= $NOW + ($MAX_WEEKS * $WEEK); // seconds since epoch
98   $max_text = gmstrftime("%A %b-%d-%y %T %Z", $max_exp);
99
100   // xxx some extra code needed to enable this area only if the slice description is OK:
101   // description and url must be non void
102   $toggle=
103     new PlekitToggle('renew',"Expires $current_text - Renew this slice",
104                      array("bubble"=>
105                            "Enter this zone if you wish to renew your slice",
106                            'visible'=>$visible));
107   $toggle->start();
108
109   // xxx message could take roles into account
110   if ($site['max_slices']<=0) {
111      $message= <<< EOF
112 <p class='my-slice-renewal'>Slice creation and renewal have been temporarily disabled for your
113 <site. This may have occurred because your site's nodes have been down
114 or unreachable for several weeks, and multiple attempts to contact
115 your site's PI(s) and Technical Contact(s) have all failed. If so,
116 contact your site's PI(s) and Technical Contact(s) and ask them to
117 bring up your site's nodes. Please visit your <a
118 href='/db/sites/index.php?id=$site_id'>site details</a> page to find
119 out more about your site's nodes, and how to contact your site's PI(s)
120 and Technical Contact(s).</p>
121 EOF;
122      echo $message;
123  
124   } else {
125     // xxx this is a rough cut and paste from the former UI
126     // showing a datepicker view could be considered as well with some extra work
127     // calculate possible extension lengths
128     $selectors = array();
129     foreach ( array ( 1 => "One more week", 
130                       2 => "Two more weeks", 
131                       3 => "Three more weeks", 
132                       4 => "One more month" ) as $weeks => $text ) {
133       $candidate_exp = $current_exp + $weeks*$WEEK;
134       if ( $candidate_exp < $max_exp) {
135         $selectors []= array('display'=>"$text (" . gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp) . ")",
136                              'value'=>$candidate_exp);
137         $max_renewal_weeks=$weeks;
138         $max_renewal_date= gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp);
139       }
140     }
141
142     if ( empty( $selectors ) ) {
143       print <<< EOF
144 <div class='my-slice-renewal'>
145 Slices annot be renewed more than $MAX_WEEKS weeks from now, i.e. not beyond $max_text. 
146 For this reason, the current slice cannot be renewed any further into the future, try again closer to expiration date.
147 </div>
148 EOF;
149      } else {
150       print <<< EOF
151 <div class='my-slice-renewal'>
152 <p>You <span class='bold'>must</span> provide a short description, 
153 as well as a link to a project website, before renewing it.
154
155 <br/> Please make sure to provide reasonable details on <span class='bold'>
156 the kind of traffic</span>, and <span class='bold'>copyrights</span> if relevant. 
157 Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against 
158 your slice  and your PlanetLab Operations Center is unable to determine what the normal behavior 
159 of your slice is, your slice may be deleted to resolve the complaint.</p>
160
161 <p><span class='bold'>NOTE:</span> 
162 Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date).
163 </p>
164 </div>
165 EOF;
166
167       $form = new PlekitForm (l_actions(),
168                               array('action'=>'renew-slice',
169                                     'slice_id'=>$slice['slice_id']));
170       $form->start();
171       print $form->label_html('expires','Duration');
172       print $form->select_html('expires',$selectors,array('label'=>'Pick one'));
173       print $form->submit_html('renew-button','Renew');
174       $form->end();
175     }
176   }
177  
178   $toggle->end();
179 }
180
181 ////////////////////////////////////////////////////////////
182
183 $am_in_slice = in_array(plc_my_person_id(),$person_ids);
184
185 if ($am_in_slice) {
186   drupal_set_title("My slice " . $name);
187  } else {
188   drupal_set_title("Slice " . $name);
189 }
190
191 $privileges = ( $local_peer && (plc_is_admin()  || plc_is_pi() || $am_in_slice));
192 $tags_privileges = $privileges || plc_is_admin();
193
194 $tabs=array();
195 $tabs [] = tab_nodes_slice($slice_id);
196 $tabs [] = tab_site($site_id);
197
198 // are these the right privileges for deletion ?
199 if ($privileges) {
200   $tabs ['Delete']= array('url'=>l_actions(),
201                           'method'=>'post',
202                           'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id),
203                           'bubble'=>"Delete slice $name",
204                           'confirm'=>"Are you sure to delete slice $name");
205
206   $tabs["Events"]=array_merge(tablook_event(),
207                               array('url'=>l_event("Slice","slice",$slice_id),
208                                     'bubble'=>"Events for slice $name"));
209   $tabs["Comon"]=array_merge(tablook_comon(),
210                              array('url'=>l_comon("slice_id",$slice_id),
211                                    'bubble'=>"Comon page about slice $name"));
212 }
213
214 plekit_linetabs($tabs);
215
216 ////////////////////////////////////////
217 $peers->block_start($peer_id);
218
219 //////////////////////////////////////// renewal area 
220 // (1) close to expiration : show on top and open
221
222 if ($local_peer ) {
223   $renew_visible = renew_needed ($slice);
224   if ($renew_visible) renew_area ($slice,$site,true);
225  }
226
227
228 //////////////////// details
229 // default for opening the details section or not ?
230 if ($local_peer) {
231   $default_show_details = true;
232  } else {
233   $default_show_details = ! $renew_visible;
234  }
235   
236 $toggle = 
237   new PlekitToggle ('my-slice-details',"Details",
238                     array('bubble'=>
239                           'Display and modify details for that slice',
240                           'visible'=>get_arg('show_details',$default_show_details)));
241 $toggle->start();
242
243 $details=new PlekitDetails($privileges);
244 $details->form_start(l_actions(),array('action'=>'update-slice',
245                                        'slice_id'=>$slice_id,
246                                        'name'=>$name));
247
248 $details->start();
249 if (! $local_peer) {
250   $details->th_td("Peer",$peers->peer_link($peer_id));
251   $details->space();
252  }
253
254
255 $details->th_td('Name',$slice['name']);
256 $details->th_td('Description',$slice['description'],'description',
257                 array('input_type'=>'textarea',
258                       'width'=>50,'height'=>5));
259 $details->th_td('URL',$slice['url'],'url',array('width'=>50));
260 $details->tr_submit("submit","Update Slice");
261 $details->th_td('Expires',$expires);
262 $details->th_td('Instantiation',$slice['instantiation']);
263 $details->th_td("OMF-friendly", ($slice['omf_control'] ? 'Yes' : 'No') . " [to change: see 'omf_control' in the tags section below]");
264 $details->th_td('Site',l_site_obj($site));
265 // xxx show the PIs here
266 //$details->th_td('PIs',...);
267 $details->end();
268
269 $details->form_end();
270 $toggle->end();
271
272 //////////////////// persons
273 $person_columns = array('email','person_id','first_name','last_name','roles');
274 // get persons in slice
275 if (!empty($person_ids))
276   $persons=$api->GetPersons(array('person_id'=>$slice['person_ids']),$person_columns);
277 // just propose to add everyone else
278 // xxx this is maybe too much for admins as it slows stuff down 
279 // as regular persons can see only a fraction of the db anyway
280 $potential_persons=
281   $api->GetPersons(array('~person_id'=>$slice['person_ids'],
282                          'peer_id'=>NULL,
283                          'enabled'=>true),
284                    $person_columns);
285 $count=count($persons);
286
287 $toggle=
288   new PlekitToggle ('my-slice-persons',"$count Users",
289                     array('bubble'=>
290                           'Manage accounts attached to this slice',
291                           'visible'=>get_arg('show_persons',false)));
292 $toggle->start();
293
294 ////////// people currently in
295 // visible:
296 // hide if both current+add are included
297 // so user can chose which section is of interest
298 // show otherwise
299 $toggle_persons = new PlekitToggle ('my-slice-persons-current',
300                                     "$count people currently in $name",
301                                     array('visible'=>get_arg('show_persons_current',!$privileges)));
302 $toggle_persons->start();
303
304 $headers=array();
305 $headers['email']='string';
306 $headers['first']='string';
307 $headers['last']='string';
308 $headers['R']='string';
309 if ($privileges) $headers[plc_delete_icon()]="none";
310 $table=new PlekitTable('persons',$headers,'0',
311                        array('notes_area'=>false));
312 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
313 $form->start();
314 $table->start();
315 if ($persons) foreach ($persons as $person) {
316   $table->row_start();
317   $table->cell(l_person_obj($person));
318   $table->cell($person['first_name']);
319   $table->cell($person['last_name']);
320   $table->cell(plc_vertical_table ($person['roles']));
321   if ($privileges) $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
322   $table->row_end();
323 }
324 // actions area
325 if ($privileges) {
326
327   // remove persons
328   $table->tfoot_start();
329
330   $table->row_start();
331   $table->cell($form->submit_html ("remove-persons-from-slice","Remove selected"),
332                array('hfill'=>true,'align'=>'right'));
333   $table->row_end();
334  }
335 $table->end();
336 $toggle_persons->end();
337
338 ////////// people to add
339 if ($privileges) {
340   $count=count($potential_persons);
341   $toggle_persons = new PlekitToggle ('my-slice-persons-add',
342                                       "$count people may be added to $name",
343                                       array('visible'=>get_arg('show_persons_add',false)));
344   $toggle_persons->start();
345   if ( ! $potential_persons ) {
346     // xxx improve style
347     echo "<p class='not-relevant'>No person to add</p>";
348   } else {
349     $headers=array();
350     $headers['email']='string';
351     $headers['first']='string';
352     $headers['last']='string';
353     $headers['R']='string';
354     $headers['+']="none";
355     $options = array('notes_area'=>false,
356                      'search_width'=>15,
357                      'pagesize'=>8);
358     // show search for admins only as other people won't get that many names to add
359     if ( ! plc_is_admin() ) $options['search_area']=false;
360     
361     $table=new PlekitTable('add_persons',$headers,'0',$options);
362     $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
363     $form->start();
364     $table->start();
365     if ($potential_persons) foreach ($potential_persons as $person) {
366         $table->row_start();
367         $table->cell(l_person_obj($person));
368         $table->cell($person['first_name']);
369         $table->cell($person['last_name']);
370         $table->cell(plc_vertical_table ($person['roles']));
371         $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
372         $table->row_end();
373       }
374     // add users
375     $table->tfoot_start();
376     $table->row_start();
377     $table->cell($form->submit_html ("add-persons-in-slice","Add selected"),
378                  array('hfill'=>true,'align'=>'right'));
379     $table->row_end();
380     $table->end();
381     $form->end();
382   }
383   $toggle_persons->end();
384 }
385 $toggle->end();
386
387 //////////////////////////////////////////////////////////// Nodes
388 // the nodes details to display here
389 // (1) we search for the tag types for which 'category' matches 'node*/ui*'
390 // all these tags will then be tentatively displayed in this area
391 // (2) further information can also be optionally specified in the category:
392 //     (.) we split the category with '/' and search for assignments of the form var=value
393 //     (.) header can be set to supersede the column header (default is tagname)
394 //     (.) rank can be used for ordering the columns (default is tagname)
395 //     (.) type is passed to the javascript table, for sorting (default is 'string')
396
397 // minimal list as a start
398 $node_fixed_columns = array('hostname','node_id','peer_id','slice_ids_whitelist',
399                             'run_level','boot_state','last_contact','node_type');
400 // create a VisibleTags object : basically the list of tag columns to show
401 $visibletags = new VisibleTags ($api, 'node');
402 $visiblecolumns = $visibletags->column_names();
403 $node_columns=array_merge($node_fixed_columns,$visiblecolumns);
404 $nodes=$api->GetNodes(array('node_id'=>$slice['node_ids']),$node_columns);
405 $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),$node_columns);
406 // reservable nodes: display only the ones in the slice to avoid confusion - also avoid an extra API call
407 $reservable_nodes=array();
408 foreach ($nodes as $node) { if ($node['node_type']=='reservable') $reservable_nodes[]=$node; }
409
410 $reservable_mark="-R-";
411 $reservable_legend="reservable nodes are marked with " . $reservable_mark;
412
413 ////////////////////
414 // outline the number of reservable nodes
415 $nodes_message=count_english($nodes,"node");
416 if (count($reservable_nodes)) $nodes_message .= " (" . count($reservable_nodes) . " reservable)";
417 $toggle=new PlekitToggle ('my-slice-nodes',$nodes_message,
418                           array('bubble'=>
419                                 'Manage nodes attached to this slice',
420                                 'visible'=>get_arg('show_nodes',false)));
421 $toggle->start();
422
423 //////////////////// nodes currently in
424 $toggle_nodes=new PlekitToggle('my-slice-nodes-current',
425                                count_english($nodes,"node") . " currently in $name",
426                                array('visible'=>get_arg('show_nodes_current',!$privileges)));
427 $toggle_nodes->start();
428
429 $headers=array();
430 $notes=array();
431 $headers['peer']='string';
432 $headers['hostname']='string';
433 $short="ST"; $long=Node::status_footnote(); $type='string'; 
434         $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
435 $short="R"; $long=$reservable_legend; $type='string';
436         $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
437 // the extra tags, configured for the UI
438 $headers=array_merge($headers,$visibletags->headers());
439 $notes=array_merge($notes,$visibletags->notes());
440
441 if ($privileges) $headers[plc_delete_icon()]="none";
442
443 $table_options = array('notes'=>$notes,
444                        'search_width'=>15,
445                        'pagesize'=>20);
446 $table=new PlekitTable('nodes',$headers,'1',$table_options);
447
448 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
449 $form->start();
450 $table->start();
451 if ($nodes) foreach ($nodes as $node) {
452   $table->row_start();
453   $peers->cell($table,$node['peer_id']);
454   $table->cell(l_node_obj($node));
455   $run_level=$node['run_level'];
456   list($label,$class) = Node::status_label_class_($node);
457   $table->cell ($label,array('class'=>$class));
458   $table->cell( ($node['node_type']=='reservable')?$reservable_mark:"" );
459   foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
460
461   if ($privileges) $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
462   $table->row_end();
463 }
464 // actions area
465 if ($privileges) {
466
467   // remove nodes
468   $table->tfoot_start();
469
470   $table->row_start();
471   $table->cell($form->submit_html ("remove-nodes-from-slice","Remove selected"),
472                array('hfill'=>true,'align'=>'right'));
473   $table->row_end();
474  }
475 $table->end();
476 $toggle_nodes->end();
477
478 //////////////////// nodes to add
479 if ($privileges) {
480   $new_potential_nodes = array();
481   if ($potential_nodes) foreach ($potential_nodes as $node) {
482       $emptywl=empty($node['slice_ids_whitelist']);
483       $inwl = (!emptywl) and in_array($slice['slice_id'],$node['slice_ids_whitelist']);
484       if ($emptywl or $inwl)
485         $new_potential_nodes[]=$node;
486   }
487   $potential_nodes=$new_potential_nodes;
488
489   $count=count($potential_nodes);
490   $toggle_nodes=new PlekitToggle('my-slice-nodes-add',
491                                  count_english($potential_nodes,"more node") . " available",
492                                  array('visible'=>get_arg('show_nodes_add',false)));
493   $toggle_nodes->start();
494
495   if ( $potential_nodes ) {
496     $headers=array();
497     $notes=array();
498     $headers['peer']='string';
499     $headers['hostname']='string';
500     $short="ST"; $long=Node::status_footnote(); $type='string'; 
501         $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
502     $short="R"; $long=$reservable_legend; $type='string';
503         $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
504     // the extra tags, configured for the UI
505     $headers=array_merge($headers,$visibletags->headers());
506     $notes=array_merge($notes,$visibletags->notes());
507     $headers['+']="none";
508     
509     $table=new PlekitTable('add_nodes',$headers,'1', $table_options);
510     $form=new PlekitForm(l_actions(),
511                          array('slice_id'=>$slice['slice_id']));
512     $form->start();
513     $table->start();
514     if ($potential_nodes) foreach ($potential_nodes as $node) {
515         $table->row_start();
516         $peers->cell($table,$node['peer_id']);
517         $table->cell(l_node_obj($node));
518         list($label,$class) = Node::status_label_class_($node);
519         $table->cell ($label,array('class'=>$class));
520         $table->cell( ($node['node_type']=='reservable')?$reservable_mark:"" );
521         foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
522         $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
523         $table->row_end();
524       }
525     // add nodes
526     $table->tfoot_start();
527     $table->row_start();
528     $table->cell($form->submit_html ("add-nodes-in-slice","Add selected"),
529                  array('hfill'=>true,'align'=>'right'));
530     $table->row_end();
531     $table->end();
532     $form->end();
533   }
534   $toggle_nodes->end();
535 }
536
537 //////////////////// reservable nodes area
538 $count=count($reservable_nodes);
539 if ($count && $privileges) {
540   // having reservable nodes in white lists looks a bit off scope for now...
541   $toggle_nodes=new PlekitToggle('my-slice-nodes-reserve',
542                                  count_english($reservable_nodes,"reservable node") . " in slice",
543                                  array('visible'=>get_arg('show_nodes_resa',false)));
544   $toggle_nodes->start();
545   $grain=$api->GetLeaseGranularity();
546   // where to start from, expressed as an offset in hours from now
547   $resa_offset=$_GET['resa_offset'];
548   if ( ! $resa_offset ) $resa_offset=0;
549   $rough_start=time()+$resa_offset*3600;
550   // xxx should be configurable
551   $resa_slots=$_GET['resa_slots'];
552   if ( ! $resa_slots ) $resa_slots = 36;
553   // for now, show the next 72 hours, or 72 grains, which ever is smaller
554   $duration=$resa_slots*$grain;
555   $steps=$duration/$grain;
556   $start=intval($rough_start/$grain)*$grain;
557   $end=$rough_start+$duration;
558   $lease_columns=array('lease_id','name','t_from','t_until','hostname','name');
559   $leases=$api->GetLeases(array(']t_until'=>$rough_start,'[t_from'=>$end,'-SORT'=>'t_from'),$lease_columns);
560   // hash nodes -> leases
561   $host_hash=array();
562   foreach ($leases as $lease) {
563     $hostname=$lease['hostname'];
564     if ( ! $host_hash[$hostname] ) {
565         $host_hash[$hostname]=array();
566     }
567     // resync within the table
568     $lease['nfrom']=($lease['t_from']-$start)/$grain;
569     $lease['nuntil']=($lease['t_until']-$start)/$grain;
570     $host_hash[$hostname] []= $lease;
571   }
572   # leases_data is the name used by leases.js to locate this table
573   echo "<table id='leases_data'>";
574   # pass (slice_id,slicename) as the [0,0] coordinate as thead>tr>td
575   echo "<thead><tr><td>" . $slice['slice_id'] . '&' . $slice['name'] . "</td>";
576   # the timeslot headers read (timestamp,label)
577   $day_names=array('Su','M','Tu','W','Th','F','Sa');
578   for ($i=0; $i<$steps; $i++) {
579     $timestamp=($start+$i*$grain);
580     $day=$day_names[intval(strftime("%w",$timestamp))];
581     $label=$day . strftime(" %H:%M",$timestamp);
582     // expose in each header cell the full timestamp, and how to display it - use & as a separator*/
583     echo "<th>" . implode("&",array($timestamp,$label)) . "</th>";
584   }
585   echo "</tr></thead><tbody>";
586   // todo - sort on hostnames
587   function sort_hostname ($a,$b) { return ($a['hostname']<$b['hostname'])?-1:1;}
588   usort($reservable_nodes,sort_hostname);
589   foreach ($reservable_nodes as $node) {
590     echo "<tr><th scope='row'>". $node['hostname'] . "</th>";
591     $hostname=$node['hostname'];
592     $leases=$host_hash[$hostname];
593     $counter=0;
594     while ($counter<$steps) {
595       if ($leases && ($leases[0]['nfrom']<=$counter)) {
596         $lease=array_shift($leases);
597         /* nicer display, merge two consecutive leases for the same slice 
598            avoid doing that for now, as it might makes things confusing */
599         /* while ($leases && ($leases[0]['name']==$lease['name']) && ($leases[0]['nfrom']==$lease['nuntil'])) {
600           $lease['nuntil']=$leases[0]['nuntil'];
601           array_shift($leases);
602           }*/
603         $duration=$lease['nuntil']-$counter;
604         echo "<td colspan='$duration'>" . $lease['lease_id'] . '&' . $lease['name'] . "</td>";
605         $counter=$lease['nuntil']; 
606       } else {
607         echo "<td></td>";
608         $counter+=1;
609       }
610     }
611     echo "</tr>";
612   }
613   echo "</tbody></table>\n";
614
615   // the general layout for the scheduler
616   echo <<< EOF
617 <div id='leases_area'></div>
618
619 <div id='leases_buttons'>
620   <button id='leases_clear' type='submit'>Clear</button>
621   <button id='leases_submit' type='submit'>Submit</button>
622 </div>
623 EOF;
624
625   $toggle_nodes->end();
626  }
627 $toggle->end();
628
629 //////////////////////////////////////////////////////////// Tags
630 //if ( $local_peer ) {
631   $tags=$api->GetSliceTags (array('slice_id'=>$slice_id));
632   function get_tagname ($tag) { return $tag['tagname'];}
633   $tagnames = array_map ("get_tagname",$tags);
634   
635   $toggle = new PlekitToggle ('slice-tags',count_english_warning($tags,'tag'),
636                               array('bubble'=>'Inspect and set tags on tat slice',
637                                     'visible'=>get_arg('show_tags',false)));
638   $toggle->start();
639   
640   $headers=array(
641     "Name"=>"string",
642     "Value"=>"string",
643     "Node"=>"string",
644     "NodeGroup"=>"string");
645   if ($tags_privileges) $headers[plc_delete_icon()]="none";
646   
647   $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
648   $table=new PlekitTable("slice_tags",$headers,'0',$table_options);
649   $form=new PlekitForm(l_actions(),
650                        array('slice_id'=>$slice['slice_id']));
651   $form->start();
652   $table->start();
653   if ($tags) {
654     foreach ($tags as $tag) {
655       $node_name = "ALL";
656       if ($tag['node_id']) {
657         $nodes = $api->GetNodes(array('node_id'=>$tag['node_id']));
658         if($nodes) {
659           $node = $nodes[0];
660           $node_name = $node['hostname'];
661         }
662       }
663       $nodegroup_name="n/a";
664       if ($tag['nodegroup_id']) { 
665         $nodegroup=$api->GetNodeGroups(array('nodegroup_id'=>$tag['nodegroup_id']));
666         if ($nodegroup) {
667           $nodegroup = $nodegroup[0];
668           $nodegroup_name = $nodegroup['groupname'];
669         }
670       }
671       $table->row_start();
672       $table->cell(l_tag_obj($tag));
673       $table->cell($tag['value']);
674       $table->cell($node_name);
675       $table->cell($nodegroup_name);
676       if ($tags_privileges) $table->cell ($form->checkbox_html('slice_tag_ids[]',$tag['slice_tag_id']));
677       $table->row_end();
678     }
679   }
680   if ($tags_privileges) {
681     $table->tfoot_start();
682     $table->row_start();
683     $table->cell($form->submit_html ("delete-slice-tags","Remove selected"),
684                  array('hfill'=>true,'align'=>'right'));
685     $table->row_end();
686     
687     $table->row_start();
688     function tag_selector ($tag) {
689       return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']);
690     }
691     $all_tags= $api->GetTagTypes( array ("category"=>"slice*","-SORT"=>"+tagname"), array("tagname","tag_type_id"));
692     $selector_tag=array_map("tag_selector",$all_tags);
693     
694     function node_selector($node) { 
695       return array("display"=>$node["hostname"],"value"=>$node['node_id']);
696     }
697     $all_nodes = $api->GetNodes( array ("node_id" => $slice['node_ids']), array("hostname","node_id"));
698     $selector_node=array_map("node_selector",$all_nodes);
699     
700     function nodegroup_selector($ng) {
701       return array("display"=>$ng["groupname"],"value"=>$ng['nodegroup_id']);
702     }
703     $all_nodegroups = $api->GetNodeGroups( array("groupname"=>"*"), array("groupname","nodegroup_id"));
704     $selector_nodegroup=array_map("nodegroup_selector",$all_nodegroups);
705     
706     $table->cell($form->select_html("tag_type_id",$selector_tag,array('label'=>"Choose Tag")));
707     $table->cell($form->text_html("value","",array('width'=>8)));
708     $table->cell($form->select_html("node_id",$selector_node,array('label'=>"All Nodes")));
709     $table->cell($form->select_html("nodegroup_id",$selector_nodegroup,array('label'=>"No Nodegroup")));
710     $table->cell($form->submit_html("add-slice-tag","Set Tag"),array('columns'=>2,'align'=>'left'));
711     $table->row_end();
712   }
713     
714   $table->end();
715   $form->end();
716   $toggle->end();
717 //}
718
719
720 //////////////////////// renew slice
721 if ($local_peer ) {
722   if ( ! $renew_visible) renew_area ($slice,$site,false);
723  }
724
725 $peers->block_end($peer_id);
726
727 // Print footer
728 include 'plc_footer.php';
729
730 ?>