[horde] Hook question
Amith Varghese
amith at xalan.com
Tue Jul 20 06:55:48 PDT 2004
Here is what I have for my fullname hook... hope this helps...
if (!function_exists('_prefs_hook_fullname')) {
function _prefs_hook_fullname($user = null)
{
$ldapServer = 'localhost';
$ldapPort = '389';
$vdomain = $_SERVER['HTTP_HOST'];
$vdomain = preg_replace('|^mail\.|i', '', $vdomain);
$vdomain = String::lower($vdomain);
$domainparts = split("\.",$vdomain);
$searchBase = 'ou=People,o=' . $domainparts[0] . ',o=' . $domainparts
[1] . ',c=US';
$ldapcharset = 'utf-8';
$outputcharset = NLS::getCharset();
$ds = @ldap_connect($ldapServer, $ldapPort);
// Find the user
if (empty($user)) {
$user = Auth::getAuth();
if (empty($user)) {
$user = Util::getFormData('imapuser') . '@' . Util::getFormData
('maildomain');
}
}
// get the password
$password = Auth::getCredential('password');
if (empty($password)) {
$password = Util::getFormData('pass');
}
if ($ds) {
Horde::logMessage($user . ',' . $searchBase, __FILE__, __LINE__,
PEAR_LOG_DEBUG);
$ldapbind = ldap_bind($ds, 'uid=' . $user . ',' . $searchBase,
$password);
}
$searchResult = @ldap_search($ds, $searchBase, 'uid=' . $user);
$information = @ldap_get_entries($ds, $searchResult);
$name = $user;
if ($information['count'] != 0 && $information[0]['cn'][0] != '') {
$name = $information[0]['cn'][0];
}
ldap_close($ds);
$name = String::convertCharset($name, $ldapcharset, $outputcharset);
return $name;
}
}
Quoting AJ <aj at mindcrash.com>:
> Hi,
> I am trying to get the fullname hook working.
> I am trying to fetch the fullname from an ldap attribute called
> displayName. Here is what I have in hooks.php:
>
> if (!function_exists('_prefs_hook_fullname')) {
> function _prefs_hook_fullname($user = null)
> {
> $ldapServer = 'localhost';
> $ldapPort = '389';
> $searchBase = 'ou=Users,dc=mindcrash,dc=com';
> $ldapcharset = 'utf-8';
> $outputcharset = NLS::getCharset();
>
> $ds = @ldap_connect($ldapServer, $ldapPort);
>
> if (is_null($user)) {
> $user = Auth::getAuth();
> }
> $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $user);
> $information = @ldap_get_entries($ds, $searchResult);
> $name = $information[0]['displayName'][0];
>
> ldap_close($ds);
>
> $name = String::convertCharset($name, $ldapcharset,
> $outputcharset);
> return (empty($name) ? $user : $name);
> }
> }
>
> This does not work.. I added 'hook' => true to the fullname stanza in
> prefs.php, and also added $conf['hooks']['fullname'] = true; to
> conf.php, both with no results.. I have cleared out my horde_prefs
> before each trial. Can anyone help?
>
> Thanks.
> AJ
>
> --
> Horde mailing list - Join the hunt: http://horde.org/bounties/#horde
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: horde-unsubscribe at lists.horde.org
More information about the horde
mailing list