From 50c52e39521aa6ac664e542848057822fed4d395 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 26 Jan 2009 20:11:57 +0000 Subject: [PATCH] checkpoint --- drupal-hacks/node.module | 2 +- modules/planetlab.module | 4 +- planetlab/css/plc_tables.css | 7 +- planetlab/icons/clear.png | Bin 775 -> 518 bytes planetlab/includes/plc_functions.php | 134 ++--- planetlab/includes/plc_tables.php | 26 +- planetlab/nodes/add_node.php | 2 +- planetlab/nodes/node.php | 39 +- planetlab/nodes/nodes.php | 13 +- planetlab/peers/peer.php | 2 +- planetlab/peers/peers.php | 6 +- planetlab/persons/index.php | 466 +---------------- planetlab/persons/person.php | 295 +++++++++++ .../{person_action.php => person_actions.php} | 14 +- planetlab/persons/persons.php | 473 ++++++++++++++++++ 15 files changed, 902 insertions(+), 581 deletions(-) create mode 100644 planetlab/persons/person.php rename planetlab/persons/{person_action.php => person_actions.php} (94%) create mode 100644 planetlab/persons/persons.php diff --git a/drupal-hacks/node.module b/drupal-hacks/node.module index 04fafa4..2d2c649 100644 --- a/drupal-hacks/node.module +++ b/drupal-hacks/node.module @@ -2053,7 +2053,7 @@ function node_page_default() {
  1. Use your administrator account - 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.
  2. Configure your website diff --git a/modules/planetlab.module b/modules/planetlab.module index 4921cb3..e225776 100644 --- a/modules/planetlab.module +++ b/modules/planetlab.module @@ -114,7 +114,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) { $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 ) @@ -125,7 +125,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) { $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) { diff --git a/planetlab/css/plc_tables.css b/planetlab/css/plc_tables.css index 5ac6b6f..1a03646 100644 --- a/planetlab/css/plc_tables.css +++ b/planetlab/css/plc_tables.css @@ -94,8 +94,9 @@ table.table_dialogs { 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; @@ -187,7 +188,7 @@ td.sized2 { } td.sized3 { width:7em; - text-align:left; + text-align:left; } /* tfoot td diff --git a/planetlab/icons/clear.png b/planetlab/icons/clear.png index 54ef8cefacf8ad076129c58c3d94c5dad2c9eb76..4d43b22449e7e6ee348eb68a31690daccd6df725 100644 GIT binary patch literal 518 zcmV+h0{Q)kP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iXA` z5)mYs>}EXx000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0004DNklBt9kF91<4G2jWm3qXSLcs%~O-|uhEIYb0iUA>vjsH%#p ztP)jK1917g=s1on%d%>IQUKtc=i~PW!)5pqkt7ijI}8Jl#{&_;S{s{#thE3v%fc`W z05<9S{^p%WRk7C6wyo549Zhvz)3&Vyvv;1;>2x*IG({xm99`FG(=-AoK+`nRb)7or z;%DMi||j>ed{_;-bxF@`ivM^$y} zllyyr3zJ_JCRKGs`LmSOtv=JTec#{0kq1Lj6l}NKjjBeRfAk*WaipK3ZvX%Q07*qo IM6N<$f)r-lF8}}l literal 775 zcmV+i1Ni)jP)oU|iOS6an-!uu1g7ANA8rOQ&dV_dyCwcpGJ#_; z^tNSEx^f<*ra?Fck=UPSFbE^#aCC~HeyLD!K9j%+?koAMt1OX>QDK!Ji}0s}Al^dQ z24C$GEj}egZ$Cm~fZL<6K2ET?H4|6;5{L=F`U12N|Fw{`G?)XEg1RFlCnIc8h0xJ1gX@pyj6Fq!{;dB^Eg>!zH!GV1AL$gszrlR6K&vi26 zZZEbuB_@gdB*1S539MU-<{js|COgf5&S`XY(23qyAOw9RCMFh}S47Su4^~Hkd5`$U z__Vy76amLgHp{IUa3hSNcH}aCq6mi?kgw4MfxW(-%=UI+O>8+{iNCoS|EW{veOmmE zv~VrLgj$eF&#n1v(!DaQNyyl?jl9lI6Fm9+DavYPW@(v8GO>L-fvzsbq=i25mMAyP zHC~&8t3t}xgv4G~M{!37pZlKR-B2Y{wJ_Ixo2;@$j8s=M-QA5R1w7KnSwq$sS7V7y zgjB>@n^d5GR)m)=MH?6(J(v(gC_SBsvyhD85#CAW5lME&z%7!l`X%N36>0Py%VuGk z=-whkTJ%p5O-bYj@lgR^HhB38*8G<8Ps??taA}X7jTIJ@Awr3J{4s?D^j*%r7>3Kh zB`V+h_hU-7HQ9=tWfoS8;EHtt`(k*940^vMp7Vp`;2&@^6h|grps@e|002ovPDHLk FV1k#xZCU^T diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 81931df..f30b77d 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -36,67 +36,72 @@ function plc_my_person_id () { //////////////////////////////////////////////////////////// links function href ($url,$text) { return "" . $text . ""; } -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 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) { @@ -201,12 +206,15 @@ function plc_peer_shortname ($peer_hash,$peer_id) { } // 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 "
    "; + return true; } else { // set two classes, one eneraic to all foreign, and one based on the peer's shortname for finer grain tuning printf ('
    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 diff --git a/planetlab/includes/plc_tables.php b/planetlab/includes/plc_tables.php index d079c93..6fc1835 100644 --- a/planetlab/includes/plc_tables.php +++ b/planetlab/includes/plc_tables.php @@ -18,26 +18,28 @@ function plc_table_cell($cell) { // table_id: '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(); } //////////////////// diff --git a/planetlab/nodes/add_node.php b/planetlab/nodes/add_node.php index 24f39c1..b56cf1b 100644 --- a/planetlab/nodes/add_node.php +++ b/planetlab/nodes/add_node.php @@ -135,7 +135,7 @@ function updateStaticFields() { "/db/nodes/node_actions.php", 'method'=>'POST', @@ -114,7 +114,7 @@ if (empty($nodes)) { '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); } @@ -158,7 +158,7 @@ if (empty($nodes)) { echo "\n"; // same here for the download area - if ( ! $peer_id && $extra_privileges) { + if ( ! $peer_id && $privileges) { echo "
    Download "; echo "
    \n"; @@ -179,12 +179,12 @@ if (empty($nodes)) { // 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); @@ -202,16 +202,17 @@ if (empty($nodes)) { $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 @@ -222,7 +223,7 @@ if (empty($nodes)) { echo "

    No interface. Please add an interface to make this a usable PLC node

    .\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'; } @@ -235,7 +236,8 @@ if (empty($nodes)) { print "
    \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']; @@ -254,7 +256,7 @@ if (empty($nodes)) { $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', @@ -263,14 +265,14 @@ if (empty($nodes)) { 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); } } @@ -287,17 +289,18 @@ if (empty($nodes)) { print "
    \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); } //////////////////////////////////////////////////////////// diff --git a/planetlab/nodes/nodes.php b/planetlab/nodes/nodes.php index 064d1a5..d03c7b5 100644 --- a/planetlab/nodes/nodes.php +++ b/planetlab/nodes/nodes.php @@ -138,7 +138,8 @@ $columns = array ("Peer"=>"string", "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 @@ -158,10 +159,10 @@ foreach ($nodes as $node) { 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); @@ -173,9 +174,7 @@ foreach ($nodes as $node) { $fake_i += 1; } -plc_table_end(); - -plc_table_notes(); +plc_table_end($table_options); // Print footer include 'plc_footer.php'; diff --git a/planetlab/peers/peer.php b/planetlab/peers/peer.php index d2c3c89..7deca56 100644 --- a/planetlab/peers/peer.php +++ b/planetlab/peers/peer.php @@ -42,7 +42,7 @@ drupal_set_title("Details for Peer " . $peername); 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'])); diff --git a/planetlab/peers/peers.php b/planetlab/peers/peers.php index 4764778..c547a19 100644 --- a/planetlab/peers/peers.php +++ b/planetlab/peers/peers.php @@ -37,10 +37,11 @@ if ( empty($peers)) { '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 ('?'); @@ -48,6 +49,7 @@ if ( empty($peers)) { plc_table_cell (href(l_comon("peer_id",$peer['peer_id']),'Comon')); plc_table_row_end(); } + plc_table_end($table_options); } // Print footer diff --git a/planetlab/persons/index.php b/planetlab/persons/index.php index c31067e..ed8bc04 100644 --- a/planetlab/persons/index.php +++ b/planetlab/persons/index.php @@ -5,469 +5,7 @@ // 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 " No person whose email matches $emailpattern "; - } 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 "

    GetPersons( empty($filter) ? NULL : $filter, $columns ); - $persons= array_map(layout_person,$persons); - sort_persons( $persons ); - - drupal_set_html_head(' - - '); - - echo "

    \n -
    \n"; - echo paginate( $persons, "person_id" , "Persons", 25, "email"); - echo "\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 "
    \n"; - } else { - echo "
    "; - } - echo "\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 "
    "; - - if (in_array( 10, $_roles )) { - echo plc_event_button("Person","person",$person_id); - echo ""; - } - - echo "\n"; - - if( $enabled == false ) { - echo ""; - echo "   <- This user is not enabled. Choose here to enable or delete."; - } - echo "
    "; - } - - } - - // basic person info - echo "
    "; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
    First Name: $first_name
    Last Name: $last_name
    Title: $title
    Email: $email
    Phone: $phone
    URL: $url
    \n"; - - if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id ) - echo "
    Update info\n"; - - echo "
    \n"; - - // keys - $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id'])); - echo "

    Keys

    \n"; - if( !empty( $key_ids ) ) { - echo "

    \n"; - echo ""; - if ( $can_manage_keys ) - echo ""; - echo "\n"; - - foreach( $key_info as $key ) { - $key_type= $key['key_type']; - $key_id= $key['key_id']; - $key_text= wordwrap( $key['key'], 70, "
    \n", 1 ); - echo "\n"; - } - - echo "
    TypeKeyRemove
    $key_type$key_text"; - - if ( $can_manage_keys ) - echo ""; - - echo "
    \n"; - if ($can_manage_keys) - echo "


    \n"; - - } else { - echo " This user has no known key"; - } - - if( $can_manage_keys ){ - echo "
    Upload new key: \n - \n -


    \n"; - } - // sites - echo "

    Sites

    \n"; - if( !empty( $site_info ) ) { - echo "\n"; - - foreach( $site_info as $site ) { - $site_name= $site['name']; - $site_id= $site['site_id']; - - echo "\n"; - } - echo "
    $site_name ( remove)
    \n"; - echo "\n"; - - } else { - echo " This user is not affiliated with a site !!"; - } - - // 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 "

    Select a site to add this user to: "; - echo ""; - - } - echo "


    \n"; - - // roles - echo "

    Roles

    \n"; - echo "

    \n"; - echo ""; - if( in_array( "10", $_roles ) ) - echo ""; - echo "\n"; - - // construct role array - for( $n=0; $n$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 "\n"; - $button_shown=1; - } - } - - echo "\n"; - } - } else { - echo " This user has no known role !!"; - } - echo "
    RoleRemove
    $role_name"; - - - if( in_array( 10, $_roles ) ) { - echo ""; - if ( ! $button_shown ) { - $rowspan=count($roles); - echo "
    \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 "

    Add role: \n"; - - } - } - - echo "


    \n"; - - // slices - echo "

    Slices

    \n"; - if( !empty( $slice_info ) ) { - - foreach( $slice_info as $slice ) { - $slice_name= $slice['name']; - $slice_id= $slice['slice_id']; - - echo "$slice_name
    \n"; - } - - } else { - echo "No slices found for that user"; - } - - if ( ! $peer_id ) { - echo "\n"; - } else { - echo "
    \n"; - } - - } - if( $peer_id ) - echo "
    "; - - echo "

    Back to persons list"; - - } - - -// Print footer -include 'plc_footer.php'; - +if ($_GET['id']) require ('person.php') ; +else require ('persons.php'); ?> diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php new file mode 100644 index 0000000..322f98f --- /dev/null +++ b/planetlab/persons/person.php @@ -0,0 +1,295 @@ +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 "


    \n"; + + // keys + $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) ); + plc_table_title('Keys'); + if ( empty( $key_ids ) ) { + echo " This user has no known key"; + } else { + echo "

    \n"; + echo ""; + if ( $can_manage_keys ) + echo ""; + echo "\n"; + + foreach( $keys as $key ) { + $key_type= $key['key_type']; + $key_id= $key['key_id']; + $key_text= wordwrap( $key['key'], 70, "
    \n", 1 ); + echo "\n"; + } + + echo "
    TypeKeyRemove
    $key_type$key_text"; + + if ( $can_manage_keys ) + echo ""; + + echo "
    \n"; + if ($can_manage_keys) + echo "


    \n"; + } + + if( $can_manage_keys ){ + echo "
    Upload new key: \n + \n +


    \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 (""); + plc_table_row_end (); + } + plc_table_end($table_options); + } + + echo "\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 "

    Select a site to add this user to: "; + echo ""; + + } + echo "


    \n"; + + // roles + echo "

    Roles

    \n"; + echo "

    \n"; + echo ""; + if( plc_is_admin()) + echo ""; + echo "\n"; + + // construct role array + for( $n=0; $n$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 "\n"; + $button_shown=1; + } + } + + echo "\n"; + } + } else { + echo " This user has no known role !!"; + } + echo "
    RoleRemove
    $role_name"; + + + if( plc_is_admin()) { + echo ""; + if ( ! $button_shown ) { + $rowspan=count($roles); + echo "
    \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 "

    Add role: \n"; + + } + } + + echo "


    \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'; + + +?> diff --git a/planetlab/persons/person_action.php b/planetlab/persons/person_actions.php similarity index 94% rename from planetlab/persons/person_action.php rename to planetlab/persons/person_actions.php index d5bb98e..155c1bd 100644 --- a/planetlab/persons/person_action.php +++ b/planetlab/persons/person_actions.php @@ -102,20 +102,20 @@ if( $_GET['dis_id'] ) { } // 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": @@ -199,7 +199,7 @@ if( $_GET['del_id'] ) { $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) ); // start form - echo "
    \n"; + echo "\n"; // show delete confirmation echo "

    Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."

    \n"; @@ -226,4 +226,4 @@ if( $_GET['del_id'] ) { include 'plc_footer.php'; -?> \ No newline at end of file +?> diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php new file mode 100644 index 0000000..b35c675 --- /dev/null +++ b/planetlab/persons/persons.php @@ -0,0 +1,473 @@ +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 " No person whose email matches $emailpattern "; + } 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 "

    GetPersons( empty($filter) ? NULL : $filter, $columns ); + $persons= array_map(layout_person,$persons); + sort_persons( $persons ); + + drupal_set_html_head(' + + '); + + echo "

    \n +
    \n"; + echo paginate( $persons, "person_id" , "Persons", 25, "email"); + echo "\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 "
    \n"; + } else { + echo "
    "; + } + echo "\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 "
    "; + + if (in_array( 10, $_roles )) { + echo plc_event_button("Person","person",$person_id); + echo ""; + } + + echo "\n"; + + if( $enabled == false ) { + echo ""; + echo "   <- This user is not enabled. Choose here to enable or delete."; + } + echo "
    "; + } + + } + + // basic person info + echo "
    "; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
    First Name: $first_name
    Last Name: $last_name
    Title: $title
    Email: $email
    Phone: $phone
    URL: $url
    \n"; + + if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id ) + echo "
    Update info\n"; + + echo "
    \n"; + + // keys + $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id'])); + echo "

    Keys

    \n"; + if( !empty( $key_ids ) ) { + echo "

    \n"; + echo ""; + if ( $can_manage_keys ) + echo ""; + echo "\n"; + + foreach( $key_info as $key ) { + $key_type= $key['key_type']; + $key_id= $key['key_id']; + $key_text= wordwrap( $key['key'], 70, "
    \n", 1 ); + echo "\n"; + } + + echo "
    TypeKeyRemove
    $key_type$key_text"; + + if ( $can_manage_keys ) + echo ""; + + echo "
    \n"; + if ($can_manage_keys) + echo "


    \n"; + + } else { + echo " This user has no known key"; + } + + if( $can_manage_keys ){ + echo "
    Upload new key: \n + \n +


    \n"; + } + // sites + echo "

    Sites

    \n"; + if( !empty( $site_info ) ) { + echo "\n"; + + foreach( $site_info as $site ) { + $site_name= $site['name']; + $site_id= $site['site_id']; + + echo "\n"; + } + echo "
    $site_name ( remove)
    \n"; + echo "\n"; + + } else { + echo " This user is not affiliated with a site !!"; + } + + // 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 "

    Select a site to add this user to: "; + echo ""; + + } + echo "


    \n"; + + // roles + echo "

    Roles

    \n"; + echo "

    \n"; + echo ""; + if( in_array( "10", $_roles ) ) + echo ""; + echo "\n"; + + // construct role array + for( $n=0; $n$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 "\n"; + $button_shown=1; + } + } + + echo "\n"; + } + } else { + echo " This user has no known role !!"; + } + echo "
    RoleRemove
    $role_name"; + + + if( in_array( 10, $_roles ) ) { + echo ""; + if ( ! $button_shown ) { + $rowspan=count($roles); + echo "
    \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 "

    Add role: \n"; + + } + } + + echo "


    \n"; + + // slices + echo "

    Slices

    \n"; + if( !empty( $slice_info ) ) { + + foreach( $slice_info as $slice ) { + $slice_name= $slice['name']; + $slice_id= $slice['slice_id']; + + echo "$slice_name
    \n"; + } + + } else { + echo "No slices found for that user"; + } + + if ( ! $peer_id ) { + echo "\n"; + } else { + echo "
    \n"; + } + + } + if( $peer_id ) + echo "
    "; + + echo "

    Back to persons list"; + + } + + +// Print footer +include 'plc_footer.php'; + + +?> -- 2.43.0