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';
23 require_once 'form.php';
25 // -------------------- admins potentially need to get full list of users
26 ini_set('memory_limit','32M');
28 // --------------------
29 // recognized URL arguments
30 $slice_id=intval($_GET['id']);
31 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
34 // Get all columns as we focus on only one entry
35 $slices= $api->GetSlices( array($slice_id));
38 drupal_set_message ("Slice " . $slice_id . " not found");
44 // pull all node info to vars
45 $name= $slice['name'];
46 $expires = date( "d/m/Y", $slice['expires'] );
47 $site_id= $slice['site_id'];
49 //$node_ids=$slice['node_ids'];
50 $person_ids=$slice['person_ids'];
51 //$slice_tag_ids= $slice['slice_tag_ids'];
54 $peer_id= $slice['peer_id'];
55 $peers=new Peers ($api);
56 $local_peer = ! $peer_id;
59 $sites= $api->GetSites( array( $site_id ) );
61 $site_name= $site['name'];
62 $max_slices = $site['max_slices'];
64 //$pis=$api->GetPersons(...)
66 // get all persons info
67 if (!empty($person_ids))
68 $persons=$api->GetPersons($person_ids,array('email','enabled'));
71 //////////////////////////////////////// building blocks for the renew area
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();
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'];
85 $time_left = $current_exp - $NOW;
86 $visible = $time_left/$DAY <= $GRACE_DAYS;
90 function renew_area ($slice,$site,$visible) {
91 global $DAY, $WEEK, $MAX_WEEKS, $GRACE_DAYS, $NOW;
93 $current_exp=$slice['expires'];
94 $max_exp= $NOW + ($MAX_WEEKS * $WEEK); // seconds since epoch
96 // xxx some extra code needed to enable this area only if the slice description is OK:
97 // description and url must be non void
98 $toggle=new PlekitToggle('renew',"Renew this slice",
99 array("trigger-bubble"=>"Enter this zone if you wish to renew your slice",
100 'start-visible'=>$visible));
103 // xxx message could take roles into account
104 if ($site['max_slices']<=0) {
106 <p class='renewal'>Slice creation and renewal have been temporarily disabled for your
107 <site. This may have occurred because your site's nodes have been down
108 or unreachable for several weeks, and multiple attempts to contact
109 your site's PI(s) and Technical Contact(s) have all failed. If so,
110 contact your site's PI(s) and Technical Contact(s) and ask them to
111 bring up your site's nodes. Please visit your <a
112 href='/db/sites/index.php?id=$site_id'>site details</a> page to find
113 out more about your site's nodes, and how to contact your site's PI(s)
114 and Technical Contact(s).</p>
119 // xxx this is a rough cut and paste from the former UI
120 // showing a datepicker view could be considered as well with some extra work
121 // calculate possible extension lengths
122 $selectors = array();
123 foreach ( array ( 1 => "One more week",
124 2 => "Two more weeks",
125 3 => "Two more weeks",
126 4 => "One more month" ) as $weeks => $text ) {
127 $candidate_exp = $current_exp + $weeks*$WEEK;
128 if ( $candidate_exp < $max_exp) {
129 $selectors []= array('display'=>"$text (" . gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp) . ")",
130 'value'=>$candidate_exp);
131 $max_renewal_weeks=$weeks;
132 $max_renewal_date= gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp);
136 if ( empty( $selectors ) ) {
138 <div class='plc-warning renewal'>
139 Slice cannot be renewed any further into the future, try again closer to expiration date.
144 <div class='renewal'>
145 <p>You must provide a short description as well as a link to a project website before renewing it.
146 Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against your slice
147 and PlanetLab Operations is unable to determine what the normal behavior of your slice is,
148 your slice may be deleted to resolve the complaint.</p>
149 <p><span class='bold'>NOTE:</span>
150 Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date).
155 $form = new PlekitForm (l_actions(),
156 array('action'=>'renew-slice',
157 'slice_id'=>$slice['slice_id']));
159 print $form->label_html('expires','Duration');
160 print $form->select_html('expires',$selectors,array('label'=>'Pick one'));
161 print $form->submit_html('renew-button','Renew');
170 drupal_set_title("Details for slice " . $name);
171 $local_peer= ! $peer_id;
173 $am_in_slice = in_array(plc_my_person_id(),$person_ids);
175 $privileges = (plc_is_admin() || $am_in_slice);
178 $tabs [] = tab_nodes_slice($slice_id);
179 $tabs [] = tab_site($site_id);
181 // are these the right privileges for deletion ?
183 $tabs ['Delete']= array('url'=>l_actions(),
185 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id),
186 'bubble'=>"Delete slice $name",
187 'confirm'=>'Are you sure to delete $name');
189 $tabs["Events"]=array_merge(tablook_event(),
190 array('url'=>l_event("Slice","slice",$slice_id),
191 'bubble'=>"Events for slice $name"));
192 $tabs["Comon"]=array_merge(tablook_comon(),
193 array('url'=>l_comon("slice_id",$slice_id),
194 'bubble'=>"Comon page about slice $name"));
197 plekit_linetabs($tabs);
199 ////////////////////////////////////////
200 $peers->block_start($peer_id);
202 //////////////////////////////////////// renewal area
203 // (1) close to expiration : show on top and open
206 $renew_visible = renew_needed ($slice);
207 if ($renew_visible) renew_area ($slice,$site,true);
211 //////////////////// details
212 $toggle = new PlekitToggle ('slice',"Details",
213 array('trigger-bubble'=>'Display and modify details for that slice'));
216 $details=new PlekitDetails($privileges);
217 $details->form_start(l_actions(),array('action'=>'update-slice',
218 'slice_id'=>$slice_id,
223 $details->th_td("Peer",$peers->peer_link($peer_id));
228 $details->th_td('Name',$slice['name']);
229 $details->th_td('Description',$slice['description'],'description',
230 array('input_type'=>'textarea',
231 'width'=>50,'height'=>5));
232 $details->th_td('URL',$slice['url'],'url',array('width'=>50));
233 $details->th_td('Expires',$expires);
234 $details->th_td('Instantiation',$slice['instantiation']);
235 $details->th_td('Site',l_site_obj($site));
236 // xxx show the PIs here
237 //$details->th_td('PIs',...);
238 $details->tr_submit("submit","Update Slice");
241 $details->form_end();
244 //////////////////// users
245 $persons=$api->GetPersons(array('person_id'=>$slice['person_ids']));
246 // just propose to add evryone else, regular users can see only a fraction of the db anyway
247 $potential_persons=$api->GetPersons(array('~person_id'=>$slice['person_ids'],'peer_id'=>NULL),
248 array('email','person_id','first_name','last_name','roles'));
250 if ( $_GET['show_users']) $show_users=true;
251 $toggle=new PlekitToggle ('persons',"Users",array('trigger-bubble'=>'Manage users attached to this slice','start-visible'=>$show_users));
254 ////////// people currently in
256 $headers['email']='string';
257 $headers['first']='string';
258 $headers['last']='string';
259 $headers['R']='string';
260 if ($privileges) $headers[plc_delete_icon()]="none";
261 // xxx caption currently broken, messes pagination
262 $table=new PlekitTable('persons',$headers,'1',array(//'caption'=>'Current users',
263 'search_area'=>false,
265 'pagesize_area'=>false));
266 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
269 if ($persons) foreach ($persons as $person) {
271 $table->cell(l_person_obj($person));
272 $table->cell($person['first_name']);
273 $table->cell($person['last_name']);
274 $table->cell(plc_vertical_table ($person['roles']));
275 if ($privileges) $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
282 $table->tfoot_start();
285 $table->cell($form->submit_html ("remove-persons-from-slice","Remove selected"),
286 $table->columns(),"right");
291 ////////// people to add
294 $headers['email']='string';
295 $headers['first']='string';
296 $headers['last']='string';
297 $headers['R']='string';
298 $headers['Add']="none";
299 // xxx caption currently broken, messes pagination
300 $options = array(//'caption'=>'Users to add',
304 // show search for admins only as other people won't get that many names to add
305 if ( ! plc_is_admin() ) $options['search_area']=false;
307 $table=new PlekitTable('add_persons',$headers,'1',$options);
308 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
311 if ($potential_persons) foreach ($potential_persons as $person) {
313 $table->cell(l_person_obj($person));
314 $table->cell($person['first_name']);
315 $table->cell($person['last_name']);
316 $table->cell(plc_vertical_table ($person['roles']));
317 $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
321 $table->tfoot_start();
324 $table->cell($form->submit_html ("add-persons-in-slice","Add selected"),
325 $table->columns(),"right");
332 //////////////////// nodes
334 //////////////////// tags
337 if ( ! $renew_visible) renew_area ($slice,$site,false);
340 if ($renew_visible) renew_area ($slice,$site,true);
342 $peers->block_end($peer_id);
345 include 'plc_footer.php';