3 // $Id: index.php 11750 2009-01-29 10:11:53Z thierry $
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'];
52 // extra privileges to admins, and (pi||tech) on this site
53 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
56 $peer_id= $site['peer_id'];
57 $peers = new Peers ($api);
59 $address_ids= $site['address_ids'];
60 $pcu_ids= $site['pcu_ids'];
61 $node_ids= $site['node_ids'];
62 $person_ids= $site['person_ids'];
63 $slice_ids= $site['slice_ids'];
67 $api->GetAddresses( $address_ids );
70 // GetPCUs is not accessible to the 'user' role
71 //$api->GetPCUs( $pcu_ids );
74 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
77 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
79 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
81 //list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
82 list( $addresses, $nodes, $persons, $slices )= $api->commit();
86 $disabled_persons = array();
87 foreach( $persons as $person ) {
88 $role_ids= $person['role_ids'];
90 if ( in_array( '20', $role_ids )) $pis[] = $person;
91 if ( in_array( '40', $role_ids )) $techs[] = $person;
92 if ( ! $person['enabled'] ) $disabled_persons[] = $person;
96 $has_disabled_persons = count ($disabled_persons) !=0;
98 drupal_set_title("Details for site " . $sitename);
99 $local_peer = ! $peer_id;
101 // extra privileges to admins, and pi on this site
102 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
106 $tabs []= tab_sites_local();
109 if ( $local_peer && $privileges ) {
111 $tabs['Expire slices'] = array('url'=>l_actions(),
113 'values'=>array('site_id'=>$site_id,
114 'action'=>'expire-all-slices-in-site'),
115 'bubble'=>"Expire all slices and prevent creation of new slices",
116 'confirm'=>"Suspend all slices in $login_base");
118 $tabs['Delete']=array('url'=>l_actions(),
120 'values'=>array('site_id'=>$site_id,
121 'action'=>'delete-site'),
122 'bubble'=>"Delete site $sitename",
123 'confirm'=>"Are you sure you want to delete site $login_base");
124 $tabs["Events"]=array_merge (tablook_event(),
125 array('url'=>l_event("Site","site",$site_id),
126 'bubble'=>"Events for site $sitename"));
127 $tabs["Comon"]=array_merge(tablook_comon(),
128 array('url'=>l_comon("site_id",$site_id),
129 'bubble'=>"Comon page for $sitename"));
132 $tabs['Pending'] = array ('url'=>l_sites_pending(),
133 'bubble'=>'Review pending join requests');
136 plekit_linetabs($tabs);
138 // show gray background on foreign objects : start a <div> with proper class
139 $peers->block_start ($peer_id);
142 plc_warning ("This site is not enabled - Please visit " .
143 href (l_sites_pending(),"this page") .
144 " to review pending applications.");
146 $can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
147 $details = new PlekitDetails($can_update);
149 if ( ! $site['is_public'])
150 plc_warning("This site is not public!");
152 $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
156 $details->th_td("Full name",$sitename,'name',array('width'=>50));
157 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
158 $details->th_td("URL",$site_url,'url',array('width'=>40));
159 $details->th_td("Latitude",$site_lat,'latitude');
160 $details->th_td("Longitude",$site_long,'longitude');
162 // modifiable by admins only
164 $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
166 $details->th_td("Login base",$login_base);
168 $details->th_td("Max slices",$max_slices,'max_slices');
170 $details->th_td("Max slices",$max_slices);
171 $details->tr_submit("submit","Update Site");
173 if ( ! $local_peer) {
175 $details->th_td("Peer",$peers->peer_link($peer_id));
178 $details->form_end();
180 //////////////////// mode details - for local object
183 //////////////////// nodes
184 // xxx missing : would need to add columns on attached PCU name and port if avail
186 if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
188 $nodes_title = "# Nodes : ";
189 $nodes_title .= count($nodes) . " total";
190 $nodes_title .= " / " . $nb_boot . " boot";
192 $nodes_title = plc_warning_html ($nodes_title);
193 $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
195 $toggle=new PlekitToggle ('nodes',$nodes_title);
199 $headers['hostname']='string';
200 $headers['state']='string';
202 $table = new PlekitTable ('nodes',$headers,'0',array('search_area'=>false,
204 'pagesize_area'=>false));
206 foreach ($nodes as $node) {
208 $table->cell (l_node_obj($node));
209 $table->cell ($node['boot_state']);
212 $table->tfoot_start();
214 $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
215 $table->cell($button->html(),$table->columns(),"right");
220 //////////////////// Users
221 $persons_title = "# Users : ";
222 $persons_title .= count($person_ids) . " total";
223 $persons_title .= " / " . count ($pis) . " PIs";
224 $persons_title .= " / " . count ($techs) . " Techs";
225 if ($has_disabled_persons)
226 $persons_title .= " / " . ($disabled_persons) . " Disabled";
227 if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 )
228 $persons_title = plc_warning_html ($persons_title);
229 $persons_title .= href(l_persons_site($site_id)," (See as users)");
231 $toggle=new PlekitToggle ('persons',$persons_title);
235 $headers["email"]='string';
236 $headers["PI"]='string';
237 $headers['User']='string';
238 $headers["Tech"]='string';
239 if ($has_disabled_persons) $headers["Disabled"]='string';
240 $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
242 'pagesize_area'=>false));
244 foreach ($persons as $person) {
246 $table->cell(l_person_obj($person));
247 $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
248 $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
249 $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
250 if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : "yes");
256 //////////////////// Slices
257 // xxx to review after slices gets reworked
258 $toggle=new PlekitToggle ('slices',"Slices");
260 $details=new PlekitDetails (false);
263 $slice_label = count($slice_ids) . " running / " . $max_slices . " max";
264 if (count($slice_ids) >= $max_slices)
265 $slice_label = plc_warning_html ($slice_label);
266 $details->th_td("# Slices", href(l_slices_site($site_id),$slice_label));
267 if ($slices) foreach ($slices as $slice)
268 $details->th_td($slice['instantiation'],l_slice_obj($slice));
269 $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","POST");
270 $details->tr($button->html(),"right");
275 $toggle=new PlekitToggle ('addresses',"Addresses",array('start-visible'=>false));
278 print "<p class='addresses'>No known address for this site</p>";
280 $details=new PlekitDetails (false);
282 $details->th_td("Addresses","");
283 foreach ($addresses as $address) {
284 $details->th_td(plc_vertical_table($address['address_types']),
285 plc_vertical_table(array($address['line1'],
290 $address['postalcode'],
291 $address['country'])));
299 ////////////////////////////////////////
300 $peers->block_end($peer_id);
302 //plekit_linetabs ($tabs,"bottom");
305 include 'plc_footer.php';