From 7a507f102e522d1b09c9f244af2ce7f2fb764579 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 20 Oct 2005 06:00:30 +0000 Subject: [PATCH] Script management changed. 1 FAIscriptEntry will be saved directly, instead of only saving the changes if the base object (FAIscript) was saved. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1626 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_faiScript.inc | 198 +++++---------------- plugins/admin/fai/class_faiScriptEntry.inc | 115 +++++++----- plugins/admin/fai/faiScript.tpl | 1 + plugins/admin/fai/faiScriptEntry.tpl | 14 +- plugins/admin/fai/tabsScript.inc | 10 +- 5 files changed, 136 insertions(+), 202 deletions(-) diff --git a/plugins/admin/fai/class_faiScript.inc b/plugins/admin/fai/class_faiScript.inc index 57de64876..197fdc44b 100644 --- a/plugins/admin/fai/class_faiScript.inc +++ b/plugins/admin/fai/class_faiScript.inc @@ -16,17 +16,6 @@ class faiScript extends plugin /* ObjectClasses for this Object*/ var $objectclasses = array("top","FAIclass","FAIscript"); - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = "FAIscriptEntry"; - var $subClasses = array("top","FAIclass","FAIscriptEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = "faiScriptEntry"; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description","FAIpriority","FAIscript"); - var $sub64coded = array("FAIscript"); - /* Specific attributes */ var $cn = ""; // The class name for this object var $description = ""; // The description for this set of partitions @@ -34,47 +23,13 @@ class faiScript extends plugin var $dialog = NULL; // a dialog, e.g. new disk dialog var $SubObjects = array(); // All leafobjects of this object + /* new dn*/ + var $use_dn =""; + function faiScript ($config, $dn= NULL) { /* Load Attributes */ plugin::plugin ($config, $dn); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. - */ - if($dn != "new"){ - $this->dn =$dn; - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$this->subAttributes); - - while($object = $ldap->fetch()){ - /* Set status for save management */ - - foreach($this->subAttributes as $attrs){ - if(!isset($object[$attrs][0])){ - $this->SubObjects[$object['cn'][0]][$attrs]=""; - }else{ - $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; - } - } - - foreach($this->sub64coded as $codeIt){ - $this->SubObjects[$object['cn'][0]][$codeIt]=(base64_decode($this->SubObjects[$object['cn'][0]][$codeIt])); - } - - foreach($this->subAttributes as $attrs){ - $this->SubObjects[$object['cn'][0]][$attrs]=addslashes($this->SubObjects[$object['cn'][0]][$attrs]); - } - - $this->SubObjects[$object['cn'][0]]['status'] = "edited"; - $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; - } - } } function execute() @@ -85,23 +40,23 @@ class faiScript extends plugin /* Add new sub object */ if(isset($_POST['AddSubObject'])){ - $this->dialog= new $this->subClassName($this->config,"new"); + $this->dialog= new faiScriptEntry($this->config,"new"); + $this->dialog->parent = &$this; $this->is_dialog=true; } /* Edit selected Sub Object */ if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){ - $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$_POST['SubObject']]); + $this->dialog= new faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']); + $this->dialog->parent = &$this; $this->is_dialog=true; } /* Remove Sub object */ if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){ - if($this->SubObjects[$_POST['SubObject']]['status'] == "edited"){ - $this->SubObjects[$_POST['SubObject']]['status']= "delete"; - }else{ - unset($this->SubObjects[$_POST['SubObject']]); - } + $tmp = new faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']); + $tmp->remove_from_parent(); + unset($tmp); } /* Save Dialog */ @@ -113,19 +68,8 @@ class faiScript extends plugin print_red($msg); } }else{ - $obj = $this->dialog->save(); - if(isset($obj['remove'])){ - if($this->SubObjects[$obj['remove']['from']]['status']=="edited"){ - $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; - }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ - unset($this->SubObjects[$obj['remove']['from']]); - } - $obj['status'] = "new"; - $this->SubObjects[$obj['remove']['to']] = $obj; - unset($this->SubObjects[$obj['remove']['to']]['remove']); - }else{ - $this->SubObjects[$obj['cn']]=$obj; - } + $this->dialog->save_object(); + $this->dialog->save(); $this->is_dialog=false; unset($this->dialog); $this->dialog=NULL; @@ -146,8 +90,9 @@ class faiScript extends plugin return($display); } - $smarty->assign("SubObjects",$this->getList()); - $smarty->assign("SubObjectKeys",array_flip($this->getList())); + $buffer = $this->getList(); + $smarty->assign("SubObjects",$buffer); + $smarty->assign("SubObjectKeys",array_flip($buffer)); /* Magic quotes GPC, escapes every ' " \, to solve some security risks * If we post the escaped strings they will be escaped again @@ -167,14 +112,25 @@ class faiScript extends plugin /* Generate listbox friendly SubObject list */ function getList(){ - $a_return=array(); - foreach($this->SubObjects as $obj){ - if($obj['status'] != "delete"){ - if((isset($obj['description']))&&(!empty($obj['description']))){ - $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; - }else{ - $a_return[$obj['cn']]= $obj['cn']; - } + $a_return = array(); + $this->SubObjects = array(); + + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + $ldap->cd ($this->dn); + + $ldap->search("(objectClass=FAIscriptEntry)",array("cn")); + + while($entry = $ldap->fetch()){ + $tmp = array(); + $tmp['cn'] = $entry['cn'][0]; + $tmp['dn']=$entry['dn']; + $this->SubObjects[$tmp['cn']] = $tmp; + + if(isset($entry['description'][0])){ + $a_return[$tmp['cn']] = $tmp['cn']." [".$entry['description'][0]."]"; + }else{ + $a_return[$tmp['cn']] = $tmp['cn']; } } return($a_return); @@ -187,6 +143,7 @@ class faiScript extends plugin $ldap = $this->config->get_ldap_link(); $ldap->cd ($this->dn); $ldap->rmdir_recursive($this->dn); + show_ldap_error($ldap->get_error()); $this->handle_post_events("remove"); } @@ -195,10 +152,12 @@ class faiScript extends plugin */ function save_object() { - plugin::save_object(); - foreach($this->attributes as $attrs){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; + if(isset($_POST['FAIscript_submit'])){ + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } } } } @@ -216,9 +175,12 @@ class faiScript extends plugin function save() { plugin::save(); + + if($this->dn == "new"){ + $this->dn = $this->use_dn; + } $ldap = $this->config->get_ldap_link(); - $ldap->cat($this->dn); if($ldap->count()!=0){ /* Write FAIscript to ldap*/ @@ -232,76 +194,6 @@ class faiScript extends plugin $ldap->add($this->attrs); } show_ldap_error($ldap->get_error()); - - /* Prepare FAIscriptEntry to write it to ldap - * First sort array. - * Because we must delete old entries first. - * After deletion, we perform add and modify - */ - $Objects = array(); - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "delete"){ - $Objects[$name] = $obj; - } - } - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] != "delete"){ - $Objects[$name] = $obj; - } - } - - foreach($Objects as $name => $obj){ - - foreach($this->sub64coded as $codeIt){ - $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt])); - } - - $tmp = array(); - foreach($this->subAttributes as $attrs){ - if(empty($obj[$attrs])){ - $obj[$attrs] = array(); - } - if(!is_array($obj[$attrs])){ - $tmp[$attrs] = stripslashes($obj[$attrs]); - }else{ - $tmp[$attrs] = $obj[$attrs]; - } - } - - $tmp['objectClass'] = $this->subClasses; - - $sub_dn = "cn=".$obj['cn'].",".$this->dn; - - if($obj['status']=="new"){ - $ldap->cat($sub_dn); - if($ldap->count()){ - $obj['status']="modify"; - } - } - - if($obj['status'] == "delete"){ - $ldap->cd($sub_dn); - $ldap->rmdir_recursive($sub_dn); - $this->handle_post_events("remove"); - }elseif($obj['status'] == "edited"){ - $ldap->cd($sub_dn); - $ldap->modify($tmp); - $this->handle_post_events("modify"); - }elseif($obj['status']=="new"){ - if($tmp['description']==array()){ - unset($tmp['description']); - } - if($tmp['FAIscript']==array()){ - $tmp['FAIscript']=" "; - } - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); - $ldap->cd($sub_dn); - $ldap->add($tmp); - $this->handle_post_events("add"); - } - show_ldap_error($ldap->get_error()); - } } } diff --git a/plugins/admin/fai/class_faiScriptEntry.inc b/plugins/admin/fai/class_faiScriptEntry.inc index 1fb0239d9..e2148014f 100644 --- a/plugins/admin/fai/class_faiScriptEntry.inc +++ b/plugins/admin/fai/class_faiScriptEntry.inc @@ -3,37 +3,36 @@ class faiScriptEntry extends plugin { /* CLI vars */ - var $cli_summary= "Manage server basic objects"; - var $cli_description= "Some longer text\nfor help"; - var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); + var $cli_summary = "Manage server basic objects"; + var $cli_description = "Some longer text\nfor help"; + var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* attribute list for save action */ var $ignore_account= TRUE; - var $attributes = array("Object_cn","Object_description","Object_FAIpriority","Object_FAIscript"); - var $objectclasses= array(); + var $attributes = array("cn","description","FAIpriority","FAIscript"); + var $objectclasses= array("FAIscriptEntry"); - var $orig_cn = ""; - - var $Object_dn = ""; - var $Object_cn = ""; - var $Object_FAIpriority = ""; - var $Object_FAIscript = ""; - var $Object_description = ""; - var $Object_status = "new"; + var $orig_cn = ""; + var $dn = ""; + var $cn = ""; + var $FAIpriority = ""; + var $FAIscript = ""; + var $description = ""; + var $status = "new"; + var $parent = false; + var $is_parent_saved = false; - function faiScriptEntry ($config, $dn= NULL,$object=false) + function faiScriptEntry ($config, $dn) { + /* Dn is dn currently assigned to this object + 'new' if object wasn't saved yet + */ plugin::plugin ($config, $dn); if($dn != "new"){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = "Object_".$name; - $this->$oname=$value; - } + $this->orig_cn = $this->cn; }else{ - $this->Object_status = "new"; - $this->orig_cn = false; + $this->status = "new"; + $this->orig_cn = false; } } @@ -51,10 +50,9 @@ class faiScriptEntry extends plugin print_red(_("Selected file is empty.")); }else{ $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name'])); - $this->Object_FAIscript = $str; + $this->FAIscript = $str; } } - foreach($this->attributes as $attrs){ if(get_magic_quotes_gpc()){ @@ -65,13 +63,25 @@ class faiScriptEntry extends plugin } for($i =0 ; $i < 100 ; $i++){ - $Object_FAIprioritys[$i]=$i; + $FAIprioritys[$i]=$i; } - $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys); + $smarty->assign("FAIprioritys",$FAIprioritys); $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE)); return($display); } + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->rmdir_recursive($this->dn); + show_ldap_error($ldap->get_error()); + $this->handle_post_events("remove"); + } + + /* Save data to object */ function save_object() { @@ -91,11 +101,11 @@ class faiScriptEntry extends plugin { $message= array(); - if(empty($this->Object_cn)){ + if(empty($this->cn)){ $message[] = _("Please enter a name."); } - if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){ + if(preg_match("/[^0-9a-z]/i",$this->cn)){ $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed."); } @@ -104,20 +114,45 @@ class faiScriptEntry extends plugin function save() { - $tmp=array(); - foreach($this->attributes as $attrs){ - $attr = preg_replace("/^Object_/","",$attrs); - $tmp[$attr] = $this->$attrs; - } + plugin::save(); - if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ - $tmp['remove']['from'] = $this->orig_cn; - $tmp['remove']['to'] = $tmp['cn']; + /* Get ldap connection */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + + /* First : Check if parent was already saved ... */ + $ldap->cd($this->parent->dn); + $ldap->cat($this->parent->dn); + + /* no entry was found. So save our base object first */ + if($ldap->count()==0){ + $this->parent->save(); + } + + /* Generate this->dn */ + /* if !orig_dn -> This is a new object */ + if($this->orig_cn == false){ + $this->dn = "cn=".$this->cn.",".$this->parent->dn; + $mode = "add"; + }else{ + /* This is an already existing entry, check if cn was changed */ + if($this->orig_cn != $this->cn ){ + /* rename */ + $ldap->cd($this->dn); + $ldap->rmdir($this->dn); + $this->dn = "cn=".$this->cn.",".$this->parent->dn; + $mode = "add"; + }else{ + /* modify */ + $mode = "modify"; + } } - - $tmp['dn'] = $this->dn; - $tmp['status'] = $this->Object_status; - return($tmp); + + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees($this->parent->dn); + $ldap->cd ($this->dn); + $ldap->$mode($this->attrs); + show_ldap_error($ldap->get_error()); } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/plugins/admin/fai/faiScript.tpl b/plugins/admin/fai/faiScript.tpl index 7896626c7..43000d7ee 100644 --- a/plugins/admin/fai/faiScript.tpl +++ b/plugins/admin/fai/faiScript.tpl @@ -49,3 +49,4 @@ + diff --git a/plugins/admin/fai/faiScriptEntry.tpl b/plugins/admin/fai/faiScriptEntry.tpl index 0017e6095..6a137a4ba 100644 --- a/plugins/admin/fai/faiScriptEntry.tpl +++ b/plugins/admin/fai/faiScriptEntry.tpl @@ -9,7 +9,7 @@ {t}Name{/t}{$must}  - + @@ -17,7 +17,7 @@ {t}Description{/t}  - + @@ -30,13 +30,13 @@ @@ -46,14 +46,14 @@
- - + {html_options values=$FAIprioritys output=$FAIprioritys selected=$FAIpriority}

 

  -

- +
diff --git a/plugins/admin/fai/tabsScript.inc b/plugins/admin/fai/tabsScript.inc index b9a63d34b..75f7e39d0 100644 --- a/plugins/admin/fai/tabsScript.inc +++ b/plugins/admin/fai/tabsScript.inc @@ -4,16 +4,22 @@ class tabsScript extends tabs { var $base= ""; - function tabsScript($config, $data, $dn) + function tabsScript($config, $data, $dn, $new_cn = "") { tabs::tabs($config, $data, $dn); + + /* Directly assign a valid dn + * cn can't be changed anymore, since the object was created + */ + $baseobject= $this->by_object['faiScript']; + $use_dn= 'cn='.$new_cn.",ou=scripts,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base']; + $this->by_object['faiScript']->use_dn=$use_dn; } function check() { return (tabs::check(TRUE)); } - function save() { -- 2.30.2