Code

Updated objectGroups
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 2 Sep 2008 08:49:16 +0000 (08:49 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 2 Sep 2008 08:49:16 +0000 (08:49 +0000)
-It s no longer possible to add a workstation to more than one object group.

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

gosa-core/plugins/admin/ogroups/class_ogroup.inc

index 029feeb1730ec1fae99dcd70ba463fce68d27fe0..497183659bfa9210504bbcc1ec611415001becc6 100644 (file)
@@ -59,6 +59,10 @@ class ogroup extends plugin
 
   var $was_trust_account= FALSE;
 
+  /* Already assigned Workstations. Will be hidden in selection. 
+   */
+  var $used_workstations = array();
+
   /* attribute list for save action */
   var $attributes= array("cn", "description", "gosaGroupObjects","member","accessTo","trustModel");
   var $objectclasses= array("top", "gosaGroupOfNames");
@@ -140,6 +144,28 @@ class ogroup extends plugin
       }
     }
 
+    /* Detect all workstations, which are already assigned to an object group  
+        - Those objects will be hidden in the add object dialog.
+        - Check() will complain if such a system is assigned to this object group.
+     */ 
+    $base = $this->config->current['BASE'];
+    $res    = get_list("(objectClass=gotoWorkstation)","none" , 
+        $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
+    $ws_dns = array();
+    foreach($res as $data){
+      $ws_dns[] = $data['dn'];
+    }
+    $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
+        $base, array("dn","member"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
+    $this->used_workstations = array();
+    foreach($res as $og){
+      if($og['dn'] == $this->dn) continue;
+      $test = array_intersect($ws_dns,$og['member']);
+      if(count($test)){
+        $this->used_workstations = array_merge($this->used_workstations,$test);
+      }
+    }
+
     $this->orig_cn = $this->cn;
     $this->orig_base = $this->base;
 
@@ -677,6 +703,12 @@ class ogroup extends plugin
         /* fetch results and append them to the list */
         foreach($res as $attrs){
 
+          /* Skip workstations which are already assigned to an object group.
+           */
+          if(in_array($attrs['dn'],$this->used_workstations)){
+            continue;
+          }
+
           $type= $this->getObjectType($attrs);
           $name= $this->getObjectName($attrs);
 
@@ -857,6 +889,23 @@ class ogroup extends plugin
       $new_dn= $this->dn;
     }
 
+    /* Check if we have workstations assigned, that are already assigned to
+        another object group.
+     */
+    $test =array_intersect($this->used_workstations,$this->member); 
+    if(count($test)){
+      $str = "";
+      $cnt = 0;
+      foreach($test as $dn){
+        $str .= $dn.",  ";
+        $cnt ++;
+        if($cnt > 2){
+          $str .= "...";
+          break;
+        }
+      }
+#      $message[] = sprintf(_("The following workstations are already member in another object group and can not be added: '%s'"),$str);
+    }
 
     $ldap = $this->config->get_ldap_link();
     if($this->dn != $new_dn){