This (PHP) function cycles through the existing usernames and comes up with the next unique one, built from the customers first name and surname.
It returns the username once it's found one.
Code:
function workout_user($fname, $sname)
{
$fname = substr($fname, 0, 4);
$lim = 9 - strlen($fname);
for($i = 0; $i <= $lim; $i++ )
{
if (array_key_exists('user', $this->list_accounts('user', $fname . substr($sname, 0, $i))->acct))
{
continue;
}
else
{
return strtolower($fname . substr($sname, 0, $i));
break;
}
}
}
$this->list_accounts is the result of... '/xml-api/listaccts?searchtype=$arg1&search=$arg2' - $argx are from the function call above. (passed thru simplexml_load_string(); )