Code

Added copy & paste to gofon Macros
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 13 Jun 2007 12:15:00 +0000 (12:15 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 13 Jun 2007 12:15:00 +0000 (12:15 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6576 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/gofon/macro/class_divListMacros.inc
plugins/gofon/macro/class_gofonMacro.inc
plugins/gofon/macro/class_gofonMacroManagement.inc
plugins/gofon/macro/class_gofonMacroParameters.inc
plugins/gofon/macro/paste_generic.tpl [new file with mode: 0644]

index 8fc64b956806c2f1598214661e0010f9b248bb03..0c16a67ecc62c3de213bf2d983a66a5e1b6c6dc8 100755 (executable)
@@ -42,7 +42,7 @@ class divListMacro extends MultiSelectWindow
     $this->EnableSaveButton (false);
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 60;
+    $action_col_size = 100;
     if($this->parent->snapshotEnabled()){
       $action_col_size += 20;
     }
@@ -126,9 +126,19 @@ class divListMacro extends MultiSelectWindow
     /* Add default header */
     $listhead = MultiSelectWindow::get_default_header();
 
+    /* Get copy & paste icon */
+    $Copy_Paste ="";
+    if(preg_match("/(c.*w|w.*c)/",$acls) &&  $this->parent->CopyPasteHandler){
+      $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
+      $addsep = true;
+    }
+
     if(preg_match("/w/",$acls) && preg_match("/c/",$acls)){
       $listhead .= $this->get_snapshot_header($this->selectedBase);
     }
+
+    $listhead .= $Copy_Paste;      
+
     if(preg_match("/c/",$acls)){
       $listhead .=  " <input class='center' type='image' align='middle' src='images/list_new_macro.png' 
         title='"._("Create new phone macro")."' alt='"._("New")."' name='goFonMacro_new'>&nbsp;";
@@ -142,6 +152,15 @@ class divListMacro extends MultiSelectWindow
     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
         title='"._("Remove selected macros")."' alt='"._("Remove macros")."' name='remove_multiple_macros'>&nbsp;";
 
+    /* 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>";
+    }
+
     $listhead .="</div>";
     $this->SetListHeader($listhead);
   }
@@ -162,7 +181,7 @@ class divListMacro extends MultiSelectWindow
     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 60;
+    $action_col_size = 100;
     if($this->parent->snapshotEnabled()){
       $action_col_size += 20;
     }
@@ -178,6 +197,13 @@ class divListMacro extends MultiSelectWindow
         continue;
       }
 
+      if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$sacl)){
+        $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='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
 
index 05f761b0d2afdc17f026506bc409b5afba73a9d2..7078cf998efc6af5a0214dc1a379b7a728ef1e43 100755 (executable)
@@ -544,6 +544,26 @@ class macro extends plugin
   }
 
 
+  function getCopyDialog()
+  {
+    $smarty = get_smarty();
+    $smarty->assign("cn" ,$this->cn);
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = $_POST['cn'];
+    }
+  }
+
+
   function plInfo()
   {
     return (array(
index f7a0e337f04a4e1c71a6393c190d24b696f11fbd..d51135a015acf23f074fb0217965315c8cab4044 100755 (executable)
@@ -31,6 +31,9 @@ class gofonMacro extends plugin
   var $ui                                      = NULL;
   var $DivListMacro     = NULL;
 
+  var $CopyPasteHandler = NULL;
+  var $start_pasting_copied_objects = FALSE;
+
   function gofonMacro($config, $ui)
   {
     /* Save configuration for internal use */
@@ -38,6 +41,11 @@ class gofonMacro extends plugin
     $this->ui= $ui;
 
     $this->DivListMacro = new divListMacro($this->config,$this);
+
+    /* Copy & Paste enabled ?*/
+    if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
+      $this->CopyPasteHandler = new CopyPasteHandler($this->config);
+    }
   }
 
   function execute()
@@ -76,6 +84,18 @@ class gofonMacro extends plugin
         $s_action="new";
       }elseif(preg_match("/^remove_multiple_macros/",$key)){
         $s_action="del_multiple";
+      }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);
+      }elseif(preg_match("/^multiple_copy_objects/",$key)){
+        $s_action = "copy_multiple";
+      }elseif(preg_match("/^multiple_cut_objects/",$key)){
+        $s_action = "cut_multiple";
       }
     }
     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
@@ -85,6 +105,17 @@ class gofonMacro extends plugin
     $s_entry  = preg_replace("/_.$/","",$s_entry);
 
 
+    /********************
+      Copy & Paste Handling  ...
+     ********************/
+
+    /* Display the copy & paste dialog, if it is currently open */
+    $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
+    if($ret){
+      return($ret);
+    }
+
+
     /*****************
       Create a new Macro 
      *****************/
@@ -370,6 +401,71 @@ class gofonMacro extends plugin
   }
 
 
+  function copyPasteHandling_from_queue($s_action,$s_entry)
+  {
+    /* 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->macros[$s_entry]['dn'];
+      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"macrotabs","MACROTABS","gofonmacro");
+    }
+
+    /* Add entries to queue */
+    if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
+
+      /* Cleanup object queue */
+      $this->CopyPasteHandler->cleanup_queue();
+
+      /* Add new entries to CP queue */
+      foreach($this->list_get_selected_items() as $id){
+        $dn = $this->macros[$id]['dn'];
+
+        if($s_action == "copy_multiple"){
+          $this->CopyPasteHandler->add_to_queue($dn,"copy","macrotabs","MACROTABS","gofonmacro");
+        }
+        if($s_action == "cut_multiple"){
+          $this->CopyPasteHandler->add_to_queue($dn,"cut","macrotabs","MACROTABS","gofonmacro");
+        }
+      }
+    }
+
+    /* 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()){
+
+      /* Load entry from queue and set base */
+      $this->CopyPasteHandler->load_entry_from_queue();
+      $this->CopyPasteHandler->SetVar("base",$this->DivListMacro->selectedBase);
+
+      /* 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("");
+  }
+
+
+
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
index b1ca0a8afe3dab8dad79b05a168777a58ec03629..2960bbeb87c12b54174833e0afa8b6d96bbf835a 100755 (executable)
@@ -402,6 +402,13 @@ class macroParameter extends plugin
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed."),$this->dn));
   }
 
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    $source_o = new macroParameter($this->config,$source['dn']);
+    $this->goFonMacroParameter = $source_o-> goFonMacroParameter;
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
diff --git a/plugins/gofon/macro/paste_generic.tpl b/plugins/gofon/macro/paste_generic.tpl
new file mode 100644 (file)
index 0000000..0f5acf4
--- /dev/null
@@ -0,0 +1,9 @@
+<table summary="">
+       <tr>
+       <td>
+                       <LABEL for="cn">{t}Macro name{/t}</LABEL>{$must}</td>
+               <td>
+                       <input name="cn" id="id" size=13 maxlength=13 value="{$cn}" title="{t}Macro name{/t}">
+               </td>
+       </tr>
+</table>