2 // $Id: index.php 1162 2008-01-24 19:13:12Z thierry $
6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api, $adm;
13 require_once 'plc_drupal.php';
15 drupal_set_title('Sites');
16 include 'plc_header.php';
19 require_once 'plc_functions.php';
20 require_once 'plc_sorts.php';
23 $_person= $plc->person;
24 $_roles= $_person['role_ids'];
27 // The set of columns to fetch
28 // and the filter applied for fetching sites
29 if ( !in_array( '10', $_roles ) ) {
30 $columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
31 $filter = array ("enabled" => TRUE);
33 $columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
39 // perform post-processing on site objects as returned by GetSites
40 // performs sanity check and summarize the result in a single column
41 // performs in-place replacement, so passes a reference
42 function layout_site ($site) {
44 // we need the 'enabled' field to do this
45 // so regular users wont run this
46 if ( ! array_key_exists ('enabled', $site))
51 if (empty ($site['node_ids'])) $messages [] = "Site has no node";
54 // do all this stuff on local sites only
55 if ( ! $site['peer_id'] ) {
59 // check that site is enabled
60 if ( ! $site['enabled']) {
61 $messages [] = "Not enabled";
64 // check that site has at least a PI and a tech
66 $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
70 if ( ! empty ($persons)) {
71 foreach ($persons as $person) {
72 if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
73 if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
76 if ($nb_pis == 0) $messages [] = "Site has no PI";
77 if ($nb_techs == 0) $messages [] = "Site has no Tech";
79 // check number of slices
80 if ( $site['max_slices'] == 0) {
81 $messages [] = "No slice allowed";
82 } else if (count($site["slice_ids"]) >= $site['max_slices']) {
83 $messages [] = "Site has no slice left";
86 // pretty print the cell
88 // but always cleanup $site columns
89 unset ($site['enabled']);
90 unset ($site['person_ids']);
91 unset ($site['max_slices']);
92 unset ($site['slice_ids']);
93 unset ($site['node_ids']);
94 $site['sanity check'] = plc_make_table($class,$messages);
100 // if sitepattern or peerscope is set : search the sites
101 // we use GET rather than POST so paginate can display the right contents on subsequent pages
102 // can be useful for writing bookmarkable URL's as well
103 if( $_GET['sitepattern'] || $_GET['peerscope']) {
104 $sitename= $_GET['sitepattern'];
105 if (empty($sitename)) {
108 $filter = array_merge (array( "name"=>$sitename ), $filter);
109 switch ($_GET['peerscope']) {
111 $peer_label="all peers";
114 $filter=array_merge(array("peer_id"=>NULL),$filter);
115 $peer_label="local peer";
118 $filter=array_merge(array("~peer_id"=>NULL),$filter);
119 $peer_label="foreign peers";
122 $peer_id=intval($_GET['peerscope']);
123 $filter=array_merge(array("peer_id"=>$peer_id),$filter);
124 $peer=$api->GetPeers(array("peer_id"=>$peer_id));
125 $peer_label='peer "' . $peer[0]['peername'] . '"';
129 $sites= $api->GetSites( $filter , $columns);
130 $sites = array_map(layout_site,$sites);
132 $sites_count = count ($sites);
133 if ( $sites_count == 1) {
134 header( "location: index.php?id=". $sites[0]['site_id'] );
136 } else if ( $sites_count == 0) {
137 echo "<span class='plc-warning'> No site matching $sitename on " . $peer_label . " </span>";
139 drupal_set_title ("Sites matching $sitename on " . $peer_label);
141 echo paginate( $sites, "site_id", "Sites", 25, "name");
146 // if no site id, display list of sites to choose
147 elseif( !$_GET['id'] ) {
150 // careful, need to pass NULL and *not* array() if no filter is given
151 $sites= $api->GetSites( empty($filter) ? NULL : $filter, $columns );
152 $sites = array_map(layout_site,$sites);
153 if ( empty ($sites)) {
154 echo "No site to display";
156 sort_sites( $sites );
158 drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
159 <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
160 <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
163 <form method=get action='index.php'>\n";
165 <th><label for='testinput'>Enter Site Name or pattern: </label></th>\n
166 <td><input type='text' id='testinput' name='sitepattern' size=40 value='' /></td>\n
167 <td rowspan=2><input type=submit value='Search Sites' /></td>\n
169 <th><label for='peerscope'>Federation scope: </label></th>\n
170 <td><select id='peerscope' name='peerscope' onChange='submit()'>\n
172 echo plc_peers_option_list($api);
173 echo "</select></td>\n
174 </tr></table></form></div>\n
177 echo paginate( $sites, "site_id", "Sites", 25, "name" );
179 echo "<script type=\"text/javascript\">\n
181 script:\"/planetlab/sites/test.php?\",\n
185 var as = new AutoSuggest('testinput', options);\n
190 // stores get variable and casts it as int
191 $site_id= intval( $_GET['id'] );
194 $site_info= $adm->GetSites( array( $site_id ) );
196 // var names to api return
197 $sitename= $site_info[0]['name'];
198 $abbrev_name= $site_info[0]['abbreviated_name'];
199 $site_url= $site_info[0]['url'];
200 $login_base= $site_info[0]['login_base'];
201 $site_lat= $site_info[0]['latitude'];
202 $site_long= $site_info[0]['longitude'];
203 $max_slivers= $site_info[0]['max_slivers'];
204 $max_slices= $site_info[0]['max_slices'];
206 $enabled = $site_info[0]['enabled'];
209 $peer_id= $site_info[0]['peer_id'];
211 $site_addresses= $site_info[0]['address_ids'];
212 $site_pcus= $site_info[0]['pcu_ids'];
213 $site_nodes= $site_info[0]['node_ids'];
214 $site_persons= $site_info[0]['person_ids'];
215 $site_slices= $site_info[0]['slice_ids'];
219 $adm->GetAddresses( $site_addresses );
222 $adm->GetPCUs( $site_pcus );
225 $adm->GetNodes( $site_nodes, array( "node_id", "hostname", "boot_state" ) );
228 $adm->GetPersons( $site_persons, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
230 $adm->GetSlices ( $site_slices, array ("slice_id", "name", "instantiation" ) );
232 list( $addresses, $pcus, $nodes, $persons, $slices )= $adm->commit();
236 foreach( $persons as $person ) {
237 $role_ids= $person['role_ids'];
238 if( in_array( '40', $role_ids ))
241 if( in_array( '20', $role_ids ))
247 echo "<div class='plc-foreign'>\n";
251 drupal_set_title("Site $sitename details");
252 // echo "<h3>$sitename Site details</h3>\n";
255 $actions= array( ''=>'Choose Action' );
257 if( in_array( 10, $_roles )
258 || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) {
259 $actions['update']= 'Update Site';
262 if( in_array( 10, $_roles ) ) {
263 $actions['delete']= 'Delete Site';
264 $actions['expire']= 'Expire All Slices';
267 echo "<table> <tr><td>";
268 if( in_array( 10, $_roles ) ) {
269 echo plc_event_button("Site","site",$site_id);
272 echo plc_comon_button("site_id",$site_id);
276 // list to take site action
277 echo "<form action='/db/sites/site_action.php' method='post'>\n";
278 echo "<input type=hidden name=site_id value=$site_id>\n";
279 echo "<select name='actions' onChange=\"submit();\">\n";
280 foreach( $actions as $key => $val ) {
281 echo "<option value='$key'";
282 if( $key == $_POST['actions'] ) {
290 echo "</td></tr></table>\n";
295 echo "<p class='plc-warning'> This site is not enabled - Please visit <a href='/db/sites/join_request.php'> this page </a> to review pending applications. </p>";
299 echo "<p><table class='list_set' border=0>\n
300 <tr class='list_set'><th>Full name: </th><td class='list_set'> $sitename</td></tr>\n
301 <tr class='list_set'><th>Login base: </th><td class='list_set'> $login_base</td></tr>\n
302 <tr class='list_set'><th>Abbreviated Name: </th><td class='list_set'> $abbrev_name</td></tr>\n
303 <tr class='list_set'><th>URL: </th><td class='list_set'> <a href='$site_url'>$site_url</a></td></tr>\n
304 <tr class='list_set'><th>Latitude: </th><td class='list_set'> $site_lat</td></tr>\n
305 <tr class='list_set'><th>Longitude: </th><td class='list_set'> $site_long</td></tr>\n";
309 echo "<tr><th></th><td></td></tr>\n";
310 $peer = $api->GetPeers(array('peer_id'=>$peer_id));
311 echo "<tr><th>Managed at foreign peer:</th><td>" . $peer[0]['peername'] . "</td></tr>";
312 // we wrap up everything here
313 // the local version closes the table in the middle of the page...
320 echo "<tr><th></th><td></td></tr>\n";
321 $href="'/db/slices/index.php?site_id=" . $site_id . "'";
322 $slice_text="" . count($site_slices) . "/" . $max_slices;
323 if (count($site_slices) >= $max_slices) {
324 $slice_text .= " <span class='plc-warning'>Maximum number of slices reached !</span>";
326 printf("<tr><th><a href=%s># Slices Used/Allocated:</a> </th><td> <a href=%s>%s</a></td></tr>\n",$href,$href,$slice_text);
327 if ( ! empty ($site_slices)) {
328 foreach ($slices as $slice) {
329 $href="'/db/slices/index.php?id=" . $slice['slice_id'] . "'";
330 printf ("<tr><td><a href=%s> %s</a></td><td> <a href=%d> %s </a> </td> </tr>\n",
331 $href,$slice['name'],$href,$slice['instantiation']);
336 echo "<tr><th></th><td></td></tr>\n";
337 $href="'/db/persons/index.php?site_id=" . $site_id . "'";
338 printf ("<tr><th> <a href=%s># Users</a></th><td><a href=%s>Total %d users</a></td>\n",$href,$href,count($site_persons));
340 echo "<tr><th>PI(s)</th><td>";
342 echo "<span class='plc-warning'>Site has no PI !!</span>";
344 echo "<table border=0>";
345 foreach( $pis as $person ) {
347 if ( ! $person['enabled'] ) {
348 printf("<span class='plc-warning'> <a href='/db/persons/index.php?id=%d'>%s</a> (not enabled yet)</span><br />\n",$person['person_id'],$person['email']);
350 printf("<a href='/db/persons/index.php?id=%d'>%s</a><br />\n",$person['person_id'],$person['email']);
358 echo "<tr><th>Tech(s)</th><td>";
360 echo "<span class='plc-warning'>Site has no Technical contact !!</span>";
362 echo "<table border=0>";
363 foreach( $techs as $person ) {
365 if ( ! $person['enabled'] ) {
366 printf("<span class='plc-warning'> <a href='/db/persons/index.php?id=%d'>%s</a> (not enabled yet)</span><br />\n",$person['person_id'],$person['email']);
368 printf("<a href='/db/persons/index.php?id=%d'>%s</a><br />\n",$person['person_id'],$person['email']);
377 echo "<tr><th></th><td></td></tr>\n";
378 $href="'/db/nodes/index.php?site_id=" . $site_id . "'";
379 printf ("<tr><th><a href=%s># Nodes</a></th>",$href);
380 if (empty ($site_nodes)) {
381 $right_site = in_array($site_id,$_person['site_ids']);
382 $right_role = in_array(30,$_roles) || in_array(40,$_roles);
383 $can_add = $right_site && $right_role;
385 $href_add_node = "'/db/nodes/add_node.php'";
386 printf ("<td><a href=%s>0 <span class='plc-warning'>Site has no node, please add one</span></a></td>",$href_add_node);
388 printf ("<td><a href=%s>0 <span class='plc-warning'>Site has no node</span></a></td>",$href);
391 printf ("<td><a href=%s>%d</a></td>",$href,count($nodes));
395 if( !empty( $site_nodes ) ) {
396 foreach( $nodes as $node ) {
397 echo "<tr><td><a href='/db/nodes/index.php?id=". $node['node_id'] ."'>". $node['hostname'] ."</a></td><td class='list_set'>". $node['boot_state'] ."</td></tr>\n";
407 // if there is an address list it.
408 if( !empty( $addresses ) ) {
409 echo "<h4>Addresses</h4>\n";
411 foreach( $addresses as $address ) {
412 echo "<p><table cellpadding=2><tbody><tr><td><a href='/db/addresses/index.php?id=". $address['address_id'] ."'>";
414 $comma= count( $address['address_types'] );
416 foreach( $address['address_types'] as $add_type ) {
419 if ( $comma > 0 && $count != $comma )
423 echo "</a></td></tr>\n<tr><td>". $address['line1'] ."</td></tr>\n</tr><td>". $address['line2'] ."</td></tr>\n<tr><td>". $address['line3'] ."</td></tr>\n<tr><td>". $address['city'] .", ". $address['state'] ." ". $address['postalcode'] ."</td></tr>\n<tr><td>". $address['country'] ."</td></tr></tbody></table></p>\n";
428 echo "Site has no addresses. \n";
431 // if eligable display add address
432 /*if( in_array( '10', $_roles ) || in_array( '20', $_roles ) )
433 echo "<br /><p><a href='/db/addresses/add_address.php'>Add an address</a>\n";*/
437 echo "<br /><hr /><p><a href='/db/sites/index.php'>Back to site list</a>";
443 include 'plc_footer.php';