diff --git a/admin/setup/config.inc.php b/admin/setup/config.inc.php
index a97ac45e20..5c49e96e11 100644
--- a/admin/setup/config.inc.php
+++ b/admin/setup/config.inc.php
@@ -33,6 +33,16 @@
+
+ Minimum account id (e.g. 500 or 100, etc.): |
+ "> |
+
+
+ Maximum account id (e.g. 65535 or 1000000): |
+ "> |
+
+
+
If using LDAP, do you want to store homedirectory and loginshell attributes for new accounts?: |
> |
diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php
index f9e9a46e62..d9f4c31383 100644
--- a/phpgwapi/inc/class.accounts_ldap.inc.php
+++ b/phpgwapi/inc/class.accounts_ldap.inc.php
@@ -301,25 +301,38 @@
{
global $phpgw_info, $phpgw;
- if (!$account_id) {
- mt_srand((double)microtime()*1000000);
- $account_id = mt_rand (100, 65535);
- }
- // auto_increment/serial in the db won't necessarily work for ldap, nor would
- // randomization. Need to check for lastid in ldap, then create newid for sql and ldap
+ $ds = $phpgw->common->ldapConnect();
+
+ if (!$account_id) {
+ if ($phpgw_info["server"]["account_min_id"]) { $min = $phpgw_info["server"]["account_min_id"]; }
+ if ($phpgw_info["server"]["account_max_id"]) { $max = $phpgw_info["server"]["account_max_id"]; }
+
+ $nextid = $phpgw->common->last_id("accounts_ldap",$min,$max);
+
+ // Loop until we find a free id
+ $free = 0;
+ while (!$free) {
+ $ldap_fields = "";
+ $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$nextid);
+ $ldap_test = ldap_get_entries($ds, $sri);
+ if ($ldap_test[0]['dn'][0]) {
+ $nextid = $phpgw->common->next_id("accounts_ldap",$min,$max);
+ } else {
+ $free = True;
+ }
+ }
+ if ($phpgw_info["server"]["account_max_id"] && ($nextid > $phpgw_info["server"]["account_max_id"])) {
+ return False;
+ }
+ $account_id = $nextid;
+ //echo $account_id;exit;
+ }
-/* if (!$account_id) {
- $this->db->query("insert into phpgw_accounts (account_lid, account_type, account_pwd, "
- . "account_firstname, account_lastname, account_status) values ('" . $account_lid
- . "','" . $account_type . "','" . md5($account_pwd) . "', '" . $account_firstname
- . "','" . $account_lastname . "','" . $account_status . "')",__LINE__,__FILE__);
- } else { */
$this->db->query("insert into phpgw_accounts (account_id, account_lid, account_type, account_pwd, "
. "account_firstname, account_lastname, account_status) values ('" . $account_id . "','" . $account_lid
. "','" . $account_type . "','" . md5($account_pwd) . "', '" . $account_firstname
. "','" . $account_lastname . "','" . $account_status . "')",__LINE__,__FILE__);
- $ds = $phpgw->common->ldapConnect();
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uid=".$account_lid);
$allValues = ldap_get_entries($ds, $sri);