Code

First steps implemented to support copy & paste for aclroles
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 14 Jun 2007 07:55:28 +0000 (07:55 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 14 Jun 2007 07:55:28 +0000 (07:55 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6582 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/acl/class_aclManagement.inc
plugins/admin/acl/class_divListACL.inc

index ab61375a1b3c8aafb4b0025500a55efb8c0066d4..04839ad30215654ffd92e6ff3b14f2a8197ff505 100644 (file)
@@ -34,6 +34,7 @@ class aclManagement extends plugin
   var $DivListACL           = NULL;
 
   var $CopyPasteHandler;
+  var $start_pasting_copied_objects = FALSE;
 
   function aclManagement($config, $ui)
   {
@@ -81,6 +82,8 @@ class aclManagement extends plugin
                     "edit_role" =>"^list_acl_role_edit",
                     "copy"      =>"^copy",
                     "cut"       =>"^cut",
+                    "copy_multiple"=> "^multiple_copy_objects",
+                    "cut_multiple" => "^multiple_cut_objects",
                     "editPaste" =>"^editPaste",
                     "addrole"   =>"^new_acl_role");
 
@@ -113,12 +116,10 @@ class aclManagement extends plugin
       Copy & Paste Handling  ...
      ********************/
 
-    /* Only perform copy&paste requests if it is enabled
-     */
-    if($this->CopyPasteHandler){
-      if($str = $this->copyPasteHandling($s_action,$s_entry)){
-        return $str;
-      }
+    /* Display the copy & paste dialog, if it is currently open */
+    $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
+    if($ret){
+      return($ret);
     }
 
 
@@ -425,7 +426,7 @@ class aclManagement extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListACL->SubSearch){
-      $this->DivListACL->AddDepartments($this->DivListACL->selectedBase,3);
+      $this->DivListACL->AddDepartments($this->DivListACL->selectedBase,3,1);
     }
     $this->reload();
     $this->DivListACL->setEntries($this->list);
@@ -514,61 +515,85 @@ class aclManagement extends plugin
   }
 
 
-  /* Perform copy & paste requests
-     If copy&paste is in progress this returns a dialog to fix required attributes
-   */
-  function copyPasteHandling($s_action,$s_entry)
+  function copyPasteHandling_from_queue($s_action,$s_entry)
   {
-    /* Paste copied/cutted object in here
-     */
-    $ui = get_userinfo();
-    if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
-      $this->CopyPasteHandler->save_object();
-      $this->CopyPasteHandler->SetVar("base",$this->DivListGroup->selectedBase);
-      if($str = $this->CopyPasteHandler->execute()){
-        return( $str);
-      };
-      /* Ensure that the new object is shown in the list now */
-      $this->reload();
+    /* Check if Copy & Paste is disabled */
+    if(!is_object($this->CopyPasteHandler)){
+      return("");
     }
 
+    /* Add a single entry to queue */
+    if($s_action == "cut" || $s_action == "copy"){
+
+      /* Cleanup object queue */
+      $this->CopyPasteHandler->cleanup_queue();
+      $dn = $this->list[$s_entry]['dn'];
+  
+      if(isset($this->list[$s_entry]['objectClass']) && in_array("gosaRole",$this->list[$s_entry]['objectClass'])){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"aclroletab","ACLROLETAB","aclroles");
+      }
+    }
 
-    /* Copy current object to CopyHandler
-     */
-    if($s_action == "copy"){
+    /* Add entries to queue */
+    if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
 
-      $dn  = $this->list[trim($s_entry)]['dn'];
-      $acl_all  = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
-      if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+      /* Cleanup object queue */
+      $this->CopyPasteHandler->cleanup_queue();
 
-        $this->CopyPasteHandler->Clear();
-        $obj    = new acl($this->config, NULL, $dn, TRUE);
-        $obj->set_acl_base($dn);
-        $objNew = new acl($this->config, NULL,"new", TRUE);
-        $objNew->set_acl_base($dn);
+      /* Add new entries to CP queue */
+      foreach($this->list_get_selected_items() as $id){
+        $dn = $this->list[$id]['dn'];
 
-        $this->CopyPasteHandler->Copy($obj,$objNew);
-      }else{
-        print_red("You are not allowed to copy this entry.");
+        if(isset($this->list[$id]['objectClass']) && in_array("gosaRole",$this->list[$id]['objectClass'])){
+
+          if($s_action == "copy_multiple"){
+            $this->CopyPasteHandler->add_to_queue($dn,"copy","aclroletab","ACLROLETAB","aclroles");
+          }
+          if($s_action == "cut_multiple"){
+            $this->CopyPasteHandler->add_to_queue($dn,"cut","aclroletab","ACLROLETAB","aclroles");
+          }
+        }
       }
     }
 
-    /* Copy current object to CopyHandler
-     */
-    if($s_action == "cut"){
+    /* Start pasting entries */
+    if($s_action == "editPaste"){
+      $this->start_pasting_copied_objects = TRUE;
+    }
+    /* Return C&P dialog */
+    if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
 
-      $dn = $this->list[trim($s_entry)]['dn'];
-      $acl_all  = $ui->has_complete_category_acls($this->DivListACL->selectedBase,"acl") ;
-      if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+      /* Load entry from queue and set base */
+      $this->CopyPasteHandler->load_entry_from_queue();
+      $this->CopyPasteHandler->SetVar("base",$this->DivListACL->selectedBase);
 
-        $this->CopyPasteHandler->Clear();
-        $obj= new acl($this->config,NULL, $dn, TRUE);
-        $obj->set_acl_base($dn);
-        $this->CopyPasteHandler->Cut($obj);
-      }else{
-        print_red("You are not allowed to cut this entry.");
+      /* Get dialog */
+      $data = $this->CopyPasteHandler->execute();
+
+      /* Return dialog data */
+      if(!empty($data)){
+        return($data);
+      }
+    }
+
+    /* Automatically disable status for pasting */
+    if(!$this->CopyPasteHandler->entries_queued()){
+      $this->start_pasting_copied_objects = FALSE;
+    }
+    return("");
+  }
+
+
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[0-9]*$/",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
       }
     }
