Code

msgPool
[gosa.git] / gosa-core / include / class_plugin.inc
index 4e3b0a9af128bd3176e22d54deb8811b90a0691d..2bd31a5e33f6829c5b6880509fe3bb8f64162807 100644 (file)
@@ -153,13 +153,13 @@ class plugin
     $this->acl_base= $dn;
 
     /* Get LDAP descriptor */
-    $ldap= $this->config->get_ldap_link();
     if ($dn !== NULL){
 
       /* Load data to 'attrs' and save 'dn' */
       if ($parent !== NULL){
         $this->attrs= $parent->attrs;
       } else {
+        $ldap= $this->config->get_ldap_link();
         $ldap->cat ($dn);
         $this->attrs= $ldap->fetch();
       }
@@ -224,6 +224,9 @@ class plugin
 
         unset($this->saved_attributes["$index"]["count"]);
       }
+      if(isset($this->attrs['gosaUnitTag'])){
+        $this->saved_attributes['gosaUnitTag'] = $this->attrs['gosaUnitTag'][0];
+      }
     }
 
     /* Save initial account state */
@@ -368,7 +371,7 @@ class plugin
   function cleanup()
   {
     foreach ($this->attrs as $index => $value){
-
+      
       /* Convert arrays with one element to non arrays, if the saved
          attributes are no array, too */
       if (is_array($this->attrs[$index]) && 
@@ -800,7 +803,7 @@ class plugin
     $ldap->cd($dst_dn);
     $ldap->add($new);
 
-    if ($ldap->error != "Success"){
+    if (!$ldap->success()){
       trigger_error("Trying to save $dst_dn failed.",
           E_USER_WARNING);
       return(FALSE);
@@ -865,7 +868,7 @@ class plugin
     /* Delete source */
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir_recursive($src_dn);
-    if ($ldap->error != "Success"){
+    if (!$ldap->success()){
       trigger_error("Trying to delete $src_dn failed.",
           E_USER_WARNING);
       return (FALSE);
@@ -1007,7 +1010,7 @@ class plugin
         }
       }
     }
-
+  
     /* Remove tags that may already be here... */
     remove_objectClass("gosaAdministrativeUnitTag", $at);
     if (isset($at['gosaUnitTag'])){
@@ -1019,6 +1022,15 @@ class plugin
       add_objectClass("gosaAdministrativeUnitTag", $at);
       $at['gosaUnitTag']= $tag;
     }
+
+    /* Initially this object was tagged. 
+       - But now, it is no longer inside a tagged department. 
+       So force the remove of the tag.
+       (objectClass was already removed obove)
+     */
+    if($tag == "" && $this->gosaUnitTag){
+      $at['gosaUnitTag'] = array();
+    }
   }
 
 
@@ -1059,9 +1071,13 @@ class plugin
       $password       = $tmp['SNAPSHOT_PASSWORD'];
       $snapldapbase   = $tmp['SNAPSHOT_BASE'];
 
-      $ldap_to        = new LDAP($user,$password, $server);
+      $ldap_to        = new ldapMultipelxer(new LDAP($user,$password, $server));
       $ldap_to -> cd($snapldapbase);
-      show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$snapldapbase));
+
+      if (!$ldap_to->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
+      }
+
     }
 
     /* check if the dn exists */ 
@@ -1107,9 +1123,14 @@ class plugin
       $ldap_to->create_missing_trees($new_base);
       $ldap_to->cd($new_dn);
       $ldap_to->add($target);
-    
-      show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
-      show_ldap_error($ldap_to->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
+      if (!$ldap_to->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $new_dn, LDAP_ADD, get_class()));
+      }
+
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $new_base, "", get_class()));
+      }
+
     }
   }
 
@@ -1181,9 +1202,11 @@ class plugin
       $password     = $cfg['SNAPSHOT_PASSWORD'];
       $snapldapbase = $cfg['SNAPSHOT_BASE'];
 
-      $ldap_to      = new LDAP($user,$password, $server);
+      $ldap_to      = new ldapMultiplexer(new LDAP($user,$password, $server));
       $ldap_to -> cd ($snapldapbase);
-      show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
+      if (!$ldap_to->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
+      }
     }else{
       $ldap_to    = $ldap;
     }
@@ -1237,9 +1260,11 @@ class plugin
       $user         = $cfg['SNAPSHOT_USER'];
       $password     = $cfg['SNAPSHOT_PASSWORD'];
       $snapldapbase = $cfg['SNAPSHOT_BASE'];
-      $ldap_to      = new LDAP($user,$password, $server);
+      $ldap_to      = new ldapMultiplexer(new LDAP($user,$password, $server));
       $ldap_to->cd ($snapldapbase);
-      show_ldap_error($ldap_to->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
+      if (!$ldap_to->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
+      }
     }else{
       $ldap_to    = $ldap;
     }
@@ -1301,9 +1326,11 @@ class plugin
       $user         = $cfg['SNAPSHOT_USER'];
       $password     = $cfg['SNAPSHOT_PASSWORD'];
       $snapldapbase = $cfg['SNAPSHOT_BASE'];
-      $ldap_to      = new LDAP($user,$password, $server);
+      $ldap_to      = new ldapMultiplexer(new LDAP($user,$password, $server));
       $ldap_to->cd ($snapldapbase);
-      show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
+      if (!$ldap_to->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap_to->get_error(), $snapldapbase, "", get_class()));
+      }
     }else{
       $ldap_to    = $ldap;
     }
@@ -1317,7 +1344,9 @@ class plugin
 
     /* Import the given data */
     $ldap->import_complete_ldif($data,$err,false,false);
-    show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, "", get_class()));
+    }
   }