| | |
| | | |
| | | /* |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcube_user.inc | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2012, The Roundcube Dev Team | |
| | | | | |
| | |
| | | | PURPOSE: | |
| | | | This class represents a system user linked and provides access | |
| | | | to the related database records. | |
| | | | | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: Thomas Bruederli <roundcube@gmail.com> | |
| | | | Author: Aleksander Machniak <alec@alec.pl> | |
| | | +-----------------------------------------------------------------------+ |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * Class representing a system user |
| | |
| | | /** |
| | | * Build a user name string (as e-mail address) |
| | | * |
| | | * @param string $part Username part (empty or 'local' or 'domain') |
| | | * @param string $part Username part (empty or 'local' or 'domain', 'mail') |
| | | * @return string Full user name or its part |
| | | */ |
| | | function get_username($part = null) |
| | | { |
| | | if ($this->data['username']) { |
| | | // return real name |
| | | if (!$part) { |
| | | return $this->data['username']; |
| | | } |
| | | |
| | | list($local, $domain) = explode('@', $this->data['username']); |
| | | |
| | | // at least we should always have the local part |
| | |
| | | */ |
| | | function get_prefs() |
| | | { |
| | | $prefs = array(); |
| | | |
| | | if (!empty($this->language)) |
| | | $prefs = array('language' => $this->language); |
| | | $prefs['language'] = $this->language; |
| | | |
| | | if ($this->ID) { |
| | | // Preferences from session (write-master is unavailable) |
| | |
| | | if (!$this->ID) |
| | | return false; |
| | | |
| | | $config = $this->rc->config; |
| | | $old_prefs = (array)$this->get_prefs(); |
| | | $plugin = $this->rc->plugins->exec_hook('preferences_update', array( |
| | | 'userid' => $this->ID, 'prefs' => $a_user_prefs, 'old' => (array)$this->get_prefs())); |
| | | |
| | | if (!empty($plugin['abort'])) { |
| | | return; |
| | | } |
| | | |
| | | $a_user_prefs = $plugin['prefs']; |
| | | $old_prefs = $plugin['old']; |
| | | $config = $this->rc->config; |
| | | |
| | | // merge (partial) prefs array with existing settings |
| | | $save_prefs = $a_user_prefs + $old_prefs; |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Generate a unique hash to identify this user which |
| | | */ |
| | | 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']); |
| | | } |
| | | |
| | | /** |
| | | * Get default identity of this user |
| | |
| | | /** |
| | | * Return a list of all identities linked with this user |
| | | * |
| | | * @param string $sql_add Optional WHERE clauses |
| | | * @param string $sql_add Optional WHERE clauses |
| | | * @param bool $formatted Format identity email and name |
| | | * |
| | | * @return array List of identities |
| | | */ |
| | | function list_identities($sql_add = '') |
| | | function list_identities($sql_add = '', $formatted = false) |
| | | { |
| | | $result = array(); |
| | | |
| | |
| | | "SELECT * FROM ".$this->db->table_name('identities'). |
| | | " WHERE del <> 1 AND user_id = ?". |
| | | ($sql_add ? " ".$sql_add : ""). |
| | | " ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC, identity_id ASC", |
| | | " ORDER BY ". $this->db->quote_identifier('standard') . " DESC, " |
| | | . $this->db->quote_identifier('name') . " ASC, " |
| | | . $this->db->quote_identifier('email') . " ASC, " |
| | | . $this->db->quote_identifier('identity_id') . " ASC", |
| | | $this->ID); |
| | | |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) { |
| | | if ($formatted) { |
| | | $ascii_email = format_email($sql_arr['email']); |
| | | $utf8_email = format_email(rcube_utils::idn_to_utf8($ascii_email)); |
| | | |
| | | $sql_arr['email_ascii'] = $ascii_email; |
| | | $sql_arr['email'] = $utf8_email; |
| | | $sql_arr['ident'] = format_email_recipient($ascii_email, $sql_arr['name']); |
| | | } |
| | | |
| | | $result[] = $sql_arr; |
| | | } |
| | | |
| | |
| | | $query_cols = $query_params = array(); |
| | | |
| | | foreach ((array)$data as $col => $value) { |
| | | $query_cols[] = $this->db->quoteIdentifier($col) . ' = ?'; |
| | | $query_cols[] = $this->db->quote_identifier($col) . ' = ?'; |
| | | $query_params[] = $value; |
| | | } |
| | | $query_params[] = $iid; |
| | |
| | | |
| | | $insert_cols = $insert_values = array(); |
| | | foreach ((array)$data as $col => $value) { |
| | | $insert_cols[] = $this->db->quoteIdentifier($col); |
| | | $insert_cols[] = $this->db->quote_identifier($col); |
| | | $insert_values[] = $value; |
| | | } |
| | | $insert_cols[] = 'user_id'; |
| | |
| | | if ($this->ID && $iid) { |
| | | $this->db->query( |
| | | "UPDATE ".$this->db->table_name('identities'). |
| | | " SET ".$this->db->quoteIdentifier('standard')." = '0'". |
| | | " SET ".$this->db->quote_identifier('standard')." = '0'". |
| | | " WHERE user_id = ?". |
| | | " AND identity_id <> ?". |
| | | " AND del <> 1", |
| | |
| | | "INSERT INTO ".$dbh->table_name('users'). |
| | | " (created, last_login, username, mail_host, language)". |
| | | " VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?)", |
| | | strip_newlines($data['user']), |
| | | strip_newlines($data['host']), |
| | | strip_newlines($data['language'])); |
| | | $data['user'], |
| | | $data['host'], |
| | | $data['language']); |
| | | |
| | | if ($user_id = $dbh->insert_id('users')) { |
| | | // create rcube_user instance to make plugin hooks work |
| | |
| | | if (empty($user_email)) { |
| | | $user_email = strpos($data['user'], '@') ? $user : sprintf('%s@%s', $data['user'], $mail_domain); |
| | | } |
| | | $email_list[] = strip_newlines($user_email); |
| | | $email_list[] = $user_email; |
| | | } |
| | | // identities_level check |
| | | else if (count($email_list) > 1 && $rcube->config->get('identities_level', 0) > 1) { |
| | |
| | | $record['name'] = $user_name != $record['email'] ? $user_name : ''; |
| | | } |
| | | |
| | | $record['name'] = strip_newlines($record['name']); |
| | | $record['user_id'] = $user_id; |
| | | $record['standard'] = $standard; |
| | | |
| | |
| | | $result = array(); |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT search_id AS id, ".$this->db->quoteIdentifier('name') |
| | | "SELECT search_id AS id, ".$this->db->quote_identifier('name') |
| | | ." FROM ".$this->db->table_name('searches') |
| | | ." WHERE user_id = ?" |
| | | ." AND ".$this->db->quoteIdentifier('type')." = ?" |
| | | ." ORDER BY ".$this->db->quoteIdentifier('name'), |
| | | ." AND ".$this->db->quote_identifier('type')." = ?" |
| | | ." ORDER BY ".$this->db->quote_identifier('name'), |
| | | (int) $this->ID, (int) $type); |
| | | |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) { |
| | |
| | | } |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT ".$this->db->quoteIdentifier('name') |
| | | .", ".$this->db->quoteIdentifier('data') |
| | | .", ".$this->db->quoteIdentifier('type') |
| | | "SELECT ".$this->db->quote_identifier('name') |
| | | .", ".$this->db->quote_identifier('data') |
| | | .", ".$this->db->quote_identifier('type') |
| | | ." FROM ".$this->db->table_name('searches') |
| | | ." WHERE user_id = ?" |
| | | ." AND search_id = ?", |
| | |
| | | |
| | | $insert_cols[] = 'user_id'; |
| | | $insert_values[] = (int) $this->ID; |
| | | $insert_cols[] = $this->db->quoteIdentifier('type'); |
| | | $insert_cols[] = $this->db->quote_identifier('type'); |
| | | $insert_values[] = (int) $data['type']; |
| | | $insert_cols[] = $this->db->quoteIdentifier('name'); |
| | | $insert_cols[] = $this->db->quote_identifier('name'); |
| | | $insert_values[] = $data['name']; |
| | | $insert_cols[] = $this->db->quoteIdentifier('data'); |
| | | $insert_cols[] = $this->db->quote_identifier('data'); |
| | | $insert_values[] = serialize($data['data']); |
| | | |
| | | $sql = "INSERT INTO ".$this->db->table_name('searches') |