\n";
+$peers->block_start ($peer_id);
+
+if ($local_peer && $privileges && ! $enabled )
+ drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
+
+$enabled_label="Yes";
+if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
+
+$can_update = (plc_is_admin() && $local_peer) || $is_my_account;
+
+$toggle = new PlekitToggle ('person',"Details",
+ array('bubble'=>'Display and modify details for that account',
+ 'visible'=>get_arg('show_details',true)));
+$toggle->start();
+
+$details = new PlekitDetails($can_update);
+
+$details->form_start(l_actions(),array("action"=>"update-person",
+ "person_id"=>$person_id));
+$details->start();
+
+
+$details->th_td("Title",$title,"title",array('width'=>10));
+$details->th_td("First Name",$first_name,"first_name");
+$details->th_td("Last Name",$last_name,"last_name");
+$details->th_td(href("mailto:$email","Email"),$email,"email",array("width"=>30));
+$details->th_td("Phone",$phone,"phone");
+$details->th_td("URL",$url,"url",array('width'=>40));
+$details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
+
+// xxx need to check that this is working
+if ($can_update) {
+ $details->th_td("Password","","password1",array('input_type'=>'password'));
+ $details->th_td("Repeat","","password2",array('input_type'=>'password'));
+ $details->tr_submit("submit","Update Account");
+ $details->space();
+ }
+
+$details->th_td("Enabled",$enabled_label);
+if ( ! $local_peer ) {
+ $details->th_td("Peer",$peers->peer_link($peer_id));
+ $details->space();
+ }
+
+$details->end();
+$details->form_end();
+$toggle->end();
+
+//////////////////// slices
+if ($local_peer) {
+ $slices_title=count_english_warning($slices,'slice');
+ $toggle=new PlekitToggle ('slices',$slices_title,
+ array('visible'=>get_arg('show_slices',false)));
+ $toggle->start();
+
+ if( ! $slices) {
+ plc_warning ("User has no slice");
+ } else {
+ $headers=array('Slice name'=>'string');
+ $reasonable_page=5;
+ $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
+ if (count ($slices) <= $reasonable_page) {
+ $table_options['search_area']=false;
+ $table_options['pagesize_area']=false;
}
+ $table=new PlekitTable ("person_slices",$headers,1,$table_options);
+ $table->start();
- echo "
\n";
- if ($can_manage_keys)
- echo "
\n";
+ foreach( $slices as $slice ) {
+ $slice_name= $slice['name'];
+ $slice_id= $slice['slice_id'];
+ $table->row_start();
+ $table->cell(l_slice_t($slice_id,$slice_name));
+ $table->row_end();
+ }
+ $table->end();
}
+ $toggle->end();
+ }
+
+////////////////////////////////////////
+// we don't set 'action', but use the submit button name instead
+$form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
+$form->start();
+
+//////////////////// keys
+if ($local_peer) {
+ $keys_title = count_english_warning($keys,'key');
+ $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys',false)));
+ $toggle->start();
- if( $can_manage_keys ){
- echo " Upload new key: \n
- \n
-
\n";
+ $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
+ if ( empty( $key_ids ) ) {
+ plc_warning("This user has no known key");
+ }
+
+ $headers=array("Type"=>"string",
+ "Key"=>"string");
+ if ($can_manage_keys) $headers[plc_delete_icon()]="none";
+ // table overall options
+ $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
+ $table=new PlekitTable("person_keys",$headers,"1",$table_options);
+ $table->start();
+
+ if ($keys) foreach ($keys as $key) {
+ $key_id=$key['key_id'];
+ $table->row_start();
+ $table->cell ($key['key_type']);
+ $table->cell(wordwrap( $key['key'], 60, " \n", 1 ));
+ if ($can_manage_keys)
+ $table->cell ($form->checkbox_html('key_ids[]',$key_id));
+ $table->row_end();
+ }
+ // the footer area is used for displaying key-management buttons
+ // add the 'remove keys' button and key upload areas as the table footer
+ if ($can_manage_keys) {
+ $table->tfoot_start();
+ // no need to remove if there's no key
+ if ($keys) {
+ $table->row_start();
+ $table->cell($form->submit_html ("delete-keys","Remove keys"),
+ array('hfill'=>true,'align'=>'right'));
+ $table->row_end();
+ }
+ $table->row_start();
+ $table->cell($form->label_html("key","Upload new key")
+ . $form->file_html("key","upload",array('size'=>60))
+ . $form->submit_html("upload-key","Upload key"),
+ array('hfill'=>true,'align'=>'right'));
+ $table->row_end();
}
- // sites
- plc_table_title('Sites');
+ $table->end();
+ $toggle->end();
+ }
+
+//////////////////// sites
+if ($local_peer) {
+ $sites_title = count_english_warning($sites,'site');
+ $toggle=new PlekitToggle('sites',$sites_title,
+ array('visible'=>get_arg('show_sites',false)));
+ $toggle->start();
- // 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);
+ }
+ $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
+ $headers=array();
+ $headers['Login_base']="string";
+ $headers['Name']="string";
+ if ($can_manage_sites) $headers[plc_delete_icon()]="none";
+ $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
+ $table=new PlekitTable ("person_sites",$headers,0,$table_options);
+ $table->start();
+ foreach( $sites as $site ) {
+ $site_name= $site['name'];
+ $site_id= $site['site_id'];
+ $login_base=$site['login_base'];
+ $table->row_start();
+ $table->cell ($login_base);
+ $table->cell (l_site_t($site_id,$site_name));
+ if ($can_manage_sites)
+ $table->cell ($form->checkbox_html('site_ids[]',$site_id));
+ $table->row_end ();
}
+ if ($can_manage_sites) {
+ $table->tfoot_start();
- 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 "";
-
+
+ $table->row_start();
+
+ // get list of local sites that the person is not in
+ function get_site_id ($site) { return $site['site_id'];}
+ $person_site_ids=array_map("get_site_id",$sites);
+ $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids, '-SORT'=>'name'), $site_columns);
+ // xxx cannot use onchange=submit() - would need to somehow pass action name
+ function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
+ $selectors = array_map ("site_selector",$relevant_sites);
+ $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
+ $form->submit_html("add-person-to-site","Add in site"),
+ array('hfill'=>true,'align'=>'right'));
+ $table->row_end();
}
- echo "
\n";
- $button_shown=1;
- }
- }
-
- echo "\n";
- }
- } else {
- echo " This user has no known role !!";
+ // construct array of role objs
+ $role_objs=array();
+ for ($n=0; $n$role_ids[$n], 'name'=>$roles[$n]);
}
- 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 "