Code

Updated Copy & Paste
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Jun 2007 13:23:42 +0000 (13:23 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Jun 2007 13:23:42 +0000 (13:23 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6562 594d385d-05f5-0310-b6e9-bd551577e9d8

ihtml/themes/default/copyPasteDialog.tpl
include/class_CopyPasteHandler.inc

index a9de778409929a6c526584343dbfb0ad7c0ba51b..b4327460a93938d6e4bf03e256e958b1c314e682 100644 (file)
        <div style='text-align:right;width:100%;'>
                <input type='submit' name='PerformCopyPaste' value='{t}Save{/t}'>&nbsp;
                <input type='submit' name='abort_current_cut-copy_operation' value='{t}Cancel{/t}'>
+       
+       {if $type == "copy"}
                <input type='submit' name='abort_all_cut-copy_operations' value='{t}Cancel all{/t}'>
-               
+       {/if}
        </div>
        {/if}
 {else}
index 83ecc51d91e7e7509267afa1eb65ee9cd554a8c8..44cc6d01cff9b9d5ddc80cad35bdaf8738f08051 100644 (file)
@@ -12,11 +12,12 @@ class CopyPasteHandler {
   var $dialogOpen  = false;
   var $objectdn    = false;
 
-  var $lastdn      = "";
   var $was_successfull = false;
 
   /* this array contains all dns of the currently copyied objects */
   var $queue       = array(); 
+  var $setvar_array= array();
+  var $lastdn      = "";
 
   /* Create CP handler  */
   function CopyPasteHandler($config)
@@ -24,6 +25,7 @@ class CopyPasteHandler {
     $this->config = $config;   
     $this->current= NULL;
     $this->queue  = array();
+    $this->setvar_array = array();
   }
 
 
@@ -71,6 +73,7 @@ class CopyPasteHandler {
   function cleanup_queue()
   {
     $this->current = FALSE;
+    $this->setvar_array = array();
 
     /* Remove all entries from queue */  
     foreach($this->queue as $key => $entry){
@@ -167,19 +170,30 @@ class CopyPasteHandler {
       $entry  = $this->queue[$key];
       $tab_c = $entry['tab_class'];
       $tab_o = $entry['tab_object'];
-      $entry['object']      = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],"new");
+  
+      if($entry['method'] == "copy"){
+        $entry['object']      = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],"new");
+      }else{
+        $entry['object']      = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],$entry['dn'],"users");
+      }
+
+      
+
       $entry['source_data'] = $this->load_attributes_from_hdd($entry['file_name']);
 
-      /* Prepare each plugin of this tab object to be posted */
-      foreach($entry['object']->by_object as $name => $obj){
+      if($entry['method'] == "copy"){
+
+        /* Prepare each plugin of this tab object to be posted */
+        foreach($entry['object']->by_object as $name => $obj){
 
-        /* Prepare every single class, to be copied  */
-        $entry['object']->by_object[$name]->PrepareForCopyPaste($entry['source_data']);
+          /* Prepare every single class, to be copied  */
+          $entry['object']->by_object[$name]->PrepareForCopyPaste($entry['source_data']);
 
-        /* handle some special vars */
-        foreach(array("is_account") as $attr){
-          if(isset($entry['source_data'][$attr])){
-            $entry['object']->by_object[$name]->$attr = $entry['source_data'][$attr];
+          /* handle some special vars */
+          foreach(array("is_account") as $attr){
+            if(isset($entry['source_data'][$attr])){
+              $entry['object']->by_object[$name]->$attr = $entry['source_data'][$attr];
+            }
           }
         }
       }
@@ -217,6 +231,44 @@ class CopyPasteHandler {
   function execute()
   {
     $type = $this->current['method'];
+    if($type == "cut"){
+      if(isset($_POST['PerformCopyPaste'])){
+        while($this->entries_queued()){
+          $this->load_entry_from_queue();      
+          $this->_update_vars();
+
+           $msgs = $this->check();
+           if(count ($msgs) ){
+             foreach( $msgs as $msg){
+               print_red($msg);
+             }
+           }else{
+
+             /* Load next queue entry */
+             $this->lastdn = $this->current['object']->dn;
+             $this->current['object']->save();
+           }
+
+          $this->current =FALSE;
+        }
+      }
+      if($this->current){
+
+        $dns = $this->current['dn']."\n";
+        foreach($this->queue as $entry){
+          $dns .= $entry['dn']."\n";
+        }
+
+        $smarty = get_smarty();
+        $smarty->assign("type","cut");
+        $smarty->assign("Complete",false);
+        $smarty->assign("AttributesToFix","&nbsp;");
+        $smarty->assign("SubDialog",$this->current['object']->SubDialog);
+        $smarty->assign("objectDN"     ,$dns);
+        $smarty->assign("message", sprintf(_("You are going to paste the cutted entry '%s'."), "<pre>".$dns."</pre>"));
+        return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
+      }
+    }
     if($type == "copy"){
       if(isset($_POST['PerformCopyPaste'])){
         $msgs = $this->check();
@@ -225,6 +277,7 @@ class CopyPasteHandler {
             print_red($msg);
           }
         }else{
+          $this->_update_vars();
           $this->current['object']->save();
           $this->lastdn = $this->current['object']->dn;
           $this->current =FALSE;
@@ -287,11 +340,31 @@ class CopyPasteHandler {
   /* Set a single attribute to specified value
    *  example :   ("base", $newBase );    */
   function SetVar($name,$value)
+  {
+    $this->setvar_array[$name]=$value; 
+  }
+
+  
+  /* Update current object attributes, collected via SetVar */
+  function _update_vars()
   {
     if($this->current){
+
+      /* Update all attributes specified with SetVar */
+      foreach($this->setvar_array as $name => $value){
+        if(isset($this->current['object']->$name)){
+          $this->current['object']->$name = $value;
+        }
+      }
+      
+      /* Walk through tabs */
       foreach($this->current['object']->by_object as $key => $obj){
-        if(isset($this->current['object']->by_object[$key]->$name)){
-          $this->current['object']->by_object[$key]->$name = $value;
+
+        /* Update all attributes specified with SetVar */
+        foreach($this->setvar_array as $name => $value){
+          if(isset($this->current['object']->by_object[$key]->$name)){
+            $this->current['object']->by_object[$key]->$name = $value;
+          }
         }
       }
     }
@@ -369,8 +442,6 @@ class CopyPasteHandler {
      Create unique names, ids, or what ever */
   function execute_old()
   {
-    print_a($this->current);
-
     return;
     /* Cut & paste
      */