Code

Added copy & paste for groups
[gosa.git] / plugins / admin / groups / class_groupManagement.inc
index 6bf78f1545b001fa94d68605f8923a3467ff036a..0636d6c4460fff0caad0c82bb1b6409caae6506c 100644 (file)
@@ -32,12 +32,20 @@ class groupManagement extends plugin
   var $ui= NULL;
   var $acl= "";
 
+  var $CopyPasteHandler ;
+  var $enableCopyPaste = false;
+
   function groupManagement ($config, $ui)
   {
     /* Save configuration for internal use */
     $this->config= $config;
     $this->ui= $ui;
 
+    if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
+      $this->enableCopyPaste = true;
+    }
+    $this->CopyPasteHandler = new CopyPasteHandler($this->config);
+
     /* Get global filter config */
     if (!is_global("groupfilter")){
       $base= get_base_from_people($ui->dn);
@@ -66,7 +74,6 @@ class groupManagement extends plugin
     $s_action   = "";
     $s_entry    = "";
 
-
     if (!isset($this->grouptab)){
       foreach( array("depselect", "guser", "regex") as $type){
         if (isset($_POST[$type])){
@@ -124,6 +131,14 @@ class groupManagement extends plugin
         $s_action="edit";
         $s_entry  = preg_replace("/".$type."_group_edit_/i","",$key); 
         $_POST['arg'] = $type;
+      }elseif(preg_match("/^editPaste.*/i",$key)){
+        $s_action="editPaste";
+      }elseif(preg_match("/^copy_.*/",$key)){
+        $s_action="copy";
+        $s_entry  = preg_replace("/^copy_/i","",$key);
+      }elseif(preg_match("/^cut_.*/",$key)){
+        $s_action="cut";
+        $s_entry  = preg_replace("/^cut_/i","",$key);
       }
     }
     $s_entry  = preg_replace("/_.$/","",$s_entry); 
@@ -179,6 +194,51 @@ class groupManagement extends plugin
       return($message);
     }
 
+    /* Only perform copy / paste if it is enabled
+     */
+    if($this->enableCopyPaste){
+
+      /* Paste copied/cutted object in here
+       */
+      if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
+        $this->CopyPasteHandler->save_object();
+        $this->CopyPasteHandler->SetVar("base",$groupfilter['depselect']);
+        return($this->CopyPasteHandler->execute());
+      }
+
+
+      /* Copy current object to CopyHandler
+       */
+      if($s_action == "copy"){
+        $this->CopyPasteHandler->Clear();
+        
+        $dn     = $this->grouplist[trim($s_entry)]['dn'];
+        $acl    = get_permissions ($dn, $this->ui->subtreeACL);
+
+        $obj    = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
+        $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
+        $obj->set_acl($acl);
+        $objNew->set_acl($acl);
+        
+        $this->CopyPasteHandler->Copy($obj,$objNew);
+      }
+
+
+      /* Copy current object to CopyHandler
+       */
+      if($s_action == "cut"){
+        $this->CopyPasteHandler->Clear();
+        $dn = $this->grouplist[trim($s_entry)]['dn'];
+        $acl= get_permissions ($dn, $this->ui->subtreeACL);
+
+        $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
+        $obj->set_acl($acl);
+
+        $this->CopyPasteHandler->Cut($obj);
+      }
+    }
+
+
     /* New group? */
     if ($s_action=="new"){
 
@@ -358,6 +418,25 @@ class groupManagement extends plugin
             }
     }
 
+    /* Create paste icon 
+     */
+    if($this->enableCopyPaste){
+      $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+      if($this->CopyPasteHandler->isCurrentObjectPastAble()){
+        if($this->CopyPasteHandler->isCurrentCutted()){
+          $img = "images/cutpaste.png";
+        }else{
+          $img = "images/copypaste.png";
+        }
+        $Copy_Paste .= "<input type='image' name='editPaste' class='center'
+          src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'>&nbsp;";
+      }else{
+        $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'>&nbsp;";
+      }
+    }else{
+      $Copy_Paste ="";
+    }
+
     // Managment
     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
@@ -365,14 +444,29 @@ class groupManagement extends plugin
       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&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;".
+      $Copy_Paste.
       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
       _("Base")."&nbsp;<select name='depselect' 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;".
       "</div>";
 
     
-    $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")."'>";
+    if($this->enableCopyPaste){
+      $actions = "<input class='center' type='image'
+        src='images/editdelete.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")."'>";
+    }else{
+      $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")."'>";
+    }
+
 
     // Defining Links
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
@@ -419,7 +513,7 @@ class groupManagement extends plugin
           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
           array("string" => _("Groupname")." / "._("Department"), "attach" => "style=''"),
           array("string" => _("Properties"), "attach" => "style='width:136px;'"),
-          array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")
+          array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
           ));
 
     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
@@ -443,7 +537,7 @@ class groupManagement extends plugin
       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
       $field3 = array("string" => "&nbsp;", "attach" => "style='width:136px;'");
-      $field4 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
+      $field4 = array("string" => "&nbsp;", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
 
       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
     }
@@ -471,7 +565,7 @@ class groupManagement extends plugin
       $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:60px;border-right:0px;text-align:right;'");
+      $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
       
       $divlist->AddEntry(array($field1,$field2,$field3,$field4));    
     }