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 // Thomas Dreibholz suggested that utf8_decode could be non-needed
42 // and maybe even harmful on modern systems like f23
43 // $sitename= htmlentities(utf8_decode($site['name']));
44 $sitename= htmlentities($site['name']);
45 $abbreviated_name= htmlentities($site['abbreviated_name']);
46 $site_url= $site['url'];
47 $login_base= $site['login_base'];
48 $site_lat= $site['latitude'];
49 $site_long= $site['longitude'];
50 $max_slivers= $site['max_slivers'];
51 $max_slices= $site['max_slices'];
53 $enabled = $site['enabled'];
54 $ext_consortium_id = $site ['ext_consortium_id'];
57 $peer_id= $site['peer_id'];
58 $peers = new Peers ($api);
59 $local_peer = ! $peer_id;
61 // extra privileges to admins, and (pi||tech) on this site
62 $is_site_pi = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
63 $is_site_tech = ( $local_peer && plc_is_pi() && plc_in_site($site_id) );
64 $is_site_admin = ($local_peer && plc_is_admin());
66 $address_ids= $site['address_ids'];
67 $pcu_ids= $site['pcu_ids'];
68 $node_ids= $site['node_ids'];
69 $person_ids= $site['person_ids'];
70 $slice_ids= $site['slice_ids'];
74 $addresses = $api->GetAddresses( $address_ids );
78 $nodes = $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state", "pcu_ids", "ports" ) );
84 $persons = $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" , "slice_ids") );
90 $slices = $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation", "node_ids", "person_ids" ) );
95 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
96 $display_pcus = (plc_is_admin() || plc_is_pi() || plc_is_tech());
99 $pcus = $api->GetPCUs ($pcu_ids, array ('hostname', 'pcu_id' ));
106 // list( $addresses, $nodes, $persons, $slices, $pcus )= $api->commit();
108 // list( $addresses, $nodes, $persons, $slices )= $api->commit();
112 $disabled_persons = array();
113 if ($persons) foreach( $persons as $person ) {
114 $role_ids= $person['role_ids'];
116 if ( in_array( '20', $role_ids )) $pis[] = $person;
117 if ( in_array( '40', $role_ids )) $techs[] = $person;
118 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
122 $has_disabled_persons = count ($disabled_persons) !=0;
124 // get number of slivers
126 if ($slices) foreach ($slices as $slice) $slivers_count += count ($slice['node_ids']);
128 ////////////////////////////////////////
129 drupal_set_title("Details for site " . $sitename);
133 $tabs []= tab_mysite();
137 $tabs['Expire slices'] = array('url'=>l_actions(),
139 'values'=>array('site_id'=>$site_id,
140 'action'=>'expire-all-slices-in-site'),
141 'bubble'=>"Expire all slices and prevent creation of new slices",
142 'confirm'=>"Suspend all slices in $login_base");
144 $tabs['Delete']=array('url'=>l_actions(),
146 'values'=>array('site_id'=>$site_id,
147 'action'=>'delete-site'),
148 'bubble'=>"Delete site $sitename",
149 'confirm'=>"Are you sure you want to delete site $login_base");
152 $tabs ['Add slice'] = array ('url'=>l_slice_add(),
154 'bubble'=>'Create new slice in site');
156 if (plc_is_admin() || plc_in_site($site_id))
157 $tabs["Events"]=array_merge (tablook_event(),
158 array('url'=>l_event("Site","site",$site_id),
159 'bubble'=>"Events for site $sitename"));
160 if (plc_is_admin() || plc_in_site($site_id))
161 $tabs["Comon"]=array_merge(tablook_comon(),
162 array('url'=>l_comon("site_id",$site_id),
163 'bubble'=>"Comon page for $sitename"));
166 plekit_linetabs($tabs);
168 // show gray background on foreign objects : start a <div> with proper class
169 $peers->block_start ($peer_id);
174 global $PENDING_CONSORTIUM_ID;
175 if ( $ext_consortium_id === $PENDING_CONSORTIUM_ID) {
177 plc_warning ("This site is under pending registration - Please visit " .
178 href (l_sites_pending(),"this page") .
179 " to review pending applications.");
181 plc_warning ("This site is pending but is also enabled - something is wrong. You should fix the issue with plcsh");
184 plc_warning ("This site is disabled.");
188 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
191 $toggle = new PlekitToggle ('site',"Details",
192 array('visible'=>get_arg('show_details'),
193 'bubble'=>'Display and modify details for that site'));
196 $details = new PlekitDetails($can_update);
198 $f = $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
202 if ( ! $site['is_public'])
203 $details->tr(plc_warning_html("This site is not public!"));
205 $details->th_td("Full name",$sitename,'name',array('width'=>50));
206 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
207 $details->th_td("URL",$site_url,'url',array('width'=>40));
208 $details->th_td("Latitude",$site_lat,'latitude');
209 $details->th_td("Longitude",$site_long,'longitude');
211 // modifiable by admins only
213 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
215 $details->th_td("Login base",$login_base);
217 $details->th_td("Max slices",$max_slices,'max_slices');
219 $details->th_td("Max slices",$max_slices);
222 $selectors=array(array('display'=>"False",'value'=>'0'),
223 array('display'=>"True",'value'=>'1'));
224 $selectors[intval($enabled)]['selected'] = 'selected';
226 $enable_select = $f->select_html ("enabled", $selectors);
228 $details->th_td("Enabled",$enable_select,'enabled', array('input_type' => 'select', 'value'=>$enabled));
230 $details->th_td("Enabled",$enabled);
232 $details->tr_submit("submit","Update Site");
234 if ( ! $local_peer) {
236 $details->th_td("Peer",$peers->peer_link($peer_id));
239 $details->form_end();
242 //////////////////// mode details - for local object
245 //////////////////// nodes
247 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
249 $nodes_title = "Nodes : ";
250 $nodes_title .= count($nodes) . " total";
251 $nodes_title .= " / " . $nb_boot . " boot";
253 $nodes_title = plc_warning_html ($nodes_title);
254 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
256 $toggle=new PlekitToggle ('nodes',$nodes_title,
257 array('visible'=>get_arg('show_nodes')));
262 if ($display_pcus) { $headers['PCU']='string'; $sort_column = '1' ; }
263 $headers['hostname']='string';
264 $headers['state']='string';
266 $table = new PlekitTable ('nodes',$headers,$sort_column,array('search_area'=>false,
268 'pagesize_area'=>false));
269 // hash pcus on pcu_id
273 if ($pcus) foreach ($pcus as $pcu) $pcu_hash[$pcu['pcu_id']]=$pcu;
275 // search the pcu, return the string to display and mark the pcu as displayed
276 // function display_and_mark ($pcu_hash,$pcu_ids,$ports) {
277 function display_and_mark ($pcu_ids,$ports) {
279 if (empty($pcu_ids)) return plc_warning_html('None');
281 if (empty($ports)) return plc_error_html('???');
283 $pcu=$pcu_hash[$pcu_id];
284 $display= l_pcu_href($pcu_id, $pcu['hostname'] . ' : ' . $port);
285 $pcu_hash[$pcu_id]['displayed']=true;
290 foreach ($nodes as $node) {
293 // $table->cell(display_and_mark($pcu_hash,$node['pcu_ids'],$node['ports']));
294 $table->cell(display_and_mark($node['pcu_ids'],$node['ports']));
296 $table->cell (l_node_obj($node));
297 $table->cell ($node['boot_state']);
300 // show undisplayed PCU's if any
302 if ($pcu_hash) foreach ($pcu_hash as $id=>$pcu) {
303 if (!$pcu['displayed']) {
305 $table->cell($pcu['hostname']); $table->cell(''); $table->cell('');
310 $table->tfoot_start();
312 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
313 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
318 //////////////////// Users
319 $persons_title = "Users : ";
320 $persons_title .= count($person_ids) . " total";
321 $persons_title .= " / " . count ($pis) . " PIs";
322 $persons_title .= " / " . count ($techs) . " Techs";
323 if ($has_disabled_persons)
324 $persons_title .= " / " . count($disabled_persons) . " Disabled";
325 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
326 $persons_title = plc_warning_html ($persons_title);
327 $persons_title .= href(l_persons_site($site_id)," (See as users)");
329 $toggle=new PlekitToggle ('persons',$persons_title,
330 array('visible'=>get_arg('show_persons')));
334 $headers["email"]='string';
336 $headers["PI"]='string';
337 $headers['User']='string';
338 $headers["Tech"]='string';
339 if ($has_disabled_persons) $headers["Disabled"]='string';
340 $notes=array('S = slices');
341 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
343 'pagesize_area'=>false));
345 if ($persons) foreach ($persons as $person) {
347 $table->cell(l_person_obj($person));
348 $table->cell(count($person['slice_ids']));
349 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
350 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
351 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
352 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : plc_warning_html("yes"));
358 //////////////////// Slices
359 $slices_title="Slices : ";
360 $slices_title .= $max_slices . " max";
361 $slices_title .= " / " . count($slice_ids) . " running";
362 $slices_title .= " / $slivers_count slivers";
363 if (count($slice_ids) >= $max_slices)
364 $slices_title = plc_warning_html($slices_title);
365 $slices_title .= href(l_slices_site($site_id)," (See as slices)");
367 $toggle=new PlekitToggle ('slices',$slices_title,
368 array('visible'=>get_arg('show_slices')));
372 $headers ['name']='string';
373 $headers ['I'] = 'string';
374 $headers ['N']='int';
375 $headers ['U']='int';
376 $notes=array('I = instantiation type',
377 'N = number of nodes',
378 'U = number of users');
379 $table=new PlekitTable ('slices',$headers,0,array('search_area'=>false,
380 'pagesize_area'=>false,
384 if ($slices) foreach ($slices as $slice) {
386 $table->cell(l_slice_obj($slice));
387 $table->cell(instantiation_label($slice));
388 $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
389 $table->cell (count($slice['person_ids']));
393 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","post");
394 $table->tfoot_start();
396 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
402 $form=new PlekitForm (l_actions(), array('site_id'=>$site_id));
404 //////////////////////////////////////////////////////////// Tags
406 // already inside a if ( $local_peer )...
408 $tags=$api->GetSiteTags (array('site_id'=>$site_id));
409 function get_tagname ($tag) { return $tag['tagname'];}
410 // xxx looks like tech-only see an error here,
411 // might be that GetSiteTags is not accessible or something
412 $tagnames = array_map ("get_tagname",$tags);
414 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
415 array('bubble'=>'Inspect and set tags on that site',
416 'visible'=>get_arg('show_tags')));
419 $headers=array("Name"=>"string",
422 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
424 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
425 $table=new PlekitTable("site_tags",$headers,0,$table_options);
427 if ($tags) foreach ($tags as $tag) {
429 $table->cell(l_tag_obj($tag));
430 $table->cell($tag['value']);
431 // the remove checkbox
432 if (plc_is_admin()) $table->cell ($form->checkbox_html('site_tag_ids[]',$tag['site_tag_id']));
436 if ($is_site_pi || $is_site_admin) {
437 $table->tfoot_start();
441 $table->cell($form->submit_html("delete-site-tags","Remove Tags"),
442 // use the whole columns and right adjust
443 array('hfill'=>true,'align'=>'right'));
448 // get list of tag names in the site/* category
449 $all_tags= $api->GetTagTypes( array ("category"=>"site*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
450 // xxx cannot use onchange=submit() - would need to somehow pass action name
451 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
452 $selector=array_map("tag_selector",$all_tags);
453 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
454 $table->cell($form->text_html("value","",array('width'=>8)));
455 $table->cell($form->submit_html("set-tag-on-site","Set Tag"),array('columns'=>2,'align'=>'left'));
463 //////////////////// Addresses
464 $toggle=new PlekitToggle ('addresses',"Addresses",
465 array('visible'=>get_arg('show_addresses')));
468 print "<p class='addresses'>No known address for this site</p>";
470 $details=new PlekitDetails (false);
472 $details->th_td("Addresses","");
473 foreach ($addresses as $address) {
474 $details->th_td(plc_vertical_table($address['address_types']),
475 plc_vertical_table(array($address['line1'],
480 $address['postalcode'],
481 $address['country'])));
489 ////////////////////////////////////////
490 $peers->block_end($peer_id);
492 //plekit_linetabs ($tabs,"bottom");
495 include 'plc_footer.php';