cannot disable my own account
[plewww.git] / planetlab / persons / person.php
index dac8028..4e978af 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 // Require login
 require_once 'plc_login.php';
 
@@ -69,22 +67,24 @@ $local_peer = ! $peer_id;
 
 $peers = new Peers ($api);
 
+if (count($site_ids))
+    $site_id = $site_ids[0];
 $is_my_account = plc_my_person_id() == $person_id;
-$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+$privileges = plc_is_admin () || ( plc_in_site($site_ids[0]) && plc_is_pi());
 
 $tabs=array();
 
 // enable / disable
 // become
-if (plc_is_admin() && ! $is_my_account && $local_peer) 
+if (plc_is_admin() && ! $is_my_account && $local_peer && $enabled
   $tabs['Become'] = array('method'=>'POST',
                          'url'=>l_actions(),
                          'values'=>array('action'=>'become-person',
                                          'person_id'=>$person_id),
                          'bubble'=>"Become $first_name $last_name",
-                         'confirm'=>"Are you sure you want to su $first_name $last_name");
+                         'confirm'=>"Are you sure you want to become $first_name $last_name");
     
-if ($local_peer && $privileges) 
+if ($local_peer && $privileges && ! $is_my_account
   if ($enabled) 
     $tabs['Disable'] = array ('method'=>'POST',
                              'url'=>l_actions(),
@@ -139,10 +139,10 @@ $details->form_start(l_actions(),array("action"=>"update-person",
 $details->start();
 
 
-$details->th_td("Title",$title,"title",array('width'=>5));
+$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");
+$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));
@@ -297,7 +297,7 @@ if ($local_peer) {
     // 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), $site_columns);
+    $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);
@@ -311,13 +311,13 @@ if ($local_peer) {
  }
 //////////////////// roles
 if ($local_peer) {
-  $toggle=new PlekitToggle ('roles','Roles',array('visible'=>get_arg('show_roles',false)));
+  $toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles',false)));
   $toggle->start();
 
   if (! $roles) plc_warning ("This user has no role !");
 
-  $can_manage_roles= ($local_peer && plc_is_admin());
-  $table_options=array("search_area"=>false,"notes_area"=>false);
+  $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
+  $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site );
 
   $headers=array("Role"=>"string");
   if ($can_manage_roles) $headers [plc_delete_icon()]="none";
@@ -341,6 +341,8 @@ if ($local_peer) {
 
   // footers : the remove and add buttons
   if ($can_manage_roles) {
+
+    // remove
     $table->tfoot_start();
     if ($roles) {
       $table->row_start();
@@ -349,14 +351,26 @@ if ($local_peer) {
       $table->row_end();
     }
 
-    $table->row_start();
-    $selectors=$form->role_selectors_excluding($api,$role_ids);
-    $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
-    // add a role : the button
-    $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
-    $table->cell ($add_role_left_area . $add_role_right_area,
-                 array('hfill'=>true,'align'=>'right'));
-    $table->row_end();
+    // add
+    // compute the roles that can be added
+    if (plc_is_admin()) 
+      // all roles
+      $exclude_role_ids=array();
+    else
+      // all roles except admin and pi
+      $exclude_role_ids=array(10,20);
+    $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
+    $roles_to_add = roles_except ($possible_roles,$role_ids);
+    if ( $roles_to_add ) {
+      $selectors=$form->role_selectors($roles_to_add);
+      $table->row_start();
+      $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
+      // add a role : the button
+      $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
+      $table->cell ($add_role_left_area . $add_role_right_area,
+                   array('hfill'=>true,'align'=>'right'));
+      $table->row_end();
+    }
   }
   $table->end();
   $toggle->end();