* @version 2.1 */ class Prefs { // Namespace of this instance of Prefs. var $_ns; /** * Prefs constructor. */ function Prefs($namespace='') { $this->_ns = '_prefs_' . $namespace; // Initialized the prefs array. if (!isset($_SESSION[$this->_ns])) { $_SESSION[$this->_ns] = array(); } } /** * Sets the default value of a preference. The pref will be set only if * is not set already. * * @param string $key The name of the preference to modify. * @param string $val The new value for this preference. */ function setDefault($key, $val) { // Set it only if not set already. if (!isset($_SESSION[$this->_ns][$key])) { $_SESSION[$this->_ns][$key] = $val; } } /** * Sets the given preferences to the specific value, * * @param string $key The name of the preference to modify. * @param string $val The new value for this preference. */ function set($key, $val) { $_SESSION[$this->_ns][$key] = $val; } /** * Returns the value of the requested preference. * * @param string $key The name of the preference to retrieve. * * @return string The value of the preference. */ function get($key) { return (isset($_SESSION[$this->_ns][$key])) ? $_SESSION[$this->_ns][$key] : null; } /** * To see if a preference has been set. * * @param string $key The name of the preference to check. * * @return boolean True if the preference isset and not empty * false otherwise. */ function exists($key) { return isset($_SESSION[$this->_ns][$key]); } /** * Clear a set preference value. * * @param string $key The name of the preference to check. */ function delete($key) { if (isset($_SESSION[$this->_ns][$key])) { unset($_SESSION[$this->_ns][$key]); } } /** * Perform cleanup operations. */ function clear() { $_SESSION[$this->_ns] = array(); } } ?>