| | |
| | | public $ID; |
| | | public $data; |
| | | public $language; |
| | | public $prefs; |
| | | |
| | | /** |
| | | * Holds database connection. |
| | |
| | | * @var array |
| | | */ |
| | | private $identities = array(); |
| | | |
| | | /** |
| | | * Internal emails cache |
| | | * |
| | | * @var array |
| | | */ |
| | | private $emails; |
| | | |
| | | |
| | | const SEARCH_ADDRESSBOOK = 1; |
| | | const SEARCH_MAIL = 2; |
| | |
| | | $this->language = $sql_arr['language']; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Build a user name string (as e-mail address) |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get the preferences saved for this user |
| | | * |
| | |
| | | */ |
| | | function get_prefs() |
| | | { |
| | | $prefs = array(); |
| | | if (isset($this->prefs)) { |
| | | return $this->prefs; |
| | | } |
| | | |
| | | $this->prefs = array(); |
| | | |
| | | if (!empty($this->language)) |
| | | $prefs['language'] = $this->language; |
| | | $this->prefs['language'] = $this->language; |
| | | |
| | | if ($this->ID) { |
| | | // Preferences from session (write-master is unavailable) |
| | |
| | | } |
| | | |
| | | if ($this->data['preferences']) { |
| | | $prefs += (array)unserialize($this->data['preferences']); |
| | | $this->prefs += (array)unserialize($this->data['preferences']); |
| | | } |
| | | } |
| | | |
| | | return $prefs; |
| | | return $this->prefs; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Write the given user prefs to the user's record |
| | |
| | | $config = $this->rc->config; |
| | | |
| | | // merge (partial) prefs array with existing settings |
| | | $save_prefs = $a_user_prefs + $old_prefs; |
| | | $this->prefs = $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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Generate a unique hash to identify this user which |
| | | * Generate a unique hash to identify this user whith |
| | | */ |
| | | function get_hash() |
| | | { |
| | | $key = substr($this->rc->config->get('des_key'), 1, 4); |
| | | return md5($this->data['user_id'] . $key . $this->data['username'] . '@' . $this->data['mail_host']); |
| | | $prefs = $this->get_prefs(); |
| | | |
| | | // generate a random hash and store it in user prefs |
| | | if (empty($prefs['client_hash'])) { |
| | | $prefs['client_hash'] = md5($this->data['username'] . mt_rand() . $this->data['mail_host']); |
| | | $this->save_prefs(array('client_hash' => $prefs['client_hash'])); |
| | | } |
| | | |
| | | return $prefs['client_hash']; |
| | | } |
| | | |
| | | /** |
| | | * Return a list of all user emails (from identities) |
| | | * |
| | | * @param bool Return only default identity |
| | | * |
| | | * @return array List of emails (identity_id, name, email) |
| | | */ |
| | | function list_emails($default = false) |
| | | { |
| | | if ($this->emails === null) { |
| | | $this->emails = array(); |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT `identity_id`, `name`, `email`" |
| | | ." FROM " . $this->db->table_name('identities', true) |
| | | ." WHERE `user_id` = ? AND `del` <> 1" |
| | | ." ORDER BY `standard` DESC, `name` ASC, `email` ASC, `identity_id` ASC", |
| | | $this->ID); |
| | | |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) { |
| | | $this->emails[] = $sql_arr; |
| | | } |
| | | } |
| | | |
| | | return $default ? $this->emails[0] : $this->emails; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | return $this->identities[$id]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return a list of all identities linked with this user |
| | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Update a specific identity record |
| | | * |
| | |
| | | call_user_func_array(array($this->db, 'query'), |
| | | array_merge(array($sql), $query_params)); |
| | | |
| | | // clear the cache |
| | | $this->identities = array(); |
| | | $this->emails = null; |
| | | |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create a new identity record linked with this user |
| | |
| | | $insert_cols[] = $this->db->quote_identifier($col); |
| | | $insert_values[] = $value; |
| | | } |
| | | $insert_cols[] = 'user_id'; |
| | | $insert_cols[] = $this->db->quote_identifier('user_id'); |
| | | $insert_values[] = $this->ID; |
| | | |
| | | $sql = "INSERT INTO ".$this->db->table_name('identities', true). |
| | |
| | | call_user_func_array(array($this->db, 'query'), |
| | | array_merge(array($sql), $insert_values)); |
| | | |
| | | // clear the cache |
| | | $this->identities = array(); |
| | | $this->emails = null; |
| | | |
| | | return $this->db->insert_id('identities'); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Mark the given identity as deleted |
| | |
| | | $this->ID, |
| | | $iid); |
| | | |
| | | // clear the cache |
| | | $this->identities = array(); |
| | | $this->emails = null; |
| | | |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Make this identity the default one for this user |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Update user's last_login timestamp |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clear the saved object state |
| | | */ |
| | |
| | | $this->ID = null; |
| | | $this->data = null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Find a user record matching the given name and host |
| | |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create a new user record and return a rcube_user instance |
| | |
| | | return $user_id ? $user_instance : false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Resolve username using a virtuser plugins |
| | | * |
| | |
| | | |
| | | return $plugin['user']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Resolve e-mail address from virtuser plugins |
| | |
| | | |
| | | return empty($plugin['email']) ? NULL : $plugin['email']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return a list of saved searches linked with this user |
| | |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return saved search data. |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Deletes given saved search record |
| | | * |
| | |
| | | |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create a new saved search record linked with this user |