[horde] update preferences cache

Aleksey Chudov aleksey at bb.lv
Sat Nov 29 21:05:37 UTC 2008


Jan Schneider wrote:

> You want to use a preference hook for the from_addr preference instead.
>
> Jan.

Thanks!
The problem has solved with preference hook _prefs_hook_from_addr.
Is it possible to use existing database connection, without creating new 
connection at each users login?

Now my code looks as follows:

------------------------------------------------------------------------------------ 

<?php
require_once 'MDB2.php';
if (!function_exists('_prefs_hook_from_addr')) {
   function _prefs_hook_from_addr($name = null)
   {
       if (is_null($name)) {
           $name = Auth::getAuth();
       }
       if (!empty($name)) {
           $dsn = array(
               'phptype'  => $GLOBALS['conf']['auth']['params']['phptype'],
               'username' => 
$GLOBALS['conf']['auth']['params']['username'],
               'password' => 
$GLOBALS['conf']['auth']['params']['password'],
               'hostspec' => 
$GLOBALS['conf']['auth']['params']['hostspec'],
               'database' => 
$GLOBALS['conf']['auth']['params']['database'],
           );
           $_db = &MDB2::singleton($dsn);
           if(PEAR::isError($_db)) {
               die($_db->getMessage());
           }
           $query = "SELECT alias FROM virtual WHERE username = " . 
$_db->quote($name);
           $res = $_db->query($query);
           if(PEAR::isError($res)) {
               die($res->getMessage());
           }
           while($row = $res->fetchRow()) {
               $mail = $row[0];
           }
           return (empty($mail) ? '' : $mail);
       }
       return '';
   }
}


More information about the horde mailing list