| | |
| | | */ |
| | | 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) |
| | |
| | | * Write the given user prefs to the user's record |
| | | * |
| | | * @param array $a_user_prefs User prefs to save |
| | | * @param bool $no_session Simplified language/preferences handling |
| | | * |
| | | * @return boolean True on success, False on failure |
| | | */ |
| | | function save_prefs($a_user_prefs) |
| | | function save_prefs($a_user_prefs, $no_session = false) |
| | | { |
| | | if (!$this->ID) |
| | | return false; |
| | |
| | | } |
| | | |
| | | $save_prefs = serialize($save_prefs); |
| | | if (!$no_session) { |
| | | $this->language = $_SESSION['language']; |
| | | } |
| | | |
| | | $this->db->query( |
| | | "UPDATE ".$this->db->table_name('users'). |
| | |
| | | ", language = ?". |
| | | " WHERE user_id = ?", |
| | | $save_prefs, |
| | | $_SESSION['language'], |
| | | $this->language, |
| | | $this->ID); |
| | | |
| | | $this->language = $_SESSION['language']; |
| | | |
| | | // Update success |
| | | if ($this->db->affected_rows() !== false) { |
| | | $config->set_user_prefs($a_user_prefs); |
| | | $this->data['preferences'] = $save_prefs; |
| | | |
| | | if (isset($_SESSION['preferences'])) { |
| | | $this->rc->session->remove('preferences'); |
| | | $this->rc->session->remove('preferences_time'); |
| | | if (!$no_session) { |
| | | $config->set_user_prefs($a_user_prefs); |
| | | |
| | | if (isset($_SESSION['preferences'])) { |
| | | $this->rc->session->remove('preferences'); |
| | | $this->rc->session->remove('preferences_time'); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | // Update error, but we are using replication (we have read-only DB connection) |
| | | // and we are storing session not in the SQL database |
| | | // we can store preferences in session and try to write later (see get_prefs()) |
| | | else if ($this->db->is_replicated() && $config->get('session_storage', 'db') != 'db') { |
| | | else if (!$no_session && $this->db->is_replicated() |
| | | && $config->get('session_storage', 'db') != 'db' |
| | | ) { |
| | | $_SESSION['preferences'] = $save_prefs; |
| | | $_SESSION['preferences_time'] = time(); |
| | | $config->set_user_prefs($a_user_prefs); |
| | |
| | | "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, name ASC, identity_id ASC", |
| | | $this->ID); |
| | | |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) { |
| | |
| | | $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", |
| | |
| | | $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') |