From 196568f754f4ce68dae7af8fad9dcec40df01031 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 16 Mar 2006 10:23:32 +0000 Subject: [PATCH] Added initial copy&paste. Only for apllications right now. To enable and 'Test' this feature, enable it your gosa.conf. (enableCopyPaste="false") git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2848 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/gosa.conf | 1 + html/images/cant_editpaste.png | Bin 0 -> 465 bytes ihtml/themes/default/copyPasteDialog.tpl | 25 +++ include/class_CopyPasteHandler.inc | 198 ++++++++++++++++++ include/class_plugin.inc | 8 +- include/class_tabs.inc | 22 ++ .../applications/class_applicationGeneric.inc | 29 ++- .../class_applicationManagement.inc | 110 ++++++++-- 8 files changed, 377 insertions(+), 16 deletions(-) create mode 100644 html/images/cant_editpaste.png create mode 100644 ihtml/themes/default/copyPasteDialog.tpl create mode 100644 include/class_CopyPasteHandler.inc diff --git a/contrib/gosa.conf b/contrib/gosa.conf index 009a199b5..5ad665ee5 100644 --- a/contrib/gosa.conf +++ b/contrib/gosa.conf @@ -229,6 +229,7 @@
Q0b)r+K~yNu zJQZTOPfPy$Nx^&>W_m zF)-AVzZlHMzM)D&I=Pk*Etpd6#7bdcsL)83KqeE-n|2^JdXAKWBupA=BYllr5KCSC zNpU8iHqh6YK}#GtR!;&ElnR-Af*xy)3N({}N)QCu7`FTC&+V3k+N_{a3nw(hqemZ~ z%@hemv2f|}la^c~Xel*X!acbeNy5hZjnC~=H_6!AM~D9bMCy#5s1X|U00000NkvXX Hu0mjfb@|BV literal 0 HcmV?d00001 diff --git a/ihtml/themes/default/copyPasteDialog.tpl b/ihtml/themes/default/copyPasteDialog.tpl new file mode 100644 index 000000000..01a48a1d2 --- /dev/null +++ b/ihtml/themes/default/copyPasteDialog.tpl @@ -0,0 +1,25 @@ +

{t}Copy & paste wizzard{/t}

+ +{t}This dialog assists you with GOsas copy and paste functionality.{/t}
+{t}Some objects require unique attributes, as example the often used cn should be unique within the complete ldap database in order to exclude a confounding.{/t} +

+{t}If a paste requires such unique attributes, the wizard will display them below.{/t} +

+

 

+
+{if $Complete == false} + {$objectDN} +

+ {$AttributesToFix} +

 

+
+
+   + +
+{else} +

{t}Operation complete{/t}

