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