+    return($ids);
   }
 
 
index b20002053bf91002ae2391e378b00307497ccc5c..a09716fcc93015db38b88b0855d00125d701ed5e 100644 (file)
@@ -44,7 +44,12 @@ class divListACL extends MultiSelectWindow
     /* Dynamic action col */
     $this->action_col_size = 120;
 
+    /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all'
+      onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
     /* set Page header */
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Summary")));
     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
@@ -151,6 +156,16 @@ class divListACL extends MultiSelectWindow
       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
       "</div>";
 
+        /* Add multiple copy & cut icons */
+    if(is_object($this->parent->CopyPasteHandler)){
+      $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
+        title='"._("Copy selected objects")."' alt='"._("Copy objects")."' name='multiple_copy_objects'>&nbsp;";
+      $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
+        title='"._("cut selected objects")."' alt='"._("Cut objects")."' name='multiple_cut_objects'>&nbsp;";
+      $listhead .= "</div>";
+    }
+
+
     $this->SetListHeader($listhead);
   }
 
@@ -223,10 +238,17 @@ class divListACL extends MultiSelectWindow
         }
       }
 
+      if(in_array("gosaRole",$acl_entry['objectClass'])){
+        $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+            "attach" => "style='width:20px;'");
+      }else{
+        $field0 = array("string" => "", "attach" => "style='width:20px;'");
+      }
+  
       $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,$cn)."&nbsp;","attach" => "");
       $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
-      $this->AddElement(array($field1,$field2,$field3));
+      $this->AddElement(array($field0,$field1,$field2,$field3));
     }
   }