// Copyright: Copyright (C) 2002-2007 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/addget.inc.php"; require_once "monica/addslash.inc.php"; require_once "monica/callform.inc.php"; require_once "monica/checker.inc.php"; require_once "monica/http.inc.php"; require_once "monica/process.inc.php"; require_once "monica/requri.inc.php"; require_once "monica/sql.inc.php"; require_once "monica/userpref.inc.php"; // ListPreference: The list preference handler class ListPreference { protected $_form = array(); protected $_referer = null; protected $_domain = null; protected $_listcols = null; // __construct: Initialize the handler function __construct(&$form) { $this->_form =& $form; // Set the referer, the domain and the list columns $this->_set_referer(); $this->_set_domain(); } // main: Change the list preference function main() { // Lock the necessary tables $locktable = array("userpref" => LOCK_EX); sql_lock($locktable); $error = $this->_check_post(); // If an error occurs if (!is_null($error)) { $error["isform"] = false; error_redirect($error); // Else, save the data } else { $processor = new ListPreferenceProcessor($_POST); $success = $processor->process(); http_303($this->_referer); } } // _check_post: Check the list preference form function _check_post() { // Run the checker $checker = new ListPreferenceChecker($this->_form); $error = $checker->check(array("domain", "listcols", "listsize")); if (!is_null($error)) { return $error; } // OK return null; } // _set_referer: Obtain the referer to return to function _set_referer() { // Obtained before if (!is_null($this->_referer)) { return $this->_referer; } // Obtain the source referer $this->_referer = $this->_source_referer(); // Remove the status from the referer $this->_referer = rem_get_arg($this->_referer, "statid"); return $this->_referer; } // _source_referer: Obtain the source referer function _source_referer() { // Use the POSTed referer if (array_key_exists("referer", $this->_form)) { return $this->_form["referer"]; // Use the referer from the request } elseif (array_key_exists("HTTP_REFERER", $_SERVER)) { return $_SERVER["HTTP_REFERER"]; // Fall back to the myself } else { return REQUEST_FULLURI; } } // _set_domain: Obtain the domain this preference belongs to function _set_domain() { // Obtained before if (!is_null($this->_domain)) { return $this->_domain; } // Return the supplied domain if (array_key_exists("domain", $this->_form)) { $this->_domain = $this->_form["domain"]; return $this->_domain; } // Obtain the referer first $this->_set_referer(); // Return the current script path for the most cases if ($this->_referer == REQUEST_FULLURI) { $this->_domain = REQUEST_PATH; $this->_form["domain"] = $this->_domain; return $this->_domain; } // Parse the referer to get the script path $url = parse_url($this->_referer); // Fall back to the root directory if there is no script part $this->_domain = array_key_exists("path", $url)? $url["path"]: "/"; // Strip the leading root difference $ROOTDIFF_RE = addslashes_re_php(ROOT_DIFF); $this->_domain = preg_replace("/^$ROOTDIFF_RE/", "", $this->_domain); $this->_form["domain"] = $this->_domain; return $this->_domain; } } ?>