Code

Added a divlist that allows us to delete existing snap shots
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Jun 2006 09:24:25 +0000 (09:24 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Jun 2006 09:24:25 +0000 (09:24 +0000)
This is an initial commit, there possibly follow some fixes

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

ihtml/themes/default/snapshotdialog.tpl
include/class_MultiSelectWindow.inc
include/class_SnapShotDialog.inc
include/class_plugin.inc

index c71b0704183e7bc48c60dd01874a99f1606ae28a..677bc17ec5f0d25c7c2a21369079dc62146d8d49 100755 (executable)
        </tr>
        <tr>
                <td>
-                       <select name="SnapShot" {if $CountSnapShots==0} disabled {/if}>
-                               {if $CountSnapShots==0} disabled 
-                                       <option value="">&nbsp;{t}none{/t}&nbsp;</option>
-                               {else}
-                                       <option value="">&nbsp;</option>
-                                       {html_options options=$SnapShots}
-                               {/if}
-                       </select>
+                       {$SnapShotDivlist}
                </td>
        </tr>
 </table>
index 8481095f07e457aaf426bc5402a57d0a5ff075e6..59aa9eb22419221c4a7cb1e217bd294fdcc42ead 100644 (file)
@@ -491,11 +491,11 @@ class MultiSelectWindow{
     if($this->parent->snapshotEnabled()){
 
       $str .="<input class='center' type='image' src='images/snapshot.png'
-        alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'>&nbsp;";
+        alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'>&nbsp;";
 
       if(count($this->parent->Available_SnapsShots($dn))){
         $str .="<input class='center' type='image' src='images/restore.png'
-          alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
+          alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
       }else{
         $str.= "<img src='images/empty.png' style='width:16px;' class='center'>&nbsp;";
       }
index 9e42c81a6a733d5c27516016bcd87c1c0c0beee6..9391c1370493078d02ab910b7c10d2ec6ba108dc 100755 (executable)
@@ -11,11 +11,15 @@ class SnapShotDialog extends plugin
        var $display_all_removed_objects= false;                /* Specifies which objects will be listed, all snapshots for a single entry 
                                                                                                                or all snapshots of already deleted objects  */ 
        var $dialog                                             = true;
+       var $del_dn                                             = "";
+       var $ui;
+       var $acl;
        
        function SnapShotDialog($config,$dn,$parent)
        {
                plugin::plugin($config,$dn);
-               $this->parent = $parent;
+               $this->parent   = $parent;
+               $this->ui               = get_userinfo();
        }
        
        
@@ -24,6 +28,41 @@ class SnapShotDialog extends plugin
        {
                plugin::execute();
                $smarty = get_smarty();
+       
+               $once = true;
+               foreach($_POST as $name => $value){
+                       if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
+                               $once = false;
+       
+                               $entry = preg_replace("/^RemoveSnapShot_/","",$name);
+                               $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
+
+                               $acl                    = get_permissions ($entry, $this->ui->subtreeACL);
+                               $this->acl              = get_module_permission($acl, "snapshot", $entry );
+
+                               if (chkacl($this->acl, "delete") == ""){
+                                       $this->del_dn   = $entry;
+                                       $smarty= get_smarty();
+                                       $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), @LDAP::fix($this->del_dn)));
+                                       return($smarty->fetch (get_template_path('remove.tpl')));
+                               } else {
+
+                                       /* Obviously the user isn't allowed to delete. Show message and
+                                          clean session. */
+                                       print_red (_("You are not allowed to delete this snap shot!"));
+                               }
+                       }
+               }
+
+               /* Remove snapshot */
+               if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
+                       $acl                    = get_permissions ($this->del_dn, $this->ui->subtreeACL);
+                       $this->acl              = get_module_permission($acl, "snapshot", $this->del_dn);
+                       if (chkacl($this->acl, "delete") == ""){
+                               $this->remove_snapshot($this->del_dn);
+                               $this->del_dn = "";
+                       }       
+               }
 
                /* We must restore a snapshot */
                if($this->display_restore_dialog){
@@ -43,25 +82,43 @@ class SnapShotDialog extends plugin
                        }else{
                                $tmp = $this->Available_SnapsShots($this->dn,true);
                        }
-               
+
+                       $DivListSnapShots = new DivSelectBox("SnapShotRestore");
+                       $DivListSnapShots->SetHeight(180);
+
+                       $list_of_elements = array();                    
+                       
                        /* Walk through all entries and setup the display text */
                        foreach($tmp as $key => $entry){
-                       
-                               $data = $entry['description'][0];
-                               $date = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
-                               if($this->display_all_removed_objects){
-                                       $data.= " - ".$entry['gosaSnapshotDN'][0];
-                               }
+                               $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
+                               $list_of_elements[$TimeStamp] = $entry;
+                       }
+
+                       /* Sort generated list */
+                       krsort($list_of_elements);
        
