/**
* A method to perform redirects. Only suitable for use once OpenX is installed,
* as it requires the OpenX configuration file to be correctly set up.
*
* @param string $adminPage The administration interface page to redirect to
* (excluding a leading slash ("/")). Default is the
* index (i.e. login) page.
* @param boolean $manualAccountSwitch Flag to know if the user has switched account.
* @param boolean $redirectTopLevel Flag to know if the redirection should be to the top
* level, even it not a manual account switch.
*/
function redirect($adminPage = 'index.php', $manualAccountSwitch = false, $redirectTopLevel = false)
{
if ($manualAccountSwitch || $redirectTopLevel) {
// Get the page where the user was in when switched account
if (!empty($_SERVER['HTTP_REFERER'])) {
$aUrlComponents = parse_url($_SERVER['HTTP_REFERER']);
} elseif (!empty($_SERVER['REQUEST_URI'])) {
$aUrlComponents = parse_url($_SERVER['REQUEST_URI']);
}
$aPathInformation = pathinfo($aUrlComponents['path']);
$sectionID = $aPathInformation['filename'];
// Get the top level page
$adminPage = OA_Admin_UI::getTopLevelPage($sectionID);
if (!empty($adminPage)) {
header('Location: ' . MAX::constructURL(MAX_URL_ADMIN, $adminPage));
exit;
}
}
if (!$manualAccountSwitch || empty($return_url) && empty($GLOBALS['installing'])) {
if (!preg_match('/[\\r\\n]/', $adminPage)) {
header('Location: ' . MAX::constructURL(MAX_URL_ADMIN, $adminPage));
exit;
}
}
exit;
}
/**
* Process input from user and creates/upgrades DB etc....
*
* @param OA_Admin_UI_Component_Form $oForm
* @param OX_Admin_UI_Install_Wizard $oWizard
*/
protected function processDatabaseAction($oForm, $oWizard)
{
$oUpgrader = $this->getUpgrader();
$upgraderSuccess = false;
$aDbConfig = $oForm->populateDbConfig();
if ($oUpgrader->canUpgradeOrInstall()) {
$installStatus = $oUpgrader->existing_installation_status;
define('DISABLE_ALL_EMAILS', 1);
OA_Permission::switchToSystemProcessUser('Installer');
if ($installStatus == OA_STATUS_NOT_INSTALLED) {
if ($oUpgrader->install($aDbConfig)) {
$message = $GLOBALS['strDBInstallSuccess'];
$upgraderSuccess = true;
}
} else {
if ($oUpgrader->upgrade($oUpgrader->package_file)) {
// Timezone support - hack
if ($oUpgrader->versionInitialSchema['tables_core'] < 538 && empty($aDbConfig['noTzAlert'])) {
OA_Dal_ApplicationVariables::set('utc_update', OA::getNowUTC());
}
// Clear the menu cache to built a new one with the new settings
OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADMIN);
OA_Admin_Menu::_clearCache(OA_ACCOUNT_MANAGER);
OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADVERTISER);
OA_Admin_Menu::_clearCache(OA_ACCOUNT_TRAFFICKER);
OA_Admin_Menu::singleton();
$message = $GLOBALS['strDBUpgradeSuccess'];
$upgraderSuccess = true;
}
}
OA_Permission::switchToSystemProcessUser();
//get back to normal user previously logged in
} else {
if ($oUpgrader->existing_installation_status == OA_STATUS_CURRENT_VERSION) {
$upgraderSuccess = true;
//rare but can occur if DB has been installed and user revisits the screen
}
}
$dbSuccess = $upgraderSuccess && !$oUpgrader->oLogger->errorExists;
if ($dbSuccess) {
//show success status
OA_Admin_UI::getInstance()->queueMessage($message, 'global', 'info');
} else {
//sth went wrong, display messages from upgrader
$aMessages = OX_Admin_UI_Install_InstallUtils::getMessagesWithType($oUpgrader->getMessages());
$this->setModelProperty('aMessages', $aMessages);
}
return $dbSuccess;
}
/**
* A method to switch the active account to a different one
*
* @static
* @param int $accountId
* @param boolean $hasAccess Can be used for optimization - if we know that user
* has access to the account he is switching to there is
* no need to check it again
*/
public static function switchAccount($accountId, $hasAccess = false)
{
if ($hasAccess || self::hasAccess($accountId)) {
$oUser =& self::getCurrentUser();
$oUser->loadAccountData($accountId);
}
// Force session save
phpAds_SessionDataRegister('user', $oUser);
// If exists previous message related to switchAccount remove it
OA_Admin_UI::removeOneMessage('switchAccount');
// Queue confirmation message
$translation = new OX_Translation();
$translated_message = $translation->translate($GLOBALS['strYouAreNowWorkingAsX'], array(htmlspecialchars($oUser->aAccount['account_name'])));
OA_Admin_UI::queueMessage($translated_message, 'global', 'info', null, 'switchAccount');
}
/**
* A static method to display a login screen
*
* @static
*
* @param string $sMessage
* @param string $sessionID
* @param bool $inlineLogin
*/
function displayLogin($sMessage = '', $sessionID = 0, $inLineLogin = false)
{
global $strUsername, $strPassword, $strLogin, $strWelcomeTo, $strEnterUsername, $strNoAdminInteface, $strForgotPassword;
$aConf = $GLOBALS['_MAX']['CONF'];
$aPref = $GLOBALS['_MAX']['PREF'];
@header('Cache-Control: max-age=0, no-cache, proxy-revalidate, must-revalidate');
if (!$inLineLogin) {
phpAds_PageHeader(phpAds_Login);
}
// Check environment settings
$oSystemMgr = new OA_Environment_Manager();
$aSysInfo = $oSystemMgr->checkSystem();
foreach ($aSysInfo as $env => $vals) {
$errDetails = '';
if (is_array($vals['error']) && !empty($vals['error'])) {
if ($env == 'PERMS') {
// Just note that some file/folders are unwritable and that more information can be found in the debug.log
OA_Admin_UI::queueMessage('Error: File permission errors detected.<br />These <em>may</em> impact the accurate delivery of your ads,<br />See the debug.log file for the list of unwritable files', 'global', 'error', 0);
} else {
foreach ($vals['error'] as $key => $val) {
$errDetails .= '<li>' . htmlspecialchars($key) . ' => ' . htmlspecialchars($val) . '</li>';
}
phpAds_Die(' Error: ' . $err, $errDetails);
}
}
}
$oTpl = new OA_Admin_Template('login.html');
// we build the URL of the current page to use a redirect URL after login
// this code should work on all server configurations hence why it is a bit complicated
// inspired by http://dev.piwik.org/svn/trunk/core/Url.php getCurrentUrl()
$url = '';
if (!empty($_SERVER['PATH_INFO'])) {
$url = $_SERVER['PATH_INFO'];
} else {
if (!empty($_SERVER['REQUEST_URI'])) {
if (($pos = strpos($_SERVER['REQUEST_URI'], "?")) !== false) {
$url = substr($_SERVER['REQUEST_URI'], 0, $pos);
} else {
$url = $_SERVER['REQUEST_URI'];
}
}
}
if (empty($url)) {
$url = $_SERVER['SCRIPT_NAME'];
}
if (!empty($_SERVER['QUERY_STRING'])) {
$url .= '?' . $_SERVER['QUERY_STRING'];
}
if (!empty($url)) {
// remove any extra slashes that would confuse the browser (see OX-5234)
$url = '/' . ltrim($url, '/');
}
$appName = !empty($aConf['ui']['applicationName']) ? $aConf['ui']['applicationName'] : MAX_PRODUCT_NAME;
$oTpl->assign('uiEnabled', $aConf['ui']['enabled']);
$oTpl->assign('formAction', $url);
$oTpl->assign('sessionID', $sessionID);
$oTpl->assign('appName', $appName);
$oTpl->assign('message', $sMessage);
$oTpl->display();
phpAds_PageFooter();
exit;
}
}
}
if (!count($aErrormessage) && $changePassword) {
$result = $oPlugin->changePassword($doUsers, $pw, $pwold);
if (PEAR::isError($result)) {
$aErrormessage[0][] = $result->getMessage();
}
}
if (!count($aErrormessage)) {
if ($doUsers->update() === false) {
// Unable to update the preferences
$aErrormessage[0][] = $strUnableToWritePrefs;
} else {
$translation = new OX_Translation();
$translated_message = $translation->translate($GLOBALS['strPasswordChanged']);
OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
// The "preferences" were written correctly saved to the database,
// go to the "next" preferences page from here
OX_Admin_Redirect::redirect(basename($_SERVER['SCRIPT_NAME']));
}
}
}
// Set the correct section of the preference pages and display the drop-down menu
$prefSection = "password";
$setPref = $oOptions->getSettingsPreferences($prefSection);
$title = $setPref[$prefSection]['name'];
// Display the settings page's header and sections
$oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel($title);
phpAds_PageHeader('account-user-index', $oHeaderModel);
// Get the current logged in user details
$oUser = OA_Permission::getCurrentUser();
/**
* Method that returns the top level page of the page passed as parameter.
*
* @param string $sectionId The page that we want to know its parent page.
* @return string A string with the parent page, it will be null if the page
* doesn't have a parent page.
*/
function getTopLevelPage($sectionId = null)
{
$sectionId = OA_Admin_UI::getID($sectionId);
$oMenu = OA_Admin_Menu::singleton();
$parentSections = $oMenu->getParentSections($sectionId);
return count($parentSections) ? $parentSections[0]->link : '';
}
/**
* Show page header
*
* @todo Remove the "if stats, use numeric system" mechanism, should happen with the stats rewrite
* Also, this function seems to just be a wrapper to OA_Admin_UI::showHeader()... removing it would seem to make sense
*
* @param string ID If not passed in (or null) the page filename is used as the ID
* @param string Extra
* @param string imgPath: a relative path to Images, CSS files. Used if calling function from anything other than admin folder
* @param bool $showSidebar Set to false if you do not wish to show the sidebar navigation
* @param bool $showContentFrame Set to false if you do not wish to show the content frame
* @param bool $showMainNavigation Set to false if you do not wish to show the main navigation
*/
function phpAds_PageHeader($ID = null, $headerModel = null, $imgPath = "", $showSidebar = true, $showContentFrame = true, $showMainNavigation = true)
{
$GLOBALS['_MAX']['ADMIN_UI'] = OA_Admin_UI::getInstance();
$GLOBALS['_MAX']['ADMIN_UI']->showHeader($ID, $headerModel, $imgPath, $showSidebar, $showContentFrame, $showMainNavigation);
$GLOBALS['phpAds_GUIDone'] = true;
}
请发表评论