- }
- // if no person id, display list of persons to choose
- elseif( !$_GET['id'] ) {
-
- // GetPersons API call
- $persons= $api->GetPersons( NULL, array( "person_id", "first_name", "last_name", "email", "roles" , "peer_id", "enabled" ) );
-
- sort_persons( $persons );
-
- echo "<div>\n
- <form method=post action='/db/persons/allinfo.php'>\n";
- if( $pers_email ) echo "<font color=red>'$pers_email' is not a valid person email.</font>\n";
- echo "<p><label for='testinput'>Query: </label>\n
- <input type='text' id='testinput' name='userquery' size=50 value='' />\n
- <input type=submit value='Search' />\n
- </div>\n
- <br />\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' method='post'>\n";
- } else {
- echo "<div class='plc-foreign'>";
- }
- echo "<input type=hidden name='person_id' value='$person_id'>\n";
-
- if ( ! $peer_id ) {
-# if ( Admin, PI, or user ) allow deletion
- if( in_array( 10, $_roles ) ||
- ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ||
- $_person['person_id'] == $person_id) {
-
- // list to take person action
- echo "<p><select name='actions' onChange=\"submit();\">\n";
-
- $actions= array( ''=>'Choose Action', 'delete'=>"Delete $first_name" );
- $select_end = "</select>\n";
-
-# if ( Admin or PI ) check whether to allow # 'enabling/disabling'.
- if( in_array( 10, $_roles ) ||
- ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) {
-
- if( $enabled == true ) {
- $actions['disable']= "Disable $first_name";
- } else {
- $actions['enable']= "Enable $first_name";
- $select_end = $select_end . " <font color=red size=-1>".
- "<- This user is not enabled. Choose here to enable or delete.</font>";
- }
- if ( in_array( 10, $_roles )) {
- $actions['su'] = "Become $first_name";
- }
- }
-
-# for all cases, list each 'select' key
- foreach( $actions as $key => $val ) {
- echo "<option value='$key'";
-
- if( $key == $_POST['actions'] )
- echo " selected";
-
- echo ">$val\n";
- }
-
- echo $select_end;
- }
- }
-
- // basic person info
- echo "<p><table border=0>\n";
- echo "<tr><td>First Name: </td><td> $first_name</td></tr>\n";
- echo "<tr><td>Last Name: </td><td> $last_name</td></tr>\n";
- echo "<tr><td>Title: </td><td> $title</td></tr>\n";
- echo "<tr><td>Email: </td><td><a href='mailto:$email'>$email</a></td></tr>\n";
- echo "<tr><td>Password: </td><td>***********</td></tr>\n";
- echo "<tr><td>Phone: </td><td>$phone</td></tr>\n";
- echo "<tr><td>URL: </td><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 account information</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></tr></thead><tbody>\n";
-
- foreach( $key_info as $key ) {
- $key_type= $key['key_type'];
- $key_id= $key['key_id'];
- $key_html= wordwrap( $key['key'], 70, "<br />\n", 1 );
- echo "<tr><td>$key_type</td><td>$key_html</td></tr>\n";
- }
-
- echo "</tbody></table>\n";
-
-
- } else {
- echo "<span class='plc-warning'> This user has no known key</span>";
- }
-
- if( $can_manage_keys )
- echo "<p><a href='/db/persons/keys.php?id=$person_id'>Manage Keys</a>\n";
- echo "<hr />";
-
-
- // 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 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] );
- }
-
-
- 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'>";
-
- }
-
- echo "</td></tr>\n";
- }
- } else {
- echo "<span class='plc-warning'> This user has no known role !!</span>";
- }
-
- echo "</tbody></table>\n";
-
- if ( in_array( 10, $_roles ) )
- echo "<input type=submit value='Update Roles'><br />\n";
-
-
-
- // if admin show roles to add
- if( in_array( 10, $_roles ) ) {
- $all_roles= $api->GetRoles();
- $addable_roles= arr_diff( $all_roles, $proles );
-
- if( !empty( $addable_roles ) ) {
- echo "<p><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";
- }