-                               if(strlen($data) > 83){
-                                       $data= substr($data,0,80)." ...";
+                       /* Add Elements to divlist */   
+                       foreach($list_of_elements as $entry){
+
+                               $actions = "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY' title='"._("Remove snapshot")."'>&nbsp;";
+                               $actions.= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY' title='"._("Restore snapshot")."'>&nbsp;";
+
+                               $time_stamp     = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
+                               $display_data   = $entry['description'][0];
+
+                               if($this->display_all_removed_objects){
+                                       $display_data.= " - ".$entry['gosaSnapshotDN'][0];
                                }
-       
-                               $res[base64_encode($entry['dn'])] = $date." - ".$data;
-                       }
-                       natcasesort($res);
-                       $smarty->assign("SnapShots",array_reverse($res));
-                       $smarty->assign("CountSnapShots",count($res));
+
+                               $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
+                               $field1 = array("string"=> $display_data , "attach"=> "");
+                               $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) , 
+                                                               "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
+                               $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
+                       }               
+
+                       $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());       
+                       $smarty->assign("CountSnapShots",count($list_of_elements));
                }
 
                $smarty->assign("RestoreMode",$this->display_restore_dialog);
index 323fbeddfe0f7ae6aa49bc964e70fec496fa73a1..c56cfae687e9f38d8e8b144314cc3a8ec8e38842 100644 (file)
@@ -996,12 +996,6 @@ class plugin
 
     /* Get configuration from gosa.conf */
     $tmp = $this->config->current;
-    /* Check if the undo level is specified */
-    if(isset($tmp['SNAPSHOT_UNDO_LEVEL'])){      
-      $UndoLvl   = $tmp['SNAPSHOT_UNDO_LEVEL'];
-    }else{
-      $UndoLvl   = 5;
-    }
 
     /* Create lokal ldap connection */
     $ldap= $this->config->get_ldap_link();
@@ -1025,7 +1019,6 @@ class plugin
       show_ldap_error($ldap_to->get_error(), _("Snapshot failed."));
     }
 
-
     /* check if the dn exists */ 
     if ($ldap->dn_exists($this->dn)){
 
@@ -1071,23 +1064,21 @@ class plugin
 
       show_ldap_error($ldap_to->get_error(), _("Create snapshot failed."));
       show_ldap_error($ldap->get_error(), _("Create snapshot failed."));
+    }
+  }
 
-      /* Check amount of used snapshots, and remove old ones if necessary */
-      $test = $this->Available_SnapsShots($this->dn,true);
-      if(count($test) > $UndoLvl){
-        $toDel = array();
-        foreach($test as $entry){
-          $toDel[preg_replace("/-/","",$entry['gosaSnapshotTimestamp'][0])] = $entry['dn'];
-        }
-        krsort($toDel);
-        $i = 0 ; 
-        foreach($toDel as $entryID => $entry){
-          $i ++ ; 
-          if($i > $UndoLvl){
-            $ldap_to->rmdir_recursive($entry);
-          }
-        }
-      }
+  function remove_snapshot($dn)
+  {
+    $ui   = get_userinfo();
+    $acl  = get_permissions ($dn, $ui->subtreeACL);
+    $acl  = get_module_permission($acl, "snapshot", $dn);
+
+    if (chkacl($this->acl, "delete") == ""){
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->rmdir_recursive($dn);
+    }else{
+      print_red (_("You are not allowed to delete this snap shot!"));
     }
   }
 
@@ -1290,17 +1281,17 @@ class plugin
     foreach($_POST as $name => $value){
 
       /* Create a new snapshot, display a dialog */
-      if(preg_match("/^CreateSnapShot_/",$name) && $once){
+      if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
         $once = false;
-        $entry = preg_replace("/^CreateSnapShot_/","",$name);
+        $entry = preg_replace("/^CreateSnapShotDialog_/","",$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){
+      if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
         $once = false;
-        $entry = preg_replace("/^RestoreSnapShot_/","",$name);
+        $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
         $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
         $this->snapDialog->display_restore_dialog = true;
@@ -1313,6 +1304,17 @@ class plugin
         $this->snapDialog->display_restore_dialog      = true;
         $this->snapDialog->display_all_removed_objects  = true;
       }
+
+      /* Restore selected snapshot */
+      if(preg_match("/^RestoreSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = preg_replace("/^RestoreSnapShot_/","",$name);
+        $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
+        if(!empty($entry)){
+          $this->restore_snapshot($entry);
+          $this->snapDialog = NULL;
+        }
+      }
     }
 
     /* Create a new snapshot requested, check
@@ -1333,12 +1335,6 @@ class plugin
 
     /* 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'])){