From aa2719f8feacc18fad13404ede9ffa743f3544db Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 5 Jul 2009 22:13:17 +1000 Subject: [PATCH] Template modifications now add/remove attributes as per the template definition --- htdocs/update_confirm.php | 66 +++++++++++++++++++++++++++++++++------ lib/Attribute.php | 15 +++++++-- lib/Template.php | 14 ++++++--- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/htdocs/update_confirm.php b/htdocs/update_confirm.php index e9f7bf6..7d735a9 100644 --- a/htdocs/update_confirm.php +++ b/htdocs/update_confirm.php @@ -54,6 +54,15 @@ if (count($request['template']->getLDAPmodify(true))) { _('Attribute'),_('Old Value'),_('New Value'),_('Skip')); echo "\n\n"; + # If we skip objectclass changes, but there are new must/may attrs provided by the new objectclass, they need to be skip. + $mustattrs = array(); + foreach ($request['template']->getAttribute('objectclass')->getValues() as $value) { + $soc = $app['server']->getSchemaObjectClass($value); + + foreach ($soc->getMustAttrs() as $sma) + array_push($mustattrs,$sma->getName()); + } + $counter = 0; foreach ($request['template']->getLDAPmodify(true) as $attribute) { $counter++; @@ -109,23 +118,60 @@ if (count($request['template']->getLDAPmodify(true))) { $input_disabled = ''; $input_onclick = ''; - if ($attribute->isForceDelete()) + if ($attribute->isForceDelete() || in_array($attribute->getName(),$mustattrs)) $input_disabled = 'disabled="disabled"'; - if ($attribute->getName() == 'objectclass' && (count($request['template']->getForceDeleteAttrs()) > 0)) { - $input_onclick = 'onclick="if (this.checked) {'; + if ($attribute->getName() == 'objectclass') { + $input_onclick = ''; - foreach ($request['template']->getForceDeleteAttrs() as $ad_name) { - $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = false;",$ad_name->getName()); - $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = true;",$ad_name->getName()); + if (count($request['template']->getForceDeleteAttrs()) > 0) { + $input_onclick = 'onclick="if (this.checked) {'; + + foreach ($request['template']->getForceDeleteAttrs() as $ad_name) { + $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = false;",$ad_name->getName()); + $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = true;",$ad_name->getName()); + $input_onclick .= "\n"; + } + + $input_onclick .= '} else {'; + + foreach ($request['template']->getForceDeleteAttrs() as $ad_name) { + $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = false;",$ad_name->getName()); + $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = true;",$ad_name->getName()); + $input_onclick .= "\n"; + } + + $input_onclick .= '};'; + } + + if ($input_onclick) + $input_onclick .= 'if (this.checked) {'; + else + $input_onclick = 'onclick="if (this.checked) {'; + + foreach ($request['template']->getLDAPmodify(true) as $skipattr) { + if (! $skipattr->getOldValues()) { + if (! in_array($skipattr->getName(),$mustattrs)) + $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = true;",$skipattr->getName()); + + $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = true;",$skipattr->getName()); + $input_onclick .= "\n"; + } } $input_onclick .= '} else {'; - foreach ($request['template']->getForceDeleteAttrs() as $ad_name) { - $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = false;",$ad_name->getName()); - $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = true;",$ad_name->getName()); + + foreach ($request['template']->getLDAPmodify(true) as $skipattr) { + if (! $skipattr->getOldValues()) { + if (! in_array($skipattr->getName(),$mustattrs)) + $input_onclick .= sprintf("document.getElementById('skip_array_%s').disabled = false;",$skipattr->getName()); + + $input_onclick .= sprintf("document.getElementById('skip_array_%s').checked = false;",$skipattr->getName()); + $input_onclick .= "\n"; + } } - $input_onclick .= '}"'; + + $input_onclick .= '};"'; } printf('', diff --git a/lib/Attribute.php b/lib/Attribute.php index 0ac9998..03e28dc 100644 --- a/lib/Attribute.php +++ b/lib/Attribute.php @@ -146,6 +146,10 @@ class Attribute { return count($this->values); } + public function getSource() { + return $this->source; + } + /** * Autovalue is called after the attribute is initialised, and thus the values from the ldap server will be set. */ @@ -169,9 +173,16 @@ class Attribute { $this->values = array(); } + public function setOldValue($val) { + $this->oldvalues = $val; + } + public function setValue($new_val) { if ($this->values) { - if ($this->oldvalues && ($new_val != $this->values)) { + if ($this->values == $new_val) + return; + + if ($this->oldvalues) { debug_dump($this); debug_dump_backtrace('old values are set',1); } else @@ -595,6 +606,7 @@ class Attribute { case 'readonly': case 'rows': case 'size': + case 'values': case 'verify': $this->$index = $value; break; @@ -607,7 +619,6 @@ class Attribute { elseif (is_string($values) && (strlen($values) > 0)) $this->values = array($values); - } /** diff --git a/lib/Template.php b/lib/Template.php index 70b9f3d..d232d76 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -175,9 +175,10 @@ class Template extends xmlTemplate { return; } else { - $attribute = $this->addAttribute('objectClass',array('values'=>$objectclasses)); + $attribute = $this->addAttribute('objectClass',array('values'=>$objectclasses),'XML'); $attribute->justModified(); $attribute->setRequired(); + $attribute->hide(); } $this->rebuildTemplateAttrs(); @@ -266,9 +267,14 @@ class Template extends xmlTemplate { if (is_null($attribute)) $attribute = $this->addAttribute($attr,array('values'=>$values)); else - if ($attribute->getValues()) - $attribute->setValue(array_values($values)); - else + if ($attribute->getValues()) { + # Override values to those that are defined in the XML file. + if ($attribute->getSource() != 'XML') + $attribute->setValue(array_values($values)); + else + $attribute->setOldValue(array_values($values)); + + } else $attribute->initValue(array_values($values)); # Work out the RDN attributes