From 76cedb15a246378a45cae826c833389ce5067ecc Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Fri, 12 Aug 2022 20:07:38 +0200 Subject: [PATCH] Only allow betting if user is in a match --- block/bet.php | 5 +++-- includes/functions.php | 26 ++++++++++++++++++++++++++ language/de/football.php | 2 +- language/en/football.php | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/block/bet.php b/block/bet.php index 56124e9..a7b0bb8 100644 --- a/block/bet.php +++ b/block/bet.php @@ -20,7 +20,9 @@ $join_league = false; $matchnumber = 0; $userid = $user->data['user_id']; $lang_dates = $user->lang['datetime']; +$league_info = league_info($season, $league); $user_is_member = user_is_member($userid, $season, $league); +$user_is_allowed_to_bet = $league_info['bet_type'] ? true : user_is_allowed_to_bet($userid, $season, $league, $matchday); $display_rating = false; // Calculate multiple delivery @@ -470,7 +472,6 @@ while ($row = $db->sql_fetchrow($result)) } $db->sql_freeresult($result); -$league_info = league_info($season, $league); $bet_explain = ''; switch ($league_info['bet_ko_type']) { @@ -511,7 +512,7 @@ $template->assign_vars(array( 'S_FORM_ACTION_BET' => $this->helper->route('football_main_controller', array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday, 'action' => 'bet')), 'S_FORM_ACTION_JOIN' => $this->helper->route('football_main_controller', array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday, 'action' => 'join')), 'S_USER_IS_MEMBER' => $user_is_member, - 'S_DATA_BET' => $data_bet, + 'S_DATA_BET' => $data_bet && $user_is_allowed_to_bet, 'S_DATA_GROUP' => $data_group, 'S_DATA_BET_RESULTS' => $data_bet_results, 'S_EDIT_MODE' => $edit_mode, diff --git a/includes/functions.php b/includes/functions.php index 2096e04..ef8be25 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -741,6 +741,32 @@ function user_is_member($userid, $season, $league) $db->sql_freeresult($result); } +/** +* Is user allowed to bet this matchday +*/ +function user_is_allowed_to_bet($userid, $season, $league, $matchday) +{ + global $db; + $sql = 'SELECT COUNT(*) AS counter + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + 50 + AND matchday = $matchday + AND (team_id_home = $userid + 2000 OR team_id_guest = $userid + 2000)"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + + if ($row['counter'] > 0) + { + return true; + } + else + { + return false; + } + $db->sql_freeresult($result); +} + /** * Count existing matches on matchday or league */ diff --git a/language/de/football.php b/language/de/football.php index 067dc6c..4a4a7c3 100644 --- a/language/de/football.php +++ b/language/de/football.php @@ -246,7 +246,7 @@ $lang = array_merge($lang, array( 'NO_MATCH' => 'Das von dir ausgewählte Spiel existiert nicht. ', 'NO_MATCHDAY' => 'Der von dir ausgewählte Spieltag existiert nicht. ', 'NO_MATCHES' => 'Keine Spiele vorhanden!', - 'NO_MATCHES_ON_MATCHDAY' => 'Der Spielplan wurde noch nicht erstellt. ', + 'NO_MATCHES_ON_MATCHDAY' => 'Der Spielplan wurde noch nicht erstellt oder du darfst diesen Spieltag nicht tippen. ', 'NO_MATCHES_TEAM' => 'Dieses Team hat in dieser Saison noch keine Spiele bestritten. ', 'NO_MEMBER' => 'Du bist kein Mitglied dieser Tipprunde!', 'NO_MYBETS_ME' => 'Du bist kein Mitglied dieser Tipprunde!', diff --git a/language/en/football.php b/language/en/football.php index 8d9b781..d4934bb 100644 --- a/language/en/football.php +++ b/language/en/football.php @@ -234,7 +234,7 @@ $lang = array_merge($lang, array( 'NO_MATCH' => 'The match chosen by you does not exist. ', 'NO_MATCHDAY' => 'The matchday chosen by you does not exist. ', 'NO_MATCHES' => 'No matches available!', - 'NO_MATCHES_ON_MATCHDAY' => 'The fixture list was not created yet. ', + 'NO_MATCHES_ON_MATCHDAY' => 'The fixture list was not created yet or you are not allowed to bet this matchday. ', 'NO_MATCHES_TEAM' => 'This team has not played any matches this season yet . ', 'NO_MEMBER' => 'You are not a member of this Webtip!', 'NO_MYBETS_ME' => 'You are not a member of this Webtip!',