From 75debac551728ef0012be4a7049fc191868be948 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 5 Oct 2010 12:23:17 +0000 Subject: [PATCH] Updated adapt_from_template function -Allow to use placeholder in arrays -Allow to use slices of variables by adding [n-m] to the variable to replace git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19918 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_plugin.inc | 48 ++++++++++++++++-------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/gosa-core/include/class_plugin.inc b/gosa-core/include/class_plugin.inc index d7a97a60e..46d127d35 100644 --- a/gosa-core/include/class_plugin.inc +++ b/gosa-core/include/class_plugin.inc @@ -594,43 +594,47 @@ class plugin $ldap->cat ($dn); $this->attrs= $ldap->fetch(); - /* Walk through attributes */ - foreach ($this->attributes as $val){ + $values = array(); + foreach($this->attributes as $name){ + if(isset($this->parent->$name)){ + $value = $this->parent->$name; + if(is_numeric($name)) continue; + if(is_string($value)) $values[$name] = $value; + if(is_array($value) && isset($value[0])) $values[$name] = $value[0]; + } + } - /* Skip the ones in skip list */ - if (in_array($val, $skip)){ - continue; - } + foreach($this->attributes as $name){ - if (isset($this->attrs["$val"][0])){ + // Skip the ones in skip list + if (in_array($name, $skip)) continue; + if (!isset($this->attrs[$name]['count'])) continue; - /* If attribute is set, replace dynamic parts: - %sn, %givenName and %uid. Fill these in our local variables. */ - $value= $this->attrs["$val"][0]; + $value= $this->attrs[$name][0]; - foreach (array("sn", "givenName", "uid") as $repl){ - if (preg_match("/%$repl/i", $value)){ - $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value); - } + if($this->attrs[$name]['count'] == 1){ + $value = fillReplacements($this->attrs[$name][0], $values); + }else{ + $value = array(); + for($i=0;$i<$this->attrs[$name]['count'];$i++){ + $value[] = fillReplacements($this->attrs[$name][$i], $values); + } } - $this->$val= $value; - } + + $this->$name = $value; + print_a(array($name => $value)); } /* Is Account? */ $found= TRUE; foreach ($this->objectclasses as $obj){ - if (preg_match('/top/i', $obj)){ - continue; - } + if (preg_match('/top/i', $obj)) continue; if (!in_array_ics ($obj, $this->attrs['objectClass'])){ $found= FALSE; break; } } - if ($found){ - $this->is_account= TRUE; - } + $this->is_account = $found; } /* \brief Indicate whether a password change is needed or not */ -- 2.30.2