Code

Added snapshot to users management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Jun 2006 08:36:10 +0000 (08:36 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Jun 2006 08:36:10 +0000 (08:36 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3796 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_SnapShotDialog.inc
plugins/admin/systems/class_divListSystem.inc
plugins/admin/users/class_divListUsers.inc
plugins/admin/users/class_userManagement.inc

index 4da63c0b54e4acb41ee0cc8d8f53e6c3e7d4ab91..0720d70810653e78acade689f69398630f201c43 100755 (executable)
@@ -9,7 +9,7 @@ class SnapShotDialog extends plugin
        var $parent                             = NULL;
        var $Restore                    = false;                /* Defines the restore mode */
        var $DeletedOnes                = false;                /* Specifies which objects will be listed */    
-
+       var $dialog                             = true;
        
        function SnapShotDialog($config,$dn,$parent)
        {
index 7b0097267bcc4bb8fda4cfb153c77909a50ad70b..008c519f8d81f507da7d2120e985b34ec56cf570 100644 (file)
@@ -95,7 +95,7 @@ class divListSystem extends MultiSelectWindow
 
     if($this->parent->snapshotEnabled()){ 
       $listhead .= "  <input class='center' type='image' align='middle' src='images/restore.png'
-        title='"._("Restore objects")."' alt='"._("Up")."' name='RestoreDeletedSnapShot'>".
+        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;";
     }
 
@@ -133,7 +133,7 @@ class divListSystem extends 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 snapshot")."'>&nbsp;";
+        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' 
index 16522abd83b4dbb373d25ca6639d535d3e00c5ac..55efed9eed4225a3b6ec9d7412eaafc0c89f0f5c 100644 (file)
@@ -49,7 +49,7 @@ class divListUsers extends MultiSelectWindow
     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:152px;'"));
-    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:102px;border-right:0px;text-align:right;'"));
+    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:132px;border-right:0px;text-align:right;'"));
     
     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
@@ -66,6 +66,26 @@ class divListUsers extends MultiSelectWindow
     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
   }
 
+  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,
@@ -97,8 +117,15 @@ class divListUsers extends MultiSelectWindow
       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' align='middle' alt='' height='16' width='1'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
+      " <img   class='center' src='images/list_seperator.png' align='middle' 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 class='center' type='image' align='middle' src='images/list_new_user.png' 
       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
       " <input class='center' type='image' align='middle' src='images/list_new.png' 
       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
@@ -132,21 +159,6 @@ class divListUsers extends MultiSelectWindow
     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
-    /* Create action icons */
-    $action = "";
-    if($this->parent->CopyPasteHandler){
-      $action .= "<input class='center' type='image'
-        src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
-      $action.= "<input class='center' type='image'
-        src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
-    }
-    $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
-      name='user_edit_%KEY%' title='"._("Edit user")."'>";
-    $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
-      name='user_chgpw_%KEY%' title='"._("Change password")."'>";
-    $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
-      name='user_del_%KEY%' title='"._("Delete user")."'>";
-    
     /* Possilbe objectClass image combinations */  
     $possibleAccounts = array(
             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
@@ -211,6 +223,22 @@ class divListUsers extends MultiSelectWindow
     // Test Every Entry and generate divlist Array
     foreach($list as $key => $val){
 
+      /* Create action icons */
+      $action = $this->GetSnapShotActions($val['dn']);
+      if($this->parent->CopyPasteHandler){
+        $action .= "<input class='center' type='image'
+          src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
+        $action.= "<input class='center' type='image'
+          src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
+      }
+      $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
+        name='user_edit_%KEY%' title='"._("Edit user")."'>";
+      $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
+        name='user_chgpw_%KEY%' title='"._("Change password")."'>";
+      $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
+        name='user_del_%KEY%' title='"._("Delete user")."'>";
+
+
       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
       $connected  = ""; // This string represents timestamp or offline status
       $ip_port    = ""; // String that will represent ip : port of the connected phone
@@ -281,7 +309,7 @@ class divListUsers extends MultiSelectWindow
       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
-                      "attach" => "style='width:102px;border-right:0px;    text-align:right;'");
+                      "attach" => "style='width:132px;border-right:0px;    text-align:right;'");
       /* Add to list */
       $add = array($field1,$field2,$field3,$field4);
       $this->AddElement($add);
index 362245e0540052215c3597ab519e4cf16029eade..517ef7887bb729e22345a7cb14e9d8f35dc5cb70 100644 (file)
@@ -620,16 +620,18 @@ class userManagement extends plugin
       $display= $this->usertab->execute();
 
       /* Don't show buttons if tab dialog requests this */
-      if (!$this->usertab->by_object[$this->usertab->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->usertab->by_object)){
+        if (!$this->usertab->by_object[$this->usertab->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);
     }
@@ -777,8 +779,8 @@ class userManagement extends plugin
       }
 
       /* Copy selected object 
-          Create a new empty object and the current selected object. 
-          Send both to copy&paste class*/
+         Create a new empty object and the current selected object. 
+         Send both to copy&paste class*/
       if($s_action == "copy"){
         $this->CopyPasteHandler->Clear();
         $dn= $this->list[trim($s_entry)]['dn'];
@@ -791,7 +793,7 @@ class userManagement extends plugin
       }
 
       /* Cut selected object. 
-          Open user object and send it to the copy & paste handler */
+         Open user object and send it to the copy & paste handler */
       if($s_action == "cut"){
         $this->CopyPasteHandler->Clear();
         $dn= $this->list[trim($s_entry)]['dn'];
@@ -807,6 +809,64 @@ class userManagement extends plugin
   {
     /* Handle divlist filter && department selection*/
     $this->DivListUsers->save_object();
+
+    /* check for posts */
+    $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->usertab = 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->usertab = new SnapShotDialog($this->config,$entry,$this);
+        $this->usertab->Restore = true;
+      }
+
+      /* Restore one of the already deleted objects */
+      if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
+        $once = false;
+        $entry = get_people_ou().$this->DivListUsers->selectedBase;
+        $this->usertab = new SnapShotDialog($this->config,$entry,$this);
+        $this->usertab->Restore      = true;
+        $this->usertab->DeletedOnes  = true;
+      }
+    }
+
+    /* Create a new snapshot requested, check
+       the given attributes and create the snapshot*/
+    if(isset($_POST['CreateSnapshot'])){
+      $this->usertab->save_object();
+      $msgs = $this->usertab->check();
+      if(count($msgs)){
+        foreach($msgs as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->dn =  $this->usertab->dn;
+        echo $this->dn;
+        $this->create_snapshot("snapshot",$this->usertab->CurrentDescription);
+        $this->usertab = 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->usertab = NULL;
+      }
+    }
   }
 
   /* A set of disabled and therefore overloaded functions. They are