/** * @param int $id * @return bool */ function CheckAccountAccess($_id, $_xmlRes = null) { $_result = User::AccountAccess($_id); if (!$_result && $_xmlRes !== null) { CXmlProcessing::PrintErrorAndExit(PROC_WRONG_ACCT_ACCESS, $_xmlRes); } return $_result; }
/** * @param int $_deleteId * @param int $_edit_id * @param bool $_clearClassic = false * @return bool|7 (7 - logout) */ function ProcessDeleteAccount($_deleteId, &$_edit_id, $_clearClassic = false) { if (!isset($_SESSION[ACCOUNT_ID], $_SESSION[USER_ID]) || !User::AccountAccess($_deleteId)) { setGlobalError(PROC_WRONG_ACCT_ACCESS); return false; } $null = null; $_accounts = array(); $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($_dbStorage->Connect()) { $_accounts =& $_dbStorage->SelectAccounts($_SESSION[USER_ID]); if (!$_accounts) { setGlobalError(PROC_CANT_GET_ACCT_LIST); return false; } } else { return false; } $_is_def = false; $_is_lastdef = false; $_is_edit = false; $_c = count($_accounts); if ($_c > 1) { foreach ($_accounts as $_id => $_currAccount) { if ($_id == $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_def = true; } } if ($_is_def) { $_is_lastdef = true; foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_lastdef = false; } } } if ($_edit_id == $_deleteId) { $_is_edit = true; } } else { if ($_c == 1) { if (isset($_accounts[$_deleteId])) { $_is_edit = true; } } else { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } if ($_c > 1) { if ($_is_lastdef) { setGlobalError(ACCT_CANT_DEL_LAST_DEF_ACCT); return false; } } else { if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } return 7; } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } else { if ($_is_edit) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && $_currAccount[6]) { $_edit_id = $_id; break; } } if ($_SESSION[SARRAY][EDIT_ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_edit_id = $_id; break; } } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } return true; }