Code

Added snapshot to groups && fixed restore dialog
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Jun 2006 09:30:24 +0000 (09:30 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Jun 2006 09:30:24 +0000 (09:30 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3798 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/groups/class_divListGroup.inc
plugins/admin/groups/class_groupManagement.inc
plugins/admin/systems/class_SnapShotDialog.inc
plugins/admin/systems/snapshotdialog.tpl

index f8139ab5870acaf79d020f998003092cc33ca9ea..30b1df8a439aac22d4beb18a85b0c19bf7189c4c 100644 (file)
@@ -48,7 +48,7 @@ class divListGroup extends MultiSelectWindow
     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Groupname / Department")));
     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
-    $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:80px;border-right:0px;'"));
+    $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:110px;border-right:0px;'"));
 
     /*                  Text        ,Value    ,Name         ,Is selected */
     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"),          _("Show primary groups"),      true);
@@ -67,6 +67,26 @@ class divListGroup extends MultiSelectWindow
   }
 
 
+ function GetSnapShotActions($dn)
+  {
+    $str = "";
+
+    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;";
+
+      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;";
+      }else{
+        $str.= "<img src='images/empty.png' style='width:16px;' class='center'>&nbsp;";
+      }
+    }
+    return($str);
+  }
+
+
   function GenHeader()
   {
     /* Prepare departments,
@@ -94,13 +114,21 @@ class divListGroup extends MultiSelectWindow
       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
-      " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
-      " <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;".
+      " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;";
+
+
+    if($this->parent->snapshotEnabled()){
+      $listhead .= "  <input class='center' type='image' align='middle' src='images/restore.png'
+        title='"._("Restore snapshopts of already deleted objects")."' alt='"._("Restore")."' name='RestoreDeletedSnapShot'>".
+        " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+    }
+
+    $listhead.=" <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;".
       $Copy_Paste.
       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
-       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
-"'>&nbsp;".
+      " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
+      "'>&nbsp;".
       "</div>";
 
     $this->SetListHeader($listhead);
@@ -138,25 +166,26 @@ class divListGroup extends MultiSelectWindow
     // Space
     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
 
-    /* Create action icons - copy & paste icons */
-    $actions = "";
-    if($this->parent->CopyPasteHandler){
-      $actions.= "<input class='center' type='image'
-        src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
-      $actions.= "<input class='center' type='image'
-        src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
-    }
-    $actions.= "<input class='center' type='image'
-      src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
-    $actions.= "<input class='center' type='image'
-      src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
-
 
     // User and Template  Images
     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
     // Test Every Entry and generate divlist Array
     foreach($groups as $key => $val){
+    
+      /* Create action icons - copy & paste icons */
+      $actions = $this->GetSnapShotActions($val['dn']);
+      if($this->parent->CopyPasteHandler){
+        $actions.= "<input class='center' type='image'
+          src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
+        $actions.= "<input class='center' type='image'
+          src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
+      }
+      $actions.= "<input class='center' type='image'
+        src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
+      $actions.= "<input class='center' type='image'
+        src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
+
 
       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
 
@@ -185,7 +214,7 @@ class divListGroup extends MultiSelectWindow
       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
-      $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
+      $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:110px;border-right:0px;text-align:right;'");
 
       $this->AddElement(array($field1,$field2,$field3,$field4));
     }
index 30309740d75196d112843b707cab8be5088c7e9a..305fd6a9c82657f959ec9aabbd9b922856d9f7bc 100644 (file)
@@ -306,7 +306,9 @@ class groupManagement extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
-      del_lock ($this->grouptab->dn);
+      if(isset($this->grouptab->dn)){
+        del_lock ($this->grouptab->dn);
+      }
       unset ($this->grouptab);
       $this->grouptab= NULL;
       unset($_SESSION['objectinfo']);
@@ -322,16 +324,18 @@ class groupManagement extends plugin
       $display= $this->grouptab->execute();
 
       /* Don't show buttons if tab dialog requests this */
-      if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
-        $display.= "<p style=\"text-align:right\">\n";
-        $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
-        $display.= "&nbsp;\n";
-        if ($this->dn != "new"){
-          $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
+      if(isset($this->grouptab->by_object)){
+        if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
+          $display.= "<p style=\"text-align:right\">\n";
+          $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
           $display.= "&nbsp;\n";
+          if ($this->dn != "new"){
+            $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
+            $display.= "&nbsp;\n";
+          }
+          $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
+          $display.= "</p>";
         }
-        $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
-        $display.= "</p>";
       }
       return ($display);
     }
