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 $api->GetAddresses( $address_ids );
77 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state", "pcu_ids", "ports" ) );
80 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" , "slice_ids") );
82 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation", "node_ids", "person_ids" ) );
85 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
86 $display_pcus = (plc_is_admin() || plc_is_pi() || plc_is_tech());
88 $api->GetPCUs ($pcu_ids, array ('hostname', 'pcu_id' ));
92 list( $addresses, $nodes, $persons, $slices, $pcus )= $api->commit();
94 list( $addresses, $nodes, $persons, $slices )= $api->commit();
98 $disabled_persons = array();
99 if ($persons) foreach( $persons as $person ) {
100 $role_ids= $person['role_ids'];
102 if ( in_array( '20', $role_ids )) $pis[] = $person;
103 if ( in_array( '40', $role_ids )) $techs[] = $person;
104 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
108 $has_disabled_persons = count ($disabled_persons) !=0;
110 // get number of slivers
112 if ($slices) foreach ($slices as $slice) $slivers_count += count ($slice['node_ids']);
114 ////////////////////////////////////////
115 drupal_set_title("Details for site " . $sitename);
119 $tabs []= tab_mysite();
123 $tabs['Expire slices'] = array('url'=>l_actions(),
125 'values'=>array('site_id'=>$site_id,
126 'action'=>'expire-all-slices-in-site'),
127 'bubble'=>"Expire all slices and prevent creation of new slices",
128 'confirm'=>"Suspend all slices in $login_base");
130 $tabs['Delete']=array('url'=>l_actions(),
132 'values'=>array('site_id'=>$site_id,
133 'action'=>'delete-site'),
134 'bubble'=>"Delete site $sitename",
135 'confirm'=>"Are you sure you want to delete site $login_base");
138 $tabs ['Add slice'] = array ('url'=>l_slice_add(),
140 'bubble'=>'Create new slice in site');
142 if (plc_is_admin() || plc_in_site($site_id))
143 $tabs["Events"]=array_merge (tablook_event(),
144 array('url'=>l_event("Site","site",$site_id),
145 'bubble'=>"Events for site $sitename"));
146 if (plc_is_admin() || plc_in_site($site_id))
147 $tabs["Comon"]=array_merge(tablook_comon(),
148 array('url'=>l_comon("site_id",$site_id),
149 'bubble'=>"Comon page for $sitename"));
152 plekit_linetabs($tabs);
154 // show gray background on foreign objects : start a <div> with proper class
155 $peers->block_start ($peer_id);
160 global $PENDING_CONSORTIUM_ID;
161 if ( $ext_consortium_id === $PENDING_CONSORTIUM_ID) {
163 plc_warning ("This site is under pending registration - Please visit " .
164 href (l_sites_pending(),"this page") .
165 " to review pending applications.");
167 plc_warning ("This site is pending but is also enabled - something is wrong. You should fix the issue with plcsh");
170 plc_warning ("This site is disabled.");
174 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
177 $toggle = new PlekitToggle ('site',"Details",
178 array('visible'=>get_arg('show_details'),
179 'bubble'=>'Display and modify details for that site'));
182 $details = new PlekitDetails($can_update);
184 $f = $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
188 if ( ! $site['is_public'])
189 $details->tr(plc_warning_html("This site is not public!"));
191 $details->th_td("Full name",$sitename,'name',array('width'=>50));
192 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
193 $details->th_td("URL",$site_url,'url',array('width'=>40));
194 $details->th_td("Latitude",$site_lat,'latitude');
195 $details->th_td("Longitude",$site_long,'longitude');
197 // modifiable by admins only
199 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
201 $details->th_td("Login base",$login_base);
203 $details->th_td("Max slices",$max_slices,'max_slices');
205 $details->th_td("Max slices",$max_slices);
208 $selectors=array(array('display'=>"False",'value'=>'0'),
209 array('display'=>"True",'value'=>'1'));
210 $selectors[intval($enabled)]['selected'] = 'selected';
212 $enable_select = $f->select_html ("enabled", $selectors);
214 $details->th_td("Enabled",$enable_select,'enabled', array('input_type' => 'select', 'value'=>$enabled));
216 $details->th_td("Enabled",$enabled);
218 $details->tr_submit("submit","Update Site");
220 if ( ! $local_peer) {
222 $details->th_td("Peer",$peers->peer_link($peer_id));
225 $details->form_end();
228 //////////////////// mode details - for local object
231 //////////////////// nodes
233 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
235 $nodes_title = "Nodes : ";
236 $nodes_title .= count($nodes) . " total";
237 $nodes_title .= " / " . $nb_boot . " boot";
239 $nodes_title = plc_warning_html ($nodes_title);
240 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
242 $toggle=new PlekitToggle ('nodes',$nodes_title,
243 array('visible'=>get_arg('show_nodes')));
248 if ($display_pcus) { $headers['PCU']='string'; $sort_column = '1' ; }
249 $headers['hostname']='string';
250 $headers['state']='string';
252 $table = new PlekitTable ('nodes',$headers,$sort_column,array('search_area'=>false,
254 'pagesize_area'=>false));
255 // hash pcus on pcu_id
259 if ($pcus) foreach ($pcus as $pcu) $pcu_hash[$pcu['pcu_id']]=$pcu;
261 // search the pcu, return the string to display and mark the pcu as displayed
262 // function display_and_mark ($pcu_hash,$pcu_ids,$ports) {
263 function display_and_mark ($pcu_ids,$ports) {
265 if (empty($pcu_ids)) return plc_warning_html('None');
267 if (empty($ports)) return plc_error_html('???');
269 $pcu=$pcu_hash[$pcu_id];
270 $display= l_pcu_href($pcu_id, $pcu['hostname'] . ' : ' . $port);
271 $pcu_hash[$pcu_id]['displayed']=true;
276 foreach ($nodes as $node) {
279 // $table->cell(display_and_mark($pcu_hash,$node['pcu_ids'],$node['ports']));
280 $table->cell(display_and_mark($node['pcu_ids'],$node['ports']));
282 $table->cell (l_node_obj($node));
283 $table->cell ($node['boot_state']);
286 // show undisplayed PCU's if any
288 if ($pcu_hash) foreach ($pcu_hash as $id=>$pcu) {
289 if (!$pcu['displayed']) {
291 $table->cell($pcu['hostname']); $table->cell(''); $table->cell('');
296 $table->tfoot_start();
298 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
299 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
304 //////////////////// Users
305 $persons_title = "Users : ";
306 $persons_title .= count($person_ids) . " total";
307 $persons_title .= " / " . count ($pis) . " PIs";
308 $persons_title .= " / " . count ($techs) . " Techs";
309 if ($has_disabled_persons)
310 $persons_title .= " / " . count($disabled_persons) . " Disabled";
311 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
312 $persons_title = plc_warning_html ($persons_title);
313 $persons_title .= href(l_persons_site($site_id)," (See as users)");
315 $toggle=new PlekitToggle ('persons',$persons_title,
316 array('visible'=>get_arg('show_persons')));
320 $headers["email"]='string';
322 $headers["PI"]='string';
323 $headers['User']='string';
324 $headers["Tech"]='string';
325 if ($has_disabled_persons) $headers["Disabled"]='string';
326 $notes=array('S = slices');
327 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
329 'pagesize_area'=>false));
331 if ($persons) foreach ($persons as $person) {
333 $table->cell(l_person_obj($person));
334 $table->cell(count($person['slice_ids']));
335 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
336 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
337 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
338 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : plc_warning_html("yes"));
344 //////////////////// Slices
345 $slices_title="Slices : ";
346 $slices_title .= $max_slices . " max";
347 $slices_title .= " / " . count($slice_ids) . " running";
348 $slices_title .= " / $slivers_count slivers";
349 if (count($slice_ids) >= $max_slices)
350 $slices_title = plc_warning_html($slices_title);
351 $slices_title .= href(l_slices_site($site_id)," (See as slices)");
353 $toggle=new PlekitToggle ('slices',$slices_title,
354 array('visible'=>get_arg('show_slices')));
358 $headers ['name']='string';
359 $headers ['I'] = 'string';
360 $headers ['N']='int';
361 $headers ['U']='int';
362 $notes=array('I = instantiation type',
363 'N = number of nodes',
364 'U = number of users');
365 $table=new PlekitTable ('slices',$headers,0,array('search_area'=>false,
366 'pagesize_area'=>false,
370 if ($slices) foreach ($slices as $slice) {
372 $table->cell(l_slice_obj($slice));
373 $table->cell(instantiation_label($slice));
374 $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
375 $table->cell (count($slice['person_ids']));
379 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","post");
380 $table->tfoot_start();
382 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
388 $form=new PlekitForm (l_actions(), array('site_id'=>$site_id));
390 //////////////////////////////////////////////////////////// Tags
392 // already inside a if ( $local_peer )...
394 $tags=$api->GetSiteTags (array('site_id'=>$site_id));
395 function get_tagname ($tag) { return $tag['tagname'];}
396 // xxx looks like tech-only see an error here,
397 // might be that GetSiteTags is not accessible or something
398 $tagnames = array_map ("get_tagname",$tags);
400 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
401 array('bubble'=>'Inspect and set tags on that site',
402 'visible'=>get_arg('show_tags')));
405 $headers=array("Name"=>"string",
408 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
410 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
411 $table=new PlekitTable("site_tags",$headers,0,$table_options);
413 if ($tags) foreach ($tags as $tag) {
415 $table->cell(l_tag_obj($tag));
416 $table->cell($tag['value']);
417 // the remove checkbox
418 if (plc_is_admin()) $table->cell ($form->checkbox_html('site_tag_ids[]',$tag['site_tag_id']));
422 if ($is_site_pi || $is_site_admin) {
423 $table->tfoot_start();
427 $table->cell($form->submit_html("delete-site-tags","Remove Tags"),
428 // use the whole columns and right adjust
429 array('hfill'=>true,'align'=>'right'));
434 // get list of tag names in the site/* category
435 $all_tags= $api->GetTagTypes( array ("category"=>"site*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
436 // xxx cannot use onchange=submit() - would need to somehow pass action name
437 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
438 $selector=array_map("tag_selector",$all_tags);
439 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
440 $table->cell($form->text_html("value","",array('width'=>8)));
441 $table->cell($form->submit_html("set-tag-on-site","Set Tag"),array('columns'=>2,'align'=>'left'));
449 //////////////////// Addresses
450 $toggle=new PlekitToggle ('addresses',"Addresses",
451 array('visible'=>get_arg('show_addresses')));
454 print "<p class='addresses'>No known address for this site</p>";
456 $details=new PlekitDetails (false);
458 $details->th_td("Addresses","");
459 foreach ($addresses as $address) {
460 $details->th_td(plc_vertical_table($address['address_types']),
461 plc_vertical_table(array($address['line1'],
466 $address['postalcode'],
467 $address['country'])));
475 ////////////////////////////////////////
476 $peers->block_end($peer_id);
478 //plekit_linetabs ($tabs,"bottom");
481 include 'plc_footer.php';