X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fsites%2Findex.php;h=a8719482130786dbffcefb1d9a639266d6909bbe;hb=9fea82d06df5c051a457045595aa682c56cddefd;hp=4b7443f947bf354702f4925d244e485e2684755a;hpb=7772d4ba04b97c8a32f3b9baf680ce4a76da1e25;p=plewww.git diff --git a/planetlab/sites/index.php b/planetlab/sites/index.php index 4b7443f..a871948 100644 --- a/planetlab/sites/index.php +++ b/planetlab/sites/index.php @@ -1,445 +1,11 @@ person; -$_roles= $_person['role_ids']; - -//////////////////// -// The set of columns to fetch -// and the filter applied for fetching sites -if ( !in_array( '10', $_roles ) ) { - $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" ); - $filter = array ("enabled" => TRUE); - } else { - $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids"); - $filter = array (); - } - - -////////////////// -// perform post-processing on site objects as returned by GetSites -// performs sanity check and summarize the result in a single column -// performs in-place replacement, so passes a reference -function layout_site ($site) { - - // we need the 'enabled' field to do this - // so regular users wont run this - if ( ! array_key_exists ('enabled', $site)) - return $site; - - $messages=array(); - - if (empty ($site['node_ids'])) $messages [] = "Site has no node"; - $class='plc-foreign'; - - // do all this stuff on local sites only - if ( ! $site['peer_id'] ) { - - $class='plc-warning'; - - // check that site is enabled - if ( ! $site['enabled']) { - $messages [] = "Not enabled"; - } - - // check that site has at least a PI and a tech - global $api; - $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids")); - $nb_pis=0; - $nb_tech=0; - - if ( ! empty ($persons)) { - foreach ($persons as $person) { - if (in_array( '20', $person['role_ids'])) $nb_pis += 1; - if (in_array( '40', $person['role_ids'])) $nb_techs += 1; - } - } - if ($nb_pis == 0) $messages [] = "Site has no PI"; - if ($nb_techs == 0) $messages [] = "Site has no Tech"; - - // check number of slices - if ( $site['max_slices'] == 0) { - $messages [] = "No slice allowed"; - } else if (count($site["slice_ids"]) >= $site['max_slices']) { - $messages [] = "Site has no slice left"; - } - - // pretty print the cell - } - // but always cleanup $site columns - unset ($site['enabled']); - unset ($site['person_ids']); - unset ($site['max_slices']); - unset ($site['slice_ids']); - unset ($site['node_ids']); - $site['sanity check'] = plc_vertical_table($messages,$class); - - return $site; -} - - -// if sitepattern or peerscope is set : search the sites -// we use GET rather than POST so paginate can display the right contents on subsequent pages -// can be useful for writing bookmarkable URL's as well -if( $_GET['sitepattern'] || $_GET['peerscope']) { - $sitename= $_GET['sitepattern']; - if (empty($sitename)) { - $sitename="*"; - } - $filter = array_merge (array( "name"=>$sitename ), $filter); - switch ($_GET['peerscope']) { - case '': - $peer_label="all peers"; - break; - case 'local': - $filter=array_merge(array("peer_id"=>NULL),$filter); - $peer_label="local peer"; - break; - case 'foreign': - $filter=array_merge(array("~peer_id"=>NULL),$filter); - $peer_label="foreign peers"; - break; - default: - $peer_id=intval($_GET['peerscope']); - $filter=array_merge(array("peer_id"=>$peer_id),$filter); - $peer=$api->GetPeers(array("peer_id"=>$peer_id)); - $peer_label='peer "' . $peer[0]['peername'] . '"'; - break; - } - - $sites= $api->GetSites( $filter , $site_columns); - $sites = array_map(layout_site,$sites); - - $sites_count = count ($sites); - if ( $sites_count == 1) { - header( "location: index.php?id=". $sites[0]['site_id'] ); - exit(); - } else if ( $sites_count == 0) { - echo " No site matching $sitename on " . $peer_label . " "; - } else { - drupal_set_title ("Sites matching $sitename on " . $peer_label); - sort_sites ($sites); - echo paginate( $sites, "site_id", "Sites", 25, "name"); - } -} - - -// if no site id, display list of sites to choose -elseif( !$_GET['id'] ) { - - // GetSites API call - // careful, need to pass NULL and *not* array() if no filter is given - $sites= $api->GetSites( empty($filter) ? NULL : $filter, $site_columns ); - $sites = array_map(layout_site,$sites); - if ( empty ($sites)) { - echo "No site to display"; - } else { - sort_sites( $sites ); - - drupal_set_html_head(' - - '); - - echo "
\n -
\n"; - echo "\n -\n -\n -\n - -\n -\n -
\n -
\n"; - - echo paginate( $sites, "site_id", "Sites", 25, "name" ); - - echo "\n"; - } -} -else { - // stores get variable and casts it as int - $site_id= intval( $_GET['id'] ); - - // api call GetSites - $site_info= $adm->GetSites( array( $site_id ) ); - - // var names to api return - $sitename= $site_info[0]['name']; - $abbrev_name= $site_info[0]['abbreviated_name']; - $site_url= $site_info[0]['url']; - $login_base= $site_info[0]['login_base']; - $site_lat= $site_info[0]['latitude']; - $site_long= $site_info[0]['longitude']; - $max_slivers= $site_info[0]['max_slivers']; - $max_slices= $site_info[0]['max_slices']; - - $enabled = $site_info[0]['enabled']; - - // peer id - $peer_id= $site_info[0]['peer_id']; - - $site_addresses= $site_info[0]['address_ids']; - $site_pcus= $site_info[0]['pcu_ids']; - $site_nodes= $site_info[0]['node_ids']; - $site_persons= $site_info[0]['person_ids']; - $site_slices= $site_info[0]['slice_ids']; - - $adm->begin(); - // gets address info - $adm->GetAddresses( $site_addresses ); - - // gets pcu info - $adm->GetPCUs( $site_pcus ); - - // gets node info - $adm->GetNodes( $site_nodes, array( "node_id", "hostname", "boot_state" ) ); - - // gets person info - $adm->GetPersons( $site_persons, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) ); - - $adm->GetSlices ( $site_slices, array ("slice_id", "name", "instantiation" ) ); - - list( $addresses, $pcus, $nodes, $persons, $slices )= $adm->commit(); - - $techs = array(); - $pis = array(); - foreach( $persons as $person ) { - $role_ids= $person['role_ids']; - if( in_array( '40', $role_ids )) - $techs[] = $person; - - if( in_array( '20', $role_ids )) - $pis[] = $person; - - } - - if( $peer_id ) { - echo "
\n"; - } - - // start form - drupal_set_title("Site $sitename details"); - // echo "

