From 583eed02d9be15b6071a443d92a64fb430bc1ccc Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 13 Nov 2006 07:49:10 +0000 Subject: [PATCH] Initial FAI copy & paste test. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5076 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_divListFai.inc | 33 ++++- plugins/admin/fai/class_faiHook.inc | 16 +++ plugins/admin/fai/class_faiManagement.inc | 119 +++++++++++++++++- plugins/admin/fai/class_faiPackage.inc | 17 +++ plugins/admin/fai/class_faiPartitionTable.inc | 16 +++ plugins/admin/fai/class_faiProfile.inc | 18 ++- plugins/admin/fai/class_faiScript.inc | 17 +++ plugins/admin/fai/class_faiTemplate.inc | 16 +++ plugins/admin/fai/class_faiVariable.inc | 16 +++ 9 files changed, 257 insertions(+), 11 deletions(-) diff --git a/plugins/admin/fai/class_divListFai.inc b/plugins/admin/fai/class_divListFai.inc index f1111e60d..4637552b7 100644 --- a/plugins/admin/fai/class_divListFai.inc +++ b/plugins/admin/fai/class_divListFai.inc @@ -57,7 +57,7 @@ class divListFai extends MultiSelectWindow $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); $this->AddHeader(array("string" => _("Name of FAI class"), "attach" => "style=''")); $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'")); - $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")); + $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")); $this->AddCheckBox("ShowProfiles" , _("Display FAI profile objects") ,_("Show profiles") ,true); $this->AddCheckBox("ShowTemplates" , _("Display FAI template objects") ,_("Show templates") ,true); @@ -101,7 +101,17 @@ class divListFai extends MultiSelectWindow } } - /* Create listhead, it will be shown on top of the divlist. + + + + /* Get copy & paste icon */ + if($this->parent->CopyPasteHandler){ + $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon(); + }else{ + $Copy_Paste =""; + } + + /* Create listhead, it will be shown on top of the divlist. * It provides general navigation and object creation */ $listhead = @@ -144,6 +154,8 @@ _("Submit")."'> ". "  ". + $Copy_Paste. + "  ". _("Base")." ". @@ -204,13 +216,22 @@ _("Submit")."'> ". $desc= ""; } + /* Create action icons */ + $action =""; + if($this->parent->CopyPasteHandler){ + $action .= " "; + $action.= " "; + } + if($value['FAIstate'] == "freeze"){ - $action = ""; $edi = $editlink; $acti = $action; }else{ - $action = ""; $action .= ""; @@ -218,10 +239,12 @@ _("Submit")."'> ". $edi = $editlink; } + + $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'"); $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$value['cn'].$desc,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''"); $field3 = array("string" => $info, "attach" => "style='width:200px;'"); - $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'"); + $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:80px;border-right:0px;text-align:right;'"); $this->AddElement(array($field1,$field2,$field3,$field4)); } } diff --git a/plugins/admin/fai/class_faiHook.inc b/plugins/admin/fai/class_faiHook.inc index 75555fd01..6fa2680a2 100644 --- a/plugins/admin/fai/class_faiHook.inc +++ b/plugins/admin/fai/class_faiHook.inc @@ -37,6 +37,9 @@ class faiHook extends plugin var $SubObjects = array(); // All leafobjects of this object var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; function faiHook ($config, $dn= NULL) { @@ -368,6 +371,19 @@ class faiHook extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=hooks,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a fai hook named '%s' in '%s' there is already a hook with the given name."),$this->cn,$r); + } + } return ($message); } diff --git a/plugins/admin/fai/class_faiManagement.inc b/plugins/admin/fai/class_faiManagement.inc index cf0bae1c5..83e4c11ad 100644 --- a/plugins/admin/fai/class_faiManagement.inc +++ b/plugins/admin/fai/class_faiManagement.inc @@ -53,8 +53,8 @@ class faiManagement extends plugin var $dispNewBranch= false; var $dispNewFreeze= false; - var $DivListFai; + var $CopyPasteHandler = NULL; /* construction/reconstruction */ @@ -68,6 +68,11 @@ class faiManagement extends plugin /* Creat dialog object */ $this->DivListFai = new divListFai($this->config,$this); $this->DivListFai->AvailableBranches = $this->getBranches(); + + /* Copy & Paste handler */ + if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){ + $this->CopyPasteHandler= new CopyPasteHandler($this->config); + } } function execute() @@ -116,6 +121,18 @@ class faiManagement extends plugin $s_entry = preg_replace("/_.*$/","",$s_entry); $s_action = "delete"; } + + /* Check for Copy & Paste actions */ + foreach(array( "editPaste" => "editPaste", + "copy" => "copy", + "cut" => "cut") as $act => $action){ + if (preg_match("/".$act.".*/", $name)){ + $s_action= $action; + $s_entry= preg_replace("/".$act."_/i", "", $name); + $s_entry = preg_replace("/_.*$/","",$s_entry); + break; + } + } } if(isset($_GET['edit_entry'])){ @@ -128,6 +145,11 @@ class faiManagement extends plugin $this->dispNewFreeze = false; } + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandling($s_action,$s_entry); + if($ret){ + return($ret); + } /**************** Delete confirme dialog @@ -587,7 +609,102 @@ class faiManagement extends plugin return ($ret); } + + /* Perform copy & paste requests + If copy&paste is in progress this returns a dialog to fix required attributes + */ + function copyPasteHandling($s_action,$s_entry) + { + /* Only perform copy/paste if it is enabled */ + if($this->CopyPasteHandler){ + + /* Prepare current object to be pasted */ + if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){ + + $this->CopyPasteHandler->save_object(); + $this->CopyPasteHandler->SetVar("base", $this->DivListFai->selectedBase); + $this->CopyPasteHandler->SetVar("copy_paste_mode", TRUE); + + $release = $_SESSION['CurrentMainBase']; + if($_SESSION['faifilter']['branch']!="main"){ + $release = $_SESSION['faifilter']['branch']; + } + $this->CopyPasteHandler->SetVar("release", $release); + + /* Execute copy & paste dialog and display returned data, normaly a dialog which allows + us to solve all attribute mismatches for this object. + If nothing is returned, copy & paste was succesfully or aborted */ + if(($ret= $this->CopyPasteHandler->execute())){ + return ($ret); + } + + /* Use the last dn to search for it's ID in the newly generated list. */ + $dn= $this->CopyPasteHandler->lastdn; + + /* Get new list */ + $this->reload(); + foreach($this->objects as $id => $entry){ + if($entry['dn'] == $dn){ + $s_entry= $id; + break; + } + } + } + + /* Copy selected object + Create a new empty object and the current selected object. + Send both to copy&paste class*/ + if($s_action == "copy"){ + $this->CopyPasteHandler->Clear(); + + $dn= $this->objects[$s_entry]['dn']; + $acl= get_permissions ($dn, $this->ui->subtreeACL); + + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + $attr = $ldap->fetch(); + $tmp = $this->get_type($attr); + + if(!count($tmp) == 3 ) return; + + $tabs = $tmp[0]; + $class = $tmp[1]; + $data = $tmp[2]; + + $obj = new $tabs($this->config, $this->config->data['TABS'][$data], $dn); + $objNew = new $tabs($this->config, $this->config->data['TABS'][$data], "new"); + $obj-> set_acl($acl); + $objNew-> set_acl($acl); + $this->CopyPasteHandler->Copy($obj,$objNew); + } + + /* Cut selected object. + Open user object and send it to the copy & paste handler */ + if($s_action == "cut"){ + $this->CopyPasteHandler->Clear(); + $dn= $this->objects[$s_entry]['dn']; + $acl= get_permissions ($dn, $this->ui->subtreeACL); + + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + $attr = $ldap->fetch(); + $tmp = $this->get_type($attr); + + if(!count($tmp) == 3 ) return; + + $tabs = $tmp[0]; + $class = $tmp[1]; + $data = $tmp[2]; + $obj= new $tabs($this->config, $this->config->data['TABS'][$data], $dn); + $obj->set_acl($acl); + $this->CopyPasteHandler->Cut($obj); + } + } + } + + + /* reload list of objects */ function reload() { diff --git a/plugins/admin/fai/class_faiPackage.inc b/plugins/admin/fai/class_faiPackage.inc index d2fe6bac3..e2e112dc9 100644 --- a/plugins/admin/fai/class_faiPackage.inc +++ b/plugins/admin/fai/class_faiPackage.inc @@ -61,6 +61,9 @@ class faiPackage extends plugin "hold", "clean", "aptitude", "aptitude-r", "pending", "dpkgc" ); + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; function faiPackage ($config, $dn= NULL) { @@ -378,9 +381,23 @@ class faiPackage extends plugin $message[]=_("Please choose a valid combination for your repository setup."); } + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=packages,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a fai package list named '%s' in '%s' there is already a package list with the given name."),$this->cn,$r); + } + } return ($message); } + function printUsedPackages(){ $a_ret=array(); if(is_array($this->usedPackages)) { diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index 64604d971..f5ca9f7b1 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -20,6 +20,9 @@ class faiPartitionTable extends plugin var $dialog = NULL; // a dialog, e.g. new disk dialog var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; function faiPartitionTable ($config, $dn= NULL) { @@ -316,6 +319,19 @@ class faiPartitionTable extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=disk,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a new fai partition table named '%s' in '%s' there is already one defined with the given name."),$this->cn,$r); + } + } return ($message); } diff --git a/plugins/admin/fai/class_faiProfile.inc b/plugins/admin/fai/class_faiProfile.inc index 7a6640330..92969c285 100644 --- a/plugins/admin/fai/class_faiProfile.inc +++ b/plugins/admin/fai/class_faiProfile.inc @@ -30,7 +30,12 @@ class faiProfile extends plugin var $FAIclasses = array(); // Contains classname seperated in an array var $FAIAllclasses = array(); // Contains all possible Classnames - var $FAIstate = ""; + var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode= false; + + var $CopyPasteVars = array("FAIclass","FAIclasses","FAIAllclasses","FAIstate"); function faiProfile($config, $dn= NULL) { @@ -87,7 +92,7 @@ class faiProfile extends plugin /* Get ldap connection */ $ldap= $this->config->get_ldap_link(); $ldap->cd($base); - + $sort = array(); /* Capture objects from given base */ $result = array(); foreach($ObjectTypes as $oc => $data){ @@ -389,17 +394,20 @@ class faiProfile extends plugin } $ldap = $this->config->get_ldap_link(); - $ldap->cd($_SESSION['CurrentMainBase']); + $release = "ou=profiles,ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase']; + if($_SESSION['faifilter']['branch']!="main"){ + $release = "ou=profiles,".$_SESSION['faifilter']['branch']; + } + $ldap->cd($release); if ($this->old_cn == ""){ $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn."))",array("*")); } else { $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*")); } - if($ldap->count()){ $message[]=_("There is already a profile with this class name defined."); } - + return ($message); } diff --git a/plugins/admin/fai/class_faiScript.inc b/plugins/admin/fai/class_faiScript.inc index ee8c3c5c1..935b771b2 100644 --- a/plugins/admin/fai/class_faiScript.inc +++ b/plugins/admin/fai/class_faiScript.inc @@ -38,6 +38,10 @@ class faiScript extends plugin var $FAIstate =""; + var $base =""; + var $release =""; + var $copy_paste_mode = false; + function faiScript ($config, $dn= NULL) { /* Load Attributes */ @@ -340,6 +344,19 @@ class faiScript extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=scripts,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a script named '%s' in '%s' there is already a script with the given name."),$this->cn,$r); + } + } return ($message); } diff --git a/plugins/admin/fai/class_faiTemplate.inc b/plugins/admin/fai/class_faiTemplate.inc index 8e7cf4005..e34f5d4bb 100644 --- a/plugins/admin/fai/class_faiTemplate.inc +++ b/plugins/admin/fai/class_faiTemplate.inc @@ -37,6 +37,9 @@ class faiTemplate extends plugin var $SubObjects = array(); // All leafobjects of this object var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; function faiTemplate ($config, $dn= NULL) { @@ -338,6 +341,19 @@ class faiTemplate extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=templates,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a fai template named '%s' in '%s' there is already a template with the given name."),$this->cn,$r); + } + } return ($message); } diff --git a/plugins/admin/fai/class_faiVariable.inc b/plugins/admin/fai/class_faiVariable.inc index 1c596cb50..4b10b70e4 100644 --- a/plugins/admin/fai/class_faiVariable.inc +++ b/plugins/admin/fai/class_faiVariable.inc @@ -35,6 +35,9 @@ class faiVariable extends plugin var $SubObjects = array(); // All leafobjects of this object var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode = false; function faiVariable ($config, $dn= NULL) { @@ -266,6 +269,19 @@ class faiVariable extends plugin /* Call common method to give check the hook */ $message= plugin::check(); + /* If this is a new script, check if a script with this name already exists */ + if(!empty($this->release) && $this->copy_paste_mode){ + + /* Check if current name is already used for fai scripts in selected release */ + $dn = 'cn='.$this->cn.",ou=variables,".$this->release; + $ldap = $this->config->get_ldap_link(); + $ldap->cat($dn); + if($ldap->count()){ + + $r =convert_department_dn($this->release);; + $message[] = sprintf(_("Can't insert a fai variable named '%s' in '%s' there is already a variable with the given name."),$this->cn,$r); + } + } return ($message); } -- 2.30.2