From: cajus Date: Thu, 17 Sep 2009 08:03:32 +0000 (+0000) Subject: Updated index generation to have an optional parameter X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=600037a20063174cbb630726968fc3b68b1ddef7;p=gosa.git Updated index generation to have an optional parameter git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14260 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/contrib/gosa.conf.5 b/gosa-core/contrib/gosa.conf.5 index d1718e209..75ccf4858 100644 --- a/gosa-core/contrib/gosa.conf.5 +++ b/gosa-core/contrib/gosa.conf.5 @@ -988,6 +988,13 @@ functions supported - which can be combined: will generate a three digits id with the next free entry appended to "acct". +.nf + idGenerator="acct{id!1}" +.fi + + will generate a one digit id with the next free entry appended to + "acct" - if needed. + .nf idGenerator="ext{id#3}" .fi diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index 1e6cba28f..d9d12986f 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -1662,8 +1662,8 @@ function recurse($rule, $variables) function expand_id($rule, $attributes) { /* Check for id rule */ - if(preg_match('/^id(:|#)\d+$/',$rule)){ - return (array("\{$rule}")); + if(preg_match('/^id(:|#|!)\d+$/',$rule)){ + return (array("{$rule}")); } /* Check for clean attribute */ @@ -1739,12 +1739,17 @@ function gen_uids($rule, $attributes) foreach($proposed as $uid){ /* Check for id tag and modify uid if needed */ - if(preg_match('/\{id:\d+}/',$uid)){ - $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid); + if(preg_match('/\{id(:|!)\d+}/',$uid, $m)){ + $size= preg_replace('/^.*{id(:|!)(\d+)}.*$/', '\\2', $uid); - for ($i= 0, $p= pow(10,$size); $i < $p; $i++){ - $number= sprintf("%0".$size."d", $i); - $res= preg_replace('/{id:(\d+)}/', $number, $uid); + $start= $m[1]==":"?0:-1; + for ($i= $start, $p= pow(10,$size); $i < $p; $i++){ + if ($i == -1) { + $number= ""; + } else { + $number= sprintf("%0".$size."d", $i+1); + } + $res= preg_replace('/{id(:|!)\d+}/', $number, $uid); $ldap->search("(uid=".preg_replace('/[{}]/', '', $res).")",array('dn')); if($ldap->count() == 0){