alecpl
2010-09-29 e99991996dbb9e7b0b0ff6cfa94dc0fb2522eb66
program/include/rcube_user.php
@@ -4,8 +4,8 @@
 +-----------------------------------------------------------------------+
 | program/include/rcube_user.inc                                        |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland                 |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
@@ -44,7 +44,7 @@
    function __construct($id = null, $sql_arr = null)
    {
        $this->db = rcmail::get_instance()->get_dbh();
        if ($id && !$sql_arr) {
            $sql_result = $this->db->query(
                "SELECT * FROM ".get_table_name('users')." WHERE user_id = ?", $id);
@@ -74,9 +74,11 @@
            if ($part == 'local') {
                return $local;
            }
            // if no domain was provided use the default if available
            if (empty($domain))
                $domain = $this->data['mail_host'];
            // if no domain was provided...
            if (empty($domain)) {
                $rcmail = rcmail::get_instance();
                $domain = $rcmail->config->mail_domain($this->data['mail_host']);
            }
            if ($part == 'domain') {
                return $domain;
@@ -119,14 +121,14 @@
    {
        if (!$this->ID)
            return false;
        $config = rcmail::get_instance()->config;
        $old_prefs = (array)$this->get_prefs();
        // merge (partial) prefs array with existing settings
        $save_prefs = $a_user_prefs + $old_prefs;
        unset($save_prefs['language']);
        // don't save prefs with default values if they haven't been changed yet
        foreach ($a_user_prefs as $key => $value) {
            if (!isset($old_prefs[$key]) && ($value == $config->get($key)))
@@ -184,11 +186,11 @@
            ($sql_add ? " ".$sql_add : "").
            " ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC, identity_id ASC",
            $this->ID);
        while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
            $result[] = $sql_arr;
        }
        return $result;
    }
@@ -206,7 +208,7 @@
            return false;
        $query_cols = $query_params = array();
        foreach ((array)$data as $col => $value) {
            $query_cols[]   = $this->db->quoteIdentifier($col) . ' = ?';
            $query_params[] = $value;
@@ -222,11 +224,11 @@
        call_user_func_array(array($this->db, 'query'),
            array_merge(array($sql), $query_params));
        return $this->db->affected_rows();
    }
    /**
     * Create a new identity record linked with this user
     *
@@ -257,8 +259,8 @@
        return $this->db->insert_id('identities');
    }
    /**
     * Mark the given identity as deleted
     *
@@ -280,7 +282,7 @@
        // we'll not delete last identity
        if ($sql_arr['ident_count'] <= 1)
            return false;
        $this->db->query(
            "UPDATE ".get_table_name('identities').
            " SET del = 1, changed = ".$this->db->now().
@@ -291,8 +293,8 @@
        return $this->db->affected_rows();
    }
    /**
     * Make this identity the default one for this user
     *
@@ -311,8 +313,8 @@
                $iid);
        }
    }
    /**
     * Update user's last_login timestamp
     */
@@ -326,8 +328,8 @@
                $this->ID);
        }
    }
    /**
     * Clear the saved object state
     */
@@ -336,8 +338,8 @@
        $this->ID = null;
        $this->data = null;
    }
    /**
     * Find a user record matching the given name and host
     *
@@ -348,25 +350,25 @@
    static function query($user, $host)
    {
        $dbh = rcmail::get_instance()->get_dbh();
        // query for matching user name
        $query = "SELECT * FROM ".get_table_name('users')." WHERE mail_host = ? AND %s = ?";
        $sql_result = $dbh->query(sprintf($query, 'username'), $host, $user);
        // query for matching alias
        if (!($sql_arr = $dbh->fetch_assoc($sql_result))) {
            $sql_result = $dbh->query(sprintf($query, 'alias'), $host, $user);
            $sql_arr = $dbh->fetch_assoc($sql_result);
        }
        // user already registered -> overwrite username
        if ($sql_arr)
            return new rcube_user($sql_arr['user_id'], $sql_arr);
        else
            return false;
    }
    /**
     * Create a new user record and return a rcube_user instance
     *
@@ -385,7 +387,7 @@
            $user_email = is_array($email_list[0]) ? $email_list[0]['email'] : $email_list[0];
        }
        $data = $rcmail->plugins->exec_hook('create_user',
        $data = $rcmail->plugins->exec_hook('user_create',
           array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email));
        // plugin aborted this operation
@@ -404,7 +406,7 @@
            strip_newlines($user),
            strip_newlines($host),
            strip_newlines($data['alias'] ? $data['alias'] : $user_email),
            $_SESSION['language']);
            strip_newlines($data['language'] ? $data['language'] : $_SESSION['language']));
        if ($user_id = $dbh->insert_id('users')) {
            // create rcube_user instance to make plugin hooks work
@@ -444,9 +446,9 @@
                $record['user_id'] = $user_id;
                $record['standard'] = $standard;
                $plugin = $rcmail->plugins->exec_hook('create_identity',
                $plugin = $rcmail->plugins->exec_hook('identity_create',
                   array('login' => true, 'record' => $record));
                if (!$plugin['abort'] && $plugin['record']['email']) {
                    $rcmail->user->insert_identity($plugin['record']);
                }
@@ -461,11 +463,11 @@
                'file' => __FILE__,
                'message' => "Failed to create new user"), true, false);
        }
        return $user_id ? $user_instance : false;
    }
    /**
     * Resolve username using a virtuser plugins
     *