ckp
[plewww.git] / planetlab / sites / site.php
1 <?php
2
3   // $Id$
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 'linetabs.php';
20 require_once 'table.php';
21 require_once 'details.php';
22 require_once 'form.php';
23 require_once 'toggle.php';
24
25 // -------------------- 
26 // recognized URL arguments
27 $site_id=intval($_GET['id']);
28 if ( ! $site_id ) { plc_error('Malformed URL - id not set'); return; }
29
30 ////////////////////
31 // Get all columns as we focus on only one entry
32 $sites = $api->GetSites( array($site_id));
33
34 if (empty($sites)) {
35   drupal_set_message ("Site " . $site_id . " not found");
36   return;
37  }
38
39 $site=$sites[0];
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'];
49
50 $enabled = $site['enabled'];
51
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()));
54   
55 // get peer 
56 $peer_id= $site['peer_id'];
57 $peers = new Peers ($api);
58
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'];
64
65 $api->begin();
66 // gets address info
67 $api->GetAddresses( $address_ids );
68
69 // gets pcu info
70 // GetPCUs is not accessible to the 'user' role
71 //$api->GetPCUs( $pcu_ids );
72
73 // gets node info
74 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
75
76 // gets person info
77 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
78
79 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
80
81 //list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
82 list( $addresses, $nodes, $persons, $slices )= $api->commit();
83   
84 $techs = array();
85 $pis = array();
86 $disabled_persons = array();
87 foreach( $persons as $person ) {
88   $role_ids= $person['role_ids'];
89
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;
93   
94 }
95
96 $has_disabled_persons = count ($disabled_persons) !=0;
97
98 drupal_set_title("Details for site " . $sitename);
99 $local_peer = ! $peer_id;
100   
101 // extra privileges to admins, and pi on this site
102 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
103   
104 $tabs=array();
105
106 $tabs []= tab_sites_local();
107
108 // available actions
109 if ( $local_peer  && $privileges ) {
110   
111   $tabs['Expire slices'] = array('url'=>l_actions(),
112                                  'method'=>'POST',
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");
117   if (plc_is_admin())
118     $tabs['Delete']=array('url'=>l_actions(),
119                           'method'=>'POST',
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"));
130
131   if (plc_is_admin()) 
132     $tabs['Pending'] = array ('url'=>l_sites_pending(),
133                               'bubble'=>'Review pending join requests');
134  }
135
136 plekit_linetabs($tabs);
137
138 // show gray background on foreign objects : start a <div> with proper class
139 $peers->block_start ($peer_id);
140
141 if ( ! $enabled ) 
142   plc_warning ("This site is not enabled - Please visit " . 
143                href (l_sites_pending(),"this page") . 
144                " to review pending applications.");
145
146 $can_update=(plc_is_admin ()  && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
147
148
149 $toggle = new PlekitToggle ('site',"Details",
150                             array('trigger-bubble'=>'Display and modify details for that site'));
151 $toggle->start();
152
153 $details = new PlekitDetails($can_update);
154
155 if ( ! $site['is_public']) 
156   plc_warning("This site is not public!");
157
158 $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
159
160 $details->start();
161
162 $details->th_td("Full name",$sitename,'name',array('width'=>50));
163 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
164 $details->th_td("URL",$site_url,'url',array('width'=>40));
165 $details->th_td("Latitude",$site_lat,'latitude');
166 $details->th_td("Longitude",$site_long,'longitude');
167
168 // modifiable by admins only
169 if (plc_is_admin()) 
170   $details->th_td("Login base",$login_base,'login_base',array('width'=>12));
171 else
172   $details->th_td("Login base",$login_base);
173 if (plc_is_admin())
174   $details->th_td("Max slices",$max_slices,'max_slices');
175 else
176   $details->th_td("Max slices",$max_slices);
177 $details->tr_submit("submit","Update Site");
178
179 if ( ! $local_peer) {
180   $details->space();
181   $details->th_td("Peer",$peers->peer_link($peer_id));
182  }
183 $details->end();
184 $details->form_end();
185 $toggle->end();
186
187 //////////////////// mode details - for local object
188 if ( $local_peer ) {
189
190   //////////////////// nodes
191   // xxx missing : would need to add columns on attached PCU name and port if avail
192   $nb_boot = 0;
193   if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
194
195   $nodes_title = "Nodes : ";
196   $nodes_title .= count($nodes) . " total";
197   $nodes_title .= " / " . $nb_boot . " boot";
198   if ($nb_boot < 2 ) 
199     $nodes_title = plc_warning_html ($nodes_title);
200   $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
201
202   $toggle=new PlekitToggle ('nodes',$nodes_title);
203   $toggle->start();
204
205   $headers=array();
206   $headers['hostname']='string';
207   $headers['state']='string';
208
209   $table = new PlekitTable ('nodes',$headers,'0',array('search_area'=>false,
210                                                     'notes_area'=>false,
211                                                     'pagesize_area'=>false));
212   $table->start();
213   foreach ($nodes as $node) {
214     $table->row_start();
215     $table->cell (l_node_obj($node));
216     $table->cell ($node['boot_state']);
217     $table->row_end();
218   }
219   $table->tfoot_start();
220   $table->row_start();
221   $button=new PlekitFormButton (l_node_add(),"node_add","Add node","POST");
222   $table->cell($button->html(),$table->columns(),"right");
223   $table->row_end();
224   $table->end();
225   $toggle->end();
226     
227   //////////////////// Users
228   $persons_title = "Users : ";
229   $persons_title .= count($person_ids) . " total";
230   $persons_title .= " / " . count ($pis) . " PIs";
231   $persons_title .= " / " . count ($techs) . " Techs";
232   if ($has_disabled_persons) 
233     $persons_title .= " / " . count($disabled_persons) . " Disabled";
234   if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 ) 
235     $persons_title = plc_warning_html ($persons_title);
236   $persons_title .= href(l_persons_site($site_id)," (See as users)");
237
238   $toggle=new PlekitToggle ('persons',$persons_title);
239   $toggle->start();
240
241   $headers = array ();
242   $headers["email"]='string';
243   $headers["PI"]='string';
244   $headers['User']='string';
245   $headers["Tech"]='string';
246   if ($has_disabled_persons) $headers["Disabled"]='string';
247   $table=new PlekitTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
248                                                          'notes_area'=>false,
249                                                          'pagesize_area'=>false));
250   $table->start();
251   foreach ($persons as $person) {
252     $table->row_start();
253     $table->cell(l_person_obj($person));
254     $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
255     $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
256     $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
257     if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : "yes");
258     $table->row_end();
259   }
260   $table->end();
261   $toggle->end();
262
263   //////////////////// Slices
264   // xxx to review after slices gets reworked
265   $toggle=new PlekitToggle ('slices',"Slices");
266   $toggle->start();
267   $details=new PlekitDetails (false);
268   $details->start();
269   // summary on slices
270   $slice_label = count($slice_ids) . " running / " . $max_slices . " max";
271   if (count($slice_ids) >= $max_slices) 
272     $slice_label = plc_warning_html ($slice_label);
273   $details->th_td("# Slices", href(l_slices_site($site_id),$slice_label));
274   if ($slices) foreach ($slices as $slice)
275      $details->th_td($slice['instantiation'],l_slice_obj($slice));
276   $button=new PlekitFormButton (l_slice_add(),"slice_add","Add slice","POST");
277   $details->tr($button->html(),"right");
278   $details->end();
279   $toggle->end();
280
281   // Addresses
282   $toggle=new PlekitToggle ('addresses',"Addresses",array('start-visible'=>false));
283   $toggle->start();
284   if ( ! $addresses) {
285     print "<p class='addresses'>No known address for this site</p>";
286   } else {
287     $details=new PlekitDetails (false);
288     $details->start();
289     $details->th_td("Addresses","");
290     foreach ($addresses as $address) {
291       $details->th_td(plc_vertical_table($address['address_types']),
292                        plc_vertical_table(array($address['line1'],
293                                                 $address['line2'],
294                                                 $address['line3'],
295                                                 $address['city'],
296                                                 $address['state'],
297                                                 $address['postalcode'],
298                                                 $address['country'])));
299     }
300     $details->end();
301   }
302   $toggle->end();
303
304  }
305
306 ////////////////////////////////////////
307 $peers->block_end($peer_id);
308
309 //plekit_linetabs ($tabs,"bottom");
310
311 // Print footer
312 include 'plc_footer.php';
313
314 ?>