| | |
| | | { |
| | | $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); |
| | | if ($id && !$sql_arr) { |
| | | $sql_result = $this->db->query( |
| | | "SELECT * FROM ".get_table_name('users')." WHERE user_id = ?", $id); |
| | | $sql_arr = $this->db->fetch_assoc($sql_result); |
| | | } |
| | | |
| | | if (!empty($sql_arr)) |
| | | { |
| | | if (!empty($sql_arr)) { |
| | | $this->ID = $sql_arr['user_id']; |
| | | $this->data = $sql_arr; |
| | | $this->language = $sql_arr['language']; |
| | |
| | | */ |
| | | function get_username() |
| | | { |
| | | return $this->data['username'] ? $this->data['username'] . (!strpos($this->data['username'], '@') ? '@'.$this->data['mail_host'] : '') : false; |
| | | if ($this->data['username']) { |
| | | if (!strpos($this->data['username'], '@')) |
| | | return $this->data['username'] . '@' . $this->data['mail_host']; |
| | | else |
| | | return $this->data['username']; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | |
| | | $save_prefs = serialize($save_prefs); |
| | | |
| | | $this->db->query( |
| | | "UPDATE ".get_table_name('users')." |
| | | SET preferences=?, |
| | | language=? |
| | | WHERE user_id=?", |
| | | "UPDATE ".get_table_name('users'). |
| | | " SET preferences = ?". |
| | | ", language = ?". |
| | | " WHERE user_id = ?", |
| | | $save_prefs, |
| | | $_SESSION['language'], |
| | | $this->ID); |
| | | |
| | | $this->language = $_SESSION['language']; |
| | | |
| | | if ($this->db->affected_rows()) { |
| | | $config->set_user_prefs($a_user_prefs); |
| | | $this->data['preferences'] = $save_prefs; |
| | |
| | | */ |
| | | function list_identities($sql_add = '') |
| | | { |
| | | // get contacts from DB |
| | | $result = array(); |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT * FROM ".get_table_name('identities')." |
| | | WHERE del<>1 AND user_id=? |
| | | $sql_add |
| | | ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC, identity_id ASC", |
| | | "SELECT * FROM ".get_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", |
| | | $this->ID); |
| | | |
| | | $result = array(); |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) { |
| | | $result[] = $sql_arr; |
| | | } |
| | |
| | | |
| | | $query_cols = $query_params = array(); |
| | | |
| | | foreach ((array)$data as $col => $value) |
| | | { |
| | | foreach ((array)$data as $col => $value) { |
| | | $query_cols[] = $this->db->quoteIdentifier($col) . '=?'; |
| | | $query_params[] = $value; |
| | | } |
| | | $query_params[] = $iid; |
| | | $query_params[] = $this->ID; |
| | | |
| | | $sql = "UPDATE ".get_table_name('identities')." |
| | | SET changed=".$this->db->now().", ".join(', ', $query_cols)." |
| | | WHERE identity_id=? |
| | | AND user_id=? |
| | | AND del<>1"; |
| | | $sql = "UPDATE ".get_table_name('identities'). |
| | | " SET changed = ".$this->db->now().", ".join(', ', $query_cols). |
| | | " WHERE identity_id = ?". |
| | | " AND user_id = ?". |
| | | " AND del <> 1"; |
| | | |
| | | call_user_func_array(array($this->db, 'query'), |
| | | array_merge(array($sql), $query_params)); |
| | |
| | | unset($data['user_id']); |
| | | |
| | | $insert_cols = $insert_values = array(); |
| | | foreach ((array)$data as $col => $value) |
| | | { |
| | | foreach ((array)$data as $col => $value) { |
| | | $insert_cols[] = $this->db->quoteIdentifier($col); |
| | | $insert_values[] = $value; |
| | | } |
| | | $insert_cols[] = 'user_id'; |
| | | $insert_values[] = $this->ID; |
| | | |
| | | $sql = "INSERT INTO ".get_table_name('identities')." |
| | | (changed, ".join(', ', $insert_cols).") |
| | | VALUES (".$this->db->now().", ".join(', ', array_pad(array(), sizeof($insert_values), '?')).")"; |
| | | $sql = "INSERT INTO ".get_table_name('identities'). |
| | | " (changed, ".join(', ', $insert_cols).")". |
| | | " VALUES (".$this->db->now().", ".join(', ', array_pad(array(), sizeof($insert_values), '?')).")"; |
| | | |
| | | call_user_func_array(array($this->db, 'query'), |
| | | array_merge(array($sql), $insert_values)); |
| | |
| | | return false; |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT count(*) AS ident_count FROM ".get_table_name('identities')." |
| | | WHERE user_id = ? AND del <> 1", |
| | | "SELECT count(*) AS ident_count FROM ".get_table_name('identities'). |
| | | " WHERE user_id = ? AND del <> 1", |
| | | $this->ID); |
| | | |
| | | $sql_arr = $this->db->fetch_assoc($sql_result); |
| | | |
| | | // 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()." |
| | | WHERE user_id=? |
| | | AND identity_id=?", |
| | | "UPDATE ".get_table_name('identities'). |
| | | " SET del = 1, changed = ".$this->db->now(). |
| | | " WHERE user_id = ?". |
| | | " AND identity_id = ?", |
| | | $this->ID, |
| | | $iid); |
| | | |
| | |
| | | */ |
| | | function set_default($iid) |
| | | { |
| | | if ($this->ID && $iid) |
| | | { |
| | | if ($this->ID && $iid) { |
| | | $this->db->query( |
| | | "UPDATE ".get_table_name('identities')." |
| | | SET ".$this->db->quoteIdentifier('standard')."='0' |
| | | WHERE user_id=? |
| | | AND identity_id<>? |
| | | AND del<>1", |
| | | "UPDATE ".get_table_name('identities'). |
| | | " SET ".$this->db->quoteIdentifier('standard')." = '0'". |
| | | " WHERE user_id = ?". |
| | | " AND identity_id <> ?". |
| | | " AND del <> 1", |
| | | $this->ID, |
| | | $iid); |
| | | } |
| | |
| | | */ |
| | | function touch() |
| | | { |
| | | if ($this->ID) |
| | | { |
| | | if ($this->ID) { |
| | | $this->db->query( |
| | | "UPDATE ".get_table_name('users')." |
| | | SET last_login=".$this->db->now()." |
| | | WHERE user_id=?", |
| | | "UPDATE ".get_table_name('users'). |
| | | " SET last_login = ".$this->db->now(). |
| | | " WHERE user_id = ?", |
| | | $this->ID); |
| | | } |
| | | } |
| | |
| | | $dbh = $rcmail->get_dbh(); |
| | | |
| | | $dbh->query( |
| | | "INSERT INTO ".get_table_name('users')." |
| | | (created, last_login, username, mail_host, alias, language) |
| | | VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?, ?)", |
| | | "INSERT INTO ".get_table_name('users'). |
| | | " (created, last_login, username, mail_host, alias, language)". |
| | | " VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?, ?)", |
| | | strip_newlines($user), |
| | | strip_newlines($host), |
| | | strip_newlines($data['alias'] ? $data['alias'] : $user_email), |
| | | $_SESSION['language']); |
| | | |
| | | if ($user_id = $dbh->insert_id('users')) |
| | | { |
| | | if ($user_id = $dbh->insert_id('users')) { |
| | | // create rcube_user instance to make plugin hooks work |
| | | $user_instance = new rcube_user($user_id); |
| | | $rcmail->user = $user_instance; |
| | | |
| | | $mail_domain = $rcmail->config->mail_domain($host); |
| | | |
| | | if ($user_email=='') |
| | | if ($user_email == '') { |
| | | $user_email = strpos($user, '@') ? $user : sprintf('%s@%s', $user, $mail_domain); |
| | | |
| | | } |
| | | if ($user_name == '') { |
| | | $user_name = $user != $user_email ? $user : ''; |
| | | } |
| | |
| | | $standard = 0; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | else { |
| | | raise_error(array( |
| | | 'code' => 500, |
| | | 'type' => 'php', |