/** * Parses a specified page ID and redirects to another ID if required. * * @param WebSoccer $websoccer Website context. * @param I18n $i18n messages provider. * @param string $requestedPageId unfiltered Page ID that has been requested. * @return string target page ID to display. */ public static function getTargetPageId(WebSoccer $websoccer, I18n $i18n, $requestedPageId) { $pageId = $requestedPageId; // set default page ID if ($pageId == NULL) { $pageId = DEFAULT_PAGE_ID; } // redirect to log-in form if website is generally protected $user = $websoccer->getUser(); if ($websoccer->getConfig('password_protected') && $user->getRole() == ROLE_GUEST) { // list of page IDs that needs to be excluded. $freePageIds = array(LOGIN_PAGE_ID, 'register', 'register-success', 'activate-user', 'forgot-password', 'imprint', 'logout', 'termsandconditions'); if (!$websoccer->getConfig('password_protected_startpage')) { $freePageIds[] = DEFAULT_PAGE_ID; } if (!in_array($pageId, $freePageIds)) { // create warning message $websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $i18n->getMessage('requireslogin_box_title'), $i18n->getMessage('requireslogin_box_message'))); $pageId = LOGIN_PAGE_ID; } } // exception rule: If user clicks at breadcrumb navigation on team details, there will be no ID given, so redirect to leagues if ($pageId == 'team' && $websoccer->getRequestParameter('id') == null) { $pageId = 'leagues'; } // prompt user to enter user name, after he has been created without user name (e.g. by a custom LoginMethod). if ($user->getRole() == ROLE_USER && !strlen($user->username)) { $pageId = ENTERUSERNAME_PAGE_ID; } return $pageId; }
/** * Creates a new unseen notification about any event which shall catch the user's attention. * * @param WebSoccer $websoccer application context. * @param DbConnection $db DB connection. * @return int ID of national team managed by the current user, or NULL if user does not manage a national team. */ public static function getNationalTeamManagedByCurrentUser(WebSoccer $websoccer, DbConnection $db) { $result = $db->queryCachedSelect("id", $websoccer->getConfig("db_prefix") . "_verein", "user_id = %d AND nationalteam = '1'", $websoccer->getUser()->id, 1); if (count($result)) { return $result[0]["id"]; } return NULL; }
private static function createTransaction(WebSoccer $websoccer, DbConnection $db, $user, $userId, $amount, $subject, $data) { // create transaction $fromTable = $websoccer->getConfig('db_prefix') . '_premiumstatement'; $columns = array('user_id' => $userId, 'action_id' => $subject, 'amount' => $amount, 'created_date' => $websoccer->getNowAsTimestamp(), 'subject_data' => json_encode($data)); $db->queryInsert($columns, $fromTable); // update user budget $newBudget = $user['premium_balance'] + $amount; $updateColumns = array('premium_balance' => $newBudget); $fromTable = $websoccer->getConfig('db_prefix') . '_user'; $whereCondition = 'id = %d'; $parameters = $userId; $db->queryUpdate($updateColumns, $fromTable, $whereCondition, $parameters); // also update user profile, if executed by user. if ($userId == $websoccer->getUser()->id) { $websoccer->getUser()->premiumBalance = $newBudget; } }
public static function getLastMatch(WebSoccer $websoccer, DbConnection $db) { // where $whereCondition = 'M.berechnet = 1 AND (HOME.user_id = %d OR GUEST.user_id = %d) AND M.datum < %d ORDER BY M.datum DESC'; $parameters = array($websoccer->getUser()->id, $websoccer->getUser()->id, $websoccer->getNowAsTimestamp()); return self::_getMatchSummaryByCondition($websoccer, $db, $whereCondition, $parameters); }
public static function countOutboxMessages(WebSoccer $websoccer, DbConnection $db) { $userId = $websoccer->getUser()->id; $columns = "COUNT(*) AS hits"; $fromTable = $websoccer->getConfig("db_prefix") . "_briefe AS L"; $whereCondition = "L.absender_id = %d AND typ = 'ausgang'"; $result = $db->querySelect($columns, $fromTable, $whereCondition, $userId); $letters = $result->fetch_array(); $result->free(); if (isset($letters["hits"])) { return $letters["hits"]; } return 0; }
private static function _handlePremiumAction(WebSoccer $website, DbConnection $db, I18n $i18n, $actionId, $creditsRequired, $validatedParams, $controllerName) { // check if user has enough credit if ($creditsRequired > $website->getUser()->premiumBalance) { $targetPage = $website->getConfig('premium_infopage'); // redirect to external info page if (filter_var($targetPage, FILTER_VALIDATE_URL)) { header('location: ' . $targetPage); exit; // render info page } else { $website->addContextParameter('premium_balance_required', $creditsRequired); return $targetPage; } } // debit amount and execute action if ($website->getRequestParameter('premiumconfirmed')) { PremiumDataService::debitAmount($website, $db, $website->getUser()->id, $creditsRequired, $actionId); return self::_executeAction($website, $db, $i18n, $actionId, $controllerName, $validatedParams); } // redirect to confirmation page $website->addContextParameter('premium_balance_required', $creditsRequired); $website->addContextParameter('actionparameters', $validatedParams); $website->addContextParameter('actionid', $actionId); $website->addContextParameter('srcpage', $website->getPageId()); return 'premium-confirm-action'; }
/** * Stores ID of user in session and triggers authentication by SessionBasedUserAuthentication. * * @param WebSoccer $websoccer Application context. * @param int $userId ID of user to log in. */ public static function loginFrontUserUsingApplicationSession(WebSoccer $websoccer, $userId) { // actual log-in $_SESSION['frontuserid'] = $userId; session_regenerate_id(); // update user data $userProvider = new SessionBasedUserAuthentication($websoccer); $userProvider->verifyAndUpdateCurrentUser($websoccer->getUser()); }