Code

Added snapshot to deps
[gosa.git] / include / class_plugin.inc
index b30cdcb1d67c5303fb3a6ed6b4dd3ece7e049f52..dda58a731aba9b18f6921aae455172fdeb7c8187 100644 (file)
@@ -100,6 +100,7 @@ class plugin
   var $givenName= "";
   var $acl= "*none*";
   var $dialog= FALSE;
+  var $snapDialog = NULL;
 
   /* attribute list for save action */
   var $attributes= array();
@@ -1018,7 +1019,7 @@ class plugin
       /* Collect some infos */
       $base           = $this->config->current['BASE'];
       $snap_base      = $tmp['SNAPSHOT_BASE'];
-      $base_of_object = dn2base($this->dn);
+      $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
       $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
 
       /* Create object */
@@ -1038,13 +1039,14 @@ class plugin
           an unused value. */ 
       $new_dn                           = "gosaSnapshotTimestamp=".$newName.",".$new_base;
       $ldap_to->cat($new_dn);
-      while($ldap->count()){
+      while($ldap_to->count()){
         $ldap_to->cat($new_dn);
         $newName = preg_replace("/\./", "", $sec."-".($usec++));
         $new_dn                           = "gosaSnapshotTimestamp=".$newName.",".$new_base;
         $target['gosaSnapshotTimestamp']  = $newName;
       } 
 
+
       /* Inset this new snapshot */
       $ldap_to->create_missing_trees($new_base);
       $ldap_to->cd($new_dn);
@@ -1101,7 +1103,7 @@ class plugin
     /* Prepare bases and some other infos */
     $base           = $this->config->current['BASE'];
     $snap_base      = $tmp['SNAPSHOT_BASE'];
-    $base_of_object = dn2base($dn);
+    $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
     $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
     $tmp            = array(); 
 
@@ -1163,8 +1165,12 @@ class plugin
     $ui = get_userinfo();
     $tmp = array();
     $ldap_to->cd($new_base);
-    $ldap_to->search("(&(objectClass=gosaSnapshotObject))",array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
+    $ldap_to->ls("(&(objectClass=gosaSnapshotObject))",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
     while($entry = $ldap_to->fetch()){
+
+      $chk =  str_replace($base,"",$entry['gosaSnapshotDN'][0]);
+      if(preg_match("/,ou=/",$chk)) continue;
+
       if(!isset($entry['description'][0])){
         $entry['description'][0]  = "";
       }
@@ -1179,6 +1185,8 @@ class plugin
       }
     }
 
+    
+
     /* Format result as requested */
     if($raw) {
       return($tmp);
@@ -1227,6 +1235,75 @@ class plugin
     show_ldap_error($ldap_to->get_error().$err, _("Restore snapshot failed."));
   }
 
+
+  function showSnapshotDialog($base,$baseSuffix)
+  {
+    $once = true;
+    foreach($_POST as $name => $value){
+
+      /* Create a new snapshot, display a dialog */
+      if(preg_match("/^CreateSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = preg_replace("/^CreateSnapShot_/","",$name);
+        $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
+        $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
+      }
+
+      /* Restore a snapshot, display a dialog with all snapshots of the current object */
+      if(preg_match("/^RestoreSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = preg_replace("/^RestoreSnapShot_/","",$name);
+        $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
+        $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
+        $this->snapDialog->Restore = true;
+      }
+
+      /* Restore one of the already deleted objects */
+      if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = $baseSuffix.$base;
+        $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
+        $this->snapDialog->Restore      = true;
+        $this->snapDialog->DeletedOnes  = true;
+      }
+    }
+
+    /* Create a new snapshot requested, check
+       the given attributes and create the snapshot*/
+    if(isset($_POST['CreateSnapshot'])){
+      $this->snapDialog->save_object();
+      $msgs = $this->snapDialog->check();
+      if(count($msgs)){
+        foreach($msgs as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->dn =  $this->snapDialog->dn;
+        $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
+        $this->snapDialog = NULL;
+      }
+    }
+
+    /* Restore is requested, restore the object with the posted dn .*/
+    if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
+      $entry =trim($_POST['SnapShot']);
+      if(!empty($entry)){
+        $entry = base64_decode($entry);
+        $this->restore_snapshot($entry);
+        $this->snapDialog = NULL;
+      }
+    }
+   
+    if(isset($_POST['CancelSnapshot'])){
+      $this->snapDialog = NULL;
+    }
+    if($this->snapDialog){
+      $this->snapDialog->save_object();
+      return($this->snapDialog->execute());
+    }
+
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>