<ol>
<li>
<strong>Use your administrator account</strong>
- Enter the site using the credentials that you have provided when configuring MyPLC (see PLC_ROOT_USER and PLC_ROOT_PASSWORD). This account has full administration rights and will allows to configure your website using Drupal tools.
+ Enter the site using the credentials that you have provided when configuring MyPLC (see PLC_ROOT_USER and PLC_ROOT_PASSWORD). This account has full administration rights and allows you to configure your website using Drupal tools.
</li>
<li>
<strong>Configure your website</strong>
$site_item = '';
$site_item .= href(l_sites(),"Sites");
$site_item .= ul_start();
- $site_item .= leaf( href(l_site_u(plc_my_site_id()),"My site"));
+ $site_item .= leaf( href(l_site(plc_my_site_id()),"My site"));
if ( $is_admin )
$site_item .= leaf( href(l_site_pending(),"Pending Requests"));
if( $is_admin )
$user_item = '';
$user_item .= href(l_persons(),'Users');
$user_item .= ul_start();
- $user_item .= leaf( href(l_person_u(plc_my_person_id()),"My account"));
+ $user_item .= leaf( l_person_t(plc_my_person_id(),"My account"));
if (is_pi)
$user_item .= leaf( href( l_persons_site(plc_my_site_id()), "My users"));
if ( $plc->alt_person && $plc->alt_auth) {
width:100%;
border:1px;
}
-.pagesize_label{
- font-weight:bold;
+.pagesize_label, .pagesize_input {
+ font-style: oblique;
+ font-size: .5em;
}
.table_search_label{
font-weight:bold;
}
td.sized3 {
width:7em;
- text-align:left;
+ text-align:left;
}
/*
tfoot td
//////////////////////////////////////////////////////////// links
function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>"; }
-function l_nodes () { return "/db/nodes/index.php"; }
-function l_node_u ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
-function l_node ($node_id) { return href (l_node_u($node_id),$node_id); }
-function l_node2 ($node_id,$text) { return href (l_node_u($node_id),$text); }
-function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=" . $site_id; }
-function l_node_add () { return "/db/nodes/add_node.php"; }
-
-function l_interface_u ($interface_id) { return "/db/nodes/interfaces.php?id=" . $interface_id; }
-function l_interface_add_u($node_id) { return "/db/nodes/interfaces.php?node_id=" . $node_id; }
-function l_interface ($interface_id) { return href (l_interface_u($interface_id),$interface_id); }
-function l_interface2 ($interface_id,$text) { return href (l_interface_u($interface_id),$text); }
-
-function l_sites () { return "/db/sites/index.php"; }
-function l_site_u ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
-function l_site ($site_id) { return href (l_site_u($site_id),$site_id); }
-function l_site2 ($site_id,$text) { return href (l_site_u($site_id),$text); }
-
-function l_slices () { return "/db/slices/index.php"; }
-function l_slice_u ($slice_id) { return "/db/slices/index.php?id=" . $slice_id; }
-function l_slice ($slice_id) { return href (l_slice_u($slice_id),$slice_id); }
-function l_slice2 ($slice_id,$text) { return href (l_slice_u($slice_id),$text); }
-function l_slice_add () { return "/db/slices/add_slice.php"; }
-
-function l_sliver_u ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=" . $node_id. "&slice_id=" . $slice_id; }
-function l_sliver3 ($node_id,$slice_id,$text) { return href (l_sliver_u($node_id,$slice_id),$text) ; }
-
-function l_persons () { return "/db/persons/index.php"; }
-function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=" . $site_id; }
-function l_person_u ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
-function l_person ($person_id) { return href (l_person_u($person_id),$person_id); }
-function l_person2 ($person_id,$text) { return href (l_person_u($person_id),$text); }
-
-function l_tags () { return "/db/tags/index.php"; }
-function l_tags_node () { return "/db/tags/index.php?type=node"; }
+// naming scheme is
+// l_objects() -> the url to the page that list objects
+// l_object($object_id) -> the url to hte page thas details object with given id
+// l_object_t($object_id,text) -> an <a> tag that shows text and links to the above
+// l_object_add () -> the url to that object-afding page
+
+function l_nodes () { return "/db/nodes/index.php"; }
+function l_node ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
+function l_node_t ($node_id,$text) { return href (l_node($node_id),$text); }
+function l_node_add () { return "/db/nodes/add_node.php"; }
+function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=" . $site_id; }
+
+function l_interface ($interface_id) { return "/db/nodes/interfaces.php?id=" . $interface_id; }
+function l_interface_t ($interface_id,$text) {
+ return href (l_interface($interface_id),$text); }
+function l_interface_add($node_id) { return "/db/nodes/interfaces.php?node_id=" . $node_id; }
+
+function l_sites () { return "/db/sites/index.php"; }
+function l_site ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
+function l_site_t ($site_id,$text) { return href (l_site($site_id),$text); }
+
+function l_slices () { return "/db/slices/index.php"; }
+function l_slice ($slice_id) { return "/db/slices/index.php?id=" . $slice_id; }
+function l_slice_t ($slice_id,$text) { return href (l_slice($slice_id),$text); }
+function l_slice_add () { return "/db/slices/add_slice.php"; }
+
+function l_sliver ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=" . $node_id. "&slice_id=" . $slice_id; }
+function l_sliver_t ($node_id,$slice_id,$text) {
+ return href (l_sliver($node_id,$slice_id),$text) ; }
+
+function l_persons () { return "/db/persons/index.php"; }
+function l_person ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
+function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); }
+function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=" . $site_id; }
+
+function l_tags () { return "/db/tags/index.php"; }
+function l_tags_node () { return "/db/tags/index.php?type=node"; }
# xxx cleanup duplicate pages
-#function l_tags_interface () { return "/db/tags/index.php?type=interface"; }
-function l_tags_interface () { return "/db/nodes/settings.php"; }
-function l_tags_slice () { return "/db/tags/index.php?type=slice"; }
-
-function l_nodegroups () { return "/db/tags/node_groups.php"; }
-function l_nodegroup_u ($nodegroup_id) { return "/db/tags/node_groups.php?id=" . $nodegroup_id; }
-function l_nodegroup2 ($nodegroup_id,$text) { return href(l_nodegroup_u($nodegroup_id),$text); }
-
-function l_events () { return '/db/events/index.php'; }
-function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
-
-function l_peers() { return "/db/peers/index.php"; }
-function l_peer_u($peer_id) { return "/db/peers/index.php?id=" . $peer_id; }
-function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
-function l_sirius() { return "/db/sirius/index.php"; }
-function l_about() { return "/db/about.php"; }
-function l_doc_plcapi() { return "/db/doc/PLCAPI.php"; }
-function l_doc_nmapi() { return "/db/doc/NMAPI.php"; }
-
-function l_logout() { return "/planetlab/logout.php"; }
-function l_sulogout() { return "/planetlab/sulogout.php"; }
-function l_reset_password() { return "/db/persons/reset_password.php"; }
-function l_person_register() { return "/db/persons/register.php"; }
-function l_site_register() { return "/db/sites/register.php"; }
-function l_site_pending() { return "/db/sites/join_request.php"; }
-function l_site_status() { return "/db/sites/peers.php"; }
+#function l_tags_interface () { return "/db/tags/index.php?type=interface"; }
+function l_tags_interface () { return "/db/nodes/settings.php"; }
+function l_tags_slice () { return "/db/tags/index.php?type=slice"; }
+
+function l_nodegroups () { return "/db/tags/node_groups.php"; }
+function l_nodegroup ($nodegroup_id) { return "/db/tags/node_groups.php?id=" . $nodegroup_id; }
+function l_nodegroup_t ($nodegroup_id,$text) {
+ return href(l_nodegroup($nodegroup_id),$text); }
+
+function l_events () { return '/db/events/index.php'; }
+function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
+
+function l_peers() { return "/db/peers/index.php"; }
+function l_peer($peer_id) { return "/db/peers/index.php?id=" . $peer_id; }
+
+function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
+function l_sirius() { return "/db/sirius/index.php"; }
+function l_about() { return "/db/about.php"; }
+function l_doc_plcapi() { return "/db/doc/PLCAPI.php"; }
+function l_doc_nmapi() { return "/db/doc/NMAPI.php"; }
+
+function l_logout() { return "/planetlab/logout.php"; }
+function l_sulogout() { return "/planetlab/sulogout.php"; }
+function l_reset_password() { return "/db/persons/reset_password.php"; }
+function l_person_register() { return "/db/persons/register.php"; }
+function l_site_register() { return "/db/sites/register.php"; }
+function l_site_pending() { return "/db/sites/join_request.php"; }
+function l_site_status() { return "/db/sites/peers.php"; }
//////////////////////////////////////////////////////////// validation functions
function topdomain ($hostname) {
}
// to set the background to grey on foreign objects
+// return true if the peer is local
function plc_peer_block_start ($peer_hash,$peer_id) {
if ( ! $peer_id ) {
print "<div>";
+ return true;
} else {
// set two classes, one eneraic to all foreign, and one based on the peer's shortname for finer grain tuning
printf ('<div class="plc-foreign plc-%s>"',strtolower(plc_peer_shortname($peer_hash,$peer_id)));
+ return false;
}
}
function t_slice ($slice) { return " running slice " . $slice['name'] . " (" . $slice['slice_id'] . ")"; }
//////////////////////////////////////////////////////////// nav tabs
-function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node_u($node_id)); }
-function tabs_site($site) { return array('Site ' . $site['name']=>l_site_u($site_id)); }
-function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice_u($slice_id)); }
+function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node($node_id)); }
+function tabs_site($site) { return array('Site ' . $site['name']=>l_site($site_id)); }
+function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice($slice_id)); }
//////////////////////////////////////////////////////////// presentation
// builds a table from an array of strings, with the given class
// table_id: <table>'s id tag
// headers: an associative array "label"=>"type"
// column_sort: the column to sort on at load-time
-// options : an associative array to override options:
-// - search_area : boolean
+// options : an associative array to override options (should be passed to both _stsart and _end)
+// - search_area : boolean (default true)
+// - notes_area : boolean (default true)
// - pagesize: the initial pagination size
// - pagesize_def: the page size when one clicks the pagesize reset button
// - max_pages: the max number of pages to display in the paginator
-function plc_table_start ($table_id, $headers, $column_sort,
- $options=array()) {
- $search_area= array_key_exists('search_area',$options) ? $options['search_area'] : true;
- $max_pages= array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
- $pagesize= array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
- $pagesize_def= array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
-
- if ($search_area) {
+function plc_table_start ($table_id, $headers, $column_sort, $options) {
+ $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true;
+ $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
+ $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
+ $pagesize_def = array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
+
+ if ($search_area)
plc_table_search_area($table_id,$pagesize,$pagesize_def);
- }
plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
}
-function plc_table_end () {
+function plc_table_end ($options) {
plc_table_foot();
+ $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true;
+ if ($notes_area)
+ plc_table_notes();
}
////////////////////
<?php
if ( $success ) {
- $link=l_node2($node_id,"here");
+ $link=l_node_t($node_id,"here");
drupal_set_title('Node created');
print <<< EOF
drupal_set_title("Details for node " . $hostname);
// extra privileges to admins, and (pi||tech) on this site
- $extra_privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
+ $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
$tabs=array();
// available actions
- if ( ! $peer_id && $extra_privileges ) {
+ if ( ! $peer_id && $privileges ) {
$tabs['Update'] = array ('url'=>"/db/nodes/node_actions.php",
'method'=>'POST',
'values'=>array('action'=>'delete','node_id'=>$node_id),
'confirm'=>'Are you sure to delete ' . $hostname. ' ?');
// xxx subject to roles
- $tabs["Add Interface"]=l_interface_add_u($node_id);
+ $tabs["Add Interface"]=l_interface_add($node_id);
$tabs["Comon"]=l_comon("node_id",$node_id);
$tabs["Events"]=l_event("Node","node",$node_id);
}
echo "</td></tr>\n";
// same here for the download area
- if ( ! $peer_id && $extra_privileges) {
+ if ( ! $peer_id && $privileges) {
echo "<tr><th>Download </th><td>";
echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
// site info and all site nodes
plc_details_space_line ();
- plc_details_line("Site",l_site2($site_id,$site_name));
+ plc_details_line("Site",l_site_t($site_id,$site_name));
// build list of node links
$nodes_area=array();
foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
- $nodes_area []= l_node2($hash_node_id,$hash_hostname);
+ $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
}
plc_details_line_list ("All site nodes",$nodes_area);
$columns['Peer']="string";
$columns['Name']="string";
$columns['Slivers']="string";
- plc_table_start ("slivers",$columns,1);
+ $table_options = array('notes_area'=>false);
+ plc_table_start ("slivers",$columns,1,$table_options);
foreach ($slices as $slice) {
plc_table_row_start($slice['name']);
plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
- plc_table_cell (l_slice2 ($slice['slice_id'],$slice['name']));
- plc_table_cell (l_sliver3 ($node_id,$slice['slice_id'],'view'));
+ plc_table_cell (l_slice_t ($slice['slice_id'],$slice['name']));
+ plc_table_cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
plc_table_row_end();
}
- plc_table_end();
+ plc_table_end($table_options);
}
//////////////////////////////////////////////////////////// interfaces
echo "<p><span class='plc-warning'>No interface</span>. Please add an interface to make this a usable PLC node</p>.\n";
} else {
$columns=array();
- if ( $extra_privileges ) {
+ if ( $privileges ) {
// a single symbol, marking 'p' for primary and a delete button for non-primary
$columns[' ']='string';
}
print "<hr/>\n";
plc_table_title('Interfaces');
- plc_table_start("interfaces",$columns,2,array('search_area'=>false));
+ $table_options=array('search_area'=>false);
+ plc_table_start("interfaces",$columns,2,$table_options);
foreach ( $interfaces as $interface ) {
$interface_id= $interface['interface_id'];
$interface_method= $interface['method'];
plc_table_row_start($interface['ip']);
- if ( $extra_privileges ) {
+ if ( $privileges ) {
if (!$interface_primary) {
// xxx
plc_table_cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1',
plc_table_cell('p');
}
}
- plc_table_cell(l_interface2($interface_id,$interface_ip));
+ plc_table_cell(l_interface_t($interface_id,$interface_ip));
plc_table_cell($interface_method);
plc_table_cell($interface_type);
plc_table_cell($interface_mac);
plc_table_cell($interface_bwlimit);
plc_table_row_end();
}
- plc_table_end();
+ plc_table_end($table_options);
}
}
print "<hr/>\n";
plc_table_title("Nodegroups");
- plc_table_start("nodegroups",$columns,0,array('search_area'=>false));
+ $table_options = array('search_area'=>false);
+ plc_table_start("nodegroups",$columns,0,$table_options);
foreach( $nodegroups as $nodegroup ) {
plc_table_row_start();
- plc_table_cell(l_nodegroup2($nodegroup_id,$nodegroup['groupname']));
+ plc_table_cell(l_nodegroup_t($nodegroup_id,$nodegroup['groupname']));
$tag_types=$api->GetTagTypes(array($nodegroup['tag_type_id']));
plc_table_cell($tag_types[0]['tagname']);
plc_table_cell($nodegroup['value']);
plc_table_row_end();
}
- plc_table_end();
+ plc_table_end($table_options);
}
////////////////////////////////////////////////////////////
"Float"=>"float");
# initial sort on hostnames
-plc_table_start("nodes",$columns,4);
+$table_options=array();
+plc_table_start("nodes",$columns,4,$table_options);
$peer_hash = plc_peer_get_hash ($api);
// write rows
plc_table_row_start($hostname);
plc_table_cell ($shortname);
plc_table_cell (topdomain($hostname));
- plc_table_cell (l_site2($site_id,$login_base));
+ plc_table_cell (l_site_t($site_id,$login_base));
plc_table_cell ($node['boot_state']);
- plc_table_cell (l_node2($node_id,$hostname));
- plc_table_cell (l_interface2($interface_id,$ip));
+ plc_table_cell (l_node_t($node_id,$hostname));
+ plc_table_cell (l_interface_t($interface_id,$ip));
plc_table_cell ($node_type);
plc_table_cell (node_status($node));
plc_table_cell ($fake1);
$fake_i += 1;
}
-plc_table_end();
-
-plc_table_notes();
+plc_table_end($table_options);
// Print footer
include 'plc_footer.php';
plc_details_start();
plc_details_line("Peer name",$peer['peername']);
plc_details_line("Short name",$peer['shortname']);
-plc_details_line("Hierarchical name","not implemented yet");
+plc_details_line("Hierarchical name",$peer['hrn_root']);
plc_details_line("API URL",$peer['peer_url']);
plc_details_line("Number of sites",sizeof($peer['site_ids']));
'URL'=>'string',
'Comon'=>'string');
- plc_table_start ("peers",$columns,1);
+ $table_options=array('search_area'=>false, 'notes_area'=>false);
+ plc_table_start ("peers",$columns,1,$table_options);
foreach ($peers as $peer) {
plc_table_row_start();
- plc_table_cell (href(l_peer_u($peer['peer_id']),$peer['peername']));
+ plc_table_cell (href(l_peer($peer['peer_id']),$peer['peername']));
plc_table_cell ($peer['shortname']);
// xxx no HRN yet
plc_table_cell ('?');
plc_table_cell (href(l_comon("peer_id",$peer['peer_id']),'Comon'));
plc_table_row_end();
}
+ plc_table_end($table_options);
}
// Print footer
// Require login
require_once 'plc_login.php';
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-// Print header
-require_once 'plc_drupal.php';
-// set default
-drupal_set_title('People');
-include 'plc_header.php';
-
-// Common functions
-require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-
-//fix the memory limit for this page
-ini_set("memory_limit","48M");
-
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-
-////////////////////
-// The set of columns to fetch
-// and the filter applied for fetching sites
-if ( !in_array( '10', $_roles ) ) {
- $columns = array("person_id", "first_name", "last_name", "email", "roles" , "peer_id");
- // PIs can see users not yet enabled
- if ( ! in_array ('20', $_roles) ) {
- $filter = array ("enabled" => TRUE);
- } else {
- $filter = array();
- }
- } else {
- $columns = array("person_id", "first_name", "last_name", "email", "roles" , "peer_id", "key_ids", "enabled","slice_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_person ($person) {
-
- // we need the 'key_ids' field to do this
- // so regular users wont run this
- if ( ! array_key_exists ('key_ids', $person))
- return $person ;
-
- $messages=array();
-
- // do all this stuff on local persons only
- if ( $person['peer_id'] ) {
- $class='plc-foreign';
- } else {
- $class='plc-warning';
- // check that the person has keys, but dont do that for admins
- if ( ! in_array ('admin',$person['roles']) && count($person['key_ids']) == 0)
- $messages [] = "No Key";
- }
- if ( ! $person['enabled'] )
- $messages[] = "Disabled";
- // but always cleanup $person columns
- unset ($person['key_ids']);
- unset ($person['enabled']);
- //detect tech already involved on some slices.
- if( ( count($person['roles'])==1 ) && ( in_array('tech',$person['roles']) ) && (! empty($person["slice_ids"])) ) {
- $messages[]="Tech involved in a Slice";
- }
- // cleanup $person columns
- unset ($person['slice_ids']);
- //display the extra status column
- $person['status'] = plc_vertical_table($messages,$class);
- return $person;
-}
-
-// if emailpattern or peerscope is set then search for Persons.
-// 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['emailpattern'] || $_GET['peerscope']) {
- $emailpattern= $_GET['emailpattern'];
- if (empty($emailpattern)) {
- $emailpattern="*";
- }
- $filter = array_merge (array( "email"=>$emailpattern ), $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;
- }
- // need to use a hash filter for patterns to be properly handled
- $persons= $api->GetPersons($filter , $columns );
- $persons= array_map(layout_person,$persons);
- $person_count = count ($persons);
- if ( $person_count == 1) {
- header( "location: index.php?id=". $persons[0]['person_id'] );
- exit();
- } else if ( $person_count == 0) {
- echo "<span class='plc-warning'> No person whose email matches $emailpattern </span>";
- } else {
- drupal_set_title ("Users matching $emailpattern on ". $peer_label);
- sort_persons ($persons);
- echo paginate( $persons, "person_id", "Persons", 25, "email");
- }
- }
-// if a site_id is given, display the site persons only
-else if( $_GET['site_id'] ) {
- $site_id= $_GET['site_id'];
- // Get site info
- $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "person_ids" ) );
- drupal_set_title("People with " . $site_info[0]['name']);
- // Get site nodes
- $persons= $api->GetPersons( array_merge (array("person_id"=>$site_info[0]['person_ids']),$filter), $columns );
- $persons= array_map(layout_person,$persons);
- sort_persons( $persons );
-
- echo paginate( $persons, "person_id", "Persons", 25, "email" );
-
-}
-// if a slice_id is given,display the persons involved in this slice
-else if( $_GET['slice_id'] ) {
- $slice_id= $_GET['slice_id'];
- // Get slice infos
- $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "person_ids" ) );
- drupal_set_title("People In " . $slice_info[0]['name']);
- // Get slice persons
- $persons= $api->GetPersons( array_merge (array("person_id"=>$slice_info[0]['person_ids']),$filter), $columns );
- if ( empty ($persons) ) {
- echo "No persons to display";
- } else {
-
- $persons= array_map(layout_person,$persons);
- sort_persons( $persons );
-
- echo paginate( $persons, "person_id", "Persons", 25, "email" );
- echo "<br /><p><a href='/db/slices/index.php?id=".$slice_id.">Back to slice page</a></div>";
- }
-
- }
-// if no person id, display list of persons to choose
-elseif( !$_GET['id'] ) {
-
- // GetPersons API call
- $persons= $api->GetPersons( empty($filter) ? NULL : $filter, $columns );
- $persons= array_map(layout_person,$persons);
- sort_persons( $persons );
-
- drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
- <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
- <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
-
- echo "<div>\n
- <form method=get action='index.php'>\n";
- //if( $emailpattern ) echo "<font color=red>'$emailpattern' is not a valid person email.</font>\n";
- echo "<table><tr>\n
-<th><label for='testinput'>Enter Person Email or pattern: : </label></th>\n
-<td><input type='text' id='testinput' name='emailpattern' size=40 value='' /></td>\n
-<td rowspan=2><input type=submit value='Select Person' /></td>\n
-</tr> <tr>
-<th><label for='peerscope'>Federation scope: </label></th>\n
-<td><select id='peerscope' name='peerscope' onChange='submit()'>\n
-";
- echo plc_peers_option_list($api);
- echo "</select></td>\n
-</tr></table></form></div>\n
-<br />\n";
- echo paginate( $persons, "person_id" , "Persons", 25, "email");
- echo "<script type=\"text/javascript\">\n
-var options = {\n
- script:\"/planetlab/persons/test.php?\",\n
- varname:\"input\",\n
- minchars:1\n
-};\n
-var as = new AutoSuggest('testinput', options);\n
-</script>\n";
-}
-else {
- // get the person_id from the URL
- $person_id= intval( $_GET['id'] );
- // GetPersons API call for this person
- $person_info= $api->GetPersons( array( $person_id ) );
- if( empty( $person_info ) ) {
- echo "No such person.";
- } else {
- // vars from api
- $first_name= $person_info[0]['first_name'];
- $last_name= $person_info[0]['last_name'];
- $title= $person_info[0]['title'];
- $url= $person_info[0]['url'];
- $phone= $person_info[0]['phone'];
- $email= $person_info[0]['email'];
- $enabled= $person_info[0]['enabled'];
- $peer_id=$person_info[0]['peer_id'];
-
- // arrays from api
- $role_ids= $person_info[0]['role_ids'];
- $roles= $person_info[0]['roles'];
- $site_ids= $person_info[0]['site_ids'];
- $slice_ids= $person_info[0]['slice_ids'];
- $key_ids= $person_info[0]['key_ids'];
-
- // gets more data from API calls
- $site_info= $api->GetSites( $site_ids, array( "site_id", "name" ) );
- $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
- $key_info= $api->GetKeys( $key_ids );
-
- drupal_set_title("$first_name $last_name Account Information");
-
- // start form
- if ( ! $peer_id ) {
- echo "<form action='/db/persons/person_action.php' enctype='multipart/form-data' method='post'>\n";
- } else {
- echo "<div class='plc-foreign'>";
- }
- echo "<input type=hidden name='person_id' value='$person_id'>\n";
-
- if ( ! $peer_id ) {
- if( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) {
- // list to take person action
-
- echo "<table><tr><td>";
-
- if (in_array( 10, $_roles )) {
- echo plc_event_button("Person","person",$person_id);
- echo "</td><td>";
- }
-
- echo "<select name='actions' onChange=\"submit();\">\n";
-
- $actions= array( ''=>'Choose Action', 'delete'=>"Delete $first_name" );
-
- if( $enabled == true )
- $actions['disable']= "Disable $first_name";
- else
- $actions['enable']= "Enable $first_name";
-
- if ( in_array(10,$_roles)) {
- $actions['su'] = "Become $first_name";
- }
-
- foreach( $actions as $key => $val ) {
- echo "<option value='$key'";
-
- if( $key == $_POST['actions'] )
- echo " selected";
-
- echo ">$val</option>\n";
- }
-
- echo "</select>\n";
-
- if( $enabled == false ) {
- echo "</td><td>";
- echo " <font color=red size=-1><- This user is not enabled. Choose here to enable or delete.</font>";
- }
- echo "</td></tr></table>";
- }
-
- }
-
- // basic person info
- echo "<hr />";
- echo "<table border=0>\n";
- echo "<tr><th>First Name: </th><td> $first_name</td></tr>\n";
- echo "<tr><th>Last Name: </th><td> $last_name</td></tr>\n";
- echo "<tr><th>Title: </th><td> $title</td></tr>\n";
- echo "<tr><th>Email: </th><td><a href='mailto:$email'>$email</a></td></tr>\n";
- echo "<tr><th>Phone: </th><td>$phone</td></tr>\n";
- echo "<tr><th>URL: </th><td>$url</td></tr>\n";
- echo "</table>\n";
-
- if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id )
- echo "<br /><a href='/db/persons/update.php?id=$person_id'>Update info</a>\n";
-
- echo "<hr />\n";
-
- // keys
- $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id']));
- echo "<h3>Keys</h3>\n";
- if( !empty( $key_ids ) ) {
- echo "<p><table border=0 width=450>\n";
- echo "<thead><tr><th>Type</th><th>Key</th>";
- if ( $can_manage_keys )
- echo "<th>Remove</th>";
- echo "</tr></thead><tbody>\n";
-
- foreach( $key_info as $key ) {
- $key_type= $key['key_type'];
- $key_id= $key['key_id'];
- $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
- echo "<tr><td>$key_type</td><td>$key_text";
-
- if ( $can_manage_keys )
- echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
-
- echo "</td></tr>\n";
- }
-
- echo "</tbody></table>\n";
- if ($can_manage_keys)
- echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
-
- } else {
- echo "<span class='plc-warning'> This user has no known key</span>";
- }
-
- if( $can_manage_keys ){
- echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
- <input type='submit' name='Upload' value='Upload'>\n
- <br /><hr />\n";
- }
- // sites
- echo "<h3>Sites</h3>\n";
- if( !empty( $site_info ) ) {
- echo "<table cellpadding=3><tbody>\n";
-
- foreach( $site_info as $site ) {
- $site_name= $site['name'];
- $site_id= $site['site_id'];
-
- echo "<tr><td><a href='/db/sites/index.php?id=$site_id'>$site_name</a> </td><td> (<input type=checkbox name='rem_site[]' value='$site_id'> remove)</td></tr>\n";
- }
- echo "</tbody></table>\n";
- echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
-
- } else {
- echo "<span class='plc-warning'> This user is not affiliated with a site !!</span>";
- }
-
- // diplay site select list to add another site for user
- if( ! $peer_id && in_array( 10, $_roles ) ) {
- // get site info
- $full_site_info= $api->GetSites( NULL, array( "site_id", "name" ) );
-
- if( $site_info )
- $person_site= arr_diff( $full_site_info, $site_info );
- else
- $person_site= $full_site_info;
-
- sort_sites( $person_site );
-
- echo "<p>Select a site to add this user to: ";
- echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
-
- foreach( $person_site as $site ) {
- echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
-
- }
-
- echo "</select>";
-
- }
- echo "<hr />\n";
-
- // roles
- echo "<h3>Roles</h3>\n";
- echo "<p><table>\n";
- echo "<thead><tr><th>Role</th>";
- if( in_array( "10", $_roles ) )
- echo "<th>Remove</th>";
- echo "</tr></thead><tbody>\n";
-
- // construct role array
- for( $n=0; $n<count($roles); $n++ ) {
- $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
- }
-
- $button_shown=0;
- if ( !empty ($roles) ) {
- foreach( $proles as $role ) {
- $role_name= $role['name'];
- $role_id= $role['role_id'];
-
- echo "<tr><td>$role_name";
-
-
- if( in_array( 10, $_roles ) ) {
- echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
- if ( ! $button_shown ) {
- $rowspan=count($roles);
- echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
- $button_shown=1;
- }
- }
-
- echo "</td></tr>\n";
- }
- } else {
- echo "<span class='plc-warning'> This user has no known role !!</span>";
- }
- echo "</tbody></table>\n";
-
- // if admin show roles to add
- if( in_array( 10, $_roles ) ) {
- $all_roles= $api->GetRoles();
- $addable_roles= arr_diff( $all_roles, $proles );
- ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
- ##return an empty array and the scrolling roles list is not displayed in this case
- ##assign to addablerole all the roles
- if (count($proles)==0)
- $addable_roles=$all_roles;
-
- if( !empty( $addable_roles ) ) {
- echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
-
- foreach( $addable_roles as $arole ) {
- echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
-
- }
-
- echo "</select>\n";
-
- }
- }
-
- echo "<hr />\n";
-
- // slices
- echo "<h3>Slices</h3>\n";
- if( !empty( $slice_info ) ) {
-
- foreach( $slice_info as $slice ) {
- $slice_name= $slice['name'];
- $slice_id= $slice['slice_id'];
-
- echo "<a href='/db/slices/index.php?id=$slice_id'>$slice_name</a><br />\n";
- }
-
- } else {
- echo "No slices found for that user";
- }
-
- if ( ! $peer_id ) {
- echo "</form>\n";
- } else {
- echo "</div>\n";
- }
-
- }
- if( $peer_id )
- echo "<br /></div>";
-
- echo "<br /><hr /><p><a href='/db/persons/index.php'>Back to persons list</a></div>";
-
- }
-
-
-// Print footer
-include 'plc_footer.php';
-
+if ($_GET['id']) require ('person.php') ;
+else require ('persons.php');
?>
--- /dev/null
+<?php
+
+// $Id: index.php 11645 2009-01-21 23:09:49Z thierry $
+
+// Require login
+require_once 'plc_login.php';
+
+// Get session and API handles
+require_once 'plc_session.php';
+global $plc, $api;
+
+// Print header
+require_once 'plc_drupal.php';
+include 'plc_header.php';
+
+// Common functions
+require_once 'plc_functions.php';
+require_once 'plc_minitabs.php';
+require_once 'plc_tables.php';
+require_once 'plc_details.php';
+
+// --------------------
+// recognized URL arguments
+$person_id=intval($_GET['id']);
+if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; }
+
+////////////////////
+// Get all columns as we focus on only one entry
+$persons= $api->GetPersons( array($person_id));
+
+if (empty($persons)) {
+ drupal_set_message ("Person " . $person_id . " not found");
+ } else {
+ $person=$persons[0];
+
+ // vars from api
+ $first_name= $person['first_name'];
+ $last_name= $person['last_name'];
+ $title= $person['title'];
+ $url= $person['url'];
+ $phone= $person['phone'];
+ $email= $person['email'];
+ $enabled= $person['enabled'];
+ $peer_id=$person['peer_id'];
+
+ // arrays from api
+ $role_ids= $person['role_ids'];
+ $roles= $person['roles'];
+ $site_ids= $person['site_ids'];
+ $slice_ids= $person['slice_ids'];
+ $key_ids= $person['key_ids'];
+
+ // gets more data from API calls
+ $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
+ $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
+ $keys= $api->GetKeys( $key_ids );
+
+ drupal_set_title("Details for account " . $first_name . " " . $last_name);
+
+ $plc_hash=plc_peer_get_hash($api);
+
+ $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
+ $is_my_account = plc_my_person_id() == $person_id;
+ $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+
+ $tabs=array();
+
+ if ($local_peer && $privileges) {
+ if (plc_is_admin())
+ $tabs['Events'] = array('url'=>l_event("Person","person",$person_id),
+ 'bubble'=>'Related events',
+ 'image'=>'/planetlab/icons/event.png',
+ 'height'=>18);
+ if ($enabled)
+ $tabs['Disable'] = array ('method'=>'POST',
+ 'url'=>'/db/persons/person_actions.php',
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'disable'),
+ 'bubble'=>"Disable $first_name");
+ else
+ $tabs['Enable'] = array ('method'=>'POST',
+ 'url'=>'/db/persons/person_actions.php',
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'enable'),
+ 'bubble'=>"Enable $first_name");
+ $tabs['Delete'] = array ('method'=>'POST',
+ 'url'=>'/db/persons/person_actions.php',
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'delete'),
+ 'bubble'=>"Delete $first_name",
+ 'confirm'=>"Are you sure to delete $first_name $last_name");
+ }
+
+ if ($privileges || $is_my_account)
+ $tabs['Update'] = array('url'=>'/db/persons/update.php',
+ 'values'=>array('id'=>$person_id),
+ 'bubble'=>"Update $first_name");
+
+ $tabs['Persons'] = array ('url'=>l_persons());
+
+ plc_tabs($tabs);
+
+ plc_details_start();
+ plc_details_line("First Name",$first_name);
+ plc_details_line("Last Name",$last_name);
+ plc_details_line("Title",$title);
+ plc_details_line("Email",href("mailto:$email",$email));
+ plc_details_line("Phone",$phone);
+ plc_details_line("URL",$url);
+ plc_details_end();
+
+
+ echo "<hr />\n";
+
+ // keys
+ $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
+ plc_table_title('Keys');
+ if ( empty( $key_ids ) ) {
+ echo "<span class='plc-warning'> This user has no known key</span>";
+ } else {
+ echo "<p><table border=0 width=450>\n";
+ echo "<thead><tr><th>Type</th><th>Key</th>";
+ if ( $can_manage_keys )
+ echo "<th>Remove</th>";
+ echo "</tr></thead><tbody>\n";
+
+ foreach( $keys as $key ) {
+ $key_type= $key['key_type'];
+ $key_id= $key['key_id'];
+ $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
+ echo "<tr><td>$key_type</td><td>$key_text";
+
+ if ( $can_manage_keys )
+ echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
+
+ echo "</td></tr>\n";
+ }
+
+ echo "</tbody></table>\n";
+ if ($can_manage_keys)
+ echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
+ }
+
+ if( $can_manage_keys ){
+ echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
+ <input type='submit' name='Upload' value='Upload'>\n
+ <br /><hr />\n";
+ }
+
+ // sites
+ plc_table_title('Sites');
+
+ // sites
+ if (empty( $sites ) ) {
+ plc_warning('This user is not affiliated with a site !!');
+ } else {
+ $columns=array();
+ $columns['Name']="string";
+ $columns['Login_base']="string";
+ $columns['Remove']="string";
+ $table_options = array('notes_area'=>false,'search_area'=>false);
+ plc_table_start ("person_slices",$columns,1,$table_options);
+ foreach( $sites as $site ) {
+ $site_name= $site['name'];
+ $site_id= $site['site_id'];
+ $login_base=$site['login_base'];
+ plc_table_row_start();
+ plc_table_cell (l_site_t($site_id,$site_name));
+ plc_table_cell ($login_base);
+ plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
+ plc_table_row_end ();
+ }
+ plc_table_end($table_options);
+ }
+
+ echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
+
+
+ // diplay site select list to add another site for user
+ if ($local_peer && plc_is_admin()) {
+ // get site info
+ $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
+
+ if( $sites )
+ $person_site= arr_diff( $all_sites, $sites );
+ else
+ $person_site= $all_sites;
+
+ // sort_sites( $person_site );
+
+ echo "<p>Select a site to add this user to: ";
+ echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
+
+ foreach( $person_site as $site ) {
+ echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
+
+ }
+
+ echo "</select>";
+
+ }
+ echo "<hr />\n";
+
+ // roles
+ echo "<h3>Roles</h3>\n";
+ echo "<p><table>\n";
+ echo "<thead><tr><th>Role</th>";
+ if( plc_is_admin())
+ echo "<th>Remove</th>";
+ echo "</tr></thead><tbody>\n";
+
+ // construct role array
+ for( $n=0; $n<count($roles); $n++ ) {
+ $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
+ }
+
+ $button_shown=0;
+ if ( !empty ($roles) ) {
+ foreach( $proles as $role ) {
+ $role_name= $role['name'];
+ $role_id= $role['role_id'];
+
+ echo "<tr><td>$role_name";
+
+
+ if( plc_is_admin()) {
+ echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
+ if ( ! $button_shown ) {
+ $rowspan=count($roles);
+ echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
+ $button_shown=1;
+ }
+ }
+
+ echo "</td></tr>\n";
+ }
+ } else {
+ echo "<span class='plc-warning'> This user has no known role !!</span>";
+ }
+ echo "</tbody></table>\n";
+
+ // if admin show roles to add
+ if( plc_is_admin()) {
+ $all_roles= $api->GetRoles();
+ $addable_roles= arr_diff( $all_roles, $proles );
+ ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
+ ##return an empty array and the scrolling roles list is not displayed in this case
+ ##assign to addablerole all the roles
+ if (count($proles)==0)
+ $addable_roles=$all_roles;
+
+ if( !empty( $addable_roles ) ) {
+ echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
+
+ foreach( $addable_roles as $arole ) {
+ echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
+
+ }
+
+ echo "</select>\n";
+
+ }
+ }
+
+ echo "<hr />\n";
+
+ // slices
+ plc_table_title('Slices');
+
+ if( empty( $slices ) ) {
+ drupal_set_message ("User has no slice");
+ } else {
+ $columns=array('Slice name'=>'string');
+ $table_options=array();
+ plc_table_start("person_slices",$columns,1,$table_options);
+
+ foreach( $slices as $slice ) {
+ $slice_name= $slice['name'];
+ $slice_id= $slice['slice_id'];
+ plc_table_row_start();
+ plc_table_cell(l_slice_t($slice_id,$slice_name));
+ plc_table_row_end();
+ }
+ plc_table_end($table_options);
+ }
+
+ plc_peer_block_end();
+
+ }
+
+// Print footer
+include 'plc_footer.php';
+
+
+?>
}
// if action exists figure out what to do
-if( $_POST['actions'] ) {
+if( $_POST['action'] ) {
// depending on action, run function
- switch( $_POST['actions'] ) {
+ switch( $_POST['action'] ) {
case "delete":
- header( "location: person_action.php?del_id=$person_id" );
+ header( "location: person_actions.php?del_id=$person_id" );
exit();
break;
case "disable":
- header( "location: person_action.php?dis_id=$person_id" );
+ header( "location: person_actions.php?dis_id=$person_id" );
exit();
break;
case "enable":
- header( "location: person_action.php?enab_id=$person_id" );
+ header( "location: person_actions.php?enab_id=$person_id" );
exit();
break;
case "su":
$person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) );
// start form
- echo "<form action='person_action.php?per_id=$person_id' method=post>\n";
+ echo "<form action='person_actions.php?per_id=$person_id' method=post>\n";
// show delete confirmation
echo "<h2>Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."</h2>\n";
include 'plc_footer.php';
-?>
\ No newline at end of file
+?>
--- /dev/null
+<?php
+
+// $Id: index.php 11645 2009-01-21 23:09:49Z thierry $
+
+// Require login
+require_once 'plc_login.php';
+
+// Get session and API handles
+require_once 'plc_session.php';
+global $plc, $api;
+
+// Print header
+require_once 'plc_drupal.php';
+// set default
+drupal_set_title('People');
+include 'plc_header.php';
+
+// Common functions
+require_once 'plc_functions.php';
+require_once 'plc_sorts.php';
+
+//fix the memory limit for this page
+ini_set("memory_limit","48M");
+
+// find person roles
+$_person= $plc->person;
+$_roles= $_person['role_ids'];
+
+
+////////////////////
+// The set of columns to fetch
+// and the filter applied for fetching sites
+if ( !in_array( '10', $_roles ) ) {
+ $columns = array("person_id", "first_name", "last_name", "email", "roles" , "peer_id");
+ // PIs can see users not yet enabled
+ if ( ! in_array ('20', $_roles) ) {
+ $filter = array ("enabled" => TRUE);
+ } else {
+ $filter = array();
+ }
+ } else {
+ $columns = array("person_id", "first_name", "last_name", "email", "roles" , "peer_id", "key_ids", "enabled","slice_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_person ($person) {
+
+ // we need the 'key_ids' field to do this
+ // so regular users wont run this
+ if ( ! array_key_exists ('key_ids', $person))
+ return $person ;
+
+ $messages=array();
+
+ // do all this stuff on local persons only
+ if ( $person['peer_id'] ) {
+ $class='plc-foreign';
+ } else {
+ $class='plc-warning';
+ // check that the person has keys, but dont do that for admins
+ if ( ! in_array ('admin',$person['roles']) && count($person['key_ids']) == 0)
+ $messages [] = "No Key";
+ }
+ if ( ! $person['enabled'] )
+ $messages[] = "Disabled";
+ // but always cleanup $person columns
+ unset ($person['key_ids']);
+ unset ($person['enabled']);
+ //detect tech already involved on some slices.
+ if( ( count($person['roles'])==1 ) && ( in_array('tech',$person['roles']) ) && (! empty($person["slice_ids"])) ) {
+ $messages[]="Tech involved in a Slice";
+ }
+ // cleanup $person columns
+ unset ($person['slice_ids']);
+ //display the extra status column
+ $person['status'] = plc_vertical_table($messages,$class);
+ return $person;
+}
+
+// if emailpattern or peerscope is set then search for Persons.
+// 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['emailpattern'] || $_GET['peerscope']) {
+ $emailpattern= $_GET['emailpattern'];
+ if (empty($emailpattern)) {
+ $emailpattern="*";
+ }
+ $filter = array_merge (array( "email"=>$emailpattern ), $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;
+ }
+ // need to use a hash filter for patterns to be properly handled
+ $persons= $api->GetPersons($filter , $columns );
+ $persons= array_map(layout_person,$persons);
+ $person_count = count ($persons);
+ if ( $person_count == 1) {
+ header( "location: index.php?id=". $persons[0]['person_id'] );
+ exit();
+ } else if ( $person_count == 0) {
+ echo "<span class='plc-warning'> No person whose email matches $emailpattern </span>";
+ } else {
+ drupal_set_title ("Users matching $emailpattern on ". $peer_label);
+ sort_persons ($persons);
+ echo paginate( $persons, "person_id", "Persons", 25, "email");
+ }
+ }
+// if a site_id is given, display the site persons only
+else if( $_GET['site_id'] ) {
+ $site_id= $_GET['site_id'];
+ // Get site info
+ $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "person_ids" ) );
+ drupal_set_title("People with " . $site_info[0]['name']);
+ // Get site nodes
+ $persons= $api->GetPersons( array_merge (array("person_id"=>$site_info[0]['person_ids']),$filter), $columns );
+ $persons= array_map(layout_person,$persons);
+ sort_persons( $persons );
+
+ echo paginate( $persons, "person_id", "Persons", 25, "email" );
+
+}
+// if a slice_id is given,display the persons involved in this slice
+else if( $_GET['slice_id'] ) {
+ $slice_id= $_GET['slice_id'];
+ // Get slice infos
+ $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "person_ids" ) );
+ drupal_set_title("People In " . $slice_info[0]['name']);
+ // Get slice persons
+ $persons= $api->GetPersons( array_merge (array("person_id"=>$slice_info[0]['person_ids']),$filter), $columns );
+ if ( empty ($persons) ) {
+ echo "No persons to display";
+ } else {
+
+ $persons= array_map(layout_person,$persons);
+ sort_persons( $persons );
+
+ echo paginate( $persons, "person_id", "Persons", 25, "email" );
+ echo "<br /><p><a href='/db/slices/index.php?id=".$slice_id.">Back to slice page</a></div>";
+ }
+
+ }
+// if no person id, display list of persons to choose
+elseif( !$_GET['id'] ) {
+
+ // GetPersons API call
+ $persons= $api->GetPersons( empty($filter) ? NULL : $filter, $columns );
+ $persons= array_map(layout_person,$persons);
+ sort_persons( $persons );
+
+ drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
+ <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
+ <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
+
+ echo "<div>\n
+ <form method=get action='index.php'>\n";
+ //if( $emailpattern ) echo "<font color=red>'$emailpattern' is not a valid person email.</font>\n";
+ echo "<table><tr>\n
+<th><label for='testinput'>Enter Person Email or pattern: : </label></th>\n
+<td><input type='text' id='testinput' name='emailpattern' size=40 value='' /></td>\n
+<td rowspan=2><input type=submit value='Select Person' /></td>\n
+</tr> <tr>
+<th><label for='peerscope'>Federation scope: </label></th>\n
+<td><select id='peerscope' name='peerscope' onChange='submit()'>\n
+";
+ echo plc_peers_option_list($api);
+ echo "</select></td>\n
+</tr></table></form></div>\n
+<br />\n";
+ echo paginate( $persons, "person_id" , "Persons", 25, "email");
+ echo "<script type=\"text/javascript\">\n
+var options = {\n
+ script:\"/planetlab/persons/test.php?\",\n
+ varname:\"input\",\n
+ minchars:1\n
+};\n
+var as = new AutoSuggest('testinput', options);\n
+</script>\n";
+}
+else {
+ // get the person_id from the URL
+ $person_id= intval( $_GET['id'] );
+ // GetPersons API call for this person
+ $person_info= $api->GetPersons( array( $person_id ) );
+ if( empty( $person_info ) ) {
+ echo "No such person.";
+ } else {
+ // vars from api
+ $first_name= $person_info[0]['first_name'];
+ $last_name= $person_info[0]['last_name'];
+ $title= $person_info[0]['title'];
+ $url= $person_info[0]['url'];
+ $phone= $person_info[0]['phone'];
+ $email= $person_info[0]['email'];
+ $enabled= $person_info[0]['enabled'];
+ $peer_id=$person_info[0]['peer_id'];
+
+ // arrays from api
+ $role_ids= $person_info[0]['role_ids'];
+ $roles= $person_info[0]['roles'];
+ $site_ids= $person_info[0]['site_ids'];
+ $slice_ids= $person_info[0]['slice_ids'];
+ $key_ids= $person_info[0]['key_ids'];
+
+ // gets more data from API calls
+ $site_info= $api->GetSites( $site_ids, array( "site_id", "name" ) );
+ $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
+ $key_info= $api->GetKeys( $key_ids );
+
+ drupal_set_title("$first_name $last_name Account Information");
+
+ // start form
+ if ( ! $peer_id ) {
+ echo "<form action='/db/persons/person_actions.php' enctype='multipart/form-data' method='post'>\n";
+ } else {
+ echo "<div class='plc-foreign'>";
+ }
+ echo "<input type=hidden name='person_id' value='$person_id'>\n";
+
+ if ( ! $peer_id ) {
+ if( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) {
+ // list to take person action
+
+ echo "<table><tr><td>";
+
+ if (in_array( 10, $_roles )) {
+ echo plc_event_button("Person","person",$person_id);
+ echo "</td><td>";
+ }
+
+ echo "<select name='actions' onChange=\"submit();\">\n";
+
+ $actions= array( ''=>'Choose Action', 'delete'=>"Delete $first_name" );
+
+ if( $enabled == true )
+ $actions['disable']= "Disable $first_name";
+ else
+ $actions['enable']= "Enable $first_name";
+
+ if ( in_array(10,$_roles)) {
+ $actions['su'] = "Become $first_name";
+ }
+
+ foreach( $actions as $key => $val ) {
+ echo "<option value='$key'";
+
+ if( $key == $_POST['actions'] )
+ echo " selected";
+
+ echo ">$val</option>\n";
+ }
+
+ echo "</select>\n";
+
+ if( $enabled == false ) {
+ echo "</td><td>";
+ echo " <font color=red size=-1><- This user is not enabled. Choose here to enable or delete.</font>";
+ }
+ echo "</td></tr></table>";
+ }
+
+ }
+
+ // basic person info
+ echo "<hr />";
+ echo "<table border=0>\n";
+ echo "<tr><th>First Name: </th><td> $first_name</td></tr>\n";
+ echo "<tr><th>Last Name: </th><td> $last_name</td></tr>\n";
+ echo "<tr><th>Title: </th><td> $title</td></tr>\n";
+ echo "<tr><th>Email: </th><td><a href='mailto:$email'>$email</a></td></tr>\n";
+ echo "<tr><th>Phone: </th><td>$phone</td></tr>\n";
+ echo "<tr><th>URL: </th><td>$url</td></tr>\n";
+ echo "</table>\n";
+
+ if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id )
+ echo "<br /><a href='/db/persons/update.php?id=$person_id'>Update info</a>\n";
+
+ echo "<hr />\n";
+
+ // keys
+ $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id']));
+ echo "<h3>Keys</h3>\n";
+ if( !empty( $key_ids ) ) {
+ echo "<p><table border=0 width=450>\n";
+ echo "<thead><tr><th>Type</th><th>Key</th>";
+ if ( $can_manage_keys )
+ echo "<th>Remove</th>";
+ echo "</tr></thead><tbody>\n";
+
+ foreach( $key_info as $key ) {
+ $key_type= $key['key_type'];
+ $key_id= $key['key_id'];
+ $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
+ echo "<tr><td>$key_type</td><td>$key_text";
+
+ if ( $can_manage_keys )
+ echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
+
+ echo "</td></tr>\n";
+ }
+
+ echo "</tbody></table>\n";
+ if ($can_manage_keys)
+ echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
+
+ } else {
+ echo "<span class='plc-warning'> This user has no known key</span>";
+ }
+
+ if( $can_manage_keys ){
+ echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
+ <input type='submit' name='Upload' value='Upload'>\n
+ <br /><hr />\n";
+ }
+ // sites
+ echo "<h3>Sites</h3>\n";
+ if( !empty( $site_info ) ) {
+ echo "<table cellpadding=3><tbody>\n";
+
+ foreach( $site_info as $site ) {
+ $site_name= $site['name'];
+ $site_id= $site['site_id'];
+
+ echo "<tr><td><a href='/db/sites/index.php?id=$site_id'>$site_name</a> </td><td> (<input type=checkbox name='rem_site[]' value='$site_id'> remove)</td></tr>\n";
+ }
+ echo "</tbody></table>\n";
+ echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
+
+ } else {
+ echo "<span class='plc-warning'> This user is not affiliated with a site !!</span>";
+ }
+
+ // diplay site select list to add another site for user
+ if( ! $peer_id && in_array( 10, $_roles ) ) {
+ // get site info
+ $full_site_info= $api->GetSites( NULL, array( "site_id", "name" ) );
+
+ if( $site_info )
+ $person_site= arr_diff( $full_site_info, $site_info );
+ else
+ $person_site= $full_site_info;
+
+ sort_sites( $person_site );
+
+ echo "<p>Select a site to add this user to: ";
+ echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
+
+ foreach( $person_site as $site ) {
+ echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
+
+ }
+
+ echo "</select>";
+
+ }
+ echo "<hr />\n";
+
+ // roles
+ echo "<h3>Roles</h3>\n";
+ echo "<p><table>\n";
+ echo "<thead><tr><th>Role</th>";
+ if( in_array( "10", $_roles ) )
+ echo "<th>Remove</th>";
+ echo "</tr></thead><tbody>\n";
+
+ // construct role array
+ for( $n=0; $n<count($roles); $n++ ) {
+ $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
+ }
+
+ $button_shown=0;
+ if ( !empty ($roles) ) {
+ foreach( $proles as $role ) {
+ $role_name= $role['name'];
+ $role_id= $role['role_id'];
+
+ echo "<tr><td>$role_name";
+
+
+ if( in_array( 10, $_roles ) ) {
+ echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
+ if ( ! $button_shown ) {
+ $rowspan=count($roles);
+ echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
+ $button_shown=1;
+ }
+ }
+
+ echo "</td></tr>\n";
+ }
+ } else {
+ echo "<span class='plc-warning'> This user has no known role !!</span>";
+ }
+ echo "</tbody></table>\n";
+
+ // if admin show roles to add
+ if( in_array( 10, $_roles ) ) {
+ $all_roles= $api->GetRoles();
+ $addable_roles= arr_diff( $all_roles, $proles );
+ ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
+ ##return an empty array and the scrolling roles list is not displayed in this case
+ ##assign to addablerole all the roles
+ if (count($proles)==0)
+ $addable_roles=$all_roles;
+
+ if( !empty( $addable_roles ) ) {
+ echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
+
+ foreach( $addable_roles as $arole ) {
+ echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
+
+ }
+
+ echo "</select>\n";
+
+ }
+ }
+
+ echo "<hr />\n";
+
+ // slices
+ echo "<h3>Slices</h3>\n";
+ if( !empty( $slice_info ) ) {
+
+ foreach( $slice_info as $slice ) {
+ $slice_name= $slice['name'];
+ $slice_id= $slice['slice_id'];
+
+ echo "<a href='/db/slices/index.php?id=$slice_id'>$slice_name</a><br />\n";
+ }
+
+ } else {
+ echo "No slices found for that user";
+ }
+
+ if ( ! $peer_id ) {
+ echo "</form>\n";
+ } else {
+ echo "</div>\n";
+ }
+
+ }
+ if( $peer_id )
+ echo "<br /></div>";
+
+ echo "<br /><hr /><p><a href='/db/persons/index.php'>Back to persons list</a></div>";
+
+ }
+
+
+// Print footer
+include 'plc_footer.php';
+
+
+?>