Code

Updated posix plugin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 Dec 2007 14:03:47 +0000 (14:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 Dec 2007 14:03:47 +0000 (14:03 +0000)
- Group membership is now editable for multiple users

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8105 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_multi_plug.inc
gosa-core/include/class_plugin.inc
gosa-core/plugins/personal/posix/class_posixAccount.inc
gosa-core/plugins/personal/posix/generic.tpl

index 06a3ccd7a210f0e80d7a9bb88cbe249b68ca84ec..f9a02ba3e3a02e4be8c6f0393cb068f2d65bd516 100644 (file)
@@ -279,15 +279,12 @@ class multi_plug
    */
   public function populate_values()
   {
-
     if($this->multiple_available() && is_array($this->a_handles)){
       foreach($this->o_tab->by_object as $name => $obj){
 
         $values = $this->o_tab->by_object[$name]->get_multi_edit_values();
         foreach($this->a_handles as $i_id => $o_handle){
-          foreach($values as $a_name => $a_value){
-            $this->a_handles[$i_id]->by_object[$name]->$a_name = $a_value;
-          }
+          $this->a_handles[$i_id]->by_object[$name]->set_multi_edit_values($values);
         }
       }
     }
index da0a6c4d1e6001f4fc9189e5e5a4ad95612d6904..9d4434090c60940007e89458bc600473da931d7f 100644 (file)
@@ -1726,6 +1726,16 @@ class plugin
     return($ret);
   }
 
+  
+  /*! \brief  Update class variables with values collected by multiple edit.
+   */
+  function set_multi_edit_values($attrs)
+  {
+    foreach($attrs as $name => $value){
+      $this->$name = $value;
+    }
+  }
+
 
   /*! \brief execute plugin
 
index e1a5412c9adba153911a6030fb7232617a1e8a4d..e2430559e272bec00a20d350cf028c5ca544321f 100644 (file)
@@ -80,6 +80,7 @@ class posixAccount extends plugin
 
   var $uid= "";
   var $multiple_support = TRUE;
+  var $groupMembership_some = array();
 
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
@@ -509,10 +510,15 @@ class posixAccount extends plugin
     $smarty->assign("shells", $this->loginShellList);
     $smarty->assign("secondaryGroups", $this->secondaryGroups);
     $smarty->assign("primaryGroup", $this->primaryGroup);
-    if (!count($this->groupMembership)){
-      $smarty->assign("groupMembership", array("&nbsp;"));
-    } else {
+    if(!$this->multiple_support_active){
+      if (!count($this->groupMembership)){
+        $smarty->assign("groupMembership", array("&nbsp;"));
+      } else {
+        $smarty->assign("groupMembership", $this->groupMembership);
+      }
+    }else{
       $smarty->assign("groupMembership", $this->groupMembership);
+      $smarty->assign("groupMembership_some", $this->groupMembership_some);
     }
     if (count($this->groupMembership) > 16){
       $smarty->assign("groups", "too_many_for_nfs");
@@ -1038,6 +1044,7 @@ class posixAccount extends plugin
 
     /* Walk through groups and add the descriptive entry if not exists */
     foreach ($groups as $value){
+
       if (!array_key_exists($value, $this->groupMembership)){
         $ldap->cat($value, array('cn', 'description', 'dn'));
         $attrs= $ldap->fetch();
@@ -1052,6 +1059,9 @@ class posixAccount extends plugin
 
         if(obj_is_writable($attrs['dn'],"groups/group","memberUid")){
           $this->groupMembership[$attrs['dn']]= $entry;
+          if($this->multiple_support_active && isset($this->groupMembership_some[$attrs['dn']])){
+            unset($this->groupMembership_some[$attrs['dn']]);
+          }
         }
       }
     }
@@ -1070,6 +1080,11 @@ class posixAccount extends plugin
       if(isset($this->groupMembership[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
         unset($this->groupMembership[$dn_to_del]);
       }
+      if($this->multiple_support_active){
+        if(isset($this->groupMembership_some[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
+          unset($this->groupMembership_some[$dn_to_del]);
+        }
+      }
     }
   }
 
@@ -1403,6 +1418,8 @@ class posixAccount extends plugin
   function get_multi_edit_values()
   {
     $ret = plugin::get_multi_edit_values();
+    $ret['groupMembership']     = $this->groupMembership;
+    $ret['groupMembership_some']= $this->groupMembership_some;
     return($ret);
   }
 
@@ -1427,6 +1444,73 @@ class posixAccount extends plugin
       }
     }
   }
+
+  function init_multiple_support($attrs,$all)
+  {
+    plugin::init_multiple_support($attrs,$all);
+
+    restore_error_handler();
+
+    $groups_some = array();
+    $groups_all  = array();
+    $groups_uid  = array();
+    $uids = array();
+    $first = TRUE;
+
+    $uid_filter="";  
+    for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){
+      $uid = $this->multi_attrs_all['uid'][$i];
+      $uids[] = $uid;
+      $uid_filter.= "(memberUid=".$uid.")"; 
+    }
+    $uid_filter = "(&(objectClass=posixGroup)(|".$uid_filter."))";
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search($uid_filter,array("dn","cn","memberUid"));
+    while($group = $ldap->fetch()){
+      $groups_some[$group['dn']] = $group['cn'][0];
+      for($i = 0 ; $i < $group['memberUid']['count'] ; $i++){
+        $groups_uid[$group['dn']][] = $group['memberUid'][$i];
+      }
+    }
+
+    $groups_all = $groups_some;
+    foreach($groups_all as $id => $group){
+      foreach($uids as $uid){
+        if(!in_array($uid,$groups_uid[$id])){
+          unset($groups_all[$id]);
+          break;
+        }
+      }
+    }
+
+    $this->groupMembership = $groups_all;
+    foreach( $groups_all as $dn => $cn){
+      if(isset($groups_some[$dn])){
+        unset($groups_some[$dn]);
+      }
+    }
+    $this->groupMembership_some = $groups_some;
+  }
+
+
+  function set_multi_edit_values($attrs)
+  {
+    $groups = array();
+
+    /* Update groupMembership, keep optinal group */
+    foreach($attrs['groupMembership_some'] as $dn => $cn){
+      if(isset($this->groupMembership[$dn])){
+        $groups[$dn] = $cn;
+      }
+    }
+    /* Update groupMembership, add forced groups */
+    foreach($attrs['groupMembership'] as $dn => $cn){
+      $groups[$dn] = $cn;
+    }
+    plugin::set_multi_edit_values($attrs);
+    $this->groupMembership = $groups;
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index c9dc98d4779b4123e678e306c9ccd0411dffaa73..5371c53b73c3a57fe5364d7d27f16fd079cfad79 100644 (file)
 {if !$multiple_support}
     {html_options options=$groupMembership}
 {else}
-
-       
+       {foreach from=$groupMembership item=group key=key}
+               <option value="{$key}">{$group}&nbsp;({t}In all groups{/t})</option>
+       {/foreach}
+       {foreach from=$groupMembership_some item=group key=key}
+               <option value="{$key}" 
+                       style='color: #888888; background: #DDDDDD;background-color: #DDDDDD;'>{$group}&nbsp;({t}Not in all groups{/t})</option>
+       {/foreach}
 {/if}
    </select>
 {/render}