[horde] Set "from_addr" as pre populated "enum" field

Nicolás Valera nvalera at gmail.com
Tue Apr 23 15:55:11 UTC 2013


On 03/20/2013 05:48 AM, lst_hoe02 at kwsoft.de wrote:
>
> Zitat von lst_hoe02 at kwsoft.de:
>
>> Zitat von Michael M Slusarz <slusarz at horde.org>:
>>
>>> Quoting lst_hoe02 at kwsoft.de:
>>>
>>>> Zitat von Michael M Slusarz <slusarz at horde.org>:
>>>>
>>>>> Quoting lst_hoe02 at kwsoft.de:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> we are on the way to Horde 5 and try to get the prefs.local.php
>>>>>> for Horde altered so a enum filed is used for the from_addr
>>>>>> preference, so the user is only able to choose the from_addr out
>>>>>> of a list of aliases obtained with a database query.
>>>>>>
>>>>>> What is the easiest way to use a Database query for standard SQL
>>>>>> source in prefs.local.php?
>>>>>
>>>>> Are you asking how to populate a preference field with dynamic
>>>>> results obtained from an SQL query?  Use the 'on_init' feature
>>>>> (see, e.g., the 'language' preference).
>>>>
>>>> No, the problem is how to get a Database Connection the "Horde" way.
>>>> The table to query is within the same scope as all the horde stuff,
>>>> but i'm not sure about the horde objects/functions to use. The hooks
>>>> examples are mostly LDAP and i have not yet found a SQL example.
>>>
>>> $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter');
>>>
>>> Returns the Horde_Db_Adapter object for the base Horde DB
>>> configuration.
>>> (http://dev.horde.org/api/master/lib/Db/classes/Horde_Db_Adapter.html)
>>>
>>>>>> Is it correct to use $userId as logged in user?
>>>>>
>>>>> Not sure where you are getting $userId from?  Authenticated is
>>>>> always $registry->getAuth().
>>>>
>>>> So a simply username = $registry->getAuth() should do the trick?
>>>> Sorry for asking the obvious but i'm not a PHP coder at all.
>>>
>>> Should be "$username = $registry->getAuth();"  But yes.
>>>
>>
>> Thanks, i will try and let you know how it works.
>>
>
> Hey, cool ;-)
>
> With this set in horde prefs.local.php it works as expected so the user
> can only choose aliases assigned to his/her account:
>
> $userId = $registry->getAuth();
> $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter');
> $db->connect();
> $result = $db->selectAssoc(" SELECT alias,alias FROM
> postfix_virtual_aliases WHERE user_uid='$userId' ");
> $db->disconnect();
>
> $_prefs['from_addr'] = array(
>      'value' => '',
> //    'type' => 'text',
>      'type' => 'enum',
>      'enum' => $result,
>      'desc' =>  _("The default e-mail address to use with this identity:")
> );
>
> Many Thanks
>
> Andreas
>
>
Hi there!

Im trying to do the same but my list of aliases is in another host.
The parameters to connect to the database are defined in the conf.php
because they are the same i use to authenticate the horde

Any ideas?
Thanks in advance!!!


More information about the horde mailing list