Code

Patch for #6056
[gosa.git] / trunk / gosa-core / plugins / admin / ogroups / class_ogroup.inc
index d36a32fd5370ed5b9f7d62ceda7a1548853cff79..8e1d17061b1b010df278a2b9a9aae3e0902f1ee3 100644 (file)
@@ -67,6 +67,8 @@ class ogroup extends plugin
   var $attributes= array("cn", "description", "gosaGroupObjects","member","accessTo","trustModel");
   var $objectclasses= array("top", "gosaGroupOfNames");
 
+  var $copyMembers = TRUE;
+
   function ogroup (&$config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
@@ -160,8 +162,8 @@ class ogroup extends plugin
     $this->used_workstations = array();
     foreach($res as $og){
       if($og['dn'] == $this->dn) continue;
-      $test = array_intersect($ws_dns,$og['member']);
-      if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
+      $test = array_intersect($ws_dns,LDAP::convert($og['member']));
+      if(($og['gosaGroupObjects'][0] == "[W]" || $og['gosaGroupObjects'][0] == "[T]") && count($test)){
         $this->used_workstations = array_merge($this->used_workstations,$test);
       }
     }
@@ -209,7 +211,14 @@ class ogroup extends plugin
 
       /* Add objects to group */
       if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
-
+        $test = array_unique(array_intersect($this->used_workstations, $_POST['objects']));
+        if(count($test)) {
+          $str = "";
+          foreach($test as $dn) {
+            $str .= "<li>".$dn."</li>";
+          }
+          msg_dialog::display(_("Error"), sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>", $str), ERROR_DIALOG);
+        }
         $tmp = "";
         foreach($this->memberList as $obj){
           $tmp .= $obj['type'];
@@ -220,6 +229,8 @@ class ogroup extends plugin
             $skipped =TRUE;
           }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
             $skipped =TRUE;
+          }elseif(in_array($value, $this->used_workstations)) {
+            continue;
           }else{
             $this->memberList["$value"]= $this->objects[$value];
             $this->member["$value"]= $value;
@@ -900,19 +911,6 @@ class ogroup extends plugin
       $new_dn= $this->dn;
     }
 
-    /* Check if we have workstations assigned, that are already assigned to
-        another object group.  */
-    if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
-      $test =array_intersect($this->used_workstations,$this->member); 
-      if(count($test)){
-        $str = "";
-        foreach($test as $dn){
-          $str .= "<li>".$dn."</li>";
-        }
-        $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
-      }
-    }
-
     $ldap = $this->config->get_ldap_link();
     if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
       $ldap->cat ($new_dn, array('dn'));
@@ -932,8 +930,8 @@ class ogroup extends plugin
       $message[]= msgPool::required(_("Name"));
     }
 
-    if (preg_match('/[=,+<>#;]/', $this->cn)) {
-      $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/");
+    if (preg_match('/[\\\\=\",+<>#;]/', $this->cn)) {
+      $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^\\\\=\"+,<>#;]/");
     }
 
     /* To many different object types? */
@@ -1065,6 +1063,12 @@ class ogroup extends plugin
       $this->gosaGroupObjects =  $source['gosaGroupObjects'][0];
     }
 
+    if (preg_match("/[STW]/", $this->gosaGroupObjects) || !isset($source['member'])) {
+      $this->copyMembers = false;
+    } else {
+      $this->copyMembers = true;
+    }
+
     /* Reload tabs */
     $this->parent->reload($this->gosaGroupObjects );
    
@@ -1092,6 +1096,7 @@ class ogroup extends plugin
   {
     $smarty = get_smarty();
     $smarty->assign("cn",     $this->cn);
+    $smarty->assign("copyMembers",     $this->copyMembers);
     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
     $ret = array();
     $ret['string'] = $str;
@@ -1104,6 +1109,9 @@ class ogroup extends plugin
     if(isset($_POST['cn'])){
       $this->cn = $_POST['cn'];
     }
+    if(!isset($_POST['copyMembers'])){
+      $this->member = array();
+    }
   }