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 // GetPCUs is not accessible to the 'user' role
74 //$api->GetPCUs( $pcu_ids );
77 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
80 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
82 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation", "node_ids", "person_ids" ) );
84 //list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
85 list( $addresses, $nodes, $persons, $slices )= $api->commit();
89 $disabled_persons = array();
90 foreach( $persons as $person ) {
91 $role_ids= $person['role_ids'];
93 if ( in_array( '20', $role_ids )) $pis[] = $person;
94 if ( in_array( '40', $role_ids )) $techs[] = $person;
95 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
99 $has_disabled_persons = count ($disabled_persons) !=0;
101 // get number of slivers
103 if ($slices) foreach ($slices as $slice) $slivers_count += count ($slice['node_ids']);
105 ////////////////////////////////////////
106 drupal_set_title("Details for site " . $sitename);
110 $tabs []= tab_sites_local();
114 $tabs['Expire slices'] = array('url'=>l_actions(),
116 'values'=>array('site_id'=>$site_id,
117 'action'=>'expire-all-slices-in-site'),
118 'bubble'=>"Expire all slices and prevent creation of new slices",
119 'confirm'=>"Suspend all slices in $login_base");
121 $tabs['Delete']=array('url'=>l_actions(),
123 'values'=>array('site_id'=>$site_id,
124 'action'=>'delete-site'),
125 'bubble'=>"Delete site $sitename",
126 'confirm'=>"Are you sure you want to delete site $login_base");
129 $tabs ['Add site'] = array ('url'=>l_slice_add(),
131 'bubble'=>'Create new slice in site');
133 if (plc_in_site($site_id))
134 $tabs["Events"]=array_merge (tablook_event(),
135 array('url'=>l_event("Site","site",$site_id),
136 'bubble'=>"Events for site $sitename"));
137 if (plc_in_site($site_id))
138 $tabs["Comon"]=array_merge(tablook_comon(),
139 array('url'=>l_comon("site_id",$site_id),
140 'bubble'=>"Comon page for $sitename"));
143 plekit_linetabs($tabs);
145 // show gray background on foreign objects : start a <div> with proper class
146 $peers->block_start ($peer_id);
148 if ( $local_peer && ( ! $enabled ) )
149 plc_warning ("This site is not enabled - Please visit " .
150 href (l_sites_pending(),"this page") .
151 " to review pending applications.");
153 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
156 $toggle = new PlekitToggle ('site',"Details",
157 array('visible'=>get_arg('show_details',true),
158 'bubble'=>'Display and modify details for that site'));
161 $details = new PlekitDetails($can_update);
163 if ( ! $site['is_public'])
164 plc_warning("This site is not public!");
166 $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
170 $details->th_td("Full name",$sitename,'name',array('width'=>50));
171 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
172 $details->th_td("URL",$site_url,'url',array('width'=>40));
173 $details->th_td("Latitude",$site_lat,'latitude');
174 $details->th_td("Longitude",$site_long,'longitude');
176 // modifiable by admins only
178 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
180 $details->th_td("Login base",$login_base);
182 $details->th_td("Max slices",$max_slices,'max_slices');
184 $details->th_td("Max slices",$max_slices);
185 $details->tr_submit("submit","Update Site");
187 if ( ! $local_peer) {
189 $details->th_td("Peer",$peers->peer_link($peer_id));
192 $details->form_end();
195 //////////////////// mode details - for local object
198 //////////////////// nodes
199 // xxx missing : would need to add columns on attached PCU name and port if avail
201 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
203 $nodes_title = "Nodes : ";
204 $nodes_title .= count($nodes) . " total";
205 $nodes_title .= " / " . $nb_boot . " boot";
207 $nodes_title = plc_warning_html ($nodes_title);
208 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
210 $toggle=new PlekitToggle ('nodes',$nodes_title,
211 array('visible'=>get_arg('show_nodes',false)));
215 $headers['hostname']='string';
216 $headers['state']='string';
218 $table = new PlekitTable ('nodes',$headers,'0',array('search_area'=>false,
220 'pagesize_area'=>false));
222 foreach ($nodes as $node) {
224 $table->cell (l_node_obj($node));
225 $table->cell ($node['boot_state']);
228 $table->tfoot_start();
230 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
231 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
236 //////////////////// Users
237 $persons_title = "Users : ";
238 $persons_title .= count($person_ids) . " total";
239 $persons_title .= " / " . count ($pis) . " PIs";
240 $persons_title .= " / " . count ($techs) . " Techs";
241 if ($has_disabled_persons)
242 $persons_title .= " / " . count($disabled_persons) . " Disabled";
243 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
244 $persons_title = plc_warning_html ($persons_title);
245 $persons_title .= href(l_persons_site($site_id)," (See as users)");
247 $toggle=new PlekitToggle ('persons',$persons_title,
248 array('visible'=>get_arg('show_persons',false)));
252 $headers["email"]='string';
253 $headers["PI"]='string';
254 $headers['User']='string';
255 $headers["Tech"]='string';
256 if ($has_disabled_persons) $headers["Disabled"]='string';
257 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
259 'pagesize_area'=>false));
261 if ($persons) foreach ($persons as $person) {
263 $table->cell(l_person_obj($person));
264 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
265 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
266 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
267 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : plc_warning_html("yes"));
273 //////////////////// Slices
274 $slices_title="Slices : ";
275 $slices_title .= $max_slices . " max";
276 $slices_title .= " / " . count($slice_ids) . " running";
277 $slices_title .= " / $slivers_count slivers";
278 if (count($slice_ids) >= $max_slices)
279 $slices_title = plc_warning_html($slices_title);
280 $slices_title .= href(l_slices_site($site_id)," (See as slices)");
282 $toggle=new PlekitToggle ('slices',$slices_title,
283 array('visible'=>get_arg('show_slices',false)));
287 $headers ['name']='string';
288 $headers ['I'] = 'string';
289 $headers ['N']='int';
290 $headers ['U']='int';
291 $notes=array('I column shows instantiation type',
292 'N column shows number of nodes',
293 'U column shows number of users');
294 $table=new PlekitTable ('slices',$headers,0,array('search_area'=>false,
295 'pagesize_area'=>false,
299 if ($slices) foreach ($slices as $slice) {
301 $table->cell(l_slice_obj($slice));
302 $table->cell(instantiation_label($slice));
303 $table->cell (href(l_nodes_slice($slice['slice_id']),count($slice['node_ids'])));
304 $table->cell (count($slice['person_ids']));
308 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","post");
309 $table->tfoot_start();
311 $table->cell($button->html(),array('hfill'=>true,'align'=>'right'));
317 //////////////////// Addresses
318 $toggle=new PlekitToggle ('addresses',"Addresses",
319 array('visible'=>get_arg('show_addresses',false)));
322 print "<p class='addresses'>No known address for this site</p>";
324 $details=new PlekitDetails (false);
326 $details->th_td("Addresses","");
327 foreach ($addresses as $address) {
328 $details->th_td(plc_vertical_table($address['address_types']),
329 plc_vertical_table(array($address['line1'],
334 $address['postalcode'],
335 $address['country'])));
343 ////////////////////////////////////////
344 $peers->block_end($peer_id);
346 //plekit_linetabs ($tabs,"bottom");
349 include 'plc_footer.php';