+
+   +
+{/if} diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc new file mode 100644 index 000000000..c26192a43 --- /dev/null +++ b/include/class_CopyPasteHandler.inc @@ -0,0 +1,198 @@ +config = $config; + $this->current= NULL; + } + + + /* Returns wether the current object can be pasted + */ + function isCurrentObjectPastAble(){ + + /* Check if we got a valid object + */ + if($this->current == NULL){ + return(false); + } + return(true); + } + + + /* Clears all copy & paste informations + */ + function Clear() + { + $this->copyCurrent = false; + $this->cutCurrent = false; + $this->dialogOpen = false; + $this->current = NULL; + } + + + /* Add Object which should be copied + */ + function Copy($obj,$emptyObj) + { + $this->copyCurrent = true; + $this->objectdn = $obj->dn; + $this->current = $emptyObj; + foreach($obj->by_object as $name => $obj){ + foreach($obj->attributes as $attr){ + $this->current->by_object[$name]->$attr = $obj->$attr; + } + } + if($this->isCurrentObjectPastAble()){ + return(true); + }else{ + $this->cutCurrent = $this->copyCurrent = false; + $this->obj = NULL; + } + return(false); + } + + + /* Add Object which should be cutted + */ + function Cut($obj){ + $this->cutCurrent = true; + $this->current = $obj; + if($this->isCurrentObjectPastAble()){ + return(true); + }else{ + $this->cutCurrent = $this->copyCurrent = false; + $this->obj = NULL; + } + return(false); + } + + + /* Returns true if current object + * is cutted. And awaits to be pasted anywhere + */ + function isCurrentCutted(){ + return($this->cutCurrent); + } + + + /* Returns true if current object + * was copied, and awaits to be pasted again + */ + function isCurrentCopied(){ + return($this->copyCurrent); + } + + + /* stillOpen + */ + function stillOpen(){ + if(isset($_POST['AbortCopyPaste'])){ + $this->dialogOpen = false; + } + + return($this->dialogOpen); + } + + + /* Displays a dialog which allows the user to fix all dependencies of this object. + Create unique names, ids, or what ever + */ + function execute() + { + $this->dialogOpen = true; + + /* Cut & paste + */ + if($this->cutCurrent){ + $this->current->save(); + $this->dialogOpen =false; + $smarty = get_smarty(); + $smarty->assign("Complete",true); + $this->Clear(); + return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); + + /* Copy & paste + */ + }else{ + if(isset($_POST['PerformCopyPaste'])){ + $msgs = $this->check(); + if(count ($msgs) ){ + foreach( $msgs as $msg){ + print_red($msg); + } + }else{ + $this->current->save(); + $this->dialogOpen =false; + $smarty = get_smarty(); + $smarty->assign("Complete",true); + $this->Clear(); + return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); + } + } + $smarty = get_smarty(); + $smarty->assign("Complete",false); + $smarty->assign("AttributesToFix",$this->generateAttributesToFix()); + $smarty->assign("objectDN" ,$this->objectdn); + return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); + } + } + + /* Create dialog which asks unique attributes values ... + * calls tabs -> getCopyDialog() + * which calls tab -> getCopyDialog() + */ + function generateAttributesToFix() + { + return($this->current->getCopyDialog()); + } + + + /* Set a single attribute to specified value + * example : ("base", $newBase ); + */ + function SetVar($name,$value) + { + foreach($this-> current->by_object as $key => $obj){ + if(isset($this->current->by_object[$key]->$name)){ + $this->current->by_object[$key]->$name = $value; + } + } + } + + + /* Save new values posted by copy & paste dialog + */ + function save_object() + { + /* Assign posted var to all tabs + */ + $this->current->saveCopyDialog(); + } + + + /* Returns possible errors returned from all including tabs .. + */ + function check() + { + $ret = array(); + foreach($this-> current->by_object as $obj){ + $ret = array_merge($ret , $obj->check()); + } + return($ret); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/include/class_plugin.inc b/include/class_plugin.inc index b34fc5ed0..4f927edf0 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -743,7 +743,13 @@ class plugin } } -} + function saveCopyDialog(){ + } + function getCopyDialog(){ + return(""); + } + +} // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/include/class_tabs.inc b/include/class_tabs.inc index 2fc2fdf0f..9c0ebfd56 100644 --- a/include/class_tabs.inc +++ b/include/class_tabs.inc @@ -245,6 +245,28 @@ class tabs } } + + /* Save attributes posted by copy & paste dialog + */ + function saveCopyDialog() + { + foreach ($this->by_object as $key => $obj){ + $this->by_object[$key]->saveCopyDialog(); + } + } + + + /* return copy & paste dialog + */ + function getCopyDialog() + { + $ret = ""; + foreach ($this->by_object as $key => $obj){ + $ret .= $this->by_object[$key]->getCopyDialog(); + } + return($ret); + } + } ?> diff --git a/plugins/admin/applications/class_applicationGeneric.inc b/plugins/admin/applications/class_applicationGeneric.inc index cedecff9c..f85385ab9 100644 --- a/plugins/admin/applications/class_applicationGeneric.inc +++ b/plugins/admin/applications/class_applicationGeneric.inc @@ -185,8 +185,6 @@ class application extends plugin function save_object() { if (isset($_POST['cn'])){ - - plugin::save_object(); /* Save application flags */ $flag= ""; @@ -366,7 +364,32 @@ $ldap->modify ($this->attrs); } } + function getCopyDialog() + { + $vars = array("cn"); + + $str =" + + + + +
". + _("Application name"). + " + +
"; + + return($str); + } + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + } } - +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/applications/class_applicationManagement.inc b/plugins/admin/applications/class_applicationManagement.inc index 874e803f2..60a83685f 100644 --- a/plugins/admin/applications/class_applicationManagement.inc +++ b/plugins/admin/applications/class_applicationManagement.inc @@ -31,12 +31,27 @@ class applicationManagement extends plugin var $ui= NULL; var $acl= ""; + var $CopyPasteHandler ; + + var $enableCopyPaste = false; + function applicationManagement ($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("appfilter")){ $base= get_base_from_people($ui->dn); @@ -80,14 +95,23 @@ class applicationManagement extends plugin $s_action="edit"; $s_entry = preg_replace("/appl_".$s_action."_/i","",$key); // Post for new - }elseif(preg_match("/dep_back.*/i",$key)){ + }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); + // Post for new + }elseif(preg_match("/^dep_back.*/i",$key)){ $s_action="back"; - }elseif(preg_match("/appl_new.*/",$key)){ + }elseif(preg_match("/^appl_new.*/",$key)){ $s_action="new"; - }elseif(preg_match("/dep_home.*/i",$key)){ + }elseif(preg_match("/^dep_home.*/i",$key)){ $s_action="home"; - }elseif(preg_match("/dep_root.*/i",$key)){ + }elseif(preg_match("/^dep_root.*/i",$key)){ $s_action="root"; + }elseif(preg_match("/^editPaste.*/i",$key)){ + $s_action="editPaste"; } } @@ -147,6 +171,40 @@ class applicationManagement extends plugin } + /* 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",$appfilter['depselect']); + return($this->CopyPasteHandler->execute()); + } + + + /* Copy current object to CopyHandler + */ + if($s_action == "copy"){ + $this->CopyPasteHandler->Clear(); + $dn = $this->applications[$s_entry]['dn']; + $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn); + $objNew = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], "new"); + $this->CopyPasteHandler->Copy($obj,$objNew); + } + + + /* Copy current object to CopyHandler + */ + if($s_action == "cut"){ + $this->CopyPasteHandler->Clear(); + $dn = $this->applications[$s_entry]['dn']; + $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn); + $this->CopyPasteHandler->Cut($obj); + } + } + /* New application? */ if ($s_action=="new"){ @@ -324,6 +382,17 @@ class applicationManagement extends plugin $options.= ""; } } + + if($this->enableCopyPaste){ + $Copy_Paste = "  "; + if($this->CopyPasteHandler->isCurrentObjectPastAble()){ + $Copy_Paste .= " "; + }else{ + $Copy_Paste .= ""._("Can "; + } + }else{ + $Copy_Paste =""; + } // Managment $listhead = "
". @@ -332,14 +401,31 @@ class applicationManagement extends plugin "  ". "  ". "  ". + $Copy_Paste. "  ". _("Base")." ". "  ". "
"; - $actions = ""; - $actions.= ""; + + if($this->enableCopyPaste){ + $actions = " "; + $actions.= " "; + $actions.= ""; + $actions.= ""; + }else{ + + $actions = ""; + $actions.= ""; + } + // Defining Links $linkopen = "%s"; @@ -359,7 +445,7 @@ class applicationManagement extends plugin $divlist->SetHeader(array( array("string" => " ", "attach" => "style='text-align:center;width:20px;'"), array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"), - 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;'") )); @@ -382,7 +468,7 @@ class applicationManagement extends plugin $field1 = array("string" => "department", "attach" => "style='text-align:center;width:20px;'"); $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''"); - $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'"); + $field3 = array("string" => " ", "attach" => "style='width:80px;border-right:0px;text-align:right;'"); $divlist->AddEntry(array($field1,$field2,$field3)); } @@ -397,7 +483,7 @@ class applicationManagement extends plugin } $field1 = array("string" => sprintf($applimg,$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, $actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'"); + $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'"); $divlist->AddEntry(array($field1,$field2,$field3)); } @@ -532,9 +618,9 @@ class applicationManagement extends plugin function remove_lock() { - if (isset($this->apptabs->dn)){ - del_lock ($this->apptabs->dn); - } + if (isset($this->apptabs->dn)){ + del_lock ($this->apptabs->dn); + } } } -- 2.30.2