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 'form.php';
23 require_once 'toggle.php';
25 // --------------------
26 // recognized URL arguments
27 $site_id=intval($_GET['id']);
28 if ( ! $site_id ) { plc_error('Malformed URL - id not set'); return; }
31 // Get all columns as we focus on only one entry
32 $sites = $api->GetSites( array($site_id));
35 drupal_set_message ("Site " . $site_id . " not found");
40 // var names to api return
41 $sitename= htmlentities($site['name']);
42 $abbreviated_name= htmlentities($site['abbreviated_name']);
43 $site_url= $site['url'];
44 $login_base= $site['login_base'];
45 $site_lat= $site['latitude'];
46 $site_long= $site['longitude'];
47 $max_slivers= $site['max_slivers'];
48 $max_slices= $site['max_slices'];
50 $enabled = $site['enabled'];
53 $peer_id= $site['peer_id'];
54 $peers = new Peers ($api);
55 $local_peer = ! $peer_id;
57 // extra privileges to admins, and (pi||tech) on this site
58 $is_site_pi = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
59 $is_site_tech = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
60 $is_site_admin = ($local_peer && plc_is_admin());
62 $address_ids= $site['address_ids'];
63 $pcu_ids= $site['pcu_ids'];
64 $node_ids= $site['node_ids'];
65 $person_ids= $site['person_ids'];
66 $slice_ids= $site['slice_ids'];
70 $api->GetAddresses( $address_ids );
73 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state", "pcu_ids", "ports" ) );
76 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" , "slice_ids") );
78 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation", "node_ids", "person_ids" ) );
81 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
82 $display_pcus = (plc_is_admin() || plc_is_pi() || plc_is_tech());
84 $api->GetPCUs ($pcu_ids, array ('hostname', 'pcu_id' ));
88 list( $addresses, $nodes, $persons, $slices, $pcus )= $api->commit();
90 list( $addresses, $nodes, $persons, $slices )= $api->commit();
94 $disabled_persons = array();
95 if ($persons) foreach( $persons as $person ) {
96 $role_ids= $person['role_ids'];
98 if ( in_array( '20', $role_ids )) $pis[] = $person;
99 if ( in_array( '40', $role_ids )) $techs[] = $person;
100 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
104 $has_disabled_persons = count ($disabled_persons) !=0;
106 // get number of slivers
108 if ($slices) foreach ($slices as $slice) $slivers_count += count ($slice['node_ids']);
110 ////////////////////////////////////////
111 drupal_set_title("Details for site " . $sitename);
115 $tabs []= tab_mysite();
119 $tabs['Expire slices'] = array('url'=>l_actions(),
121 'values'=>array('site_id'=>$site_id,
122 'action'=>'expire-all-slices-in-site'),
123 'bubble'=>"Expire all slices and prevent creation of new slices",
124 'confirm'=>"Suspend all slices in $login_base");
126 $tabs['Delete']=array('url'=>l_actions(),
128 'values'=>array('site_id'=>$site_id,
129 'action'=>'delete-site'),
130 'bubble'=>"Delete site $sitename",
131 'confirm'=>"Are you sure you want to delete site $login_base");
134 $tabs ['Add slice'] = array ('url'=>l_slice_add(),
136 'bubble'=>'Create new slice in site');
138 if (plc_is_admin() || plc_in_site($site_id))
139 $tabs["Events"]=array_merge (tablook_event(),
140 array('url'=>l_event("Site","site",$site_id),
141 'bubble'=>"Events for site $sitename"));
142 if (plc_is_admin() || plc_in_site($site_id))
143 $tabs["Comon"]=array_merge(tablook_comon(),
144 array('url'=>l_comon("site_id",$site_id),
145 'bubble'=>"Comon page for $sitename"));
148 plekit_linetabs($tabs);
150 // show gray background on foreign objects : start a <div> with proper class
151 $peers->block_start ($peer_id);
153 if ( $local_peer && ( ! $enabled ) )
154 plc_warning ("This site is not enabled - Please visit " .
155 href (l_sites_pending(),"this page") .
156 " to review pending applications.");
158 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
161 $toggle = new PlekitToggle ('site',"Details",
162 array('visible'=>get_arg('show_details',true),
163 'bubble'=>'Display and modify details for that site'));
166 $details = new PlekitDetails($can_update);
168 $f = $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
172 if ( ! $site['is_public'])
173 $details->tr(plc_warning_html("This site is not public!"));
175 $details->th_td("Full name",$sitename,'name',array('width'=>50));
176 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
177 $details->th_td("URL",$site_url,'url',array('width'=>40));
178 $details->th_td("Latitude",$site_lat,'latitude');
179 $details->th_td("Longitude",$site_long,'longitude');
181 // modifiable by admins only
183 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
185 $details->th_td("Login base",$login_base);
187 $details->th_td("Max slices",$max_slices,'max_slices');
189 $details->th_td("Max slices",$max_slices);
192 $selectors=array(array('display'=>"False",'value'=>'0'),
193 array('display'=>"True",'value'=>'1'));
194 $selectors[intval($enabled)]['selected'] = 'selected';
196 $enable_select = $f->select_html ("enabled", $selectors);
198 $details->th_td("Enabled",$enable_select,'enabled', array('input_type' => 'select', 'value'=>$enabled));
200 $details->th_td("Enabled",$enabled);
202 $details->tr_submit("submit","Update Site");
204 if ( ! $local_peer) {
206 $details->th_td("Peer",$peers->peer_link($peer_id));
209 $details->form_end();
212 //////////////////// mode details - for local object
215 //////////////////// nodes
217 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
219 $nodes_title = "Nodes : ";
220 $nodes_title .= count($nodes) . " total";
221 $nodes_title .= " / " . $nb_boot . " boot";
223 $nodes_title = plc_warning_html ($nodes_title);
224 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
226 $toggle=new PlekitToggle ('nodes',$nodes_title,
227 array('visible'=>get_arg('show_nodes',true)));
232 if ($display_pcus) { $headers['PCU']='string'; $sort_column = '1' ; }
233 $headers['hostname']='string';
234 $headers['state']='string';
236 $table = new PlekitTable ('nodes',$headers,$sort_column,array('search_area'=>false,
238 'pagesize_area'=>false));
239 // hash pcus on pcu_id
243 if ($pcus) foreach ($pcus as $pcu) $pcu_hash[$pcu['pcu_id']]=$pcu;
245 // search the pcu, return the string to display and mark the pcu as displayed
246 // function display_and_mark ($pcu_hash,$pcu_ids,$ports) {
247 function display_and_mark ($pcu_ids,$ports) {
249 if (empty($pcu_ids)) return plc_warning_html('None');
251 if (empty($ports)) return plc_error_html('???');
253 $pcu=$pcu_hash[$pcu_id];
254 $display= $pcu['hostname'] . ' : ' . $port;
255 $pcu_hash[$pcu_id]['displayed']=true;
260 foreach ($nodes as $node) {
263 // $table->cell(display_and_mark($pcu_hash,$node['pcu_ids'],$node['ports']));
264 $table->cell(display_and_mark($node['pcu_ids'],$node['ports']));
266 $table->cell (l_node_obj($node));
267 $table->cell ($node['boot_state']);
270 // show undisplayed PCU's if any
272 if ($pcu_hash) foreach ($pcu_hash as $id=>$pcu) {
273 if (!$pcu['displayed']) {
275 $table->cell($pcu['hostname']); $table->cell(''); $table->cell('');
280 $table->tfoot_start();
282 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
283 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
288 //////////////////// Users
289 $persons_title = "Users : ";
290 $persons_title .= count($person_ids) . " total";
291 $persons_title .= " / " . count ($pis) . " PIs";
292 $persons_title .= " / " . count ($techs) . " Techs";
293 if ($has_disabled_persons)
294 $persons_title .= " / " . count($disabled_persons) . " Disabled";
295 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
296 $persons_title = plc_warning_html ($persons_title);
297 $persons_title .= href(l_persons_site($site_id)," (See as users)");
299 $toggle=new PlekitToggle ('persons',$persons_title,
300 array('visible'=>get_arg('show_persons',false)));
304 $headers["email"]='string';
306 $headers["PI"]='string';
307 $headers['User']='string';
308 $headers["Tech"]='string';
309 if ($has_disabled_persons) $headers["Disabled"]='string';
310 $notes=array('S = slices');
311 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
313 'pagesize_area'=>false));
315 if ($persons) foreach ($persons as $person) {
317 $table->cell(l_person_obj($person));
318 $table->cell(count($person['slice_ids']));
319 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
320 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
321 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
322 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : plc_warning_html("yes"));
328 //////////////////// Slices
329 $slices_title="Slices : ";
330 $slices_title .= $max_slices . " max";
331 $slices_title .= " / " . count($slice_ids) . " running";
332 $slices_title .= " / $slivers_count slivers";
333 if (count($slice_ids) >= $max_slices)
334 $slices_title = plc_warning_html($slices_title);
335 $slices_title .= href(l_slices_site($site_id)," (See as slices)");
337 $toggle=new PlekitToggle ('slices',$slices_title,
338 array('visible'=>get_arg('show_slices',false)));
342 $headers ['name']='string';
343 $headers ['I'] = 'string';
344 $headers ['N']='int';
345 $headers ['U']='int';
346 $notes=array('I = instantiation type',
347 'N = number of nodes',
348 'U = number of users');
349 $table=new PlekitTable ('slices',$headers,0,array('search_area'=>false,
350 'pagesize_area'=>false,
354 if ($slices) foreach ($slices as $slice) {
356 $table->cell(l_slice_obj($slice));
357 $table->cell(instantiation_label($slice));
358 $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
359 $table->cell (count($slice['person_ids']));
363 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","post");
364 $table->tfoot_start();
366 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
372 //////////////////// Addresses
373 $toggle=new PlekitToggle ('addresses',"Addresses",
374 array('visible'=>get_arg('show_addresses',false)));
377 print "<p class='addresses'>No known address for this site</p>";
379 $details=new PlekitDetails (false);
381 $details->th_td("Addresses","");
382 foreach ($addresses as $address) {
383 $details->th_td(plc_vertical_table($address['address_types']),
384 plc_vertical_table(array($address['line1'],
389 $address['postalcode'],
390 $address['country'])));
398 ////////////////////////////////////////
399 $peers->block_end($peer_id);
401 //plekit_linetabs ($tabs,"bottom");
404 include 'plc_footer.php';