$sitename Site details

\n"; - - if( !$peer_id ) { - $actions= array( ''=>'Choose Action' ); - - if( in_array( 10, $_roles ) - || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) { - $actions['update']= 'Update Site'; - } - - if( in_array( 10, $_roles ) ) { - $actions['delete']= 'Delete Site'; - $actions['expire']= 'Expire All Slices'; - } - - echo "
"; - if( in_array( 10, $_roles ) ) { - echo plc_event_button("Site","site",$site_id); - echo "\n"; - } - echo plc_comon_button("site_id",$site_id); - // comon link - echo ""; - - // list to take site action - echo "
\n"; - echo "\n"; - echo "\n"; - echo "
"; - - echo "
\n"; - } - - - if ( ! $enabled ) { - echo "

This site is not enabled - Please visit this page to review pending applications.

"; - } - - // basic site info - echo "

\n - \n - \n - \n - \n - \n - \n"; - - if( $peer_id ) { - // display peer name - echo "\n"; - $peer = $api->GetPeers(array('peer_id'=>$peer_id)); - echo ""; - // we wrap up everything here - // the local version closes the table in the middle of the page... - echo "
Full name: $sitename
Login base: $login_base
Abbreviated Name: $abbrev_name
URL: $site_url
Latitude: $site_lat
Longitude: $site_long
Managed at foreign peer:" . $peer[0]['peername'] . "
"; - echo "

