/** * Write the given user prefs to the user's record * * @param array $a_user_prefs User prefs to save * @return boolean True on success, False on failure */ function save_prefs($a_user_prefs) { if (!$this->ID) { return false; } $config = $this->rc->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)) { unset($save_prefs[$key]); } } $save_prefs = serialize($save_prefs); $this->db->query("UPDATE " . $this->db->table_name('users') . " SET preferences = ?" . ", language = ?" . " WHERE user_id = ?", $save_prefs, $_SESSION['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'); } return true; } else { if ($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); $this->data['preferences'] = $save_prefs; } } return false; }