cleaned up tabs
[plewww.git] / planetlab / sites / site.php
1 <?php
2
3   // $Id: index.php 11750 2009-01-29 10:11:53Z thierry $
4
5 // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'plc_peers.php';
19 require_once 'plc_minitabs.php';
20 require_once 'plc_tables.php';
21 require_once 'plc_details.php';
22 require_once 'plc_forms.php';
23
24 // -------------------- 
25 // recognized URL arguments
26 $site_id=intval($_GET['id']);
27 if ( ! $site_id ) { plc_error('Malformed URL - id not set'); return; }
28
29 ////////////////////
30 // Get all columns as we focus on only one entry
31 $sites= $api->GetSites( array($site_id));
32
33 if (empty($sites)) {
34   drupal_set_message ("Site " . $site_id . " not found");
35   return;
36  }
37
38 $site=$sites[0];
39 // var names to api return
40 $sitename= htmlentities($site['name']);
41 $abbreviated_name= htmlentities($site['abbreviated_name']);
42 $site_url= $site['url'];
43 $login_base= $site['login_base'];
44 $site_lat= $site['latitude'];
45 $site_long= $site['longitude'];
46 $max_slivers= $site['max_slivers'];
47 $max_slices= $site['max_slices'];
48
49 $enabled = $site['enabled'];
50
51 // extra privileges to admins, and (pi||tech) on this site
52 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
53   
54 // get peer details
55 $peer_id= $site['peer_id'];
56 $peers = new Peers ($api);
57
58 $adress_ids= $site['address_ids'];
59 $pcu_ids= $site['pcu_ids'];
60 $node_ids= $site['node_ids'];
61 $person_ids= $site['person_ids'];
62 $slice_ids= $site['slice_ids'];
63
64 $api->begin();
65 // gets address info
66 $api->GetAddresses( $adress_ids );
67
68 // gets pcu info
69 // GetPCUs is not accessible to the 'user' role
70 //$api->GetPCUs( $pcu_ids );
71
72 // gets node info
73 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
74
75 // gets person info
76 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
77
78 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
79
80 //list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
81 list( $addresses, $nodes, $persons, $slices )= $api->commit();
82   
83 $techs = array();
84 $pis = array();
85 $disabled_persons = array();
86 foreach( $persons as $person ) {
87   $role_ids= $person['role_ids'];
88
89   if ( in_array( '20', $role_ids ))     $pis[] = $person;
90   if ( in_array( '40', $role_ids ))     $techs[] = $person;
91   if ( ! $person['enabled'] )           $disabled_persons[] = $person;
92   
93 }
94
95 drupal_set_title("Details for site " . $sitename);
96 $local_peer = ! $peer_id;
97   
98 // extra privileges to admins, and pi on this site
99 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
100   
101 $tabs=array();
102
103 $tabs []= tab_sites();
104 $tabs []= tab_sites_local();
105
106 // available actions
107 if ( $local_peer  && $privileges ) {
108   
109   $tabs['Expire slices'] = array('url'=>l_actions(),
110                                  'method'=>'POST',
111                                  'values'=>array('site_id'=>$site_id,
112                                                  'action'=>'expire-all-slices-in-site'),
113                                  'bubble'=>"Expire all slices and prevent creation of new slices",
114                                  'confirm'=>"Suspend all slices in $login_base");
115   if (plc_is_admin())
116     $tabs['Delete']=array('url'=>l_actions(),
117                           'method'=>'POST',
118                           'values'=>array('site_id'=>$site_id,
119                                           'action'=>'delete-site'),
120                           'bubble'=>"Delete site $sitename",
121                           'confirm'=>"Are you sure you want to delete site $login_base");
122   $tabs["Events"]=array_merge (tablook_event(),
123                                array('url'=>l_event("Site","site",$site_id),
124                                      'bubble'=>"Events for site $sitename"));
125   $tabs["Comon"]=array_merge(tablook_comon(),
126                              array('url'=>l_comon("site_id",$site_id),
127                                    'bubble'=>"Comon page for $sitename"));
128
129   if (plc_is_admin()) 
130     $tabs['Pending'] = array ('url'=>l_sites_pending(),
131                               'bubble'=>'Review pending join requests');
132  }
133
134 plc_tabs($tabs);
135
136 // show gray background on foreign objects : start a <div> with proper class
137 $peers->block_start ($peer_id);
138
139 if ( ! $enabled ) 
140   plc_warning ("This site is not enabled - Please visit " . 
141                href (l_sites_pending(),"this page") . 
142                " to review pending applications.");
143
144 $can_update=(plc_is_admin ()  && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
145 $details = new PlcDetails($can_update);
146
147 if ( ! $site['is_public']) 
148   plc_warning("This site is not public!");
149
150 $details->start();
151
152 $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
153 $details->th_td("Full name",$sitename,'name',array('width'=>50));
154 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
155 $details->th_td("URL",$site_url,'url',array('width'=>50));
156 $details->th_td("Latitude",$site_lat,'latitude');
157 $details->th_td("Longitude",$site_long,'longitude');
158
159 // modifiable by admins only
160 if (plc_is_admin()) 
161   $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
162 else
163   $details->th_td("Login base",$login_base);
164 if (plc_is_admin())
165   $details->th_td("Max slices",$max_slices,'max_slices');
166 else
167   $details->th_td("Max slices",$max_slices);
168 $details->tr_submit("submit","Update Site");
169 $details->form_end();
170
171 if ( ! $local_peer) {
172   $details->space();
173   $details->th_td("Peer",$peers->peer_link($peer_id));
174  }
175
176 if ( $local_peer ) {
177
178   // Nodes
179   $details->space();
180   $nb_boot = 0;
181   if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
182   $node_label = $nb_boot . " boot / " .  count($nodes) . " total";
183   $details->th_td("# Nodes", href(l_nodes_site($site_id),$node_label));
184   function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");}
185   $nodes_label= plc_vertical_table(array_map ("n_link",$nodes));
186   $details->th_td ("Hostnames",$nodes_label);
187   $button=new PlcFormButton (l_node_add(),"add_node","Add node","POST");
188   $details->tr($button->html(),"right");
189
190   // Users
191   $details->space();
192   $user_label = count($person_ids) . " Total / " .
193     count ($pis) . " PIs / " .
194     count ($techs) . " Techs";
195   if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) 
196     $user_label = plc_warning_html ($user_label);
197   $details->th_td ("# Users",href(l_persons_site($site_id),$user_label));
198   function p_link ($p) { return l_person_t($p['person_id'],$p['email']); }
199   // PIs
200   $details->th_td("PI's",plc_vertical_table (array_map ("p_link",$pis)));
201   // techs
202   $details->th_td("Techs's",plc_vertical_table (array_map ("p_link",$techs)));
203   if (count ($disabled_persons)) 
204     $details->th_td("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons)));
205
206   // Slices
207   $details->space();
208   // summary on slices
209   $slice_label = count($slice_ids) . " running / " . $max_slices . " max";
210   if (count($slice_ids) >= $max_slices) 
211     $slice_label = plc_warning_html ($slice_label);
212   $details->th_td("# Slices", href(l_slices_site($site_id),$slice_label));
213   if ($slices) foreach ($slices as $slice)
214      $details->th_td($slice['instantiation'],l_slice_obj($slice));
215   $button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST");
216   $details->tr($button->html(),"right");
217
218   // Addresses
219   if ($addresses) {
220     $details->space();
221     $details->th_td("Addresses","");
222     foreach ($addresses as $address) {
223       $details->th_td(plc_vertical_table($address['address_types']),
224                        plc_vertical_table(array($address['line1'],
225                                                 $address['line2'],
226                                                 $address['line3'],
227                                                 $address['city'],
228                                                 $address['state'],
229                                                 $address['postalcode'],
230                                                 $address['country'])));
231     }
232   }
233
234  }
235
236 $details->end();
237
238 ////////////////////////////////////////
239 $peers->block_end($peer_id);
240
241 // Print footer
242 include 'plc_footer.php';
243
244 ?>