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'];
51 $ext_consortium_id = $site ['ext_consortium_id'];
54 $peer_id= $site['peer_id'];
55 $peers = new Peers ($api);
56 $local_peer = ! $peer_id;
58 // extra privileges to admins, and (pi||tech) on this site
59 $is_site_pi = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
60 $is_site_tech = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
61 $is_site_admin = ($local_peer && plc_is_admin());
63 $address_ids= $site['address_ids'];
64 $pcu_ids= $site['pcu_ids'];
65 $node_ids= $site['node_ids'];
66 $person_ids= $site['person_ids'];
67 $slice_ids= $site['slice_ids'];
71 $api->GetAddresses( $address_ids );
74 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state", "pcu_ids", "ports" ) );
77 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" , "slice_ids") );
79 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation", "node_ids", "person_ids" ) );
82 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
83 $display_pcus = (plc_is_admin() || plc_is_pi() || plc_is_tech());
85 $api->GetPCUs ($pcu_ids, array ('hostname', 'pcu_id' ));
89 list( $addresses, $nodes, $persons, $slices, $pcus )= $api->commit();
91 list( $addresses, $nodes, $persons, $slices )= $api->commit();
95 $disabled_persons = array();
96 if ($persons) foreach( $persons as $person ) {
97 $role_ids= $person['role_ids'];
99 if ( in_array( '20', $role_ids )) $pis[] = $person;
100 if ( in_array( '40', $role_ids )) $techs[] = $person;
101 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
105 $has_disabled_persons = count ($disabled_persons) !=0;
107 // get number of slivers
109 if ($slices) foreach ($slices as $slice) $slivers_count += count ($slice['node_ids']);
111 ////////////////////////////////////////
112 drupal_set_title("Details for site " . $sitename);
116 $tabs []= tab_mysite();
120 $tabs['Expire slices'] = array('url'=>l_actions(),
122 'values'=>array('site_id'=>$site_id,
123 'action'=>'expire-all-slices-in-site'),
124 'bubble'=>"Expire all slices and prevent creation of new slices",
125 'confirm'=>"Suspend all slices in $login_base");
127 $tabs['Delete']=array('url'=>l_actions(),
129 'values'=>array('site_id'=>$site_id,
130 'action'=>'delete-site'),
131 'bubble'=>"Delete site $sitename",
132 'confirm'=>"Are you sure you want to delete site $login_base");
135 $tabs ['Add slice'] = array ('url'=>l_slice_add(),
137 'bubble'=>'Create new slice in site');
139 if (plc_is_admin() || plc_in_site($site_id))
140 $tabs["Events"]=array_merge (tablook_event(),
141 array('url'=>l_event("Site","site",$site_id),
142 'bubble'=>"Events for site $sitename"));
143 if (plc_is_admin() || plc_in_site($site_id))
144 $tabs["Comon"]=array_merge(tablook_comon(),
145 array('url'=>l_comon("site_id",$site_id),
146 'bubble'=>"Comon page for $sitename"));
149 plekit_linetabs($tabs);
151 // show gray background on foreign objects : start a <div> with proper class
152 $peers->block_start ($peer_id);
157 global $PENDING_CONSORTIUM_ID;
158 if ( $ext_consortium_id === $PENDING_CONSORTIUM_ID) {
160 plc_warning ("This site is under pending registration - Please visit " .
161 href (l_sites_pending(),"this page") .
162 " to review pending applications.");
164 plc_warning ("This site is pending but is also enabled - something is wrong. You should fix the issue with plcsh");
167 plc_warning ("This site is disabled.");
171 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
174 $toggle = new PlekitToggle ('site',"Details",
175 array('visible'=>get_arg('show_details',true),
176 'bubble'=>'Display and modify details for that site'));
179 $details = new PlekitDetails($can_update);
181 $f = $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
185 if ( ! $site['is_public'])
186 $details->tr(plc_warning_html("This site is not public!"));
188 $details->th_td("Full name",$sitename,'name',array('width'=>50));
189 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
190 $details->th_td("URL",$site_url,'url',array('width'=>40));
191 $details->th_td("Latitude",$site_lat,'latitude');
192 $details->th_td("Longitude",$site_long,'longitude');
194 // modifiable by admins only
196 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
198 $details->th_td("Login base",$login_base);
200 $details->th_td("Max slices",$max_slices,'max_slices');
202 $details->th_td("Max slices",$max_slices);
205 $selectors=array(array('display'=>"False",'value'=>'0'),
206 array('display'=>"True",'value'=>'1'));
207 $selectors[intval($enabled)]['selected'] = 'selected';
209 $enable_select = $f->select_html ("enabled", $selectors);
211 $details->th_td("Enabled",$enable_select,'enabled', array('input_type' => 'select', 'value'=>$enabled));
213 $details->th_td("Enabled",$enabled);
215 $details->tr_submit("submit","Update Site");
217 if ( ! $local_peer) {
219 $details->th_td("Peer",$peers->peer_link($peer_id));
222 $details->form_end();
225 //////////////////// mode details - for local object
228 //////////////////// nodes
230 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
232 $nodes_title = "Nodes : ";
233 $nodes_title .= count($nodes) . " total";
234 $nodes_title .= " / " . $nb_boot . " boot";
236 $nodes_title = plc_warning_html ($nodes_title);
237 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
239 $toggle=new PlekitToggle ('nodes',$nodes_title,
240 array('visible'=>get_arg('show_nodes',true)));
245 if ($display_pcus) { $headers['PCU']='string'; $sort_column = '1' ; }
246 $headers['hostname']='string';
247 $headers['state']='string';
249 $table = new PlekitTable ('nodes',$headers,$sort_column,array('search_area'=>false,
251 'pagesize_area'=>false));
252 // hash pcus on pcu_id
256 if ($pcus) foreach ($pcus as $pcu) $pcu_hash[$pcu['pcu_id']]=$pcu;
258 // search the pcu, return the string to display and mark the pcu as displayed
259 // function display_and_mark ($pcu_hash,$pcu_ids,$ports) {
260 function display_and_mark ($pcu_ids,$ports) {
262 if (empty($pcu_ids)) return plc_warning_html('None');
264 if (empty($ports)) return plc_error_html('???');
266 $pcu=$pcu_hash[$pcu_id];
267 $display= $pcu['hostname'] . ' : ' . $port;
268 $pcu_hash[$pcu_id]['displayed']=true;
273 foreach ($nodes as $node) {
276 // $table->cell(display_and_mark($pcu_hash,$node['pcu_ids'],$node['ports']));
277 $table->cell(display_and_mark($node['pcu_ids'],$node['ports']));
279 $table->cell (l_node_obj($node));
280 $table->cell ($node['boot_state']);
283 // show undisplayed PCU's if any
285 if ($pcu_hash) foreach ($pcu_hash as $id=>$pcu) {
286 if (!$pcu['displayed']) {
288 $table->cell($pcu['hostname']); $table->cell(''); $table->cell('');
293 $table->tfoot_start();
295 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
296 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
301 //////////////////// Users
302 $persons_title = "Users : ";
303 $persons_title .= count($person_ids) . " total";
304 $persons_title .= " / " . count ($pis) . " PIs";
305 $persons_title .= " / " . count ($techs) . " Techs";
306 if ($has_disabled_persons)
307 $persons_title .= " / " . count($disabled_persons) . " Disabled";
308 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
309 $persons_title = plc_warning_html ($persons_title);
310 $persons_title .= href(l_persons_site($site_id)," (See as users)");
312 $toggle=new PlekitToggle ('persons',$persons_title,
313 array('visible'=>get_arg('show_persons',false)));
317 $headers["email"]='string';
319 $headers["PI"]='string';
320 $headers['User']='string';
321 $headers["Tech"]='string';
322 if ($has_disabled_persons) $headers["Disabled"]='string';
323 $notes=array('S = slices');
324 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
326 'pagesize_area'=>false));
328 if ($persons) foreach ($persons as $person) {
330 $table->cell(l_person_obj($person));
331 $table->cell(count($person['slice_ids']));
332 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
333 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
334 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
335 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : plc_warning_html("yes"));
341 //////////////////// Slices
342 $slices_title="Slices : ";
343 $slices_title .= $max_slices . " max";
344 $slices_title .= " / " . count($slice_ids) . " running";
345 $slices_title .= " / $slivers_count slivers";
346 if (count($slice_ids) >= $max_slices)
347 $slices_title = plc_warning_html($slices_title);
348 $slices_title .= href(l_slices_site($site_id)," (See as slices)");
350 $toggle=new PlekitToggle ('slices',$slices_title,
351 array('visible'=>get_arg('show_slices',false)));
355 $headers ['name']='string';
356 $headers ['I'] = 'string';
357 $headers ['N']='int';
358 $headers ['U']='int';
359 $notes=array('I = instantiation type',
360 'N = number of nodes',
361 'U = number of users');
362 $table=new PlekitTable ('slices',$headers,0,array('search_area'=>false,
363 'pagesize_area'=>false,
367 if ($slices) foreach ($slices as $slice) {
369 $table->cell(l_slice_obj($slice));
370 $table->cell(instantiation_label($slice));
371 $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
372 $table->cell (count($slice['person_ids']));
376 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","post");
377 $table->tfoot_start();
379 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
385 //////////////////// Addresses
386 $toggle=new PlekitToggle ('addresses',"Addresses",
387 array('visible'=>get_arg('show_addresses',false)));
390 print "<p class='addresses'>No known address for this site</p>";
392 $details=new PlekitDetails (false);
394 $details->th_td("Addresses","");
395 foreach ($addresses as $address) {
396 $details->th_td(plc_vertical_table($address['address_types']),
397 plc_vertical_table(array($address['line1'],
402 $address['postalcode'],
403 $address['country'])));
411 ////////////////////////////////////////
412 $peers->block_end($peer_id);
414 //plekit_linetabs ($tabs,"bottom");
417 include 'plc_footer.php';