"; - - } else { - - // Slices - echo "\n"; - $href="'/db/slices/index.php?site_id=" . $site_id . "'"; - $slice_text="" . count($site_slices) . "/" . $max_slices; - if (count($site_slices) >= $max_slices) { - $slice_text .= " Maximum number of slices reached !"; - } - printf("# Slices Used/Allocated: %s\n",$href,$href,$slice_text); - if ( ! empty ($site_slices)) { - foreach ($slices as $slice) { - $href="'/db/slices/index.php?id=" . $slice['slice_id'] . "'"; - printf (" %s %s \n", - $href,$slice['name'],$href,$slice['instantiation']); - } - } - - // Users - echo "\n"; - $href="'/db/persons/index.php?site_id=" . $site_id . "'"; - printf (" # UsersTotal %d users\n",$href,$href,count($site_persons)); - - echo "PI(s)"; - if ( ! $pis) { - echo "Site has no PI !!"; - } else { - echo ""; - foreach( $pis as $person ) { - echo "\n"; - } - echo "
"; - if ( ! $person['enabled'] ) { - printf(" %s (not enabled yet)
\n",$person['person_id'],$person['email']); - } else { - printf("%s
\n",$person['person_id'],$person['email']); - } - echo "
\n"; - } - echo "\n"; - - echo "Tech(s)"; - if ( ! $techs) { - echo "Site has no Technical contact !!"; - } else { - echo ""; - foreach( $techs as $person ) { - echo "\n"; - } - echo "
"; - if ( ! $person['enabled'] ) { - printf(" %s (not enabled yet)
\n",$person['person_id'],$person['email']); - } else { - printf("%s
\n",$person['person_id'],$person['email']); - } - echo "
\n"; - } - echo "\n"; - - // Nodes - echo "\n"; - $href="'/db/nodes/index.php?site_id=" . $site_id . "'"; - printf ("# Nodes",$href); - if (empty ($site_nodes)) { - $right_site = in_array($site_id,$_person['site_ids']); - $right_role = in_array(30,$_roles) || in_array(40,$_roles); - $can_add = $right_site && $right_role; - if ($can_add) { - $href_node_add = "'/db/nodes/node_add.php'"; - printf ("0 Site has no node, please add one",$href_node_add); - } else { - printf ("0 Site has no node",$href); - } - } else { - printf ("%d",$href,count($nodes)); - } - echo ""; - - if( !empty( $site_nodes ) ) { - foreach( $nodes as $node ) { - echo "". $node['hostname'] ."". $node['boot_state'] ."\n"; - } - - } - - echo "\n"; - - // Addresses - echo "
\n"; - - // if there is an address list it. - if( !empty( $addresses ) ) { - echo "

Addresses

\n"; - - foreach( $addresses as $address ) { - echo "

\n\n\n\n\n
"; - - $comma= count( $address['address_types'] ); - $count= 0; - foreach( $address['address_types'] as $add_type ) { - echo $add_type; - $count++; - if ( $comma > 0 && $count != $comma ) - echo ", "; - } - - echo "
". $address['line1'] ."
". $address['line2'] ."
". $address['line3'] ."
". $address['city'] .", ". $address['state'] ." ". $address['postalcode'] ."
". $address['country'] ."

\n"; - } - - } - else { - echo "Site has no addresses. \n"; - } - - // if eligable display add address - /*if( in_array( '10', $_roles ) || in_array( '20', $_roles ) ) - echo "

Add an address\n";*/ - - } - - echo "


Back to site list"; - -} - - -// Print footer -include 'plc_footer.php'; +if ($_GET['id']) require ('site.php') ; +else require ('sites.php'); ?>