@@ -518,6 +522,61 @@ class groupManagement extends plugin
   function save_object()
   {
     $this->DivListGroup->save_object();
+        $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->grouptab = 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->grouptab = new SnapShotDialog($this->config,$entry,$this);
+        $this->grouptab->Restore = true;
+      }
+
+      /* Restore one of the already deleted objects */
+      if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = get_groups_ou().$this->DivListGroup->selectedBase;
+        $this->grouptab = new SnapShotDialog($this->config,$entry,$this);
+        $this->grouptab->Restore      = true;
+        $this->grouptab->DeletedOnes  = true;
+      }
+    }
+
+    /* Create a new snapshot requested, check
+       the given attributes and create the snapshot*/
+    if(isset($_POST['CreateSnapshot'])){
+      $this->grouptab->save_object();
+      $msgs = $this->grouptab->check();
+      if(count($msgs)){
+        foreach($msgs as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->dn =  $this->grouptab->dn;
+        $this->create_snapshot("snapshot",$this->grouptab->CurrentDescription);
+        $this->grouptab = 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->grouptab = NULL;
+      }
+    }
   }
 
 
index 0720d70810653e78acade689f69398630f201c43..213bde0aeffd1d8eb738ab59dbb707cf311d2e56 100755 (executable)
@@ -52,6 +52,7 @@ class SnapShotDialog extends plugin
                                $res[base64_encode($entry['dn'])] = $date." - ".$data;
                        }
                        $smarty->assign("SnapShots",$res);
+                       $smarty->assign("CountSnapShots",count($res));
                }
 
                $smarty->assign("RestoreMode",$this->Restore);
index 3495d77cb99d0f3a54cbb71e4a5ad22b5abd7660..e3d1035599c2a181786041ac8c956a3f9cc5863a 100755 (executable)
@@ -8,21 +8,35 @@
 </p>
 <p class="seperator">
 <br>
-<b>{t}You will be able to restore from{/t}</b>
+
+       {if $CountSnapShots!=0}
+               <b>{t}You will be able to restore from{/t}</b>
+       {else}
+               <b>{t}There are no available snapshots.{/t}</b>
+       {/if}
 <br>
 <br>
 </p>
 <br>
 <table summary="">
        <tr>
-               <td>{t}Choose a snapshot and click continue, to restore the snapshot.{/t}
+               <td>
+                       {if $CountSnapShots==0}
+                               {t}There is no snapshot available that could be restored.{/t}
+                       {else}
+                               {t}Choose a snapshot and click continue, to restore the snapshot.{/t}
+                       {/if}
                </td>
        </tr>
        <tr>
                <td>
-                       <select name="SnapShot">
-                               <option value="">&nbsp;</option>
-                               {html_options options=$SnapShots}
+                       <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>
                </td>
        </tr>
@@ -31,7 +45,7 @@
 <p class="seperator">&nbsp;</p>
 <p>
 <div style="width:100%; text-align:right;">
-    <input type='submit' name='RestoreSnapshot' value='{t}Save{/t}'>
+    <input type='submit' name='RestoreSnapshot' value='{t}Save{/t}' {if $CountSnapShots==0} disabled {/if}>
     &nbsp;
     <input type='submit' name='edit_cancel' value='{t}Cancel{/t}'>
 </div></p>