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

Michael M Slusarz slusarz at horde.org
Thu Apr 25 00:10:40 UTC 2013


Quoting Nicolás Valera <nvalera at gmail.com>:

> On 04/23/2013 01:31 PM, Michael M Slusarz wrote:
>> Quoting Nicolás Valera <nvalera at gmail.com>:
>>
>>> On 03/20/2013 05:48 AM, lst_hoe02 at kwsoft.de wrote:
>>>>
>>>> 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:")
>>>> );
>>
>> [snip]
>>
>>> 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
>>
>> Then you need to manually instantiate a Horde_Db object (e.g. new
>> Horde_Db_Adapter_Foo) instead of using the Horde_Db_Adapter instance.
>> You can use the code in the Horde_Db_Adapter factory
>> (Horde_Core_Factory_Db class) to aid you in doing this.
>>
>> michael
>>
>> ___________________________________
>> Michael Slusarz [slusarz at horde.org]
>>
> Michael, thanks for the answer!
>
> I wrote somthing like this:
>
> global $conf;
>        require dirname( __FILE__ ) . '/../config/conf.php';
>
> 	$dbhost   = $conf['auth']['params']['hostspec'];
> 	$dbuser   = $conf['auth']['params']['username'];
> 	$dbpasswd = $conf['auth']['params']['password'];
> 	$dbname   = $conf['auth']['params']['database'];
>
> $mysqli = new mysqli( $dbhost, $dbuser, $dbpasswd, $dbname );         
> if( $mysqli->connect_error ) { die( 'Cannot connect to database' ); }
>
> $query = $mysqli->query( " SELECT alias FROM virtual_aliases WHERE  
> virtual_user_email like'%$userId%' " );
>
> if( ! $query ) { Horde::logMessage( $mysqli->error, 'ERR' ); die(  
> 'Cannot query from_addr' ); }
>
> $result = $query->fetch_assoc( );
>
> $_prefs['from_addr']['hook'] = true;
> $_prefs['from_addr']['type'] = 'enum';
> $_prefs['from_addr']['enum'] = $result;
>
> But i got this error:
>
> [horde] PHP ERROR: Invalid argument supplied for foreach() [pid 584  
> on line 515 of "/usr/share/php/Horde/Core/Prefs/Ui.php"]

This indicates that the value of 'enum' is not an array (or other  
Iterable object).

michael

___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the horde mailing list