From a16e0e3c7911538539fbbd8d537e27d7946bb7e7 Mon Sep 17 00:00:00 2001 From: football Date: Sun, 19 Feb 2017 20:25:32 +0100 Subject: [PATCH] Version 0.9.8 --- acp/all_bets_module.php | 1196 ++-- acp/bank_module.php | 1342 +++-- acp/bets_module.php | 1502 +++-- acp/extra_module.php | 922 ++- acp/football_module.php | 848 ++- acp/ko_module.php | 510 +- acp/leagues_module.php | 1468 +++-- acp/matchdays_module.php | 2264 ++++---- acp/matches_module.php | 1530 +++-- acp/results_module.php | 1634 +++--- acp/seasons_module.php | 788 ++- acp/teams_module.php | 1314 +++-- acp/update_module.php | 2918 +++++----- block/delivery.php | 266 +- composer.json | 6 +- cron/task/football_remember.php | 668 +-- event/main_listener.php | 1100 ++-- includes/functions.php | 5061 +++++++++-------- language/de/info_acp_football.php | 409 +- language/en/info_acp_football.php | 1 + migrations/v094_beta_update.php | 16 +- migrations/v098_beta.php | 30 + .../event/overall_header_head_append.html | 58 +- .../overall_header_page_body_before.html | 126 +- styles/prosilver/template/football_body.html | 438 +- .../template/mobile_football_body.html | 354 +- 26 files changed, 13323 insertions(+), 13446 deletions(-) create mode 100644 migrations/v098_beta.php diff --git a/acp/all_bets_module.php b/acp/all_bets_module.php index 59d0273..dc4268b 100644 --- a/acp/all_bets_module.php +++ b/acp/all_bets_module.php @@ -1,600 +1,598 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_all_bets'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_all_bets'; - $this->page_title = 'ACP_FOOTBALL_ALL_BETS_VIEW'; - - $form_key = 'acp_football_all_bets'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $start = $this->request->variable('start', 0); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = current_league($season); - } - - $league_info = league_info($season, $league); - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $matches_matchday = $row['matches_on_matchday']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&m=$season"), E_USER_WARNING); - } - - // Grab basic data for select matchday - if (!$matchday) - { - $matchday = curr_matchday($season, $league); - } - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $matchday_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - if ($selected <> '') - { - $matchday_name = $day_name; - if ($matches_matchday) - { - $matches_on_matchday = $matches_matchday; - } - else - { - $matches_on_matchday = $row['matches']; - } - } - } - $db->sql_freeresult($result); - if ($matchday_options == '') - { - trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&m=$season&l=$league"), E_USER_WARNING); - } - - $matches_on_matchday = false; - - $sql = 'SELECT - COUNT(DISTINCT user_id) AS num_users - FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $total_users = (int) $db->sql_fetchfield('num_users'); - $db->sql_freeresult($result); - - $sql = "SELECT - m.match_no, - m.status, - m.formula_home, - m.formula_guest, - t1.team_name_short AS hname, - t2.team_name_short AS gname, - t1.team_id AS hid, - t2.team_id AS gid, - m.goals_home, - m.goals_guest, - SUM(IF(b.goals_home + 0 > b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS home, - SUM(IF(b.goals_home = b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS draw, - SUM(IF(b.goals_home + 0 < b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS guest - FROM " . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . ' AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) - LEFT JOIN ' . FOOTB_BETS . " AS b ON(b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - WHERE m.season = $season - AND m.league = $league - AND m.matchday = $matchday - GROUP BY m.match_no - ORDER BY m.match_datetime ASC, m.match_no ASC - "; - - $result = $db->sql_query($sql); - $matches = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $count_matches = sizeof($matches); - if ($count_matches > 11) - { - $split_after = 8; - $splits = ceil($count_matches / 8); - } - else - { - $split_after = $count_matches; - $splits = 1; - } - $db->sql_freeresult($result); - - // Make sure $start is set to the last page if it exceeds the amount - if ($start < 0 || $start >= $total_users) - { - $start = ($start < 0) ? 0 : floor(($total_users - 1) / $this->config['football_users_per_page']) * $this->config['football_users_per_page']; - } - else - { - $start = floor($start / $this->config['football_users_per_page']) * $this->config['football_users_per_page']; - } - - $sql_start = $start * $count_matches; - $sql_limit = $this->config['football_users_per_page'] * $count_matches; - - // handle pagination. - $base_url = $this->u_action . "&s=$season&l=$league&m=$matchday"; - $pagination = $phpbb_container->get('pagination'); - $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_users, $this->config['football_users_per_page'], $start); - - if ($count_matches > 0) - { - $matches_on_matchday = true; - - $sql = "SELECT - u.user_id, - u.username, - m.status, - b.goals_home AS bet_home, - b.goals_guest AS bet_guest, - " . select_points() . " - FROM " . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_BETS . ' AS b ON(b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - LEFT JOIN ' . USERS_TABLE . " AS u ON (u.user_id=b.user_id) - WHERE m.season = $season - AND m.league = $league - AND m.matchday = $matchday - ORDER BY LOWER(u.username) ASC, m.match_datetime ASC, m.match_no ASC"; - $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); - $user_bets = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $bet_index = 0; - $split_index = 0; - foreach ($user_bets AS $user_bet) - { - if ($bet_index == $count_matches) - { - $bet_index = 0; - $split_index = 0; - } - if (!($bet_index % $split_after)) - { - $split_index++; - } - $sum_total[$user_bet['username']] = 0; - $bet_line[$split_index][] = $user_bet; - $bet_index++; - } - } - $match_index = 0; - $last_match_index = 0; - $split_index = 0; - $matchday_sum_total = 0; - $colorstyle_total = ' color_finally'; - foreach ($matches AS $match) - { - if (!($match_index % $split_after)) - { - if ($match_index > 0) - { - $total = 0; - $count_user = 0; - $bet_index = 0; - $last_match_index = 0; - foreach ($bet_line[$split_index] AS $user_bet) - { - if ($bet_index == 0) - { - $count_user++; - $row_class = (!($count_user % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - if ($user_bet['user_id'] == $user->data['user_id']) - { - $row_class = 'bg3 row_user'; - } - $template->assign_block_vars('match_panel.user_row', array( - 'ROW_CLASS' => $row_class, - 'USER_NAME' => $user_bet['username'], - ) - ); - $total = 0; - } - $bet_index++; - $total += $user_bet['points']; - if ($user_bet['status'] < 3) - { - $colorstyle_total = ' color_provisionally'; - } - $bet_home = $user_bet['bet_home']; - $bet_guest = $user_bet['bet_guest']; - - $colorstyle_bet = color_style($user_bet['status']); - $template->assign_block_vars('match_panel.user_row.bet', array( - 'BET' => $bet_home. ':'. $bet_guest, - 'COLOR_STYLE' => $colorstyle_bet, - 'POINTS' => ($user_bet['points'] == '') ? ' ' : $user_bet['points'], - ) - ); - - if ($bet_index == $split_after) - { - $sum_total[$user_bet['username']] += $total; - $matchday_sum_total += $total; - $bet_index = 0; - } - } - - $template->assign_block_vars('match_panel.tendency_footer', array( - 'S_TOTAL' => false, - ) - ); - foreach ($matches_tendency AS $match_tendency) - { - $template->assign_block_vars('match_panel.tendency_footer.tendency', array( - 'TENDENCY' => $match_tendency[0], - 'MATCH_ENTRY' => $match_tendency[1], - ) - ); - } - } - $matches_tendency = array(); - $split_index++; - if ($split_index == $splits) - { - $display_total = true; - } - else - { - $display_total = false; - } - $template->assign_block_vars('match_panel', array( - 'S_TOTAL' => $display_total, - ) - ); - } - if (0 == $match['hid']) - { - $home_info = get_team($season, $league, $match['match_no'], 'team_id_home', $match['formula_home']); - $home_in_array = explode("#",$home_info); - $homename = $home_in_array[3]; - } - else - { - $homename = $match['hname']; - } - if (0 == $match['gid']) - { - $guest_info = get_team($season, $league, $match['match_no'], 'team_id_guest', $match['formula_guest']); - $guest_in_array = explode("#",$guest_info); - $guestname = $guest_in_array[3]; - } - else - { - $guestname = $match['gname']; - } - $colorstyle_match = color_style($match['status']); - $template->assign_block_vars('match_panel.match', array( - 'HOME_NAME' => $homename, - 'GUEST_NAME' => $guestname, - 'RESULT' => $match['goals_home']. ':'.$match['goals_guest'], - 'COLOR_STYLE' => $colorstyle_match, - ) - ); - - $matches_tendency[] = array($match['home'] . '-' . $match['draw'] . '-' . $match['guest'], $homename . '-' . $guestname); - $match_index++; - $last_match_index++; - } - if ($count_matches > 0) - { - $total = 0; - $count_user = 0; - $bet_index = 0; - foreach ($bet_line[$split_index] AS $user_bet) - { - if ($bet_index == 0) - { - $count_user++; - $row_class = (!($count_user % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - if ($user_bet['user_id'] == $user->data['user_id']) - { - $row_class = 'bg3 row_user'; - } - $template->assign_block_vars('match_panel.user_row', array( - 'ROW_CLASS' => $row_class, - 'USER_NAME' => $user_bet['username'], - ) - ); - $total = 0; - } - $bet_index++; - $total += $user_bet['points']; - if ($user_bet['status'] < 3) - { - $colorstyle_total = ' color_provisionally'; - } - $bet_home = $user_bet['bet_home']; - $bet_guest = $user_bet['bet_guest']; - - $colorstyle_bet = color_style($user_bet['status']); - $template->assign_block_vars('match_panel.user_row.bet', array( - 'BET' => $bet_home. ':'. $bet_guest, - 'COLOR_STYLE' => $colorstyle_bet, - 'POINTS' => ($user_bet['points'] == '') ? ' ' : $user_bet['points'], - ) - ); - - if ($bet_index == $last_match_index) - { - $sum_total[$user_bet['username']] += $total; - $matchday_sum_total += $total; - $template->assign_block_vars('match_panel.user_row.points', array( - 'COLOR_STYLE' => $colorstyle_total, - 'POINTS_TOTAL' => $sum_total[$user_bet['username']], - ) - ); - $bet_index = 0; - } - } - - $template->assign_block_vars('match_panel.tendency_footer', array( - 'S_TOTAL' => true, - 'COLOR_STYLE' => $colorstyle_total, //currently ignored - 'SUMTOTAL' => $matchday_sum_total, - ) - ); - foreach ($matches_tendency AS $match_tendency) - { - $template->assign_block_vars('match_panel.tendency_footer.tendency', array( - 'TENDENCY' => $match_tendency[0], - 'MATCH_ENTRY' => $match_tendency[1], - ) - ); - } - } - - //extra bets - // Calculate extra bets of matchday - $sql_start = $start; - $sql_limit = $this->config['football_users_per_page']; - $sql = "SELECT e.*, - t1.team_name AS result_team - FROM " . FOOTB_EXTRA . ' AS e - LEFT JOIN ' . FOOTB_TEAMS . " AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) - WHERE e.season = $season - AND e.league = $league - AND e.matchday = $matchday - ORDER BY e.extra_no ASC"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $extra_no = $row['extra_no']; - switch($row['question_type']) - { - case '1': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '2': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '3': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '4': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '5': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); - } - break; - default : - { - $display_type = 2; - $eval_title = ''; - } - break; - } - $extra_colorstyle = color_style($row['extra_status']); - - $template->assign_block_vars('extra_panel', array( - 'QUESTION' => $row['question'], - 'RESULT' => ($display_type == 1) ? $row['result_team'] : $row['result'], - 'POINTS' => $row['extra_points'], - 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), - 'EVALUATION_TITLE' => $eval_title, - 'COLOR_STYLE' => $extra_colorstyle, - ) - ); - - // Get all extra bets of matchday - $bet_number = 0; - $sql = "SELECT u.user_id, - u.username, - e.*, - eb.bet, - eb.bet_points, - t2.team_name AS bet_team - FROM " . FOOTB_BETS . ' AS b - LEFT JOIN ' . USERS_TABLE . ' AS u ON (u.user_id = b.user_id) - LEFT JOIN ' . FOOTB_EXTRA . " AS e ON (e.season = b.season AND e.league = b.league AND e.matchday = $matchday AND e.extra_no = $extra_no) - LEFT JOIN " . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = b.season AND eb.league = b.league AND eb.extra_no = $extra_no AND eb.user_id = b.user_id) - LEFT JOIN " . FOOTB_TEAMS . " AS t2 ON (t2.season = b.season AND t2.league = b.league AND t2.team_id = eb.bet) - WHERE b.season = $season - AND b.league = $league - AND b.match_no = 1 - GROUP by b.user_id - ORDER BY LOWER(u.username) ASC"; - $result_bet = $db->sql_query_limit($sql, $sql_limit, $sql_start); - - while ($user_row = $db->sql_fetchrow($result_bet)) - { - $bet_number++ ; - $row_class = (!($bet_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - if ($user_row['user_id'] == $user->data['user_id']) - { - $row_class = 'bg3 row_user'; - } - - $bet = ($user_row['bet'] == '') ? ' ' : $user_row['bet']; - $bet_team = ($user_row['bet_team'] == NULL) ? ' ' : $user_row['bet_team']; - - - $template->assign_block_vars('extra_panel.user_row', array( - 'ROW_CLASS' => $row_class, - 'USER_NAME' => $user_row['username'], - 'BET' => ($display_type == 1) ? $bet_team : $bet, - 'BET_POINTS' => $user_row['bet_points'], - 'COLOR_STYLE' => $extra_colorstyle, - ) - ); - } - } - - $legend = delivery($season, $league, $matchday); - - $template->assign_vars(array( - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'all_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_MATCHDAY' => $matchday, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_MATCHDAY_OPTIONS' => $matchday_options, - 'S_DISPLAY_ALL_BETS' => true, - 'S_MATCHES_ON_MATCHDAY' => $matches_on_matchday, - 'S_SPALTEN' => ($count_matches * 2)+2, - 'S_VERSION_NO' => $this->config['football_version'], - 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_users), - 'PAGE_NUMBER' => $pagination->on_page($total_users, $this->config['football_users_per_page'], $start), - ) - ); - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_all_bets'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_all_bets'; + $this->page_title = 'ACP_FOOTBALL_ALL_BETS_VIEW'; + + $form_key = 'acp_football_all_bets'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $start = $this->request->variable('start', 0); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = current_league($season); + } + + $league_info = league_info($season, $league); + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $matches_matchday = $row['matches_on_matchday']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&m=$season"), E_USER_WARNING); + } + + // Grab basic data for select matchday + if (!$matchday) + { + $matchday = curr_matchday($season, $league); + } + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $matchday_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + if ($selected <> '') + { + $matchday_name = $day_name; + if ($matches_matchday) + { + $matches_on_matchday = $matches_matchday; + } + else + { + $matches_on_matchday = $row['matches']; + } + } + } + $db->sql_freeresult($result); + if ($matchday_options == '') + { + trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&m=$season&l=$league"), E_USER_WARNING); + } + + $matches_on_matchday = false; + + $sql = 'SELECT + COUNT(DISTINCT user_id) AS num_users + FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $total_users = (int) $db->sql_fetchfield('num_users'); + $db->sql_freeresult($result); + + $sql = "SELECT + m.match_no, + m.status, + m.formula_home, + m.formula_guest, + t1.team_name_short AS hname, + t2.team_name_short AS gname, + t1.team_id AS hid, + t2.team_id AS gid, + m.goals_home, + m.goals_guest, + SUM(IF(b.goals_home + 0 > b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS home, + SUM(IF(b.goals_home = b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS draw, + SUM(IF(b.goals_home + 0 < b.goals_guest AND b.goals_home <> '' AND b.goals_guest <> '', 1, 0)) AS guest + FROM " . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . ' AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) + LEFT JOIN ' . FOOTB_BETS . " AS b ON(b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + WHERE m.season = $season + AND m.league = $league + AND m.matchday = $matchday + GROUP BY m.match_no + ORDER BY m.match_datetime ASC, m.match_no ASC + "; + + $result = $db->sql_query($sql); + $matches = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $count_matches = sizeof($matches); + if ($count_matches > 11) + { + $split_after = 8; + $splits = ceil($count_matches / 8); + } + else + { + $split_after = $count_matches; + $splits = 1; + } + $db->sql_freeresult($result); + + // Make sure $start is set to the last page if it exceeds the amount + if ($start < 0 || $start >= $total_users) + { + $start = ($start < 0) ? 0 : floor(($total_users - 1) / $this->config['football_users_per_page']) * $this->config['football_users_per_page']; + } + else + { + $start = floor($start / $this->config['football_users_per_page']) * $this->config['football_users_per_page']; + } + + $sql_start = $start * $count_matches; + $sql_limit = $this->config['football_users_per_page'] * $count_matches; + + // handle pagination. + $base_url = $this->u_action . "&s=$season&l=$league&m=$matchday"; + $pagination = $phpbb_container->get('pagination'); + $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_users, $this->config['football_users_per_page'], $start); + + if ($count_matches > 0) + { + $matches_on_matchday = true; + + $sql = "SELECT + u.user_id, + u.username, + m.status, + b.goals_home AS bet_home, + b.goals_guest AS bet_guest, + " . select_points() . " + FROM " . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_BETS . ' AS b ON(b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + LEFT JOIN ' . USERS_TABLE . " AS u ON (u.user_id=b.user_id) + WHERE m.season = $season + AND m.league = $league + AND m.matchday = $matchday + ORDER BY LOWER(u.username) ASC, m.match_datetime ASC, m.match_no ASC"; + $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); + $user_bets = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $bet_index = 0; + $split_index = 0; + foreach ($user_bets AS $user_bet) + { + if ($bet_index == $count_matches) + { + $bet_index = 0; + $split_index = 0; + } + if (!($bet_index % $split_after)) + { + $split_index++; + } + $sum_total[$user_bet['username']] = 0; + $bet_line[$split_index][] = $user_bet; + $bet_index++; + } + } + $match_index = 0; + $last_match_index = 0; + $split_index = 0; + $matchday_sum_total = 0; + $colorstyle_total = ' color_finally'; + foreach ($matches AS $match) + { + if (!($match_index % $split_after)) + { + if ($match_index > 0) + { + $total = 0; + $count_user = 0; + $bet_index = 0; + $last_match_index = 0; + foreach ($bet_line[$split_index] AS $user_bet) + { + if ($bet_index == 0) + { + $count_user++; + $row_class = (!($count_user % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + if ($user_bet['user_id'] == $user->data['user_id']) + { + $row_class = 'bg3 row_user'; + } + $template->assign_block_vars('match_panel.user_row', array( + 'ROW_CLASS' => $row_class, + 'USER_NAME' => $user_bet['username'], + ) + ); + $total = 0; + } + $bet_index++; + $total += $user_bet['points']; + if ($user_bet['status'] < 3) + { + $colorstyle_total = ' color_provisionally'; + } + $bet_home = $user_bet['bet_home']; + $bet_guest = $user_bet['bet_guest']; + + $colorstyle_bet = color_style($user_bet['status']); + $template->assign_block_vars('match_panel.user_row.bet', array( + 'BET' => $bet_home. ':'. $bet_guest, + 'COLOR_STYLE' => $colorstyle_bet, + 'POINTS' => ($user_bet['points'] == '') ? ' ' : $user_bet['points'], + ) + ); + + if ($bet_index == $split_after) + { + $sum_total[$user_bet['username']] += $total; + $matchday_sum_total += $total; + $bet_index = 0; + } + } + + $template->assign_block_vars('match_panel.tendency_footer', array( + 'S_TOTAL' => false, + ) + ); + foreach ($matches_tendency AS $match_tendency) + { + $template->assign_block_vars('match_panel.tendency_footer.tendency', array( + 'TENDENCY' => $match_tendency[0], + 'MATCH_ENTRY' => $match_tendency[1], + ) + ); + } + } + $matches_tendency = array(); + $split_index++; + if ($split_index == $splits) + { + $display_total = true; + } + else + { + $display_total = false; + } + $template->assign_block_vars('match_panel', array( + 'S_TOTAL' => $display_total, + ) + ); + } + if (0 == $match['hid']) + { + $home_info = get_team($season, $league, $match['match_no'], 'team_id_home', $match['formula_home']); + $home_in_array = explode("#",$home_info); + $homename = $home_in_array[3]; + } + else + { + $homename = $match['hname']; + } + if (0 == $match['gid']) + { + $guest_info = get_team($season, $league, $match['match_no'], 'team_id_guest', $match['formula_guest']); + $guest_in_array = explode("#",$guest_info); + $guestname = $guest_in_array[3]; + } + else + { + $guestname = $match['gname']; + } + $colorstyle_match = color_style($match['status']); + $template->assign_block_vars('match_panel.match', array( + 'HOME_NAME' => $homename, + 'GUEST_NAME' => $guestname, + 'RESULT' => $match['goals_home']. ':'.$match['goals_guest'], + 'COLOR_STYLE' => $colorstyle_match, + ) + ); + + $matches_tendency[] = array($match['home'] . '-' . $match['draw'] . '-' . $match['guest'], $homename . '-' . $guestname); + $match_index++; + $last_match_index++; + } + if ($count_matches > 0) + { + $total = 0; + $count_user = 0; + $bet_index = 0; + foreach ($bet_line[$split_index] AS $user_bet) + { + if ($bet_index == 0) + { + $count_user++; + $row_class = (!($count_user % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + if ($user_bet['user_id'] == $user->data['user_id']) + { + $row_class = 'bg3 row_user'; + } + $template->assign_block_vars('match_panel.user_row', array( + 'ROW_CLASS' => $row_class, + 'USER_NAME' => $user_bet['username'], + ) + ); + $total = 0; + } + $bet_index++; + $total += $user_bet['points']; + if ($user_bet['status'] < 3) + { + $colorstyle_total = ' color_provisionally'; + } + $bet_home = $user_bet['bet_home']; + $bet_guest = $user_bet['bet_guest']; + + $colorstyle_bet = color_style($user_bet['status']); + $template->assign_block_vars('match_panel.user_row.bet', array( + 'BET' => $bet_home. ':'. $bet_guest, + 'COLOR_STYLE' => $colorstyle_bet, + 'POINTS' => ($user_bet['points'] == '') ? ' ' : $user_bet['points'], + ) + ); + + if ($bet_index == $last_match_index) + { + $sum_total[$user_bet['username']] += $total; + $matchday_sum_total += $total; + $template->assign_block_vars('match_panel.user_row.points', array( + 'COLOR_STYLE' => $colorstyle_total, + 'POINTS_TOTAL' => $sum_total[$user_bet['username']], + ) + ); + $bet_index = 0; + } + } + + $template->assign_block_vars('match_panel.tendency_footer', array( + 'S_TOTAL' => true, + 'COLOR_STYLE' => $colorstyle_total, //currently ignored + 'SUMTOTAL' => $matchday_sum_total, + ) + ); + foreach ($matches_tendency AS $match_tendency) + { + $template->assign_block_vars('match_panel.tendency_footer.tendency', array( + 'TENDENCY' => $match_tendency[0], + 'MATCH_ENTRY' => $match_tendency[1], + ) + ); + } + } + + //extra bets + // Calculate extra bets of matchday + $sql_start = $start; + $sql_limit = $this->config['football_users_per_page']; + $sql = "SELECT e.*, + t1.team_name AS result_team + FROM " . FOOTB_EXTRA . ' AS e + LEFT JOIN ' . FOOTB_TEAMS . " AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) + WHERE e.season = $season + AND e.league = $league + AND e.matchday = $matchday + ORDER BY e.extra_no ASC"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $extra_no = $row['extra_no']; + switch($row['question_type']) + { + case '1': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '2': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '3': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '4': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '5': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); + } + break; + default : + { + $display_type = 2; + $eval_title = ''; + } + break; + } + $extra_colorstyle = color_style($row['extra_status']); + + $template->assign_block_vars('extra_panel', array( + 'QUESTION' => $row['question'], + 'RESULT' => ($display_type == 1) ? $row['result_team'] : $row['result'], + 'POINTS' => $row['extra_points'], + 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), + 'EVALUATION_TITLE' => $eval_title, + 'COLOR_STYLE' => $extra_colorstyle, + ) + ); + + // Get all extra bets of matchday + $bet_number = 0; + $sql = "SELECT u.user_id, + u.username, + e.*, + eb.bet, + eb.bet_points, + t2.team_name AS bet_team + FROM " . FOOTB_BETS . ' AS b + LEFT JOIN ' . USERS_TABLE . ' AS u ON (u.user_id = b.user_id) + LEFT JOIN ' . FOOTB_EXTRA . " AS e ON (e.season = b.season AND e.league = b.league AND e.matchday = $matchday AND e.extra_no = $extra_no) + LEFT JOIN " . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = b.season AND eb.league = b.league AND eb.extra_no = $extra_no AND eb.user_id = b.user_id) + LEFT JOIN " . FOOTB_TEAMS . " AS t2 ON (t2.season = b.season AND t2.league = b.league AND t2.team_id = eb.bet) + WHERE b.season = $season + AND b.league = $league + AND b.match_no = 1 + GROUP by b.user_id + ORDER BY LOWER(u.username) ASC"; + $result_bet = $db->sql_query_limit($sql, $sql_limit, $sql_start); + + while ($user_row = $db->sql_fetchrow($result_bet)) + { + $bet_number++ ; + $row_class = (!($bet_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + if ($user_row['user_id'] == $user->data['user_id']) + { + $row_class = 'bg3 row_user'; + } + + $bet = ($user_row['bet'] == '') ? ' ' : $user_row['bet']; + $bet_team = ($user_row['bet_team'] == NULL) ? ' ' : $user_row['bet_team']; + + + $template->assign_block_vars('extra_panel.user_row', array( + 'ROW_CLASS' => $row_class, + 'USER_NAME' => $user_row['username'], + 'BET' => ($display_type == 1) ? $bet_team : $bet, + 'BET_POINTS' => $user_row['bet_points'], + 'COLOR_STYLE' => $extra_colorstyle, + ) + ); + } + } + + $legend = delivery($season, $league, $matchday); + + $template->assign_vars(array( + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'all_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_MATCHDAY' => $matchday, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_MATCHDAY_OPTIONS' => $matchday_options, + 'S_DISPLAY_ALL_BETS' => true, + 'S_MATCHES_ON_MATCHDAY' => $matches_on_matchday, + 'S_SPALTEN' => ($count_matches * 2)+2, + 'S_VERSION_NO' => $this->config['football_version'], + 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_users), + 'PAGE_NUMBER' => $pagination->on_page($total_users, $this->config['football_users_per_page'], $start), + ) + ); + } +} ?> \ No newline at end of file diff --git a/acp/bank_module.php b/acp/bank_module.php index 520d56c..af79a1d 100644 --- a/acp/bank_module.php +++ b/acp/bank_module.php @@ -1,673 +1,671 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_bank'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - if (!$this->config['football_bank']) - { - trigger_error($user->lang['FOOTBALL_BANK_OFF'], E_USER_WARNING); - } - - if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) - { - $user->add_lang_ext('dmzx/ultimatepoints', 'common'); - // Get an instance of the ultimatepoints functions_points - $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); - } - else - { - // Get an instance of the football functions_points - $functions_points = $phpbb_container->get('football.football.core.functions.points'); - } - - $this->tpl_name = 'acp_football_bank'; - $this->page_title = 'ACP_FOOTBALL_BANK_MANAGE'; - - $form_key = 'acp_football_bank'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addmembers'])) ? 'addmembers' : $this->request->variable('action', '')); - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $type = $this->request->variable('t', 0); - $start = $this->request->variable('start', 0); - - // Clear some vars - $league_info = array(); - $error = array(); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - // Grab basic data for season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for league, if league is set and exists - if ($league) - { - $league_info = league_info($season, $league); - } - - // Which page? - switch ($action) - { - case 'bet': - case 'deposit': - case 'delete_wins': - case 'pay': - switch ($action) - { - case 'bet': - $type = POINTS_BET; - $default_matchday = 1; - $select_win = 'l.bet_points - SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS win'; - $points_var = 'BET'; - break; - case 'deposit': - $type = POINTS_DEPOSITED; - $default_matchday = 1; - $select_win = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)) > 0, - SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)), 0.00) AS win'; - $points_var = 'DEPOSIT'; - break; - case 'delete_wins': - $default_matchday = 0; - $points_var = 'DELETE_WIN'; - break; - case 'pay': - $type = POINTS_PAID; - $default_matchday = 1; - $select_win = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)) > 0, - SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)), 0.00) AS win'; - $points_var = 'PAY'; - break; - } - - $mark_ary = $this->request->variable('markleague', array(0)); - $cash = $this->request->variable('cash', false); - - if (sizeof($mark_ary) == 0) - { - trigger_error($user->lang['NO_LEAGUES_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - if (confirm_box(true)) - { - $count_updates = 0; - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - $league = $mark_ary[$i]; - if ($action == 'delete_wins') - { - rollback_points(POINTS_MATCHDAY, $season, $league, 0, $cash); - rollback_points(POINTS_SEASON, $season, $league, 0, $cash); - rollback_points(POINTS_MOST_HITS, $season, $league, 0, $cash); - rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, 0, $cash); - $sql = 'DELETE FROM ' . FOOTB_POINTS . " - WHERE season = $season - AND league = $league - AND points_type IN (" . POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . ')'; - $result = $db->sql_query($sql); - $count_updates += $db->sql_affectedrows(); - } - else - { - $sql = "SELECT b.user_id, - $select_win - FROM " . FOOTB_BETS . ' AS b - JOIN ' . FOOTB_LEAGUES . " AS l ON (l.season = $season AND l.league = $league ) - LEFT JOIN " . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = $league AND p.user_id = b.user_id) - WHERE b.season = $season - AND b.league = $league - AND b.match_no = 1 - GROUP BY b.season, b.league, b.user_id - HAVING win > 0"; - $result = $db->sql_query($sql); - $points_ary = $db->sql_fetchrowset($result); - if (!$default_matchday) - { - $matchday = (curr_matchday($season, $league) > 0) ? curr_matchday($season, $league) : 1; - } - else - { - $matchday = $default_matchday; - } - if (sizeof($points_ary) > 0) - { - $count_updates += sizeof($points_ary); - set_footb_points($type, $season, $league, $matchday, $points_ary, $cash); - } - } - } - $back_link = $this->u_action . '&s=' . $season; - trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) .adm_back_link($back_link)); - } - else - { - confirm_box(false, sprintf($user->lang['CONFIRM_LEAGUE_' . $points_var]), build_hidden_fields(array( - 'markleague'=> $mark_ary, - 'cash' => $cash, - 's' => $season, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'book': - switch ($type) - { - case POINTS_BET: - $points_var = 'BET'; - break; - case POINTS_DEPOSITED: - $points_var = 'DEPOSIT'; - break; - case POINTS_PAID: - $points_var = 'PAY'; - break; - } - - $mark_ary = $this->request->variable('mark', array(0)); - - if (sizeof($mark_ary) == 0) - { - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $cash = $this->request->variable('cash', false); - $newvalue_ary = $this->request->variable('newvalue', array(0.00)); - if (sizeof($newvalue_ary) == 0) - { - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - $newvalue_ary[] = 1.00 * str_replace (",", ".", $this->request->variable('newvalue' . $mark_ary[$i], '0.00')); - } - } - if (confirm_box(true)) - { - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - if ($newvalue_ary[$i] <> 0) - { - $points_ary[] = array('user_id' => $mark_ary[$i], 'win' => $newvalue_ary[$i]); - } - } - $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; - if (sizeof($points_ary) > 0) - { - set_footb_points($type, $season, $league, $matchday, $points_ary, $cash); - } - trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . (sizeof($points_ary) == 1 ? '' : 'S')], sizeof($points_ary)) . adm_back_link($back_link)); - - } - else - { - confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( - 'mark' => $mark_ary, - 'start' => $start, - 'cash' => $cash, - 'newvalue' => $newvalue_ary, - 's' => $season, - 'l' => $league, - 'm' => $matchday, - 't' => $type, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'cancel': - switch ($type) - { - case POINTS_BET: - $points_var .= 'CANCEL_BET'; - break; - case POINTS_DEPOSITED: - $points_var .= 'CANCEL_DEPOSIT'; - break; - case POINTS_PAID: - $points_var .= 'CANCEL_PAY'; - break; - } - - $mark_ary = $this->request->variable('mark', array(0.00)); - - if (sizeof($mark_ary) == 0) - { - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $cash = $this->request->variable('cash', false); - if (confirm_box(true)) - { - $count_updates = 0; - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - $curr_user = $mark_ary[$i]; - if ($cash) - { - $sql = 'SELECT * - FROM ' . FOOTB_POINTS . " AS p - WHERE season = $season - AND league = $league - AND user_id = $curr_user - AND points_type = $type - AND cash = 1"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - if ($type == POINTS_BET OR $type == POINTS_PAID) - { - $functions_points->add_points($curr_user, round($row['points'],2)); - } - if ($type == POINTS_DEPOSITED) - { - $functions_points->substract_points($curr_user, round($row['points'],2)); - } - } - $db->sql_freeresult($result); - - } - $sql = 'DELETE FROM ' . FOOTB_POINTS . " - WHERE season = $season - AND league = $league - AND user_id = $curr_user - AND points_type = $type"; - $result = $db->sql_query($sql); - $count_updates += $db->sql_affectedrows(); - } - $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; - trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) . adm_back_link($back_link)); - } - else - { - confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( - 'mark' => $mark_ary, - 'start' => $start, - 'cash' => $cash, - 's' => $season, - 'l' => $league, - 't' => $type, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'carryover': - - if ($type <> POINTS_PAID) - { - trigger_error($user->lang['NO_VALID_CALL'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $points_var .= 'CARRYOVER_PAY'; - $bet_points = $league_info['bet_points']; - $league_info_next = league_info($season + 1, $league); - if (sizeof($league_info_next) > 0) - { - $bet_points = $league_info_next['bet_points']; - } - - $mark_ary = $this->request->variable('mark', array(0)); - - if (sizeof($mark_ary) == 0) - { - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $newvalue_ary = $this->request->variable('newvalue', array(0.00)); - if (sizeof($newvalue_ary) == 0) - { - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - $newvalue_ary[] = 1.00 * str_replace (",", ".", $this->request->variable('newvalue' . $mark_ary[$i], '0.00')); - } - } - if (confirm_box(true)) - { - $count_updates = 0; - for ($i = 0; $i < sizeof($mark_ary); $i++) - { - $curr_user = $mark_ary[$i]; - $carryover = ($newvalue_ary[$i] >= $bet_points) ? $bet_points : $newvalue_ary[$i]; - if ($carryover > 0) - { - // Payout old season - $points_comment = sprintf($user->lang['CARRYOVER_NEW_SEASON']); - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $matchday, - 'points_type' => POINTS_PAID, - 'user_id' => (int) $curr_user, - 'points' => round($carryover,2), - 'points_comment'=> $points_comment, - 'cash' => 1, - ); - $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - // Deposit new season - $points_comment = sprintf($user->lang['CARRYOVER_OLD_SEASON']); - $sql_ary = array( - 'season' => (int) $season + 1, - 'league' => (int) $league, - 'matchday' => 1, - 'points_type' => POINTS_DEPOSITED, - 'user_id' => (int) $curr_user, - 'points' => round($carryover,2), - 'points_comment'=> $points_comment, - 'cash' => 1, - ); - $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - $count_updates++; - } - } - $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; - trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) . adm_back_link($back_link)); - } - else - { - confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( - 'mark' => $mark_ary, - 'start' => $start, - 'newvalue' => $newvalue_ary, - 's' => $season, - 'l' => $league, - 'm' => $matchday, - 't' => $type, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'list': - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $bet_points = $league_info['bet_points']; - - - switch ($type) - { - case POINTS_BET: - $page_type = sprintf($user->lang['DEBIT_BET']); - $page_type_explain = sprintf($user->lang['DEBIT_BET_EXPLAIN']); - $this->page_title = 'BET_POINTS'; - $target = sprintf($user->lang['BET_POINTS']); - $actual = sprintf($user->lang['BOOKED']); - $sum_target = "$bet_points AS target,"; - $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS actual,'; - $new_value = $bet_points . ' - SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS new_value'; - $options = array('book' => 'BET', 'cancel' => 'CANCEL_BET'); - break; - case POINTS_DEPOSITED: - $page_type = sprintf($user->lang['BET_DEPOSIT']); - $page_type_explain = sprintf($user->lang['BET_DEPOSIT_EXPLAIN']); - $this->page_title = 'DEPOSITED'; - $target = sprintf($user->lang['BET_POINTS']); - $actual = sprintf($user->lang['DEPOSITED']); - $sum_target = "$bet_points AS target,"; - $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_DEPOSITED . ', p.points, 0.00)) AS actual,'; - $new_value = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)) > 0, - SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)), 0.00) AS new_value'; - $options = array('book' => 'DEPOSITED', 'cancel' => 'CANCEL_DEPOSITED'); - break; - case POINTS_PAID: - $page_type = sprintf($user->lang['PAY_WINS']); - $page_type_explain = sprintf($user->lang['PAY_WINS_EXPLAIN']); - $this->page_title = 'PAID'; - $target = sprintf($user->lang['WINS']); - $actual = sprintf($user->lang['PAID']); - $sum_target = 'SUM(IF(p.points_type IN (' . - POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . - '), p.points, 0.00)) AS target,'; - $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_PAID . ', p.points, 0.00)) AS actual,'; - $new_value = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)) > 0, - SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)), 0.00) AS new_value'; - $options = array('book' => 'PAID', 'cancel' => 'CANCEL_PAID', 'carryover' => 'CARRYOVER_PAID'); - break; - } - - // Total number of league members - $sql = 'SELECT - COUNT(DISTINCT user_id) AS total_members - FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $total_members = (int) $db->sql_fetchfield('total_members'); - $db->sql_freeresult($result); - - $s_action_options = ''; - - foreach ($options as $option => $lang) - { - $s_action_options .= ''; - } - $curr_matchday = (curr_matchday($season, $league) > 0) ? curr_matchday($season, $league) : 1; - $matchday = ($type == 1) ? 1 : $curr_matchday; - - $base_url = $this->u_action . "&action=$action&s=$season&l=$league&m=$matchday&t=$type"; - $pagination = $phpbb_container->get('pagination'); - $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $this->config['football_users_per_page'], $start); - - $template->assign_vars(array( - 'S_LIST' => true, - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_MATCHDAY' => $matchday, - 'S_START' => $start, - 'S_SELECT_MATCHDAY' => ($type == POINTS_BET) ? false : true, - 'S_TYPE' => $type, - 'S_ACTION_OPTIONS' => $s_action_options, - 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, - 'S_VERSION_NO' => $this->config['football_version'], - 'TOTAL_MEMBERS' => ($total_members == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_members), - 'PAGE_NUMBER' => $pagination->on_page($total_members, $this->config['football_users_per_page'], $start), - 'LEAGUE_NAME' => $league_info['league_name']. ' ' . $season_name, - 'PAGE_TYPE' => $page_type, - 'PAGE_TYPE_EXPLAIN' => $page_type_explain, - 'BET_POINTS' => $bet_points, - 'POINTS' => $this->config['points_name'], - 'TARGET' => $target, - 'ACTUAL' => $actual, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season, 'l' => $league)), - 'U_ACTION' => $this->u_action . "&s=$season&l=$league", - 'U_BACK' => $this->u_action. "&s=$season&l=$league", - ) - ); - - $user_points = ''; - if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints') && $this->config['points_enable']) - { - $user_points = 'u.user_points,'; - } - else - { - $user_points = "0,00 AS user_points,"; - } - - // Grab the members - $sql = "SELECT - b.user_id, - u.username, - $user_points - $sum_target - $sum_actual - $new_value - FROM " . FOOTB_BETS . ' AS b - JOIN ' . USERS_TABLE . ' AS u ON (u.user_id = b.user_id) - LEFT JOIN ' . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = $league AND p.user_id = b.user_id) - WHERE b.season = $season - AND b.league = $league - AND b.match_no = 1 - GROUP BY b.user_id - ORDER BY u.username ASC"; - $result = $db->sql_query_limit($sql, $this->config['football_users_per_page'], $start); - - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('member', array( - 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), - 'U_USER_BANK' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season, 'l' => $league, 'u' => $row['user_id'])), - 'USERNAME' => $row['username'], - 'POINTS' => $functions_points->number_format_points($row['user_points']), - 'TARGET' => $functions_points->number_format_points($row['target']), - 'ACTUAL' => $functions_points->number_format_points($row['actual']), - 'NEW_VALUE' => $functions_points->number_format_points($row['new_value']), - 'USER_ID' => $row['user_id'], - ) - ); - } - $db->sql_freeresult($result); - - return; - break; - } - - $options = array('bet' => 'BET', 'deposit' => 'DEPOSITED', 'delete_wins' => 'DELETE_WINS', 'pay' => 'PAID'); - $s_action_options = ''; - - foreach ($options as $option => $lang) - { - $s_action_options .= ''; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season)), - 'U_DLOAD_BANK_OPEN' => $helper->route('football_football_download',array('downside' => 'dload_bank_open', 's' => $season)), - 'S_SEASON' => $season, - 'S_LIST_DEPOSITED' => ($this->config['football_ult_points'] == UP_POINTS) ? false : true, - 'S_LIST_PAID' => ($this->config['football_ult_points'] == UP_POINTS) ? false : true, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_ACTION_OPTIONS' => $s_action_options, - 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Get us all the league banks - $sql = 'SELECT - l.league, - l.league_name, - SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS bet_points, - SUM(IF(p.points_type = ' . POINTS_DEPOSITED . ', p.points, 0.00)) AS deposited, - SUM(IF(p.points_type IN (' . - POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . - '), p.points, 0.00)) AS wins, - SUM(IF(p.points_type = ' . POINTS_PAID . ', p.points, 0.00)) AS paid - FROM ' . FOOTB_LEAGUES . ' AS l - LEFT JOIN ' . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = l.league) - WHERE l.season = $season - GROUP BY l.league - ORDER BY league ASC"; - $result = $db->sql_query($sql); - $rows_leagues = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $row_number = 0; - foreach ($rows_leagues as $row_league) - { - $template->assign_block_vars('leagues', array( - 'LEAGUE' => $row_league['league'], - 'LEAGUE_NAME' => $row_league['league_name'], - 'BET_POINTS' => $functions_points->number_format_points($row_league['bet_points']), - 'DEPOSITED' => $functions_points->number_format_points($row_league['deposited']), - 'WINS' => $functions_points->number_format_points($row_league['wins']), - 'PAID' => $functions_points->number_format_points($row_league['paid']), - 'U_LIST_BET_POINTS' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=1", - 'U_LIST_DEPOSITED' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=2", - 'U_LIST_WINS' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=3", - 'U_LIST_PAID' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=7", - 'U_DLOAD_BANK' => $helper->route('football_football_download', array('downside' => 'dload_bank', 's' => $season, 'l' => $row_league['league'])), - ) - ); - } - } -} - +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_bank'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + if (!$this->config['football_bank']) + { + trigger_error($user->lang['FOOTBALL_BANK_OFF'], E_USER_WARNING); + } + + if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) + { + $user->add_lang_ext('dmzx/ultimatepoints', 'common'); + // Get an instance of the ultimatepoints functions_points + $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); + } + else + { + // Get an instance of the football functions_points + $functions_points = $phpbb_container->get('football.football.core.functions.points'); + } + + $this->tpl_name = 'acp_football_bank'; + $this->page_title = 'ACP_FOOTBALL_BANK_MANAGE'; + + $form_key = 'acp_football_bank'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addmembers'])) ? 'addmembers' : $this->request->variable('action', '')); + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $type = $this->request->variable('t', 0); + $start = $this->request->variable('start', 0); + + // Clear some vars + $league_info = array(); + $error = array(); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + // Grab basic data for season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for league, if league is set and exists + if ($league) + { + $league_info = league_info($season, $league); + } + + // Which page? + switch ($action) + { + case 'bet': + case 'deposit': + case 'delete_wins': + case 'pay': + switch ($action) + { + case 'bet': + $type = POINTS_BET; + $default_matchday = 1; + $select_win = 'l.bet_points - SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS win'; + $points_var = 'BET'; + break; + case 'deposit': + $type = POINTS_DEPOSITED; + $default_matchday = 1; + $select_win = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)) > 0, + SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)), 0.00) AS win'; + $points_var = 'DEPOSIT'; + break; + case 'delete_wins': + $default_matchday = 0; + $points_var = 'DELETE_WIN'; + break; + case 'pay': + $type = POINTS_PAID; + $default_matchday = 1; + $select_win = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)) > 0, + SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)), 0.00) AS win'; + $points_var = 'PAY'; + break; + } + + $mark_ary = $this->request->variable('markleague', array(0)); + $cash = $this->request->variable('cash', false); + + if (sizeof($mark_ary) == 0) + { + trigger_error($user->lang['NO_LEAGUES_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (confirm_box(true)) + { + $count_updates = 0; + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + $league = $mark_ary[$i]; + if ($action == 'delete_wins') + { + rollback_points(POINTS_MATCHDAY, $season, $league, 0, $cash); + rollback_points(POINTS_SEASON, $season, $league, 0, $cash); + rollback_points(POINTS_MOST_HITS, $season, $league, 0, $cash); + rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, 0, $cash); + $sql = 'DELETE FROM ' . FOOTB_POINTS . " + WHERE season = $season + AND league = $league + AND points_type IN (" . POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . ')'; + $result = $db->sql_query($sql); + $count_updates += $db->sql_affectedrows(); + } + else + { + $sql = "SELECT b.user_id, + $select_win + FROM " . FOOTB_BETS . ' AS b + JOIN ' . FOOTB_LEAGUES . " AS l ON (l.season = $season AND l.league = $league ) + LEFT JOIN " . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = $league AND p.user_id = b.user_id) + WHERE b.season = $season + AND b.league = $league + AND b.match_no = 1 + GROUP BY b.season, b.league, b.user_id + HAVING win > 0"; + $result = $db->sql_query($sql); + $points_ary = $db->sql_fetchrowset($result); + if (!$default_matchday) + { + $matchday = (curr_matchday($season, $league) > 0) ? curr_matchday($season, $league) : 1; + } + else + { + $matchday = $default_matchday; + } + if (sizeof($points_ary) > 0) + { + $count_updates += sizeof($points_ary); + set_footb_points($type, $season, $league, $matchday, $points_ary, $cash); + } + } + } + $back_link = $this->u_action . '&s=' . $season; + trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) .adm_back_link($back_link)); + } + else + { + confirm_box(false, sprintf($user->lang['CONFIRM_LEAGUE_' . $points_var]), build_hidden_fields(array( + 'markleague'=> $mark_ary, + 'cash' => $cash, + 's' => $season, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'book': + switch ($type) + { + case POINTS_BET: + $points_var = 'BET'; + break; + case POINTS_DEPOSITED: + $points_var = 'DEPOSIT'; + break; + case POINTS_PAID: + $points_var = 'PAY'; + break; + } + + $mark_ary = $this->request->variable('mark', array(0)); + + if (sizeof($mark_ary) == 0) + { + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $cash = $this->request->variable('cash', false); + $newvalue_ary = $this->request->variable('newvalue', array(0.00)); + if (sizeof($newvalue_ary) == 0) + { + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + $newvalue_ary[] = 1.00 * str_replace (",", ".", $this->request->variable('newvalue' . $mark_ary[$i], '0.00')); + } + } + if (confirm_box(true)) + { + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + if ($newvalue_ary[$i] <> 0) + { + $points_ary[] = array('user_id' => $mark_ary[$i], 'win' => $newvalue_ary[$i]); + } + } + $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; + if (sizeof($points_ary) > 0) + { + set_footb_points($type, $season, $league, $matchday, $points_ary, $cash); + } + trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . (sizeof($points_ary) == 1 ? '' : 'S')], sizeof($points_ary)) . adm_back_link($back_link)); + + } + else + { + confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( + 'mark' => $mark_ary, + 'start' => $start, + 'cash' => $cash, + 'newvalue' => $newvalue_ary, + 's' => $season, + 'l' => $league, + 'm' => $matchday, + 't' => $type, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'cancel': + switch ($type) + { + case POINTS_BET: + $points_var .= 'CANCEL_BET'; + break; + case POINTS_DEPOSITED: + $points_var .= 'CANCEL_DEPOSIT'; + break; + case POINTS_PAID: + $points_var .= 'CANCEL_PAY'; + break; + } + + $mark_ary = $this->request->variable('mark', array(0.00)); + + if (sizeof($mark_ary) == 0) + { + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $cash = $this->request->variable('cash', false); + if (confirm_box(true)) + { + $count_updates = 0; + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + $curr_user = $mark_ary[$i]; + if ($cash) + { + $sql = 'SELECT * + FROM ' . FOOTB_POINTS . " AS p + WHERE season = $season + AND league = $league + AND user_id = $curr_user + AND points_type = $type + AND cash = 1"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + if ($type == POINTS_BET OR $type == POINTS_PAID) + { + $functions_points->add_points($curr_user, round($row['points'],2)); + } + if ($type == POINTS_DEPOSITED) + { + $functions_points->substract_points($curr_user, round($row['points'],2)); + } + } + $db->sql_freeresult($result); + + } + $sql = 'DELETE FROM ' . FOOTB_POINTS . " + WHERE season = $season + AND league = $league + AND user_id = $curr_user + AND points_type = $type"; + $result = $db->sql_query($sql); + $count_updates += $db->sql_affectedrows(); + } + $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; + trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) . adm_back_link($back_link)); + } + else + { + confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( + 'mark' => $mark_ary, + 'start' => $start, + 'cash' => $cash, + 's' => $season, + 'l' => $league, + 't' => $type, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'carryover': + + if ($type <> POINTS_PAID) + { + trigger_error($user->lang['NO_VALID_CALL'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $points_var .= 'CARRYOVER_PAY'; + $bet_points = $league_info['bet_points']; + $league_info_next = league_info($season + 1, $league); + if (sizeof($league_info_next) > 0) + { + $bet_points = $league_info_next['bet_points']; + } + + $mark_ary = $this->request->variable('mark', array(0)); + + if (sizeof($mark_ary) == 0) + { + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $newvalue_ary = $this->request->variable('newvalue', array(0.00)); + if (sizeof($newvalue_ary) == 0) + { + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + $newvalue_ary[] = 1.00 * str_replace (",", ".", $this->request->variable('newvalue' . $mark_ary[$i], '0.00')); + } + } + if (confirm_box(true)) + { + $count_updates = 0; + for ($i = 0; $i < sizeof($mark_ary); $i++) + { + $curr_user = $mark_ary[$i]; + $carryover = ($newvalue_ary[$i] >= $bet_points) ? $bet_points : $newvalue_ary[$i]; + if ($carryover > 0) + { + // Payout old season + $points_comment = sprintf($user->lang['CARRYOVER_NEW_SEASON']); + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $matchday, + 'points_type' => POINTS_PAID, + 'user_id' => (int) $curr_user, + 'points' => round($carryover,2), + 'points_comment'=> $points_comment, + 'cash' => 1, + ); + $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + // Deposit new season + $points_comment = sprintf($user->lang['CARRYOVER_OLD_SEASON']); + $sql_ary = array( + 'season' => (int) $season + 1, + 'league' => (int) $league, + 'matchday' => 1, + 'points_type' => POINTS_DEPOSITED, + 'user_id' => (int) $curr_user, + 'points' => round($carryover,2), + 'points_comment'=> $points_comment, + 'cash' => 1, + ); + $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + $count_updates++; + } + } + $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league . '&t=' . $type . '&start=' . $start; + trigger_error(sprintf($user->lang['LEAGUE_' . $points_var . ($count_updates == 1 ? '' : 'S')], $count_updates) . adm_back_link($back_link)); + } + else + { + confirm_box(false, sprintf($user->lang['CONFIRM_' . $points_var]), build_hidden_fields(array( + 'mark' => $mark_ary, + 'start' => $start, + 'newvalue' => $newvalue_ary, + 's' => $season, + 'l' => $league, + 'm' => $matchday, + 't' => $type, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'list': + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + $bet_points = $league_info['bet_points']; + + + switch ($type) + { + case POINTS_BET: + $page_type = sprintf($user->lang['DEBIT_BET']); + $page_type_explain = sprintf($user->lang['DEBIT_BET_EXPLAIN']); + $this->page_title = 'BET_POINTS'; + $target = sprintf($user->lang['BET_POINTS']); + $actual = sprintf($user->lang['BOOKED']); + $sum_target = "$bet_points AS target,"; + $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS actual,'; + $new_value = $bet_points . ' - SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS new_value'; + $options = array('book' => 'BET', 'cancel' => 'CANCEL_BET'); + break; + case POINTS_DEPOSITED: + $page_type = sprintf($user->lang['BET_DEPOSIT']); + $page_type_explain = sprintf($user->lang['BET_DEPOSIT_EXPLAIN']); + $this->page_title = 'DEPOSITED'; + $target = sprintf($user->lang['BET_POINTS']); + $actual = sprintf($user->lang['DEPOSITED']); + $sum_target = "$bet_points AS target,"; + $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_DEPOSITED . ', p.points, 0.00)) AS actual,'; + $new_value = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)) > 0, + SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points, p.points * -1.0)), 0.00) AS new_value'; + $options = array('book' => 'DEPOSITED', 'cancel' => 'CANCEL_DEPOSITED'); + break; + case POINTS_PAID: + $page_type = sprintf($user->lang['PAY_WINS']); + $page_type_explain = sprintf($user->lang['PAY_WINS_EXPLAIN']); + $this->page_title = 'PAID'; + $target = sprintf($user->lang['WINS']); + $actual = sprintf($user->lang['PAID']); + $sum_target = 'SUM(IF(p.points_type IN (' . + POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . + '), p.points, 0.00)) AS target,'; + $sum_actual = 'SUM(IF(p.points_type = ' . POINTS_PAID . ', p.points, 0.00)) AS actual,'; + $new_value = 'IF(SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)) > 0, + SUM(IF(p.points_type IN (' . POINTS_BET . ',' . POINTS_PAID . ' ), p.points * -1.0, p.points)), 0.00) AS new_value'; + $options = array('book' => 'PAID', 'cancel' => 'CANCEL_PAID', 'carryover' => 'CARRYOVER_PAID'); + break; + } + + // Total number of league members + $sql = 'SELECT + COUNT(DISTINCT user_id) AS total_members + FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $total_members = (int) $db->sql_fetchfield('total_members'); + $db->sql_freeresult($result); + + $s_action_options = ''; + + foreach ($options as $option => $lang) + { + $s_action_options .= ''; + } + $curr_matchday = (curr_matchday($season, $league) > 0) ? curr_matchday($season, $league) : 1; + $matchday = ($type == 1) ? 1 : $curr_matchday; + + $base_url = $this->u_action . "&action=$action&s=$season&l=$league&m=$matchday&t=$type"; + $pagination = $phpbb_container->get('pagination'); + $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $this->config['football_users_per_page'], $start); + + $template->assign_vars(array( + 'S_LIST' => true, + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_MATCHDAY' => $matchday, + 'S_START' => $start, + 'S_SELECT_MATCHDAY' => ($type == POINTS_BET) ? false : true, + 'S_TYPE' => $type, + 'S_ACTION_OPTIONS' => $s_action_options, + 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, + 'S_VERSION_NO' => $this->config['football_version'], + 'TOTAL_MEMBERS' => ($total_members == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_members), + 'PAGE_NUMBER' => $pagination->on_page($total_members, $this->config['football_users_per_page'], $start), + 'LEAGUE_NAME' => $league_info['league_name']. ' ' . $season_name, + 'PAGE_TYPE' => $page_type, + 'PAGE_TYPE_EXPLAIN' => $page_type_explain, + 'BET_POINTS' => $bet_points, + 'POINTS' => $this->config['points_name'], + 'TARGET' => $target, + 'ACTUAL' => $actual, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season, 'l' => $league)), + 'U_ACTION' => $this->u_action . "&s=$season&l=$league", + 'U_BACK' => $this->u_action. "&s=$season&l=$league", + ) + ); + + $user_points = ''; + if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints') && $this->config['points_enable']) + { + $user_points = 'u.user_points,'; + } + else + { + $user_points = "0,00 AS user_points,"; + } + + // Grab the members + $sql = "SELECT + b.user_id, + u.username, + $user_points + $sum_target + $sum_actual + $new_value + FROM " . FOOTB_BETS . ' AS b + JOIN ' . USERS_TABLE . ' AS u ON (u.user_id = b.user_id) + LEFT JOIN ' . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = $league AND p.user_id = b.user_id) + WHERE b.season = $season + AND b.league = $league + AND b.match_no = 1 + GROUP BY b.user_id + ORDER BY u.username ASC"; + $result = $db->sql_query_limit($sql, $this->config['football_users_per_page'], $start); + + while ($row = $db->sql_fetchrow($result)) + { + $template->assign_block_vars('member', array( + 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), + 'U_USER_BANK' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season, 'l' => $league, 'u' => $row['user_id'])), + 'USERNAME' => $row['username'], + 'POINTS' => $functions_points->number_format_points($row['user_points']), + 'TARGET' => $functions_points->number_format_points($row['target']), + 'ACTUAL' => $functions_points->number_format_points($row['actual']), + 'NEW_VALUE' => $functions_points->number_format_points($row['new_value']), + 'USER_ID' => $row['user_id'], + ) + ); + } + $db->sql_freeresult($result); + + return; + break; + } + + $options = array('bet' => 'BET', 'deposit' => 'DEPOSITED', 'delete_wins' => 'DELETE_WINS', 'pay' => 'PAID'); + $s_action_options = ''; + + foreach ($options as $option => $lang) + { + $s_action_options .= ''; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bank', 's' => $season)), + 'U_DLOAD_BANK_OPEN' => $helper->route('football_football_download',array('downside' => 'dload_bank_open', 's' => $season)), + 'S_SEASON' => $season, + 'S_LIST_DEPOSITED' => ($this->config['football_ult_points'] == UP_POINTS) ? false : true, + 'S_LIST_PAID' => ($this->config['football_ult_points'] == UP_POINTS) ? false : true, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_ACTION_OPTIONS' => $s_action_options, + 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Get us all the league banks + $sql = 'SELECT + l.league, + l.league_name, + SUM(IF(p.points_type = ' . POINTS_BET . ', p.points, 0.00)) AS bet_points, + SUM(IF(p.points_type = ' . POINTS_DEPOSITED . ', p.points, 0.00)) AS deposited, + SUM(IF(p.points_type IN (' . + POINTS_MATCHDAY . ',' . POINTS_SEASON . ',' . POINTS_MOST_HITS . ',' . POINTS_MOST_HITS_AWAY . + '), p.points, 0.00)) AS wins, + SUM(IF(p.points_type = ' . POINTS_PAID . ', p.points, 0.00)) AS paid + FROM ' . FOOTB_LEAGUES . ' AS l + LEFT JOIN ' . FOOTB_POINTS . " AS p ON (p.season = $season AND p.league = l.league) + WHERE l.season = $season + GROUP BY l.league + ORDER BY league ASC"; + $result = $db->sql_query($sql); + $rows_leagues = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + $row_number = 0; + foreach ($rows_leagues as $row_league) + { + $template->assign_block_vars('leagues', array( + 'LEAGUE' => $row_league['league'], + 'LEAGUE_NAME' => $row_league['league_name'], + 'BET_POINTS' => $functions_points->number_format_points($row_league['bet_points']), + 'DEPOSITED' => $functions_points->number_format_points($row_league['deposited']), + 'WINS' => $functions_points->number_format_points($row_league['wins']), + 'PAID' => $functions_points->number_format_points($row_league['paid']), + 'U_LIST_BET_POINTS' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=1", + 'U_LIST_DEPOSITED' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=2", + 'U_LIST_WINS' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=3", + 'U_LIST_PAID' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'] . "&t=7", + 'U_DLOAD_BANK' => $helper->route('football_football_download', array('downside' => 'dload_bank', 's' => $season, 'l' => $row_league['league'])), + ) + ); + } + } +} + ?> \ No newline at end of file diff --git a/acp/bets_module.php b/acp/bets_module.php index 164b3e4..c0e1e81 100644 --- a/acp/bets_module.php +++ b/acp/bets_module.php @@ -1,753 +1,751 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_bets'); - - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; - if(!function_exists('season_info')) - { - include($this->ext_football_path . 'includes/functions.' . $phpEx); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->ext_football_path . 'includes/constants.' . $phpEx); - } - - - if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) - { - //$this->user->add_lang_ext('football/football', 'modules/points'); - // Get an instance of the ultimatepoints functions_points - $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); - } - - $this->tpl_name = 'acp_football_bets'; - $this->page_title = 'ACP_FOOTBALL_BETS_MANAGE'; - - $form_key = 'acp_football_bets'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['bet'])) ? 'bet' : $this->request->variable('action', ''); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $user_id = $this->request->variable('u', 0); - - // Clear some vars - $success = array(); - - // Grab current season - $curr_season = curr_season(); - if (!$season) - { - $season = $curr_season; - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = current_league($season); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $matches_matchday = $row['matches_on_matchday']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for select matchday - if (!$matchday) - { - $matchday = curr_matchday($season, $league); - } - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $matchday_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - if ($selected <> '') - { - $matchday_name = $day_name; - if ($matches_matchday) - { - $matches_on_matchday = $matches_matchday; - } - else - { - $matches_on_matchday = $row['matches']; - } - } - } - $db->sql_freeresult($result); - if ($matchday_options == '') - { - trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Grab basic data for select user - if (!$user_id) - { - if (user_is_member($user->data['user_id'], $season, $league)) - { - $user_id = $user->data['user_id']; - } - } - $user_options = ''; - $sql = 'SELECT - DISTINCT u.user_id, - u.username - FROM ' . FOOTB_BETS . ' AS w - LEFT JOIN ' . USERS_TABLE . " AS u ON (u.user_id = w.user_id) - WHERE season = $season - AND league = $league - ORDER BY LOWER(u.username) ASC"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - if (!$user_id) - { - $selected = ' selected="selected"'; - $user_id = $row['user_id']; - - } - else - { - $selected = ($user_id && $row['user_id'] == $user_id) ? ' selected="selected"' : ''; - } - $user_options .= ''; - if ($selected <> '') - { - $user_name = $row['username']; - } - } - $db->sql_freeresult($result); - - switch($action) - { - case 'bet': - { - if ($season < $curr_season) - { - trigger_error("Diese Saison kann nicht mehr gespeichert werden!", E_USER_WARNING); - } - $sqlopen = 'SELECT * - FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday"; - $resultopen = $db->sql_query($sqlopen); - $count_matches = 0; - $count_updates = 0; - while( $row = $db->sql_fetchrow($resultopen)) - { - $match_no = $row['match_no']; - $goalsh = $this->request->variable('goalsh' . $match_no, 'nv'); - $goalsg = $this->request->variable('goalsg' . $match_no, 'nv'); - if ($goalsh != 'nv' AND $goalsg != 'nv') - { - if(($goalsh != '') AND ($goalsg != '')) - { - if(is_numeric($goalsh) AND is_numeric($goalsg) AND $goalsh >= 0 AND $goalsg >= 0) - { - if (0 == $count_matches) - { - $sameh = $goalsh; - $sameg = $goalsg; - $same = 1; - } - else - { - if ($goalsh != $sameh OR $goalsg != $sameg) - $same = 0; - } - $sql = 'SELECT * - FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND match_no = $match_no - AND user_id = $user_id"; - $result = $db->sql_query($sql); - $row2 = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - if(!$row2) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'match_no' => (int) $match_no, - 'user_id' => (int) $user_id, - 'goals_home' => (int) $goalsh, - 'goals_guest' => (int) $goalsg, - 'bet_time' => time(), - ); - $sql = 'INSERT INTO ' . FOOTB_BETS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - $count_updates++; - } - else - { - if($row2['goals_home'] != $goalsh OR $row2['goals_guest'] != $goalsg) - { - $sql_ary = array( - 'goals_home' => (int) $goalsh, - 'goals_guest' => (int) $goalsg, - 'bet_time' => time(), - ); - $sql = 'UPDATE ' . FOOTB_BETS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league - AND match_no = $match_no - AND user_id = $user_id"; - $db->sql_query($sql); - $count_updates++; - } - } - $count_matches++; - $lastmatch_no = $match_no; - } - } - else - { - // Goals unset - $sql_ary = array( - 'goals_home' => '', - 'goals_guest' => '', - 'bet_time' => time(), - ); - $sql = 'UPDATE ' . FOOTB_BETS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league - AND match_no = $match_no - AND user_id = $user_id"; - $db->sql_query($sql); - } - } - } - if ($count_updates > 0) - { - if ($same AND ($count_matches > 6) AND $this->config['football_same_allowed'] == 0) - { - $sql_ary = array( - 'goals_home' => (int) $goalsh + 1, - 'bet_time' => time(), - ); - $sql = 'UPDATE ' . FOOTB_BETS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league - AND match_no = $lastmatch_no - AND user_id = $user_id"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['SAMESAVED'], $count_updates); - } - else - { - if ($count_updates == 1) - { - $success[] = sprintf($user->lang['BETSAVED']); - } - else - { - $success[] = sprintf($user->lang['BETSSAVED'], $count_updates); - } - } - } - else - { - $success[] = sprintf($user->lang['NO_BETS_SAVED']); - } - $db->sql_freeresult($resultopen); - - // extra bets - $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND matchday = $matchday"; - $resultextra = $db->sql_query($sql); - $count_extra_updates = 0; - while( $row = $db->sql_fetchrow($resultextra)) - { - $extra_no = $row['extra_no']; - $extra_bet = $this->request->variable('extra' . $extra_no, 'nv'); - if ($extra_bet != 'nv') - { - if ($row['question_type'] == 5 && !is_numeric($extra_bet)) - { - $extra_bet = ''; - } - if ($extra_bet != '') - { - $sql = 'SELECT * FROM ' . FOOTB_EXTRA_BETS . " WHERE season = $season AND league = $league AND extra_no = $extra_no and user_id = $user_id"; - $result = $db->sql_query($sql); - $row2 = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - if(!$row2) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'extra_no' => (int) $extra_no, - 'user_id' => (int) $user_id, - 'bet' => $extra_bet, - 'bet_points' => 0, - ); - $sql = 'INSERT INTO ' . FOOTB_EXTRA_BETS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - else - { - $sql_ary = array( - 'bet' => $extra_bet, - ); - $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND extra_no = $extra_no AND user_id = $user_id"; - $db->sql_query($sql); - } - $count_extra_updates++; - } - else - { - // extra bet unset - $sql_ary = array( - 'bet' => '', - ); - $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND extra_no = $extra_no AND user_id = $user_id"; - $db->sql_query($sql); - } - } - } - if ($count_extra_updates) - { - $success[] = sprintf($user->lang['EXTRA_BET' . (($count_extra_updates == 1) ? '' : 'S') . '_SAVED'], $count_extra_updates); - } - $league_info = league_info($season, $league); - $cash = $this->request->variable('cash', false); - save_ranking_matchday($season, $league, $matchday, $cash); - } - break; - } - - $data_group = false; - $matchnumber = 0; - $lang_dates = $user->lang['datetime']; - - // Calculate matches and bets of matchday - $sql = "SELECT - s.league, - s.match_no, - s.matchday, - s.status, - s.group_id, - s.formula_home, - s.formula_guest, - v1.team_symbol AS logo_home, - v2.team_symbol AS logo_guest, - v1.team_id AS hid, - v2.team_id AS gid, - v1.team_name AS hname, - v2.team_name AS gname, - w.bet_time, - w.goals_home AS bet_home, - w.goals_guest AS bet_guest, - s.goals_home, - s.goals_guest, - CONCAT( - CASE DATE_FORMAT(s.match_datetime,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(s.match_datetime,' %d.%m. %H:%i') - ) AS match_time - FROM " . FOOTB_MATCHES . ' AS s - INNER JOIN ' . FOOTB_BETS . " AS w ON (w.season = s.season AND w.league = s.league AND w.match_no = s.match_no AND w.user_id = $user_id) - LEFT JOIN " . FOOTB_TEAMS . ' AS v1 ON (v1.season = s.season AND v1.league = s.league AND v1.team_id = s.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS v2 ON (v2.season = s.season AND v2.league = s.league AND v2.team_id = s.team_id_guest) - WHERE s.season = $season - AND s.league = $league - AND s.matchday = $matchday - GROUP BY s.match_no - ORDER BY s.match_datetime ASC, s.match_no ASC"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $matchnumber++ ; - $class = (!($matchnumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $display_link = true; - - if (0 == $row['hid']) - { - $display_link = false; - $home_info = get_team($season, $league, $row['match_no'], 'team_id_home', $row['formula_home']); - $home_in_array = explode("#",$home_info); - $homelogo = $home_in_array[0]; - $homeid = $home_in_array[1]; - $homename = $home_in_array[2]; - } - else - { - $homelogo = $row['logo_home']; - $homeid = $row['hid']; - $homename = $row['hname']; - } - - if (0 == $row['gid']) - { - $display_link = false; - $guest_info = get_team($season, $league, $row['match_no'], 'team_id_guest', $row['formula_guest']); - $guest_in_array = explode("#",$guest_info); - $guestlogo = $guest_in_array[0]; - $guestid = $guest_in_array[1]; - $guestname = $guest_in_array[2]; - } - else - { - $guestlogo = $row['logo_guest']; - $guestid = $row['gid']; - $guestname = $row['gname']; - } - - if ($homelogo <> '') - { - $logoH = "ext_football_path . 'images/flags/' . $homelogo . "\" alt=\"" . $homelogo . "\" width=\"28\" height=\"28\"/>" ; - } - else - { - $logoH = "ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ; - } - - if ($guestlogo <> '') - { - $logoG = "ext_football_path . 'images/flags/' . $guestlogo . "\" alt=\"" . $guestlogo . "\" width=\"28\" height=\"28\"/>" ; - } - else - { - $logoG = "ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ; - } - - if ($row['status'] == -1) - { - $delivertag = "*"; - } - else - { - if ($row['status'] == -2) - { - $delivertag = "**"; - } - else - { - $delivertag = ''; - } - } - - if ($row['group_id'] == '') - { - $group_id = ' '; - } - else - { - $data_group = true; - $group_id = $row['group_id']; - } - - $template->assign_block_vars('bet_edit', array( - 'ROW_CLASS' => $class, - 'LEAGUE_ID' => $row['league'], - 'MATCH_NUMBER' => $row['match_no'], - 'MATCHDAY' => $row['matchday'], - 'STATUS' => $row['status'], - 'MATCH_TIME' => $row['match_time'], - 'GROUP' => $group_id, - 'HOME_ID' => $homeid, - 'GUEST_ID' => $guestid, - 'LOGO_HOME' => $logoH, - 'LOGO_GUEST' => $logoG, - 'HOME_NAME' => $homename, - 'GUEST_NAME' => $guestname, - 'BET_HOME' => $row['bet_home'], - 'BET_GUEST' => $row['bet_guest'], - 'DELIVERTAG' => $delivertag, - 'GOALS_HOME' => ($row['goals_home'] == '') ? ' ' : $row['goals_home'], - 'GOALS_GUEST' => ($row['goals_guest'] == '') ? ' ' : $row['goals_guest'], - 'BET_TIME' => ($row['bet_time'] == 0) ? '' : $user->format_date($row['bet_time']), - 'DISPLAY_LINK' => $display_link, - ) - ); - } - - // Calculate extra bets of matchday - // Start select team - $sql = 'SELECT - team_id AS option_value, - team_name AS option_name - FROM ' . FOOTB_TEAMS . " - WHERE season = $season - AND league = $league - ORDER BY team_name ASC"; - $result = $db->sql_query($sql); - $option_rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $sql = "SELECT e.*, - eb.bet, - eb.bet_points, - t1.team_name AS result_team, - t2.team_name AS bet_team - FROM " . FOOTB_EXTRA . ' AS e - LEFT JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season AND eb.league = e.league AND eb.extra_no = e.extra_no AND eb.user_id = $user_id) - LEFT JOIN " . FOOTB_TEAMS . ' AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) - LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = e.season AND t2.league = e.league AND t2.team_id = eb.bet) - WHERE e.season = $season - AND e.league = $league - AND e.matchday = $matchday - ORDER BY e.extra_no ASC"; - $result = $db->sql_query($sql); - - $extra_bet = false; - $extra_edit = false; - $extra_results = false; - $extranumber = 0; - - while ($row = $db->sql_fetchrow($result)) - { - $extra_bet = true; - $extranumber++ ; - $row_class = (!($extranumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - - switch($row['question_type']) - { - case '1': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '2': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '3': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '4': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '5': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); - } - break; - default : - { - $display_type = 2; - $eval_title = ''; - } - break; - } - - // edit extra bets - $extra_edit = true; - $bet_extra = ($row['bet_team'] == NULL) ? '' : $row['bet_team']; - - switch($row['question_type']) - { - case '3': - case '4': - { - $option_arr = array(); - for ($i = 65; $i <= 72; $i++) - { - if (strstr($row['question'], chr($i) . ':')) - { - $option_arr[] = array( - 'option_value' => chr($i), - 'option_name' => chr($i), - ); - } - } - if ( sizeof($option_arr) > 1 ) - { - $display_type = 1; - $option_rows = $option_arr; - $bet_extra = $row['bet']; - } - } - break; - } - - $template->assign_block_vars('extra_edit', array( - 'ROW_CLASS' => $row_class, - 'EXTRA_NO' => $row['extra_no'], - 'QUESTION' => $row['question'], - 'EXTRA_POINTS' => $row['extra_points'], - 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), - 'EVALUATION_TITLE' => $eval_title, - 'BET' => ($display_type == 1) ? $bet_extra : $row['bet'], - 'S_DISPLAY_TYPE' => $display_type, - ) - ); - - if ($display_type == 1) - { - $selected = ($row['bet'] == '') ? ' selected="selected"' : ''; - - $template->assign_block_vars('extra_edit.extra_option', array( - 'OPTION_VALUE' => '', - 'OPTION_NAME' => sprintf($user->lang['SELECT']), - 'S_SELECTED' => $selected)); - - foreach ($option_rows as $option_row) - { - $selected = ($row['bet'] && $option_row['option_value'] == $row['bet']) ? ' selected="selected"' : ''; - $template->assign_block_vars('extra_edit.extra_option', array( - 'OPTION_VALUE' => $option_row['option_value'], - 'OPTION_NAME' => $option_row['option_name'], - 'S_SELECTED' => $selected)); - } - } - } - $db->sql_freeresult($result); - - $legend = delivery($season, $league, $matchday); - - $template->assign_vars(array( - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'S_LEGEND' => $legend, - 'S_SUCCESS' => (sizeof($success)) ? true : false, - 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', - 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_MATCHDAY' => $matchday, - 'S_USER' => $user_id, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_MATCHDAY_OPTIONS' => $matchday_options, - 'S_USER_OPTIONS' => $user_options, - 'S_USERS' => ($user_options == '') ? false : true, - 'S_EXTRA_BET' => $extra_bet, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_bets'); + + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; + if(!function_exists('season_info')) + { + include($this->ext_football_path . 'includes/functions.' . $phpEx); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->ext_football_path . 'includes/constants.' . $phpEx); + } + + + if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) + { + //$this->user->add_lang_ext('football/football', 'modules/points'); + // Get an instance of the ultimatepoints functions_points + $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); + } + + $this->tpl_name = 'acp_football_bets'; + $this->page_title = 'ACP_FOOTBALL_BETS_MANAGE'; + + $form_key = 'acp_football_bets'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['bet'])) ? 'bet' : $this->request->variable('action', ''); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $user_id = $this->request->variable('u', 0); + + // Clear some vars + $success = array(); + + // Grab current season + $curr_season = curr_season(); + if (!$season) + { + $season = $curr_season; + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = current_league($season); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $matches_matchday = $row['matches_on_matchday']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for select matchday + if (!$matchday) + { + $matchday = curr_matchday($season, $league); + } + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $matchday_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + if ($selected <> '') + { + $matchday_name = $day_name; + if ($matches_matchday) + { + $matches_on_matchday = $matches_matchday; + } + else + { + $matches_on_matchday = $row['matches']; + } + } + } + $db->sql_freeresult($result); + if ($matchday_options == '') + { + trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Grab basic data for select user + if (!$user_id) + { + if (user_is_member($user->data['user_id'], $season, $league)) + { + $user_id = $user->data['user_id']; + } + } + $user_options = ''; + $sql = 'SELECT + DISTINCT u.user_id, + u.username + FROM ' . FOOTB_BETS . ' AS w + LEFT JOIN ' . USERS_TABLE . " AS u ON (u.user_id = w.user_id) + WHERE season = $season + AND league = $league + ORDER BY LOWER(u.username) ASC"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + if (!$user_id) + { + $selected = ' selected="selected"'; + $user_id = $row['user_id']; + + } + else + { + $selected = ($user_id && $row['user_id'] == $user_id) ? ' selected="selected"' : ''; + } + $user_options .= ''; + if ($selected <> '') + { + $user_name = $row['username']; + } + } + $db->sql_freeresult($result); + + switch($action) + { + case 'bet': + { + if ($season < $curr_season) + { + trigger_error("Diese Saison kann nicht mehr gespeichert werden!", E_USER_WARNING); + } + $sqlopen = 'SELECT * + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday"; + $resultopen = $db->sql_query($sqlopen); + $count_matches = 0; + $count_updates = 0; + while( $row = $db->sql_fetchrow($resultopen)) + { + $match_no = $row['match_no']; + $goalsh = $this->request->variable('goalsh' . $match_no, 'nv'); + $goalsg = $this->request->variable('goalsg' . $match_no, 'nv'); + if ($goalsh != 'nv' AND $goalsg != 'nv') + { + if(($goalsh != '') AND ($goalsg != '')) + { + if(is_numeric($goalsh) AND is_numeric($goalsg) AND $goalsh >= 0 AND $goalsg >= 0) + { + if (0 == $count_matches) + { + $sameh = $goalsh; + $sameg = $goalsg; + $same = 1; + } + else + { + if ($goalsh != $sameh OR $goalsg != $sameg) + $same = 0; + } + $sql = 'SELECT * + FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND match_no = $match_no + AND user_id = $user_id"; + $result = $db->sql_query($sql); + $row2 = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + if(!$row2) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'match_no' => (int) $match_no, + 'user_id' => (int) $user_id, + 'goals_home' => (int) $goalsh, + 'goals_guest' => (int) $goalsg, + 'bet_time' => time(), + ); + $sql = 'INSERT INTO ' . FOOTB_BETS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + $count_updates++; + } + else + { + if($row2['goals_home'] != $goalsh OR $row2['goals_guest'] != $goalsg) + { + $sql_ary = array( + 'goals_home' => (int) $goalsh, + 'goals_guest' => (int) $goalsg, + 'bet_time' => time(), + ); + $sql = 'UPDATE ' . FOOTB_BETS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league + AND match_no = $match_no + AND user_id = $user_id"; + $db->sql_query($sql); + $count_updates++; + } + } + $count_matches++; + $lastmatch_no = $match_no; + } + } + else + { + // Goals unset + $sql_ary = array( + 'goals_home' => '', + 'goals_guest' => '', + 'bet_time' => time(), + ); + $sql = 'UPDATE ' . FOOTB_BETS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league + AND match_no = $match_no + AND user_id = $user_id"; + $db->sql_query($sql); + } + } + } + if ($count_updates > 0) + { + if ($same AND ($count_matches > 6) AND $this->config['football_same_allowed'] == 0) + { + $sql_ary = array( + 'goals_home' => (int) $goalsh + 1, + 'bet_time' => time(), + ); + $sql = 'UPDATE ' . FOOTB_BETS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league + AND match_no = $lastmatch_no + AND user_id = $user_id"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['SAMESAVED'], $count_updates); + } + else + { + if ($count_updates == 1) + { + $success[] = sprintf($user->lang['BETSAVED']); + } + else + { + $success[] = sprintf($user->lang['BETSSAVED'], $count_updates); + } + } + } + else + { + $success[] = sprintf($user->lang['NO_BETS_SAVED']); + } + $db->sql_freeresult($resultopen); + + // extra bets + $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND matchday = $matchday"; + $resultextra = $db->sql_query($sql); + $count_extra_updates = 0; + while( $row = $db->sql_fetchrow($resultextra)) + { + $extra_no = $row['extra_no']; + $extra_bet = $this->request->variable('extra' . $extra_no, 'nv'); + if ($extra_bet != 'nv') + { + if ($row['question_type'] == 5 && !is_numeric($extra_bet)) + { + $extra_bet = ''; + } + if ($extra_bet != '') + { + $sql = 'SELECT * FROM ' . FOOTB_EXTRA_BETS . " WHERE season = $season AND league = $league AND extra_no = $extra_no and user_id = $user_id"; + $result = $db->sql_query($sql); + $row2 = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + if(!$row2) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'extra_no' => (int) $extra_no, + 'user_id' => (int) $user_id, + 'bet' => $extra_bet, + 'bet_points' => 0, + ); + $sql = 'INSERT INTO ' . FOOTB_EXTRA_BETS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + else + { + $sql_ary = array( + 'bet' => $extra_bet, + ); + $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND extra_no = $extra_no AND user_id = $user_id"; + $db->sql_query($sql); + } + $count_extra_updates++; + } + else + { + // extra bet unset + $sql_ary = array( + 'bet' => '', + ); + $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND extra_no = $extra_no AND user_id = $user_id"; + $db->sql_query($sql); + } + } + } + if ($count_extra_updates) + { + $success[] = sprintf($user->lang['EXTRA_BET' . (($count_extra_updates == 1) ? '' : 'S') . '_SAVED'], $count_extra_updates); + } + $league_info = league_info($season, $league); + $cash = $this->request->variable('cash', false); + save_ranking_matchday($season, $league, $matchday, $cash); + } + break; + } + + $data_group = false; + $matchnumber = 0; + $lang_dates = $user->lang['datetime']; + + // Calculate matches and bets of matchday + $sql = "SELECT + s.league, + s.match_no, + s.matchday, + s.status, + s.group_id, + s.formula_home, + s.formula_guest, + v1.team_symbol AS logo_home, + v2.team_symbol AS logo_guest, + v1.team_id AS hid, + v2.team_id AS gid, + v1.team_name AS hname, + v2.team_name AS gname, + w.bet_time, + w.goals_home AS bet_home, + w.goals_guest AS bet_guest, + s.goals_home, + s.goals_guest, + CONCAT( + CASE DATE_FORMAT(s.match_datetime,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(s.match_datetime,' %d.%m. %H:%i') + ) AS match_time + FROM " . FOOTB_MATCHES . ' AS s + INNER JOIN ' . FOOTB_BETS . " AS w ON (w.season = s.season AND w.league = s.league AND w.match_no = s.match_no AND w.user_id = $user_id) + LEFT JOIN " . FOOTB_TEAMS . ' AS v1 ON (v1.season = s.season AND v1.league = s.league AND v1.team_id = s.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS v2 ON (v2.season = s.season AND v2.league = s.league AND v2.team_id = s.team_id_guest) + WHERE s.season = $season + AND s.league = $league + AND s.matchday = $matchday + GROUP BY s.match_no + ORDER BY s.match_datetime ASC, s.match_no ASC"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $matchnumber++ ; + $class = (!($matchnumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $display_link = true; + + if (0 == $row['hid']) + { + $display_link = false; + $home_info = get_team($season, $league, $row['match_no'], 'team_id_home', $row['formula_home']); + $home_in_array = explode("#",$home_info); + $homelogo = $home_in_array[0]; + $homeid = $home_in_array[1]; + $homename = $home_in_array[2]; + } + else + { + $homelogo = $row['logo_home']; + $homeid = $row['hid']; + $homename = $row['hname']; + } + + if (0 == $row['gid']) + { + $display_link = false; + $guest_info = get_team($season, $league, $row['match_no'], 'team_id_guest', $row['formula_guest']); + $guest_in_array = explode("#",$guest_info); + $guestlogo = $guest_in_array[0]; + $guestid = $guest_in_array[1]; + $guestname = $guest_in_array[2]; + } + else + { + $guestlogo = $row['logo_guest']; + $guestid = $row['gid']; + $guestname = $row['gname']; + } + + if ($homelogo <> '') + { + $logoH = "ext_football_path . 'images/flags/' . $homelogo . "\" alt=\"" . $homelogo . "\" width=\"28\" height=\"28\"/>" ; + } + else + { + $logoH = "ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ; + } + + if ($guestlogo <> '') + { + $logoG = "ext_football_path . 'images/flags/' . $guestlogo . "\" alt=\"" . $guestlogo . "\" width=\"28\" height=\"28\"/>" ; + } + else + { + $logoG = "ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ; + } + + if ($row['status'] == -1) + { + $delivertag = "*"; + } + else + { + if ($row['status'] == -2) + { + $delivertag = "**"; + } + else + { + $delivertag = ''; + } + } + + if ($row['group_id'] == '') + { + $group_id = ' '; + } + else + { + $data_group = true; + $group_id = $row['group_id']; + } + + $template->assign_block_vars('bet_edit', array( + 'ROW_CLASS' => $class, + 'LEAGUE_ID' => $row['league'], + 'MATCH_NUMBER' => $row['match_no'], + 'MATCHDAY' => $row['matchday'], + 'STATUS' => $row['status'], + 'MATCH_TIME' => $row['match_time'], + 'GROUP' => $group_id, + 'HOME_ID' => $homeid, + 'GUEST_ID' => $guestid, + 'LOGO_HOME' => $logoH, + 'LOGO_GUEST' => $logoG, + 'HOME_NAME' => $homename, + 'GUEST_NAME' => $guestname, + 'BET_HOME' => $row['bet_home'], + 'BET_GUEST' => $row['bet_guest'], + 'DELIVERTAG' => $delivertag, + 'GOALS_HOME' => ($row['goals_home'] == '') ? ' ' : $row['goals_home'], + 'GOALS_GUEST' => ($row['goals_guest'] == '') ? ' ' : $row['goals_guest'], + 'BET_TIME' => ($row['bet_time'] == 0) ? '' : $user->format_date($row['bet_time']), + 'DISPLAY_LINK' => $display_link, + ) + ); + } + + // Calculate extra bets of matchday + // Start select team + $sql = 'SELECT + team_id AS option_value, + team_name AS option_name + FROM ' . FOOTB_TEAMS . " + WHERE season = $season + AND league = $league + ORDER BY team_name ASC"; + $result = $db->sql_query($sql); + $option_rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + $sql = "SELECT e.*, + eb.bet, + eb.bet_points, + t1.team_name AS result_team, + t2.team_name AS bet_team + FROM " . FOOTB_EXTRA . ' AS e + LEFT JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season AND eb.league = e.league AND eb.extra_no = e.extra_no AND eb.user_id = $user_id) + LEFT JOIN " . FOOTB_TEAMS . ' AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) + LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = e.season AND t2.league = e.league AND t2.team_id = eb.bet) + WHERE e.season = $season + AND e.league = $league + AND e.matchday = $matchday + ORDER BY e.extra_no ASC"; + $result = $db->sql_query($sql); + + $extra_bet = false; + $extra_edit = false; + $extra_results = false; + $extranumber = 0; + + while ($row = $db->sql_fetchrow($result)) + { + $extra_bet = true; + $extranumber++ ; + $row_class = (!($extranumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + + switch($row['question_type']) + { + case '1': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '2': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '3': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '4': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '5': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); + } + break; + default : + { + $display_type = 2; + $eval_title = ''; + } + break; + } + + // edit extra bets + $extra_edit = true; + $bet_extra = ($row['bet_team'] == NULL) ? '' : $row['bet_team']; + + switch($row['question_type']) + { + case '3': + case '4': + { + $option_arr = array(); + for ($i = 65; $i <= 72; $i++) + { + if (strstr($row['question'], chr($i) . ':')) + { + $option_arr[] = array( + 'option_value' => chr($i), + 'option_name' => chr($i), + ); + } + } + if ( sizeof($option_arr) > 1 ) + { + $display_type = 1; + $option_rows = $option_arr; + $bet_extra = $row['bet']; + } + } + break; + } + + $template->assign_block_vars('extra_edit', array( + 'ROW_CLASS' => $row_class, + 'EXTRA_NO' => $row['extra_no'], + 'QUESTION' => $row['question'], + 'EXTRA_POINTS' => $row['extra_points'], + 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), + 'EVALUATION_TITLE' => $eval_title, + 'BET' => ($display_type == 1) ? $bet_extra : $row['bet'], + 'S_DISPLAY_TYPE' => $display_type, + ) + ); + + if ($display_type == 1) + { + $selected = ($row['bet'] == '') ? ' selected="selected"' : ''; + + $template->assign_block_vars('extra_edit.extra_option', array( + 'OPTION_VALUE' => '', + 'OPTION_NAME' => sprintf($user->lang['SELECT']), + 'S_SELECTED' => $selected)); + + foreach ($option_rows as $option_row) + { + $selected = ($row['bet'] && $option_row['option_value'] == $row['bet']) ? ' selected="selected"' : ''; + $template->assign_block_vars('extra_edit.extra_option', array( + 'OPTION_VALUE' => $option_row['option_value'], + 'OPTION_NAME' => $option_row['option_name'], + 'S_SELECTED' => $selected)); + } + } + } + $db->sql_freeresult($result); + + $legend = delivery($season, $league, $matchday); + + $template->assign_vars(array( + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'S_LEGEND' => $legend, + 'S_SUCCESS' => (sizeof($success)) ? true : false, + 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', + 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_MATCHDAY' => $matchday, + 'S_USER' => $user_id, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_MATCHDAY_OPTIONS' => $matchday_options, + 'S_USER_OPTIONS' => $user_options, + 'S_USERS' => ($user_options == '') ? false : true, + 'S_EXTRA_BET' => $extra_bet, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + } +} ?> \ No newline at end of file diff --git a/acp/extra_module.php b/acp/extra_module.php index 627d6b2..7cd2ab0 100644 --- a/acp/extra_module.php +++ b/acp/extra_module.php @@ -1,463 +1,461 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_extra'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_extra'; - $this->page_title = 'ACP_FOOTBALL_EXTRA_MANAGE'; - - $form_key = 'acp_football_extra'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['remove'])) ? 'remove' : $this->request->variable('action', '')); - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('matchday', 0); - $matchday_eval = $this->request->variable('matchday_eval', 0); - $extra_no = $this->request->variable('e', 0); - $update = (isset($_POST['update'])) ? true : false; - - // Clear some vars - $extra_row = array(); - $error = array(); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = first_league($season, false); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for extra bets, if extra bet is set and exists - if ($extra_no) - { - $sql = 'SELECT * - FROM ' . FOOTB_EXTRA . " - WHERE season = $season - AND league = $league - AND extra_no = $extra_no"; - $result = $db->sql_query($sql); - $extra_row = $db->sql_fetchrow($result); - $existing_extra = sizeof($extra_row); - $db->sql_freeresult($result); - } - - $db->sql_freeresult($result); - - // Which page? - switch ($action) - { - case 'delete': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (!$extra_no) - { - trigger_error($user->lang['NO_EXTRA'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['EXTRA_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Delete extra - $sql = 'DELETE FROM ' . FOOTB_EXTRA . " - WHERE season = $season AND league = $league AND extra_no = $extra_no"; - $db->sql_query($sql); - - // Delete extra bets - $sql = 'DELETE FROM ' . FOOTB_EXTRA_BETS . " - WHERE season = $season - AND league = $league - AND extra_no = $extra_no"; - $db->sql_query($sql); - - trigger_error($user->lang['EXTRA_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - confirm_box(false, sprintf($user->lang['EXTRA_CONFIRM_DELETE'], $extra_row['question'], $league, $season), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 'e' => $extra_no, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add': - $sql = "SELECT - max(extra_no) AS max_extra_no - FROM " . FOOTB_EXTRA . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $row_extra = $db->sql_fetchrow($result); - $existing_extra = sizeof($row_extra); - $db->sql_freeresult($result); - $extra_no = ($existing_extra) ? $row_extra['max_extra_no'] + 1 : 1; - $extra_row['extra_no'] = $extra_no; - $extra_row['question_type'] = $this->request->variable('question_type', 3); - $extra_row['question'] = utf8_normalize_nfc($this->request->variable('question', '', true)); - $extra_row['matchday'] = $this->request->variable('matchday', 0); - $extra_row['matchday_eval'] = $this->request->variable('matchday_eval', 0); - $extra_row['result'] = utf8_normalize_nfc($this->request->variable('result', '')); - $extra_row['extra_points'] = $this->request->variable('extra_points', 0); - $extra_row['extra_status'] = $this->request->variable('extra_status', 0); - // No break for edit add - case 'edit': - $error_msg = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$extra_no) - { - trigger_error($user->lang['NO_EXTRA'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - $matchday = $extra_row['matchday']; - $matchday_eval = $extra_row['matchday_eval']; - - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $matchday_options = ''; - $matchday_eval_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - if ($row['status'] == 0 or $action == 'edit') - { - $selected_matchday = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; - $selected_eval = ($matchday_eval && $row['matchday'] == $matchday_eval) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - $matchday_eval_options .= ''; - } - } - - $question_type_options = ''; - for($i = 1; $i<= 5; $i++) - { - $selected = ($i == $extra_row['question_type']) ? ' selected="selected"' : ''; - $question_type_options .= ''; - } - - $extra_status_options = ''; - for($i = 0; $i<= 3; $i++) - { - $selected = ($i == $extra_row['extra_status']) ? ' selected="selected"' : ''; - $extra_status_options .= ''; - } - - - // Did we submit? - if ($update) - { - $data = array(); - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - $extra_row['extra_no'] = $extra_no; - $extra_row['question_type'] = $this->request->variable('question_type', $extra_row['question_type']); - $extra_row['question'] = $this->request->variable('question', $extra_row['question'], true); - $extra_row['matchday'] = $this->request->variable('matchday', $extra_row['matchday']); - $extra_row['matchday_eval'] = $this->request->variable('matchday_eval', $extra_row['matchday_eval']); - $extra_row['extra_points'] = $this->request->variable('extra_points', $extra_row['extra_points']); - $extra_row['extra_status'] = $this->request->variable('extra_status', $extra_row['extra_status']); - - $data['extra_points'] = (int) $extra_row['extra_points']; - $data['matchday'] = (int) $extra_row['matchday']; - $data['matchday_eval'] = (int) $extra_row['matchday_eval']; - - if ($data['matchday_eval'] < $data['matchday']) - { - $error[] = $user->lang['EVAL_BEFORE_DELIVERY']; - } - - - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'extra_no' => (int) $extra_no, - 'question_type' => (int) $extra_row['question_type'], - 'question' => strlen($extra_row['question']) ? $extra_row['question'] : '', - 'matchday' => (int) $extra_row['matchday'], - 'matchday_eval' => (int) $extra_row['matchday_eval'], - 'result' => $extra_row['result'], - 'extra_points' => (int) $extra_row['extra_points'], - 'extra_status' => (int) $extra_row['extra_status'], - ); - - $var_ary = array( - 'extra_points' => array('num', false, 0, 99), - 'matchday' => array('num', false, 1), - 'matchday_eval' => array('num', false, 1), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - if ($action == 'add') - { - $sql = 'INSERT INTO ' . FOOTB_EXTRA . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . FOOTB_EXTRA . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND extra_no = $extra_no"; - $db->sql_query($sql); - } - trigger_error($user->lang['EXTRA_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $error[] = $user->lang['EXTRA_UPDATE_FAILED']; - $error = array_merge($error, $error_msg); - } - } - } - } - - $u_back = $this->u_action . "&s=$season&l=$league"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_EXTRA' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'S_EDIT_EXTRAS' => ($existing_extra) ? false : true, - 'S_QUESTION_TYPE_OPTIONS' => $question_type_options, - 'S_MATCHDAY_OPTIONS' => $matchday_options, - 'S_MATCHDAY_EVAL_OPTIONS' => $matchday_eval_options, - 'S_EXTRA_STATUS_OPTIONS' => $extra_status_options, - 'S_VERSION_NO' => $this->config['football_version'], - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'EXTRA_NO' => $extra_no, - 'QUESTION_TYPE' => $extra_row['question_type'], - 'QUESTION' => $extra_row['question'], - 'MATCHDAY' => $extra_row['matchday'], - 'MATCHDAY_EVAL' => $extra_row['matchday_eval'], - 'MATCHDAY_OPTION' => $extra_row['matchday'], - 'MATCHDAY_EVAL' => $extra_row['matchday_eval'], - 'RESULT' => $extra_row['result'], - 'EXTRA_POINTS' => $extra_row['extra_points'], - 'EXTRA_STATUS' => $extra_row['extra_status'], - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", - ) - ); - return; - break; - } - - // Check open matchday in league - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - AND status <= 0"; - $result = $db->sql_query($sql); - $open_matchdays = sizeof($db->sql_fetchrowset($result)); - $db->sql_freeresult($result); - - // Get us all the extra - $sql = "SELECT e.*, - m1.matchday_name AS matchday_name, - m2.matchday_name AS matchday_eval_name - FROM " . FOOTB_EXTRA . ' AS e - LEFT JOIN ' . FOOTB_MATCHDAYS . ' AS m1 ON (m1.season = e.season AND m1.league = e.league AND m1.matchday = e.matchday) - LEFT JOIN ' . FOOTB_MATCHDAYS . " AS m2 ON (m2.season = e.season AND m2.league = e.league AND m2.matchday = e.matchday_eval) - WHERE e.season = $season - AND e.league = $league - ORDER BY e.extra_no ASC"; - $result = $db->sql_query($sql); - $rows_extra = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_EXTRA_ADD' => ($open_matchdays) ? true : false, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Check if the user is allowed to delete a extra. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - foreach ($rows_extra as $row_extra) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('extras', array( - 'ROW_CLASS' => $row_class, - 'EXTRA_NO' => $row_extra['extra_no'], - 'QUESTION_TYPE' => $row_extra['question_type'], - 'QUESTION' => $row_extra['question'], - 'MATCHDAY' => (strlen($row_extra['matchday_name']) > 0) ? $row_extra['matchday_name'] : $row_extra['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']), - 'MATCHDAY_EVAL' => (strlen($row_extra['matchday_name']) > 0) ? $row_extra['matchday_eval_name'] : $row_extra['matchday_eval'] . '. ' . sprintf($user->lang['MATCHDAY']), - 'EXTRA_POINTS' => $row_extra['extra_points'], - 'EXTRA_STATUS' => $row_extra['extra_status'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&e=" .$row_extra['extra_no'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&e=" . $row_extra['extra_no'] : '', - ) - ); - } - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_extra'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_extra'; + $this->page_title = 'ACP_FOOTBALL_EXTRA_MANAGE'; + + $form_key = 'acp_football_extra'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['remove'])) ? 'remove' : $this->request->variable('action', '')); + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('matchday', 0); + $matchday_eval = $this->request->variable('matchday_eval', 0); + $extra_no = $this->request->variable('e', 0); + $update = (isset($_POST['update'])) ? true : false; + + // Clear some vars + $extra_row = array(); + $error = array(); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = first_league($season, false); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for extra bets, if extra bet is set and exists + if ($extra_no) + { + $sql = 'SELECT * + FROM ' . FOOTB_EXTRA . " + WHERE season = $season + AND league = $league + AND extra_no = $extra_no"; + $result = $db->sql_query($sql); + $extra_row = $db->sql_fetchrow($result); + $existing_extra = sizeof($extra_row); + $db->sql_freeresult($result); + } + + $db->sql_freeresult($result); + + // Which page? + switch ($action) + { + case 'delete': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (!$extra_no) + { + trigger_error($user->lang['NO_EXTRA'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['EXTRA_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Delete extra + $sql = 'DELETE FROM ' . FOOTB_EXTRA . " + WHERE season = $season AND league = $league AND extra_no = $extra_no"; + $db->sql_query($sql); + + // Delete extra bets + $sql = 'DELETE FROM ' . FOOTB_EXTRA_BETS . " + WHERE season = $season + AND league = $league + AND extra_no = $extra_no"; + $db->sql_query($sql); + + trigger_error($user->lang['EXTRA_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + confirm_box(false, sprintf($user->lang['EXTRA_CONFIRM_DELETE'], $extra_row['question'], $league, $season), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 'e' => $extra_no, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add': + $sql = "SELECT + max(extra_no) AS max_extra_no + FROM " . FOOTB_EXTRA . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $row_extra = $db->sql_fetchrow($result); + $existing_extra = sizeof($row_extra); + $db->sql_freeresult($result); + $extra_no = ($existing_extra) ? $row_extra['max_extra_no'] + 1 : 1; + $extra_row['extra_no'] = $extra_no; + $extra_row['question_type'] = $this->request->variable('question_type', 3); + $extra_row['question'] = utf8_normalize_nfc($this->request->variable('question', '', true)); + $extra_row['matchday'] = $this->request->variable('matchday', 0); + $extra_row['matchday_eval'] = $this->request->variable('matchday_eval', 0); + $extra_row['result'] = utf8_normalize_nfc($this->request->variable('result', '')); + $extra_row['extra_points'] = $this->request->variable('extra_points', 0); + $extra_row['extra_status'] = $this->request->variable('extra_status', 0); + // No break for edit add + case 'edit': + $error_msg = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$extra_no) + { + trigger_error($user->lang['NO_EXTRA'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + $matchday = $extra_row['matchday']; + $matchday_eval = $extra_row['matchday_eval']; + + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $matchday_options = ''; + $matchday_eval_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + if ($row['status'] == 0 or $action == 'edit') + { + $selected_matchday = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; + $selected_eval = ($matchday_eval && $row['matchday'] == $matchday_eval) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + $matchday_eval_options .= ''; + } + } + + $question_type_options = ''; + for($i = 1; $i<= 5; $i++) + { + $selected = ($i == $extra_row['question_type']) ? ' selected="selected"' : ''; + $question_type_options .= ''; + } + + $extra_status_options = ''; + for($i = 0; $i<= 3; $i++) + { + $selected = ($i == $extra_row['extra_status']) ? ' selected="selected"' : ''; + $extra_status_options .= ''; + } + + + // Did we submit? + if ($update) + { + $data = array(); + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + $extra_row['extra_no'] = $extra_no; + $extra_row['question_type'] = $this->request->variable('question_type', $extra_row['question_type']); + $extra_row['question'] = $this->request->variable('question', $extra_row['question'], true); + $extra_row['matchday'] = $this->request->variable('matchday', $extra_row['matchday']); + $extra_row['matchday_eval'] = $this->request->variable('matchday_eval', $extra_row['matchday_eval']); + $extra_row['extra_points'] = $this->request->variable('extra_points', $extra_row['extra_points']); + $extra_row['extra_status'] = $this->request->variable('extra_status', $extra_row['extra_status']); + + $data['extra_points'] = (int) $extra_row['extra_points']; + $data['matchday'] = (int) $extra_row['matchday']; + $data['matchday_eval'] = (int) $extra_row['matchday_eval']; + + if ($data['matchday_eval'] < $data['matchday']) + { + $error[] = $user->lang['EVAL_BEFORE_DELIVERY']; + } + + + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'extra_no' => (int) $extra_no, + 'question_type' => (int) $extra_row['question_type'], + 'question' => strlen($extra_row['question']) ? $extra_row['question'] : '', + 'matchday' => (int) $extra_row['matchday'], + 'matchday_eval' => (int) $extra_row['matchday_eval'], + 'result' => $extra_row['result'], + 'extra_points' => (int) $extra_row['extra_points'], + 'extra_status' => (int) $extra_row['extra_status'], + ); + + $var_ary = array( + 'extra_points' => array('num', false, 0, 99), + 'matchday' => array('num', false, 1), + 'matchday_eval' => array('num', false, 1), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + if ($action == 'add') + { + $sql = 'INSERT INTO ' . FOOTB_EXTRA . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . FOOTB_EXTRA . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND extra_no = $extra_no"; + $db->sql_query($sql); + } + trigger_error($user->lang['EXTRA_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $error[] = $user->lang['EXTRA_UPDATE_FAILED']; + $error = array_merge($error, $error_msg); + } + } + } + } + + $u_back = $this->u_action . "&s=$season&l=$league"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_EXTRA' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'S_EDIT_EXTRAS' => ($existing_extra) ? false : true, + 'S_QUESTION_TYPE_OPTIONS' => $question_type_options, + 'S_MATCHDAY_OPTIONS' => $matchday_options, + 'S_MATCHDAY_EVAL_OPTIONS' => $matchday_eval_options, + 'S_EXTRA_STATUS_OPTIONS' => $extra_status_options, + 'S_VERSION_NO' => $this->config['football_version'], + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'EXTRA_NO' => $extra_no, + 'QUESTION_TYPE' => $extra_row['question_type'], + 'QUESTION' => $extra_row['question'], + 'MATCHDAY' => $extra_row['matchday'], + 'MATCHDAY_EVAL' => $extra_row['matchday_eval'], + 'MATCHDAY_OPTION' => $extra_row['matchday'], + 'MATCHDAY_EVAL' => $extra_row['matchday_eval'], + 'RESULT' => $extra_row['result'], + 'EXTRA_POINTS' => $extra_row['extra_points'], + 'EXTRA_STATUS' => $extra_row['extra_status'], + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", + ) + ); + return; + break; + } + + // Check open matchday in league + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + AND status <= 0"; + $result = $db->sql_query($sql); + $open_matchdays = sizeof($db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + // Get us all the extra + $sql = "SELECT e.*, + m1.matchday_name AS matchday_name, + m2.matchday_name AS matchday_eval_name + FROM " . FOOTB_EXTRA . ' AS e + LEFT JOIN ' . FOOTB_MATCHDAYS . ' AS m1 ON (m1.season = e.season AND m1.league = e.league AND m1.matchday = e.matchday) + LEFT JOIN ' . FOOTB_MATCHDAYS . " AS m2 ON (m2.season = e.season AND m2.league = e.league AND m2.matchday = e.matchday_eval) + WHERE e.season = $season + AND e.league = $league + ORDER BY e.extra_no ASC"; + $result = $db->sql_query($sql); + $rows_extra = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_EXTRA_ADD' => ($open_matchdays) ? true : false, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Check if the user is allowed to delete a extra. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + foreach ($rows_extra as $row_extra) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('extras', array( + 'ROW_CLASS' => $row_class, + 'EXTRA_NO' => $row_extra['extra_no'], + 'QUESTION_TYPE' => $row_extra['question_type'], + 'QUESTION' => $row_extra['question'], + 'MATCHDAY' => (strlen($row_extra['matchday_name']) > 0) ? $row_extra['matchday_name'] : $row_extra['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']), + 'MATCHDAY_EVAL' => (strlen($row_extra['matchday_name']) > 0) ? $row_extra['matchday_eval_name'] : $row_extra['matchday_eval'] . '. ' . sprintf($user->lang['MATCHDAY']), + 'EXTRA_POINTS' => $row_extra['extra_points'], + 'EXTRA_STATUS' => $row_extra['extra_status'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&e=" .$row_extra['extra_no'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&e=" . $row_extra['extra_no'] : '', + ) + ); + } + } +} ?> \ No newline at end of file diff --git a/acp/football_module.php b/acp/football_module.php index 3179038..c4dcb35 100644 --- a/acp/football_module.php +++ b/acp/football_module.php @@ -1,426 +1,424 @@ -add_lang_ext('football/football', 'help_football'); - $user->add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_football'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - $this->phpbb_container = $phpbb_container; - $this->version_check = $this->phpbb_container->get('football.football.version.check'); - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $phpbb_log; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $user->add_lang('acp/board'); - - $action = $this->request->variable('action', ''); - $submit = (isset($_POST['submit'])) ? true : false; - - $form_key = 'acp_football'; - add_form_key($form_key); - - switch ($mode) - { - case 'userguide': - $this->page_title = 'ACP_FOOTBALL_USERGUIDE'; - $this->tpl_name = 'acp_football_userguide'; - - $template->assign_vars(array( - 'S_IN_FOOTBALL_USERGUIDE' => true, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), - 'L_BACK_TO_TOP' => $user->lang['BACK_TO_TOP'], - 'ICON_BACK_TO_TOP' => '' . $user->lang['BACK_TO_TOP'] . '', - 'S_VERSION_NO' => $this->config['football_version'], - )); - - // Pull the array data from the lang pack - foreach ($user->help as $help_ary) - { - if ($help_ary[0] == '--') - { - $template->assign_block_vars('userguide_block', array( - 'BLOCK_TITLE' => $help_ary[1]) - ); - - continue; - } - - $template->assign_block_vars('userguide_block.userguide_row', array( - 'USERGUIDE_QUESTION' => $help_ary[0], - 'USERGUIDE_ANSWER' => $help_ary[1]) - ); - } - return; - break; - case 'settings': - $display_vars = array( - 'title' => 'ACP_FOOTBALL_SETTINGS', - 'vars' => array( - 'legend1' => 'ACP_FOOTBALL_SETTINGS', - 'football_name' => array('lang' => 'FOOTBALL_NAME', 'validate' => 'string', 'type' => 'text:25:25', 'explain' => true), - 'football_disable' => array('lang' => 'DISABLE_FOOTBALL', 'validate' => 'bool', 'type' => 'custom', 'method' => 'football_disable', 'explain' => true), - 'football_disable_msg' => false, - 'football_fullscreen' => array('lang' => 'FOOTBALL_FULLSCREEN','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_header_enable' => array('lang' => 'FOOTBALL_HEADER_ENABLE','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_guest_view' => array('lang' => 'GUEST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_user_view' => array('lang' => 'USER_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_host_timezone' => array('lang' => 'HOST_TIMEZONE', 'validate' => 'string', 'type' => 'select', 'function' => 'phpbb_timezone_select', 'params' => array($template, $user, '{CONFIG_VALUE}', true), 'explain' => true), - 'football_info_display' => array('lang' => 'FOOTBALL_INFO', 'validate' => 'bool', 'type' => 'custom', 'method' => 'football_info', 'explain' => true), - 'football_info' => false, - 'football_win_name' => array('lang' => 'WIN_NAME', 'validate' => 'string', 'type' => 'text:6:6', 'explain' => true), - 'football_code' => array('lang' => 'FOOTBALL_CODE', 'validate' => 'string', 'type' => 'text:25:25', 'explain' => true), - 'football_style' => array('lang' => 'FOOTBALL_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => false), - 'football_override_style' => array('lang' => 'FOOTBALL_OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_update_source' => array('lang' => 'FOOTBALL_UPDATE_SOURCE', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => true), - 'football_update_code' => array('lang' => 'FOOTBALL_UPDATE_CODE', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true), - - 'legend2' => 'GENERAL_SETTINGS', - 'football_left_column_width' => array('lang' => 'LEFT_COLUMN', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'football_right_column_width' => array('lang' => 'RIGHT_COLUMN', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'football_display_ranks' => array('lang' => 'DISPLAY_RANKS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'football_users_per_page' => array('lang' => 'USERS_PAGE', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - - 'legend3' => 'ACP_SUBMIT_CHANGES', - ) - ); - // show the extension version check on Settings page - $this->version_check->check(); - break; - - case 'features': - $display_vars = array( - 'title' => 'ACP_FOOTBALL_FEATURES', - 'vars' => array( - 'legend1' => 'ACP_FOOTBALL_FEATURES', - 'football_founder_delete' => array('lang' => 'FOUNDER_DELETE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_results_at_time' => array('lang' => 'RESULTS_AT_TIME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_win_hits02' => array('lang' => 'WIN_HITS02', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_same_allowed' => array('lang' => 'SAME_ALLOWED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_season_start' => array('lang' => 'FOOTBALL_SEASON_START', 'validate' => 'int', 'type' => 'select', 'method' => 'season_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), - 'football_view_current' => array('lang' => 'VIEW_CURRENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_view_bets' => array('lang' => 'VIEW_BETS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_view_tendencies' => array('lang' => 'VIEW_TENDENCIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_bank' => array('lang' => 'BANK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_ult_points' => array('lang' => 'ULT_POINTS', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_up_method', 'explain' => true), - 'football_ult_points_factor'=> array('lang' => 'ULT_POINTS_FACTOR', 'validate' => 'dec:3:2','type' => 'text:4:10', 'explain' => true), - 'football_remember_enable' => array('lang' => 'FOOTBALL_REMEMBER_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_remember_next_run'=> array('lang' => 'FOOTBALL_REMEMBER_NEXT_RUN','validate' => 'int', 'type' => 'custom', 'method' => 'next_run', 'explain' => true), - - 'legend2' => 'ACP_SUBMIT_CHANGES', - ) - ); - break; - - case 'menu': - $display_vars = array( - 'title' => 'ACP_FOOTBALL_MENU', - 'vars' => array( - 'legend1' => 'ACP_FOOTBALL_MENU', - 'football_breadcrumb' => array('lang' => 'FOOTBALL_BREADCRUMB', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_side' => array('lang' => 'FOOTBALL_SIDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_menu' => array('lang' => 'FOOTBALL_MENU', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'football_menu_link1' => array('lang' => 'MENU_LINK1', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => true), - 'football_menu_desc1' => array('lang' => 'MENU_DESC1', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => true), - 'football_menu_link2' => array('lang' => 'MENU_LINK2', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => false), - 'football_menu_desc2' => array('lang' => 'MENU_DESC2', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => false), - 'football_menu_link3' => array('lang' => 'MENU_LINK3', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => false), - 'football_menu_desc3' => array('lang' => 'MENU_DESC3', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => false), - ) - ); - break; - - default: - trigger_error('NO_MODE', E_USER_ERROR); - break; - } - - if (isset($display_vars['lang'])) - { - $user->add_lang($display_vars['lang']); - } - - $this->new_config = $this->config; - $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; - $error = array(); - - // We validate the complete config if whished - validate_config_vars($display_vars['vars'], $cfg_array, $error); - - if ($submit && !check_form_key($form_key)) - { - $error[] = $user->lang['FORM_INVALID']; - } - // Do not write values if there is an error - if (sizeof($error)) - { - $submit = false; - } - - // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... - foreach ($display_vars['vars'] as $this->config_name => $null) - { - if (!isset($cfg_array[$this->config_name]) || strpos($this->config_name, 'legend') !== false) - { - continue; - } - $this->new_config[$this->config_name] = $this->config_value = $cfg_array[$this->config_name]; - - if ($submit) - { - if ($this->config_name == 'football_ult_points' && $this->config_value) - { - $this->config->set('football_bank', 1); - } - if ($this->config_name == 'football_remember_enable') - { - $day = $this->request->variable('next_run_day', 0); - $month = $this->request->variable('next_run_month', 0); - $year = $this->request->variable('next_run_year', 0); - $hour = $this->request->variable('next_run_hour', 0); - $minute = $this->request->variable('next_run_minute', 0); - - $next_run = mktime($hour, $minute, 0, $month, $day, $year); - $this->config->set('football_remember_next_run', $next_run); - } - $this->config->set($this->config_name, $this->config_value); - } - } - - if ($submit) - { - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTBALL_' . strtoupper($mode)); - - trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); - } - - $this->tpl_name = 'acp_football'; - $this->page_title = $display_vars['title']; - - $template->assign_vars(array( - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), - 'L_TITLE' => $user->lang[$display_vars['title']], - 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], - 'S_ERROR' => (sizeof($error)) ? true : false, - 'ERROR_MSG' => implode('
', $error), - 'U_ACTION' => $this->u_action, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Output relevant page - foreach ($display_vars['vars'] as $this->config_key => $vars) - { - if (!is_array($vars) && strpos($this->config_key, 'legend') === false) - { - continue; - } - - if (strpos($this->config_key, 'legend') !== false) - { - $template->assign_block_vars('options', array( - 'S_LEGEND' => true, - 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars, - ) - ); - - continue; - } - - $type = explode(':', $vars['type']); - - $l_explain = ''; - if ($vars['explain'] && isset($vars['lang_explain'])) - { - $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; - } - else if ($vars['explain']) - { - $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; - } - - $content = build_cfg_template($type, $this->config_key, $this->new_config, $this->config_key, $vars); - - if (empty($content)) - { - continue; - } - - $template->assign_block_vars('options', array( - 'KEY' => $this->config_key, - 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'], - 'S_EXPLAIN' => $vars['explain'], - 'TITLE_EXPLAIN' => $l_explain, - 'CONTENT' => $content, - ) - ); - - unset($display_vars['vars'][$this->config_key]); - } - } - - /** - * Football disable option and message - */ - function football_disable($value, $key) - { - global $user; - - $radio_ary = array(1 => 'YES', 0 => 'NO'); - - return h_radio('config[football_disable]', $radio_ary, $value) . '
'; - } - - /** - * Football info option and message - */ - function football_info($value, $key) - { - global $user; - - $radio_ary = array(1 => 'YES', 0 => 'NO'); - - return h_radio('config[football_info_display]', $radio_ary, $value) . '
'; - } - - /** - * Select ultimate points method - */ - function select_up_method($value, $key = '') - { - global $user, $config; - - $radio_ary = array(UP_NONE => 'UP_NONE', UP_WINS => 'UP_WINS', UP_POINTS => 'UP_POINTS'); - - return h_radio('config[football_ult_points]', $radio_ary, $value, $key); - } - - - function season_select($default = 0) - { - global $user, $db; - - $sql = 'SELECT DISTINCT s.season, s.season_name_short FROM ' . FOOTB_SEASONS . ' AS s - INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) - INNER JOIN ' . FOOTB_MATCHDAYS . ' AS md ON (md.season = s.season AND md.league = l.league) - WHERE 1 - ORDER BY s.season DESC'; - $result = $db->sql_query($sql); - - $selected = (0 == $default) ? ' selected="selected"' : ''; - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($row['season'] == $default) ? ' selected="selected"' : ''; - $season_options .= ''; - } - $db->sql_freeresult($result); - - return $season_options; - } - - /** - * Adjust Cronjob EMail remember next un - */ - function next_run($value, $key = '') - { - global $user, $db; - $next_run = getdate($this->config['football_remember_next_run']); - - // Days - $day_options = ''; - - // Months - $month_options = ''; - - // Years - $year_options = ''; - - // Hours - $hour_options = ''; - - // Minutes - $minute_options = ''; - - - return $user->lang['DAY'] . ': ' . $day_options . ' ' . $user->lang['MONTH'] . ': ' . $month_options . ' ' . $user->lang['YEAR'] . ': ' . - $year_options . ' ' . $user->lang['HOURS'] . ': ' . $hour_options . ' ' . $user->lang['MINUTES'] . ': ' . $minute_options; - - } -} - +add_lang_ext('football/football', 'help_football'); + $user->add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_football'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + $this->phpbb_container = $phpbb_container; + $this->version_check = $this->phpbb_container->get('football.football.version.check'); + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $phpbb_log; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $user->add_lang('acp/board'); + + $action = $this->request->variable('action', ''); + $submit = (isset($_POST['submit'])) ? true : false; + + $form_key = 'acp_football'; + add_form_key($form_key); + + switch ($mode) + { + case 'userguide': + $this->page_title = 'ACP_FOOTBALL_USERGUIDE'; + $this->tpl_name = 'acp_football_userguide'; + + $template->assign_vars(array( + 'S_IN_FOOTBALL_USERGUIDE' => true, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), + 'L_BACK_TO_TOP' => $user->lang['BACK_TO_TOP'], + 'ICON_BACK_TO_TOP' => '' . $user->lang['BACK_TO_TOP'] . '', + 'S_VERSION_NO' => $this->config['football_version'], + )); + + // Pull the array data from the lang pack + foreach ($user->help as $help_ary) + { + if ($help_ary[0] == '--') + { + $template->assign_block_vars('userguide_block', array( + 'BLOCK_TITLE' => $help_ary[1]) + ); + + continue; + } + + $template->assign_block_vars('userguide_block.userguide_row', array( + 'USERGUIDE_QUESTION' => $help_ary[0], + 'USERGUIDE_ANSWER' => $help_ary[1]) + ); + } + return; + break; + case 'settings': + $display_vars = array( + 'title' => 'ACP_FOOTBALL_SETTINGS', + 'vars' => array( + 'legend1' => 'ACP_FOOTBALL_SETTINGS', + 'football_name' => array('lang' => 'FOOTBALL_NAME', 'validate' => 'string', 'type' => 'text:25:25', 'explain' => true), + 'football_disable' => array('lang' => 'DISABLE_FOOTBALL', 'validate' => 'bool', 'type' => 'custom', 'method' => 'football_disable', 'explain' => true), + 'football_disable_msg' => false, + 'football_fullscreen' => array('lang' => 'FOOTBALL_FULLSCREEN','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_header_enable' => array('lang' => 'FOOTBALL_HEADER_ENABLE','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_guest_view' => array('lang' => 'GUEST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_user_view' => array('lang' => 'USER_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_host_timezone' => array('lang' => 'HOST_TIMEZONE', 'validate' => 'string', 'type' => 'select', 'function' => 'phpbb_timezone_select', 'params' => array($template, $user, '{CONFIG_VALUE}', true), 'explain' => true), + 'football_info_display' => array('lang' => 'FOOTBALL_INFO', 'validate' => 'bool', 'type' => 'custom', 'method' => 'football_info', 'explain' => true), + 'football_info' => false, + 'football_win_name' => array('lang' => 'WIN_NAME', 'validate' => 'string', 'type' => 'text:6:6', 'explain' => true), + 'football_code' => array('lang' => 'FOOTBALL_CODE', 'validate' => 'string', 'type' => 'text:25:25', 'explain' => true), + 'football_style' => array('lang' => 'FOOTBALL_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => false), + 'football_override_style' => array('lang' => 'FOOTBALL_OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_update_source' => array('lang' => 'FOOTBALL_UPDATE_SOURCE', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => true), + 'football_update_code' => array('lang' => 'FOOTBALL_UPDATE_CODE', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true), + + 'legend2' => 'GENERAL_SETTINGS', + 'football_left_column_width' => array('lang' => 'LEFT_COLUMN', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'football_right_column_width' => array('lang' => 'RIGHT_COLUMN', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'football_display_ranks' => array('lang' => 'DISPLAY_RANKS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + 'football_users_per_page' => array('lang' => 'USERS_PAGE', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + + 'legend3' => 'ACP_SUBMIT_CHANGES', + ) + ); + // show the extension version check on Settings page + $this->version_check->check(); + break; + + case 'features': + $display_vars = array( + 'title' => 'ACP_FOOTBALL_FEATURES', + 'vars' => array( + 'legend1' => 'ACP_FOOTBALL_FEATURES', + 'football_founder_delete' => array('lang' => 'FOUNDER_DELETE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_results_at_time' => array('lang' => 'RESULTS_AT_TIME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_win_hits02' => array('lang' => 'WIN_HITS02', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_same_allowed' => array('lang' => 'SAME_ALLOWED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_season_start' => array('lang' => 'FOOTBALL_SEASON_START', 'validate' => 'int', 'type' => 'select', 'method' => 'season_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), + 'football_view_current' => array('lang' => 'VIEW_CURRENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_view_bets' => array('lang' => 'VIEW_BETS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_view_tendencies' => array('lang' => 'VIEW_TENDENCIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_bank' => array('lang' => 'BANK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_ult_points' => array('lang' => 'ULT_POINTS', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_up_method', 'explain' => true), + 'football_ult_points_factor'=> array('lang' => 'ULT_POINTS_FACTOR', 'validate' => 'dec:3:2','type' => 'text:4:10', 'explain' => true), + 'football_remember_enable' => array('lang' => 'FOOTBALL_REMEMBER_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_remember_next_run'=> array('lang' => 'FOOTBALL_REMEMBER_NEXT_RUN','validate' => 'int', 'type' => 'custom', 'method' => 'next_run', 'explain' => true), + + 'legend2' => 'ACP_SUBMIT_CHANGES', + ) + ); + break; + + case 'menu': + $display_vars = array( + 'title' => 'ACP_FOOTBALL_MENU', + 'vars' => array( + 'legend1' => 'ACP_FOOTBALL_MENU', + 'football_breadcrumb' => array('lang' => 'FOOTBALL_BREADCRUMB', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_side' => array('lang' => 'FOOTBALL_SIDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_menu' => array('lang' => 'FOOTBALL_MENU', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'football_menu_link1' => array('lang' => 'MENU_LINK1', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => true), + 'football_menu_desc1' => array('lang' => 'MENU_DESC1', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => true), + 'football_menu_link2' => array('lang' => 'MENU_LINK2', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => false), + 'football_menu_desc2' => array('lang' => 'MENU_DESC2', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => false), + 'football_menu_link3' => array('lang' => 'MENU_LINK3', 'validate' => 'string', 'type' => 'text:80:255', 'explain' => false), + 'football_menu_desc3' => array('lang' => 'MENU_DESC3', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => false), + ) + ); + break; + + default: + trigger_error('NO_MODE', E_USER_ERROR); + break; + } + + if (isset($display_vars['lang'])) + { + $user->add_lang($display_vars['lang']); + } + + $this->new_config = $this->config; + $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; + $error = array(); + + // We validate the complete config if whished + validate_config_vars($display_vars['vars'], $cfg_array, $error); + + if ($submit && !check_form_key($form_key)) + { + $error[] = $user->lang['FORM_INVALID']; + } + // Do not write values if there is an error + if (sizeof($error)) + { + $submit = false; + } + + // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... + foreach ($display_vars['vars'] as $this->config_name => $null) + { + if (!isset($cfg_array[$this->config_name]) || strpos($this->config_name, 'legend') !== false) + { + continue; + } + $this->new_config[$this->config_name] = $this->config_value = $cfg_array[$this->config_name]; + + if ($submit) + { + if ($this->config_name == 'football_ult_points' && $this->config_value) + { + $this->config->set('football_bank', 1); + } + if ($this->config_name == 'football_remember_enable') + { + $day = $this->request->variable('next_run_day', 0); + $month = $this->request->variable('next_run_month', 0); + $year = $this->request->variable('next_run_year', 0); + $hour = $this->request->variable('next_run_hour', 0); + $minute = $this->request->variable('next_run_minute', 0); + + $next_run = mktime($hour, $minute, 0, $month, $day, $year); + $this->config->set('football_remember_next_run', $next_run); + } + $this->config->set($this->config_name, $this->config_value); + } + } + + if ($submit) + { + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTBALL_' . strtoupper($mode)); + + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); + } + + $this->tpl_name = 'acp_football'; + $this->page_title = $display_vars['title']; + + $template->assign_vars(array( + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), + 'L_TITLE' => $user->lang[$display_vars['title']], + 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => implode('
', $error), + 'U_ACTION' => $this->u_action, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Output relevant page + foreach ($display_vars['vars'] as $this->config_key => $vars) + { + if (!is_array($vars) && strpos($this->config_key, 'legend') === false) + { + continue; + } + + if (strpos($this->config_key, 'legend') !== false) + { + $template->assign_block_vars('options', array( + 'S_LEGEND' => true, + 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars, + ) + ); + + continue; + } + + $type = explode(':', $vars['type']); + + $l_explain = ''; + if ($vars['explain'] && isset($vars['lang_explain'])) + { + $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; + } + else if ($vars['explain']) + { + $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; + } + + $content = build_cfg_template($type, $this->config_key, $this->new_config, $this->config_key, $vars); + + if (empty($content)) + { + continue; + } + + $template->assign_block_vars('options', array( + 'KEY' => $this->config_key, + 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'], + 'S_EXPLAIN' => $vars['explain'], + 'TITLE_EXPLAIN' => $l_explain, + 'CONTENT' => $content, + ) + ); + + unset($display_vars['vars'][$this->config_key]); + } + } + + /** + * Football disable option and message + */ + function football_disable($value, $key) + { + global $user; + + $radio_ary = array(1 => 'YES', 0 => 'NO'); + + return h_radio('config[football_disable]', $radio_ary, $value) . '
'; + } + + /** + * Football info option and message + */ + function football_info($value, $key) + { + global $user; + + $radio_ary = array(1 => 'YES', 0 => 'NO'); + + return h_radio('config[football_info_display]', $radio_ary, $value) . '
'; + } + + /** + * Select ultimate points method + */ + function select_up_method($value, $key = '') + { + global $user, $config; + + $radio_ary = array(UP_NONE => 'UP_NONE', UP_WINS => 'UP_WINS', UP_POINTS => 'UP_POINTS'); + + return h_radio('config[football_ult_points]', $radio_ary, $value, $key); + } + + + function season_select($default = 0) + { + global $user, $db; + + $sql = 'SELECT DISTINCT s.season, s.season_name_short FROM ' . FOOTB_SEASONS . ' AS s + INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) + INNER JOIN ' . FOOTB_MATCHDAYS . ' AS md ON (md.season = s.season AND md.league = l.league) + WHERE 1 + ORDER BY s.season DESC'; + $result = $db->sql_query($sql); + + $selected = (0 == $default) ? ' selected="selected"' : ''; + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($row['season'] == $default) ? ' selected="selected"' : ''; + $season_options .= ''; + } + $db->sql_freeresult($result); + + return $season_options; + } + + /** + * Adjust Cronjob EMail remember next un + */ + function next_run($value, $key = '') + { + global $user, $db; + $next_run = getdate($this->config['football_remember_next_run']); + + // Days + $day_options = ''; + + // Months + $month_options = ''; + + // Years + $year_options = ''; + + // Hours + $hour_options = ''; + + // Minutes + $minute_options = ''; + + + return $user->lang['DAY'] . ': ' . $day_options . ' ' . $user->lang['MONTH'] . ': ' . $month_options . ' ' . $user->lang['YEAR'] . ': ' . + $year_options . ' ' . $user->lang['HOURS'] . ': ' . $hour_options . ' ' . $user->lang['MINUTES'] . ': ' . $minute_options; + + } +} + ?> \ No newline at end of file diff --git a/acp/ko_module.php b/acp/ko_module.php index a761a73..5b5f41e 100644 --- a/acp/ko_module.php +++ b/acp/ko_module.php @@ -1,257 +1,255 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_ko'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_ko'; - $this->page_title = 'ACP_FOOTBALL_KO_MANAGE'; - - $form_key = 'acp_football_ko'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['update'])) ? 'update' : $this->request->variable('action', ''); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday_from = $this->request->variable('matchday_from', 0); - $matchday_to = $this->request->variable('matchday_to', 0); - $matchday_new = $this->request->variable('matchday_new', 0); - $check_rank = $this->request->variable('check_rank', 0); - $rank = $this->request->variable('rank', 2); - $move_rank = $this->request->variable('move_rank', 3); - $move_league = $this->request->variable('move_league', 0); - $move_matchday = $this->request->variable('move_matchday', 8); - - // Clear some vars - $error = array(); - $success = array(); - - $curr_season = curr_season(); - // Grab current season - if (!$season) - { - $season = $curr_season; - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT - DISTINCT s.* - FROM ' . FOOTB_SEASONS . ' AS s - LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) - WHERE l.league_type = 2 - ORDER BY s.season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab basic data for select league - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . ' - WHERE season = ' . $season . ' - AND league_type = ' . LEAGUE_KO . ' - ORDER BY league ASC'; - $result = $db->sql_query($sql); - - $league_options = ''; - if ($move_league == 0) - { - $league_move_options = ''; - } - else - { - $league_move_options = ''; - } - while ($row = $db->sql_fetchrow($result)) - { - // Grab current league - if (!$league) - { - $league = $row['league']; - } - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $matches_matchday = $row['matches_on_matchday']; - $league_name = $row['league_name']; - } - else - { - $selected_move = ($move_league && $row['league'] == $move_league) ? ' selected="selected"' : ''; - $league_move_options .= ''; - } - } - $db->sql_freeresult($result); - - if (!$league) - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for select matchday - if (!$matchday_from) - { - $matchday_from = curr_matchday($season, $league); - if ($matchday_from > 1) - { - $matchday_from = $matchday_from - 1; - } - } - if (!$matchday_to) - { - $matchday_to = $matchday_from; - } - if (!$matchday_new) - { - $matchday_new = $matchday_to + 1; - } - - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $matchday_from_options = ''; - $matchday_to_options = ''; - $matchday_new_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected_from = ($matchday_from && $row['matchday'] == $matchday_from) ? ' selected="selected"' : ''; - $selected_to = ($matchday_to && $row['matchday'] == $matchday_to) ? ' selected="selected"' : ''; - $selected_new = ($matchday_new && $row['matchday'] == $matchday_new) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_from_options .= ''; - $matchday_to_options .= ''; - $matchday_new_options .= ''; - } - $db->sql_freeresult($result); - if ($matchday_from_options == '') - { - trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Which page? - switch ($action) - { - case 'update': - { - if ($matchday_from > $matchday_to) - { - $error[] = sprintf($user->lang['ERROR_FROM_TO']); - } - if ($matchday_new <= $matchday_to) - { - $error[] = sprintf($user->lang['ERROR_TARGET']); - } - if (!sizeof($error)) - { - if (1 == $check_rank) - { - $success = ko_group_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new, $rank, $move_rank, $move_league, $move_matchday); - } - else - { - $success = ko_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new); - } - trigger_error($success . adm_back_link($this->u_action)); - } - } - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), - 'S_ERROR' => (sizeof($error)) ? true : false, - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'S_SUCCESS' => (sizeof($success)) ? true : false, - 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_MATCHDAY_FROM_OPTIONS'=> $matchday_from_options, - 'S_MATCHDAY_TO_OPTIONS' => $matchday_to_options, - 'S_MATCHDAY_NEW_OPTIONS'=> $matchday_new_options, - 'S_CHECK_RANK' => $check_rank, - 'S_RANK' => $rank, - 'S_MOVE_RANK' => $move_rank, - 'S_MOVE_LEAGUE_OPTIONS' => $league_move_options, - 'S_MOVE_MATCHDAY' => $move_matchday, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_ko'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_ko'; + $this->page_title = 'ACP_FOOTBALL_KO_MANAGE'; + + $form_key = 'acp_football_ko'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['update'])) ? 'update' : $this->request->variable('action', ''); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday_from = $this->request->variable('matchday_from', 0); + $matchday_to = $this->request->variable('matchday_to', 0); + $matchday_new = $this->request->variable('matchday_new', 0); + $check_rank = $this->request->variable('check_rank', 0); + $rank = $this->request->variable('rank', 2); + $move_rank = $this->request->variable('move_rank', 3); + $move_league = $this->request->variable('move_league', 0); + $move_matchday = $this->request->variable('move_matchday', 8); + + // Clear some vars + $error = array(); + $success = array(); + + $curr_season = curr_season(); + // Grab current season + if (!$season) + { + $season = $curr_season; + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT + DISTINCT s.* + FROM ' . FOOTB_SEASONS . ' AS s + LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) + WHERE l.league_type = 2 + ORDER BY s.season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab basic data for select league + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . ' + WHERE season = ' . $season . ' + AND league_type = ' . LEAGUE_KO . ' + ORDER BY league ASC'; + $result = $db->sql_query($sql); + + $league_options = ''; + if ($move_league == 0) + { + $league_move_options = ''; + } + else + { + $league_move_options = ''; + } + while ($row = $db->sql_fetchrow($result)) + { + // Grab current league + if (!$league) + { + $league = $row['league']; + } + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $matches_matchday = $row['matches_on_matchday']; + $league_name = $row['league_name']; + } + else + { + $selected_move = ($move_league && $row['league'] == $move_league) ? ' selected="selected"' : ''; + $league_move_options .= ''; + } + } + $db->sql_freeresult($result); + + if (!$league) + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for select matchday + if (!$matchday_from) + { + $matchday_from = curr_matchday($season, $league); + if ($matchday_from > 1) + { + $matchday_from = $matchday_from - 1; + } + } + if (!$matchday_to) + { + $matchday_to = $matchday_from; + } + if (!$matchday_new) + { + $matchday_new = $matchday_to + 1; + } + + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $matchday_from_options = ''; + $matchday_to_options = ''; + $matchday_new_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected_from = ($matchday_from && $row['matchday'] == $matchday_from) ? ' selected="selected"' : ''; + $selected_to = ($matchday_to && $row['matchday'] == $matchday_to) ? ' selected="selected"' : ''; + $selected_new = ($matchday_new && $row['matchday'] == $matchday_new) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_from_options .= ''; + $matchday_to_options .= ''; + $matchday_new_options .= ''; + } + $db->sql_freeresult($result); + if ($matchday_from_options == '') + { + trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Which page? + switch ($action) + { + case 'update': + { + if ($matchday_from > $matchday_to) + { + $error[] = sprintf($user->lang['ERROR_FROM_TO']); + } + if ($matchday_new <= $matchday_to) + { + $error[] = sprintf($user->lang['ERROR_TARGET']); + } + if (!sizeof($error)) + { + if (1 == $check_rank) + { + $success = ko_group_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new, $rank, $move_rank, $move_league, $move_matchday); + } + else + { + $success = ko_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new); + } + trigger_error($success . adm_back_link($this->u_action)); + } + } + break; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'S_SUCCESS' => (sizeof($success)) ? true : false, + 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_MATCHDAY_FROM_OPTIONS'=> $matchday_from_options, + 'S_MATCHDAY_TO_OPTIONS' => $matchday_to_options, + 'S_MATCHDAY_NEW_OPTIONS'=> $matchday_new_options, + 'S_CHECK_RANK' => $check_rank, + 'S_RANK' => $rank, + 'S_MOVE_RANK' => $move_rank, + 'S_MOVE_LEAGUE_OPTIONS' => $league_move_options, + 'S_MOVE_MATCHDAY' => $move_matchday, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + } +} ?> \ No newline at end of file diff --git a/acp/leagues_module.php b/acp/leagues_module.php index 7485d95..8cd554e 100644 --- a/acp/leagues_module.php +++ b/acp/leagues_module.php @@ -1,736 +1,734 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_leagues'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_leagues'; - $this->page_title = 'ACP_FOOTBALL_LEAGUES_MANAGE'; - - $form_key = 'acp_football_leagues'; - add_form_key($form_key); - - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addmembers'])) ? 'addmembers' : $this->request->variable('action', '')); - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $group_id = $this->request->variable('g', 0); - $start = $this->request->variable('start', 0); - $update = (isset($_POST['update'])) ? true : false; - - // Clear some vars - $league_info = array(); - $error = array(); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - // Grab basic data for season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for league, if league is set and exists - if ($league) - { - $league_info = league_info($season, $league); - } - - // Which page? - switch ($action) - { - case 'addmembers': - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $usernames = $this->request->variable('usernames', '', true); - if ($usernames) - { - $username_ary = array_unique(explode("\n", $usernames)); - - // Add user/s to league - // We need both username and user_id info - $user_id_ary = false; - $result = user_get_id_name($user_id_ary, $username_ary); - - if (!sizeof($user_id_ary) || $result !== false) - { - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action . "&action=list&s=$season&l=$league"), E_USER_WARNING); - } - } - else - { - if ($group_id) - { - $sql = 'SELECT u.user_id, u.username - FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug - WHERE ug.group_id = ' . $group_id . ' - AND ug.user_pending = 0 - AND u.user_id = ug.user_id - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - ORDER BY u.user_id'; - } - else - { - $sql = 'SELECT user_id, username - FROM ' . USERS_TABLE . ' - WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - ORDER BY user_id'; - } - $result = $db->sql_query($sql); - if (!($row = $db->sql_fetchrow($result))) - { - $db->sql_freeresult($result); - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action . "&action=list&s=$season&l=$league"), E_USER_WARNING); - } - - do - { - $username_ary[$row['user_id']] = $row['username']; - $user_id_ary[] = $row['user_id']; - } - while ($row = $db->sql_fetchrow($result)); - $db->sql_freeresult($result); - } - - - if ($league_info['league_type'] == LEAGUE_KO) - { - // Check matchdays - $sql = 'SELECT - COUNT(matchday) AS matchdays - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $matchdays = (int) $db->sql_fetchfield('matchdays'); - $db->sql_freeresult($result); - if ($matchdays < $league_info['matchdays']) - { - trigger_error($user->lang['NO_MATCHDAYS_KO'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - foreach ($user_id_ary as $user_id) - { - // Test user is member - $sql = 'SELECT - COUNT(user_id) AS total_bets - FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND user_id = $user_id"; - $result = $db->sql_query($sql); - $total_bets = (int) $db->sql_fetchfield('total_bets'); - $db->sql_freeresult($result); - - if ($total_bets > 0) - { - $error[] = $user->lang['MEMBER_EXISTS']; - } - else - { - $count_updates = join_league($season, $league, $user_id); - } - } - - $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league; - trigger_error($user->lang['LEAGUE_USERS_ADD'] . adm_back_link($back_link)); - break; - case 'deletemembers': - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $mark_ary = $this->request->variable('mark', array(0)); - if (sizeof($mark_ary) == 0) - { - trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['SEASONS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND " . $db->sql_in_set('user_id', $mark_ary); - $db->sql_query($sql); - // Delete ranks - $sql = 'DELETE FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league - AND " . $db->sql_in_set('user_id', $mark_ary); - $db->sql_query($sql); - // Delete bank statements - $sql = 'DELETE FROM ' . FOOTB_POINTS . " - WHERE season = $season - AND league = $league - AND " . $db->sql_in_set('user_id', $mark_ary); - $db->sql_query($sql); - - $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league; - trigger_error($user->lang['LEAGUE_USERS_REMOVE'] . adm_back_link($back_link)); - } - else - { - confirm_box(false, sprintf($user->lang['MEMBER_CONFIRM_DELETE'], $league_info['league_name'], $season), build_hidden_fields(array( - 'mark' => $mark_ary, - 's' => $season, - 'l' => $league, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'list': - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $this->page_title = 'LEAGUE_MEMBERS'; - - // Total number of league members - $sql = 'SELECT - COUNT(DISTINCT user_id) AS total_members - FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $total_members = (int) $db->sql_fetchfield('total_members'); - $db->sql_freeresult($result); - - $s_action_options = ''; - $options = array('deletemembers' => 'DELETE'); - - foreach ($options as $option => $lang) - { - $s_action_options .= ''; - } - - // Exclude bots and guests... - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name IN ('BOTS', 'GUESTS')"; - $result = $db->sql_query($sql); - - $exclude = array(); - while ($row = $db->sql_fetchrow($result)) - { - $exclude[] = $row['group_id']; - } - $db->sql_freeresult($result); - $select_list = ''; - $select_list .= group_select_options($group_id, $exclude); - $base_url = $this->u_action . "&action=list&s=$season&l=$league"; - $pagination = $phpbb_container->get('pagination'); - $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $this->config['football_users_per_page'], $start); - - $template->assign_vars(array( - 'S_LIST' => true, - 'S_ACTION_OPTIONS' => $s_action_options, - 'TOTAL_MEMBERS' => ($total_members == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_members), - 'PAGE_NUMBER' => $pagination->on_page($total_members, $this->config['football_users_per_page'], $start), - 'LEAGUE_NAME' => $league_info['league_name']. ' ' . $season_name, - 'U_ACTION' => $this->u_action . "&s=$season&l=$league", - 'U_BACK' => $this->u_action. "&s=$season&l=$league", - 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), - 'U_DEFAULT_ALL' => "{$this->u_action}&action=addmembers&s=$season&l=$league&g=0", - 'S_GROUP_OPTIONS' => $select_list, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Grab the members - $sql = 'SELECT - DISTINCT u.user_id, - u.username, - u.username_clean, - u.user_regdate - FROM ' . FOOTB_BETS . ' b, ' . USERS_TABLE . " u - WHERE b.season = $season AND b.league = $league - AND u.user_id = b.user_id - ORDER BY u.username_clean"; - $result = $db->sql_query_limit($sql, $this->config['football_users_per_page'], $start); - - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('member', array( - 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), - 'USERNAME' => $row['username'], - 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ', - 'USER_ID' => $row['user_id'], - ) - ); - } - $db->sql_freeresult($result); - - return; - break; - case 'delete': - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['LEAGUES_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Delete league - $sql = 'DELETE FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - // Delete matchdays - $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - // Delete matches - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - // Delete teams - $sql = 'DELETE FROM ' . FOOTB_TEAMS . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - // Delete ranks - $sql = 'DELETE FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - - trigger_error($user->lang['LEAGUE_DELETED'] . adm_back_link($this->u_action . "&s=$season")); - } - else - { - confirm_box(false, sprintf($user->lang['LEAGUE_CONFIRM_DELETE'], $league_info['league_name'], $season), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add': - if ($league > 0 AND $league <= 99) - { - if ($league_info) - { - if ($edit) - { - $error[] = $user->lang['LEAGUE_TAKEN']; - } - else - { - trigger_error($user->lang['LEAGUE_TAKEN'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - } - $league_info['league_name'] = utf8_normalize_nfc($this->request->variable('league_name', '', true)); - $league_info['league_name_short'] = utf8_normalize_nfc($this->request->variable('league_short', '', true)); - $league_info['league_type'] = $this->request->variable('league_type', 1, true); - $league_info['bet_ko_type'] = $this->request->variable('bet_ko_type', 1, true); - $league_info['matchdays'] = $this->request->variable('league_matchdays', 34, true); - $league_info['matches_on_matchday'] = $this->request->variable('league_matches', 9, true); - $league_info['bet_points'] = round($this->request->variable('bet_points', 0), 2); - $league_info['win_result'] = $this->request->variable('league_win_hits', 0, true); - $league_info['win_result_02'] = $this->request->variable('league_win_hits_away', 0, true); - $league_info['win_matchday'] = $this->request->variable('league_win_matchdays', 0, true); - $league_info['win_season'] = $this->request->variable('league_win_season', 0, true); - $league_info['points_mode'] = $this->request->variable('league_points_mode', 1, true); - $league_info['points_result'] = $this->request->variable('league_points_hit', 0, true); - $league_info['points_tendency'] = $this->request->variable('league_points_tendency', 0, true); - $league_info['points_diff'] = $this->request->variable('league_points_diff', 0, true); - $league_info['points_last'] = $this->request->variable('league_points_last', 1, true); - $league_info['join_by_user'] = $this->request->variable('league_join_by_user', 0, true); - $league_info['join_in_season'] = $this->request->variable('league_join_in_season', 0, true); - $league_info['bet_in_time'] = $this->request->variable('league_bet_in_time', 0, true); - $league_info['rules_post_id'] = $this->request->variable('league_rules_post_id', 0, true); - } - else - { - trigger_error($user->lang['LEAGUE_NUMBER'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - // No break for edit add - case 'edit': - - $data = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Did we submit? - if ($update) - { - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - $league_info['league_name'] = utf8_normalize_nfc($this->request->variable('league_name', '', true)); - $league_info['league_name_short'] = utf8_normalize_nfc($this->request->variable('league_short', '', true)); - $league_info['league_type'] = $this->request->variable('league_type', $league_info['league_type'], true); - $league_info['bet_ko_type'] = $this->request->variable('bet_ko_type', $league_info['bet_ko_type'], true); - $league_info['matchdays'] = $this->request->variable('league_matchdays', $league_info['matchdays'], true); - $league_info['matches_on_matchday'] = $this->request->variable('league_matches', $league_info['matches_on_matchday'], true); - $league_info['bet_points'] = round($this->request->variable('bet_points', $league_info['bet_points']),2); - $league_info['win_result'] = $this->request->variable('league_win_hits', $league_info['win_result'], true); - $league_info['win_result_02'] = $this->request->variable('league_win_hits_away', $league_info['win_result_02'], true); - $league_info['win_matchday'] = $this->request->variable('league_win_matchdays', $league_info['win_matchday'], true); - $league_info['win_season'] = $this->request->variable('league_win_season', $league_info['win_season'], true); - $league_info['points_mode'] = $this->request->variable('league_points_mode', $league_info['points_mode'], true); - $league_info['points_result'] = $this->request->variable('league_points_hit', $league_info['points_result'], true); - $league_info['points_tendency'] = $this->request->variable('league_points_tendency', $league_info['points_tendency'], true); - $league_info['points_diff'] = $this->request->variable('league_points_diff', $league_info['points_diff'], true); - $league_info['points_last'] = $this->request->variable('league_points_last', $league_info['points_last'], true); - $league_info['join_by_user'] = $this->request->variable('league_join_by_user', $league_info['join_by_user'], true); - $league_info['join_in_season'] = $this->request->variable('league_join_in_season', $league_info['join_in_season'], true); - $league_info['bet_in_time'] = $this->request->variable('league_bet_in_time', $league_info['bet_in_time'], true); - $league_info['rules_post_id'] = $this->request->variable('league_rules_post_id', $league_info['rules_post_id'], true); - - if (!$league_info['rules_post_id'] and $league_info['join_by_user'] == 1) - { - $error[] = $user->lang['CHECK_RULES_POST_ID']; - } - - if (!is_numeric($league_info['win_result']) or $league_info['win_result'] < 0) - { - $error[] = $user->lang['CHECK_HIT_WINS']; - } - - if (!is_numeric($league_info['win_result_02']) or $league_info['win_result_02'] < 0) - { - $error[] = $user->lang['CHECK_HITS02_WINS']; - } - - $matchday_wins = explode(';',$league_info['win_matchday']); - foreach ($matchday_wins as $matchday_win) - { - if (!is_numeric($matchday_win) or $matchday_win < 0) - { - $error[] = $user->lang['CHECK_MATCHDAY_WINS']; - break; - } - } - - $season_wins = explode(';',$league_info['win_season']); - foreach ($season_wins as $season_win) - { - if (!is_numeric($season_win) or $season_win < 0) - { - $error[] = $user->lang['CHECK_SEASON_WINS']; - break; - } - } - - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'league_name' => $league_info['league_name'], - 'league_name_short' => $league_info['league_name_short'], - 'league_type' => $league_info['league_type'], - 'bet_ko_type' => $league_info['bet_ko_type'], - 'matchdays' => $league_info['matchdays'], - 'matches_on_matchday' => ($league_info['league_type'] == LEAGUE_KO) ? 0 : $league_info['matches_on_matchday'], - 'win_result' => $league_info['win_result'], - 'win_result_02' => $league_info['win_result_02'], - 'win_matchday' => $league_info['win_matchday'], - 'win_season' => $league_info['win_season'], - 'points_mode' => $league_info['points_mode'], - 'points_result' => (is_numeric($league_info['points_result'])) ? $league_info['points_result'] : 0, - 'points_tendency' => (is_numeric($league_info['points_tendency'])) ? $league_info['points_tendency'] : 0, - 'points_diff' => (is_numeric($league_info['points_diff'])) ? $league_info['points_diff'] : 0, - 'points_last' => $league_info['points_last'], - 'join_by_user' => $league_info['join_by_user'], - 'join_in_season' => $league_info['join_in_season'], - 'bet_in_time' => $league_info['bet_in_time'], - 'rules_post_id' => (is_numeric($league_info['rules_post_id'])) ? $league_info['rules_post_id'] : 0, - 'bet_points' => $league_info['bet_points'], - ); - - $data['league'] = $league; - $data['league_name'] = $league_info['league_name']; - $data['league_short'] = $league_info['league_name_short']; - $data['league_matchdays'] = $league_info['matchdays']; - $data['league_matches'] = ($league_info['league_type'] == LEAGUE_KO) ? 0 : $league_info['matches_on_matchday']; - - $var_ary = array( - 'league' => array('num', false, 1, 99), - 'league_name' => array('string', false, 2, 20), - 'league_short' => array('string', false, 1, 3), - 'league_matchdays' => array('num', false, 0, 99), - 'league_matches' => array('num', false, 0, 99), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - if ($action == 'add') - { - $sql = 'INSERT INTO ' . FOOTB_LEAGUES . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . FOOTB_LEAGUES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league"; - $db->sql_query($sql); - } - if ($league_info['bet_in_time']) - { - set_bet_in_time_delivery($season, $league); - } - $message = ($action == 'edit') ? 'LEAGUE_UPDATED' : 'LEAGUE_CREATED'; - trigger_error($user->lang[$message] . adm_back_link($this->u_action . "&s=$season")); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $message = ($action == 'edit') ? 'LEAGUE_UPDATE_FAILED' : 'LEAGUE_CREATE_FAILED'; - $error[] = $user->lang[$message]; - $error = array_merge($error, $error_msg); - } - } - } - } - $type_champ = ($league_info['league_type'] == LEAGUE_CHAMP) ? ' checked="checked"' : ''; - $type_ko = ($league_info['league_type'] == LEAGUE_KO) ? ' checked="checked"' : ''; - $bet_ko_90 = ($league_info['bet_ko_type'] == BET_KO_90) ? ' checked="checked"' : ''; - $bet_ko_extratime = ($league_info['bet_ko_type'] == BET_KO_EXTRATIME) ? ' checked="checked"' : ''; - $bet_ko_penalty = ($league_info['bet_ko_type'] == BET_KO_PENALTY) ? ' checked="checked"' : ''; - $mode_options = ''; - for($i = 1; $i <= 6; $i++) - { - $selected = ($i == $league_info['points_mode']) ? ' selected="selected"' : ''; - $mode_options .= ''; - } - - // check if matches created - $existing_matches_on_league = count_existing_matches($season, $league, 0); - - $u_back = $this->u_action . "&s=$season"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_LEAGUE' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'S_EDIT_MATCHES' => ($existing_matches_on_league) ? false : true, - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'BET_IN_TIME_YES' => ($league_info['bet_in_time'] == 1) ? ' checked="checked"' : '', - 'BET_IN_TIME_NO' => ($league_info['bet_in_time'] == 0) ? ' checked="checked"' : '', - 'BET_TYPE_KO_90' => BET_KO_90, - 'BET_TYPE_KO_EXTRATIME' => BET_KO_EXTRATIME, - 'BET_TYPE_KO_PENALTY' => BET_KO_PENALTY, - 'BET_KO_90' => $bet_ko_90, - 'BET_KO_EXTRATIME' => $bet_ko_extratime, - 'BET_KO_PENALTY' => $bet_ko_penalty, - 'JOIN_BY_USER_YES' => ($league_info['join_by_user'] == 1) ? ' checked="checked"' : '', - 'JOIN_BY_USER_NO' => ($league_info['join_by_user'] == 0) ? ' checked="checked"' : '', - 'JOIN_IN_SEASON_YES' => ($league_info['join_in_season'] == 1) ? ' checked="checked"' : '', - 'JOIN_IN_SEASON_NO' => ($league_info['join_in_season'] == 0) ? ' checked="checked"' : '', - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_info['league_name'], - 'LEAGUE_SHORT' => $league_info['league_name_short'], - 'LEAGUE_TYPE_CHAMP' => LEAGUE_CHAMP, - 'LEAGUE_TYPE_KO' => LEAGUE_KO, - 'LEAGUE_CHAMP' => $type_champ, - 'LEAGUE_KO' => $type_ko, - 'LEAGUE_MATCHDAYS' => $league_info['matchdays'], - 'LEAGUE_MATCHES' => $league_info['matches_on_matchday'], - 'LEAGUE_POINTS_MODE_OPTIONS' => $mode_options, - 'LEAGUE_POINTS_HIT' => $league_info['points_result'], - 'LEAGUE_POINTS_TENDENCY'=> $league_info['points_tendency'], - 'LEAGUE_POINTS_DIFF' => $league_info['points_diff'], - 'LEAGUE_RULES_POST_ID' => $league_info['rules_post_id'], - 'BET_POINTS' => $league_info['bet_points'], - 'LEAGUE_WIN_HITS' => $league_info['win_result'], - 'LEAGUE_WIN_HITS_AWAY' => $league_info['win_result_02'], - 'LEAGUE_WIN_MATCHDAYS' => $league_info['win_matchday'], - 'LEAGUE_WIN_SEASON' => $league_info['win_season'], - 'POINTS_LAST_YES' => ($league_info['points_last'] == 1) ? ' checked="checked"' : '', - 'POINTS_LAST_NO' => ($league_info['points_last'] == 0) ? ' checked="checked"' : '', - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season", - ) - ); - return; - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season)), - 'S_SEASON' => $season, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_ADD' => true, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Get us all the leagues - $sql = 'SELECT - l.season, - l.league, - l.league_name, - l.league_name_short, - COUNT(DISTINCT b.user_id) AS members - FROM ' . FOOTB_LEAGUES . ' AS l - LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = l.season AND b.league = l.league) - WHERE l.season = $season - GROUP BY league - ORDER BY league ASC"; - $result = $db->sql_query($sql); - $rows_leagues = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - // Check if the user is allowed to delete a league. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - foreach ($rows_leagues as $row_league) - { - // check if matches created - $existing_matches_on_league = count_existing_matches($row_league['season'], $row_league['league'], 0); - - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('leagues', array( - 'ROW_CLASS' => $row_class, - 'SEASON' => $row_league['season'], - 'LEAGUE' => $row_league['league'], - 'LEAGUE_NAME' => $row_league['league_name'], - 'LEAGUE_SHORT' => $row_league['league_name_short'], - 'MEMBERS' => $row_league['members'], - 'S_MEMBER' => ($existing_matches_on_league) ? true : false, - 'U_LIST' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$row_league['league'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $row_league['league'] : '', - ) - ); - } - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_leagues'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_leagues'; + $this->page_title = 'ACP_FOOTBALL_LEAGUES_MANAGE'; + + $form_key = 'acp_football_leagues'; + add_form_key($form_key); + + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addmembers'])) ? 'addmembers' : $this->request->variable('action', '')); + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $group_id = $this->request->variable('g', 0); + $start = $this->request->variable('start', 0); + $update = (isset($_POST['update'])) ? true : false; + + // Clear some vars + $league_info = array(); + $error = array(); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + // Grab basic data for season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for league, if league is set and exists + if ($league) + { + $league_info = league_info($season, $league); + } + + // Which page? + switch ($action) + { + case 'addmembers': + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + $usernames = $this->request->variable('usernames', '', true); + if ($usernames) + { + $username_ary = array_unique(explode("\n", $usernames)); + + // Add user/s to league + // We need both username and user_id info + $user_id_ary = false; + $result = user_get_id_name($user_id_ary, $username_ary); + + if (!sizeof($user_id_ary) || $result !== false) + { + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action . "&action=list&s=$season&l=$league"), E_USER_WARNING); + } + } + else + { + if ($group_id) + { + $sql = 'SELECT u.user_id, u.username + FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug + WHERE ug.group_id = ' . $group_id . ' + AND ug.user_pending = 0 + AND u.user_id = ug.user_id + AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') + ORDER BY u.user_id'; + } + else + { + $sql = 'SELECT user_id, username + FROM ' . USERS_TABLE . ' + WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') + ORDER BY user_id'; + } + $result = $db->sql_query($sql); + if (!($row = $db->sql_fetchrow($result))) + { + $db->sql_freeresult($result); + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action . "&action=list&s=$season&l=$league"), E_USER_WARNING); + } + + do + { + $username_ary[$row['user_id']] = $row['username']; + $user_id_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); + } + + + if ($league_info['league_type'] == LEAGUE_KO) + { + // Check matchdays + $sql = 'SELECT + COUNT(matchday) AS matchdays + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $matchdays = (int) $db->sql_fetchfield('matchdays'); + $db->sql_freeresult($result); + if ($matchdays < $league_info['matchdays']) + { + trigger_error($user->lang['NO_MATCHDAYS_KO'] . adm_back_link($this->u_action), E_USER_WARNING); + } + } + + foreach ($user_id_ary as $user_id) + { + // Test user is member + $sql = 'SELECT + COUNT(user_id) AS total_bets + FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND user_id = $user_id"; + $result = $db->sql_query($sql); + $total_bets = (int) $db->sql_fetchfield('total_bets'); + $db->sql_freeresult($result); + + if ($total_bets > 0) + { + $error[] = $user->lang['MEMBER_EXISTS']; + } + else + { + $count_updates = join_league($season, $league, $user_id); + } + } + + $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league; + trigger_error($user->lang['LEAGUE_USERS_ADD'] . adm_back_link($back_link)); + break; + case 'deletemembers': + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + $mark_ary = $this->request->variable('mark', array(0)); + if (sizeof($mark_ary) == 0) + { + trigger_error($user->lang['NO_MEMBERS_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (confirm_box(true)) + { + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['SEASONS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND " . $db->sql_in_set('user_id', $mark_ary); + $db->sql_query($sql); + // Delete ranks + $sql = 'DELETE FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league + AND " . $db->sql_in_set('user_id', $mark_ary); + $db->sql_query($sql); + // Delete bank statements + $sql = 'DELETE FROM ' . FOOTB_POINTS . " + WHERE season = $season + AND league = $league + AND " . $db->sql_in_set('user_id', $mark_ary); + $db->sql_query($sql); + + $back_link = $this->u_action . '&action=list&s=' . $season . '&l=' . $league; + trigger_error($user->lang['LEAGUE_USERS_REMOVE'] . adm_back_link($back_link)); + } + else + { + confirm_box(false, sprintf($user->lang['MEMBER_CONFIRM_DELETE'], $league_info['league_name'], $season), build_hidden_fields(array( + 'mark' => $mark_ary, + 's' => $season, + 'l' => $league, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'list': + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + $this->page_title = 'LEAGUE_MEMBERS'; + + // Total number of league members + $sql = 'SELECT + COUNT(DISTINCT user_id) AS total_members + FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $total_members = (int) $db->sql_fetchfield('total_members'); + $db->sql_freeresult($result); + + $s_action_options = ''; + $options = array('deletemembers' => 'DELETE'); + + foreach ($options as $option => $lang) + { + $s_action_options .= ''; + } + + // Exclude bots and guests... + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name IN ('BOTS', 'GUESTS')"; + $result = $db->sql_query($sql); + + $exclude = array(); + while ($row = $db->sql_fetchrow($result)) + { + $exclude[] = $row['group_id']; + } + $db->sql_freeresult($result); + $select_list = ''; + $select_list .= group_select_options($group_id, $exclude); + $base_url = $this->u_action . "&action=list&s=$season&l=$league"; + $pagination = $phpbb_container->get('pagination'); + $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $this->config['football_users_per_page'], $start); + + $template->assign_vars(array( + 'S_LIST' => true, + 'S_ACTION_OPTIONS' => $s_action_options, + 'TOTAL_MEMBERS' => ($total_members == 1) ? $user->lang['VIEW_BET_USER'] : sprintf($user->lang['VIEW_BET_USERS'], $total_members), + 'PAGE_NUMBER' => $pagination->on_page($total_members, $this->config['football_users_per_page'], $start), + 'LEAGUE_NAME' => $league_info['league_name']. ' ' . $season_name, + 'U_ACTION' => $this->u_action . "&s=$season&l=$league", + 'U_BACK' => $this->u_action. "&s=$season&l=$league", + 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), + 'U_DEFAULT_ALL' => "{$this->u_action}&action=addmembers&s=$season&l=$league&g=0", + 'S_GROUP_OPTIONS' => $select_list, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Grab the members + $sql = 'SELECT + DISTINCT u.user_id, + u.username, + u.username_clean, + u.user_regdate + FROM ' . FOOTB_BETS . ' b, ' . USERS_TABLE . " u + WHERE b.season = $season AND b.league = $league + AND u.user_id = b.user_id + ORDER BY u.username_clean"; + $result = $db->sql_query_limit($sql, $this->config['football_users_per_page'], $start); + + while ($row = $db->sql_fetchrow($result)) + { + $template->assign_block_vars('member', array( + 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), + 'USERNAME' => $row['username'], + 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ', + 'USER_ID' => $row['user_id'], + ) + ); + } + $db->sql_freeresult($result); + + return; + break; + case 'delete': + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['LEAGUES_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Delete league + $sql = 'DELETE FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + // Delete matchdays + $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + // Delete matches + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + // Delete teams + $sql = 'DELETE FROM ' . FOOTB_TEAMS . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + // Delete ranks + $sql = 'DELETE FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + + trigger_error($user->lang['LEAGUE_DELETED'] . adm_back_link($this->u_action . "&s=$season")); + } + else + { + confirm_box(false, sprintf($user->lang['LEAGUE_CONFIRM_DELETE'], $league_info['league_name'], $season), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add': + if ($league > 0 AND $league <= 99) + { + if ($league_info) + { + if ($edit) + { + $error[] = $user->lang['LEAGUE_TAKEN']; + } + else + { + trigger_error($user->lang['LEAGUE_TAKEN'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + } + $league_info['league_name'] = utf8_normalize_nfc($this->request->variable('league_name', '', true)); + $league_info['league_name_short'] = utf8_normalize_nfc($this->request->variable('league_short', '', true)); + $league_info['league_type'] = $this->request->variable('league_type', 1, true); + $league_info['bet_ko_type'] = $this->request->variable('bet_ko_type', 1, true); + $league_info['matchdays'] = $this->request->variable('league_matchdays', 34, true); + $league_info['matches_on_matchday'] = $this->request->variable('league_matches', 9, true); + $league_info['bet_points'] = round($this->request->variable('bet_points', 0), 2); + $league_info['win_result'] = $this->request->variable('league_win_hits', 0, true); + $league_info['win_result_02'] = $this->request->variable('league_win_hits_away', 0, true); + $league_info['win_matchday'] = $this->request->variable('league_win_matchdays', 0, true); + $league_info['win_season'] = $this->request->variable('league_win_season', 0, true); + $league_info['points_mode'] = $this->request->variable('league_points_mode', 1, true); + $league_info['points_result'] = $this->request->variable('league_points_hit', 0, true); + $league_info['points_tendency'] = $this->request->variable('league_points_tendency', 0, true); + $league_info['points_diff'] = $this->request->variable('league_points_diff', 0, true); + $league_info['points_last'] = $this->request->variable('league_points_last', 1, true); + $league_info['join_by_user'] = $this->request->variable('league_join_by_user', 0, true); + $league_info['join_in_season'] = $this->request->variable('league_join_in_season', 0, true); + $league_info['bet_in_time'] = $this->request->variable('league_bet_in_time', 0, true); + $league_info['rules_post_id'] = $this->request->variable('league_rules_post_id', 0, true); + } + else + { + trigger_error($user->lang['LEAGUE_NUMBER'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + // No break for edit add + case 'edit': + + $data = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Did we submit? + if ($update) + { + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + $league_info['league_name'] = utf8_normalize_nfc($this->request->variable('league_name', '', true)); + $league_info['league_name_short'] = utf8_normalize_nfc($this->request->variable('league_short', '', true)); + $league_info['league_type'] = $this->request->variable('league_type', $league_info['league_type'], true); + $league_info['bet_ko_type'] = $this->request->variable('bet_ko_type', $league_info['bet_ko_type'], true); + $league_info['matchdays'] = $this->request->variable('league_matchdays', $league_info['matchdays'], true); + $league_info['matches_on_matchday'] = $this->request->variable('league_matches', $league_info['matches_on_matchday'], true); + $league_info['bet_points'] = round($this->request->variable('bet_points', $league_info['bet_points']),2); + $league_info['win_result'] = $this->request->variable('league_win_hits', $league_info['win_result'], true); + $league_info['win_result_02'] = $this->request->variable('league_win_hits_away', $league_info['win_result_02'], true); + $league_info['win_matchday'] = $this->request->variable('league_win_matchdays', $league_info['win_matchday'], true); + $league_info['win_season'] = $this->request->variable('league_win_season', $league_info['win_season'], true); + $league_info['points_mode'] = $this->request->variable('league_points_mode', $league_info['points_mode'], true); + $league_info['points_result'] = $this->request->variable('league_points_hit', $league_info['points_result'], true); + $league_info['points_tendency'] = $this->request->variable('league_points_tendency', $league_info['points_tendency'], true); + $league_info['points_diff'] = $this->request->variable('league_points_diff', $league_info['points_diff'], true); + $league_info['points_last'] = $this->request->variable('league_points_last', $league_info['points_last'], true); + $league_info['join_by_user'] = $this->request->variable('league_join_by_user', $league_info['join_by_user'], true); + $league_info['join_in_season'] = $this->request->variable('league_join_in_season', $league_info['join_in_season'], true); + $league_info['bet_in_time'] = $this->request->variable('league_bet_in_time', $league_info['bet_in_time'], true); + $league_info['rules_post_id'] = $this->request->variable('league_rules_post_id', $league_info['rules_post_id'], true); + + if (!$league_info['rules_post_id'] and $league_info['join_by_user'] == 1) + { + $error[] = $user->lang['CHECK_RULES_POST_ID']; + } + + if (!is_numeric($league_info['win_result']) or $league_info['win_result'] < 0) + { + $error[] = $user->lang['CHECK_HIT_WINS']; + } + + if (!is_numeric($league_info['win_result_02']) or $league_info['win_result_02'] < 0) + { + $error[] = $user->lang['CHECK_HITS02_WINS']; + } + + $matchday_wins = explode(';',$league_info['win_matchday']); + foreach ($matchday_wins as $matchday_win) + { + if (!is_numeric($matchday_win) or $matchday_win < 0) + { + $error[] = $user->lang['CHECK_MATCHDAY_WINS']; + break; + } + } + + $season_wins = explode(';',$league_info['win_season']); + foreach ($season_wins as $season_win) + { + if (!is_numeric($season_win) or $season_win < 0) + { + $error[] = $user->lang['CHECK_SEASON_WINS']; + break; + } + } + + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'league_name' => $league_info['league_name'], + 'league_name_short' => $league_info['league_name_short'], + 'league_type' => $league_info['league_type'], + 'bet_ko_type' => $league_info['bet_ko_type'], + 'matchdays' => $league_info['matchdays'], + 'matches_on_matchday' => ($league_info['league_type'] == LEAGUE_KO) ? 0 : $league_info['matches_on_matchday'], + 'win_result' => $league_info['win_result'], + 'win_result_02' => $league_info['win_result_02'], + 'win_matchday' => $league_info['win_matchday'], + 'win_season' => $league_info['win_season'], + 'points_mode' => $league_info['points_mode'], + 'points_result' => (is_numeric($league_info['points_result'])) ? $league_info['points_result'] : 0, + 'points_tendency' => (is_numeric($league_info['points_tendency'])) ? $league_info['points_tendency'] : 0, + 'points_diff' => (is_numeric($league_info['points_diff'])) ? $league_info['points_diff'] : 0, + 'points_last' => $league_info['points_last'], + 'join_by_user' => $league_info['join_by_user'], + 'join_in_season' => $league_info['join_in_season'], + 'bet_in_time' => $league_info['bet_in_time'], + 'rules_post_id' => (is_numeric($league_info['rules_post_id'])) ? $league_info['rules_post_id'] : 0, + 'bet_points' => $league_info['bet_points'], + ); + + $data['league'] = $league; + $data['league_name'] = $league_info['league_name']; + $data['league_short'] = $league_info['league_name_short']; + $data['league_matchdays'] = $league_info['matchdays']; + $data['league_matches'] = ($league_info['league_type'] == LEAGUE_KO) ? 0 : $league_info['matches_on_matchday']; + + $var_ary = array( + 'league' => array('num', false, 1, 99), + 'league_name' => array('string', false, 2, 20), + 'league_short' => array('string', false, 1, 3), + 'league_matchdays' => array('num', false, 0, 99), + 'league_matches' => array('num', false, 0, 99), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + if ($action == 'add') + { + $sql = 'INSERT INTO ' . FOOTB_LEAGUES . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . FOOTB_LEAGUES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league"; + $db->sql_query($sql); + } + if ($league_info['bet_in_time']) + { + set_bet_in_time_delivery($season, $league); + } + $message = ($action == 'edit') ? 'LEAGUE_UPDATED' : 'LEAGUE_CREATED'; + trigger_error($user->lang[$message] . adm_back_link($this->u_action . "&s=$season")); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $message = ($action == 'edit') ? 'LEAGUE_UPDATE_FAILED' : 'LEAGUE_CREATE_FAILED'; + $error[] = $user->lang[$message]; + $error = array_merge($error, $error_msg); + } + } + } + } + $type_champ = ($league_info['league_type'] == LEAGUE_CHAMP) ? ' checked="checked"' : ''; + $type_ko = ($league_info['league_type'] == LEAGUE_KO) ? ' checked="checked"' : ''; + $bet_ko_90 = ($league_info['bet_ko_type'] == BET_KO_90) ? ' checked="checked"' : ''; + $bet_ko_extratime = ($league_info['bet_ko_type'] == BET_KO_EXTRATIME) ? ' checked="checked"' : ''; + $bet_ko_penalty = ($league_info['bet_ko_type'] == BET_KO_PENALTY) ? ' checked="checked"' : ''; + $mode_options = ''; + for($i = 1; $i <= 6; $i++) + { + $selected = ($i == $league_info['points_mode']) ? ' selected="selected"' : ''; + $mode_options .= ''; + } + + // check if matches created + $existing_matches_on_league = count_existing_matches($season, $league, 0); + + $u_back = $this->u_action . "&s=$season"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_LEAGUE' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'S_EDIT_MATCHES' => ($existing_matches_on_league) ? false : true, + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'BET_IN_TIME_YES' => ($league_info['bet_in_time'] == 1) ? ' checked="checked"' : '', + 'BET_IN_TIME_NO' => ($league_info['bet_in_time'] == 0) ? ' checked="checked"' : '', + 'BET_TYPE_KO_90' => BET_KO_90, + 'BET_TYPE_KO_EXTRATIME' => BET_KO_EXTRATIME, + 'BET_TYPE_KO_PENALTY' => BET_KO_PENALTY, + 'BET_KO_90' => $bet_ko_90, + 'BET_KO_EXTRATIME' => $bet_ko_extratime, + 'BET_KO_PENALTY' => $bet_ko_penalty, + 'JOIN_BY_USER_YES' => ($league_info['join_by_user'] == 1) ? ' checked="checked"' : '', + 'JOIN_BY_USER_NO' => ($league_info['join_by_user'] == 0) ? ' checked="checked"' : '', + 'JOIN_IN_SEASON_YES' => ($league_info['join_in_season'] == 1) ? ' checked="checked"' : '', + 'JOIN_IN_SEASON_NO' => ($league_info['join_in_season'] == 0) ? ' checked="checked"' : '', + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_info['league_name'], + 'LEAGUE_SHORT' => $league_info['league_name_short'], + 'LEAGUE_TYPE_CHAMP' => LEAGUE_CHAMP, + 'LEAGUE_TYPE_KO' => LEAGUE_KO, + 'LEAGUE_CHAMP' => $type_champ, + 'LEAGUE_KO' => $type_ko, + 'LEAGUE_MATCHDAYS' => $league_info['matchdays'], + 'LEAGUE_MATCHES' => $league_info['matches_on_matchday'], + 'LEAGUE_POINTS_MODE_OPTIONS' => $mode_options, + 'LEAGUE_POINTS_HIT' => $league_info['points_result'], + 'LEAGUE_POINTS_TENDENCY'=> $league_info['points_tendency'], + 'LEAGUE_POINTS_DIFF' => $league_info['points_diff'], + 'LEAGUE_RULES_POST_ID' => $league_info['rules_post_id'], + 'BET_POINTS' => $league_info['bet_points'], + 'LEAGUE_WIN_HITS' => $league_info['win_result'], + 'LEAGUE_WIN_HITS_AWAY' => $league_info['win_result_02'], + 'LEAGUE_WIN_MATCHDAYS' => $league_info['win_matchday'], + 'LEAGUE_WIN_SEASON' => $league_info['win_season'], + 'POINTS_LAST_YES' => ($league_info['points_last'] == 1) ? ' checked="checked"' : '', + 'POINTS_LAST_NO' => ($league_info['points_last'] == 0) ? ' checked="checked"' : '', + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season", + ) + ); + return; + break; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season)), + 'S_SEASON' => $season, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_ADD' => true, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Get us all the leagues + $sql = 'SELECT + l.season, + l.league, + l.league_name, + l.league_name_short, + COUNT(DISTINCT b.user_id) AS members + FROM ' . FOOTB_LEAGUES . ' AS l + LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = l.season AND b.league = l.league) + WHERE l.season = $season + GROUP BY league + ORDER BY league ASC"; + $result = $db->sql_query($sql); + $rows_leagues = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + // Check if the user is allowed to delete a league. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + foreach ($rows_leagues as $row_league) + { + // check if matches created + $existing_matches_on_league = count_existing_matches($row_league['season'], $row_league['league'], 0); + + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('leagues', array( + 'ROW_CLASS' => $row_class, + 'SEASON' => $row_league['season'], + 'LEAGUE' => $row_league['league'], + 'LEAGUE_NAME' => $row_league['league_name'], + 'LEAGUE_SHORT' => $row_league['league_name_short'], + 'MEMBERS' => $row_league['members'], + 'S_MEMBER' => ($existing_matches_on_league) ? true : false, + 'U_LIST' => "{$this->u_action}&action=list&s=" . $season . "&l=" .$row_league['league'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$row_league['league'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $row_league['league'] : '', + ) + ); + } + } +} ?> \ No newline at end of file diff --git a/acp/matchdays_module.php b/acp/matchdays_module.php index bcae002..1a9c48f 100644 --- a/acp/matchdays_module.php +++ b/acp/matchdays_module.php @@ -1,1134 +1,1132 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_matchdays'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_matchdays'; - $this->page_title = 'ACP_FOOTBALL_MATCHDAYS_MANAGE'; - - $form_key = 'acp_football_matchdays'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : ''; - $action = (isset($_POST['remove'])) ? 'remove' : $action; - $action = (isset($_POST['change_delivery'])) ? 'change_delivery' : $action; - $action = (isset($_POST['show_delivery'])) ? 'show_delivery' : $action; - $action = (isset($_POST['update_delivery'])) ? 'update_delivery' : $action; - $action = (empty($action)) ? $this->request->variable('action', '') : $action; - - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $update = (isset($_POST['update'])) ? true : false; - $backward_days = $this->request->variable('backward_days', 0); - $backward_hours = $this->request->variable('backward_hours', 0); - $backward_minutes = $this->request->variable('backward_minutes', 0); - - // Clear some vars - $matchday_row = array(); - $error = array(); - $show_delivery_select = true; - $show_delivery = false; - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = first_league($season, false); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $edit_delivery = !$row['bet_in_time']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for matchday, if matchday is set and exists - if ($matchday) - { - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - AND matchday = $matchday"; - $result = $db->sql_query($sql); - $matchday_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - // Which page? - switch ($action) - { - case 'update_delivery': - $show_delivery_select = false; - $count_updates = 0; - $sql = "SELECT - matchday - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $rows_matchdays = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - foreach ($rows_matchdays as $row_matchday) - { - $sql_ary = array(); - $matchday = $row_matchday['matchday']; - if ($this->request->variable('delivery_' . $matchday . '_1', false)) - { - $sql_ary['delivery_date'] = $this->request->variable('new_delivery_' . $matchday . '_1', ''); - } - if ($this->request->variable('delivery_' . $matchday . '_2', '')) - { - $sql_ary['delivery_date_2'] = $this->request->variable('new_delivery_' . $matchday . '_2', ''); - } - if ($this->request->variable('delivery_' . $matchday . '_3', '')) - { - $sql_ary['delivery_date_3'] = $this->request->variable('new_delivery_' . $matchday . '_3', ''); - } - if ( sizeof($sql_ary) ) - { - $count_updates = $count_updates + sizeof($sql_ary); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league - AND matchday = $matchday"; - $db->sql_query($sql); - } - } - if ($count_updates) - { - trigger_error(sprintf($user->lang['UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - trigger_error($user->lang['NO_DELIVERIES_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - break; - case 'show_delivery': - $show_delivery_select = false; - $show_delivery = true; - $lang_dates = $user->lang['datetime']; - $sql = "(SELECT md.matchday, - 1 AS number, - md.delivery_date, - CASE DATE_FORMAT(md.delivery_date,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS delivery_date_day, - DATE_FORMAT(DATE_SUB(agg.min_delivery_date, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, - CASE DATE_FORMAT(DATE_SUB(agg.min_delivery_date, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS new_delivery_day - FROM " . FOOTB_MATCHDAYS . " AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND status = 0 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday) - UNION - (SELECT md2.matchday, - 2 AS number, - md2.delivery_date_2 AS delivery_date, - CASE DATE_FORMAT(md2.delivery_date_2,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS delivery_date_day, - DATE_FORMAT(DATE_SUB(agg2.min_delivery_date_2, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, - CASE DATE_FORMAT(DATE_SUB(agg2.min_delivery_date_2, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS new_delivery_day - FROM " . FOOTB_MATCHDAYS . " AS md2 - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date_2 - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND status = -1 - GROUP BY season, league, matchday) AS agg2 - WHERE md2.season = agg2.season - AND md2.league = agg2.league - AND md2.matchday = agg2.matchday) - UNION - (SELECT md3.matchday, - 3 AS number, - md3.delivery_date_3 AS delivery_date, - CASE DATE_FORMAT(md3.delivery_date_3,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS delivery_date_day, - DATE_FORMAT(DATE_SUB(agg3.min_delivery_date_3, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, - CASE DATE_FORMAT(DATE_SUB(agg3.min_delivery_date_3, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' - END AS new_delivery_day - FROM " . FOOTB_MATCHDAYS . " AS md3 - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date_3 - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND status = -2 - GROUP BY season, league, matchday) AS agg3 - WHERE md3.season = agg3.season - AND md3.league = agg3.league - AND md3.matchday = agg3.matchday) - ORDER BY matchday ASC, number ASC"; - $result = $db->sql_query($sql); - $rows_matchdays = $db->sql_fetchrowset($result); - $row_number = 0; - foreach ($rows_matchdays as $row_matchday) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('delivery', array( - 'ROW_CLASS' => $row_class, - 'MATCHDAY' => $row_matchday['matchday'], - 'NUMBER' => $row_matchday['number'], - 'DELIVERY_ERROR' => ($row_matchday['delivery_date'] > $row_matchday['new_delivery_date']) ? true : false, - 'DELIVERY_DATE_DAY' => $row_matchday['delivery_date_day'], - 'DELIVERY_DATE' => $row_matchday['delivery_date'], - 'NEW_DELIVERY_DAY' => $row_matchday['new_delivery_day'], - 'NEW_DELIVERY' => $row_matchday['new_delivery_date'], - ) - ); - } - case 'change_delivery': - $edit_delivery = false; - $change_delivery = true; - $backwards_days_options = ''; - for ($i = 0; $i < 7; $i++) - { - $selected = ($i == $backward_days) ? ' selected="selected"' : ''; - $backwards_days_options .= ""; - } - $backwards_hours_options = ''; - for ($i = 0; $i < 24; $i++) - { - $selected = ($i == $backward_hours) ? ' selected="selected"' : ''; - $backwards_hours_options .= ""; - } - $backwards_minutes_options = ''; - for ($i = 0; $i < 60; $i = $i + 5) - { - $selected = ($i == $backward_minutes) ? ' selected="selected"' : ''; - $backwards_minutes_options .= ""; - } - - $u_back = $this->u_action . "&s=$season&l=$league"; - - $template->assign_vars(array( - 'S_EDIT' => false, - 'S_CHANGE_DELIVERY' => true, - 'S_SHOW_DELIVERY_SELECT' => $show_delivery_select, - 'S_SHOW_DELIVERY' => $show_delivery, - 'S_BACKWARD_DAYS_OPTIONS' => $backwards_days_options, - 'S_BACKWARD_HOURS_OPTIONS' => $backwards_hours_options, - 'S_BACKWARD_MINUTES_OPTIONS' => $backwards_minutes_options, - 'S_VERSION_NO' => $this->config['football_version'], - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", - ) - ); - return; - break; - case 'delete': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (!$matchday) - { - trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['MATCHDAYS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Delete matchday - $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND match_no IN - (SELECT DISTINCT - match_no - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday)"; - $db->sql_query($sql); - - // Delete matches - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - - trigger_error($user->lang['MATCHDAY_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - confirm_box(false, sprintf($user->lang['MATCHDAY_CONFIRM_DELETE'], $matchday, $season), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 'm' => $matchday, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'remove': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['MATCHDAYS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Delete matchday - $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND matchday > $league_matchdays"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND match_no IN - (SELECT DISTINCT - match_no - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday > $league_matchdays)"; - $db->sql_query($sql); - - // Delete matches - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND matchday > $league_matchdays"; - $db->sql_query($sql); - - trigger_error($user->lang['MATCHDAYS_REMOVED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - confirm_box(false, sprintf($user->lang['MATCHDAY_CONFIRM_REMOVE'], $season), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 'm' => $matchday, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add': - $sql = "SELECT - matchday - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $rows_matchdays = $db->sql_fetchrowset($result); - $existing_matchdays = sizeof($rows_matchdays); - $db->sql_freeresult($result); - if ($existing_matchdays < $league_matchdays) - { - $last_matchday = 0; - $count_updates = 0; - if ($existing_matchdays > 0) - { - foreach ($rows_matchdays as $row_exist) - { - if ($last_matchday + 1 < $row_exist['matchday']) - { - for ( $i = $last_matchday + 1; $i < $row_exist['matchday']; $i++ ) - { - $count_updates++; - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $i, - 'status' => 0, - 'delivery_date' => '', - 'delivery_date_2' => '', - 'delivery_date_3' => '', - 'matchday_name' => '', - 'matches' => 0, - ); - $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - $last_matchday = $row_exist['matchday']; - } - for ( $i = $last_matchday + 1; $i <= $league_matchdays; $i++ ) - { - $count_updates++; - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $i, - 'status' => 0, - 'delivery_date' => '', - 'delivery_date_2' => '', - 'delivery_date_3' => '', - 'matchday_name' => '', - 'matches' => 0, - ); - - $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - else - { - for ( $i = 1; $i <= $league_matchdays; $i++ ) - { - $count_updates++; - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $i, - 'status' => 0, - 'delivery_date' => '', - 'delivery_date_2' => '', - 'delivery_date_3' => '', - 'matchday_name' => '', - 'matches' => 0, - ); - - $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - $message = ($count_updates > 1) ? 'MATCHDAYS_CREATED' : 'MATCHDAY_CREATED'; - trigger_error(sprintf($user->lang[$message],$count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - trigger_error($user->lang['NO_MORE_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - // No break for edit add - case 'edit': - $data = array(); - $error_msg = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$matchday) - { - trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - $data = array( - 'dday1_day' => 0, - 'dday1_month' => 0, - 'dday1_year' => 0, - 'dday1_hour' => 0, - 'dday1_min' => 0, - 'dday2_day' => 0, - 'dday2_month' => 0, - 'dday2_year' => 0, - 'dday2_hour' => 0, - 'dday2_min' => 0, - 'dday3_day' => 0, - 'dday3_month' => 0, - 'dday3_year' => 0, - 'dday3_hour' => 0, - 'dday3_min' => 0, - ); - if ($matchday_row['delivery_date']) - { - list($data['dday1_date'], $data['dday1_time']) = explode(' ', $matchday_row['delivery_date']); - list($data['dday1_year'], $data['dday1_month'], $data['dday1_day']) = explode('-', $data['dday1_date']); - list($data['dday1_hour'], $data['dday1_min'], $data['dday1_sec']) = explode(':', $data['dday1_time']); - } - - $data['dday1_day'] = $this->request->variable('dday1_day', $data['dday1_day']); - $data['dday1_month'] = $this->request->variable('dday1_month', $data['dday1_month']); - $data['dday1_year'] = $this->request->variable('dday1_year', $data['dday1_year']); - $data['dday1_hour'] = $this->request->variable('dday1_hour', $data['dday1_hour']); - $data['dday1_min'] = $this->request->variable('dday1_min', $data['dday1_min']); - $data['dday1_sec'] = '00'; - $data['dday1_date'] = sprintf('%02d-%02d-%04d', $data['dday1_day'], $data['dday1_month'], $data['dday1_year']); - $data['dday1_time'] = sprintf('%02d:%02d:%02d', $data['dday1_hour'], $data['dday1_min'], $data['dday1_sec']); - $matchday_row['delivery_date'] = sprintf('%04d-%02d-%02d', $data['dday1_year'], $data['dday1_month'], $data['dday1_day']) . ' ' . $data['dday1_time']; - - if ($matchday_row['delivery_date_2']) - { - list($data['dday2_date'], $data['dday2_time']) = explode(' ', $matchday_row['delivery_date_2']); - list($data['dday2_year'], $data['dday2_month'], $data['dday2_day']) = explode('-', $data['dday2_date']); - list($data['dday2_hour'], $data['dday2_min'], $data['dday2_sec']) = explode(':', $data['dday2_time']); - } - - $data['dday2_day'] = $this->request->variable('dday2_day', $data['dday2_day']); - $data['dday2_month'] = $this->request->variable('dday2_month', $data['dday2_month']); - $data['dday2_year'] = $this->request->variable('dday2_year', $data['dday2_year']); - $data['dday2_hour'] = $this->request->variable('dday2_hour', $data['dday2_hour']); - $data['dday2_min'] = $this->request->variable('dday2_min', $data['dday2_min']); - $data['dday2_sec'] = '00'; - if (!$data['dday2_day'] and !$data['dday2_month'] and !$data['dday2_year']) - { - $matchday_row['delivery_date_2'] = ''; - $data['dday2_date'] = '01-01-1980'; - } - else - { - $data['dday2_date'] = sprintf('%02d-%02d-%04d', $data['dday2_day'], $data['dday2_month'], $data['dday2_year']); - $data['dday2_time'] = sprintf('%02d:%02d:%02d', $data['dday2_hour'], $data['dday2_min'], $data['dday2_sec']); - $matchday_row['delivery_date_2'] = sprintf('%04d-%02d-%02d', $data['dday2_year'], $data['dday2_month'], $data['dday2_day']) . - ' ' . $data['dday2_time']; - - } - - if ($matchday_row['delivery_date_3']) - { - list($data['dday3_date'], $data['dday3_time']) = explode(' ', $matchday_row['delivery_date_3']); - list($data['dday3_year'], $data['dday3_month'], $data['dday3_day']) = explode('-', $data['dday3_date']); - list($data['dday3_hour'], $data['dday3_min'], $data['dday3_sec']) = explode(':', $data['dday3_time']); - } - - $data['dday3_day'] = $this->request->variable('dday3_day', $data['dday3_day']); - $data['dday3_month'] = $this->request->variable('dday3_month', $data['dday3_month']); - $data['dday3_year'] = $this->request->variable('dday3_year', $data['dday3_year']); - $data['dday3_hour'] = $this->request->variable('dday3_hour', $data['dday3_hour']); - $data['dday3_min'] = $this->request->variable('dday3_min', $data['dday3_min']); - $data['dday3_sec'] = '00'; - if (!$data['dday3_day'] and !$data['dday3_month'] and !$data['dday3_year']) - { - $matchday_row['delivery_date_3'] = ''; - $data['dday3_date'] = '01-01-1980'; - } - else - { - $data['dday3_date'] = sprintf('%02d-%02d-%04d', $data['dday3_day'], $data['dday3_month'], $data['dday3_year']); - $data['dday3_time'] = sprintf('%02d:%02d:%02d', $data['dday3_hour'], $data['dday3_min'], $data['dday3_sec']); - $matchday_row['delivery_date_3'] = sprintf('%04d-%02d-%02d', $data['dday3_year'], $data['dday3_month'], $data['dday3_day']) . - ' ' . $data['dday3_time']; - } - - // Did we submit? - if ($update) - { - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - $matchday_row['matchday_name'] = utf8_normalize_nfc($this->request->variable('matchday_name', '', true)); - $matchday_row['status'] = utf8_normalize_nfc($this->request->variable('matchday_status', '', true)); - $matchday_row['matches'] = utf8_normalize_nfc($this->request->variable('matchday_matches', $matchday_row['matches'], true)); - - if ($data['dday1_day'] <> '--' and $data['dday1_month'] <> '--' and $data['dday1_year'] <> '--') - { - $delivery_timestamp = mktime($data['dday1_hour'], $data['dday1_min'], 0, $data['dday1_month'], $data['dday1_day'], $data['dday1_year']); - $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); - if ($delivery_timestamp > $local_board_time AND $matchday_row['status'] == 0) - { - // check if delivery is before all open matches - $sql = "SELECT - match_no - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday - AND status = 0 - AND match_datetime < FROM_UNIXTIME('$delivery_timestamp')"; - $result = $db->sql_query($sql); - $open_matches = ''; - while ($rows_open = $db->sql_fetchrow($result)) - { - $open_matches .= ($open_matches == '') ? $rows_open['match_no'] : ', ' . $rows_open['match_no']; - } - $db->sql_freeresult($result); - if ($open_matches <> '') - { - $error[] = (strpos($open_matches, ',')) ? sprintf($user->lang['OPEN_MATCHES'], $open_matches) : - sprintf($user->lang['OPEN_MATCH'], $open_matches); - } - } - - if ($delivery_timestamp > $local_board_time AND ($matchday_row['status'] == 1 OR $matchday_row['status'] == 2)) - { - $sql_ary = array( - 'status' => 0, - ); - // set all matches after delivery on status 0 - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season - AND league = $league - AND matchday = $matchday - AND status IN (1, 2) - AND match_datetime >= FROM_UNIXTIME('$delivery_timestamp')"; - $db->sql_query($sql); - // check on open matches - $sql = "SELECT - match_no - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday - AND status = 0"; - $result = $db->sql_query($sql); - if ($rows_open = $db->sql_fetchrow($result)) - { - // reopen matchday - $matchday_row['status'] = 0; - } - } - } - else - { - $error[] = $user->lang['NO_DELIVERY']; - } - - if ($data['dday2_day'] <> '--' and $data['dday2_month'] <> '--' and $data['dday2_year'] <> '--') - { - $delivery2_timestamp = mktime($data['dday2_hour'], $data['dday2_min'], 0, $data['dday2_month'], $data['dday2_day'], $data['dday2_year']); - if ($delivery2_timestamp < $delivery_timestamp) - { - $error[] = $user->lang['TOO_SMALL_DELIVERY2']; - } - } - else - { - $delivery2_timestamp = 0; - } - - if ($data['dday3_day'] <> '--' and $data['dday3_month'] <> '--' and $data['dday3_year'] <> '--') - { - if ($delivery2_timestamp == 0) - { - $error[] = $user->lang['NO_DELIVERY2']; - } - $delivery3_timestamp = mktime($data['dday3_hour'], $data['dday3_min'], 0, $data['dday3_month'], $data['dday3_day'], $data['dday3_year']); - if ($delivery3_timestamp < $delivery2_timestamp) - { - $error[] = $user->lang['TOO_SMALL_DELIVERY3']; - } - } - - if ($ko_league) - { - $data['matches'] = $matchday_row['matches']; - } - else - { - $data['matches'] = ''; - } - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $matchday, - 'status' => $matchday_row['status'], - 'delivery_date' => $matchday_row['delivery_date'], - 'delivery_date_2' => strlen($matchday_row['delivery_date_2']) ? $matchday_row['delivery_date_2'] : '', - 'delivery_date_3' => strlen($matchday_row['delivery_date_3']) ? $matchday_row['delivery_date_3'] : '', - 'matchday_name' => strlen($matchday_row['matchday_name']) ? $matchday_row['matchday_name'] : '', - 'matches' => strlen($matchday_row['matches']) ? $matchday_row['matches'] : 0, - ); - - $var_ary = array( - 'dday1_date' => array('date', false), - 'dday2_date' => array('date', false), - 'dday3_date' => array('date', false), - 'matches' => array('num', true, 1,99), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - trigger_error($user->lang['MATCHDAY_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $error[] = $user->lang['MATCHDAY_UPDATE_FAILED']; - $error = array_merge($error, $error_msg); - } - } - } - } - - $s_delivery1_day_options = ''; - for ($i = 1; $i < 32; $i++) - { - $selected = ($i == $data['dday1_day']) ? ' selected="selected"' : ''; - $s_delivery1_day_options .= ""; - } - - $s_delivery1_month_options = ''; - for ($i = 1; $i < 13; $i++) - { - $selected = ($i == $data['dday1_month']) ? ' selected="selected"' : ''; - $s_delivery1_month_options .= ""; - } - $s_delivery1_year_options = ''; - - $s_delivery1_year_options = ''; - for ($i = $season - 1 ; $i <= $season; $i++) - { - $selected = ($i == $data['dday1_year']) ? ' selected="selected"' : ''; - $s_delivery1_year_options .= ""; - } - - $s_delivery1_hour_options = ''; - if (!$data['dday1_hour']) - { - $data['dday1_hour'] = 0; - } - for ($i = 0; $i < 24; $i++) - { - $selected = ($i == $data['dday1_hour']) ? ' selected="selected"' : ''; - $s_delivery1_hour_options .= ""; - } - - $s_delivery1_min_options = ''; - if (!$data['dday1_min']) - { - $data['dday1_min'] = 0; - } - for ($i = 0; $i < 12; $i++) - { - $selected = (($i * 5) == $data['dday1_min']) ? ' selected="selected"' : ''; - $s_delivery1_min_options .= ""; - } - - $s_delivery2_day_options = ''; - for ($i = 1; $i < 32; $i++) - { - $selected = ($i == $data['dday2_day']) ? ' selected="selected"' : ''; - $s_delivery2_day_options .= ""; - } - - $s_delivery2_month_options = ''; - for ($i = 1; $i < 13; $i++) - { - $selected = ($i == $data['dday2_month']) ? ' selected="selected"' : ''; - $s_delivery2_month_options .= ""; - } - $s_delivery2_year_options = ''; - - $s_delivery2_year_options = ''; - for ($i = $season - 1 ; $i <= $season; $i++) - { - $selected = ($i == $data['dday2_year']) ? ' selected="selected"' : ''; - $s_delivery2_year_options .= ""; - } - - $s_delivery2_hour_options = ''; - if (!$data['dday2_hour']) - { - $data['dday2_hour'] = 0; - } - for ($i = 0; $i < 24; $i++) - { - $selected = ($i == $data['dday2_hour']) ? ' selected="selected"' : ''; - $s_delivery2_hour_options .= ""; - } - - $s_delivery2_min_options = ''; - if (!$data['dday2_min']) - { - $data['dday2_min'] = 0; - } - for ($i = 0; $i < 12; $i++) - { - $selected = (($i * 5) == $data['dday2_min']) ? ' selected="selected"' : ''; - $s_delivery2_min_options .= ""; - } - - $s_delivery3_day_options = ''; - for ($i = 1; $i < 32; $i++) - { - $selected = ($i == $data['dday3_day']) ? ' selected="selected"' : ''; - $s_delivery3_day_options .= ""; - } - - $s_delivery3_month_options = ''; - for ($i = 1; $i < 13; $i++) - { - $selected = ($i == $data['dday3_month']) ? ' selected="selected"' : ''; - $s_delivery3_month_options .= ""; - } - $s_delivery3_year_options = ''; - - $s_delivery3_year_options = ''; - for ($i = $season - 1 ; $i <= $season; $i++) - { - $selected = ($i == $data['dday3_year']) ? ' selected="selected"' : ''; - $s_delivery3_year_options .= ""; - } - - $s_delivery3_hour_options = ''; - if (!$data['dday3_hour']) - { - $data['dday3_hour'] = 0; - } - for ($i = 0; $i < 24; $i++) - { - $selected = ($i == $data['dday3_hour']) ? ' selected="selected"' : ''; - $s_delivery3_hour_options .= ""; - } - - $s_delivery3_min_options = ''; - if (!$data['dday3_min']) - { - $data['dday3_min'] = 0; - } - for ($i = 0; $i < 12; $i++) - { - $selected = (($i * 5) == $data['dday3_min']) ? ' selected="selected"' : ''; - $s_delivery3_min_options .= ""; - } - - - $status_options = ''; - for ( $i = 0; $i < 4; $i++ ) - { - $selected = ($matchday_row['status'] == $i) ? ' selected="selected"' : ''; - $status_options .= ''; - } - - // check if matches created - $existing_matches_on_matchday = count_existing_matches($season, $league, $matchday); - - $u_back = $this->u_action . "&s=$season&l=$league"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_MATCHDAY' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'S_KO_LEAGUE' => $ko_league, - 'S_EDIT_DELIVERY' => $edit_delivery, - 'S_UPDATE_DELIVERY' => false, - 'S_EDIT_MATCHES' => ($existing_matches_on_matchday) ? false : true, - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'MATCHDAY' => $matchday, - 'MATCHDAY_NAME' => $matchday_row['matchday_name'], - 'MATCHDAY_STATUS' => $matchday_row['status'], - 'MATCHDAY_MATCHES' => $matchday_row['matches'], - 'MATCHDAY_DEL1' => $matchday_row['delivery_date'], - 'MATCHDAY_DEL2' => $matchday_row['delivery_date_2'], - 'MATCHDAY_DEL3' => $matchday_row['delivery_date_3'], - 'S_DELIVERY1_DAY_OPTIONS' => $s_delivery1_day_options, - 'S_DELIVERY1_MONTH_OPTIONS' => $s_delivery1_month_options, - 'S_DELIVERY1_YEAR_OPTIONS' => $s_delivery1_year_options, - 'S_DELIVERY1_HOUR_OPTIONS' => $s_delivery1_hour_options, - 'S_DELIVERY1_MIN_OPTIONS' => $s_delivery1_min_options, - 'S_DELIVERY2_DAY_OPTIONS' => $s_delivery2_day_options, - 'S_DELIVERY2_MONTH_OPTIONS' => $s_delivery2_month_options, - 'S_DELIVERY2_YEAR_OPTIONS' => $s_delivery2_year_options, - 'S_DELIVERY2_HOUR_OPTIONS' => $s_delivery2_hour_options, - 'S_DELIVERY2_MIN_OPTIONS' => $s_delivery2_min_options, - 'S_DELIVERY3_DAY_OPTIONS' => $s_delivery3_day_options, - 'S_DELIVERY3_MONTH_OPTIONS' => $s_delivery3_month_options, - 'S_DELIVERY3_YEAR_OPTIONS' => $s_delivery3_year_options, - 'S_DELIVERY3_HOUR_OPTIONS' => $s_delivery3_hour_options, - 'S_DELIVERY3_MIN_OPTIONS' => $s_delivery3_min_options, - 'S_VERSION_NO' => $this->config['football_version'], - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", - ) - ); - - return; - break; - } - - // Get us all the matchdays - $lang_dates = $user->lang['datetime']; - $sql = "SELECT *, - CONCAT( - CASE DATE_FORMAT(delivery_date,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(delivery_date,' %d.%m.%y %H:%i') - ) AS match_time, - CONCAT( - CASE DATE_FORMAT(delivery_date_2,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(delivery_date_2,' %d.%m.%y %H:%i') - ) AS match_time_2, - CONCAT( - CASE DATE_FORMAT(delivery_date_3,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(delivery_date_3,' %d.%m.%y %H:%i') - ) AS match_time_3, - DATE_FORMAT(delivery_date, '%dd') AS deliveryday, - DATE_FORMAT(delivery_date, ' %d.%m.%Y um %H:%i ') AS delivery - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $rows_matchdays = $db->sql_fetchrowset($result); - $existing_matchdays = sizeof($rows_matchdays); - $db->sql_freeresult($result); - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_MATCHDAY_ADD' => ($league_matchdays > $existing_matchdays) ? true : false, - 'S_MATCHDAYS_REMOVE'=> ($league_matchdays < $existing_matchdays) ? true : false, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Check if the user is allowed to delete a matchday. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - foreach ($rows_matchdays as $row_matchday) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('matchdays', array( - 'ROW_CLASS' => $row_class, - 'MATCHDAY' => $row_matchday['matchday'], - 'MATCHDAY_NAME' => $row_matchday['matchday_name'], - 'MATCHDAY_STATUS' => $row_matchday['status'], - 'MATCHDAY_DELIVERY' => $row_matchday['match_time'], - 'MATCHDAY_DELIVERY_2' => $row_matchday['match_time_2'], - 'MATCHDAY_DELIVERY_3' => $row_matchday['match_time_3'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&m=" .$row_matchday['matchday'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&m=" . $row_matchday['matchday'] : '', - ) - ); - } - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_matchdays'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_matchdays'; + $this->page_title = 'ACP_FOOTBALL_MATCHDAYS_MANAGE'; + + $form_key = 'acp_football_matchdays'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : ''; + $action = (isset($_POST['remove'])) ? 'remove' : $action; + $action = (isset($_POST['change_delivery'])) ? 'change_delivery' : $action; + $action = (isset($_POST['show_delivery'])) ? 'show_delivery' : $action; + $action = (isset($_POST['update_delivery'])) ? 'update_delivery' : $action; + $action = (empty($action)) ? $this->request->variable('action', '') : $action; + + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $update = (isset($_POST['update'])) ? true : false; + $backward_days = $this->request->variable('backward_days', 0); + $backward_hours = $this->request->variable('backward_hours', 0); + $backward_minutes = $this->request->variable('backward_minutes', 0); + + // Clear some vars + $matchday_row = array(); + $error = array(); + $show_delivery_select = true; + $show_delivery = false; + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = first_league($season, false); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $edit_delivery = !$row['bet_in_time']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for matchday, if matchday is set and exists + if ($matchday) + { + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + AND matchday = $matchday"; + $result = $db->sql_query($sql); + $matchday_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + // Which page? + switch ($action) + { + case 'update_delivery': + $show_delivery_select = false; + $count_updates = 0; + $sql = "SELECT + matchday + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $rows_matchdays = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + foreach ($rows_matchdays as $row_matchday) + { + $sql_ary = array(); + $matchday = $row_matchday['matchday']; + if ($this->request->variable('delivery_' . $matchday . '_1', false)) + { + $sql_ary['delivery_date'] = $this->request->variable('new_delivery_' . $matchday . '_1', ''); + } + if ($this->request->variable('delivery_' . $matchday . '_2', '')) + { + $sql_ary['delivery_date_2'] = $this->request->variable('new_delivery_' . $matchday . '_2', ''); + } + if ($this->request->variable('delivery_' . $matchday . '_3', '')) + { + $sql_ary['delivery_date_3'] = $this->request->variable('new_delivery_' . $matchday . '_3', ''); + } + if ( sizeof($sql_ary) ) + { + $count_updates = $count_updates + sizeof($sql_ary); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league + AND matchday = $matchday"; + $db->sql_query($sql); + } + } + if ($count_updates) + { + trigger_error(sprintf($user->lang['UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + trigger_error($user->lang['NO_DELIVERIES_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + break; + case 'show_delivery': + $show_delivery_select = false; + $show_delivery = true; + $lang_dates = $user->lang['datetime']; + $sql = "(SELECT md.matchday, + 1 AS number, + md.delivery_date, + CASE DATE_FORMAT(md.delivery_date,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS delivery_date_day, + DATE_FORMAT(DATE_SUB(agg.min_delivery_date, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, + CASE DATE_FORMAT(DATE_SUB(agg.min_delivery_date, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS new_delivery_day + FROM " . FOOTB_MATCHDAYS . " AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND status = 0 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday) + UNION + (SELECT md2.matchday, + 2 AS number, + md2.delivery_date_2 AS delivery_date, + CASE DATE_FORMAT(md2.delivery_date_2,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS delivery_date_day, + DATE_FORMAT(DATE_SUB(agg2.min_delivery_date_2, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, + CASE DATE_FORMAT(DATE_SUB(agg2.min_delivery_date_2, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS new_delivery_day + FROM " . FOOTB_MATCHDAYS . " AS md2 + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date_2 + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND status = -1 + GROUP BY season, league, matchday) AS agg2 + WHERE md2.season = agg2.season + AND md2.league = agg2.league + AND md2.matchday = agg2.matchday) + UNION + (SELECT md3.matchday, + 3 AS number, + md3.delivery_date_3 AS delivery_date, + CASE DATE_FORMAT(md3.delivery_date_3,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS delivery_date_day, + DATE_FORMAT(DATE_SUB(agg3.min_delivery_date_3, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE),'%Y-%m-%d %H:%i:%s') AS new_delivery_date, + CASE DATE_FORMAT(DATE_SUB(agg3.min_delivery_date_3, INTERVAL '" . $backward_days . ' ' . $backward_hours . ':' . sprintf('%02d', $backward_minutes) . "' DAY_MINUTE), '%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' + END AS new_delivery_day + FROM " . FOOTB_MATCHDAYS . " AS md3 + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date_3 + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND status = -2 + GROUP BY season, league, matchday) AS agg3 + WHERE md3.season = agg3.season + AND md3.league = agg3.league + AND md3.matchday = agg3.matchday) + ORDER BY matchday ASC, number ASC"; + $result = $db->sql_query($sql); + $rows_matchdays = $db->sql_fetchrowset($result); + $row_number = 0; + foreach ($rows_matchdays as $row_matchday) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('delivery', array( + 'ROW_CLASS' => $row_class, + 'MATCHDAY' => $row_matchday['matchday'], + 'NUMBER' => $row_matchday['number'], + 'DELIVERY_ERROR' => ($row_matchday['delivery_date'] > $row_matchday['new_delivery_date']) ? true : false, + 'DELIVERY_DATE_DAY' => $row_matchday['delivery_date_day'], + 'DELIVERY_DATE' => $row_matchday['delivery_date'], + 'NEW_DELIVERY_DAY' => $row_matchday['new_delivery_day'], + 'NEW_DELIVERY' => $row_matchday['new_delivery_date'], + ) + ); + } + case 'change_delivery': + $edit_delivery = false; + $change_delivery = true; + $backwards_days_options = ''; + for ($i = 0; $i < 7; $i++) + { + $selected = ($i == $backward_days) ? ' selected="selected"' : ''; + $backwards_days_options .= ""; + } + $backwards_hours_options = ''; + for ($i = 0; $i < 24; $i++) + { + $selected = ($i == $backward_hours) ? ' selected="selected"' : ''; + $backwards_hours_options .= ""; + } + $backwards_minutes_options = ''; + for ($i = 0; $i < 60; $i = $i + 5) + { + $selected = ($i == $backward_minutes) ? ' selected="selected"' : ''; + $backwards_minutes_options .= ""; + } + + $u_back = $this->u_action . "&s=$season&l=$league"; + + $template->assign_vars(array( + 'S_EDIT' => false, + 'S_CHANGE_DELIVERY' => true, + 'S_SHOW_DELIVERY_SELECT' => $show_delivery_select, + 'S_SHOW_DELIVERY' => $show_delivery, + 'S_BACKWARD_DAYS_OPTIONS' => $backwards_days_options, + 'S_BACKWARD_HOURS_OPTIONS' => $backwards_hours_options, + 'S_BACKWARD_MINUTES_OPTIONS' => $backwards_minutes_options, + 'S_VERSION_NO' => $this->config['football_version'], + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", + ) + ); + return; + break; + case 'delete': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (!$matchday) + { + trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['MATCHDAYS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Delete matchday + $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND match_no IN + (SELECT DISTINCT + match_no + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday)"; + $db->sql_query($sql); + + // Delete matches + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + + trigger_error($user->lang['MATCHDAY_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + confirm_box(false, sprintf($user->lang['MATCHDAY_CONFIRM_DELETE'], $matchday, $season), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 'm' => $matchday, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + case 'remove': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['MATCHDAYS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Delete matchday + $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND matchday > $league_matchdays"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND match_no IN + (SELECT DISTINCT + match_no + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday > $league_matchdays)"; + $db->sql_query($sql); + + // Delete matches + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND matchday > $league_matchdays"; + $db->sql_query($sql); + + trigger_error($user->lang['MATCHDAYS_REMOVED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + confirm_box(false, sprintf($user->lang['MATCHDAY_CONFIRM_REMOVE'], $season), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 'm' => $matchday, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add': + $sql = "SELECT + matchday + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $rows_matchdays = $db->sql_fetchrowset($result); + $existing_matchdays = sizeof($rows_matchdays); + $db->sql_freeresult($result); + if ($existing_matchdays < $league_matchdays) + { + $last_matchday = 0; + $count_updates = 0; + if ($existing_matchdays > 0) + { + foreach ($rows_matchdays as $row_exist) + { + if ($last_matchday + 1 < $row_exist['matchday']) + { + for ( $i = $last_matchday + 1; $i < $row_exist['matchday']; $i++ ) + { + $count_updates++; + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $i, + 'status' => 0, + 'delivery_date' => '', + 'delivery_date_2' => '', + 'delivery_date_3' => '', + 'matchday_name' => '', + 'matches' => 0, + ); + $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + $last_matchday = $row_exist['matchday']; + } + for ( $i = $last_matchday + 1; $i <= $league_matchdays; $i++ ) + { + $count_updates++; + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $i, + 'status' => 0, + 'delivery_date' => '', + 'delivery_date_2' => '', + 'delivery_date_3' => '', + 'matchday_name' => '', + 'matches' => 0, + ); + + $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + else + { + for ( $i = 1; $i <= $league_matchdays; $i++ ) + { + $count_updates++; + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $i, + 'status' => 0, + 'delivery_date' => '', + 'delivery_date_2' => '', + 'delivery_date_3' => '', + 'matchday_name' => '', + 'matches' => 0, + ); + + $sql = 'INSERT INTO ' . FOOTB_MATCHDAYS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + $message = ($count_updates > 1) ? 'MATCHDAYS_CREATED' : 'MATCHDAY_CREATED'; + trigger_error(sprintf($user->lang[$message],$count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + trigger_error($user->lang['NO_MORE_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + // No break for edit add + case 'edit': + $data = array(); + $error_msg = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$matchday) + { + trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + $data = array( + 'dday1_day' => 0, + 'dday1_month' => 0, + 'dday1_year' => 0, + 'dday1_hour' => 0, + 'dday1_min' => 0, + 'dday2_day' => 0, + 'dday2_month' => 0, + 'dday2_year' => 0, + 'dday2_hour' => 0, + 'dday2_min' => 0, + 'dday3_day' => 0, + 'dday3_month' => 0, + 'dday3_year' => 0, + 'dday3_hour' => 0, + 'dday3_min' => 0, + ); + if ($matchday_row['delivery_date']) + { + list($data['dday1_date'], $data['dday1_time']) = explode(' ', $matchday_row['delivery_date']); + list($data['dday1_year'], $data['dday1_month'], $data['dday1_day']) = explode('-', $data['dday1_date']); + list($data['dday1_hour'], $data['dday1_min'], $data['dday1_sec']) = explode(':', $data['dday1_time']); + } + + $data['dday1_day'] = $this->request->variable('dday1_day', $data['dday1_day']); + $data['dday1_month'] = $this->request->variable('dday1_month', $data['dday1_month']); + $data['dday1_year'] = $this->request->variable('dday1_year', $data['dday1_year']); + $data['dday1_hour'] = $this->request->variable('dday1_hour', $data['dday1_hour']); + $data['dday1_min'] = $this->request->variable('dday1_min', $data['dday1_min']); + $data['dday1_sec'] = '00'; + $data['dday1_date'] = sprintf('%02d-%02d-%04d', $data['dday1_day'], $data['dday1_month'], $data['dday1_year']); + $data['dday1_time'] = sprintf('%02d:%02d:%02d', $data['dday1_hour'], $data['dday1_min'], $data['dday1_sec']); + $matchday_row['delivery_date'] = sprintf('%04d-%02d-%02d', $data['dday1_year'], $data['dday1_month'], $data['dday1_day']) . ' ' . $data['dday1_time']; + + if ($matchday_row['delivery_date_2']) + { + list($data['dday2_date'], $data['dday2_time']) = explode(' ', $matchday_row['delivery_date_2']); + list($data['dday2_year'], $data['dday2_month'], $data['dday2_day']) = explode('-', $data['dday2_date']); + list($data['dday2_hour'], $data['dday2_min'], $data['dday2_sec']) = explode(':', $data['dday2_time']); + } + + $data['dday2_day'] = $this->request->variable('dday2_day', $data['dday2_day']); + $data['dday2_month'] = $this->request->variable('dday2_month', $data['dday2_month']); + $data['dday2_year'] = $this->request->variable('dday2_year', $data['dday2_year']); + $data['dday2_hour'] = $this->request->variable('dday2_hour', $data['dday2_hour']); + $data['dday2_min'] = $this->request->variable('dday2_min', $data['dday2_min']); + $data['dday2_sec'] = '00'; + if (!$data['dday2_day'] and !$data['dday2_month'] and !$data['dday2_year']) + { + $matchday_row['delivery_date_2'] = ''; + $data['dday2_date'] = '01-01-1980'; + } + else + { + $data['dday2_date'] = sprintf('%02d-%02d-%04d', $data['dday2_day'], $data['dday2_month'], $data['dday2_year']); + $data['dday2_time'] = sprintf('%02d:%02d:%02d', $data['dday2_hour'], $data['dday2_min'], $data['dday2_sec']); + $matchday_row['delivery_date_2'] = sprintf('%04d-%02d-%02d', $data['dday2_year'], $data['dday2_month'], $data['dday2_day']) . + ' ' . $data['dday2_time']; + + } + + if ($matchday_row['delivery_date_3']) + { + list($data['dday3_date'], $data['dday3_time']) = explode(' ', $matchday_row['delivery_date_3']); + list($data['dday3_year'], $data['dday3_month'], $data['dday3_day']) = explode('-', $data['dday3_date']); + list($data['dday3_hour'], $data['dday3_min'], $data['dday3_sec']) = explode(':', $data['dday3_time']); + } + + $data['dday3_day'] = $this->request->variable('dday3_day', $data['dday3_day']); + $data['dday3_month'] = $this->request->variable('dday3_month', $data['dday3_month']); + $data['dday3_year'] = $this->request->variable('dday3_year', $data['dday3_year']); + $data['dday3_hour'] = $this->request->variable('dday3_hour', $data['dday3_hour']); + $data['dday3_min'] = $this->request->variable('dday3_min', $data['dday3_min']); + $data['dday3_sec'] = '00'; + if (!$data['dday3_day'] and !$data['dday3_month'] and !$data['dday3_year']) + { + $matchday_row['delivery_date_3'] = ''; + $data['dday3_date'] = '01-01-1980'; + } + else + { + $data['dday3_date'] = sprintf('%02d-%02d-%04d', $data['dday3_day'], $data['dday3_month'], $data['dday3_year']); + $data['dday3_time'] = sprintf('%02d:%02d:%02d', $data['dday3_hour'], $data['dday3_min'], $data['dday3_sec']); + $matchday_row['delivery_date_3'] = sprintf('%04d-%02d-%02d', $data['dday3_year'], $data['dday3_month'], $data['dday3_day']) . + ' ' . $data['dday3_time']; + } + + // Did we submit? + if ($update) + { + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + $matchday_row['matchday_name'] = utf8_normalize_nfc($this->request->variable('matchday_name', '', true)); + $matchday_row['status'] = utf8_normalize_nfc($this->request->variable('matchday_status', '', true)); + $matchday_row['matches'] = utf8_normalize_nfc($this->request->variable('matchday_matches', $matchday_row['matches'], true)); + + if ($data['dday1_day'] <> '--' and $data['dday1_month'] <> '--' and $data['dday1_year'] <> '--') + { + $delivery_timestamp = mktime($data['dday1_hour'], $data['dday1_min'], 0, $data['dday1_month'], $data['dday1_day'], $data['dday1_year']); + $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); + if ($delivery_timestamp > $local_board_time AND $matchday_row['status'] == 0) + { + // check if delivery is before all open matches + $sql = "SELECT + match_no + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday + AND status = 0 + AND match_datetime < FROM_UNIXTIME('$delivery_timestamp')"; + $result = $db->sql_query($sql); + $open_matches = ''; + while ($rows_open = $db->sql_fetchrow($result)) + { + $open_matches .= ($open_matches == '') ? $rows_open['match_no'] : ', ' . $rows_open['match_no']; + } + $db->sql_freeresult($result); + if ($open_matches <> '') + { + $error[] = (strpos($open_matches, ',')) ? sprintf($user->lang['OPEN_MATCHES'], $open_matches) : + sprintf($user->lang['OPEN_MATCH'], $open_matches); + } + } + + if ($delivery_timestamp > $local_board_time AND ($matchday_row['status'] == 1 OR $matchday_row['status'] == 2)) + { + $sql_ary = array( + 'status' => 0, + ); + // set all matches after delivery on status 0 + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season + AND league = $league + AND matchday = $matchday + AND status IN (1, 2) + AND match_datetime >= FROM_UNIXTIME('$delivery_timestamp')"; + $db->sql_query($sql); + // check on open matches + $sql = "SELECT + match_no + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday + AND status = 0"; + $result = $db->sql_query($sql); + if ($rows_open = $db->sql_fetchrow($result)) + { + // reopen matchday + $matchday_row['status'] = 0; + } + } + } + else + { + $error[] = $user->lang['NO_DELIVERY']; + } + + if ($data['dday2_day'] <> '--' and $data['dday2_month'] <> '--' and $data['dday2_year'] <> '--') + { + $delivery2_timestamp = mktime($data['dday2_hour'], $data['dday2_min'], 0, $data['dday2_month'], $data['dday2_day'], $data['dday2_year']); + if ($delivery2_timestamp < $delivery_timestamp) + { + $error[] = $user->lang['TOO_SMALL_DELIVERY2']; + } + } + else + { + $delivery2_timestamp = 0; + } + + if ($data['dday3_day'] <> '--' and $data['dday3_month'] <> '--' and $data['dday3_year'] <> '--') + { + if ($delivery2_timestamp == 0) + { + $error[] = $user->lang['NO_DELIVERY2']; + } + $delivery3_timestamp = mktime($data['dday3_hour'], $data['dday3_min'], 0, $data['dday3_month'], $data['dday3_day'], $data['dday3_year']); + if ($delivery3_timestamp < $delivery2_timestamp) + { + $error[] = $user->lang['TOO_SMALL_DELIVERY3']; + } + } + + if ($ko_league) + { + $data['matches'] = $matchday_row['matches']; + } + else + { + $data['matches'] = ''; + } + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $matchday, + 'status' => $matchday_row['status'], + 'delivery_date' => $matchday_row['delivery_date'], + 'delivery_date_2' => strlen($matchday_row['delivery_date_2']) ? $matchday_row['delivery_date_2'] : '', + 'delivery_date_3' => strlen($matchday_row['delivery_date_3']) ? $matchday_row['delivery_date_3'] : '', + 'matchday_name' => strlen($matchday_row['matchday_name']) ? $matchday_row['matchday_name'] : '', + 'matches' => strlen($matchday_row['matches']) ? $matchday_row['matches'] : 0, + ); + + $var_ary = array( + 'dday1_date' => array('date', false), + 'dday2_date' => array('date', false), + 'dday3_date' => array('date', false), + 'matches' => array('num', true, 1,99), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + trigger_error($user->lang['MATCHDAY_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $error[] = $user->lang['MATCHDAY_UPDATE_FAILED']; + $error = array_merge($error, $error_msg); + } + } + } + } + + $s_delivery1_day_options = ''; + for ($i = 1; $i < 32; $i++) + { + $selected = ($i == $data['dday1_day']) ? ' selected="selected"' : ''; + $s_delivery1_day_options .= ""; + } + + $s_delivery1_month_options = ''; + for ($i = 1; $i < 13; $i++) + { + $selected = ($i == $data['dday1_month']) ? ' selected="selected"' : ''; + $s_delivery1_month_options .= ""; + } + $s_delivery1_year_options = ''; + + $s_delivery1_year_options = ''; + for ($i = $season - 1 ; $i <= $season; $i++) + { + $selected = ($i == $data['dday1_year']) ? ' selected="selected"' : ''; + $s_delivery1_year_options .= ""; + } + + $s_delivery1_hour_options = ''; + if (!$data['dday1_hour']) + { + $data['dday1_hour'] = 0; + } + for ($i = 0; $i < 24; $i++) + { + $selected = ($i == $data['dday1_hour']) ? ' selected="selected"' : ''; + $s_delivery1_hour_options .= ""; + } + + $s_delivery1_min_options = ''; + if (!$data['dday1_min']) + { + $data['dday1_min'] = 0; + } + for ($i = 0; $i < 12; $i++) + { + $selected = (($i * 5) == $data['dday1_min']) ? ' selected="selected"' : ''; + $s_delivery1_min_options .= ""; + } + + $s_delivery2_day_options = ''; + for ($i = 1; $i < 32; $i++) + { + $selected = ($i == $data['dday2_day']) ? ' selected="selected"' : ''; + $s_delivery2_day_options .= ""; + } + + $s_delivery2_month_options = ''; + for ($i = 1; $i < 13; $i++) + { + $selected = ($i == $data['dday2_month']) ? ' selected="selected"' : ''; + $s_delivery2_month_options .= ""; + } + $s_delivery2_year_options = ''; + + $s_delivery2_year_options = ''; + for ($i = $season - 1 ; $i <= $season; $i++) + { + $selected = ($i == $data['dday2_year']) ? ' selected="selected"' : ''; + $s_delivery2_year_options .= ""; + } + + $s_delivery2_hour_options = ''; + if (!$data['dday2_hour']) + { + $data['dday2_hour'] = 0; + } + for ($i = 0; $i < 24; $i++) + { + $selected = ($i == $data['dday2_hour']) ? ' selected="selected"' : ''; + $s_delivery2_hour_options .= ""; + } + + $s_delivery2_min_options = ''; + if (!$data['dday2_min']) + { + $data['dday2_min'] = 0; + } + for ($i = 0; $i < 12; $i++) + { + $selected = (($i * 5) == $data['dday2_min']) ? ' selected="selected"' : ''; + $s_delivery2_min_options .= ""; + } + + $s_delivery3_day_options = ''; + for ($i = 1; $i < 32; $i++) + { + $selected = ($i == $data['dday3_day']) ? ' selected="selected"' : ''; + $s_delivery3_day_options .= ""; + } + + $s_delivery3_month_options = ''; + for ($i = 1; $i < 13; $i++) + { + $selected = ($i == $data['dday3_month']) ? ' selected="selected"' : ''; + $s_delivery3_month_options .= ""; + } + $s_delivery3_year_options = ''; + + $s_delivery3_year_options = ''; + for ($i = $season - 1 ; $i <= $season; $i++) + { + $selected = ($i == $data['dday3_year']) ? ' selected="selected"' : ''; + $s_delivery3_year_options .= ""; + } + + $s_delivery3_hour_options = ''; + if (!$data['dday3_hour']) + { + $data['dday3_hour'] = 0; + } + for ($i = 0; $i < 24; $i++) + { + $selected = ($i == $data['dday3_hour']) ? ' selected="selected"' : ''; + $s_delivery3_hour_options .= ""; + } + + $s_delivery3_min_options = ''; + if (!$data['dday3_min']) + { + $data['dday3_min'] = 0; + } + for ($i = 0; $i < 12; $i++) + { + $selected = (($i * 5) == $data['dday3_min']) ? ' selected="selected"' : ''; + $s_delivery3_min_options .= ""; + } + + + $status_options = ''; + for ( $i = 0; $i < 4; $i++ ) + { + $selected = ($matchday_row['status'] == $i) ? ' selected="selected"' : ''; + $status_options .= ''; + } + + // check if matches created + $existing_matches_on_matchday = count_existing_matches($season, $league, $matchday); + + $u_back = $this->u_action . "&s=$season&l=$league"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_MATCHDAY' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'S_KO_LEAGUE' => $ko_league, + 'S_EDIT_DELIVERY' => $edit_delivery, + 'S_UPDATE_DELIVERY' => false, + 'S_EDIT_MATCHES' => ($existing_matches_on_matchday) ? false : true, + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'MATCHDAY' => $matchday, + 'MATCHDAY_NAME' => $matchday_row['matchday_name'], + 'MATCHDAY_STATUS' => $matchday_row['status'], + 'MATCHDAY_MATCHES' => $matchday_row['matches'], + 'MATCHDAY_DEL1' => $matchday_row['delivery_date'], + 'MATCHDAY_DEL2' => $matchday_row['delivery_date_2'], + 'MATCHDAY_DEL3' => $matchday_row['delivery_date_3'], + 'S_DELIVERY1_DAY_OPTIONS' => $s_delivery1_day_options, + 'S_DELIVERY1_MONTH_OPTIONS' => $s_delivery1_month_options, + 'S_DELIVERY1_YEAR_OPTIONS' => $s_delivery1_year_options, + 'S_DELIVERY1_HOUR_OPTIONS' => $s_delivery1_hour_options, + 'S_DELIVERY1_MIN_OPTIONS' => $s_delivery1_min_options, + 'S_DELIVERY2_DAY_OPTIONS' => $s_delivery2_day_options, + 'S_DELIVERY2_MONTH_OPTIONS' => $s_delivery2_month_options, + 'S_DELIVERY2_YEAR_OPTIONS' => $s_delivery2_year_options, + 'S_DELIVERY2_HOUR_OPTIONS' => $s_delivery2_hour_options, + 'S_DELIVERY2_MIN_OPTIONS' => $s_delivery2_min_options, + 'S_DELIVERY3_DAY_OPTIONS' => $s_delivery3_day_options, + 'S_DELIVERY3_MONTH_OPTIONS' => $s_delivery3_month_options, + 'S_DELIVERY3_YEAR_OPTIONS' => $s_delivery3_year_options, + 'S_DELIVERY3_HOUR_OPTIONS' => $s_delivery3_hour_options, + 'S_DELIVERY3_MIN_OPTIONS' => $s_delivery3_min_options, + 'S_VERSION_NO' => $this->config['football_version'], + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", + ) + ); + + return; + break; + } + + // Get us all the matchdays + $lang_dates = $user->lang['datetime']; + $sql = "SELECT *, + CONCAT( + CASE DATE_FORMAT(delivery_date,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(delivery_date,' %d.%m.%y %H:%i') + ) AS match_time, + CONCAT( + CASE DATE_FORMAT(delivery_date_2,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(delivery_date_2,' %d.%m.%y %H:%i') + ) AS match_time_2, + CONCAT( + CASE DATE_FORMAT(delivery_date_3,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(delivery_date_3,' %d.%m.%y %H:%i') + ) AS match_time_3, + DATE_FORMAT(delivery_date, '%dd') AS deliveryday, + DATE_FORMAT(delivery_date, ' %d.%m.%Y um %H:%i ') AS delivery + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $rows_matchdays = $db->sql_fetchrowset($result); + $existing_matchdays = sizeof($rows_matchdays); + $db->sql_freeresult($result); + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_MATCHDAY_ADD' => ($league_matchdays > $existing_matchdays) ? true : false, + 'S_MATCHDAYS_REMOVE'=> ($league_matchdays < $existing_matchdays) ? true : false, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Check if the user is allowed to delete a matchday. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + foreach ($rows_matchdays as $row_matchday) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('matchdays', array( + 'ROW_CLASS' => $row_class, + 'MATCHDAY' => $row_matchday['matchday'], + 'MATCHDAY_NAME' => $row_matchday['matchday_name'], + 'MATCHDAY_STATUS' => $row_matchday['status'], + 'MATCHDAY_DELIVERY' => $row_matchday['match_time'], + 'MATCHDAY_DELIVERY_2' => $row_matchday['match_time_2'], + 'MATCHDAY_DELIVERY_3' => $row_matchday['match_time_3'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&m=" .$row_matchday['matchday'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&m=" . $row_matchday['matchday'] : '', + ) + ); + } + } +} ?> \ No newline at end of file diff --git a/acp/matches_module.php b/acp/matches_module.php index 7420566..0522a50 100644 --- a/acp/matches_module.php +++ b/acp/matches_module.php @@ -1,767 +1,765 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_matches'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_matches'; - $this->page_title = 'ACP_FOOTBALL_MATCHES_MANAGE'; - - $form_key = 'acp_football_matches'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $match_number = $this->request->variable('g', 0); - $update = (isset($_POST['update'])) ? true : false; - - // Clear some vars - $match_row = array(); - $error = array(); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = current_league($season, false); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_info = $row; - $league_matchdays = $row['matchdays']; - $matches_matchday = $row['matches_on_matchday']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for select matchday - if (!$matchday) - { - $matchday = curr_matchday($season, $league); - } - $sql = 'SELECT *, - UNIX_TIMESTAMP(delivery_date) AS unix_delivery_date - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $delivery2 = ''; - $delivery3 = ''; - $matchday_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - if ($selected <> '') - { - $unix_delivery_date = $row['unix_delivery_date']; - $delivery2 = $row['delivery_date_2']; - $delivery3 = $row['delivery_date_3']; - $matchday_name = $day_name; - if ($matches_matchday) - { - $matches_on_matchday = $matches_matchday; - } - else - { - $matches_on_matchday = $row['matches']; - } - } - } - $db->sql_freeresult($result); - if ($matchday_options == '') - { - trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Grab basic data for match, if match is set and exists - if ($match_number) - { - $sql = 'SELECT * - FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND match_no = $match_number"; - $result = $db->sql_query($sql); - $match_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - // Which page? - switch ($action) - { - case 'delete': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (!$matchday) - { - trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['MATCHES_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); - } - - // Delete match - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND match_no = $match_number"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season AND league = $league AND match_no = $match_number"; - $db->sql_query($sql); - - trigger_error($user->lang['MATCH_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); - } - else - { - confirm_box(false, sprintf($user->lang['MATCH_CONFIRM_DELETE'], $match_row['match_no'], $league_name, $season), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 'm' => $matchday, - 'g' => $match_number, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add': - $sql = "SELECT DISTINCT user_id - FROM " . FOOTB_BETS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - $rows_users = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $sql = "SELECT - matchday, - matches AS matches_matchday, - delivery_date - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $rows_matchdays = $db->sql_fetchrowset($result); - $existing_matchdays = sizeof($rows_matchdays); - $db->sql_freeresult($result); - if ($existing_matchdays < $league_matchdays) - { - trigger_error($user->lang['MATCHDAY_MISSED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); - } - else - { - $current_match = 0; - $count_updates = 0; - $sql_betary = array(); - foreach ($rows_matchdays as $current_matchday) - { - if ($matches_matchday) - { - $matches_on_matchday = $matches_matchday; - } - else - { - $matches_on_matchday = $current_matchday['matches_matchday']; - } - for ( $i = 1; $i <= $matches_on_matchday; $i++ ) - { - $current_match++; - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'match_no' => (int) $current_match, - 'team_id_home' => 0, - 'team_id_guest' => 0, - 'goals_home' => '', - 'goals_guest' => '', - 'matchday' => $current_matchday['matchday'], - 'status' => 0, - 'odd_1' => 0, - 'odd_x' => 0, - 'odd_2' => 0, - 'rating' => 0, - 'match_datetime' => $current_matchday['delivery_date'], - 'group_id' => '', - 'formula_home' => '', - 'formula_guest' => '', - 'ko_match' => 0, - 'goals_overtime_home' => '', - 'goals_overtime_guest' => '', - ); - $sql = 'INSERT IGNORE INTO ' . FOOTB_MATCHES . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - if ($db->sql_affectedrows()) - { - $count_updates++; - foreach ($rows_users as $current_user) - { - $sql_betary[] = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'match_no' => (int) $current_match, - 'user_id' => $current_user['user_id'], - 'goals_home' => '', - 'goals_guest' => '', - 'bet_time' => 0, - ); - } - } - } - } - if (sizeof($sql_betary)) - { - $db->sql_multi_insert(FOOTB_BETS, $sql_betary); - } - $message = ($count_updates > 1) ? 'MATCHES_CREATED' : 'MATCH_CREATED'; - trigger_error(sprintf($user->lang[$message],$count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); - } - break; - case 'edit': - $data = array(); - $error_msg = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$match_number) - { - trigger_error($user->lang['NO_MATCH'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); - } - - $data = array( - 'mday_day' => 0, - 'mday_month' => 0, - 'mday_year' => 0, - 'mday_hour' => 0, - 'mday_min' => 0, - ); - if ($match_row['match_datetime']) - { - list($data['mday_date'], $data['mday_time']) = explode(' ', $match_row['match_datetime']); - list($data['mday_year'], $data['mday_month'], $data['mday_day']) = explode('-', $data['mday_date']); - list($data['mday_hour'], $data['mday_min'], $data['mday_sec']) = explode(':', $data['mday_time']); - } - - $data['mday_day'] = $this->request->variable('mday_day', $data['mday_day']); - $data['mday_month'] = $this->request->variable('mday_month', $data['mday_month']); - $data['mday_year'] = $this->request->variable('mday_year', $data['mday_year']); - $data['mday_hour'] = $this->request->variable('mday_hour', $data['mday_hour']); - $data['mday_min'] = $this->request->variable('mday_min', $data['mday_min']); - $data['mday_sec'] = '00'; - $data['mday_date'] = sprintf('%02d-%02d-%04d', $data['mday_day'], $data['mday_month'], $data['mday_year']); - $data['mday_time'] = sprintf('%02d:%02d:%02d', $data['mday_hour'], $data['mday_min'], $data['mday_sec']); - $match_row['match_datetime'] = sprintf('%04d-%02d-%02d', $data['mday_year'], $data['mday_month'], $data['mday_day']) . ' ' . $data['mday_time']; - - // Did we submit? - if ($update) - { - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); - } - - $match_row['status'] = utf8_normalize_nfc($this->request->variable('match_status', '', true)); - $match_row['odd_1'] = round($this->request->variable('odd_1', $match_row['odd_1']),2); - $match_row['odd_x'] = round($this->request->variable('odd_x', $match_row['odd_x']),2); - $match_row['odd_2'] = round($this->request->variable('odd_2', $match_row['odd_2']),2); - $match_row['rating'] = round($this->request->variable('rating', $match_row['rating']),2); - $match_row['team_id_home'] = utf8_normalize_nfc($this->request->variable('team_home', '', true)); - $match_row['team_id_guest'] = utf8_normalize_nfc($this->request->variable('team_guest', '', true)); - $match_row['formula_home'] = utf8_normalize_nfc($this->request->variable('formula_home', '', true)); - $match_row['formula_guest'] = utf8_normalize_nfc($this->request->variable('formula_guest', '', true)); - $match_row['ko_match'] = $this->request->variable('match_ko', false); - $match_row['group_id'] = ($this->request->variable('group_match', false)) ? utf8_normalize_nfc($this->request->variable('match_group', '', true)) : ''; - - if ($match_row['team_id_home'] <> '') - { - $team_arr = explode(';', $match_row['team_id_home']); - $match_row['team_id_home'] = $team_arr[1]; - } - if ($match_row['team_id_guest'] <> '') - { - $team_arr = explode(';', $match_row['team_id_guest']); - $match_row['team_id_guest'] = $team_arr[1]; - } - - if ($data['mday_day'] <> '--' and $data['mday_month'] <> '--' and $data['mday_year'] <> '--') - { - $match_timestamp = mktime($data['mday_hour'], $data['mday_min'], 0, $data['mday_month'], $data['mday_day'], $data['mday_year']); - $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); - if ($match_timestamp > $local_board_time AND $match_row['status'] < 3 AND $league_info['bet_in_time'] == 1) - { - // Bet in time and match moved to future - $match_row['status'] = 0; - } - - if ($match_timestamp <= $local_board_time AND $match_row['status'] == 0 AND $league_info['bet_in_time'] == 1) - { - // Bet in time and match moved to past - $match_row['status'] = 1; - } - - if ($match_timestamp < $unix_delivery_date AND $match_row['status'] == 0 AND !$league_info['bet_in_time']) - { - // No bet in time and match moved before delivery - $error[] = $user->lang['MATCH_BEFORE_DELIVERY']; - } - } - else - { - $error[] = $user->lang['NO_MATCH_BEGIN']; - } - - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'match_no' => (int) $match_number, - 'team_id_home' => (is_numeric($match_row['team_id_home'])) ? $match_row['team_id_home'] : 0, - 'team_id_guest' => (is_numeric($match_row['team_id_guest'])) ? $match_row['team_id_guest'] : 0, - 'goals_home' => (is_numeric($match_row['goals_home'])) ? $match_row['goals_home'] : '', - 'goals_guest' => (is_numeric($match_row['goals_guest'])) ? $match_row['goals_guest'] : '', - 'matchday' => $match_row['matchday'], - 'status' => (is_numeric($match_row['status'])) ? $match_row['status'] : 0, - 'odd_1' => (is_numeric($match_row['odd_1'])) ? $match_row['odd_1'] : 0, - 'odd_x' => (is_numeric($match_row['odd_x'])) ? $match_row['odd_x'] : 0, - 'odd_2' => (is_numeric($match_row['odd_2'])) ? $match_row['odd_2'] : 0, - 'rating' => (is_numeric($match_row['rating'])) ? $match_row['rating'] : 0, - 'match_datetime' => $match_row['match_datetime'], - 'group_id' => strlen($match_row['group_id']) ? $match_row['group_id'] : '', - 'formula_home' => strlen($match_row['formula_home']) ? $match_row['formula_home'] : '', - 'formula_guest' => strlen($match_row['formula_guest']) ? $match_row['formula_guest'] : '', - 'ko_match' => $match_row['ko_match'] ? $match_row['ko_match'] : 0, - 'goals_overtime_home' => (is_numeric($match_row['goals_overtime_home'])) ? $match_row['goals_overtime_home'] : '', - 'goals_overtime_guest' => (is_numeric($match_row['goals_overtime_guest'])) ? $match_row['goals_overtime_guest'] : '', - ); - - - $var_ary = array( - 'mday_date' => array('date', false), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND match_no = $match_number"; - $db->sql_query($sql); - - if ($match_timestamp > $local_board_time AND $match_row['status'] == 0 AND $league_info['bet_in_time'] == 1) - { - // Bet in time and match (re)open so reopen matchday and set first delivery - $sql_ary = array( - 'status' => 0, - 'delivery_date' => first_delivery($season, $league, $matchday), - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - } - - if ($match_timestamp <= $local_board_time AND $match_row['status'] <= 1 AND $league_info['bet_in_time'] == 1) - { - // Bet in time and match is closed so reopen matchday and set first delivery - $first_delivery = first_delivery($season, $league, $matchday); - if ($first_delivery <> '') - { - // Matchday has open matches, so set matchday status = 0 and first delivery - $sql_ary = array( - 'status' => 0, - 'delivery_date' => first_delivery($season, $league, $matchday), - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - } - else - { - // Matchday has no open match, so set matchday status = 1 - $sql_ary = array( - 'status' => 1, - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - } - } - trigger_error($user->lang['MATCH_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $error[] = $user->lang['MATCH_UPDATE_FAILED']; - $error = array_merge($error, $error_msg); - } - } - } - } - - $s_matchday_day_options = ''; - for ($i = 1; $i < 32; $i++) - { - $selected = ($i == $data['mday_day']) ? ' selected="selected"' : ''; - $s_matchday_day_options .= ""; - } - - $s_matchday_month_options = ''; - for ($i = 1; $i < 13; $i++) - { - $selected = ($i == $data['mday_month']) ? ' selected="selected"' : ''; - $s_matchday_month_options .= ""; - } - $s_matchday_year_options = ''; - - $s_matchday_year_options = ''; - for ($i = $season - 1 ; $i <= $season; $i++) - { - $selected = ($i == $data['mday_year']) ? ' selected="selected"' : ''; - $s_matchday_year_options .= ""; - } - - $s_matchday_hour_options = ''; - if (!$data['mday_hour']) - { - $data['mday_hour'] = 0; - } - for ($i = 0; $i < 24; $i++) - { - $selected = ($i == $data['mday_hour']) ? ' selected="selected"' : ''; - $s_matchday_hour_options .= ""; - } - - $s_matchday_min_options = ''; - if (!$data['mday_min']) - { - $data['mday_min'] = 0; - } - for ($i = 0; $i < 12; $i++) - { - $selected = (($i * 5) == $data['mday_min']) ? ' selected="selected"' : ''; - $s_matchday_min_options .= ""; - } - - // Selection status - $edit_status = false; - if ($match_row['status'] < 1) - { - $edit_status = true; - $selected_status = ($match_row['status'] == 0) ? ' selected="selected"' : ''; - $status_options = ''; - if ($delivery2 != '') - { - $selected_status = ($match_row['status'] == -1) ? ' selected="selected"' : ''; - $status_options .= ''; - if ($delivery3 != '') - { - $selected_status = ($match_row['status'] == -2) ? ' selected="selected"' : ''; - $status_options .= ''; - } - } - } - else - { - $status_options = ''; - } - // Grab for teams for selection - if ($ko_league) - { - $where_round = " AND matchday >= $matchday"; - } - else - { - $where_round = ""; - } - $sql = 'SELECT * - FROM ' . FOOTB_TEAMS . " - WHERE season = $season - AND league = $league - $where_round - ORDER BY team_name ASC"; - $result = $db->sql_query($sql); - $team_guest_options = ''; - $team_home_options = ''; - $match_group = ''; - while ($row = $db->sql_fetchrow($result)) - { - $guest_id = (empty($match_row['team_id_guest'])) ? 0 : $match_row['team_id_guest']; - $selected_guest = ($guest_id && $row['team_id'] == $guest_id) ? ' selected="selected"' : ''; - if ($row['team_id'] == $guest_id) - { - $match_group = $row['group_id']; - } - $team_guest_options .= ''; - $home_id = (empty($match_row['team_id_home'])) ? 0 : $match_row['team_id_home']; - $selected_home = ($home_id && $row['team_id'] == $home_id) ? ' selected="selected"' : ''; - $team_home_options .= ''; - } - - $u_back = $this->u_action . "&s=$season&l=$league&m=$matchday"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_MATCH' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'S_KO_LEAGUE' => $ko_league, - 'S_EDIT_STATUS' => $edit_status, - 'S_VERSION_NO' => $this->config['football_version'], - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'MATCHDAY' => $matchday, - 'MATCHDAY_NAME' => $matchday_name, - 'MATCH_NUMBER' => $match_number, - 'MATCH_STATUS' => $match_row['status'], - 'STATUS_OPTIONS' => $status_options, - 'S_GROUP_CHECKED' => (strlen($match_row['group_id']) > 0) ? true : false, - 'MATCH_GROUP' => $match_group, - 'S_KO_CHECKED' => $match_row['ko_match'], - 'FORMULA_HOME' => $match_row['formula_home'], - 'FORMULA_GUEST' => $match_row['formula_guest'], - 'FORMULA_HOME' => $match_row['formula_home'], - 'TEAM_GUEST_OPTIONS' => $team_guest_options, - 'TEAM_HOME_OPTIONS' => $team_home_options, - 'S_MATCHDAY_DAY_OPTIONS' => $s_matchday_day_options, - 'S_MATCHDAY_MONTH_OPTIONS' => $s_matchday_month_options, - 'S_MATCHDAY_YEAR_OPTIONS' => $s_matchday_year_options, - 'S_MATCHDAY_HOUR_OPTIONS' => $s_matchday_hour_options, - 'S_MATCHDAY_MIN_OPTIONS' => $s_matchday_min_options, - 'MATCH_BEGIN_D' => substr($match_row['match_datetime'],8,2), - 'MATCH_BEGIN_M' => substr($match_row['match_datetime'],5,2), - 'MATCH_BEGIN_Y' => substr($match_row['match_datetime'],0,4), - 'MATCH_BEGIN_H' => substr($match_row['match_datetime'],11,2), - 'MATCH_BEGIN_MIN' => substr($match_row['match_datetime'],14,2), - 'ODD_1' => $match_row['odd_1'], - 'ODD_x' => $match_row['odd_x'], - 'ODD_2' => $match_row['odd_2'], - 'RATING' => $match_row['rating'], - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league&m=$matchday", - ) - ); - - return; - break; - } - - // Get us all the matches - $lang_dates = $user->lang['datetime']; - $sql = "SELECT - m.match_no, - m.status, - m.group_id, - m.ko_match, - m.formula_home, - m.formula_guest, - m.team_id_home AS home_id, - m.team_id_guest AS guest_id, - th.team_name AS home_name, - tg.team_name AS guest_name, - CONCAT( - CASE DATE_FORMAT(m.match_datetime,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(m.match_datetime,' %d.%m.%y %H:%i') - ) AS match_begin - FROM " . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS th ON (th.season = m.season AND th.league = m.league AND th.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS tg ON (tg.season = m.season AND tg.league = m.league AND tg.team_id = m.team_id_guest) - WHERE m.season = $season - AND m.league = $league - AND m.matchday = $matchday - ORDER BY m.match_datetime ASC, m.match_no ASC"; - $result = $db->sql_query($sql); - $rows_matches = $db->sql_fetchrowset($result); - $existing_matches = sizeof($rows_matches); - $db->sql_freeresult($result); - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_KO_LEAGUE' => $ko_league, - 'S_MATCHDAY' => $matchday, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_MATCHDAY_OPTIONS'=> $matchday_options, - 'S_MATCH_ADD' => ($matches_on_matchday == $existing_matches) ? false:true, - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - - // Check if the user is allowed to delete a match. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - foreach ($rows_matches as $row_match) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('match', array( - 'ROW_CLASS' => $row_class, - 'MATCH_NUMBER' => $row_match['match_no'], - 'MATCH_STATUS' => $row_match['status'], - 'MATCH_GROUP' => $row_match['group_id'], - 'MATCH_KO' => ($row_match['ko_match']) ? 'KO' : '', - 'MATCH_BEGIN' => $row_match['match_begin'], - 'MATCH_HOME' => ($row_match['home_name'] == '') ? $row_match['formula_home'] : $row_match['home_name'], - 'MATCH_GUEST' => ($row_match['guest_name'] == '') ? $row_match['formula_guest'] : $row_match['guest_name'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&m=" .$matchday . "&g=" .$row_match['match_no'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&m=" . $matchday . "&g=" . $row_match['match_no'] : '', - ) - ); - } - } -} - +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_matches'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_matches'; + $this->page_title = 'ACP_FOOTBALL_MATCHES_MANAGE'; + + $form_key = 'acp_football_matches'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $match_number = $this->request->variable('g', 0); + $update = (isset($_POST['update'])) ? true : false; + + // Clear some vars + $match_row = array(); + $error = array(); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = current_league($season, false); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_info = $row; + $league_matchdays = $row['matchdays']; + $matches_matchday = $row['matches_on_matchday']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for select matchday + if (!$matchday) + { + $matchday = curr_matchday($season, $league); + } + $sql = 'SELECT *, + UNIX_TIMESTAMP(delivery_date) AS unix_delivery_date + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $delivery2 = ''; + $delivery3 = ''; + $matchday_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + if ($selected <> '') + { + $unix_delivery_date = $row['unix_delivery_date']; + $delivery2 = $row['delivery_date_2']; + $delivery3 = $row['delivery_date_3']; + $matchday_name = $day_name; + if ($matches_matchday) + { + $matches_on_matchday = $matches_matchday; + } + else + { + $matches_on_matchday = $row['matches']; + } + } + } + $db->sql_freeresult($result); + if ($matchday_options == '') + { + trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Grab basic data for match, if match is set and exists + if ($match_number) + { + $sql = 'SELECT * + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND match_no = $match_number"; + $result = $db->sql_query($sql); + $match_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + // Which page? + switch ($action) + { + case 'delete': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (!$matchday) + { + trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['MATCHES_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); + } + + // Delete match + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND match_no = $match_number"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season AND league = $league AND match_no = $match_number"; + $db->sql_query($sql); + + trigger_error($user->lang['MATCH_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); + } + else + { + confirm_box(false, sprintf($user->lang['MATCH_CONFIRM_DELETE'], $match_row['match_no'], $league_name, $season), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 'm' => $matchday, + 'g' => $match_number, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add': + $sql = "SELECT DISTINCT user_id + FROM " . FOOTB_BETS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + $rows_users = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $sql = "SELECT + matchday, + matches AS matches_matchday, + delivery_date + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $rows_matchdays = $db->sql_fetchrowset($result); + $existing_matchdays = sizeof($rows_matchdays); + $db->sql_freeresult($result); + if ($existing_matchdays < $league_matchdays) + { + trigger_error($user->lang['MATCHDAY_MISSED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); + } + else + { + $current_match = 0; + $count_updates = 0; + $sql_betary = array(); + foreach ($rows_matchdays as $current_matchday) + { + if ($matches_matchday) + { + $matches_on_matchday = $matches_matchday; + } + else + { + $matches_on_matchday = $current_matchday['matches_matchday']; + } + for ( $i = 1; $i <= $matches_on_matchday; $i++ ) + { + $current_match++; + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'match_no' => (int) $current_match, + 'team_id_home' => 0, + 'team_id_guest' => 0, + 'goals_home' => '', + 'goals_guest' => '', + 'matchday' => $current_matchday['matchday'], + 'status' => 0, + 'odd_1' => 0, + 'odd_x' => 0, + 'odd_2' => 0, + 'rating' => 0, + 'match_datetime' => $current_matchday['delivery_date'], + 'group_id' => '', + 'formula_home' => '', + 'formula_guest' => '', + 'ko_match' => 0, + 'goals_overtime_home' => '', + 'goals_overtime_guest' => '', + ); + $sql = 'INSERT IGNORE INTO ' . FOOTB_MATCHES . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + if ($db->sql_affectedrows()) + { + $count_updates++; + foreach ($rows_users as $current_user) + { + $sql_betary[] = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'match_no' => (int) $current_match, + 'user_id' => $current_user['user_id'], + 'goals_home' => '', + 'goals_guest' => '', + 'bet_time' => 0, + ); + } + } + } + } + if (sizeof($sql_betary)) + { + $db->sql_multi_insert(FOOTB_BETS, $sql_betary); + } + $message = ($count_updates > 1) ? 'MATCHES_CREATED' : 'MATCH_CREATED'; + trigger_error(sprintf($user->lang[$message],$count_updates) . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); + } + break; + case 'edit': + $data = array(); + $error_msg = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$match_number) + { + trigger_error($user->lang['NO_MATCH'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); + } + + $data = array( + 'mday_day' => 0, + 'mday_month' => 0, + 'mday_year' => 0, + 'mday_hour' => 0, + 'mday_min' => 0, + ); + if ($match_row['match_datetime']) + { + list($data['mday_date'], $data['mday_time']) = explode(' ', $match_row['match_datetime']); + list($data['mday_year'], $data['mday_month'], $data['mday_day']) = explode('-', $data['mday_date']); + list($data['mday_hour'], $data['mday_min'], $data['mday_sec']) = explode(':', $data['mday_time']); + } + + $data['mday_day'] = $this->request->variable('mday_day', $data['mday_day']); + $data['mday_month'] = $this->request->variable('mday_month', $data['mday_month']); + $data['mday_year'] = $this->request->variable('mday_year', $data['mday_year']); + $data['mday_hour'] = $this->request->variable('mday_hour', $data['mday_hour']); + $data['mday_min'] = $this->request->variable('mday_min', $data['mday_min']); + $data['mday_sec'] = '00'; + $data['mday_date'] = sprintf('%02d-%02d-%04d', $data['mday_day'], $data['mday_month'], $data['mday_year']); + $data['mday_time'] = sprintf('%02d:%02d:%02d', $data['mday_hour'], $data['mday_min'], $data['mday_sec']); + $match_row['match_datetime'] = sprintf('%04d-%02d-%02d', $data['mday_year'], $data['mday_month'], $data['mday_day']) . ' ' . $data['mday_time']; + + // Did we submit? + if ($update) + { + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday"), E_USER_WARNING); + } + + $match_row['status'] = utf8_normalize_nfc($this->request->variable('match_status', '', true)); + $match_row['odd_1'] = round($this->request->variable('odd_1', $match_row['odd_1']),2); + $match_row['odd_x'] = round($this->request->variable('odd_x', $match_row['odd_x']),2); + $match_row['odd_2'] = round($this->request->variable('odd_2', $match_row['odd_2']),2); + $match_row['rating'] = round($this->request->variable('rating', $match_row['rating']),2); + $match_row['team_id_home'] = utf8_normalize_nfc($this->request->variable('team_home', '', true)); + $match_row['team_id_guest'] = utf8_normalize_nfc($this->request->variable('team_guest', '', true)); + $match_row['formula_home'] = utf8_normalize_nfc($this->request->variable('formula_home', '', true)); + $match_row['formula_guest'] = utf8_normalize_nfc($this->request->variable('formula_guest', '', true)); + $match_row['ko_match'] = $this->request->variable('match_ko', false); + $match_row['group_id'] = ($this->request->variable('group_match', false)) ? utf8_normalize_nfc($this->request->variable('match_group', '', true)) : ''; + + if ($match_row['team_id_home'] <> '') + { + $team_arr = explode(';', $match_row['team_id_home']); + $match_row['team_id_home'] = $team_arr[1]; + } + if ($match_row['team_id_guest'] <> '') + { + $team_arr = explode(';', $match_row['team_id_guest']); + $match_row['team_id_guest'] = $team_arr[1]; + } + + if ($data['mday_day'] <> '--' and $data['mday_month'] <> '--' and $data['mday_year'] <> '--') + { + $match_timestamp = mktime($data['mday_hour'], $data['mday_min'], 0, $data['mday_month'], $data['mday_day'], $data['mday_year']); + $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); + if ($match_timestamp > $local_board_time AND $match_row['status'] < 3 AND $league_info['bet_in_time'] == 1) + { + // Bet in time and match moved to future + $match_row['status'] = 0; + } + + if ($match_timestamp <= $local_board_time AND $match_row['status'] == 0 AND $league_info['bet_in_time'] == 1) + { + // Bet in time and match moved to past + $match_row['status'] = 1; + } + + if ($match_timestamp < $unix_delivery_date AND $match_row['status'] == 0 AND !$league_info['bet_in_time']) + { + // No bet in time and match moved before delivery + $error[] = $user->lang['MATCH_BEFORE_DELIVERY']; + } + } + else + { + $error[] = $user->lang['NO_MATCH_BEGIN']; + } + + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'match_no' => (int) $match_number, + 'team_id_home' => (is_numeric($match_row['team_id_home'])) ? $match_row['team_id_home'] : 0, + 'team_id_guest' => (is_numeric($match_row['team_id_guest'])) ? $match_row['team_id_guest'] : 0, + 'goals_home' => (is_numeric($match_row['goals_home'])) ? $match_row['goals_home'] : '', + 'goals_guest' => (is_numeric($match_row['goals_guest'])) ? $match_row['goals_guest'] : '', + 'matchday' => $match_row['matchday'], + 'status' => (is_numeric($match_row['status'])) ? $match_row['status'] : 0, + 'odd_1' => (is_numeric($match_row['odd_1'])) ? $match_row['odd_1'] : 0, + 'odd_x' => (is_numeric($match_row['odd_x'])) ? $match_row['odd_x'] : 0, + 'odd_2' => (is_numeric($match_row['odd_2'])) ? $match_row['odd_2'] : 0, + 'rating' => (is_numeric($match_row['rating'])) ? $match_row['rating'] : 0, + 'match_datetime' => $match_row['match_datetime'], + 'group_id' => strlen($match_row['group_id']) ? $match_row['group_id'] : '', + 'formula_home' => strlen($match_row['formula_home']) ? $match_row['formula_home'] : '', + 'formula_guest' => strlen($match_row['formula_guest']) ? $match_row['formula_guest'] : '', + 'ko_match' => $match_row['ko_match'] ? $match_row['ko_match'] : 0, + 'goals_overtime_home' => (is_numeric($match_row['goals_overtime_home'])) ? $match_row['goals_overtime_home'] : '', + 'goals_overtime_guest' => (is_numeric($match_row['goals_overtime_guest'])) ? $match_row['goals_overtime_guest'] : '', + ); + + + $var_ary = array( + 'mday_date' => array('date', false), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND match_no = $match_number"; + $db->sql_query($sql); + + if ($match_timestamp > $local_board_time AND $match_row['status'] == 0 AND $league_info['bet_in_time'] == 1) + { + // Bet in time and match (re)open so reopen matchday and set first delivery + $sql_ary = array( + 'status' => 0, + 'delivery_date' => first_delivery($season, $league, $matchday), + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + } + + if ($match_timestamp <= $local_board_time AND $match_row['status'] <= 1 AND $league_info['bet_in_time'] == 1) + { + // Bet in time and match is closed so reopen matchday and set first delivery + $first_delivery = first_delivery($season, $league, $matchday); + if ($first_delivery <> '') + { + // Matchday has open matches, so set matchday status = 0 and first delivery + $sql_ary = array( + 'status' => 0, + 'delivery_date' => first_delivery($season, $league, $matchday), + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + } + else + { + // Matchday has no open match, so set matchday status = 1 + $sql_ary = array( + 'status' => 1, + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + } + } + trigger_error($user->lang['MATCH_UPDATED'] . adm_back_link($this->u_action . "&s=$season&l=$league&m=$matchday")); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $error[] = $user->lang['MATCH_UPDATE_FAILED']; + $error = array_merge($error, $error_msg); + } + } + } + } + + $s_matchday_day_options = ''; + for ($i = 1; $i < 32; $i++) + { + $selected = ($i == $data['mday_day']) ? ' selected="selected"' : ''; + $s_matchday_day_options .= ""; + } + + $s_matchday_month_options = ''; + for ($i = 1; $i < 13; $i++) + { + $selected = ($i == $data['mday_month']) ? ' selected="selected"' : ''; + $s_matchday_month_options .= ""; + } + $s_matchday_year_options = ''; + + $s_matchday_year_options = ''; + for ($i = $season - 1 ; $i <= $season; $i++) + { + $selected = ($i == $data['mday_year']) ? ' selected="selected"' : ''; + $s_matchday_year_options .= ""; + } + + $s_matchday_hour_options = ''; + if (!$data['mday_hour']) + { + $data['mday_hour'] = 0; + } + for ($i = 0; $i < 24; $i++) + { + $selected = ($i == $data['mday_hour']) ? ' selected="selected"' : ''; + $s_matchday_hour_options .= ""; + } + + $s_matchday_min_options = ''; + if (!$data['mday_min']) + { + $data['mday_min'] = 0; + } + for ($i = 0; $i < 12; $i++) + { + $selected = (($i * 5) == $data['mday_min']) ? ' selected="selected"' : ''; + $s_matchday_min_options .= ""; + } + + // Selection status + $edit_status = false; + if ($match_row['status'] < 1) + { + $edit_status = true; + $selected_status = ($match_row['status'] == 0) ? ' selected="selected"' : ''; + $status_options = ''; + if ($delivery2 != '') + { + $selected_status = ($match_row['status'] == -1) ? ' selected="selected"' : ''; + $status_options .= ''; + if ($delivery3 != '') + { + $selected_status = ($match_row['status'] == -2) ? ' selected="selected"' : ''; + $status_options .= ''; + } + } + } + else + { + $status_options = ''; + } + // Grab for teams for selection + if ($ko_league) + { + $where_round = " AND matchday >= $matchday"; + } + else + { + $where_round = ""; + } + $sql = 'SELECT * + FROM ' . FOOTB_TEAMS . " + WHERE season = $season + AND league = $league + $where_round + ORDER BY team_name ASC"; + $result = $db->sql_query($sql); + $team_guest_options = ''; + $team_home_options = ''; + $match_group = ''; + while ($row = $db->sql_fetchrow($result)) + { + $guest_id = (empty($match_row['team_id_guest'])) ? 0 : $match_row['team_id_guest']; + $selected_guest = ($guest_id && $row['team_id'] == $guest_id) ? ' selected="selected"' : ''; + if ($row['team_id'] == $guest_id) + { + $match_group = $row['group_id']; + } + $team_guest_options .= ''; + $home_id = (empty($match_row['team_id_home'])) ? 0 : $match_row['team_id_home']; + $selected_home = ($home_id && $row['team_id'] == $home_id) ? ' selected="selected"' : ''; + $team_home_options .= ''; + } + + $u_back = $this->u_action . "&s=$season&l=$league&m=$matchday"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_MATCH' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'S_KO_LEAGUE' => $ko_league, + 'S_EDIT_STATUS' => $edit_status, + 'S_VERSION_NO' => $this->config['football_version'], + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'MATCHDAY' => $matchday, + 'MATCHDAY_NAME' => $matchday_name, + 'MATCH_NUMBER' => $match_number, + 'MATCH_STATUS' => $match_row['status'], + 'STATUS_OPTIONS' => $status_options, + 'S_GROUP_CHECKED' => (strlen($match_row['group_id']) > 0) ? true : false, + 'MATCH_GROUP' => $match_group, + 'S_KO_CHECKED' => $match_row['ko_match'], + 'FORMULA_HOME' => $match_row['formula_home'], + 'FORMULA_GUEST' => $match_row['formula_guest'], + 'FORMULA_HOME' => $match_row['formula_home'], + 'TEAM_GUEST_OPTIONS' => $team_guest_options, + 'TEAM_HOME_OPTIONS' => $team_home_options, + 'S_MATCHDAY_DAY_OPTIONS' => $s_matchday_day_options, + 'S_MATCHDAY_MONTH_OPTIONS' => $s_matchday_month_options, + 'S_MATCHDAY_YEAR_OPTIONS' => $s_matchday_year_options, + 'S_MATCHDAY_HOUR_OPTIONS' => $s_matchday_hour_options, + 'S_MATCHDAY_MIN_OPTIONS' => $s_matchday_min_options, + 'MATCH_BEGIN_D' => substr($match_row['match_datetime'],8,2), + 'MATCH_BEGIN_M' => substr($match_row['match_datetime'],5,2), + 'MATCH_BEGIN_Y' => substr($match_row['match_datetime'],0,4), + 'MATCH_BEGIN_H' => substr($match_row['match_datetime'],11,2), + 'MATCH_BEGIN_MIN' => substr($match_row['match_datetime'],14,2), + 'ODD_1' => $match_row['odd_1'], + 'ODD_x' => $match_row['odd_x'], + 'ODD_2' => $match_row['odd_2'], + 'RATING' => $match_row['rating'], + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league&m=$matchday", + ) + ); + + return; + break; + } + + // Get us all the matches + $lang_dates = $user->lang['datetime']; + $sql = "SELECT + m.match_no, + m.status, + m.group_id, + m.ko_match, + m.formula_home, + m.formula_guest, + m.team_id_home AS home_id, + m.team_id_guest AS guest_id, + th.team_name AS home_name, + tg.team_name AS guest_name, + CONCAT( + CASE DATE_FORMAT(m.match_datetime,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(m.match_datetime,' %d.%m.%y %H:%i') + ) AS match_begin + FROM " . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS th ON (th.season = m.season AND th.league = m.league AND th.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS tg ON (tg.season = m.season AND tg.league = m.league AND tg.team_id = m.team_id_guest) + WHERE m.season = $season + AND m.league = $league + AND m.matchday = $matchday + ORDER BY m.match_datetime ASC, m.match_no ASC"; + $result = $db->sql_query($sql); + $rows_matches = $db->sql_fetchrowset($result); + $existing_matches = sizeof($rows_matches); + $db->sql_freeresult($result); + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_KO_LEAGUE' => $ko_league, + 'S_MATCHDAY' => $matchday, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_MATCHDAY_OPTIONS'=> $matchday_options, + 'S_MATCH_ADD' => ($matches_on_matchday == $existing_matches) ? false:true, + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + + // Check if the user is allowed to delete a match. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + foreach ($rows_matches as $row_match) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('match', array( + 'ROW_CLASS' => $row_class, + 'MATCH_NUMBER' => $row_match['match_no'], + 'MATCH_STATUS' => $row_match['status'], + 'MATCH_GROUP' => $row_match['group_id'], + 'MATCH_KO' => ($row_match['ko_match']) ? 'KO' : '', + 'MATCH_BEGIN' => $row_match['match_begin'], + 'MATCH_HOME' => ($row_match['home_name'] == '') ? $row_match['formula_home'] : $row_match['home_name'], + 'MATCH_GUEST' => ($row_match['guest_name'] == '') ? $row_match['formula_guest'] : $row_match['guest_name'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&m=" .$matchday . "&g=" .$row_match['match_no'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&m=" . $matchday . "&g=" . $row_match['match_no'] : '', + ) + ); + } + } +} + ?> \ No newline at end of file diff --git a/acp/results_module.php b/acp/results_module.php index 0783528..7569fd9 100644 --- a/acp/results_module.php +++ b/acp/results_module.php @@ -1,819 +1,817 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_results'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) { - // Get an instance of the ultimatepoints functions_points - $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); - } - - $this->tpl_name = 'acp_football_results'; - $this->page_title = 'ACP_FOOTBALL_RESULTS_MANAGE'; - - $form_key = 'acp_football_results'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['edit'])) ? 'edit' : $this->request->variable('action', ''); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $matchday = $this->request->variable('m', 0); - $update = (isset($_POST['update'])) ? true : false; - - // Close matchday - close_open_matchdays(); - - // Clear some vars - $success = array(); - - $curr_season = curr_season(); - // Grab current season - if (!$season) - { - $season = $curr_season; - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $sql = 'SELECT * - FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND status in (0,1,2,4,5) - ORDER BY match_datetime ASC"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $league = $row['league']; - $matchday = $row['matchday']; - } - else - { - $league = first_league($season); - } - $db->sql_freeresult($result); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_info = $row; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab basic data for select matchday - if (!$matchday) - { - $matchday = curr_matchday($season, $league); - } - $sql = 'SELECT * - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - - $matchday_options = ''; - $worldfootball = false; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - if ($selected <> '') - { - $matchday_name = $day_name; - if ($league_info['matches_on_matchday']) - { - $matches_on_matchday = $league_info['matches_on_matchday']; - $worldfootball = ($row['status'] > 0) ? true : false; } - else - { - $matches_on_matchday = $row['matches']; - } - } - } - $db->sql_freeresult($result); - if ($matchday_options == '') - { - trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_info['league_name'], $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); - - // Which page? - switch ($action) - { - case 'edit': - if ($season < $curr_season) - { - trigger_error("Diese Saison kann nicht mehr gespeichert werden!", E_USER_WARNING); - } - $sql = "SELECT * , - IF( match_datetime > FROM_UNIXTIME('$local_board_time'), 1, 0) As open_match - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday"; - $result = $db->sql_query($sql); - $rows_matches = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $matches_on_matchday = sizeof($rows_matches); - $count_delete = 0; - $count_no_valuation = 0; - $count_results = 0; - foreach ($rows_matches as $row_match) - { - $match_num = $row_match['match_no']; - $status = $row_match['status']; - $select = $this->request->variable('select_' . $match_num, false); - $no_valuation = $this->request->variable('no_valuation_' . $match_num, false); - $open_match = $row_match['open_match']; - - if ($select or $no_valuation or (!$no_valuation and $status > 3)) - { - $goals_home = $this->request->variable('goals_home_' . $match_num, ''); - $goals_guest = $this->request->variable('goals_guest_' . $match_num, ''); - $overtime_home = $this->request->variable('overtime_home_' . $match_num, ''); - $overtime_guest = $this->request->variable('overtime_guest_' . $match_num, ''); - $delete = $this->request->variable('delete_' . $match_num, false); - - if ($delete) - { - $goals_home = ''; - $goals_guest = ''; - $overtime_home = ''; - $overtime_guest = ''; - } - if ($no_valuation) - { - $status = 4; - $count_no_valuation++; - } - else if ($status > 3) - { - $status = 3; - } - if(is_numeric($goals_home) && is_numeric($goals_guest) && $goals_home >= 0 && $goals_guest >= 0) - { - if ($status <= 3) - $status = 3; - else - { - $status = 6; - } - $sql_ary = array( - 'goals_home' => $goals_home, - 'goals_guest' => $goals_guest, - 'status' => $status, - 'goals_overtime_home' => (!is_numeric($overtime_home) OR !is_numeric($overtime_guest)) ? '' : $overtime_home, - 'goals_overtime_guest' => (!is_numeric($overtime_home) OR !is_numeric($overtime_guest)) ? '' : $overtime_guest, - ); - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND match_no = $match_num"; - $db->sql_query($sql); - $count_results++; - } - else - { - if ($status <= 3) - { - if (($league_info['bet_in_time'] == 1) and $open_match) - { - $status = 0; - $sql_ary = array('status' => $status); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday AND delivery_date_2 = ''"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['SET_STATUS_TO'], $status) ; - } - else - { - $status = 1; - } - } - else - { - $status = 4; - } - $sql_ary = array( - 'goals_home' => '', - 'goals_guest' => '', - 'status' => $status, - 'goals_overtime_home' => '', - 'goals_overtime_guest' => '', - ); - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND match_no = $match_num"; - $db->sql_query($sql); - $count_delete++; - } - } - } - if ($count_results) - { - $success[] = sprintf($user->lang['RESULT' . (($count_results == 1) ? '' : 'S') . '_SAVED'],$count_results) ; - } - if ($count_delete) - { - $success[] = sprintf($user->lang['RESULT' . (($count_delete == 1) ? '' : 'S') . '_DELETED'],$count_delete) ; - } - if ($count_no_valuation) - { - $success[] = sprintf($user->lang['RESULT' . (($count_delete == 1) ? '' : 'S') . '_NO_VALUATION'],$count_no_valuation) ; - } - - // extra bets - $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND matchday_eval = $matchday AND extra_status > 0"; - $resultextra = $db->sql_query($sql); - $count_extra_updates = 0; - $count_extra_delete = 0; - $count_extra_bets = 0; - while( $row = $db->sql_fetchrow($resultextra)) - { - $count_extra_bets++; - $extra_no = $row['extra_no']; - $extra_results = $this->request->variable('extra' . $extra_no, array('nv')); - $extra_result = ''; - if (sizeof($extra_results) > 0) - { - foreach ($extra_results as $extra_selected_value) - { - $extra_result = ($extra_result == '') ? $extra_selected_value : $extra_result . ';' . $extra_selected_value; - } - } - else - { - $extra_result = $this->request->variable('extra' . $extra_no, 'nv'); - } - if ($extra_result != 'nv' && $this->request->variable('select' . $extra_no, false)) - { - if ($row['question_type'] == 5 && !is_numeric($extra_result)) - { - $extra_result = ''; - } - if ($extra_result != '') - { - $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND extra_no = $extra_no"; - $result = $db->sql_query($sql); - $row2 = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - if($row2) - { - $sql_ary = array( - 'result' => $extra_result, - 'extra_status' => 3, - ); - $sql = 'UPDATE ' . FOOTB_EXTRA . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND extra_no = $extra_no"; - $db->sql_query($sql); - $count_extra_updates++; - } - } - else - { - // extra result unset - $sql_ary = array( - 'result' => '', - 'extra_status' => 1, - ); - $sql = 'UPDATE ' . FOOTB_EXTRA . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND extra_no = $extra_no"; - $db->sql_query($sql); - $count_extra_delete++; - } - } - } - if ($count_extra_updates) - { - $success[] = sprintf($user->lang['EXTRA_RESULT' . (($count_extra_updates == 1) ? '' : 'S') . '_SAVED'], $count_extra_updates); - } - if ($count_extra_delete) - { - $success[] = sprintf($user->lang['EXTRA_RESULT' . (($count_extra_delete == 1) ? '' : 'S') . '_DELETED'], $count_extra_delete); - } - calculate_extra_points($season, $league, $matchday, true); - - $sql = 'Select - MIN(status) AS min_status, - MAX(status) AS max_status - FROM - ((SELECT - matchday_eval AS matchday, - extra_status AS status - FROM ' . FOOTB_EXTRA . " - WHERE season = $season - AND league = $league - AND matchday_eval = $matchday) - UNION - (SELECT - matchday, - status - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday )) AS ebm - GROUP BY matchday"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - if($row['min_status'] > 0) - { - if ($row['max_status'] < 3) - { - $new_status = $row['max_status']; - } - else - { - if ($row['min_status'] > 2) - { - $new_status = 3; - } - else - { - $new_status = 2; - } - } - $sql_ary = array('status' => $new_status); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday AND delivery_date_2 = ''"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['SET_STATUS_TO'], $new_status) ; - } - $db->sql_freeresult($result); - - $cash = $this->request->variable('cash', false); - save_ranking_matchday($season, $league, $matchday, $cash); - - // Patch delevirey - if ($league_info['bet_in_time'] == 1) - { - set_bet_in_time_delivery($season, $league); - } - break; - } - // Check KO matchday - $sql = 'SELECT - SUM(ko_match) AS ko_matchday - FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND matchday = $matchday - GROUP BY matchday"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $ko_matchday = $row['ko_matchday']; - $db->sql_freeresult($result); - - - // Get us all the matches - $lang_dates = $user->lang['datetime']; - $sql = "SELECT - m.match_no, - m.status, - m.team_id_home AS home_id, - m.team_id_guest AS guest_id, - m.formula_home, - m.formula_guest, - m.goals_home, - m.goals_guest, - m.goals_overtime_home, - m.goals_overtime_guest, - m.ko_match, - th.team_name AS home_name, - tg.team_name AS guest_name, - UNIX_TIMESTAMP(m.match_datetime) AS unix_match_begin, - CONCAT( - CASE DATE_FORMAT(m.match_datetime,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(m.match_datetime,' %d.%m.%y %H:%i') - ) AS match_begin - FROM " . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS th ON (th.season = m.season AND th.league = m.league AND th.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS tg ON (tg.season = m.season AND tg.league = m.league AND tg.team_id = m.team_id_guest) - WHERE m.season = $season - AND m.league = $league - AND m.matchday = $matchday - ORDER BY unix_match_begin ASC, m.match_no ASC"; - $result = $db->sql_query($sql); - $rows_matches = $db->sql_fetchrowset($result); - $existing_matches = sizeof($rows_matches); - $db->sql_freeresult($result); - $legend = delivery($season, $league, $matchday); - - $row_number = 0; - foreach ($rows_matches as $row_match) - { - $row_number++; - if ($this->config['football_results_at_time']) - { - $edit = (($row_match['unix_match_begin'] + 6300 < time()) && $row_match['status'] > 0) ? true :false; - } - else - { - $edit = ($row_match['status'] > 0) ? true :false; - } - if (0 == $row_match['home_id']) - { - $home_info = get_team($season, $league, $row_match['match_no'], 'team_id_home', $row_match['formula_home']); - $home_in_array = explode("#",$home_info); - $homename = $home_in_array[2]; - } - else - { - $homename = $row_match['home_name']; - } - if (0 == $row_match['guest_id']) - { - $guest_info = get_team($season, $league, $row_match['match_no'], 'team_id_guest', $row_match['formula_guest']); - $guest_in_array = explode("#",$guest_info); - $guestname = $guest_in_array[2]; - } - else - { - $guestname = $row_match['guest_name']; - } - - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('match', array( - 'ROW_CLASS' => $row_class, - 'EDIT' => $edit, - 'SELECT_CHECKED' => ($row_match['status'] > 0 AND $row_match['status'] < 3) ? ' selected="selected"' : '', - 'BEGIN' => $row_match['match_begin'], - 'NUMBER' => $row_match['match_no'], - 'STATUS' => $row_match['status'], - 'STATUS_COLOR' => color_match($row_match['status'], $row_match['status']), - 'HOME_NAME' => $homename, - 'GUEST_NAME' => $guestname, - 'GOALS_HOME' => $row_match['goals_home'], - 'GOALS_GUEST' => $row_match['goals_guest'], - 'OVERTIME_HOME' => $row_match['goals_overtime_home'], - 'OVERTIME_GUEST' => $row_match['goals_overtime_guest'], - 'NO_VALUATION_CHECKED' => ($row_match['status'] > 3) ? ' selected="selected"' : '', - 'KO_MATCH' => $row_match['ko_match'], - ) - ); - } - if ($worldfootball AND $season >= $curr_season) - { - $template->assign_block_vars('worldfootball', array( - ) - - ); - } - - // Calculate extra bets of matchday - // Start select team - $sql = 'SELECT - team_id AS option_value, - team_name AS option_name - FROM ' . FOOTB_TEAMS . " - WHERE season = $season - AND league = $league - ORDER BY team_name ASC"; - $result = $db->sql_query($sql); - $option_rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $sql = "SELECT e.*, - t1.team_name AS result_team - FROM " . FOOTB_EXTRA . ' AS e - LEFT JOIN ' . FOOTB_TEAMS . " AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) - WHERE e.season = $season - AND e.league = $league - AND e.matchday_eval = $matchday - ORDER BY e.extra_no ASC"; - $result = $db->sql_query($sql); - - $extra_results = false; - $extranumber = 0; - while ($row = $db->sql_fetchrow($result)) - { - $extra_results = true; - $extranumber++ ; - $row_class = (!($extranumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - - switch($row['question_type']) - { - case '1': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '2': - { - $display_type = 1; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '3': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_HIT']); - } - break; - case '4': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); - } - break; - case '5': - { - $display_type = 2; - $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); - } - break; - default : - { - $display_type = 2; - $eval_title = ''; - } - break; - } - - if ($row['extra_status'] > 0) - { - $edit_mode = true; - $result_extra = ($row['result_team'] == NULL) ? '' : $row['result_team']; - - $multiple = ''; - switch($row['question_type']) - { - case '2': - { - $multiple = ' multiple="multiple" size="3" '; - } - break; - case '4': - { - $option_arr = array(); - for ($i = 65; $i <= 72; $i++) - { - if (strstr($row['question'], chr($i) . ':')) - { - $option_arr[] = array( - 'option_value' => chr($i), - 'option_name' => chr($i), - ); - } - } - if ( sizeof($option_arr) > 1 ) - { - $display_type = 1; - $option_rows = $option_arr; - $result_extra = $row['result']; - $multiple = ' multiple="multiple" size="3" '; - } - } - break; - case '3': - { - $option_arr = array(); - for ($i = 65; $i <= 72; $i++) - { - if (strstr($row['question'], chr($i) . ':')) - { - $option_arr[] = array( - 'option_value' => chr($i), - 'option_name' => chr($i), - ); - } - } - if ( sizeof($option_arr) > 1 ) - { - $display_type = 1; - $option_rows = $option_arr; - $result_extra = $row['result']; - } - } - break; - } - - $template->assign_block_vars('extra_result', array( - 'ROW_CLASS' => $row_class, - 'EXTRA_NO' => $row['extra_no'], - 'S_EDIT_EXTRA' => true, - 'QUESTION' => $row['question'], - 'EXTRA_POINTS' => $row['extra_points'], - 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), - 'EVALUATION_TITLE' => $eval_title, - 'RESULT' => ($display_type == 1) ? $result_extra : $row['result'], - 'S_DISPLAY_TYPE' => $display_type, - 'S_MULTIPLE' => $multiple, - 'S_MULTIPLE_ARR' => ($multiple == '') ? '' : '[]', - 'STATUS' => $row['extra_status'], - 'STATUS_COLOR' => color_match($row['extra_status'], $row['extra_status']), - ) - ); - - if ($display_type == 1) - { - $selected = ($row['result'] == '') ? ' selected="selected"' : ''; - - $template->assign_block_vars('extra_result.extra_option', array( - 'OPTION_VALUE' => '', - 'OPTION_NAME' => sprintf($user->lang['SELECT']), - 'S_SELECTED' => $selected)); - - foreach ($option_rows as $option_row) - { - if (strstr($row['result'], ';')) - { - $selected = ''; - $result_arr = explode(';', $row['result']); - foreach($result_arr AS $result_value) - { - if ($result_value <> '') - { - if ($option_row['option_value'] == $result_value) - { - $selected = ' selected="selected"'; - } - } - } - } - else - { - $selected = ($option_row['option_value'] == $row['result']) ? ' selected="selected"' : ''; - } - $template->assign_block_vars('extra_result.extra_option', array( - 'OPTION_VALUE' => $option_row['option_value'], - 'OPTION_NAME' => $option_row['option_name'], - 'S_SELECTED' => $selected)); - } - } - } - else - { - $extra_colorstyle = color_style($row['extra_status']); - $extra_result = ($row['result'] == '') ? ' ' : $row['result']; - $result_extra = ($row['result_team'] == NULL) ? ' ' : $row['result_team']; - - $template->assign_block_vars('extra_result', array( - 'ROW_CLASS' => $row_class, - 'S_EDIT_EXTRA' => false, - 'QUESTION' => $row['question'], - 'EXTRA_POINTS' => $row['extra_points'], - 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), - 'RESULT' => ($display_type == 1) ? $result_extra : $extra_result, - 'COLOR_STYLE' => $extra_colorstyle, - ) - ); - } - } - - switch ($league_info['bet_ko_type']) - { - case BET_KO_90: - $result_explain = sprintf($user->lang['MIN90']); - $label_finalresult = sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']); - break; - case BET_KO_EXTRATIME: - $result_explain = sprintf($user->lang['EXTRATIME_SHORT']); - $label_finalresult = sprintf($user->lang['PENALTY']); - break; - case BET_KO_PENALTY: - $result_explain = sprintf($user->lang['PENALTY']); - $ko_matchday = false; - break; - default: - $result_explain = sprintf($user->lang['MIN90']); - $label_finalresult = sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']); - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'results', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'S_LEGEND' => $legend, - 'S_SUCCESS' => (sizeof($success)) ? true : false, - 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', - 'RESULT_EXPLAIN' => $result_explain, - 'LABEL_FINALRESULT' => (isset($label_finalresult)) ? $label_finalresult : sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']), - 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, - 'S_CASH' => ($season >= $curr_season) ? true : false, - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_MATCHDAY' => $matchday, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_KO_MATCHDAY' => $ko_matchday, - 'S_MATCHDAY_OPTIONS'=> $matchday_options, - 'S_EXTRA_RESULTS' => $extra_results, - 'S_TIME' => sprintf($user->lang['TIME']) . ': ' . date("d.m.Y H:i", $local_board_time), - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - } -} - +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_results'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) { + // Get an instance of the ultimatepoints functions_points + $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); + } + + $this->tpl_name = 'acp_football_results'; + $this->page_title = 'ACP_FOOTBALL_RESULTS_MANAGE'; + + $form_key = 'acp_football_results'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['edit'])) ? 'edit' : $this->request->variable('action', ''); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $matchday = $this->request->variable('m', 0); + $update = (isset($_POST['update'])) ? true : false; + + // Close matchday + close_open_matchdays(); + + // Clear some vars + $success = array(); + + $curr_season = curr_season(); + // Grab current season + if (!$season) + { + $season = $curr_season; + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $sql = 'SELECT * + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND status in (0,1,2,4,5) + ORDER BY match_datetime ASC"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $league = $row['league']; + $matchday = $row['matchday']; + } + else + { + $league = first_league($season); + } + $db->sql_freeresult($result); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_info = $row; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab basic data for select matchday + if (!$matchday) + { + $matchday = curr_matchday($season, $league); + } + $sql = 'SELECT * + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + + $matchday_options = ''; + $worldfootball = false; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($matchday && $row['matchday'] == $matchday) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + if ($selected <> '') + { + $matchday_name = $day_name; + if ($league_info['matches_on_matchday']) + { + $matches_on_matchday = $league_info['matches_on_matchday']; + $worldfootball = ($row['status'] > 0) ? true : false; } + else + { + $matches_on_matchday = $row['matches']; + } + } + } + $db->sql_freeresult($result); + if ($matchday_options == '') + { + trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_info['league_name'], $season) . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); + + // Which page? + switch ($action) + { + case 'edit': + if ($season < $curr_season) + { + trigger_error("Diese Saison kann nicht mehr gespeichert werden!", E_USER_WARNING); + } + $sql = "SELECT * , + IF( match_datetime > FROM_UNIXTIME('$local_board_time'), 1, 0) As open_match + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday"; + $result = $db->sql_query($sql); + $rows_matches = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $matches_on_matchday = sizeof($rows_matches); + $count_delete = 0; + $count_no_valuation = 0; + $count_results = 0; + foreach ($rows_matches as $row_match) + { + $match_num = $row_match['match_no']; + $status = $row_match['status']; + $select = $this->request->variable('select_' . $match_num, false); + $no_valuation = $this->request->variable('no_valuation_' . $match_num, false); + $open_match = $row_match['open_match']; + + if ($select or $no_valuation or (!$no_valuation and $status > 3)) + { + $goals_home = $this->request->variable('goals_home_' . $match_num, ''); + $goals_guest = $this->request->variable('goals_guest_' . $match_num, ''); + $overtime_home = $this->request->variable('overtime_home_' . $match_num, ''); + $overtime_guest = $this->request->variable('overtime_guest_' . $match_num, ''); + $delete = $this->request->variable('delete_' . $match_num, false); + + if ($delete) + { + $goals_home = ''; + $goals_guest = ''; + $overtime_home = ''; + $overtime_guest = ''; + } + if ($no_valuation) + { + $status = 4; + $count_no_valuation++; + } + else if ($status > 3) + { + $status = 3; + } + if(is_numeric($goals_home) && is_numeric($goals_guest) && $goals_home >= 0 && $goals_guest >= 0) + { + if ($status <= 3) + $status = 3; + else + { + $status = 6; + } + $sql_ary = array( + 'goals_home' => $goals_home, + 'goals_guest' => $goals_guest, + 'status' => $status, + 'goals_overtime_home' => (!is_numeric($overtime_home) OR !is_numeric($overtime_guest)) ? '' : $overtime_home, + 'goals_overtime_guest' => (!is_numeric($overtime_home) OR !is_numeric($overtime_guest)) ? '' : $overtime_guest, + ); + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND match_no = $match_num"; + $db->sql_query($sql); + $count_results++; + } + else + { + if ($status <= 3) + { + if (($league_info['bet_in_time'] == 1) and $open_match) + { + $status = 0; + $sql_ary = array('status' => $status); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday AND delivery_date_2 = ''"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['SET_STATUS_TO'], $status) ; + } + else + { + $status = 1; + } + } + else + { + $status = 4; + } + $sql_ary = array( + 'goals_home' => '', + 'goals_guest' => '', + 'status' => $status, + 'goals_overtime_home' => '', + 'goals_overtime_guest' => '', + ); + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND match_no = $match_num"; + $db->sql_query($sql); + $count_delete++; + } + } + } + if ($count_results) + { + $success[] = sprintf($user->lang['RESULT' . (($count_results == 1) ? '' : 'S') . '_SAVED'],$count_results) ; + } + if ($count_delete) + { + $success[] = sprintf($user->lang['RESULT' . (($count_delete == 1) ? '' : 'S') . '_DELETED'],$count_delete) ; + } + if ($count_no_valuation) + { + $success[] = sprintf($user->lang['RESULT' . (($count_delete == 1) ? '' : 'S') . '_NO_VALUATION'],$count_no_valuation) ; + } + + // extra bets + $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND matchday_eval = $matchday AND extra_status > 0"; + $resultextra = $db->sql_query($sql); + $count_extra_updates = 0; + $count_extra_delete = 0; + $count_extra_bets = 0; + while( $row = $db->sql_fetchrow($resultextra)) + { + $count_extra_bets++; + $extra_no = $row['extra_no']; + $extra_results = $this->request->variable('extra' . $extra_no, array('nv')); + $extra_result = ''; + if (sizeof($extra_results) > 0) + { + foreach ($extra_results as $extra_selected_value) + { + $extra_result = ($extra_result == '') ? $extra_selected_value : $extra_result . ';' . $extra_selected_value; + } + } + else + { + $extra_result = $this->request->variable('extra' . $extra_no, 'nv'); + } + if ($extra_result != 'nv' && $this->request->variable('select' . $extra_no, false)) + { + if ($row['question_type'] == 5 && !is_numeric($extra_result)) + { + $extra_result = ''; + } + if ($extra_result != '') + { + $sql = 'SELECT * FROM ' . FOOTB_EXTRA . " WHERE season = $season AND league = $league AND extra_no = $extra_no"; + $result = $db->sql_query($sql); + $row2 = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + if($row2) + { + $sql_ary = array( + 'result' => $extra_result, + 'extra_status' => 3, + ); + $sql = 'UPDATE ' . FOOTB_EXTRA . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND extra_no = $extra_no"; + $db->sql_query($sql); + $count_extra_updates++; + } + } + else + { + // extra result unset + $sql_ary = array( + 'result' => '', + 'extra_status' => 1, + ); + $sql = 'UPDATE ' . FOOTB_EXTRA . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND extra_no = $extra_no"; + $db->sql_query($sql); + $count_extra_delete++; + } + } + } + if ($count_extra_updates) + { + $success[] = sprintf($user->lang['EXTRA_RESULT' . (($count_extra_updates == 1) ? '' : 'S') . '_SAVED'], $count_extra_updates); + } + if ($count_extra_delete) + { + $success[] = sprintf($user->lang['EXTRA_RESULT' . (($count_extra_delete == 1) ? '' : 'S') . '_DELETED'], $count_extra_delete); + } + calculate_extra_points($season, $league, $matchday, true); + + $sql = 'Select + MIN(status) AS min_status, + MAX(status) AS max_status + FROM + ((SELECT + matchday_eval AS matchday, + extra_status AS status + FROM ' . FOOTB_EXTRA . " + WHERE season = $season + AND league = $league + AND matchday_eval = $matchday) + UNION + (SELECT + matchday, + status + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday )) AS ebm + GROUP BY matchday"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + if($row['min_status'] > 0) + { + if ($row['max_status'] < 3) + { + $new_status = $row['max_status']; + } + else + { + if ($row['min_status'] > 2) + { + $new_status = 3; + } + else + { + $new_status = 2; + } + } + $sql_ary = array('status' => $new_status); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday AND delivery_date_2 = ''"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['SET_STATUS_TO'], $new_status) ; + } + $db->sql_freeresult($result); + + $cash = $this->request->variable('cash', false); + save_ranking_matchday($season, $league, $matchday, $cash); + + // Patch delevirey + if ($league_info['bet_in_time'] == 1) + { + set_bet_in_time_delivery($season, $league); + } + break; + } + // Check KO matchday + $sql = 'SELECT + SUM(ko_match) AS ko_matchday + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND matchday = $matchday + GROUP BY matchday"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $ko_matchday = $row['ko_matchday']; + $db->sql_freeresult($result); + + + // Get us all the matches + $lang_dates = $user->lang['datetime']; + $sql = "SELECT + m.match_no, + m.status, + m.team_id_home AS home_id, + m.team_id_guest AS guest_id, + m.formula_home, + m.formula_guest, + m.goals_home, + m.goals_guest, + m.goals_overtime_home, + m.goals_overtime_guest, + m.ko_match, + th.team_name AS home_name, + tg.team_name AS guest_name, + UNIX_TIMESTAMP(m.match_datetime) AS unix_match_begin, + CONCAT( + CASE DATE_FORMAT(m.match_datetime,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(m.match_datetime,' %d.%m.%y %H:%i') + ) AS match_begin + FROM " . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS th ON (th.season = m.season AND th.league = m.league AND th.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS tg ON (tg.season = m.season AND tg.league = m.league AND tg.team_id = m.team_id_guest) + WHERE m.season = $season + AND m.league = $league + AND m.matchday = $matchday + ORDER BY unix_match_begin ASC, m.match_no ASC"; + $result = $db->sql_query($sql); + $rows_matches = $db->sql_fetchrowset($result); + $existing_matches = sizeof($rows_matches); + $db->sql_freeresult($result); + $legend = delivery($season, $league, $matchday); + + $row_number = 0; + foreach ($rows_matches as $row_match) + { + $row_number++; + if ($this->config['football_results_at_time']) + { + $edit = (($row_match['unix_match_begin'] + 6300 < time()) && $row_match['status'] > 0) ? true :false; + } + else + { + $edit = ($row_match['status'] > 0) ? true :false; + } + if (0 == $row_match['home_id']) + { + $home_info = get_team($season, $league, $row_match['match_no'], 'team_id_home', $row_match['formula_home']); + $home_in_array = explode("#",$home_info); + $homename = $home_in_array[2]; + } + else + { + $homename = $row_match['home_name']; + } + if (0 == $row_match['guest_id']) + { + $guest_info = get_team($season, $league, $row_match['match_no'], 'team_id_guest', $row_match['formula_guest']); + $guest_in_array = explode("#",$guest_info); + $guestname = $guest_in_array[2]; + } + else + { + $guestname = $row_match['guest_name']; + } + + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('match', array( + 'ROW_CLASS' => $row_class, + 'EDIT' => $edit, + 'SELECT_CHECKED' => ($row_match['status'] > 0 AND $row_match['status'] < 3) ? ' selected="selected"' : '', + 'BEGIN' => $row_match['match_begin'], + 'NUMBER' => $row_match['match_no'], + 'STATUS' => $row_match['status'], + 'STATUS_COLOR' => color_match($row_match['status'], $row_match['status']), + 'HOME_NAME' => $homename, + 'GUEST_NAME' => $guestname, + 'GOALS_HOME' => $row_match['goals_home'], + 'GOALS_GUEST' => $row_match['goals_guest'], + 'OVERTIME_HOME' => $row_match['goals_overtime_home'], + 'OVERTIME_GUEST' => $row_match['goals_overtime_guest'], + 'NO_VALUATION_CHECKED' => ($row_match['status'] > 3) ? ' selected="selected"' : '', + 'KO_MATCH' => $row_match['ko_match'], + ) + ); + } + if ($worldfootball AND $season >= $curr_season) + { + $template->assign_block_vars('worldfootball', array( + ) + + ); + } + + // Calculate extra bets of matchday + // Start select team + $sql = 'SELECT + team_id AS option_value, + team_name AS option_name + FROM ' . FOOTB_TEAMS . " + WHERE season = $season + AND league = $league + ORDER BY team_name ASC"; + $result = $db->sql_query($sql); + $option_rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + $sql = "SELECT e.*, + t1.team_name AS result_team + FROM " . FOOTB_EXTRA . ' AS e + LEFT JOIN ' . FOOTB_TEAMS . " AS t1 ON (t1.season = e.season AND t1.league = e.league AND t1.team_id = e.result) + WHERE e.season = $season + AND e.league = $league + AND e.matchday_eval = $matchday + ORDER BY e.extra_no ASC"; + $result = $db->sql_query($sql); + + $extra_results = false; + $extranumber = 0; + while ($row = $db->sql_fetchrow($result)) + { + $extra_results = true; + $extranumber++ ; + $row_class = (!($extranumber % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + + switch($row['question_type']) + { + case '1': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '2': + { + $display_type = 1; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '3': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_HIT']); + } + break; + case '4': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_MULTI_HIT']); + } + break; + case '5': + { + $display_type = 2; + $eval_title = sprintf($user->lang['EXTRA_DIFFERENCE']); + } + break; + default : + { + $display_type = 2; + $eval_title = ''; + } + break; + } + + if ($row['extra_status'] > 0) + { + $edit_mode = true; + $result_extra = ($row['result_team'] == NULL) ? '' : $row['result_team']; + + $multiple = ''; + switch($row['question_type']) + { + case '2': + { + $multiple = ' multiple="multiple" size="3" '; + } + break; + case '4': + { + $option_arr = array(); + for ($i = 65; $i <= 72; $i++) + { + if (strstr($row['question'], chr($i) . ':')) + { + $option_arr[] = array( + 'option_value' => chr($i), + 'option_name' => chr($i), + ); + } + } + if ( sizeof($option_arr) > 1 ) + { + $display_type = 1; + $option_rows = $option_arr; + $result_extra = $row['result']; + $multiple = ' multiple="multiple" size="3" '; + } + } + break; + case '3': + { + $option_arr = array(); + for ($i = 65; $i <= 72; $i++) + { + if (strstr($row['question'], chr($i) . ':')) + { + $option_arr[] = array( + 'option_value' => chr($i), + 'option_name' => chr($i), + ); + } + } + if ( sizeof($option_arr) > 1 ) + { + $display_type = 1; + $option_rows = $option_arr; + $result_extra = $row['result']; + } + } + break; + } + + $template->assign_block_vars('extra_result', array( + 'ROW_CLASS' => $row_class, + 'EXTRA_NO' => $row['extra_no'], + 'S_EDIT_EXTRA' => true, + 'QUESTION' => $row['question'], + 'EXTRA_POINTS' => $row['extra_points'], + 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), + 'EVALUATION_TITLE' => $eval_title, + 'RESULT' => ($display_type == 1) ? $result_extra : $row['result'], + 'S_DISPLAY_TYPE' => $display_type, + 'S_MULTIPLE' => $multiple, + 'S_MULTIPLE_ARR' => ($multiple == '') ? '' : '[]', + 'STATUS' => $row['extra_status'], + 'STATUS_COLOR' => color_match($row['extra_status'], $row['extra_status']), + ) + ); + + if ($display_type == 1) + { + $selected = ($row['result'] == '') ? ' selected="selected"' : ''; + + $template->assign_block_vars('extra_result.extra_option', array( + 'OPTION_VALUE' => '', + 'OPTION_NAME' => sprintf($user->lang['SELECT']), + 'S_SELECTED' => $selected)); + + foreach ($option_rows as $option_row) + { + if (strstr($row['result'], ';')) + { + $selected = ''; + $result_arr = explode(';', $row['result']); + foreach($result_arr AS $result_value) + { + if ($result_value <> '') + { + if ($option_row['option_value'] == $result_value) + { + $selected = ' selected="selected"'; + } + } + } + } + else + { + $selected = ($option_row['option_value'] == $row['result']) ? ' selected="selected"' : ''; + } + $template->assign_block_vars('extra_result.extra_option', array( + 'OPTION_VALUE' => $option_row['option_value'], + 'OPTION_NAME' => $option_row['option_name'], + 'S_SELECTED' => $selected)); + } + } + } + else + { + $extra_colorstyle = color_style($row['extra_status']); + $extra_result = ($row['result'] == '') ? ' ' : $row['result']; + $result_extra = ($row['result_team'] == NULL) ? ' ' : $row['result_team']; + + $template->assign_block_vars('extra_result', array( + 'ROW_CLASS' => $row_class, + 'S_EDIT_EXTRA' => false, + 'QUESTION' => $row['question'], + 'EXTRA_POINTS' => $row['extra_points'], + 'EVALUATION' => ($row['matchday'] == $row['matchday_eval']) ? sprintf($user->lang['MATCHDAY']) : sprintf($user->lang['TOTAL']), + 'RESULT' => ($display_type == 1) ? $result_extra : $extra_result, + 'COLOR_STYLE' => $extra_colorstyle, + ) + ); + } + } + + switch ($league_info['bet_ko_type']) + { + case BET_KO_90: + $result_explain = sprintf($user->lang['MIN90']); + $label_finalresult = sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']); + break; + case BET_KO_EXTRATIME: + $result_explain = sprintf($user->lang['EXTRATIME_SHORT']); + $label_finalresult = sprintf($user->lang['PENALTY']); + break; + case BET_KO_PENALTY: + $result_explain = sprintf($user->lang['PENALTY']); + $ko_matchday = false; + break; + default: + $result_explain = sprintf($user->lang['MIN90']); + $label_finalresult = sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']); + break; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'results', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'S_LEGEND' => $legend, + 'S_SUCCESS' => (sizeof($success)) ? true : false, + 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', + 'RESULT_EXPLAIN' => $result_explain, + 'LABEL_FINALRESULT' => (isset($label_finalresult)) ? $label_finalresult : sprintf($user->lang['EXTRATIME_SHORT']) . '/' . sprintf($user->lang['PENALTY_SHORT']), + 'S_CASH_POINTS' => ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false, + 'S_CASH' => ($season >= $curr_season) ? true : false, + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_MATCHDAY' => $matchday, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_KO_MATCHDAY' => $ko_matchday, + 'S_MATCHDAY_OPTIONS'=> $matchday_options, + 'S_EXTRA_RESULTS' => $extra_results, + 'S_TIME' => sprintf($user->lang['TIME']) . ': ' . date("d.m.Y H:i", $local_board_time), + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + } +} + ?> \ No newline at end of file diff --git a/acp/seasons_module.php b/acp/seasons_module.php index 1859313..33f84a4 100644 --- a/acp/seasons_module.php +++ b/acp/seasons_module.php @@ -1,396 +1,394 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_seasons'); - - $this->root_path = $phpbb_root_path . 'ext/football/football/'; - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - - if(!function_exists('season_info')) - { - include($this->root_path . 'includes/functions.' . $this->php_ext); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->root_path . 'includes/constants.' . $this->php_ext); - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->tpl_name = 'acp_football_seasons'; - $this->page_title = 'ACP_FOOTBALL_SEASONS_MANAGE'; - - $form_key = 'acp_football_seasons'; - add_form_key($form_key); - - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); - $season = $this->request->variable('s', 0); - $edit = $this->request->variable('edit', 0); - $update = (isset($_POST['update'])) ? true : false; - - // Clear some vars - $season_row = array(); - $error = array(); - - // Grab basic data for season, if season is set and exists - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . " - WHERE season = $season"; - $result = $db->sql_query($sql); - $season_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - // Which page? - switch ($action) - { - case 'delete': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['SEASONS_NO_DELETE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - // Delete season - $sql = 'DELETE FROM ' . FOOTB_SEASONS . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete leagues - $sql = 'DELETE FROM ' . FOOTB_LEAGUES . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete matchdays - $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete matches - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete teams - $sql = 'DELETE FROM ' . FOOTB_TEAMS . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete ranks - $sql = 'DELETE FROM ' . FOOTB_RANKS . " - WHERE season = $season"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season"; - $db->sql_query($sql); - - trigger_error($user->lang['SEASON_DELETED'] . adm_back_link($this->u_action)); - } - else - { - confirm_box(false, sprintf($user->lang['SEASON_CONFIRM_DELETE'], $season), build_hidden_fields(array( - 's' => $season, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add': - if ($season >= 1963 AND $season <= 2099) - { - if ($season_row) - { - if ($edit) - { - $error[] = $user->lang['SEASON_TAKEN']; - } - else - { - trigger_error($user->lang['SEASON_TAKEN'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - $season_row['season_name'] = utf8_normalize_nfc($this->request->variable('season_name', '', true)); - if ($season_row['season_name'] <> '') - { - $sql = 'SELECT - season_name - FROM ' . FOOTB_SEASONS . " - WHERE season_name = '" . $season_row['season_name'] . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - $error[] = $user->lang['SEASON_NAME_TAKEN']; - } - } - else - { - $intseason = ((int) $season) - 1; - $season_row['season_name'] = $user->lang['SEASON'] . ' ' . $intseason . '/' . $season; - } - - $season_row['season_name_short'] = utf8_normalize_nfc($this->request->variable('season_short', '', true)); - if ($season_row['season_name_short'] <> '') - { - $sql = 'SELECT - season_name_short - FROM ' . FOOTB_SEASONS . " - WHERE season_name_short = '" . $season_row['season_name_short'] . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - $error[] = $user->lang['SEASON_SHORT_TAKEN']; - } - } - else - { - $intseason = ((int) $season) - 1; - $season_row['season_name_short'] = $intseason . '/' . $season; - } - } - else - { - trigger_error($user->lang['SEASON_NUMBER'] . adm_back_link($this->u_action), E_USER_WARNING); - } - // No break for edit add - case 'edit': - $data = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Did we submit? - if ($update) - { - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - return; - } - - $season_row['season_name'] = utf8_normalize_nfc($this->request->variable('season_name', '', true)); - if ($season_row['season_name'] <> '') - { - $sql = 'SELECT - season - FROM ' . FOOTB_SEASONS . " - WHERE season_name = '" . $season_row['season_name'] . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - if ($row['season'] <> $season) - { - $error[] = $user->lang['SEASON_NAME_TAKEN']; - } - } - } - else - { - $error[] = $user->lang['SEASON_NAME_EMPTY']; - } - - $season_row['season_name_short'] = utf8_normalize_nfc($this->request->variable('season_short', '', true)); - if ($season_row['season_name_short'] <> '') - { - $sql = 'SELECT - season - FROM ' . FOOTB_SEASONS . " - WHERE season_name_short = '" . $season_row['season_name_short'] . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - if ($row['season'] <> $season) - { - $error[] = $user->lang['SEASON_SHORT_TAKEN']; - } - } - } - else - { - $error[] = $user->lang['SEASON_SHORT_EMPTY']; - } - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'season_name' => $season_row['season_name'], - 'season_name_short' => $season_row['season_name_short'], - ); - - $data['season'] = $season; - $data['season_name'] = $this->request->variable('season_name', ''); - $data['season_short'] = $this->request->variable('season_short', ''); - - $var_ary = array( - 'season' => array('num', false, 1963, 2099), - 'season_name' => array('string', false, 4, 20), - 'season_short' => array('string', false, 2, 10), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - if ($action == 'add') - { - $sql = 'INSERT INTO ' . FOOTB_SEASONS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . FOOTB_SEASONS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season"; - $db->sql_query($sql); - } - $message = ($action == 'edit') ? 'SEASON_UPDATED' : 'SEASON_CREATED'; - trigger_error($user->lang[$message] . adm_back_link($this->u_action)); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $message = ($action == 'edit') ? 'SEASON_UPDATE_FAILED' : 'SEASON_CREATE_FAILED'; - $error[] = $user->lang[$message]; - $error = array_merge($error, $error_msg); - } - } - } - } - - $u_back = $this->u_action; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_SEASON' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_row['season_name'], - 'SEASON_SHORT' => $season_row['season_name_short'], - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season", - ) - ); - return; - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), - 'S_SEASON_ADD' => true, - ) - ); - - // Get us all the seasons - $sql = 'SELECT - s.season, - s.season_name, - s.season_name_short, - COUNT(l.league) AS leagues - FROM ' . FOOTB_SEASONS . ' s - LEFT JOIN ' . FOOTB_LEAGUES . ' l on l.season = s.season - GROUP BY season - ORDER BY season DESC'; - $result = $db->sql_query($sql); - $rows_seasons = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - // Check if the user is allowed to delete a season. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - foreach ($rows_seasons as $row_season) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('seasons', array( - 'ROW_CLASS' => $row_class, - 'SEASON' => $row_season['season'], - 'SEASON_NAME' => $row_season['season_name'], - 'SEASON_SHORT' => $row_season['season_name_short'], - 'LEAGUES' => $row_season['leagues'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" .$row_season['season'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $row_season['season'] : '', - ) - ); - } - } -} - +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_seasons'); + + $this->root_path = $phpbb_root_path . 'ext/football/football/'; + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + + if(!function_exists('season_info')) + { + include($this->root_path . 'includes/functions.' . $this->php_ext); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->root_path . 'includes/constants.' . $this->php_ext); + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->tpl_name = 'acp_football_seasons'; + $this->page_title = 'ACP_FOOTBALL_SEASONS_MANAGE'; + + $form_key = 'acp_football_seasons'; + add_form_key($form_key); + + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); + $season = $this->request->variable('s', 0); + $edit = $this->request->variable('edit', 0); + $update = (isset($_POST['update'])) ? true : false; + + // Clear some vars + $season_row = array(); + $error = array(); + + // Grab basic data for season, if season is set and exists + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . " + WHERE season = $season"; + $result = $db->sql_query($sql); + $season_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + // Which page? + switch ($action) + { + case 'delete': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['SEASONS_NO_DELETE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + // Delete season + $sql = 'DELETE FROM ' . FOOTB_SEASONS . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete leagues + $sql = 'DELETE FROM ' . FOOTB_LEAGUES . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete matchdays + $sql = 'DELETE FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete matches + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete teams + $sql = 'DELETE FROM ' . FOOTB_TEAMS . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete ranks + $sql = 'DELETE FROM ' . FOOTB_RANKS . " + WHERE season = $season"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season"; + $db->sql_query($sql); + + trigger_error($user->lang['SEASON_DELETED'] . adm_back_link($this->u_action)); + } + else + { + confirm_box(false, sprintf($user->lang['SEASON_CONFIRM_DELETE'], $season), build_hidden_fields(array( + 's' => $season, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add': + if ($season >= 1963 AND $season <= 2099) + { + if ($season_row) + { + if ($edit) + { + $error[] = $user->lang['SEASON_TAKEN']; + } + else + { + trigger_error($user->lang['SEASON_TAKEN'] . adm_back_link($this->u_action), E_USER_WARNING); + } + } + $season_row['season_name'] = utf8_normalize_nfc($this->request->variable('season_name', '', true)); + if ($season_row['season_name'] <> '') + { + $sql = 'SELECT + season_name + FROM ' . FOOTB_SEASONS . " + WHERE season_name = '" . $season_row['season_name'] . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + $error[] = $user->lang['SEASON_NAME_TAKEN']; + } + } + else + { + $intseason = ((int) $season) - 1; + $season_row['season_name'] = $user->lang['SEASON'] . ' ' . $intseason . '/' . $season; + } + + $season_row['season_name_short'] = utf8_normalize_nfc($this->request->variable('season_short', '', true)); + if ($season_row['season_name_short'] <> '') + { + $sql = 'SELECT + season_name_short + FROM ' . FOOTB_SEASONS . " + WHERE season_name_short = '" . $season_row['season_name_short'] . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + $error[] = $user->lang['SEASON_SHORT_TAKEN']; + } + } + else + { + $intseason = ((int) $season) - 1; + $season_row['season_name_short'] = $intseason . '/' . $season; + } + } + else + { + trigger_error($user->lang['SEASON_NUMBER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + // No break for edit add + case 'edit': + $data = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Did we submit? + if ($update) + { + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + return; + } + + $season_row['season_name'] = utf8_normalize_nfc($this->request->variable('season_name', '', true)); + if ($season_row['season_name'] <> '') + { + $sql = 'SELECT + season + FROM ' . FOOTB_SEASONS . " + WHERE season_name = '" . $season_row['season_name'] . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + if ($row['season'] <> $season) + { + $error[] = $user->lang['SEASON_NAME_TAKEN']; + } + } + } + else + { + $error[] = $user->lang['SEASON_NAME_EMPTY']; + } + + $season_row['season_name_short'] = utf8_normalize_nfc($this->request->variable('season_short', '', true)); + if ($season_row['season_name_short'] <> '') + { + $sql = 'SELECT + season + FROM ' . FOOTB_SEASONS . " + WHERE season_name_short = '" . $season_row['season_name_short'] . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + if ($row['season'] <> $season) + { + $error[] = $user->lang['SEASON_SHORT_TAKEN']; + } + } + } + else + { + $error[] = $user->lang['SEASON_SHORT_EMPTY']; + } + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'season_name' => $season_row['season_name'], + 'season_name_short' => $season_row['season_name_short'], + ); + + $data['season'] = $season; + $data['season_name'] = $this->request->variable('season_name', ''); + $data['season_short'] = $this->request->variable('season_short', ''); + + $var_ary = array( + 'season' => array('num', false, 1963, 2099), + 'season_name' => array('string', false, 4, 20), + 'season_short' => array('string', false, 2, 10), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + if ($action == 'add') + { + $sql = 'INSERT INTO ' . FOOTB_SEASONS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . FOOTB_SEASONS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season"; + $db->sql_query($sql); + } + $message = ($action == 'edit') ? 'SEASON_UPDATED' : 'SEASON_CREATED'; + trigger_error($user->lang[$message] . adm_back_link($this->u_action)); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $message = ($action == 'edit') ? 'SEASON_UPDATE_FAILED' : 'SEASON_CREATE_FAILED'; + $error[] = $user->lang[$message]; + $error = array_merge($error, $error_msg); + } + } + } + } + + $u_back = $this->u_action; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_SEASON' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_row['season_name'], + 'SEASON_SHORT' => $season_row['season_name_short'], + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season", + ) + ); + return; + break; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet')), + 'S_SEASON_ADD' => true, + ) + ); + + // Get us all the seasons + $sql = 'SELECT + s.season, + s.season_name, + s.season_name_short, + COUNT(l.league) AS leagues + FROM ' . FOOTB_SEASONS . ' s + LEFT JOIN ' . FOOTB_LEAGUES . ' l on l.season = s.season + GROUP BY season + ORDER BY season DESC'; + $result = $db->sql_query($sql); + $rows_seasons = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + // Check if the user is allowed to delete a season. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + foreach ($rows_seasons as $row_season) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('seasons', array( + 'ROW_CLASS' => $row_class, + 'SEASON' => $row_season['season'], + 'SEASON_NAME' => $row_season['season_name'], + 'SEASON_SHORT' => $row_season['season_name_short'], + 'LEAGUES' => $row_season['leagues'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" .$row_season['season'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $row_season['season'] : '', + ) + ); + } + } +} + ?> \ No newline at end of file diff --git a/acp/teams_module.php b/acp/teams_module.php index 48febe8..3004db9 100644 --- a/acp/teams_module.php +++ b/acp/teams_module.php @@ -1,659 +1,657 @@ -add_lang_ext('football/football', 'football'); - $user->add_lang_ext('football/football', 'info_acp_teams'); - - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; - if(!function_exists('season_info')) - { - include($this->ext_football_path . 'includes/functions.' . $phpEx); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->ext_football_path . 'includes/constants.' . $phpEx); - } - - $this->tpl_name = 'acp_football_teams'; - $this->page_title = 'ACP_FOOTBALL_TEAMS_MANAGE'; - - $form_key = 'acp_football_teams'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); - $edit = $this->request->variable('edit', 0); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $team = $this->request->variable('t', 0); - $update = (isset($_POST['update'])) ? true : false; - if ($action == 'add' AND $team > 0 AND !$edit) - { - $action = 'add_old'; - } - if ($action == 'add' AND $team == 0 AND !$edit) - { - $team = nextfree_teamid(); - } - // Clear some vars - $team_row = array(); - $error = array(); - - // Grab current season - if (!$season) - { - $season = curr_season(); - } - - // Grab basic data for select season - if ($season) - { - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Grab current league - if (!$league) - { - $league = first_league($season, false); - } - - // Grab basic data for select league - if ($league) - { - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . " - WHERE season = $season - ORDER BY league ASC"; - $result = $db->sql_query($sql); - - $league_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_matchdays = $row['matchdays']; - $league_name = $row['league_name']; - $league_type = $row['league_type']; - $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; - } - } - $db->sql_freeresult($result); - } - else - { - trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - // Grab all teams for selection - $sql = 'SELECT - DISTINCT team_id, - team_name - FROM ' . FOOTB_TEAMS . ' - ORDER BY team_name ASC'; - $result = $db->sql_query($sql); - $team_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ''; - $team_options .= ''; - } - $db->sql_freeresult($result); - - // Grab basic data for team, if team is set and exists - if ($team) - { - $sql = 'SELECT * - FROM ' . FOOTB_TEAMS . " - WHERE season = $season - AND league = $league - AND team_id = $team"; - $result = $db->sql_query($sql); - $team_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - if ($action == 'add' or $action == 'edit' ) - { - // Grab all Teamsymbol for selection - $teamsymbol_options = ''; - $folder = $this->ext_football_path . 'images/flags/'; - $directory = opendir($folder); - $files = array(); - while($file = readdir($directory)) - { - if( !(bool) preg_match('/.+\.(?:jpe?g|gif|png)$/i', $file) ) - { - continue; - } - $files[] = $file; - } - sort($files); - - foreach( $files as $file ) - { - $selected = (strtoupper($file) == strtoupper($team_row['team_symbol'])) ? ' selected="selected"' : ''; - $teamsymbol_options .= ''; - } - closedir($directory); - } - - // Which page? - switch ($action) - { - case 'delete': - if (!$season) - { - trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$league) - { - trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); - } - - if (!$team) - { - trigger_error($user->lang['NO_TEAM'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $error = ''; - - if (!$auth->acl_get('a_football_delete')) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - trigger_error($user->lang['TEAMS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Delete team - $sql = 'DELETE FROM ' . FOOTB_TEAMS . " - WHERE season = $season AND league = $league AND team_id = $team"; - $db->sql_query($sql); - - // Delete bets - $sql = 'DELETE FROM ' . FOOTB_BETS . " - WHERE season = $season - AND league = $league - AND match_no IN - (SELECT - DISTINCT match_no - FROM " . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league - AND (team_id_home = $team OR team_id_home = $team))"; - $db->sql_query($sql); - - // Delete matches - $sql = 'DELETE FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND (team_id_home = $team OR team_id_home = $team)"; - $db->sql_query($sql); - - trigger_error($user->lang['TEAM_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - confirm_box(false, sprintf($user->lang['TEAM_CONFIRM_DELETE'], $team_row['team_name'], $season, $league), build_hidden_fields(array( - 's' => $season, - 'l' => $league, - 't' => $team, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - - case 'add_old': - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - $sql = 'SELECT * - FROM ' . FOOTB_TEAMS . " - WHERE team_id = $team"; - $result = $db->sql_query($sql); - $oldteam_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $matchday_options = ''; - if ($ko_league) - { - // Grab all matchdays for selection - $sql = 'SELECT - DISTINCT matchday, - matchday_name - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $matchdays = 0; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($row['matchday'] == 1) ? ' selected="selected"' : ''; - $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - $matchdays++; - } - $db->sql_freeresult($result); - if (!$matchdays) - { - trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - } - - // Grab all teamsymbol for selection - $teamsymbol_options = ''; - $folder = $this->ext_football_path . 'images/flags/'; - $directory = opendir($folder); - $files = array(); - while($file = readdir($directory)) - { - if( !(bool) preg_match('/.+\.(?:jpe?g|gif|png)$/i', $file) ) - { - continue; - } - $files[] = $file; - } - sort($files); - - foreach( $files as $file ) - { - $selected = (strtoupper($file) == strtoupper($oldteam_row['team_symbol'])) ? ' selected="selected"' : ''; - $teamsymbol_options .= ''; - } - closedir($directory); - - $u_back = $this->u_action . "&s=$season&l=$league"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_TEAM' => true, - 'S_ERROR' => false, - 'S_KO_LEAGUE' => $ko_league, - 'S_VERSION_NO' => $this->config['football_version'], - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'TEAM' => $team, - 'TEAM_NAME' => $oldteam_row['team_name'], - 'TEAM_SHORT' => $oldteam_row['team_name_short'], - 'TEAM_SYMBOL' => $oldteam_row['team_symbol'], - 'TEAM_SYMBOL_OPTIONS' => $teamsymbol_options, - 'TEAM_IMAGE' => ($oldteam_row['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $oldteam_row['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', - 'TEAM_GROUP' => '', - 'TEAM_MATCHDAY_OPTIONS' => $matchday_options, - 'PHPBB_ROOT_PATH' => $phpbb_root_path, - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=add&s=$season&l=$league", - ) - ); - return; - break; - case 'add': - if ($team > 0 AND $team <= 65535) - { - if ($team_row) - { - if ($edit) - { - $error[] = $user->lang['TEAM_TAKEN']; - } - else - { - trigger_error($user->lang['TEAM_TAKEN'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - } - $team_row['team_name'] = utf8_normalize_nfc($this->request->variable('team_name', '', true)); - $team_row['team_name_short'] = utf8_normalize_nfc($this->request->variable('team_short', '', true)); - $team_row['team_symbol'] = utf8_normalize_nfc($this->request->variable('team_symbol', '', true)); - $team_row['group_id'] = utf8_normalize_nfc($this->request->variable('team_group', '', true)); - $team_row['matchday'] = utf8_normalize_nfc($this->request->variable('team_round', '', true)); - } - else - { - trigger_error($user->lang['TEAM_NUMBER'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - // No break for edit the new team - case 'edit': - - $data = array(); - - if (!sizeof($error)) - { - if ($action == 'edit' && !$team) - { - trigger_error($user->lang['NO_TEAM'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - // Did we submit? - if ($update) - { - if (!check_form_key($form_key)) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - - $team_row['team_name'] = utf8_normalize_nfc($this->request->variable('team_name', '', true)); - $team_row['team_name_short'] = utf8_normalize_nfc($this->request->variable('team_short', '', true)); - $team_row['team_symbol'] = utf8_normalize_nfc($this->request->variable('team_symbol', '', true)); - $team_row['group_id'] = utf8_normalize_nfc($this->request->variable('team_group', '', true)); - $team_row['matchday'] = utf8_normalize_nfc($this->request->variable('team_round', '', true)); - - $where_team_id = ''; - if ($team >= 6000 AND $team <= 6999) - { - $where_team_id = ' AND team_id < 7000 AND team_id > 7999'; - } - else - { - if ($team >= 7000 AND $team <= 7999) - { - $where_team_id = ' AND team_id < 6000 AND team_id > 6999'; - } - } - // Check teamname - if (strlen($team_row['team_name']) > 2) - { - // Check double entry for team - $sql = 'SELECT - DISTINCT team_id - FROM ' . FOOTB_TEAMS . " - WHERE team_name = '" . $team_row['team_name'] . "'" . $where_team_id; - $result = $db->sql_query($sql); - $name_rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - if (sizeof($name_rows) > 1) - { - $error[] = $user->lang['TEAM_NAME_DOUBLE']; - } - elseif (sizeof($name_rows) == 1) - { - if ($name_rows[0]['team_id'] <> $team) - { - $error[] = $user->lang['TEAM_NAME_DOUBLE']; - } - } - } - - // Check teamname short - if (strlen($team_row['team_name_short']) > 1) - { - // Check double entry for team - $sql = 'SELECT - DISTINCT team_id - FROM ' . FOOTB_TEAMS . " - WHERE team_name_short = '" . $team_row['team_name_short'] . "'" . $where_team_id; - $result = $db->sql_query($sql); - $short_rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - if (sizeof($short_rows) > 1) - { - $error[] = $user->lang['TEAM_SHORT_DOUBLE']; - } - elseif (sizeof($short_rows) == 1) - { - if ($short_rows[0]['team_id'] <> $team) - { - $error[] = $user->lang['TEAM_SHORT_DOUBLE']; - } - } - } - - if (!sizeof($error)) - { - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'team_id' => (int) $team, - 'team_name' => $team_row['team_name'], - 'team_name_short' => $team_row['team_name_short'], - 'team_symbol' => strlen($team_row['team_symbol']) ? $team_row['team_symbol'] : 'blank.gif', - 'group_id' => strlen($team_row['group_id']) ? $team_row['group_id'] : '', - 'matchday' => strlen($team_row['matchday']) ? $team_row['matchday'] : 0, - ); - - if ($ko_league) - { - $data['team_group'] = $team_row['group_id']; - } - else - { - $data['team_group'] = ''; - } - $data['team'] = $team; - $data['team_name'] = $team_row['team_name']; - $data['team_short'] = $team_row['team_name_short']; - - $var_ary = array( - 'team' => array('num', false, 1, 9999), - 'team_name' => array('string', false, 3, 30), - 'team_short' => array('string', false, 1, 10), - 'team_group' => array( - array('string', true, 1, 1), - array('match', true, '#^[A-Z]#')), - ); - if (!($error_vals = validate_data($data, $var_ary))) - { - if ($action == 'add') - { - $sql = 'INSERT INTO ' . FOOTB_TEAMS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . FOOTB_TEAMS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND team_id = $team"; - $db->sql_query($sql); - } - $message = ($action == 'edit') ? 'TEAM_UPDATED' : 'TEAM_CREATED'; - trigger_error($user->lang[$message] . adm_back_link($this->u_action . "&s=$season&l=$league")); - } - else - { - foreach ($error_vals as $error_val) - { - $error_msg[] = $user->lang[$error_val]; - } - $message = ($action == 'edit') ? 'TEAM_UPDATE_FAILED' : 'TEAM_CREATE_FAILED'; - $error[] = $user->lang[$message]; - $error = array_merge($error, $error_msg); - } - } - } - } - - $matchday_options = ''; - if ($ko_league) - { - // Grab all matchdays for selection - $sql = 'SELECT - DISTINCT matchday, - matchday_name - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league - ORDER BY matchday ASC"; - $result = $db->sql_query($sql); - $matchdays = 0; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($team_row['matchday'] && $row['matchday'] == $team_row['matchday']) ? ' selected="selected"' : ''; - $matchday_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); - $matchday_options .= ''; - $matchdays++; - } - $db->sql_freeresult($result); - if (!$matchdays) - { - trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); - } - } - - $u_back = $this->u_action . "&s=$season&l=$league"; - - $template->assign_vars(array( - 'S_EDIT' => true, - 'S_ADD_TEAM' => ($action == 'add') ? true : false, - 'S_ERROR' => (sizeof($error)) ? true : false, - 'S_KO_LEAGUE' => $ko_league, - 'S_VERSION_NO' => $this->config['football_version'], - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'SEASON' => $season, - 'SEASON_NAME' => $season_name, - 'LEAGUE' => $league, - 'LEAGUE_NAME' => $league_name, - 'TEAM' => $team, - 'TEAM_NAME' => $team_row['team_name'], - 'TEAM_SHORT' => $team_row['team_name_short'], - 'TEAM_SYMBOL' => $team_row['team_symbol'], - 'TEAM_SYMBOL_OPTIONS' => $teamsymbol_options, - 'TEAM_IMAGE' => ($team_row['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $team_row['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', - 'TEAM_GROUP' => $team_row['group_id'], - 'TEAM_ROUND' => $team_row['matchday'], - 'TEAM_MATCHDAY_OPTIONS' => $matchday_options, - 'PHPBB_ROOT_PATH' => $phpbb_root_path, - 'U_BACK' => $u_back, - 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", - ) - ); - - return; - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_KO_LEAGUE' => $ko_league, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_TEAM_OPTIONS' => $team_options, - 'S_TEAM_ADD' => true, - ) - ); - - // Get us all the teams - $sql = 'SELECT t.*, - SUM(IF(m.team_id_home = t.team_id, 1 , 0)) AS matches_home, - SUM(IF(m.team_id_guest = t.team_id, 1 , 0)) AS matches_away - FROM ' . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = $season AND m.league = $league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id)) - WHERE t.season = $season - AND t.league = $league - GROUP BY t.team_id - ORDER BY team_id ASC"; - $result = $db->sql_query($sql); - $rows_teams = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - // Check if the user is allowed to delete a team. - if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) - { - $allow_delete = false; - } - else - { - $allow_delete = true; - } - - $row_number = 0; - $matches = 0; - foreach ($rows_teams as $row_team) - { - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $matches += ($row_team['matches_home'] + $row_team['matches_away']) / 2; - $template->assign_block_vars('teams', array( - 'ROW_CLASS' => $row_class, - 'TEAM' => $row_team['team_id'], - 'TEAM_IMAGE' => ($row_team['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $row_team['team_symbol'] : $this->ext_football_path . 'images/flags/blank.gif', - 'TEAM_NAME' => $row_team['team_name'], - 'TEAM_SHORT' => $row_team['team_name_short'], - 'TEAM_MATCHES' => $row_team['matches_home'] + $row_team['matches_away'], - 'TEAM_HOME' => $row_team['matches_home'], - 'TEAM_GROUP' => $row_team['group_id'], - 'TEAM_ROUND' => $row_team['matchday'], - 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&t=" .$row_team['team_id'], - 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&t=" . $row_team['team_id'] : '', - 'S_VERSION_NO' => $this->config['football_version'], - ) - ); - } - $template->assign_vars(array( - 'S_TEAMS' => ($row_number) ? '(' . $row_number . ')' : '', - 'S_MATCHES' => ($row_number) ? $matches : '', - ) - ); - } -} +add_lang_ext('football/football', 'football'); + $user->add_lang_ext('football/football', 'info_acp_teams'); + + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; + if(!function_exists('season_info')) + { + include($this->ext_football_path . 'includes/functions.' . $phpEx); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->ext_football_path . 'includes/constants.' . $phpEx); + } + + $this->tpl_name = 'acp_football_teams'; + $this->page_title = 'ACP_FOOTBALL_TEAMS_MANAGE'; + + $form_key = 'acp_football_teams'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['add'])) ? 'add' : $this->request->variable('action', ''); + $edit = $this->request->variable('edit', 0); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $team = $this->request->variable('t', 0); + $update = (isset($_POST['update'])) ? true : false; + if ($action == 'add' AND $team > 0 AND !$edit) + { + $action = 'add_old'; + } + if ($action == 'add' AND $team == 0 AND !$edit) + { + $team = nextfree_teamid(); + } + // Clear some vars + $team_row = array(); + $error = array(); + + // Grab current season + if (!$season) + { + $season = curr_season(); + } + + // Grab basic data for select season + if ($season) + { + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Grab current league + if (!$league) + { + $league = first_league($season, false); + } + + // Grab basic data for select league + if ($league) + { + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . " + WHERE season = $season + ORDER BY league ASC"; + $result = $db->sql_query($sql); + + $league_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_matchdays = $row['matchdays']; + $league_name = $row['league_name']; + $league_type = $row['league_type']; + $ko_league = ($row['league_type'] == LEAGUE_KO) ? true : false; + } + } + $db->sql_freeresult($result); + } + else + { + trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + // Grab all teams for selection + $sql = 'SELECT + DISTINCT team_id, + team_name + FROM ' . FOOTB_TEAMS . ' + ORDER BY team_name ASC'; + $result = $db->sql_query($sql); + $team_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ''; + $team_options .= ''; + } + $db->sql_freeresult($result); + + // Grab basic data for team, if team is set and exists + if ($team) + { + $sql = 'SELECT * + FROM ' . FOOTB_TEAMS . " + WHERE season = $season + AND league = $league + AND team_id = $team"; + $result = $db->sql_query($sql); + $team_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + if ($action == 'add' or $action == 'edit' ) + { + // Grab all Teamsymbol for selection + $teamsymbol_options = ''; + $folder = $this->ext_football_path . 'images/flags/'; + $directory = opendir($folder); + $files = array(); + while($file = readdir($directory)) + { + if( !(bool) preg_match('/.+\.(?:jpe?g|gif|png)$/i', $file) ) + { + continue; + } + $files[] = $file; + } + sort($files); + + foreach( $files as $file ) + { + $selected = (strtoupper($file) == strtoupper($team_row['team_symbol'])) ? ' selected="selected"' : ''; + $teamsymbol_options .= ''; + } + closedir($directory); + } + + // Which page? + switch ($action) + { + case 'delete': + if (!$season) + { + trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!$league) + { + trigger_error($user->lang['NO_LEAGUE'] . adm_back_link($this->u_action . "&s=$season"), E_USER_WARNING); + } + + if (!$team) + { + trigger_error($user->lang['NO_TEAM'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + if (confirm_box(true)) + { + $error = ''; + + if (!$auth->acl_get('a_football_delete')) + { + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + trigger_error($user->lang['TEAMS_NO_DELETE'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Delete team + $sql = 'DELETE FROM ' . FOOTB_TEAMS . " + WHERE season = $season AND league = $league AND team_id = $team"; + $db->sql_query($sql); + + // Delete bets + $sql = 'DELETE FROM ' . FOOTB_BETS . " + WHERE season = $season + AND league = $league + AND match_no IN + (SELECT + DISTINCT match_no + FROM " . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league + AND (team_id_home = $team OR team_id_home = $team))"; + $db->sql_query($sql); + + // Delete matches + $sql = 'DELETE FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND (team_id_home = $team OR team_id_home = $team)"; + $db->sql_query($sql); + + trigger_error($user->lang['TEAM_DELETED'] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + confirm_box(false, sprintf($user->lang['TEAM_CONFIRM_DELETE'], $team_row['team_name'], $season, $league), build_hidden_fields(array( + 's' => $season, + 'l' => $league, + 't' => $team, + 'mode' => $mode, + 'action' => $action)) + ); + } + break; + + case 'add_old': + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + $sql = 'SELECT * + FROM ' . FOOTB_TEAMS . " + WHERE team_id = $team"; + $result = $db->sql_query($sql); + $oldteam_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $matchday_options = ''; + if ($ko_league) + { + // Grab all matchdays for selection + $sql = 'SELECT + DISTINCT matchday, + matchday_name + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $matchdays = 0; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($row['matchday'] == 1) ? ' selected="selected"' : ''; + $day_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + $matchdays++; + } + $db->sql_freeresult($result); + if (!$matchdays) + { + trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + } + + // Grab all teamsymbol for selection + $teamsymbol_options = ''; + $folder = $this->ext_football_path . 'images/flags/'; + $directory = opendir($folder); + $files = array(); + while($file = readdir($directory)) + { + if( !(bool) preg_match('/.+\.(?:jpe?g|gif|png)$/i', $file) ) + { + continue; + } + $files[] = $file; + } + sort($files); + + foreach( $files as $file ) + { + $selected = (strtoupper($file) == strtoupper($oldteam_row['team_symbol'])) ? ' selected="selected"' : ''; + $teamsymbol_options .= ''; + } + closedir($directory); + + $u_back = $this->u_action . "&s=$season&l=$league"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_TEAM' => true, + 'S_ERROR' => false, + 'S_KO_LEAGUE' => $ko_league, + 'S_VERSION_NO' => $this->config['football_version'], + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'TEAM' => $team, + 'TEAM_NAME' => $oldteam_row['team_name'], + 'TEAM_SHORT' => $oldteam_row['team_name_short'], + 'TEAM_SYMBOL' => $oldteam_row['team_symbol'], + 'TEAM_SYMBOL_OPTIONS' => $teamsymbol_options, + 'TEAM_IMAGE' => ($oldteam_row['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $oldteam_row['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', + 'TEAM_GROUP' => '', + 'TEAM_MATCHDAY_OPTIONS' => $matchday_options, + 'PHPBB_ROOT_PATH' => $phpbb_root_path, + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=add&s=$season&l=$league", + ) + ); + return; + break; + case 'add': + if ($team > 0 AND $team <= 65535) + { + if ($team_row) + { + if ($edit) + { + $error[] = $user->lang['TEAM_TAKEN']; + } + else + { + trigger_error($user->lang['TEAM_TAKEN'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + } + $team_row['team_name'] = utf8_normalize_nfc($this->request->variable('team_name', '', true)); + $team_row['team_name_short'] = utf8_normalize_nfc($this->request->variable('team_short', '', true)); + $team_row['team_symbol'] = utf8_normalize_nfc($this->request->variable('team_symbol', '', true)); + $team_row['group_id'] = utf8_normalize_nfc($this->request->variable('team_group', '', true)); + $team_row['matchday'] = utf8_normalize_nfc($this->request->variable('team_round', '', true)); + } + else + { + trigger_error($user->lang['TEAM_NUMBER'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + // No break for edit the new team + case 'edit': + + $data = array(); + + if (!sizeof($error)) + { + if ($action == 'edit' && !$team) + { + trigger_error($user->lang['NO_TEAM'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + // Did we submit? + if ($update) + { + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + + $team_row['team_name'] = utf8_normalize_nfc($this->request->variable('team_name', '', true)); + $team_row['team_name_short'] = utf8_normalize_nfc($this->request->variable('team_short', '', true)); + $team_row['team_symbol'] = utf8_normalize_nfc($this->request->variable('team_symbol', '', true)); + $team_row['group_id'] = utf8_normalize_nfc($this->request->variable('team_group', '', true)); + $team_row['matchday'] = utf8_normalize_nfc($this->request->variable('team_round', '', true)); + + $where_team_id = ''; + if ($team >= 6000 AND $team <= 6999) + { + $where_team_id = ' AND team_id < 7000 AND team_id > 7999'; + } + else + { + if ($team >= 7000 AND $team <= 7999) + { + $where_team_id = ' AND team_id < 6000 AND team_id > 6999'; + } + } + // Check teamname + if (strlen($team_row['team_name']) > 2) + { + // Check double entry for team + $sql = 'SELECT + DISTINCT team_id + FROM ' . FOOTB_TEAMS . " + WHERE team_name = '" . $team_row['team_name'] . "'" . $where_team_id; + $result = $db->sql_query($sql); + $name_rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + if (sizeof($name_rows) > 1) + { + $error[] = $user->lang['TEAM_NAME_DOUBLE']; + } + elseif (sizeof($name_rows) == 1) + { + if ($name_rows[0]['team_id'] <> $team) + { + $error[] = $user->lang['TEAM_NAME_DOUBLE']; + } + } + } + + // Check teamname short + if (strlen($team_row['team_name_short']) > 1) + { + // Check double entry for team + $sql = 'SELECT + DISTINCT team_id + FROM ' . FOOTB_TEAMS . " + WHERE team_name_short = '" . $team_row['team_name_short'] . "'" . $where_team_id; + $result = $db->sql_query($sql); + $short_rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + if (sizeof($short_rows) > 1) + { + $error[] = $user->lang['TEAM_SHORT_DOUBLE']; + } + elseif (sizeof($short_rows) == 1) + { + if ($short_rows[0]['team_id'] <> $team) + { + $error[] = $user->lang['TEAM_SHORT_DOUBLE']; + } + } + } + + if (!sizeof($error)) + { + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'team_id' => (int) $team, + 'team_name' => $team_row['team_name'], + 'team_name_short' => $team_row['team_name_short'], + 'team_symbol' => strlen($team_row['team_symbol']) ? $team_row['team_symbol'] : 'blank.gif', + 'group_id' => strlen($team_row['group_id']) ? $team_row['group_id'] : '', + 'matchday' => strlen($team_row['matchday']) ? $team_row['matchday'] : 0, + ); + + if ($ko_league) + { + $data['team_group'] = $team_row['group_id']; + } + else + { + $data['team_group'] = ''; + } + $data['team'] = $team; + $data['team_name'] = $team_row['team_name']; + $data['team_short'] = $team_row['team_name_short']; + + $var_ary = array( + 'team' => array('num', false, 1, 9999), + 'team_name' => array('string', false, 3, 30), + 'team_short' => array('string', false, 1, 10), + 'team_group' => array( + array('string', true, 1, 1), + array('match', true, '#^[A-Z]#')), + ); + if (!($error_vals = validate_data($data, $var_ary))) + { + if ($action == 'add') + { + $sql = 'INSERT INTO ' . FOOTB_TEAMS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . FOOTB_TEAMS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND team_id = $team"; + $db->sql_query($sql); + } + $message = ($action == 'edit') ? 'TEAM_UPDATED' : 'TEAM_CREATED'; + trigger_error($user->lang[$message] . adm_back_link($this->u_action . "&s=$season&l=$league")); + } + else + { + foreach ($error_vals as $error_val) + { + $error_msg[] = $user->lang[$error_val]; + } + $message = ($action == 'edit') ? 'TEAM_UPDATE_FAILED' : 'TEAM_CREATE_FAILED'; + $error[] = $user->lang[$message]; + $error = array_merge($error, $error_msg); + } + } + } + } + + $matchday_options = ''; + if ($ko_league) + { + // Grab all matchdays for selection + $sql = 'SELECT + DISTINCT matchday, + matchday_name + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league + ORDER BY matchday ASC"; + $result = $db->sql_query($sql); + $matchdays = 0; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($team_row['matchday'] && $row['matchday'] == $team_row['matchday']) ? ' selected="selected"' : ''; + $matchday_name = (strlen($row['matchday_name']) > 0) ? $row['matchday_name'] : $row['matchday'] . '. ' . sprintf($user->lang['MATCHDAY']); + $matchday_options .= ''; + $matchdays++; + } + $db->sql_freeresult($result); + if (!$matchdays) + { + trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&s=$season&l=$league"), E_USER_WARNING); + } + } + + $u_back = $this->u_action . "&s=$season&l=$league"; + + $template->assign_vars(array( + 'S_EDIT' => true, + 'S_ADD_TEAM' => ($action == 'add') ? true : false, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'S_KO_LEAGUE' => $ko_league, + 'S_VERSION_NO' => $this->config['football_version'], + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'SEASON' => $season, + 'SEASON_NAME' => $season_name, + 'LEAGUE' => $league, + 'LEAGUE_NAME' => $league_name, + 'TEAM' => $team, + 'TEAM_NAME' => $team_row['team_name'], + 'TEAM_SHORT' => $team_row['team_name_short'], + 'TEAM_SYMBOL' => $team_row['team_symbol'], + 'TEAM_SYMBOL_OPTIONS' => $teamsymbol_options, + 'TEAM_IMAGE' => ($team_row['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $team_row['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', + 'TEAM_GROUP' => $team_row['group_id'], + 'TEAM_ROUND' => $team_row['matchday'], + 'TEAM_MATCHDAY_OPTIONS' => $matchday_options, + 'PHPBB_ROOT_PATH' => $phpbb_root_path, + 'U_BACK' => $u_back, + 'U_ACTION' => "{$this->u_action}&action=$action&s=$season&l=$league", + ) + ); + + return; + break; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_KO_LEAGUE' => $ko_league, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_TEAM_OPTIONS' => $team_options, + 'S_TEAM_ADD' => true, + ) + ); + + // Get us all the teams + $sql = 'SELECT t.*, + SUM(IF(m.team_id_home = t.team_id, 1 , 0)) AS matches_home, + SUM(IF(m.team_id_guest = t.team_id, 1 , 0)) AS matches_away + FROM ' . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = $season AND m.league = $league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id)) + WHERE t.season = $season + AND t.league = $league + GROUP BY t.team_id + ORDER BY team_id ASC"; + $result = $db->sql_query($sql); + $rows_teams = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + // Check if the user is allowed to delete a team. + if ($user->data['user_type'] != USER_FOUNDER && $this->config['football_founder_delete']) + { + $allow_delete = false; + } + else + { + $allow_delete = true; + } + + $row_number = 0; + $matches = 0; + foreach ($rows_teams as $row_team) + { + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $matches += ($row_team['matches_home'] + $row_team['matches_away']) / 2; + $template->assign_block_vars('teams', array( + 'ROW_CLASS' => $row_class, + 'TEAM' => $row_team['team_id'], + 'TEAM_IMAGE' => ($row_team['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $row_team['team_symbol'] : $this->ext_football_path . 'images/flags/blank.gif', + 'TEAM_NAME' => $row_team['team_name'], + 'TEAM_SHORT' => $row_team['team_name_short'], + 'TEAM_MATCHES' => $row_team['matches_home'] + $row_team['matches_away'], + 'TEAM_HOME' => $row_team['matches_home'], + 'TEAM_GROUP' => $row_team['group_id'], + 'TEAM_ROUND' => $row_team['matchday'], + 'U_EDIT' => "{$this->u_action}&action=edit&s=" . $season . "&l=" .$league . "&t=" .$row_team['team_id'], + 'U_DELETE' => ($allow_delete) ? "{$this->u_action}&action=delete&s=" . $season . "&l=" . $league . "&t=" . $row_team['team_id'] : '', + 'S_VERSION_NO' => $this->config['football_version'], + ) + ); + } + $template->assign_vars(array( + 'S_TEAMS' => ($row_number) ? '(' . $row_number . ')' : '', + 'S_MATCHES' => ($row_number) ? $matches : '', + ) + ); + } +} ?> \ No newline at end of file diff --git a/acp/update_module.php b/acp/update_module.php index e6acf91..725e12d 100644 --- a/acp/update_module.php +++ b/acp/update_module.php @@ -1,1462 +1,1458 @@ - 0, - 'team_id_guest' => 0, - 'match_datetime' => 0, - 'group_id' => 0, - 'formula_home' => 0, - 'formula_guest' => 0, - 'ko_match' => 0 - ); - public $u_action; - public $ext_football_path; - - protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - protected $root_path, $request, $php_ext, $log; - - - public function __construct() - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $user->add_lang_ext('football/football', 'info_acp_update'); - - $this->db = $db; - $this->user = $user; - $this->template = $template; - $this->config = $config; - $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpbb_admin_path = $phpbb_admin_path; - $this->php_ext = $phpEx; - if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) { - // Get an instance of the ultimatepoints functions_points - $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); - } - } - - public function key_compare_func($key1, $key2) - { - if ($key1 == $key2) - return 0; - else if ($key1 > $key2) - return 1; - else - return -1; - } - - public function sort_teams($value_a, $value_b) - { - if ($value_a['team_id'] > $value_b['team_id']) - { - return 1; - } - else - { - if ($value_a['team_id'] == $value_b['team_id']) - { - return 0; - } - else - { - return -1; - } - } - } - - function main($id, $mode) - { - global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points, $phpbb_log; - global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx, $cache; - $provider = new \phpbb\controller\ provider(); - $symphony_request = new \phpbb\ symfony_request($request); - $filesystem = new \phpbb\ filesystem(); - $helper = new \phpbb\controller\ helper($template, $user, $config, $provider, $phpbb_extension_manager, $symphony_request, $request, $filesystem, $phpbb_root_path, $phpEx); - - $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; - if(!function_exists('season_info')) - { - include($this->ext_football_path . 'includes/functions.' . $phpEx); - } - if (!defined('FOOTB_SEASONS')) - { - include($this->ext_football_path . 'includes/constants.' . $phpEx); - } - - $this->tpl_name = 'acp_football_update'; - $this->page_title = 'ACP_FOOTBALL_UPDATE_MANAGE'; - - $form_key = 'acp_football_update'; - add_form_key($form_key); - - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - - // Check and set some common vars - $action = (isset($_POST['load_xml_season'])) ? 'load_xml_season' : ''; - $action = (isset($_POST['team_mapping'])) ? 'team_mapping' : $action; - $action = (isset($_POST['map_teams'])) ? 'map_teams' : $action; - $action = (isset($_POST['load_xml_league'])) ? 'load_xml_league' : $action; - $action = (isset($_POST['choose'])) ? 'choose' : $action; - $action = (isset($_POST['list'])) ? 'list' : $action; - $action = (isset($_POST['insert'])) ? 'insert' : $action; - $action = (isset($_POST['update'])) ? 'update' : $action; - $action = (empty($action)) ? $this->request->variable('action', '') : $action; - $xml_season_url = $this->request->variable('xml_season_url', ''); - $xml_league_url = $this->request->variable('xml_league_url', ''); - $xseason = $this->request->variable('xs', 0); - $xleague = $this->request->variable('xl', 0); - $xcode = $this->request->variable('xcode', ''); - $season = $this->request->variable('s', 0); - $league = $this->request->variable('l', 0); - $league_name = $this->request->variable('league_name', ''); - $new_league = $this->request->variable('new_league', 0); - $insert_season = $this->request->variable('insert_season', false); - $insert_league = $this->request->variable('insert_league', false); - $list = $this->request->variable('list', false); - $this->xml_ary = unserialize(urldecode($this->request->variable('xml_ary', ''))); - $display_team_mapping = false; - // Clear some vars - $error = array(); - $success = array(); - $missing_team_ids_ary = array(); - $curr_season = curr_season(); - $choose_league = false; - $xseason_options = ''; - $xleague_options = ''; - $season_options = ''; - $league_options = ''; - - // Grab current season - $season = ($season) ? $season : $curr_season; - - // Which action? - switch ($action) - { - case 'load_xml_season': - case 'choose': - if (!$xml_season_url or strtoupper($xml_season_url) == 'LOCALHOST') - { - $xml_season_url = 'localhost'; - // Search files on localhost - $files = glob($phpbb_root_path . "/store/league*.xml"); - if ($files) - { - $first_season = ($xseason) ? false : true; - $first_league = ($xleague) ? false : true; - foreach (glob($phpbb_root_path . "/store/league*.xml") AS $filename) - { - if ($xml = @simplexml_load_file($filename)) - { - if ($first_season) - { - $selected = ' selected="selected"'; - $xseason = $xml->footb_seasons->season; - $first_season = false; - } - else - { - $selected = ($xseason && $xml->footb_seasons->season == $xseason) ? ' selected="selected"' : ''; - } - $xseason_options .= ''; - if ($selected <> '') - { - $xseason_name = $xml->footb_seasons->season_name_short; - if ($first_league) - { - $selected = ' selected="selected"'; - $first_league = false; - } - else - { - $selected = ($xleague && $xml->footb_leagues->league == $xleague) ? ' selected="selected"' : ''; - } - $xleague_options .= ''; - if ($selected <> '') - { - $league_name = $xml->footb_leagues->league_name; - } - } - } - else - { - trigger_error(sprintf($user->lang['ERROR_LOAD_LEAGUE_XML'], strstr($filename, "\\")) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - } - else - { - trigger_error(sprintf($user->lang['NO_XML_LEAGUE']) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - else - { - if (!($xml_str = $cache->get('football_xml_season'))) - { - if ($xml_str = @file_get_contents($xml_season_url)) - { - if (strpos($xml_str, 'put('football_xml_season', $xml_str, 300); - } - else - { - trigger_error(sprintf($user->lang['ERROR_READ_SEASON_XML']) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - else - { - trigger_error(sprintf($user->lang['ERROR_OPEN_SEASON_XML']) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - if($xml_season = new \SimpleXMLElement($xml_str)) - { - $first_league = ($xleague) ? false : true; - $xcode = $xml_season->code; - foreach($xml_season->season AS $tag_season) - { - $xseason = ($xseason) ? $xseason : $tag_season->season_id; - $selected = ($xseason && $tag_season->season_id == $xseason) ? ' selected="selected"' : ''; - $xseason_options .= ''; - if ($selected <> '') - { - foreach($tag_season->league AS $tag_league) - { - $selected = ($xleague && $tag_league->league_id == $xleague) ? ' selected="selected"' : ''; - if ($first_league) - { - $selected = ' selected="selected"'; - $xleague = $tag_league->league_id; - $first_league = false; - } - $xleague_options .= ''; - if ($selected <> '') - { - $league_name = $tag_league->league_name; - } - } - } - } - } - else - { - trigger_error($user->lang['NO_XML_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - } - // Grab basic data for select season - $sql = 'SELECT * - FROM ' . FOOTB_SEASONS . ' - ORDER BY season DESC'; - $result = $db->sql_query($sql); - - $season_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; - $season_options .= ''; - if ($selected <> '') - { - $season_name = $row['season_name_short']; - } - } - $db->sql_freeresult($result); - - // Grab basic data for select league - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . ' - WHERE season = ' . $season . ' - ORDER BY league ASC'; - $result = $db->sql_query($sql); - - $league_options = ''; - if (!$league) - { - $league_options = ''; - $new_league = $xleague; - } - else - { - $league_options = ''; - $new_league = $league; - } - while ($row = $db->sql_fetchrow($result)) - { - // Grab current league - $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; - $league_options .= ''; - if ($selected <> '') - { - $league_name = $row['league_name']; - } - } - $db->sql_freeresult($result); - - $choose_league = true; - $list = false; - break; - - case 'team_mapping': - case 'map_teams': - case 'load_xml_league': - if ($xseason == 0 or $xleague == 0) - { - trigger_error(sprintf($user->lang['NO_XML_SEASON']) . adm_back_link($this->u_action), E_USER_WARNING); - } - - if ($season == 0) - { - // No Season exists - $season = $xseason; - $insert_season = true; - // No league exists, so we want to insert the source league - $league = $xleague; - $insert_league = true; - } - else - { - if ($league == 0) - { - // New league so try to create the source league - $league = ($new_league) ? $new_league : $xleague; - $insert_league = true; - // Selected source league exist - if (sizeof(league_info($season, $league))) - { - trigger_error(sprintf($user->lang['NEW_LEAGUE_EXIST'], $league) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - } - - if (!$xml_season_url or strtoupper($xml_season_url) == 'LOCALHOST') - { - $xml_season_url = 'localhost'; - $xml_league_url = $phpbb_root_path . '/store/league_' . $xseason . '_' . $xleague . '.xml'; - } - else - { - $xml_league_url = substr($xml_season_url, 0, strrpos($xml_season_url, "/") + 1) . - "league.php?season=" . $xseason . "&league=" . $xleague . "&code=" . $xcode; - } - $cache_league = 'football_xml_league_' . $xseason . '_' . $xleague; - $this->xml_ary = $this->xml2array($xml_league_url, $cache_league); - - $team_id_map_ary = array(); - $duplicate_team_ids_ary = array(); - if ($action == 'map_teams') - { - if ($this->check_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary, $missing_team_ids_ary)) - { - $action = 'team_mapping'; - } - } - - if ($action == 'team_mapping') - { - if ($this->compare_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary)) - { - $display_team_mapping = true; - break; - } - } - - if (!$insert_league) - { - $league_info = league_info($season, $league); - $sql = 'SELECT COUNT(matchday) as matchdays - FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - if ($row['matchdays'] <> $league_info['matchdays']) - { - $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $row['matchdays']); - } - } - else - { - $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $row['matchdays']); - } - - $sql = 'SELECT COUNT(match_no) as matches - FROM ' . FOOTB_MATCHES . " - WHERE season = $season - AND league = $league"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - if ($row['matches'] <> sizeof($this->xml_ary['footb_matches'])) - { - $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $row['matches']); - } - } - else - { - $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $row['matches']); - } - - if (!sizeof($error)) - { - // Compare Update with existing database and switch season and league - $this->compare_table('FOOTB_LEAGUES', $season, $league, '', true, $error); - $this->compare_table('FOOTB_MATCHDAYS', $season, $league, '', true, $error); - $this->compare_table('FOOTB_TEAMS', $season, $league, '', true, $error); - $this->compare_table('FOOTB_MATCHES', $season, $league,'', true, $error); - } - } - if (!sizeof($error)) - { - foreach ($this->xml_ary['footb_teams'] AS $key => $value) - { - $this->team_ary[$value['team_id']] = $value['team_name']; - } - $this->team_ary[0] = ''; - - $choose_league = false; - $list = true; - if ($insert_season) - { - // Set default values for new season - $this->xml_ary[strtolower('footb_seasons')][0]['season'] = "$season"; - $this->xml_ary[strtolower('footb_seasons')][0]['season_name'] = sprintf($user->lang['SEASON']) . " " . ($season - 1) . "/" . $season; - $this->xml_ary[strtolower('footb_seasons')][0]['season_name_short'] = $season - 1 . "/" . $season; - $this->show_xml($this->xml_ary, 'FOOTB_SEASONS', $season, 0); - } - if ($insert_league) - { - // Show complete update - $this->show_xml($this->xml_ary, 'FOOTB_LEAGUES', $season, $league); - $this->show_xml($this->xml_ary, 'FOOTB_MATCHDAYS', $season, $league); - $this->show_xml($this->xml_ary, 'FOOTB_TEAMS', $season, $league); - $this->show_xml($this->xml_ary, 'FOOTB_MATCHES', $season, $league); - } - else - { - // Display differences between update and database - $this->compare_table('FOOTB_MATCHDAYS', $season, $league, 'matchday', false, $error); - $this->compare_table('FOOTB_TEAMS', $season, $league, 'team_id', false, $error); - $this->compare_table('FOOTB_MATCHES', $season, $league, 'match_no', false, $error); - } - } - break; - case 'insert': - if ($insert_season) - { - if ($count_inserts = $this->insert_league('FOOTB_SEASONS')) - { - $success[] = sprintf($user->lang['DB_INSERT_SEASON'], $count_inserts); - } - } - if ($count_inserts = $this->insert_league('FOOTB_LEAGUES')) - { - $success[] = sprintf($user->lang['DB_INSERT_LEAGUE'], $count_inserts); - } - if ($count_inserts = $this->insert_league('FOOTB_MATCHDAYS')) - { - $success[] = sprintf($user->lang['DB_INSERT_MATCHDAY' . (($count_inserts == 1) ? '' : 'S')], $count_inserts); - } - if ($count_inserts = $this->insert_league('FOOTB_TEAMS')) - { - $success[] = sprintf($user->lang['DB_INSERT_TEAM' . (($count_inserts == 1) ? '' : 'S')], $count_inserts); - } - if ($count_inserts = $this->insert_league('FOOTB_MATCHES')) - { - $success[] = sprintf($user->lang['DB_INSERT_MATCH' . (($count_inserts == 1) ? '' : 'ES')], $count_inserts); - } - $log_message = implode('
', $success); - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($league_name . ' ' . $season . '
' . $log_message)); - break; - case 'update': - if ($count_updates = $this->update_league('FOOTB_MATCHDAYS', $season, $league, 'matchday')) - { - $success[] = sprintf($user->lang['DB_UPDATE_MATCHDAY' . (($count_updates == 1) ? '' : 'S')], $count_updates); - } - if ($count_updates = $this->update_league('FOOTB_TEAMS', $season, $league, 'team_id')) - { - $success[] = sprintf($user->lang['DB_UPDATE_TEAM' . (($count_updates == 1) ? '' : 'S')], $count_updates); - } - if ($count_updates = $this->insert_new_teams($season, $league)) - { - $success[] = sprintf($user->lang['DB_INSERT_TEAM' . (($count_updates == 1) ? '' : 'S')], $count_updates); - } - if ($count_updates = $this->update_league('FOOTB_MATCHES', $season, $league, 'match_no')) - { - $success[] = sprintf($user->lang['DB_UPDATE_MATCH' . (($count_updates == 1) ? '' : 'ES')], $count_updates); - } - - // set delivery for bet in time - $league_info = league_info($season, $league); - if ($league_info['bet_in_time']) - { - $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . " (season, league, matchday, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) - SELECT m.season, m.league, m.matchday, min(m.match_datetime) AS delivery_date, '' AS delivery_date_2, '' AS delivery_date_3, md.matchday_name, md.matches - FROM " . FOOTB_MATCHES . ' AS m - JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) - JOIN ' . FOOTB_MATCHDAYS . " AS md ON (md.season = m.season AND md.league = m.league AND md.matchday = m.matchday) - WHERE m.season = $season - AND m.league = $league - AND l.bet_in_time = 1 - AND m.status = 0 - GROUP BY m.season, m.league, m.matchday"; - $db->sql_query($sql); - $count_updates = $db->sql_affectedrows(); - if ($count_updates) - { - $success[] = sprintf($user->lang['DB_UPDATE_BIT_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $count_updates) ; - } - } - else - { - // set first delivery - $effected_matchdays = ''; - $count_updates = 0; - $sql = 'SELECT md.matchday - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = 0 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date > agg.min_delivery_date - ORDER BY md.matchday"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $count_updates++; - $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; - } - if ($effected_matchdays <> '') - { - $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) - SELECT md.season - , md.league - , md.matchday - , md.status - , min_delivery_date AS delivery_date - , md.delivery_date_2 - , md.delivery_date_3 - , md.matchday_name - , md.matches - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = 0 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date > agg.min_delivery_date"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; - } - // set second delivery - $effected_matchdays = ''; - $count_updates = 0; - $sql = 'SELECT md.matchday - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = -1 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date_2 > agg.min_delivery_date - ORDER BY md.matchday"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $count_updates++; - $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; - } - if ($effected_matchdays <> '') - { - $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) - SELECT md.season - , md.league - , md.matchday - , md.status - , md.delivery_date - , min_delivery_date AS delivery_date_2 - , md.delivery_date_3 - , md.matchday_name - , md.matches - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = -1 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date_2 > agg.min_delivery_date"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; - } - // set third delivery - $effected_matchdays = ''; - $count_updates = 0; - $sql = 'SELECT md.matchday - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = -2 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date_3 > agg.min_delivery_date - ORDER BY md.matchday"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $count_updates++; - $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; - } - if ($effected_matchdays <> '') - { - $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) - SELECT md.season - , md.league - , md.matchday - , md.status - , md.delivery_date - , md.delivery_date_2 - , min_delivery_date AS delivery_date_3 - , md.matchday_name - , md.matches - FROM ' . FOOTB_MATCHDAYS . ' AS md - INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND status = -2 - GROUP BY season, league, matchday) AS agg - WHERE md.season = agg.season - AND md.league = agg.league - AND md.matchday = agg.matchday - AND md.delivery_date_3 > agg.min_delivery_date"; - $db->sql_query($sql); - $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; - } - } - - // check status of matchdays - $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); - $sql = $sql = 'UPDATE ' . FOOTB_MATCHDAYS . " AS target - INNER JOIN - ( - SELECT md.season - , md.league - , md.matchday - , IF( md.delivery_date > now(), - 0, - IF(ISNULL(min(e.extra_status)), - IF(min(m.status) = 1 AND max(m.status) > 1, - 2, - GREATEST(min(m.status), 0)), - IF(LEAST(min(m.status), min(e.extra_status)) = 1 AND GREATEST(max(m.status), max(e.extra_status)) > 1, - 2, - GREATEST(LEAST(min(m.status), min(e.extra_status)), 0)))) As new_status - FROM " . FOOTB_MATCHDAYS . ' AS md - LEFT JOIN ' . FOOTB_MATCHES . ' AS m ON (m.season = md.season AND m.league = md.league AND m.matchday = md.matchday) - LEFT JOIN ' . FOOTB_EXTRA . " AS e ON (e.season = md.season AND e.league = md.league AND e.matchday_eval = md.matchday) - WHERE md.season = $season AND md.league = $league - GROUP BY md.season, md.league, md.matchday) AS source - ON target.season = source.season AND target.league = source.league AND target.matchday = source.matchday - SET target.status = source.new_status"; - $db->sql_query($sql); - $count_updates = $db->sql_affectedrows(); - if ($count_updates) - { - $success[] = sprintf($user->lang['DB_UPDATE_STATUS_MATCHDAY' . (($count_updates == 1) ? '' : 'S')], $count_updates); - } - if (sizeof($success)) - { - $cash = ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false; - save_ranking_matchday($season, $league, 1, $cash); - $log_message = implode('
', $success); - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($league_info['league_name'] . ' ' . $season . '
' . $log_message)); - } - else - { - $success[] = sprintf($user->lang['NO_DB_CHANGES']); - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($success[0])); - } - break; - } - $allow_url_fopen = (int) @ini_get('allow_url_fopen'); - if ($allow_url_fopen) - { - if (trim($this->config['football_update_source']) == '') - { - $xml_season_url = ($xml_season_url == '') ? 'http://football.bplaced.net/ext/football/football/xml/seasons.php' : $xml_season_url; - } - else - { - $xml_season_url = trim($this->config['football_update_source']); - } - } - else - { - $xml_season_url = 'localhost'; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_CHOOSE_ACTION' => $this->u_action . "&action=choose", - 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), - 'S_ERROR' => (sizeof($error)) ? true : false, - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'S_SUCCESS' => (sizeof($success)) ? true : false, - 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', - 'S_MISSING_TEAMS' => (sizeof($missing_team_ids_ary)) ? sprintf($user->lang['MISSING_TEAMS'], implode(', ', $missing_team_ids_ary)) : '', - 'S_ALLOW_URL_FOPEN' => ($allow_url_fopen) ? true : false, - 'S_CHOOSE' => $choose_league, - 'S_TEAMS' => $display_team_mapping, - 'S_LIST' => $list, - 'S_INSERT_SEASON' => $insert_season, - 'S_INSERT_LEAGUE' => $insert_league, - 'S_CHECK_SAME_STATUS' => '', - 'S_CHECK_ONLY_FINAL' => 'checked="checked"', - 'S_VERSION_NO' => $this->config['football_version'], - 'DO_MATCHDAYS' => ($insert_league) ? sprintf($user->lang['INSERT_MATCHDAYS']) : sprintf($user->lang['UPDATE_MATCHDAYS']), - 'DO_TEAMS' => ($insert_league) ? sprintf($user->lang['INSERT_TEAMS']) : sprintf($user->lang['UPDATE_TEAMS']), - 'DO_MATCHES' => ($insert_league) ? sprintf($user->lang['INSERT_MATCHES']) : sprintf($user->lang['UPDATE_MATCHES']), - 'XML_SEASON_URL' => $xml_season_url, - 'XML_LEAGUE_URL' => $xml_league_url, - 'XML_ARY' => (sizeof($this->xml_ary)) ? urlencode(serialize($this->xml_ary)) : '', - 'S_XSEASON_OPTIONS' => $xseason_options, - 'S_XLEAGUE_OPTIONS' => $xleague_options, - 'S_XSEASON' => $xseason, - 'S_XLEAGUE' => $xleague, - 'S_XCODE' => $xcode, - 'S_SEASON_OPTIONS' => $season_options, - 'S_LEAGUE_OPTIONS' => $league_options, - 'S_SEASON' => $season, - 'S_LEAGUE' => $league, - 'S_LEAGUE_NAME' => $league_name, - 'NEW_LEAGUE' => $new_league, - ) - ); - } - - function xml2array($xml_league_url, $cache_league) - { - global $cache; - - if (!($xml_str = $cache->get($cache_league))) - { - if ($xml_str = @file_get_contents($xml_league_url)) - { - if (strpos($xml_str, 'put($cache_league, $xml_str, 900); - } - else - { - trigger_error(sprintf($user->lang['ERROR_READ_LEAGUE_XML']) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - else - { - trigger_error(sprintf($user->lang['ERROR_OPEN_LEAGUE_XML']) . adm_back_link($this->u_action), E_USER_WARNING); - } - } - $xml_league = new \SimpleXMLElement($xml_str); - - $xml_table = array(); - foreach ($xml_league->children() AS $node) - { - $xml_entry = array(); - foreach($node->children() AS $cnode) - { - $xml_entry[$cnode->getName()] = sprintf("%s", $cnode); - } - $xml_table[$node->getName()][] = $xml_entry; - $this->xml_ary[$node->getName()] = $xml_table[$node->getName()]; - } - return $this->xml_ary; - } - - function check_teams($season, $league, &$team_id_map_ary, &$duplicate_team_ids_ary, &$missing_team_ids_ary) - { - global $config, $db, $user, $auth, $template, $cache; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; - - $team_id_ary = array(); - foreach ($this->xml_ary['footb_teams'] AS $xml_team) - { - $new_team_id = $this->request->variable('team_id_db_' . $xml_team['team_id'], 0); - $team_id_map_ary[$xml_team['team_id']] = $new_team_id; - if (in_array($new_team_id, $team_id_ary) or $new_team_id == 0) - { - $duplicate_team_ids_ary[] = $new_team_id; - } - else - { - $team_id_ary[] = $new_team_id; - } - } - $table_name = constant('FOOTB_TEAMS'); - // All database teams selected? - $sql = 'SELECT team_id - FROM ' . $table_name . " - WHERE season = $season - AND league = $league - ORDER BY team_id"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (!in_array($row['team_id'], $team_id_ary)) - { - $missing_team_ids_ary[] = $row['team_id']; - } - } - $db->sql_freeresult($result); - if (sizeof($duplicate_team_ids_ary) or sizeof($missing_team_ids_ary)) - { - // Display Mapping - return true; - } - else - { - // set new IDs in xml_ary - foreach ($this->xml_ary['footb_teams'] AS $key => $xml_team) - { - $this->xml_ary['footb_teams'][$key]['team_id'] = $team_id_map_ary[$xml_team['team_id']]; - } - usort($this->xml_ary['footb_teams'], 'sort_teams'); - - foreach ($this->xml_ary['footb_matches'] AS $key => $xml_team) - { - $this->xml_ary['footb_matches'][$key]['team_id_home'] = $team_id_map_ary[$xml_team['team_id_home']]; - $this->xml_ary['footb_matches'][$key]['team_id_guest'] = $team_id_map_ary[$xml_team['team_id_guest']]; - } - return false; - } - } - - - function compare_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary) - { - global $config, $db, $user, $auth, $template, $cache; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; - - $i = 0; - $j = 0; - $db_teams = array(); - $different_teams = false; - $same_quantity = false; - $table_name = constant('FOOTB_TEAMS'); - // Grab basic data for select league - $sql = 'SELECT team_id - , team_name - , team_name_short - , team_symbol - FROM ' . $table_name . " - WHERE season = $season - AND league = $league - ORDER BY team_name"; - $result = $db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $same_quantity = (sizeof($rows) == sizeof($this->xml_ary['footb_teams'])) ? true : false; - - if ($same_quantity) - { - foreach ($rows AS $row) - { - $db_teams[$row['team_id']] = $row; - } - } - else - { - $different_teams = true; - $sql = 'SELECT DISTINCT team_id - , team_name - , team_name_short - , team_symbol - FROM ' . $table_name . " - ORDER BY team_name"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $db_teams[$row['team_id']] = $row; - } - $db->sql_freeresult($result); - } - $row_number = 0; - foreach ($this->xml_ary['footb_teams'] AS $xml_team) - { - $team_options = ''; - $team_id = (sizeof($team_id_map_ary)) ? $team_id_map_ary[$xml_team['team_id']] : $xml_team['team_id']; - if (!$same_quantity) - { - if (array_key_exists($team_id, $db_teams)) - { - $team_options = ''; - } - else - { - $team_options = ''; - } - } - foreach ($db_teams AS $db_team_id => $db_team_data) - { - $selected = ($db_team_id == $team_id) ? ' selected="selected"' : ''; - $team_options .= ''; - } - if (!array_key_exists($team_id, $db_teams) or sizeof($duplicate_team_ids_ary)) - { - $different_teams = true; - } - $row_number++; - $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $template->assign_block_vars('teams', array( - 'ROW_CLASS' => $row_class, - 'TEAM_ID_XML' => $xml_team['team_id'], - 'TEAM_IMAGE_XML' => ($xml_team['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $xml_team['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', - 'TEAM_NAME_XML' => $xml_team['team_name'], - 'TEAM_NAME_SHORT_XML' => $xml_team['team_name_short'], - 'TEAM_OPTIONS' => $team_options, - 'DUPLICATE_TEAM' => (in_array($team_id, $duplicate_team_ids_ary)) ? true : false, - - )); - } - if ($different_teams) - { - // Display Mapping - return true; - } - else - { - return false; - } - } - - function compare_table($table, $season, $league, $index_field, $check, &$error) - { - global $config, $db, $user, $auth, $template, $cache; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; - - $i = 0; - $j = 0; - $tpl = ''; - $order = ($table == 'FOOTB_MATCHES') ? array('season' => 0, 'league' => 0, 'match_no' => 1, 'team_id_home' => 4, 'team_id_guest' => 5, - 'goals_home' => 6, 'goals_guest' => 7, 'matchday' => 0, 'status' => 12, 'match_datetime' => 2, - 'group_id' => 3, 'formula_home' => 10, 'formula_guest' => 11, 'ko_match' => 13, - 'goals_overtime_home' => 8, 'goals_overtime_guest' => 9) : array(); - $table_name = constant($table); - // Grab basic data for select league - $sql = 'SELECT * - FROM ' . $table_name . " - WHERE season = $season - AND league = $league - ORDER BY 1, 2, 3"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if ($table == 'FOOTB_TEAMS') - { - while ($i < sizeof($this->xml_ary[strtolower($table)]) and $this->xml_ary[strtolower($table)][$i]['team_id'] <> $row['team_id']) - { - // New team - if ($check) - { - $this->xml_ary[strtolower($table)][$i]['season'] = "$season"; - $this->xml_ary[strtolower($table)][$i]['league'] = "$league"; - } - else - { - $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $id = 'insert_team'; - $tpl .= $this->print_differences(array(), $this->xml_ary[strtolower($table)][$i], $this->xml_ary[strtolower($table)][$i], $id, $row_class, array()); - $j++; - } - $i++; - } - } - $diff = array_diff_assoc($this->xml_ary[strtolower($table)][$i], $row); - if ($check) - { - foreach ($diff AS $key => $value) - { - switch($key) - { - case 'league': - $this->xml_ary[strtolower($table)][$i]['league'] = "$league"; - break; - case 'league_type': - $error[] = sprintf($user->lang['MISMATCH_LEAGUE_TYPE'], $value); - break; - case 'matchdays': - $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $value); - break; - case 'matches_on_matchday': - $error[] = sprintf($user->lang['MISMATCH_MOM'], $value); - break; - case 'matches': - $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $value); - break; - case 'season': - $this->xml_ary[strtolower($table)][$i]['season'] = "$season"; - break; - } - } - } - else - { - if (sizeof($diff)) - { - $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $id = $table . '_' . $row[$index_field]; - $tpl .= $this->print_differences($row, $this->xml_ary[strtolower($table)][$i], $diff, $id, $row_class, $order); - $j++; - } - } - $i++; - } - $db->sql_freeresult($result); - if (!$check and $tpl <> '') - { - $template->assign_block_vars(strtolower($table), array( - 'TPL' => $tpl, - )); - } - } - - - function show_xml(&$xml_ary, $table, $season, $league) - { - global $config, $db, $user, $auth, $template, $cache; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; - - $j = 0; - $tpl = ''; - switch ($table) - { - case 'FOOTB_LEAGUES': - $order = array('season' => 0, 'league' => 0, 'league_name' => 0, 'league_name_short' => 2, 'league_type' => 4, - 'matchdays' => 6, 'matches_on_matchday' => 8, 'win_result' => 10, 'win_result_02' => 10, 'win_matchday' => 10, - 'win_season' => 10, 'points_mode' => 10, 'points_result' => 12, 'points_tendency' => 12, - 'points_diff' => 12, 'points_last' => 12, 'join_by_user' => 12, 'join_in_season' => 12, - 'bet_in_time' => 12, 'rules_post_id' => 14, 'bet_ko_type' => 14, 'bet_points' => 16); - break; - case 'FOOTB_MATCHES': - $order = array('season' => 0, 'league' => 0, 'match_no' => 1, 'team_id_home' => 4, 'team_id_guest' => 5, - 'goals_home' => 6, 'goals_guest' => 7, 'matchday' => 0, 'status' => 12, 'match_datetime' => 2, - 'group_id' => 3, 'formula_home' => 10, 'formula_guest' => 11, 'ko_match' => 13, - 'goals_overtime_home' => 8, 'goals_overtime_guest' => 9); - break; - default: - $order = array(); - } - foreach ($this->xml_ary[strtolower($table)] AS $key => $xml_row) - { - $this->xml_ary[strtolower($table)][$key]['season'] = "$season"; - if ($league) - { - $this->xml_ary[strtolower($table)][$key]['league'] = "$league"; - } - $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - $tpl .= $this->print_xml_data($xml_row, $row_class, $order); - $j++; - } - $template->assign_block_vars(strtolower($table), array( - 'TPL' => $tpl, - )); - } - - - /** - * Print differences beetween Database and XML-Data - */ - function print_differences($table_row, $xml_row, $diff, $id, $row_class, $order) - { - global $user, $league_info; - - if (sizeof($table_row) AND substr($id, 0, 11) == 'FOOTB_TEAMS') - { - if ($xml_row['team_symbol'] == '') - { - unset($diff['team_symbol']); - if (!sizeof($diff)) - { - return ''; - } - } - } - if (sizeof($table_row) AND substr($id, 0, 13) == 'FOOTB_MATCHES') - { - if ($xml_row['status'] > 0 AND ($xml_row['status'] == $table_row['status'] - 3)) - { - unset($diff['status']); - if (!sizeof($diff)) - { - return ''; - } - } - if ($xml_row['status'] < 0 AND $league_info['bet_in_time']) - { - if ($table_row['status'] == 0) - { - unset($diff['status']); - if (!sizeof($diff)) - { - return ''; - } - } - else - { - $diff['status'] = 0; - } - } - } - $tpl = ''; - $tpl_ary = array(); - if (sizeof($diff)) - { - if (sizeof($table_row)) - { - $tpl .= ''; - // match status update and database - if (substr($id, 0, 13) == 'FOOTB_MATCHES') - { - $tpl .= ''; - $tpl .= ''; - if ($xml_row['status'] > 0 AND ($xml_row['status'] == $table_row['status'] +3)) - { - unset($diff['status']); - } - } - - } - else - { - // Insert team - $tpl .= ''; - } - } - - $tpl .= ' '; - foreach ($xml_row AS $key => $value) - { - if (array_key_exists($key, $diff)) - { - if (sizeof($table_row)) - { - $color_open = '* '; - $color_close = ''; - } - else - { - $color_open = '* '; - $color_close = ''; - } - } - else - { - $color_open = ''; - $color_close = ''; - } - if (sizeof($order)) - { - $value = (substr($key, 0, 7) == 'team_id') ? $value . ' ' . $this->team_ary[$value] : $value; - $tpl_ary[$order[$key]] = ($order[$key] % 2) ? $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . ' ' : - '' . $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . '
'; - } - else - { - if ($key <> 'season' and $key <> 'league') - { - // Write table fields - if (sizeof($table_row)) - { - $tpl .= '' . - $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . - ''; - } - else - { - $tpl .= '' . - $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . - ''; - } - } - } - } - if (sizeof($order)) - { - ksort($tpl_ary); - $tpl .= implode(" ", $tpl_ary); - } - if (sizeof($table_row)) - { - $tpl .= ' '; - } - else - { - $tpl .= ''; - } - - return $tpl; - } - - - /** - * Print differences beetween Database and XML-Data - */ - function print_xml_data($xml_row, $row_class, $order) - { - global $user; - - $tpl = ''; - $tpl_ary = array(); - - $tpl .= ''; - foreach ($xml_row AS $key => $value) - { - if (sizeof($order)) - { - $value = (substr($key, 0, 7) == 'team_id') ? $value . ' ' . $this->team_ary[$value] : $value; - $tpl_ary[$order[$key]] = ($order[$key] % 2) ? htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . ' ' : - '' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '
'; - } - else - { - if ($key <> 'season' and $key <> 'league') - { - // Write XML-table fields - $tpl .= '' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . ''; - } - } - } - if (sizeof($order)) - { - ksort($tpl_ary); - $tpl .= implode(" ", $tpl_ary); - } - $tpl .= ' '; - - return $tpl; - } - - /** - * Insert table into database - */ - function insert_league($table) - { - global $db, $user; - - $count_inserts = 0; - $table_name = constant($table); - foreach ($this->xml_ary[strtolower($table)] AS $sql_ary) - { - $sql = 'INSERT IGNORE INTO ' . $table_name . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - if ($db->sql_affectedrows()) - { - $count_inserts++; - } - } - return $count_inserts; - } - - /** - * Update database - */ - function update_league($table, $season, $league, $index_field) - { - global $db, $user; - - $count_updates = 0; - $table_name = constant($table); - $selected_fields = $this->selected_fields($table); - if (!sizeof($selected_fields)) - { - return 0; - } - - if ($table == 'FOOTB_MATCHES') - { - $update_neg_status = $this->request->variable('update_neg_status', false); - $update_same_status = $this->request->variable('update_same_status', false); - $update_only_final = $this->request->variable('update_only_final', false); - } - - // Grab key data for update - $sql = "SELECT $index_field AS index_field - FROM " . $table_name . " - WHERE season = $season - AND league = $league - ORDER BY 1"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if ($this->request->variable($table . '_' . $row['index_field'], false)) - { - - $diff_ary = unserialize(urldecode($this->request->variable('row_' . $table . '_' . $row['index_field'], ''))); - $sql_ary = array_intersect_ukey($diff_ary, $selected_fields, 'self::key_compare_func'); - if ($table == 'FOOTB_MATCHES') - { - $update_status = $this->request->variable('status_FOOTB_MATCHES_' . $row['index_field'], 0); - $db_status = $this->request->variable('db_status_FOOTB_MATCHES_' . $row['index_field'], 0); - switch ($update_status) - { - case -2: - case -1: - if (! $update_neg_status) - { - // remove resultfields and status - $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); - } - break; - case 0: - case 1: - // remove resultfields and status - $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); - break; - case 2: - if ($db_status <= 0 or $db_status == 3 or $db_status == 6 or $update_only_final or - (($db_status == 2 or $db_status == 5 ) and ! $update_same_status) ) - { - // remove provisional results and status - $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); - } - else - { - if ($db_status == 4 or $db_status == 5) - { - $sql_ary['status'] = 5; - } - } - break; - case 3: - if (($db_status == 3 or $db_status == 6 ) and !$update_same_status) - { - // don't replace final results - $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); - } - else - { - if ($db_status > 3) - { - $sql_ary['status'] = 6; - } - } - break; - } - } - if (sizeof($sql_ary)) - { - $sql = 'UPDATE ' . $table_name . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND $index_field = " . $row['index_field']; - $db->sql_query($sql); - if ($db->sql_affectedrows()) - { - $count_updates++; - } - } - } - } - return $count_updates; - } - - /** - * Insert new teams into database - */ - function insert_new_teams($season, $league) - { - global $db, $user; - - $count_updates = 0; - $table_name = constant('FOOTB_TEAMS'); - $insert_ary = $this->request->variable('insert_team', array('')); - if (sizeof($insert_ary) == 0) - { - return 0; - } - foreach ($insert_ary AS $insert) - { - $sql_ary = unserialize(urldecode($insert)); - $sql = 'INSERT INTO ' . $table_name . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - if ($db->sql_affectedrows()) - { - $count_updates++; - } - } - return $count_updates; - } - - - /** - * get selected fields - */ - function selected_fields($table) - { - global $db, $user; - - $tablename = strtolower($table); - $var_praefix = 'update_' . substr($tablename, 6) . '_'; - $selected_fields = array(); - $table_fields = array(); - - // Grab fields of table - $table_fields = $this->$tablename; - foreach ($table_fields AS $table_field) - { - switch ($table_field) - { - case 'formula_home': - case 'formula_guest': - $tag_name = 'formula'; - break; - case 'goals_home': - case 'goals_guest': - $tag_name = 'goals'; - break; - case 'goals_overtime_home': - case 'goals_overtime_guest': - $tag_name = 'goals_overtime'; - break; - default: - $tag_name = $table_field; - break; - } - if ($this->request->variable($var_praefix . $tag_name, false)) - { - $selected_fields[$table_field] = 0; - } - } - return $selected_fields; - } -} + 0, + 'team_id_guest' => 0, + 'match_datetime' => 0, + 'group_id' => 0, + 'formula_home' => 0, + 'formula_guest' => 0, + 'ko_match' => 0 + ); + public $u_action; + public $ext_football_path; + + protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; + protected $root_path, $request, $php_ext, $log; + + + public function __construct() + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx; + + $helper = $phpbb_container->get('controller.helper'); + + $user->add_lang_ext('football/football', 'info_acp_update'); + + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->config = $config; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ext = $phpEx; + if ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) { + // Get an instance of the ultimatepoints functions_points + $functions_points = $phpbb_container->get('dmzx.ultimatepoints.core.functions.points'); + } + } + + public function key_compare_func($key1, $key2) + { + if ($key1 == $key2) + return 0; + else if ($key1 > $key2) + return 1; + else + return -1; + } + + public function sort_teams($value_a, $value_b) + { + if ($value_a['team_id'] > $value_b['team_id']) + { + return 1; + } + else + { + if ($value_a['team_id'] == $value_b['team_id']) + { + return 0; + } + else + { + return -1; + } + } + } + + function main($id, $mode) + { + global $db, $auth, $phpbb_container, $phpbb_admin_path, $league_info, $functions_points, $phpbb_log; + global $template, $user, $config, $phpbb_extension_manager, $request, $phpbb_root_path, $phpEx, $cache; + + $helper = $phpbb_container->get('controller.helper'); + + $this->ext_football_path = $phpbb_root_path . 'ext/football/football/'; + if(!function_exists('season_info')) + { + include($this->ext_football_path . 'includes/functions.' . $phpEx); + } + if (!defined('FOOTB_SEASONS')) + { + include($this->ext_football_path . 'includes/constants.' . $phpEx); + } + + $this->tpl_name = 'acp_football_update'; + $this->page_title = 'ACP_FOOTBALL_UPDATE_MANAGE'; + + $form_key = 'acp_football_update'; + add_form_key($form_key); + + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + + // Check and set some common vars + $action = (isset($_POST['load_xml_season'])) ? 'load_xml_season' : ''; + $action = (isset($_POST['team_mapping'])) ? 'team_mapping' : $action; + $action = (isset($_POST['map_teams'])) ? 'map_teams' : $action; + $action = (isset($_POST['load_xml_league'])) ? 'load_xml_league' : $action; + $action = (isset($_POST['choose'])) ? 'choose' : $action; + $action = (isset($_POST['list'])) ? 'list' : $action; + $action = (isset($_POST['insert'])) ? 'insert' : $action; + $action = (isset($_POST['update'])) ? 'update' : $action; + $action = (empty($action)) ? $this->request->variable('action', '') : $action; + $xml_season_url = $this->request->variable('xml_season_url', ''); + $xml_league_url = $this->request->variable('xml_league_url', ''); + $xseason = $this->request->variable('xs', 0); + $xleague = $this->request->variable('xl', 0); + $xcode = $this->request->variable('xcode', ''); + $season = $this->request->variable('s', 0); + $league = $this->request->variable('l', 0); + $league_name = $this->request->variable('league_name', ''); + $new_league = $this->request->variable('new_league', 0); + $insert_season = $this->request->variable('insert_season', false); + $insert_league = $this->request->variable('insert_league', false); + $list = $this->request->variable('list', false); + $this->xml_ary = unserialize(urldecode($this->request->variable('xml_ary', ''))); + $display_team_mapping = false; + // Clear some vars + $error = array(); + $success = array(); + $missing_team_ids_ary = array(); + $curr_season = curr_season(); + $choose_league = false; + $xseason_options = ''; + $xleague_options = ''; + $season_options = ''; + $league_options = ''; + + // Grab current season + $season = ($season) ? $season : $curr_season; + + // Which action? + switch ($action) + { + case 'load_xml_season': + case 'choose': + if (!$xml_season_url or strtoupper($xml_season_url) == 'LOCALHOST') + { + $xml_season_url = 'localhost'; + // Search files on localhost + $files = glob($phpbb_root_path . "/store/league*.xml"); + if ($files) + { + $first_season = ($xseason) ? false : true; + $first_league = ($xleague) ? false : true; + foreach (glob($phpbb_root_path . "/store/league*.xml") AS $filename) + { + if ($xml = @simplexml_load_file($filename)) + { + if ($first_season) + { + $selected = ' selected="selected"'; + $xseason = $xml->footb_seasons->season; + $first_season = false; + } + else + { + $selected = ($xseason && $xml->footb_seasons->season == $xseason) ? ' selected="selected"' : ''; + } + $xseason_options .= ''; + if ($selected <> '') + { + $xseason_name = $xml->footb_seasons->season_name_short; + if ($first_league) + { + $selected = ' selected="selected"'; + $first_league = false; + } + else + { + $selected = ($xleague && $xml->footb_leagues->league == $xleague) ? ' selected="selected"' : ''; + } + $xleague_options .= ''; + if ($selected <> '') + { + $league_name = $xml->footb_leagues->league_name; + } + } + } + else + { + trigger_error(sprintf($user->lang['ERROR_LOAD_LEAGUE_XML'], strstr($filename, "\\")) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + } + else + { + trigger_error(sprintf($user->lang['NO_XML_LEAGUE']) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + else + { + if (!($xml_str = $cache->get('football_xml_season'))) + { + if ($xml_str = @file_get_contents($xml_season_url)) + { + if (strpos($xml_str, 'put('football_xml_season', $xml_str, 300); + } + else + { + trigger_error(sprintf($user->lang['ERROR_READ_SEASON_XML']) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + else + { + trigger_error(sprintf($user->lang['ERROR_OPEN_SEASON_XML']) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + + if($xml_season = new \SimpleXMLElement($xml_str)) + { + $first_league = ($xleague) ? false : true; + $xcode = $xml_season->code; + foreach($xml_season->season AS $tag_season) + { + $xseason = ($xseason) ? $xseason : $tag_season->season_id; + $selected = ($xseason && $tag_season->season_id == $xseason) ? ' selected="selected"' : ''; + $xseason_options .= ''; + if ($selected <> '') + { + foreach($tag_season->league AS $tag_league) + { + $selected = ($xleague && $tag_league->league_id == $xleague) ? ' selected="selected"' : ''; + if ($first_league) + { + $selected = ' selected="selected"'; + $xleague = $tag_league->league_id; + $first_league = false; + } + $xleague_options .= ''; + if ($selected <> '') + { + $league_name = $tag_league->league_name; + } + } + } + } + } + else + { + trigger_error($user->lang['NO_XML_SEASON'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + } + // Grab basic data for select season + $sql = 'SELECT * + FROM ' . FOOTB_SEASONS . ' + ORDER BY season DESC'; + $result = $db->sql_query($sql); + + $season_options = ''; + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($season && $row['season'] == $season) ? ' selected="selected"' : ''; + $season_options .= ''; + if ($selected <> '') + { + $season_name = $row['season_name_short']; + } + } + $db->sql_freeresult($result); + + // Grab basic data for select league + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . ' + WHERE season = ' . $season . ' + ORDER BY league ASC'; + $result = $db->sql_query($sql); + + $league_options = ''; + if (!$league) + { + $league_options = ''; + $new_league = $xleague; + } + else + { + $league_options = ''; + $new_league = $league; + } + while ($row = $db->sql_fetchrow($result)) + { + // Grab current league + $selected = ($league && $row['league'] == $league) ? ' selected="selected"' : ''; + $league_options .= ''; + if ($selected <> '') + { + $league_name = $row['league_name']; + } + } + $db->sql_freeresult($result); + + $choose_league = true; + $list = false; + break; + + case 'team_mapping': + case 'map_teams': + case 'load_xml_league': + if ($xseason == 0 or $xleague == 0) + { + trigger_error(sprintf($user->lang['NO_XML_SEASON']) . adm_back_link($this->u_action), E_USER_WARNING); + } + + if ($season == 0) + { + // No Season exists + $season = $xseason; + $insert_season = true; + // No league exists, so we want to insert the source league + $league = $xleague; + $insert_league = true; + } + else + { + if ($league == 0) + { + // New league so try to create the source league + $league = ($new_league) ? $new_league : $xleague; + $insert_league = true; + // Selected source league exist + if (sizeof(league_info($season, $league))) + { + trigger_error(sprintf($user->lang['NEW_LEAGUE_EXIST'], $league) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + } + + if (!$xml_season_url or strtoupper($xml_season_url) == 'LOCALHOST') + { + $xml_season_url = 'localhost'; + $xml_league_url = $phpbb_root_path . '/store/league_' . $xseason . '_' . $xleague . '.xml'; + } + else + { + $xml_league_url = substr($xml_season_url, 0, strrpos($xml_season_url, "/") + 1) . + "league.php?season=" . $xseason . "&league=" . $xleague . "&code=" . $xcode; + } + $cache_league = 'football_xml_league_' . $xseason . '_' . $xleague; + $this->xml_ary = $this->xml2array($xml_league_url, $cache_league); + + $team_id_map_ary = array(); + $duplicate_team_ids_ary = array(); + if ($action == 'map_teams') + { + if ($this->check_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary, $missing_team_ids_ary)) + { + $action = 'team_mapping'; + } + } + + if ($action == 'team_mapping') + { + if ($this->compare_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary)) + { + $display_team_mapping = true; + break; + } + } + + if (!$insert_league) + { + $league_info = league_info($season, $league); + $sql = 'SELECT COUNT(matchday) as matchdays + FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + if ($row['matchdays'] <> $league_info['matchdays']) + { + $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $row['matchdays']); + } + } + else + { + $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $row['matchdays']); + } + + $sql = 'SELECT COUNT(match_no) as matches + FROM ' . FOOTB_MATCHES . " + WHERE season = $season + AND league = $league"; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + if ($row['matches'] <> sizeof($this->xml_ary['footb_matches'])) + { + $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $row['matches']); + } + } + else + { + $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $row['matches']); + } + + if (!sizeof($error)) + { + // Compare Update with existing database and switch season and league + $this->compare_table('FOOTB_LEAGUES', $season, $league, '', true, $error); + $this->compare_table('FOOTB_MATCHDAYS', $season, $league, '', true, $error); + $this->compare_table('FOOTB_TEAMS', $season, $league, '', true, $error); + $this->compare_table('FOOTB_MATCHES', $season, $league,'', true, $error); + } + } + if (!sizeof($error)) + { + foreach ($this->xml_ary['footb_teams'] AS $key => $value) + { + $this->team_ary[$value['team_id']] = $value['team_name']; + } + $this->team_ary[0] = ''; + + $choose_league = false; + $list = true; + if ($insert_season) + { + // Set default values for new season + $this->xml_ary[strtolower('footb_seasons')][0]['season'] = "$season"; + $this->xml_ary[strtolower('footb_seasons')][0]['season_name'] = sprintf($user->lang['SEASON']) . " " . ($season - 1) . "/" . $season; + $this->xml_ary[strtolower('footb_seasons')][0]['season_name_short'] = $season - 1 . "/" . $season; + $this->show_xml($this->xml_ary, 'FOOTB_SEASONS', $season, 0); + } + if ($insert_league) + { + // Show complete update + $this->show_xml($this->xml_ary, 'FOOTB_LEAGUES', $season, $league); + $this->show_xml($this->xml_ary, 'FOOTB_MATCHDAYS', $season, $league); + $this->show_xml($this->xml_ary, 'FOOTB_TEAMS', $season, $league); + $this->show_xml($this->xml_ary, 'FOOTB_MATCHES', $season, $league); + } + else + { + // Display differences between update and database + $this->compare_table('FOOTB_MATCHDAYS', $season, $league, 'matchday', false, $error); + $this->compare_table('FOOTB_TEAMS', $season, $league, 'team_id', false, $error); + $this->compare_table('FOOTB_MATCHES', $season, $league, 'match_no', false, $error); + } + } + break; + case 'insert': + if ($insert_season) + { + if ($count_inserts = $this->insert_league('FOOTB_SEASONS')) + { + $success[] = sprintf($user->lang['DB_INSERT_SEASON'], $count_inserts); + } + } + if ($count_inserts = $this->insert_league('FOOTB_LEAGUES')) + { + $success[] = sprintf($user->lang['DB_INSERT_LEAGUE'], $count_inserts); + } + if ($count_inserts = $this->insert_league('FOOTB_MATCHDAYS')) + { + $success[] = sprintf($user->lang['DB_INSERT_MATCHDAY' . (($count_inserts == 1) ? '' : 'S')], $count_inserts); + } + if ($count_inserts = $this->insert_league('FOOTB_TEAMS')) + { + $success[] = sprintf($user->lang['DB_INSERT_TEAM' . (($count_inserts == 1) ? '' : 'S')], $count_inserts); + } + if ($count_inserts = $this->insert_league('FOOTB_MATCHES')) + { + $success[] = sprintf($user->lang['DB_INSERT_MATCH' . (($count_inserts == 1) ? '' : 'ES')], $count_inserts); + } + $log_message = implode('
', $success); + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($league_name . ' ' . $season . '
' . $log_message)); + break; + case 'update': + if ($count_updates = $this->update_league('FOOTB_MATCHDAYS', $season, $league, 'matchday')) + { + $success[] = sprintf($user->lang['DB_UPDATE_MATCHDAY' . (($count_updates == 1) ? '' : 'S')], $count_updates); + } + if ($count_updates = $this->update_league('FOOTB_TEAMS', $season, $league, 'team_id')) + { + $success[] = sprintf($user->lang['DB_UPDATE_TEAM' . (($count_updates == 1) ? '' : 'S')], $count_updates); + } + if ($count_updates = $this->insert_new_teams($season, $league)) + { + $success[] = sprintf($user->lang['DB_INSERT_TEAM' . (($count_updates == 1) ? '' : 'S')], $count_updates); + } + if ($count_updates = $this->update_league('FOOTB_MATCHES', $season, $league, 'match_no')) + { + $success[] = sprintf($user->lang['DB_UPDATE_MATCH' . (($count_updates == 1) ? '' : 'ES')], $count_updates); + } + + // set delivery for bet in time + $league_info = league_info($season, $league); + if ($league_info['bet_in_time']) + { + $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . " (season, league, matchday, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) + SELECT m.season, m.league, m.matchday, min(m.match_datetime) AS delivery_date, '' AS delivery_date_2, '' AS delivery_date_3, md.matchday_name, md.matches + FROM " . FOOTB_MATCHES . ' AS m + JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) + JOIN ' . FOOTB_MATCHDAYS . " AS md ON (md.season = m.season AND md.league = m.league AND md.matchday = m.matchday) + WHERE m.season = $season + AND m.league = $league + AND l.bet_in_time = 1 + AND m.status = 0 + GROUP BY m.season, m.league, m.matchday"; + $db->sql_query($sql); + $count_updates = $db->sql_affectedrows(); + if ($count_updates) + { + $success[] = sprintf($user->lang['DB_UPDATE_BIT_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $count_updates) ; + } + } + else + { + // set first delivery + $effected_matchdays = ''; + $count_updates = 0; + $sql = 'SELECT md.matchday + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = 0 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date > agg.min_delivery_date + ORDER BY md.matchday"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $count_updates++; + $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; + } + if ($effected_matchdays <> '') + { + $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) + SELECT md.season + , md.league + , md.matchday + , md.status + , min_delivery_date AS delivery_date + , md.delivery_date_2 + , md.delivery_date_3 + , md.matchday_name + , md.matches + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = 0 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date > agg.min_delivery_date"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; + } + // set second delivery + $effected_matchdays = ''; + $count_updates = 0; + $sql = 'SELECT md.matchday + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = -1 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date_2 > agg.min_delivery_date + ORDER BY md.matchday"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $count_updates++; + $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; + } + if ($effected_matchdays <> '') + { + $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) + SELECT md.season + , md.league + , md.matchday + , md.status + , md.delivery_date + , min_delivery_date AS delivery_date_2 + , md.delivery_date_3 + , md.matchday_name + , md.matches + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = -1 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date_2 > agg.min_delivery_date"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; + } + // set third delivery + $effected_matchdays = ''; + $count_updates = 0; + $sql = 'SELECT md.matchday + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = -2 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date_3 > agg.min_delivery_date + ORDER BY md.matchday"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $count_updates++; + $effected_matchdays = ($effected_matchdays == '') ? $row['matchday'] : $effected_matchdays . ', ' . $row['matchday']; + } + if ($effected_matchdays <> '') + { + $sql = 'REPLACE INTO ' . FOOTB_MATCHDAYS . ' (season, league, matchday, status, delivery_date, delivery_date_2, delivery_date_3, matchday_name, matches) + SELECT md.season + , md.league + , md.matchday + , md.status + , md.delivery_date + , md.delivery_date_2 + , min_delivery_date AS delivery_date_3 + , md.matchday_name + , md.matches + FROM ' . FOOTB_MATCHDAYS . ' AS md + INNER JOIN (SELECT season, league, matchday, min(match_datetime) AS min_delivery_date + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND status = -2 + GROUP BY season, league, matchday) AS agg + WHERE md.season = agg.season + AND md.league = agg.league + AND md.matchday = agg.matchday + AND md.delivery_date_3 > agg.min_delivery_date"; + $db->sql_query($sql); + $success[] = sprintf($user->lang['DB_UPDATE_DELIVER' . (($count_updates == 1) ? '' : 'IES')], $effected_matchdays) ; + } + } + + // check status of matchdays + $local_board_time = time() + (($this->config['board_timezone'] - $this->config['football_host_timezone']) * 3600); + $sql = $sql = 'UPDATE ' . FOOTB_MATCHDAYS . " AS target + INNER JOIN + ( + SELECT md.season + , md.league + , md.matchday + , IF( md.delivery_date > now(), + 0, + IF(ISNULL(min(e.extra_status)), + IF(min(m.status) = 1 AND max(m.status) > 1, + 2, + GREATEST(min(m.status), 0)), + IF(LEAST(min(m.status), min(e.extra_status)) = 1 AND GREATEST(max(m.status), max(e.extra_status)) > 1, + 2, + GREATEST(LEAST(min(m.status), min(e.extra_status)), 0)))) As new_status + FROM " . FOOTB_MATCHDAYS . ' AS md + LEFT JOIN ' . FOOTB_MATCHES . ' AS m ON (m.season = md.season AND m.league = md.league AND m.matchday = md.matchday) + LEFT JOIN ' . FOOTB_EXTRA . " AS e ON (e.season = md.season AND e.league = md.league AND e.matchday_eval = md.matchday) + WHERE md.season = $season AND md.league = $league + GROUP BY md.season, md.league, md.matchday) AS source + ON target.season = source.season AND target.league = source.league AND target.matchday = source.matchday + SET target.status = source.new_status"; + $db->sql_query($sql); + $count_updates = $db->sql_affectedrows(); + if ($count_updates) + { + $success[] = sprintf($user->lang['DB_UPDATE_STATUS_MATCHDAY' . (($count_updates == 1) ? '' : 'S')], $count_updates); + } + if (sizeof($success)) + { + $cash = ($phpbb_extension_manager->is_enabled('dmzx/ultimatepoints')) ? true : false; + save_ranking_matchday($season, $league, 1, $cash); + $log_message = implode('
', $success); + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($league_info['league_name'] . ' ' . $season . '
' . $log_message)); + } + else + { + $success[] = sprintf($user->lang['NO_DB_CHANGES']); + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FOOTB_UPDATE', false, array($success[0])); + } + break; + } + $allow_url_fopen = (int) @ini_get('allow_url_fopen'); + if ($allow_url_fopen) + { + if (trim($this->config['football_update_source']) == '') + { + $xml_season_url = ($xml_season_url == '') ? 'http://football.bplaced.net/ext/football/football/xml/seasons.php' : $xml_season_url; + } + else + { + $xml_season_url = trim($this->config['football_update_source']); + } + } + else + { + $xml_season_url = 'localhost'; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'U_CHOOSE_ACTION' => $this->u_action . "&action=choose", + 'U_FOOTBALL' => $helper->route('football_main_controller',array('side' => 'bet', 's' => $season, 'l' => $league)), + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', + 'S_SUCCESS' => (sizeof($success)) ? true : false, + 'SUCCESS_MSG' => (sizeof($success)) ? implode('
', $success) : '', + 'S_MISSING_TEAMS' => (sizeof($missing_team_ids_ary)) ? sprintf($user->lang['MISSING_TEAMS'], implode(', ', $missing_team_ids_ary)) : '', + 'S_ALLOW_URL_FOPEN' => ($allow_url_fopen) ? true : false, + 'S_CHOOSE' => $choose_league, + 'S_TEAMS' => $display_team_mapping, + 'S_LIST' => $list, + 'S_INSERT_SEASON' => $insert_season, + 'S_INSERT_LEAGUE' => $insert_league, + 'S_CHECK_SAME_STATUS' => '', + 'S_CHECK_ONLY_FINAL' => 'checked="checked"', + 'S_VERSION_NO' => $this->config['football_version'], + 'DO_MATCHDAYS' => ($insert_league) ? sprintf($user->lang['INSERT_MATCHDAYS']) : sprintf($user->lang['UPDATE_MATCHDAYS']), + 'DO_TEAMS' => ($insert_league) ? sprintf($user->lang['INSERT_TEAMS']) : sprintf($user->lang['UPDATE_TEAMS']), + 'DO_MATCHES' => ($insert_league) ? sprintf($user->lang['INSERT_MATCHES']) : sprintf($user->lang['UPDATE_MATCHES']), + 'XML_SEASON_URL' => $xml_season_url, + 'XML_LEAGUE_URL' => $xml_league_url, + 'XML_ARY' => (sizeof($this->xml_ary)) ? urlencode(serialize($this->xml_ary)) : '', + 'S_XSEASON_OPTIONS' => $xseason_options, + 'S_XLEAGUE_OPTIONS' => $xleague_options, + 'S_XSEASON' => $xseason, + 'S_XLEAGUE' => $xleague, + 'S_XCODE' => $xcode, + 'S_SEASON_OPTIONS' => $season_options, + 'S_LEAGUE_OPTIONS' => $league_options, + 'S_SEASON' => $season, + 'S_LEAGUE' => $league, + 'S_LEAGUE_NAME' => $league_name, + 'NEW_LEAGUE' => $new_league, + ) + ); + } + + function xml2array($xml_league_url, $cache_league) + { + global $cache; + + if (!($xml_str = $cache->get($cache_league))) + { + if ($xml_str = @file_get_contents($xml_league_url)) + { + if (strpos($xml_str, 'put($cache_league, $xml_str, 900); + } + else + { + trigger_error(sprintf($user->lang['ERROR_READ_LEAGUE_XML']) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + else + { + trigger_error(sprintf($user->lang['ERROR_OPEN_LEAGUE_XML']) . adm_back_link($this->u_action), E_USER_WARNING); + } + } + $xml_league = new \SimpleXMLElement($xml_str); + + $xml_table = array(); + foreach ($xml_league->children() AS $node) + { + $xml_entry = array(); + foreach($node->children() AS $cnode) + { + $xml_entry[$cnode->getName()] = sprintf("%s", $cnode); + } + $xml_table[$node->getName()][] = $xml_entry; + $this->xml_ary[$node->getName()] = $xml_table[$node->getName()]; + } + return $this->xml_ary; + } + + function check_teams($season, $league, &$team_id_map_ary, &$duplicate_team_ids_ary, &$missing_team_ids_ary) + { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx; + + $team_id_ary = array(); + foreach ($this->xml_ary['footb_teams'] AS $xml_team) + { + $new_team_id = $this->request->variable('team_id_db_' . $xml_team['team_id'], 0); + $team_id_map_ary[$xml_team['team_id']] = $new_team_id; + if (in_array($new_team_id, $team_id_ary) or $new_team_id == 0) + { + $duplicate_team_ids_ary[] = $new_team_id; + } + else + { + $team_id_ary[] = $new_team_id; + } + } + $table_name = constant('FOOTB_TEAMS'); + // All database teams selected? + $sql = 'SELECT team_id + FROM ' . $table_name . " + WHERE season = $season + AND league = $league + ORDER BY team_id"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (!in_array($row['team_id'], $team_id_ary)) + { + $missing_team_ids_ary[] = $row['team_id']; + } + } + $db->sql_freeresult($result); + if (sizeof($duplicate_team_ids_ary) or sizeof($missing_team_ids_ary)) + { + // Display Mapping + return true; + } + else + { + // set new IDs in xml_ary + foreach ($this->xml_ary['footb_teams'] AS $key => $xml_team) + { + $this->xml_ary['footb_teams'][$key]['team_id'] = $team_id_map_ary[$xml_team['team_id']]; + } + usort($this->xml_ary['footb_teams'], 'sort_teams'); + + foreach ($this->xml_ary['footb_matches'] AS $key => $xml_team) + { + $this->xml_ary['footb_matches'][$key]['team_id_home'] = $team_id_map_ary[$xml_team['team_id_home']]; + $this->xml_ary['footb_matches'][$key]['team_id_guest'] = $team_id_map_ary[$xml_team['team_id_guest']]; + } + return false; + } + } + + + function compare_teams($season, $league, $team_id_map_ary, $duplicate_team_ids_ary) + { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx; + + $i = 0; + $j = 0; + $db_teams = array(); + $different_teams = false; + $same_quantity = false; + $table_name = constant('FOOTB_TEAMS'); + // Grab basic data for select league + $sql = 'SELECT team_id + , team_name + , team_name_short + , team_symbol + FROM ' . $table_name . " + WHERE season = $season + AND league = $league + ORDER BY team_name"; + $result = $db->sql_query($sql); + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $same_quantity = (sizeof($rows) == sizeof($this->xml_ary['footb_teams'])) ? true : false; + + if ($same_quantity) + { + foreach ($rows AS $row) + { + $db_teams[$row['team_id']] = $row; + } + } + else + { + $different_teams = true; + $sql = 'SELECT DISTINCT team_id + , team_name + , team_name_short + , team_symbol + FROM ' . $table_name . " + ORDER BY team_name"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $db_teams[$row['team_id']] = $row; + } + $db->sql_freeresult($result); + } + $row_number = 0; + foreach ($this->xml_ary['footb_teams'] AS $xml_team) + { + $team_options = ''; + $team_id = (sizeof($team_id_map_ary)) ? $team_id_map_ary[$xml_team['team_id']] : $xml_team['team_id']; + if (!$same_quantity) + { + if (array_key_exists($team_id, $db_teams)) + { + $team_options = ''; + } + else + { + $team_options = ''; + } + } + foreach ($db_teams AS $db_team_id => $db_team_data) + { + $selected = ($db_team_id == $team_id) ? ' selected="selected"' : ''; + $team_options .= ''; + } + if (!array_key_exists($team_id, $db_teams) or sizeof($duplicate_team_ids_ary)) + { + $different_teams = true; + } + $row_number++; + $row_class = (!($row_number % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $template->assign_block_vars('teams', array( + 'ROW_CLASS' => $row_class, + 'TEAM_ID_XML' => $xml_team['team_id'], + 'TEAM_IMAGE_XML' => ($xml_team['team_symbol']) ? $this->ext_football_path . 'images/flags/' . $xml_team['team_symbol'] : $phpbb_root_path . 'football/images/flags/blank.gif', + 'TEAM_NAME_XML' => $xml_team['team_name'], + 'TEAM_NAME_SHORT_XML' => $xml_team['team_name_short'], + 'TEAM_OPTIONS' => $team_options, + 'DUPLICATE_TEAM' => (in_array($team_id, $duplicate_team_ids_ary)) ? true : false, + + )); + } + if ($different_teams) + { + // Display Mapping + return true; + } + else + { + return false; + } + } + + function compare_table($table, $season, $league, $index_field, $check, &$error) + { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx; + + $i = 0; + $j = 0; + $tpl = ''; + $order = ($table == 'FOOTB_MATCHES') ? array('season' => 0, 'league' => 0, 'match_no' => 1, 'team_id_home' => 4, 'team_id_guest' => 5, + 'goals_home' => 6, 'goals_guest' => 7, 'matchday' => 0, 'status' => 12, 'match_datetime' => 2, + 'group_id' => 3, 'formula_home' => 10, 'formula_guest' => 11, 'ko_match' => 13, + 'goals_overtime_home' => 8, 'goals_overtime_guest' => 9) : array(); + $table_name = constant($table); + // Grab basic data for select league + $sql = 'SELECT * + FROM ' . $table_name . " + WHERE season = $season + AND league = $league + ORDER BY 1, 2, 3"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if ($table == 'FOOTB_TEAMS') + { + while ($i < sizeof($this->xml_ary[strtolower($table)]) and $this->xml_ary[strtolower($table)][$i]['team_id'] <> $row['team_id']) + { + // New team + if ($check) + { + $this->xml_ary[strtolower($table)][$i]['season'] = "$season"; + $this->xml_ary[strtolower($table)][$i]['league'] = "$league"; + } + else + { + $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $id = 'insert_team'; + $tpl .= $this->print_differences(array(), $this->xml_ary[strtolower($table)][$i], $this->xml_ary[strtolower($table)][$i], $id, $row_class, array()); + $j++; + } + $i++; + } + } + $diff = array_diff_assoc($this->xml_ary[strtolower($table)][$i], $row); + if ($check) + { + foreach ($diff AS $key => $value) + { + switch($key) + { + case 'league': + $this->xml_ary[strtolower($table)][$i]['league'] = "$league"; + break; + case 'league_type': + $error[] = sprintf($user->lang['MISMATCH_LEAGUE_TYPE'], $value); + break; + case 'matchdays': + $error[] = sprintf($user->lang['MISMATCH_MATCHDAYS'], $value); + break; + case 'matches_on_matchday': + $error[] = sprintf($user->lang['MISMATCH_MOM'], $value); + break; + case 'matches': + $error[] = sprintf($user->lang['MISMATCH_MATCHES'], $value); + break; + case 'season': + $this->xml_ary[strtolower($table)][$i]['season'] = "$season"; + break; + } + } + } + else + { + if (sizeof($diff)) + { + $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $id = $table . '_' . $row[$index_field]; + $tpl .= $this->print_differences($row, $this->xml_ary[strtolower($table)][$i], $diff, $id, $row_class, $order); + $j++; + } + } + $i++; + } + $db->sql_freeresult($result); + if (!$check and $tpl <> '') + { + $template->assign_block_vars(strtolower($table), array( + 'TPL' => $tpl, + )); + } + } + + + function show_xml(&$xml_ary, $table, $season, $league) + { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx; + + $j = 0; + $tpl = ''; + switch ($table) + { + case 'FOOTB_LEAGUES': + $order = array('season' => 0, 'league' => 0, 'league_name' => 0, 'league_name_short' => 2, 'league_type' => 4, + 'matchdays' => 6, 'matches_on_matchday' => 8, 'win_result' => 10, 'win_result_02' => 10, 'win_matchday' => 10, + 'win_season' => 10, 'points_mode' => 10, 'points_result' => 12, 'points_tendency' => 12, + 'points_diff' => 12, 'points_last' => 12, 'join_by_user' => 12, 'join_in_season' => 12, + 'bet_in_time' => 12, 'rules_post_id' => 14, 'bet_ko_type' => 14, 'bet_points' => 16); + break; + case 'FOOTB_MATCHES': + $order = array('season' => 0, 'league' => 0, 'match_no' => 1, 'team_id_home' => 4, 'team_id_guest' => 5, + 'goals_home' => 6, 'goals_guest' => 7, 'matchday' => 0, 'status' => 12, 'match_datetime' => 2, + 'group_id' => 3, 'formula_home' => 10, 'formula_guest' => 11, 'ko_match' => 13, + 'goals_overtime_home' => 8, 'goals_overtime_guest' => 9); + break; + default: + $order = array(); + } + foreach ($this->xml_ary[strtolower($table)] AS $key => $xml_row) + { + $this->xml_ary[strtolower($table)][$key]['season'] = "$season"; + if ($league) + { + $this->xml_ary[strtolower($table)][$key]['league'] = "$league"; + } + $row_class = (!($j % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + $tpl .= $this->print_xml_data($xml_row, $row_class, $order); + $j++; + } + $template->assign_block_vars(strtolower($table), array( + 'TPL' => $tpl, + )); + } + + + /** + * Print differences beetween Database and XML-Data + */ + function print_differences($table_row, $xml_row, $diff, $id, $row_class, $order) + { + global $user, $league_info; + + if (sizeof($table_row) AND substr($id, 0, 11) == 'FOOTB_TEAMS') + { + if ($xml_row['team_symbol'] == '') + { + unset($diff['team_symbol']); + if (!sizeof($diff)) + { + return ''; + } + } + } + if (sizeof($table_row) AND substr($id, 0, 13) == 'FOOTB_MATCHES') + { + if ($xml_row['status'] > 0 AND ($xml_row['status'] == $table_row['status'] - 3)) + { + unset($diff['status']); + if (!sizeof($diff)) + { + return ''; + } + } + if ($xml_row['status'] < 0 AND $league_info['bet_in_time']) + { + if ($table_row['status'] == 0) + { + unset($diff['status']); + if (!sizeof($diff)) + { + return ''; + } + } + else + { + $diff['status'] = 0; + } + } + } + $tpl = ''; + $tpl_ary = array(); + if (sizeof($diff)) + { + if (sizeof($table_row)) + { + $tpl .= ''; + // match status update and database + if (substr($id, 0, 13) == 'FOOTB_MATCHES') + { + $tpl .= ''; + $tpl .= ''; + if ($xml_row['status'] > 0 AND ($xml_row['status'] == $table_row['status'] +3)) + { + unset($diff['status']); + } + } + + } + else + { + // Insert team + $tpl .= ''; + } + } + + $tpl .= ' '; + foreach ($xml_row AS $key => $value) + { + if (array_key_exists($key, $diff)) + { + if (sizeof($table_row)) + { + $color_open = '* '; + $color_close = ''; + } + else + { + $color_open = '* '; + $color_close = ''; + } + } + else + { + $color_open = ''; + $color_close = ''; + } + if (sizeof($order)) + { + $value = (substr($key, 0, 7) == 'team_id') ? $value . ' ' . $this->team_ary[$value] : $value; + $tpl_ary[$order[$key]] = ($order[$key] % 2) ? $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . ' ' : + '' . $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . '
'; + } + else + { + if ($key <> 'season' and $key <> 'league') + { + // Write table fields + if (sizeof($table_row)) + { + $tpl .= '' . + $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . + ''; + } + else + { + $tpl .= '' . + $color_open . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . $color_close . + ''; + } + } + } + } + if (sizeof($order)) + { + ksort($tpl_ary); + $tpl .= implode(" ", $tpl_ary); + } + if (sizeof($table_row)) + { + $tpl .= ' '; + } + else + { + $tpl .= ''; + } + + return $tpl; + } + + + /** + * Print differences beetween Database and XML-Data + */ + function print_xml_data($xml_row, $row_class, $order) + { + global $user; + + $tpl = ''; + $tpl_ary = array(); + + $tpl .= ''; + foreach ($xml_row AS $key => $value) + { + if (sizeof($order)) + { + $value = (substr($key, 0, 7) == 'team_id') ? $value . ' ' . $this->team_ary[$value] : $value; + $tpl_ary[$order[$key]] = ($order[$key] % 2) ? htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . ' ' : + '' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '
'; + } + else + { + if ($key <> 'season' and $key <> 'league') + { + // Write XML-table fields + $tpl .= '' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . ''; + } + } + } + if (sizeof($order)) + { + ksort($tpl_ary); + $tpl .= implode(" ", $tpl_ary); + } + $tpl .= ' '; + + return $tpl; + } + + /** + * Insert table into database + */ + function insert_league($table) + { + global $db, $user; + + $count_inserts = 0; + $table_name = constant($table); + foreach ($this->xml_ary[strtolower($table)] AS $sql_ary) + { + $sql = 'INSERT IGNORE INTO ' . $table_name . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + if ($db->sql_affectedrows()) + { + $count_inserts++; + } + } + return $count_inserts; + } + + /** + * Update database + */ + function update_league($table, $season, $league, $index_field) + { + global $db, $user; + + $count_updates = 0; + $table_name = constant($table); + $selected_fields = $this->selected_fields($table); + if (!sizeof($selected_fields)) + { + return 0; + } + + if ($table == 'FOOTB_MATCHES') + { + $update_neg_status = $this->request->variable('update_neg_status', false); + $update_same_status = $this->request->variable('update_same_status', false); + $update_only_final = $this->request->variable('update_only_final', false); + } + + // Grab key data for update + $sql = "SELECT $index_field AS index_field + FROM " . $table_name . " + WHERE season = $season + AND league = $league + ORDER BY 1"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if ($this->request->variable($table . '_' . $row['index_field'], false)) + { + + $diff_ary = unserialize(urldecode($this->request->variable('row_' . $table . '_' . $row['index_field'], ''))); + $sql_ary = array_intersect_ukey($diff_ary, $selected_fields, 'self::key_compare_func'); + if ($table == 'FOOTB_MATCHES') + { + $update_status = $this->request->variable('status_FOOTB_MATCHES_' . $row['index_field'], 0); + $db_status = $this->request->variable('db_status_FOOTB_MATCHES_' . $row['index_field'], 0); + switch ($update_status) + { + case -2: + case -1: + if (! $update_neg_status) + { + // remove resultfields and status + $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); + } + break; + case 0: + case 1: + // remove resultfields and status + $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); + break; + case 2: + if ($db_status <= 0 or $db_status == 3 or $db_status == 6 or $update_only_final or + (($db_status == 2 or $db_status == 5 ) and ! $update_same_status) ) + { + // remove provisional results and status + $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); + } + else + { + if ($db_status == 4 or $db_status == 5) + { + $sql_ary['status'] = 5; + } + } + break; + case 3: + if (($db_status == 3 or $db_status == 6 ) and !$update_same_status) + { + // don't replace final results + $sql_ary = array_intersect_ukey($sql_ary, $this->no_result_fields, 'self::key_compare_func'); + } + else + { + if ($db_status > 3) + { + $sql_ary['status'] = 6; + } + } + break; + } + } + if (sizeof($sql_ary)) + { + $sql = 'UPDATE ' . $table_name . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND $index_field = " . $row['index_field']; + $db->sql_query($sql); + if ($db->sql_affectedrows()) + { + $count_updates++; + } + } + } + } + return $count_updates; + } + + /** + * Insert new teams into database + */ + function insert_new_teams($season, $league) + { + global $db, $user; + + $count_updates = 0; + $table_name = constant('FOOTB_TEAMS'); + $insert_ary = $this->request->variable('insert_team', array('')); + if (sizeof($insert_ary) == 0) + { + return 0; + } + foreach ($insert_ary AS $insert) + { + $sql_ary = unserialize(urldecode($insert)); + $sql = 'INSERT INTO ' . $table_name . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + if ($db->sql_affectedrows()) + { + $count_updates++; + } + } + return $count_updates; + } + + + /** + * get selected fields + */ + function selected_fields($table) + { + global $db, $user; + + $tablename = strtolower($table); + $var_praefix = 'update_' . substr($tablename, 6) . '_'; + $selected_fields = array(); + $table_fields = array(); + + // Grab fields of table + $table_fields = $this->$tablename; + foreach ($table_fields AS $table_field) + { + switch ($table_field) + { + case 'formula_home': + case 'formula_guest': + $tag_name = 'formula'; + break; + case 'goals_home': + case 'goals_guest': + $tag_name = 'goals'; + break; + case 'goals_overtime_home': + case 'goals_overtime_guest': + $tag_name = 'goals_overtime'; + break; + default: + $tag_name = $table_field; + break; + } + if ($this->request->variable($var_praefix . $tag_name, false)) + { + $selected_fields[$table_field] = 0; + } + } + return $selected_fields; + } +} ?> \ No newline at end of file diff --git a/block/delivery.php b/block/delivery.php index f2243a3..b9d4299 100644 --- a/block/delivery.php +++ b/block/delivery.php @@ -1,193 +1,75 @@ -data['user_id']; -$lang_dates = $user->lang['datetime']; -$index = 0; -$local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); -$sql = "(SELECT - m.season, - m.league, - m.matchday, - l.league_name_short, - CASE m.matchday_name - WHEN '' - THEN CONCAT(m.matchday, '." . sprintf($user->lang['MATCHDAY']) . "') - ELSE m.matchday_name - END AS matchday_name, - CONCAT( - CASE DATE_FORMAT(m.delivery_date,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(m.delivery_date,' %d.%m.%y %H:%i') - ) as delivery_time, - m.delivery_date AS delivery, - SUM(IF(((b.goals_home = '') OR (b.goals_guest = '')), 0, 1)) AS bets_count, - COUNT(*) AS matches_count, - SUM(IF(eb.extra_no > 0, IF(eb.bet = '', 0, 1), 0)) AS extra_bets_count, - SUM(IF(e.extra_no > 0, 1, 0)) AS extra_count - FROM " . FOOTB_MATCHDAYS . " AS m - JOIN " . FOOTB_LEAGUES . " AS l ON(l.season = m.season AND l.league = m.league AND l.bet_in_time = 0) - JOIN " . FOOTB_MATCHES . " AS ma ON (ma.season = m.season AND ma.league = m.league AND ma.matchday = m.matchday AND ma.status = 0) - JOIN " . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = ma.match_no AND b.user_id = $user_id) - LEFT JOIN " . FOOTB_EXTRA . " AS e ON (e.season = m.season AND e.league = m.league AND e.matchday = m.matchday AND e.extra_status = 0) - LEFT JOIN " . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = m.season AND eb.league = m.league AND eb.extra_no = e.extra_no AND eb.user_id = $user_id) - WHERE m.delivery_date > FROM_UNIXTIME('$local_board_time') - AND m.status <= 0 - GROUP BY m.delivery_date, m.league, b.user_id - ) - UNION - (SELECT - m.season, - m.league, - m.matchday, - l.league_name_short, - CASE m.matchday_name - WHEN '' - THEN CONCAT(m.matchday, '." . sprintf($user->lang['MATCHDAY']) . "') - ELSE m.matchday_name - END AS matchday_name, - CONCAT( - CASE DATE_FORMAT(m.delivery_date_2,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(m.delivery_date_2,' %d.%m.%y %H:%i') - ) as delivery_time, - m.delivery_date_2 AS delivery , - SUM(IF(((b.goals_home = '') OR (b.goals_guest = '')), 0, 1)) AS bets_count, - COUNT(*) AS matches_count, - 0 AS extra_bets_count, - 0 AS extra_count - FROM " . FOOTB_MATCHDAYS . " AS m - JOIN " . FOOTB_LEAGUES . " AS l ON(l.season = m.season AND l.league = m.league AND l.bet_in_time = 0) - JOIN " . FOOTB_MATCHES . " AS ma ON (ma.season = m.season AND ma.league = m.league AND ma.matchday = m.matchday AND ma.status = -1) - JOIN " . FOOTB_BETS . " AS b ON (b.season = ma.season AND b.league = ma.league AND b.match_no = ma.match_no AND b.user_id = $user_id) - WHERE m.delivery_date_2 > FROM_UNIXTIME('$local_board_time') - AND m.status <= 0 - GROUP BY m.delivery_date, m.league, b.user_id - ) - UNION - (SELECT - m.season, - m.league, - m.matchday, - l.league_name_short, - CASE m.matchday_name - WHEN '' - THEN CONCAT(m.matchday, '." . sprintf($user->lang['MATCHDAY']) . "') - ELSE m.matchday_name - END AS matchday_name, - CONCAT( - CASE DATE_FORMAT(m.delivery_date_3,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(m.delivery_date_3,' %d.%m.%y %H:%i') - ) as delivery_time, - m.delivery_date_3 AS delivery, - SUM(IF(((b.goals_home = '') OR (b.goals_guest = '')), 0, 1)) AS bets_count, - COUNT(*) AS matches_count, - 0 AS extra_bets_count, - 0 AS extra_count - FROM " . FOOTB_MATCHDAYS . " AS m - JOIN " . FOOTB_LEAGUES . " AS l ON(l.season = m.season AND l.league = m.league AND l.bet_in_time = 0) - JOIN " . FOOTB_MATCHES . " AS ma ON (ma.season = m.season AND ma.league = m.league AND ma.matchday = m.matchday AND ma.status = -2) - JOIN " . FOOTB_BETS . " AS b ON (b.season = ma.season AND b.league = ma.league AND b.match_no = ma.match_no AND b.user_id = $user_id) - WHERE m.delivery_date_3 > FROM_UNIXTIME('$local_board_time') - AND m.status <= 0 - GROUP BY m.delivery_date, m.league, b.user_id - ) - UNION - (SELECT - m.season, - m.league, - m.matchday, - l.league_name_short, - CASE m.matchday_name - WHEN '' - THEN CONCAT(m.matchday, '." . sprintf($user->lang['MATCHDAY']) . "') - ELSE m.matchday_name - END AS matchday_name, - CONCAT( - CASE DATE_FORMAT(ma.match_datetime,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(ma.match_datetime,' %d.%m.%y %H:%i') - ) as delivery_time, - ma.match_datetime AS delivery, - SUM(IF(((b.goals_home = '') OR (b.goals_guest = '')), 0, 1)) AS bets_count, - COUNT(*) AS matches_count, - 0 AS extra_bets_count, - 0 AS extra_count - FROM " . FOOTB_MATCHDAYS . " AS m - JOIN " . FOOTB_LEAGUES . " AS l ON(l.season = m.season AND l.league = m.league AND l.bet_in_time = 1) - JOIN " . FOOTB_MATCHES . " AS ma ON (ma.season = m.season AND ma.league = m.league AND ma.matchday = m.matchday AND ma.status = 0) - JOIN " . FOOTB_BETS . " AS b ON (b.season = ma.season AND b.league = ma.league AND b.match_no = ma.match_no AND b.user_id = $user_id) - WHERE ma.match_datetime > FROM_UNIXTIME('$local_board_time') - AND m.status <= 0 - GROUP BY ma.match_datetime, m.league, b.user_id - ) - ORDER BY delivery, league"; - -$result = $db->sql_query($sql); -while($row = $db->sql_fetchrow($result) AND $index < 11) -{ - $index++; - $data_delivery = true; - $row_class = (!($index % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; - - $template->assign_block_vars('delivery', array( - 'ROW_CLASS' => $row_class, - 'U_BET_LINK' => $this->helper->route('football_main_controller', array('side' => 'bet', 's' => $row['season'], 'l' => $row['league'], 'm' => $row['matchday'])), - 'LEAGUE_SHORT' => $row['league_name_short'], - 'MATCHDAY_NAME' => $row['matchday_name'], - 'COLOR' => ($row['bets_count'] == $row['matches_count'] && $row['extra_bets_count'] == $row['extra_count']) ? 'green' : 'red', - 'TITLE' => ($row['bets_count'] == $row['matches_count']) ? sprintf($user->lang['DELIVERY_READY']) : sprintf($user->lang['DELIVERY_NOT_READY']), - 'DELIVERY' => $row['delivery_time'], - ) - ); -} -$db->sql_freeresult($result); - -$template->assign_vars(array( - 'S_DISPLAY_DELIVERY' => $data_delivery, - 'S_DATA_DELIVERY' => $data_delivery, - ) -); - +data['user_id']; +$lang_dates = $user->lang['datetime']; +$index = 0; +$local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); +$sql = "SELECT + m.season, + m.league, + m.matchday, + l.league_name_short, + CASE m.matchday_name + WHEN '' + THEN CONCAT(m.matchday, '." . sprintf($user->lang['MATCHDAY']) . "') + ELSE m.matchday_name + END AS matchday_name, + IF(l.bet_in_time = 0, IF(ma.status = 0, m.delivery_date + , IF(ma.status = -1, m.delivery_date_2 + , m.delivery_date_3 + ) + ) + , ma.match_datetime) AS delivery, + SUM(IF(((b.goals_home = '') OR (b.goals_guest = '')), 0, 1)) AS bets_count, + COUNT(*) AS matches_count, + SUM(IF(eb.extra_no > 0, IF(eb.bet = '', 0, 1), 0)) AS extra_bets_count, + SUM(IF(e.extra_no > 0, 1, 0)) AS extra_count + FROM " . FOOTB_MATCHDAYS . " AS m + JOIN " . FOOTB_LEAGUES . " AS l ON(l.season = m.season AND l.league = m.league) + JOIN " . FOOTB_MATCHES . " AS ma ON (ma.season = m.season AND ma.league = m.league AND ma.matchday = m.matchday AND ma.status = 0) + JOIN " . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = ma.match_no AND b.user_id = $user_id) + LEFT JOIN " . FOOTB_EXTRA . " AS e ON (e.season = m.season AND e.league = m.league AND e.matchday = m.matchday AND e.extra_status = 0) + LEFT JOIN " . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = m.season AND eb.league = m.league AND eb.extra_no = e.extra_no AND eb.user_id = $user_id) + WHERE m.status <= 0 + GROUP BY delivery, m.league + ORDER BY delivery, m.league"; + +$result = $db->sql_query($sql); +while($row = $db->sql_fetchrow($result) AND $index < 11) +{ + $index++; + $data_delivery = true; + $row_class = (!($index % 2)) ? 'bg1 row_light' : 'bg2 row_dark'; + + $template->assign_block_vars('delivery', array( + 'ROW_CLASS' => $row_class, + 'U_BET_LINK' => $this->helper->route('football_main_controller', array('side' => 'bet', 's' => $row['season'], 'l' => $row['league'], 'm' => $row['matchday'])), + 'LEAGUE_SHORT' => $row['league_name_short'], + 'MATCHDAY_NAME' => $row['matchday_name'], + 'COLOR' => ($row['bets_count'] == $row['matches_count'] && $row['extra_bets_count'] == $row['extra_count']) ? 'green' : 'red', + 'TITLE' => ($row['bets_count'] == $row['matches_count']) ? sprintf($user->lang['DELIVERY_READY']) : sprintf($user->lang['DELIVERY_NOT_READY']), + 'DELIVERY' => $lang_dates[date("D", strtotime($row['delivery']))] . date(" d.m.y G:i", strtotime($row['delivery'])), + ) + ); +} +$db->sql_freeresult($result); + +$template->assign_vars(array( + 'S_DISPLAY_DELIVERY' => $data_delivery, + 'S_DATA_DELIVERY' => $data_delivery, + ) +); + ?> \ No newline at end of file diff --git a/composer.json b/composer.json index 363bd73..f8373ba 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "football/football", "type": "phpbb-extension", - "description": "Football Prediction League for phpBB 3.1", + "description": "Football Prediction League", "homepage": "http://football.bplaced.net", - "version": "0.9.7", - "time": "2016-06-12", + "version": "0.9.8", + "time": "2017-02-19", "license": "GPL-2.0", "authors": [{ "name": "J. Helmke", diff --git a/cron/task/football_remember.php b/cron/task/football_remember.php index e24cda7..95eca76 100644 --- a/cron/task/football_remember.php +++ b/cron/task/football_remember.php @@ -1,334 +1,336 @@ -root_path = $root_path; - $this->php_ext = $php_ext; - $this->phpbb_extension_manager = $phpbb_extension_manager; - $this->phpbb_path_helper = $phpbb_path_helper; - $this->db = $db; - $this->config = $config; - $this->phpbb_log = $log; - $this->user = $user; - } - - /** - * Runs this cron task. - * - * @return null - */ - public function run() - { - global $request; - - $ext_path = $this->phpbb_path_helper->update_web_root_path($this->phpbb_extension_manager->get_extension_path('football/football', true)); - include($ext_path . 'includes/functions.' . $this->php_ext); - include($ext_path . 'includes/constants.' . $this->php_ext); - - // Load extension language file - $this->user->add_lang_ext('football/football', 'info_acp_football'); - - // mode=test ? - $mode = $request->variable('mode', ''); - $days = $request->variable('days', 0); - - //Mail Settings - $use_queue = false; - $used_method = NOTIFY_EMAIL; - $priority = MAIL_NORMAL_PRIORITY; - - - $season = curr_season(); - //Matchdays to close in 24 hours and 24 hours later - // shift days to test - $local_board_time = time() + ($days * 86400); - - if ($mode <> 'test') - { - // Update next run - $run_time = getdate($this->config['football_remember_next_run']); - $next_run = mktime($run_time['hours'], $run_time['minutes'], 0, date("n"), date("j") + 1, date("Y")); - $this->config->set('football_remember_next_run', $next_run, true); - } - else - { - $message = sprintf($this->user->lang['LOG_FOOTBALL_MSG_TEST' . (($days == 0) ? '' : '_TRAVEL')], date("d.m.Y H:i", $local_board_time)); - $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON_TEST', false, array($message)); - } - - $sql = 'SELECT - m.*, - l.* - FROM ' . FOOTB_MATCHDAYS . ' AS m - LEFT JOIN ' . FOOTB_LEAGUES . " AS l ON (l.season = m.season AND l.league = m.league) - WHERE m.season >= $season AND m.status = 0 - AND (DATE_SUB(m.delivery_date, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) - AND (DATE_SUB(m.delivery_date, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time'))"; - $result = $this->db->sql_query($sql); - $toclose = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - // If we found matchdays to close, search missing bets and mail them - foreach ($toclose as $close) - { - // prepare some variables - $first_mail = true; - $season = $close['season']; - $league = $close['league']; - $league_name = $close['league_name']; - $league_short = $close['league_name_short']; - $delivery = $close['delivery_date']; - $matchday = $close['matchday']; - $subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SUBJECT'], $league_short, $matchday); - $usernames = ''; - - // find missing users - $sql = 'SELECT - u.user_email AS user_email, - u.username AS username, - u.user_id AS userid, - u.user_lang - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) - LEFT JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - LEFT JOIN ' . PROFILE_FIELDS_DATA_TABLE. ' AS p ON p.user_id = b.user_id - LEFT JOIN ' . USERS_TABLE. " AS u ON u.user_id = b.user_id - WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday - AND ((b.goals_home = '') OR (b.goals_guest = '')) - AND m.status = 0 AND p.pf_footb_rem_f = 1 - AND (l.bet_in_time = 0 OR - (l.bet_in_time = 1 - AND (DATE_SUB(m.match_datetime, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) - AND (DATE_SUB(m.match_datetime, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time')))) - GROUP BY b.user_id - UNION - SELECT - p.pf_footb_email AS user_email, - u.username AS username, - u.user_id AS userid, - u.user_lang - FROM " . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) - LEFT JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - LEFT JOIN ' . PROFILE_FIELDS_DATA_TABLE. ' AS p ON p.user_id = b.user_id - LEFT JOIN ' . USERS_TABLE. " AS u ON u.user_id = b.user_id - WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday - AND ((b.goals_home = '') OR (b.goals_guest = '')) - AND m.status = 0 AND p.pf_footb_rem_s = 1 - AND (l.bet_in_time = 0 OR - (l.bet_in_time = 1 - AND (DATE_SUB(m.match_datetime, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) - AND (DATE_SUB(m.match_datetime, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time')))) - GROUP BY b.user_id - "; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - - if (!$row) - { - $this->db->sql_freeresult($result); - } - else - { - - // Send the messages - include_once($this->root_path . 'includes/functions_messenger.' . $this->php_ext); - $messenger = new \messenger($use_queue); - include_once($this->root_path . 'includes/functions_user.' . $this->php_ext); - $errored = false; - $messenger->headers('X-AntiAbuse: Board servername - ' . $this->config['server_name']); - $messenger->headers('X-AntiAbuse: User_id - ' . ANONYMOUS); - $messenger->headers('X-AntiAbuse: Username - CRON TASK Football remember'); - $messenger->headers('X-AntiAbuse: User IP - ' . $this->user->ip); - $messenger->subject(htmlspecialchars_decode($subject)); - $messenger->set_mail_priority($priority); - - do - { - // Send the messages - $used_lang = $row['user_lang']; - $mail_template_path = $ext_path . 'language/' . $used_lang . '/email/'; - - if ($mode <> 'test') - { - $messenger->to($row['user_email'], $row['username']); - } - else - { - // test send to board email - $messenger->to($this->config['board_email'], $this->config['sitename']); - } - $messenger->template('footb_send_remember', $used_lang, $mail_template_path); - - $messenger->assign_vars(array( - 'USERNAME' => $row['username'], - 'LEAGUE' => $league_name, - 'MATCHDAY' => $matchday, - 'DELIVERY' => $delivery, - 'CONTACT_EMAIL' => $this->config['board_contact']) - ); - - if ($mode <> 'test') - { - if (!($messenger->send($used_method))) - { - $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL'], $league_short, $row['user_email']) . ''; - $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); - $usernames .= (($usernames != '') ? ', ' : '') . $row['username']. '!'; - } - else - { - $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; - } - } - else - { - // Test mode - if ($first_mail) - { - // only send one mail - if (!($messenger->send($used_method))) - { - $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL'], $league_short, $row['user_email']) . ''; - $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); - $usernames .= (($usernames != '') ? ', ' : '') . $row['username']. '!'; - } - else - { - $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; - } - $first_mail = false; - } - else - { - $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; - } - } - } - while ($row = $this->db->sql_fetchrow($result)); - $this->db->sql_freeresult($result); - - // Only if mails have already been sent previously - if ($usernames <> '') - { - // send mail to board administration - $used_lang = $this->config['default_lang']; - $mail_template_path = $ext_path . 'language/' . $used_lang . '/email/'; - $subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SUBJECT_BOARD'], $league_short, $matchday); - $messenger->to($this->config['board_email'], $this->config['sitename']); - $messenger->subject(htmlspecialchars_decode($subject)); - $messenger->template('footb_board_remember', $used_lang, $mail_template_path); - $messenger->assign_vars(array( - 'CONTACT_EMAIL' => $this->config['board_contact'], - 'REMEMBER_LIST' => $usernames, - ) - ); - - if (!($messenger->send($used_method))) - { - $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL_BOARD'], $league_short, $this->config['board_email']) . ''; - $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); - } - else - { - $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SEND'], $league_short, $usernames) ; - $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); - } - } - else - { - // Log the cronjob run - $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_NOBODY']) ; - $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); - } - } - } - if (sizeof($toclose) == 0) - { - // Log the cronjob run - $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_NO_DELIVERY']) ; - $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); - } - - return; - } - - /** - * Returns whether this cron task can run, given current board configuration. - * - * @return bool - */ - public function is_runnable() - { - return (bool) $this->config['football_remember_enable']; - } - - /** - * Returns whether this cron task should run now, because next run time - * has passed. - * - * @return bool - */ - public function should_run() - { - global $request; - $mode = $request->variable('mode', ''); - - if ($mode <> 'test') - { - return $this->config['football_remember_next_run'] < time(); - } - else - { - return true; - } - } -} +root_path = $root_path; + $this->php_ext = $php_ext; + $this->phpbb_extension_manager = $phpbb_extension_manager; + $this->phpbb_path_helper = $phpbb_path_helper; + $this->db = $db; + $this->config = $config; + $this->phpbb_log = $log; + $this->user = $user; + } + + /** + * Runs this cron task. + * + * @return null + */ + public function run() + { + global $request; + + $ext_path = $this->phpbb_path_helper->update_web_root_path($this->phpbb_extension_manager->get_extension_path('football/football', true)); + include($ext_path . 'includes/functions.' . $this->php_ext); + include($ext_path . 'includes/constants.' . $this->php_ext); + + // Load extension language file + $this->user->setup(); + $this->user->add_lang_ext('football/football', 'info_acp_football'); + + // mode=test ? + $mode = $request->variable('mode', ''); + $days = $request->variable('days', 0); + + //Mail Settings + $use_queue = false; + $used_method = NOTIFY_EMAIL; + $priority = MAIL_NORMAL_PRIORITY; + + + $season = curr_season(); + //Matchdays to close in 24 hours and 24 hours later + // shift days to test + $local_board_time = time() + ($days * 86400); + + if ($mode <> 'test') + { + // Update next run + $run_time = getdate($this->config['football_remember_next_run']); + $next_run = mktime($run_time['hours'], $run_time['minutes'], 0, date("n"), date("j") + 1, date("Y")); + $this->config->set('football_remember_next_run', $next_run, true); + } + else + { + $message = sprintf($this->user->lang['LOG_FOOTBALL_MSG_TEST' . (($days == 0) ? '' : '_TRAVEL')], date("d.m.Y H:i", $local_board_time)); + $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON_TEST', false, array($message)); + } + + $sql = 'SELECT + m.*, + l.* + FROM ' . FOOTB_MATCHDAYS . ' AS m + LEFT JOIN ' . FOOTB_LEAGUES . " AS l ON (l.season = m.season AND l.league = m.league) + WHERE m.season >= $season AND m.status = 0 + AND (DATE_SUB(m.delivery_date, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) + AND (DATE_SUB(m.delivery_date, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time')) + GROUP BY m.season, m.league, m.matchday"; + $result = $this->db->sql_query($sql); + $toclose = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + // If we found matchdays to close, search missing bets and mail them + foreach ($toclose as $close) + { + // prepare some variables + $first_mail = true; + $season = $close['season']; + $league = $close['league']; + $league_name = $close['league_name']; + $league_short = $close['league_name_short']; + $delivery = $close['delivery_date']; + $matchday = $close['matchday']; + $subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SUBJECT'], $league_short, $matchday); + $usernames = ''; + + // find missing users + $sql = 'SELECT + u.user_email AS user_email, + u.username AS username, + u.user_id AS userid, + u.user_lang + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) + LEFT JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + LEFT JOIN ' . PROFILE_FIELDS_DATA_TABLE. ' AS p ON p.user_id = b.user_id + LEFT JOIN ' . USERS_TABLE. " AS u ON u.user_id = b.user_id + WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday + AND ((b.goals_home = '') OR (b.goals_guest = '')) + AND m.status = 0 AND p.pf_footb_rem_f = 1 + AND (l.bet_in_time = 0 OR + (l.bet_in_time = 1 + AND (DATE_SUB(m.match_datetime, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) + AND (DATE_SUB(m.match_datetime, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time')))) + GROUP BY b.user_id + UNION + SELECT + p.pf_footb_email AS user_email, + u.username AS username, + u.user_id AS userid, + u.user_lang + FROM " . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = m.season AND l.league = m.league) + LEFT JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + LEFT JOIN ' . PROFILE_FIELDS_DATA_TABLE. ' AS p ON p.user_id = b.user_id + LEFT JOIN ' . USERS_TABLE. " AS u ON u.user_id = b.user_id + WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday + AND ((b.goals_home = '') OR (b.goals_guest = '')) + AND m.status = 0 AND p.pf_footb_rem_s = 1 + AND (l.bet_in_time = 0 OR + (l.bet_in_time = 1 + AND (DATE_SUB(m.match_datetime, INTERVAL '1 23:59' DAY_MINUTE) < FROM_UNIXTIME('$local_board_time')) + AND (DATE_SUB(m.match_datetime, INTERVAL '1 00:00' DAY_MINUTE) > FROM_UNIXTIME('$local_board_time')))) + GROUP BY b.user_id + "; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + + if (!$row) + { + $this->db->sql_freeresult($result); + } + else + { + + // Send the messages + include_once($this->root_path . 'includes/functions_messenger.' . $this->php_ext); + $messenger = new \messenger($use_queue); + include_once($this->root_path . 'includes/functions_user.' . $this->php_ext); + $errored = false; + $messenger->headers('X-AntiAbuse: Board servername - ' . $this->config['server_name']); + $messenger->headers('X-AntiAbuse: User_id - ' . ANONYMOUS); + $messenger->headers('X-AntiAbuse: Username - CRON TASK Football remember'); + $messenger->headers('X-AntiAbuse: User IP - ' . $this->user->ip); + $messenger->subject(htmlspecialchars_decode($subject)); + $messenger->set_mail_priority($priority); + + do + { + // Send the messages + $used_lang = $row['user_lang']; + $mail_template_path = $ext_path . 'language/' . $used_lang . '/email/'; + + if ($mode <> 'test') + { + $messenger->to($row['user_email'], $row['username']); + } + else + { + // test send to board email + $messenger->to($this->config['board_email'], $this->config['sitename']); + } + $messenger->template('footb_send_remember', $used_lang, $mail_template_path); + + $messenger->assign_vars(array( + 'USERNAME' => $row['username'], + 'LEAGUE' => $league_name, + 'MATCHDAY' => $matchday, + 'DELIVERY' => $delivery, + 'CONTACT_EMAIL' => $this->config['board_contact']) + ); + + if ($mode <> 'test') + { + if (!($messenger->send($used_method))) + { + $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL'], $league_short, $row['user_email']) . ''; + $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); + $usernames .= (($usernames != '') ? ', ' : '') . $row['username']. '!'; + } + else + { + $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; + } + } + else + { + // Test mode + if ($first_mail) + { + // only send one mail + if (!($messenger->send($used_method))) + { + $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL'], $league_short, $row['user_email']) . ''; + $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); + $usernames .= (($usernames != '') ? ', ' : '') . $row['username']. '!'; + } + else + { + $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; + } + $first_mail = false; + } + else + { + $usernames .= (($usernames != '') ? ', ' : '') . $row['username']; + } + } + } + while ($row = $this->db->sql_fetchrow($result)); + $this->db->sql_freeresult($result); + + // Only if mails have already been sent previously + if ($usernames <> '') + { + // send mail to board administration + $used_lang = $this->config['default_lang']; + $mail_template_path = $ext_path . 'language/' . $used_lang . '/email/'; + $subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SUBJECT_BOARD'], $league_short, $matchday); + $messenger->to($this->config['board_email'], $this->config['sitename']); + $messenger->subject(htmlspecialchars_decode($subject)); + $messenger->template('footb_board_remember', $used_lang, $mail_template_path); + $messenger->assign_vars(array( + 'CONTACT_EMAIL' => $this->config['board_contact'], + 'REMEMBER_LIST' => $usernames, + ) + ); + + if (!($messenger->send($used_method))) + { + $message = '' . sprintf($this->user->lang['FOOTBALL_REMEMBER_ERROR_EMAIL_BOARD'], $league_short, $this->config['board_email']) . ''; + $this->phpbb_log->add('critical', ANONYMOUS, '', 'LOG_ERROR_EMAIL', false, array($message)); + } + else + { + $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_SEND'], $league_short, $usernames) ; + $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); + } + } + else + { + // Log the cronjob run + $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_NOBODY']) ; + $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); + } + } + } + if (sizeof($toclose) == 0) + { + // Log the cronjob run + $log_subject = sprintf($this->user->lang['FOOTBALL_REMEMBER_NO_DELIVERY']) ; + $this->phpbb_log->add('admin', ANONYMOUS, '', 'LOG_FOOTBALL_REMEMBER_CRON', false, array($log_subject)); + } + + return; + } + + /** + * Returns whether this cron task can run, given current board configuration. + * + * @return bool + */ + public function is_runnable() + { + return (bool) $this->config['football_remember_enable']; + } + + /** + * Returns whether this cron task should run now, because next run time + * has passed. + * + * @return bool + */ + public function should_run() + { + global $request; + $mode = $request->variable('mode', ''); + + if ($mode <> 'test') + { + return $this->config['football_remember_next_run'] < time(); + } + else + { + return true; + } + } +} ?> \ No newline at end of file diff --git a/event/main_listener.php b/event/main_listener.php index ec81a3d..1c856b9 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -1,551 +1,549 @@ -auth = $auth; - $this->config = $config; - $this->controller_helper = $helper; - $this->template = $template; - $this->phpbb_path_helper = $path_helper; - $this->phpbb_extension_manager = $phpbb_extension_manager; - $this->user = $user; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - -// include($path_helper->update_web_root_path($phpbb_extension_manager->get_extension_path('football/football', true)) . 'includes/constants.' . $php_ext); - } - - /** - * Assign functions defined in this class to event listeners in the core - * - * @return array - */ - static public function getSubscribedEvents() - { - return array( - 'core.viewonline_overwrite_location' => 'viewonline_page', - 'core.user_setup' => 'load_language_on_setup', - 'core.page_header' => 'add_football_links', - 'core.session_kill_after' => 'detect_mobile_device', - 'core.session_create_after' => 'detect_mobile_device', - 'core.permissions' => 'add_permission_cat', - ); - } - - /** - * Show users as viewing the football prediction league on Who Is Online page - * - * @param object $event The event object - * @return null - */ - public function viewonline_page($event) - { - global $db; - if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/football') === 0) - { - $action = substr($event['row']['session_page'], 17); - $url_parts = $this->phpbb_path_helper->get_url_parts($action, false); - $params = (isset($url_parts['params'])) ? $url_parts['params'] : array(); - if (isset($params['l']) and isset($params['s'])) - { - include_once($this->phpbb_root_path . 'ext/football/football/includes/constants.' . $this->php_ext); - $season = $params['s']; - $league =$params['l']; - $sql = 'SELECT league_name FROM ' . FOOTB_LEAGUES . " - WHERE season = $season AND league = $league - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $event['location'] = $this->user->lang('VIEWING_LEAGUE' . (empty($url_parts['base']) ? '' : '_' . strtoupper ($url_parts['base'])), $row['league_name']); - } - else - { - $event['location_url'] = $this->controller_helper->route('football_main_controller', array_merge(array('side' => $url_parts['base']), $url_parts['params'])); - } - $db->sql_freeresult($result); - } - else - { - $event['location'] = $this->user->lang('VIEWING_FOOTBALL' . (empty($url_parts['base']) ? '' : '_' . strtoupper ($url_parts['base']))); - } - $event['location_url'] = $this->controller_helper->route('football_main_controller', array_merge(array('side' => $url_parts['base']), $url_parts['params'])); - } - } - - /** - * Load football prediction league language during user setup - * - * @param object $event The event object - * @return null - */ - public function load_language_on_setup($event) - { - $lang_set_ext = $event['lang_set_ext']; - $lang_set_ext[] = array( - 'ext_name' => 'football/football', - 'lang_set' => 'football', - ); - if (defined('ADMIN_START')) - { - $lang_set_ext[] = array( - 'ext_name' => 'football/football', - 'lang_set' => 'permissions_football', - ); - } - $event['lang_set_ext'] = $lang_set_ext; - } - - /** - * Add football links if user is authed to see it - * - * @return null - */ - public function add_football_links($event) - { - global $request, $cache, $season, $league, $matchday; - - $ext_path = $this->phpbb_path_helper->update_web_root_path($this->phpbb_extension_manager->get_extension_path('football/football', true)); - if (!$this->has_football_access()) - { - return; - } - - if (isset($this->config['football_side']) && $this->config['football_side'] && !$this->user->data['football_mobile']) - { - if (!($wrapped_football_name = $cache->get('wrapped_football_name'))) - { - $wrapped_football_name = ''; - $string = utf8_decode($this->config['football_name']); - for($i = 0; $i < strlen($string); $i++) - { - $wrapped_football_name .= strtoupper($string[$i]) . '
'; - } - $wrapped_football_name = utf8_encode($wrapped_football_name); - $cache->put($wrapped_football_name, $wrapped_football_name); - } - - $this->template->assign_vars(array( - 'S_FOOTBALLSIDE' => $wrapped_football_name, - 'S_FOOTBALL_SIDE' => true, - )); - } - - - $football_season = (empty($this->user->data['football_season'])) ? 0 : $this->user->data['football_season']; - $football_league = (empty($this->user->data['football_league'])) ? 0 : $this->user->data['football_league']; - $football_matchday = (empty($this->user->data['football_matchday'])) ? 0 : $this->user->data['football_matchday']; - - $season = $request->variable('s', $football_season); - $league = $request->variable('l', $football_league); - $matchday = $request->variable('m', $football_matchday); - - $in_football_ext = (!defined('IN_FOOTBALL')) ? false : IN_FOOTBALL; - - $this->template->assign_vars(array( - 'S_DISPLAY_FOOTBALL_MENU' => $this->config['football_menu'], - 'S_FOOTBALL_BREADCRUMB' => $this->config['football_breadcrumb'], - 'S_FOOTBALL_NAME' => $this->config['football_name'], - 'S_FOOTBALL_HEADER_LEAGUE' => $league, - 'S_FOOTBALL_EXT_PATH' => $ext_path, - 'S_FOOTBALL_HEADER_ENABLED' => $this->config['football_header_enable'] ? $in_football_ext : false, - 'U_FOOTBALL' => $this->controller_helper->route('football_main_controller', array('side' => 'bet')), - 'U_BET' => $this->controller_helper->route('football_main_controller', array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_ALL_BETS' => $this->controller_helper->route('football_main_controller', array('side' => 'all_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_RESULTS' => $this->controller_helper->route('football_main_controller', array('side' => 'results', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_TABLE' => $this->controller_helper->route('football_main_controller', array('side' => 'table', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_RANKS_TOTAL' => $this->controller_helper->route('football_main_controller', array('side' => 'ranks_total', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_RANKS_MATCHDAY' => $this->controller_helper->route('football_main_controller', array('side' => 'ranks_matchday', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_DELIVERY_LIST' => $this->controller_helper->route('football_main_controller', array('side' => 'delivery', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_LAST_VISITORS' => $this->controller_helper->route('football_main_controller', array('side' => 'last_users', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_FOOTBALL_BANK' => $this->controller_helper->route('football_main_controller', array('side' => 'bank', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_RULES' => $this->controller_helper->route('football_football_popup', array('popside' => 'rules_popup', 's' => $season, 'l' => $league)), - 'U_EXPORT' => $this->controller_helper->route('football_football_download', array('downside' => 'dload_export', 's' => $season, 'l' => $league)), - 'U_ODDS' => $this->controller_helper->route('football_main_controller', array('side' => 'odds', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'S_MENU_LINK1' => (strlen($this->config['football_menu_link1']) > 4) ? true : false, - 'U_MENU_LINK1' => $this->config['football_menu_link1'], - 'MENU_DESC_LINK1' => $this->config['football_menu_desc1'], - 'S_MENU_LINK2' => (strlen($this->config['football_menu_link2']) > 4) ? true : false, - 'U_MENU_LINK2' => $this->config['football_menu_link2'], - 'MENU_DESC_LINK2' => $this->config['football_menu_desc2'], - 'S_MENU_LINK3' => (strlen($this->config['football_menu_link3']) > 4) ? true : false, - 'U_MENU_LINK3' => (strpos($this->config['football_menu_link3'], 'xml/league.php') === false) ? $this->config['football_menu_link3'] : $this->config['football_menu_link3'] . "&season=$season&league=$league", - 'MENU_DESC_LINK3' => $this->config['football_menu_desc3'], - 'U_MY_BETS' => $this->controller_helper->route('football_main_controller', array('side' => 'my_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_MY_POINTS' => $this->controller_helper->route('football_main_controller', array('side' => 'my_points', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_MY_TABLE' => $this->controller_helper->route('football_main_controller', array('side' => 'my_table', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_MY_RANK' => $this->controller_helper->route('football_main_controller', array('side' => 'my_rank', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_MY_CHART' => $this->controller_helper->route('football_main_controller', array('side' => 'my_chart', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_MY_KOEFF' => $this->controller_helper->route('football_main_controller', array('side' => 'my_koeff', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_STAT_RESULTS' => $this->controller_helper->route('football_main_controller', array('side' => 'stat_results', 's' => $season, 'l' => $league, 'm' => $matchday)), - 'U_STAT_POINTS' => $this->controller_helper->route('football_main_controller', array('side' => 'stat_points', 's' => $season, 'l' => $league, 'm' => $matchday)), - )); - } - - /** - * Detect mobile devices - * - * @return null - */ - public function detect_mobile_device() - { - global $db, $request, $mobile_device, $mobile; - - $mobile = false; - $user_agent = $request->server('HTTP_USER_AGENT'); - if ($this->user->data['football_mobile_device'] == '') - { - switch(true) - { - /** Remove Bots from the list */ - case (preg_match('/bot|yahoo|Java|httpget/i', $user_agent)); - $mobile = false; - break; - case (preg_match('/ipad/i', $user_agent)); - $mobile_device = 'iPad'; - $mobile = true; - break; - case (preg_match('/ipod/i', $user_agent)); - $mobile_device = 'iPod'; - $mobile = true; - break; - case (preg_match('/iphone/i', $user_agent)); - $mobile_device = 'iPhone'; - $mobile = true; - break; - case (preg_match('/android/i', $user_agent)); - if (preg_match('/SM-G870A|SM-G900A|SM-G900F|SM-G900H|SM-G900M|SM-G900P|SM-G900R4|SM-G900T|SM-G900V|SM-G900W8|SM-G800F/i', $user_agent)) - { - $mobile_device = 'Samsung S5'; - } - elseif (preg_match('/SGH-I497/i', $user_agent)) - { - $mobile_device = 'Samsung Tablet'; - } - elseif (preg_match('/GT-P5210|SM-T110|SM-T310/i', $user_agent)) - { - $mobile_device = 'Samsung Tab 3'; - } - elseif (preg_match('/SM-T335|SM-T530/i', $user_agent)) - { - $mobile_device = 'Samsung Tab 4'; - } - elseif (preg_match('/SM-T520/i', $user_agent)) - { - $mobile_device = 'Samsung TabPRO'; - } - elseif (preg_match('/SGH-I537|GT-I9505|GT-I9500|SPH-L720T/i', $user_agent)) - { - $mobile_device = 'Samsung S4'; - } - elseif (preg_match('/GT-I9100P/i', $user_agent)) - { - $mobile_device = 'Samsung S2'; - } - elseif (preg_match('/SM-N7505|SM-N9005|SM-P600/i', $user_agent)) - { - $mobile_device = 'Samsung Note 3'; - } - elseif (preg_match('/SM-N910C|SM-N910F/i', $user_agent)) - { - $mobile_device = 'Samsung Note 4'; - } - elseif (preg_match('/SM-G357FZ/i', $user_agent)) - { - $mobile_device = 'Samsung Ace 4'; - } - elseif (preg_match('/SM-G925P/i', $user_agent)) - { - $mobile_device = 'Samsung S6 Edge'; - } - elseif (preg_match('/GT-S7582/i', $user_agent)) - { - $mobile_device = 'Samsung S Duos 2'; - } - elseif (preg_match('/GT-I9100P/i', $user_agent)) - { - $mobile_device = 'Samsung S2'; - } - elseif (preg_match('/IMM76B/i', $user_agent)) - { - $mobile_device = 'Samsung Nexus'; - } - elseif (preg_match('/TF101/i', $user_agent)) - { - $mobile_device = 'Asus Transformer Tablet'; - } - elseif (preg_match('/Archos 40b/i', $user_agent)) - { - $mobile_device = 'Archos 40b Titanium Surround'; - } - elseif (preg_match('/A0001/i', $user_agent)) - { - $mobile_device = 'OnePlus One'; - } - elseif (preg_match('/Orange Nura/i', $user_agent)) - { - $mobile_device = 'Orange Nura'; - } - elseif (preg_match('/XT1030/i', $user_agent)) - { - $mobile_device = 'Motorola Droid Mini'; - } - elseif (preg_match('/TIANYU-KTOUCH/i', $user_agent)) - { - $mobile_device = 'Tianyu K-Touch'; - } - elseif (preg_match('/D2005|D2105/i', $user_agent)) - { - $mobile_device = 'Sony Xperia E1 Dual'; - } - elseif (preg_match('/C2005|D2303/i', $user_agent)) - { - $mobile_device = 'Sony XPERIA M2'; - } - elseif (preg_match('/C6906/i', $user_agent)) - { - $mobile_device = 'Sony Xperia Z1'; - } - elseif (preg_match('/D5803/i', $user_agent)) - { - $mobile_device = 'Sony Xperia Z3'; - } - elseif (preg_match('/ASUS_T00J/i', $user_agent)) - { - $mobile_device = 'ASUS T00J'; - } - elseif (preg_match('/Aquaris E5/i', $user_agent)) - { - $mobile_device = 'Aquaris E5 HD'; - } - elseif (preg_match('/P710/i', $user_agent)) - { - $mobile_device = 'LG Optimus L7 II'; - } - elseif (preg_match('/HTC Desire|626s/i', $user_agent)) - { - $mobile_device = 'HTC Desire'; - } - elseif (preg_match('/Nexus 4|LRX22C|LVY48F/i', $user_agent)) - { - $mobile_device = 'Nexus 4'; - } - elseif (preg_match('/Nexus 5|LMY48S/i', $user_agent)) - { - $mobile_device = 'Nexus 5'; - } - elseif (preg_match('/Nexus 7|KTU84P/i', $user_agent)) - { - $mobile_device = 'Nexus 7'; - } - elseif (preg_match('/Nexus 9|LMY47X/i', $user_agent)) - { - $mobile_device = 'Nexus 9'; - } - elseif (preg_match('/Lenovo_K50_T5/i', $user_agent)) - { - $mobile_device = 'Lenovo K50-t5'; - } - elseif (preg_match('/HUAWEI GRA-L09/i', $user_agent)) - { - $mobile_device = 'HUAWEI P8'; - } - else - { - $mobile_device = 'ANDROID'; - } - $mobile = true; - break; - case (preg_match('/lg/i', $user_agent)); - $mobile_device = 'LG'; - $mobile = true; - break; - case (preg_match('/opera mini/i', $user_agent)); - $mobile_device = 'MOBILE'; - $mobile = true; - break; - case (preg_match('/blackberry/i', $user_agent)); - if (preg_match('/BlackBerry9900|BlackBerry9930|BlackBerry9790|BlackBerry9780|BlackBerry9700|BlackBerry9650|BlackBerry9000/i', $user_agent)) - { - $mobile_device = 'BlackBerry Bold'; - } - elseif (preg_match('/BlackBerry9380|BlackBerry9370|BlackBerry9360|BlackBerry9350|BlackBerry9330|BlackBerry9320|BlackBerry9300|BlackBerry9220|BlackBerry8980|BlackBerry8900|BlackBerry8530|BlackBerry8520|BlackBerry8330|BlackBerry8320|BlackBerry8310|BlackBerry8300/i', $user_agent)) - { - $mobile_device = 'BlackBerry Curve'; - } - elseif (preg_match('/BlackBerry9860|BlackBerry9850|BlackBerry9810|BlackBerry9800/i', $user_agent)) - { - $mobile_device = 'BlackBerry Torch'; - } - elseif (preg_match('/BlackBerry9900/i', $user_agent)) - { - $mobile_device = 'BlackBerry Touch'; - } - elseif (preg_match('/BlackBerry9105/i', $user_agent)) - { - $mobile_device = 'BlackBerry Pearl'; - } - elseif (preg_match('/BlackBerry8220/i', $user_agent)) - { - $mobile_device = 'BlackBerry Pearl Flip'; - } - elseif (preg_match('/BlackBerry PlayBook|BlackBerry Porsche|BlackBerry Passport|BlackBerry Storm|BlackBerry Storm2/', $user_agent, $match_device)) - { - $mobile_device = $match_device[0]; - } - else - { - $mobile_device = 'BlackBerry'; - } - $mobile = true; - break; - case (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $user_agent)); - $mobile_device = 'Palm'; - $mobile = true; - break; - case (preg_match('/(iris|3g_t|windows ce|windows Phone|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i', $user_agent)); - $mobile_device = 'Windows Smartphone'; - $mobile = true; - break; - case (preg_match('/lge vx10000/i', $user_agent)); - $mobile_device = 'Voyager'; - $mobile = true; - break; - case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i', $user_agent)); - $mobile_device = 'MOBILE'; - $mobile = true; - break; - case (isset($post['HTTP_X_WAP_PROFILE'])||isset($post['HTTP_PROFILE'])); - $mobile_device = 'MOBILE'; - $mobile = true; - break; - case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))); - $mobile_device = 'MOBILE'; - $mobile = true; - break; - default; - $mobile_device = 'Desktop'; - $mobile = false; - break; - } - - // Write to sessions table - $sql_ary = array( - 'football_mobile' => $mobile, - 'football_mobile_device' => $db->sql_escape($mobile_device), - ); - $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE session_id = '" . $db->sql_escape($this->user->session_id) . "'"; - $db->sql_query($sql); - $this->user->data['football_mobile'] = $mobile; - $this->user->data['football_mobile_device'] = $mobile_device; - } - } - - /** - * Check if user should be able to access football prediction league - * - * @return bool True of user should be able to access it, false if not - */ - protected function has_football_access() - { - // Can this user view Prediction Leagues pages? - if (!$this->config['football_guest_view']) - { - if ($this->user->data['user_id'] == ANONYMOUS) - { - return false; - } - } - if (!$this->config['football_user_view']) - { - return $this->auth->acl_get('u_use_football') && ! $this->config['football_disable']; - } - return ! $this->config['football_disable']; - } - - public function add_permission_cat($event) - { - $perm_cat = $event['categories']; - $perm_cat['football'] = 'ACP_FOOTBALL'; - $event['categories'] = $perm_cat; - - $permission = $event['permissions']; - $permission['u_use_football'] = array('lang' => 'ACL_U_USE_FOOTBALL', 'cat' => 'football'); - $permission['a_football_config'] = array('lang' => 'ACL_A_FOOTBALL_CONFIG', 'cat' => 'football'); - $permission['a_football_delete'] = array('lang' => 'ACL_A_FOOTBALL_DELETE', 'cat' => 'football'); - $permission['a_football_editbets'] = array('lang' => 'ACL_A_FOOTBALL_EDITBETS', 'cat' => 'football'); - $permission['a_football_plan'] = array('lang' => 'ACL_A_FOOTBALL_PLAN', 'cat' => 'football'); - $permission['a_football_results'] = array('lang' => 'ACL_A_FOOTBALL_RESULTS', 'cat' => 'football'); - $permission['a_football_points'] = array('lang' => 'ACL_A_FOOTBALL_POINTS', 'cat' => 'football'); - $event['permissions'] = $permission; - } -} +auth = $auth; + $this->config = $config; + $this->controller_helper = $helper; + $this->template = $template; + $this->phpbb_path_helper = $path_helper; + $this->phpbb_extension_manager = $phpbb_extension_manager; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + +// include($path_helper->update_web_root_path($phpbb_extension_manager->get_extension_path('football/football', true)) . 'includes/constants.' . $php_ext); + } + + /** + * Assign functions defined in this class to event listeners in the core + * + * @return array + */ + static public function getSubscribedEvents() + { + return array( + 'core.viewonline_overwrite_location' => 'viewonline_page', + 'core.user_setup' => 'load_language_on_setup', + 'core.page_header' => 'add_football_links', + 'core.session_kill_after' => 'detect_mobile_device', + 'core.session_create_after' => 'detect_mobile_device', + 'core.permissions' => 'add_permission_cat', + ); + } + + /** + * Show users as viewing the football prediction league on Who Is Online page + * + * @param object $event The event object + * @return null + */ + public function viewonline_page($event) + { + global $db; + if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/football') === 0) + { + $action = substr($event['row']['session_page'], 17); + $url_parts = $this->phpbb_path_helper->get_url_parts($action, false); + $params = (isset($url_parts['params'])) ? $url_parts['params'] : array(); + if (isset($params['l']) and isset($params['s'])) + { + include_once($this->phpbb_root_path . 'ext/football/football/includes/constants.' . $this->php_ext); + $season = $params['s']; + $league =$params['l']; + $sql = 'SELECT league_name FROM ' . FOOTB_LEAGUES . " + WHERE season = $season AND league = $league + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $event['location'] = $this->user->lang('VIEWING_LEAGUE' . (empty($url_parts['base']) ? '' : '_' . strtoupper ($url_parts['base'])), $row['league_name']); + } + else + { + $event['location_url'] = $this->controller_helper->route('football_main_controller', array_merge(array('side' => $url_parts['base']), $url_parts['params'])); + } + $db->sql_freeresult($result); + } + else + { + $event['location'] = $this->user->lang('VIEWING_FOOTBALL' . (empty($url_parts['base']) ? '' : '_' . strtoupper ($url_parts['base']))); + } + $event['location_url'] = $this->controller_helper->route('football_main_controller', array_merge(array('side' => $url_parts['base']), $url_parts['params'])); + } + } + + /** + * Load football prediction league language during user setup + * + * @param object $event The event object + * @return null + */ + public function load_language_on_setup($event) + { + $lang_set_ext = $event['lang_set_ext']; + $lang_set_ext[] = array( + 'ext_name' => 'football/football', + 'lang_set' => 'football', + ); + if (defined('ADMIN_START')) + { + $lang_set_ext[] = array( + 'ext_name' => 'football/football', + 'lang_set' => 'permissions_football', + ); + } + $event['lang_set_ext'] = $lang_set_ext; + } + + /** + * Add football links if user is authed to see it + * + * @return null + */ + public function add_football_links($event) + { + global $request, $cache, $season, $league, $matchday; + + $ext_path = $this->phpbb_path_helper->update_web_root_path($this->phpbb_extension_manager->get_extension_path('football/football', true)); + if (!$this->has_football_access()) + { + return; + } + + if (isset($this->config['football_side']) && $this->config['football_side'] && !$this->user->data['football_mobile']) + { + if (!($wrapped_football_name = $cache->get('wrapped_football_name'))) + { + $wrapped_football_name = ''; + $string = utf8_decode($this->config['football_name']); + for($i = 0; $i < strlen($string); $i++) + { + $wrapped_football_name .= strtoupper($string[$i]) . '
'; + } + $wrapped_football_name = utf8_encode($wrapped_football_name); + $cache->put($wrapped_football_name, $wrapped_football_name); + } + + $this->template->assign_vars(array( + 'S_FOOTBALLSIDE' => $wrapped_football_name, + 'S_FOOTBALL_SIDE' => true, + )); + } + + + $football_season = (empty($this->user->data['football_season'])) ? 0 : $this->user->data['football_season']; + $football_league = (empty($this->user->data['football_league'])) ? 0 : $this->user->data['football_league']; + $football_matchday = (empty($this->user->data['football_matchday'])) ? 0 : $this->user->data['football_matchday']; + + $season = $request->variable('s', $football_season); + $league = $request->variable('l', $football_league); + $matchday = $request->variable('m', $football_matchday); + + $in_football_ext = (!defined('IN_FOOTBALL')) ? false : IN_FOOTBALL; + + $this->template->assign_vars(array( + 'S_DISPLAY_FOOTBALL_MENU' => $this->config['football_menu'], + 'S_FOOTBALL_BREADCRUMB' => $this->config['football_breadcrumb'], + 'S_FOOTBALL_NAME' => $this->config['football_name'], + 'S_FOOTBALL_HEADER_LEAGUE' => $league, + 'S_FOOTBALL_EXT_PATH' => $ext_path, + 'S_FOOTBALL_HEADER_ENABLED' => $this->config['football_header_enable'] ? $in_football_ext : false, + 'U_FOOTBALL' => $this->controller_helper->route('football_main_controller', array('side' => 'bet')), + 'U_BET' => $this->controller_helper->route('football_main_controller', array('side' => 'bet', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_ALL_BETS' => $this->controller_helper->route('football_main_controller', array('side' => 'all_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_RESULTS' => $this->controller_helper->route('football_main_controller', array('side' => 'results', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_TABLE' => $this->controller_helper->route('football_main_controller', array('side' => 'table', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_RANKS_TOTAL' => $this->controller_helper->route('football_main_controller', array('side' => 'ranks_total', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_RANKS_MATCHDAY' => $this->controller_helper->route('football_main_controller', array('side' => 'ranks_matchday', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_DELIVERY_LIST' => $this->controller_helper->route('football_main_controller', array('side' => 'delivery', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_LAST_VISITORS' => $this->controller_helper->route('football_main_controller', array('side' => 'last_users', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_FOOTBALL_BANK' => $this->controller_helper->route('football_main_controller', array('side' => 'bank', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_RULES' => $this->controller_helper->route('football_football_popup', array('popside' => 'rules_popup', 's' => $season, 'l' => $league)), + 'U_EXPORT' => $this->controller_helper->route('football_football_download', array('downside' => 'dload_export', 's' => $season, 'l' => $league)), + 'U_ODDS' => $this->controller_helper->route('football_main_controller', array('side' => 'odds', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'S_MENU_LINK1' => (strlen($this->config['football_menu_link1']) > 4) ? true : false, + 'U_MENU_LINK1' => $this->config['football_menu_link1'], + 'MENU_DESC_LINK1' => $this->config['football_menu_desc1'], + 'S_MENU_LINK2' => (strlen($this->config['football_menu_link2']) > 4) ? true : false, + 'U_MENU_LINK2' => $this->config['football_menu_link2'], + 'MENU_DESC_LINK2' => $this->config['football_menu_desc2'], + 'S_MENU_LINK3' => (strlen($this->config['football_menu_link3']) > 4) ? true : false, + 'U_MENU_LINK3' => (strpos($this->config['football_menu_link3'], 'xml/league.php') === false) ? $this->config['football_menu_link3'] : $this->config['football_menu_link3'] . "&season=$season&league=$league", + 'MENU_DESC_LINK3' => $this->config['football_menu_desc3'], + 'U_MY_BETS' => $this->controller_helper->route('football_main_controller', array('side' => 'my_bets', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_MY_POINTS' => $this->controller_helper->route('football_main_controller', array('side' => 'my_points', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_MY_TABLE' => $this->controller_helper->route('football_main_controller', array('side' => 'my_table', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_MY_RANK' => $this->controller_helper->route('football_main_controller', array('side' => 'my_rank', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_MY_CHART' => $this->controller_helper->route('football_main_controller', array('side' => 'my_chart', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_MY_KOEFF' => $this->controller_helper->route('football_main_controller', array('side' => 'my_koeff', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_STAT_RESULTS' => $this->controller_helper->route('football_main_controller', array('side' => 'stat_results', 's' => $season, 'l' => $league, 'm' => $matchday)), + 'U_STAT_POINTS' => $this->controller_helper->route('football_main_controller', array('side' => 'stat_points', 's' => $season, 'l' => $league, 'm' => $matchday)), + )); + } + + /** + * Detect mobile devices + * + * @return null + */ + public function detect_mobile_device() + { + global $db, $request, $mobile_device, $mobile; + + $mobile = false; + $user_agent = $request->server('HTTP_USER_AGENT'); + + switch(true) + { + /** Remove Bots from the list */ + case (preg_match('/bot|yahoo|Java|httpget/i', $user_agent)); + $mobile = false; + break; + case (preg_match('/ipad/i', $user_agent)); + $mobile_device = 'iPad'; + $mobile = true; + break; + case (preg_match('/ipod/i', $user_agent)); + $mobile_device = 'iPod'; + $mobile = true; + break; + case (preg_match('/iphone/i', $user_agent)); + $mobile_device = 'iPhone'; + $mobile = true; + break; + case (preg_match('/android/i', $user_agent)); + if (preg_match('/SM-G870A|SM-G900A|SM-G900F|SM-G900H|SM-G900M|SM-G900P|SM-G900R4|SM-G900T|SM-G900V|SM-G900W8|SM-G800F/i', $user_agent)) + { + $mobile_device = 'Samsung S5'; + } + elseif (preg_match('/SGH-I497/i', $user_agent)) + { + $mobile_device = 'Samsung Tablet'; + } + elseif (preg_match('/GT-P5210|SM-T110|SM-T310/i', $user_agent)) + { + $mobile_device = 'Samsung Tab 3'; + } + elseif (preg_match('/SM-T335|SM-T530/i', $user_agent)) + { + $mobile_device = 'Samsung Tab 4'; + } + elseif (preg_match('/SM-T520/i', $user_agent)) + { + $mobile_device = 'Samsung TabPRO'; + } + elseif (preg_match('/SGH-I537|GT-I9505|GT-I9500|SPH-L720T/i', $user_agent)) + { + $mobile_device = 'Samsung S4'; + } + elseif (preg_match('/GT-I9100P/i', $user_agent)) + { + $mobile_device = 'Samsung S2'; + } + elseif (preg_match('/SM-N7505|SM-N9005|SM-P600/i', $user_agent)) + { + $mobile_device = 'Samsung Note 3'; + } + elseif (preg_match('/SM-N910C|SM-N910F/i', $user_agent)) + { + $mobile_device = 'Samsung Note 4'; + } + elseif (preg_match('/SM-G357FZ/i', $user_agent)) + { + $mobile_device = 'Samsung Ace 4'; + } + elseif (preg_match('/SM-G925P/i', $user_agent)) + { + $mobile_device = 'Samsung S6 Edge'; + } + elseif (preg_match('/GT-S7582/i', $user_agent)) + { + $mobile_device = 'Samsung S Duos 2'; + } + elseif (preg_match('/GT-I9100P/i', $user_agent)) + { + $mobile_device = 'Samsung S2'; + } + elseif (preg_match('/IMM76B/i', $user_agent)) + { + $mobile_device = 'Samsung Nexus'; + } + elseif (preg_match('/TF101/i', $user_agent)) + { + $mobile_device = 'Asus Transformer Tablet'; + } + elseif (preg_match('/Archos 40b/i', $user_agent)) + { + $mobile_device = 'Archos 40b Titanium Surround'; + } + elseif (preg_match('/A0001/i', $user_agent)) + { + $mobile_device = 'OnePlus One'; + } + elseif (preg_match('/Orange Nura/i', $user_agent)) + { + $mobile_device = 'Orange Nura'; + } + elseif (preg_match('/XT1030/i', $user_agent)) + { + $mobile_device = 'Motorola Droid Mini'; + } + elseif (preg_match('/TIANYU-KTOUCH/i', $user_agent)) + { + $mobile_device = 'Tianyu K-Touch'; + } + elseif (preg_match('/D2005|D2105/i', $user_agent)) + { + $mobile_device = 'Sony Xperia E1 Dual'; + } + elseif (preg_match('/C2005|D2303/i', $user_agent)) + { + $mobile_device = 'Sony XPERIA M2'; + } + elseif (preg_match('/C6906/i', $user_agent)) + { + $mobile_device = 'Sony Xperia Z1'; + } + elseif (preg_match('/D5803/i', $user_agent)) + { + $mobile_device = 'Sony Xperia Z3'; + } + elseif (preg_match('/ASUS_T00J/i', $user_agent)) + { + $mobile_device = 'ASUS T00J'; + } + elseif (preg_match('/Aquaris E5/i', $user_agent)) + { + $mobile_device = 'Aquaris E5 HD'; + } + elseif (preg_match('/P710/i', $user_agent)) + { + $mobile_device = 'LG Optimus L7 II'; + } + elseif (preg_match('/HTC Desire|626s/i', $user_agent)) + { + $mobile_device = 'HTC Desire'; + } + elseif (preg_match('/Nexus 4|LRX22C|LVY48F/i', $user_agent)) + { + $mobile_device = 'Nexus 4'; + } + elseif (preg_match('/Nexus 5|LMY48S/i', $user_agent)) + { + $mobile_device = 'Nexus 5'; + } + elseif (preg_match('/Nexus 7|KTU84P/i', $user_agent)) + { + $mobile_device = 'Nexus 7'; + } + elseif (preg_match('/Nexus 9|LMY47X/i', $user_agent)) + { + $mobile_device = 'Nexus 9'; + } + elseif (preg_match('/Lenovo_K50_T5/i', $user_agent)) + { + $mobile_device = 'Lenovo K50-t5'; + } + elseif (preg_match('/HUAWEI GRA-L09/i', $user_agent)) + { + $mobile_device = 'HUAWEI P8'; + } + else + { + $mobile_device = 'ANDROID'; + } + $mobile = true; + break; + case (preg_match('/lg/i', $user_agent)); + $mobile_device = 'LG'; + $mobile = true; + break; + case (preg_match('/opera mini/i', $user_agent)); + $mobile_device = 'MOBILE'; + $mobile = true; + break; + case (preg_match('/blackberry/i', $user_agent)); + if (preg_match('/BlackBerry9900|BlackBerry9930|BlackBerry9790|BlackBerry9780|BlackBerry9700|BlackBerry9650|BlackBerry9000/i', $user_agent)) + { + $mobile_device = 'BlackBerry Bold'; + } + elseif (preg_match('/BlackBerry9380|BlackBerry9370|BlackBerry9360|BlackBerry9350|BlackBerry9330|BlackBerry9320|BlackBerry9300|BlackBerry9220|BlackBerry8980|BlackBerry8900|BlackBerry8530|BlackBerry8520|BlackBerry8330|BlackBerry8320|BlackBerry8310|BlackBerry8300/i', $user_agent)) + { + $mobile_device = 'BlackBerry Curve'; + } + elseif (preg_match('/BlackBerry9860|BlackBerry9850|BlackBerry9810|BlackBerry9800/i', $user_agent)) + { + $mobile_device = 'BlackBerry Torch'; + } + elseif (preg_match('/BlackBerry9900/i', $user_agent)) + { + $mobile_device = 'BlackBerry Touch'; + } + elseif (preg_match('/BlackBerry9105/i', $user_agent)) + { + $mobile_device = 'BlackBerry Pearl'; + } + elseif (preg_match('/BlackBerry8220/i', $user_agent)) + { + $mobile_device = 'BlackBerry Pearl Flip'; + } + elseif (preg_match('/BlackBerry PlayBook|BlackBerry Porsche|BlackBerry Passport|BlackBerry Storm|BlackBerry Storm2/', $user_agent, $match_device)) + { + $mobile_device = $match_device[0]; + } + else + { + $mobile_device = 'BlackBerry'; + } + $mobile = true; + break; + case (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $user_agent)); + $mobile_device = 'Palm'; + $mobile = true; + break; + case (preg_match('/(iris|3g_t|windows ce|windows Phone|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i', $user_agent)); + $mobile_device = 'Windows Smartphone'; + $mobile = true; + break; + case (preg_match('/lge vx10000/i', $user_agent)); + $mobile_device = 'Voyager'; + $mobile = true; + break; + case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i', $user_agent)); + $mobile_device = 'MOBILE'; + $mobile = true; + break; + case (isset($post['HTTP_X_WAP_PROFILE'])||isset($post['HTTP_PROFILE'])); + $mobile_device = 'MOBILE'; + $mobile = true; + break; + case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))); + $mobile_device = 'MOBILE'; + $mobile = true; + break; + default; + $mobile_device = 'Desktop'; + $mobile = false; + break; + } + + // Write to sessions table + $sql_ary = array( + 'football_mobile' => $mobile, + 'football_mobile_device' => $db->sql_escape($mobile_device), + ); + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->user->session_id) . "'"; + $db->sql_query($sql); + $this->user->data['football_mobile'] = $mobile; + $this->user->data['football_mobile_device'] = $mobile_device; + } + + /** + * Check if user should be able to access football prediction league + * + * @return bool True of user should be able to access it, false if not + */ + protected function has_football_access() + { + // Can this user view Prediction Leagues pages? + if (!$this->config['football_guest_view']) + { + if ($this->user->data['user_id'] == ANONYMOUS) + { + return false; + } + } + if (!$this->config['football_user_view']) + { + return $this->auth->acl_get('u_use_football') && ! $this->config['football_disable']; + } + return ! $this->config['football_disable']; + } + + public function add_permission_cat($event) + { + $perm_cat = $event['categories']; + $perm_cat['football'] = 'ACP_FOOTBALL'; + $event['categories'] = $perm_cat; + + $permission = $event['permissions']; + $permission['u_use_football'] = array('lang' => 'ACL_U_USE_FOOTBALL', 'cat' => 'football'); + $permission['a_football_config'] = array('lang' => 'ACL_A_FOOTBALL_CONFIG', 'cat' => 'football'); + $permission['a_football_delete'] = array('lang' => 'ACL_A_FOOTBALL_DELETE', 'cat' => 'football'); + $permission['a_football_editbets'] = array('lang' => 'ACL_A_FOOTBALL_EDITBETS', 'cat' => 'football'); + $permission['a_football_plan'] = array('lang' => 'ACL_A_FOOTBALL_PLAN', 'cat' => 'football'); + $permission['a_football_results'] = array('lang' => 'ACL_A_FOOTBALL_RESULTS', 'cat' => 'football'); + $permission['a_football_points'] = array('lang' => 'ACL_A_FOOTBALL_POINTS', 'cat' => 'football'); + $event['permissions'] = $permission; + } +} diff --git a/includes/functions.php b/includes/functions.php index a75e593..7bbf52c 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,2531 +1,2532 @@ - 0 - $where_status"; - $result = $db->sql_query($sql); - - $result_ary = array(); - $extra_points_error = true; - while($row = $db->sql_fetchrow($result)) - { - $extra_no = $row['extra_no']; - if ($row['result'] <> '') - { - switch($row['question_type']) - { - case '2': - case '4': - // multiple results - { - $bet_points = 'CASE bet '; - $result_ary = explode(';', $row['result']); - foreach($result_ary AS $result_value) - { - if ($result_value <> '') - { - $result_value = (is_numeric($result_value)) ? $result_value : "'" . $result_value . "'"; - $bet_points .= ' WHEN ' . $result_value . ' THEN ' . $row['extra_points'] . ' '; - $extra_points_error = false; - } - } - $bet_points .= ' ELSE 0 END'; - } - break; - case '5': - // difference to result - { - if (is_numeric($row['result'])) - { - $bet_points = 'IF(' . $row['extra_points'] . '- ABS(bet - ' . $row['result'] . ') > 0, ' . $row['extra_points'] . '- ABS(bet - ' . $row['result'] . ')' . ', 0)'; - $extra_points_error = false; - } - else - { - $extra_points_error = true; - } - } - break; - default: - // Case 1 and 3 and other - // correct result - { - $result_value = (is_numeric($row['result'])) ? $row['result'] : "'" . $row['result'] . "'"; - $bet_points = 'CASE bet WHEN ' . $result_value . ' THEN ' . $row['extra_points'] . ' ELSE 0 END'; - $extra_points_error = false; - } - break; - } - if (!$extra_points_error) - { - $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' - SET bet_points = ' . $bet_points . " - WHERE season = $season - AND league = $league - AND extra_no = $extra_no"; - $db->sql_query($sql); - } - } - } - $db->sql_freeresult($result); -} - - -/** -* Save matchday-ranking in database (table FOOTB_RANKS). -*/ -function save_ranking_matchday($season, $league, $matchday, $cash = false) -{ - global $db, $config, $lang, $league_info; - $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " WHERE season = $season AND league = $league AND matchday = $matchday"; - $result = $db->sql_query($sql); - - if ( $row = $db->sql_fetchrow($result)) - { - $matchday_status = $row['status']; - if ($row['delivery_date_2'] != '' OR ($league_info['bet_in_time'] AND $matchday_status <> 3)) - // We set status to 2 to skip deleting the ranking - $matchday_status = 2; - $db->sql_freeresult($result); - if ($matchday_status < 2) - { - $sql = 'SELECT * FROM ' . FOOTB_MATCHES . " WHERE season = $season AND league = $league AND matchday = $matchday AND status IN (2,3)"; - $result = $db->sql_query($sql); - if ( $row = $db->sql_fetchrow($result)) - { - $matchday_status = 2; - } - } - - if ($matchday_status == 0 OR $matchday_status == 1) - { - // No matches played, so we can delete the ranking - $sql = 'DELETE FROM ' . FOOTB_RANKS . " WHERE season = $season AND league = $league AND matchday = $matchday"; - $result = $db->sql_query($sql); - } - else - { - $matchday_wins = array(); - $matchday_wins = matchday_wins($season, $league); - $sql = " - SELECT - 1 AS rank, - 0.00 AS win, - u.user_id, - u.username AS username, - SUM(IF(m.match_no > 0, 1, 0)) AS matches, - SUM(IF(b.goals_home = '' OR b.goals_guest = '', 1, 0)) AS nobet, - SUM(IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home = m.goals_home) AND (b.goals_guest = m.goals_guest) - , 1 - , 0 - ) - , 0 - ) - ) AS direct_hit, - SUM(IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> (m.goals_home + 0 < m.goals_guest) - OR (b.goals_home = b.goals_guest) <> (m.goals_home = m.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> (m.goals_home + 0 > m.goals_guest) - , 0 - , 1 - ) - , 0 - ) - ) AS tendency, - " . select_points('m',true) . ' - FROM ' . FOOTB_MATCHES . ' AS m - INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - INNER JOIN ' . USERS_TABLE . " AS u ON (b.user_id = u.user_id) - WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday AND m.status IN (2,3) - GROUP BY b.user_id - ORDER BY points DESC, nobet ASC, username ASC - "; - - $result = $db->sql_query($sql); - - $ranking_ary = array(); - while( $row = $db->sql_fetchrow($result)) - { - $ranking_ary[$row['user_id']] = $row; - } - $db->sql_freeresult($result); - if ( sizeof($ranking_ary) > 0 ) - { - $sql = ' - SELECT - eb.user_id, - SUM(eb.bet_points) AS points - FROM ' . FOOTB_EXTRA . ' AS e - INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) - WHERE e.season = $season - AND e.league = $league - AND e.matchday = $matchday - AND e.matchday_eval = $matchday - AND e.extra_status > 1 - GROUP BY eb.user_id"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - $ranking_ary[$row['user_id']]['points'] += $row['points']; - } - $db->sql_freeresult($result); - - // sort the ranking by points - usort($ranking_ary, '_sort_points'); - } - - $last_points = -1; - $last_rank = 1; - $equal_rank = array(); - $money = array(); - $i = 0; - foreach( $ranking_ary AS $curr_user => $curr_rank) - { - if ($curr_rank['nobet'] == $curr_rank['matches'] and $league_info['points_last'] == 1) - { - if ($last_points <> -1) - { - $ranking_ary[$curr_user]['points'] = $last_points; - } - else - { - $ranking_ary[$curr_user]['points'] = 0; - $last_points = 0; - $equal_rank[$last_rank] = 0; - } - } - if ( $ranking_ary[$curr_user]['points'] != $last_points) - { - $ranking_ary[$curr_user]['rank'] = $i + 1; - $last_rank = $i + 1; - $equal_rank[$last_rank] = 1; - if ($last_rank < sizeof($matchday_wins)) - { - $money[$last_rank] = $matchday_wins[$last_rank]; - } - else - { - $money[$last_rank] = 0; - } - $last_points = $ranking_ary[$curr_user]['points']; - } - else - { - $ranking_ary[$curr_user]['rank'] = $last_rank; - $equal_rank[$last_rank] += 1; - if ($i + 1 < sizeof($matchday_wins)) - { - $money[$last_rank] += $matchday_wins[$i + 1]; - } - } - $i++; - } - foreach( $ranking_ary AS $curr_user => $curr_rank) - { - if ( round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2) <> 0 ) - { - $win = round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2); - $ranking_ary[$curr_user]['win'] = $win; - } - else - { - $win = 0; - $ranking_ary[$curr_user]['win'] = 0; - } - $sql = 'REPLACE INTO ' . FOOTB_RANKS . " - VALUES ($season - , $league - , $matchday - , " . $curr_rank['user_id'] . " - , $matchday_status - , " . $curr_rank['rank'] . " - , " . $curr_rank['points'] . " - , $win - , 0 - , " . $curr_rank['tendency'] . " - , " . $curr_rank['direct_hit'] . " - ,0 - ,0 - )"; - $result = $db->sql_query($sql); - } - if ( sizeof($ranking_ary) == 0 ) - { - $sql = 'DELETE FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league - AND matchday = $matchday"; - $result = $db->sql_query($sql); - } - else - { - // Calculate total ranking - $rank_total_ary = array(); - $sql = 'SELECT - user_id , - SUM(points) AS points, - SUM(win) AS wins_total - FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league - AND matchday <= $matchday - GROUP by user_id - ORDER BY points DESC, user_id ASC"; - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - $rank_total_ary[$row['user_id']] = $row; - } - $db->sql_freeresult($result); - - // add extra tipp points total ranking - $league_info = league_info($season, $league); - if ( sizeof($rank_total_ary) > 0 ) - { - if ( $matchday == $league_info['matchdays']) - { - $win_user_most_hits = win_user_most_hits($season, $league, $matchday); - $win_user_most_hits_away = win_user_most_hits_away($season, $league, $matchday); - $season_wins = season_wins($season, $league, $matchday); - } - $sql = 'SELECT - eb.user_id, - SUM(eb.bet_points) AS points - FROM ' . FOOTB_EXTRA . ' AS e - INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) - WHERE e.season = $season - AND e.league = $league - AND e.matchday <> e.matchday_eval - AND e.matchday_eval <= $matchday - AND e.extra_status > 1 - GROUP BY eb.user_id"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - $rank_total_ary[$row['user_id']]['points'] += $row['points']; - } - $db->sql_freeresult($result); - - // sort the ranking by points - usort($rank_total_ary, '_sort_points'); - } - - $index = 0; - $last_rank = 0; - $last_points = -1; - foreach( $rank_total_ary AS $curr_user => $curr_rank) - { - $index++; - if ( $curr_rank['points'] == $last_points) - { - $rank_total = $last_rank; - } - else - { - $rank_total = $index; - $last_points = $curr_rank['points']; - $last_rank = $rank_total; - } - if ($matchday == $league_info['matchdays']) - { - // if someone didn't bet the hole Season - if (!isset($win_user_most_hits[$curr_rank['user_id']]['win'])) - { - $win_user_most_hits[$curr_rank['user_id']]['win'] = 0; - } - if (!isset($win_user_most_hits_away[$curr_rank['user_id']]['win'])) - { - $win_user_most_hits_away[$curr_rank['user_id']]['win'] = 0; - } - if (!isset($season_wins[$curr_rank['user_id']]['win'])) - { - $season_wins[$curr_rank['user_id']]['win'] = 0; - } - $rank_total_ary[$curr_user]['wins_total'] = sprintf('%01.2f',$curr_rank['wins_total'] + $win_user_most_hits[$curr_rank['user_id']]['win'] + $win_user_most_hits_away[$curr_rank['user_id']]['win'] + $season_wins[$curr_rank['user_id']]['win']); - } - else - { - $rank_total_ary[$curr_user]['wins_total'] = sprintf('%01.2f',$curr_rank['wins_total']); - } - $curr_userid = $curr_rank['user_id']; - $points_total = $curr_rank['points']; - $win_total = $rank_total_ary[$curr_user]['wins_total']; - $sql = 'UPDATE ' . FOOTB_RANKS . " - SET rank_total = $rank_total, - points_total = $points_total, - win_total = $win_total - WHERE season = $season AND league = $league AND matchday = $matchday AND user_id = $curr_userid"; - $result = $db->sql_query($sql); - } - } - } - if ($config['football_bank']) - { - if ($matchday_status < 3) - { - //Delete points - if ($matchday == $league_info['matchdays']) - { - // On last matchday - rollback_points(POINTS_MOST_HITS, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); - rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); - rollback_points(POINTS_SEASON, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); - } - rollback_points(POINTS_MATCHDAY, $season, $league, $matchday, $cash && ($config['football_ult_points'] > 0)); - } - else - { - //Set points on played matchday - if ($matchday == $league_info['matchdays'] AND $config['football_bank']) - { - // On last matchday - set_points_most_hits($season, $league, $matchday, $win_user_most_hits, $cash && ($config['football_ult_points'] == 1)); - set_points_most_hits_away($season, $league, $matchday, $win_user_most_hits_away, $cash && ($config['football_ult_points'] == 1)); - set_points_season($season, $league, $matchday, $season_wins, $cash && ($config['football_ult_points'] == 1)); - } - set_points_matchday($season, $league, $matchday, $ranking_ary, $cash && ($config['football_ult_points'] > 0)); - } - } - $sql = 'SELECT matchday FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league - AND matchday > $matchday"; - $result = $db->sql_query($sql); - if ( $next_matchday = (int) $db->sql_fetchfield('matchday')) - { - $db->sql_freeresult($result); - save_ranking_matchday($season, $league, $next_matchday, $cash); - } - } -} - -function set_points_most_hits($season, $league, $matchday, $win_user_most_hits, $cash) -{ - rollback_points(POINTS_MOST_HITS, $season, $league, $matchday, $cash); - set_footb_points(POINTS_MOST_HITS, $season, $league, $matchday, $win_user_most_hits, $cash); -} - -function set_points_most_hits_away($season, $league, $matchday, $win_user_most_hits_away, $cash) -{ - rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $cash); - set_footb_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $win_user_most_hits_away, $cash); -} - -function set_points_season($season, $league, $matchday, $season_wins, $cash) -{ - rollback_points(POINTS_SEASON, $season, $league, $matchday, $cash); - set_footb_points(POINTS_SEASON, $season, $league, $matchday, $season_wins, $cash); -} - -function set_points_matchday($season, $league, $matchday, $ranking_ary, $cash) -{ - rollback_points(POINTS_MATCHDAY, $season, $league, $matchday, $cash); - set_footb_points(POINTS_MATCHDAY, $season, $league, $matchday, $ranking_ary, $cash); -} - -function rollback_points($points_type, $season, $league, $matchday, $cash) -{ - global $db, $functions_points; - if ($cash) - { - $where_matchday = ($matchday) ? " AND matchday = $matchday" : ''; - $sql = 'SELECT * - FROM ' . FOOTB_POINTS . " AS p - WHERE season = $season - AND league = $league - $where_matchday - AND points_type = $points_type - AND cash = 1"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - $functions_points->substract_points($row['user_id'], $row['points']); - } - $db->sql_freeresult($result); - - } - $sql = 'DELETE FROM ' . FOOTB_POINTS . " WHERE season = $season AND league = $league AND matchday = $matchday AND points_type = $points_type"; - $result = $db->sql_query($sql); -} - -function set_footb_points($points_type, $season, $league, $matchday, $wins, $cash) -{ - global $db, $user, $config, $functions_points; - switch($points_type) - { - case 1: - $points_comment = sprintf($user->lang['BET_POINTS']); - break; - case 2: - $points_comment = sprintf($user->lang['DEPOSIT']); - break; - case 3: - $points_comment = ''; - break; - case 4: - $points_comment = ''; - break; - case 5: - $points_comment = sprintf($user->lang['WIN_HITS']); - break; - case 6: - $points_comment = sprintf($user->lang['WIN_HITS02']); - break; - case 7: - $points_comment = sprintf($user->lang['PAYOUT_WIN']); - break; - } - - foreach( $wins AS $curr_user => $curr_ary) - { - if ($config['football_ult_points'] == 2 AND $points_type == 3) - { - // points mode - - if ($curr_ary['points'] > 0 AND $curr_ary['points'] <> NULL) - { - $userid = (!isset($curr_ary['user_id'])) ? $curr_user : $curr_ary['user_id']; - $points_comment = sprintf($user->lang['POINTS']); - $factor_points = round($config['football_ult_points_factor'] * $curr_ary['points'],2); - if ($cash) - { - $functions_points->add_points($userid, $factor_points); - } - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $matchday, - 'points_type' => (int) $points_type, - 'user_id' => (int) $userid, - 'points' => $factor_points, - 'points_comment'=> $points_comment, - 'cash' => $cash, - ); - $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - if ($config['football_ult_points'] <= 1 OR ($config['football_ult_points'] == 2 AND $points_type == 1)) - { - if ($curr_ary['win'] > 0) - { - switch($points_type) - { - case 3: - $points_comment = sprintf($user->lang['WIN_MATCHDAY']) . ' ' . $curr_ary['rank'] . '.' . sprintf($user->lang['PLACE']); - break; - case 4: - $points_comment = sprintf($user->lang['WIN_SEASON']) . ' ' . $curr_ary['rank'] . '.' . sprintf($user->lang['PLACE']); - break; - } - $userid = (!isset($curr_ary['user_id'])) ? $curr_user : $curr_ary['user_id']; - if ($cash) - { - if ($points_type == 1 OR $points_type == 7) - { - // substract bets and payouts - $functions_points->substract_points($userid, round($curr_ary['win'],2)); - } - else - { - $functions_points->add_points($userid, round($curr_ary['win'],2)); - } - } - $sql_ary = array( - 'season' => (int) $season, - 'league' => (int) $league, - 'matchday' => (int) $matchday, - 'points_type' => (int) $points_type, - 'user_id' => (int) $userid, - 'points' => round($curr_ary['win'],2), - 'points_comment'=> $points_comment, - 'cash' => $cash, - ); - $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - } -} - -function _sort_points($value_a, $value_b) -{ - if ($value_a['points'] > $value_b['points']) - { - return -1; - } - else - { - if ($value_a['points'] == $value_b['points']) - { - if (isset($value_a['nobet'])) - { - if ($value_a['nobet'] < $value_b['nobet']) - { - return -1; - } - else - { - if ($value_a['nobet'] == $value_b['nobet']) - { - return 0; - } - else - { - return 1; - } - } - } - else - { - return 0; - } - } - else - { - return 1; - } - } -} - - -/** -* Return season-array -*/ -function season_info($season) -{ - global $db; - $sql = 'SELECT * FROM ' . FOOTB_SEASONS . " WHERE season = $season"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - return $row; - } - else - { - return array(); - } - $db->sql_freeresult($result); -} - -/** -* Return league-array -*/ -function league_info($season, $league) -{ - global $db; - $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " - WHERE season = $season AND league = $league - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - return $row; - } - else - { - return array(); - } - $db->sql_freeresult($result); -} - -/** -* Return team-array -*/ -function team_info($season, $league, $team_id) -{ - global $db; - $sql = 'SELECT * FROM ' . FOOTB_TEAMS . " - WHERE season = $season AND league = $league AND team_id = $team_id - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - return $row; - } - else - { - return array(); - } - $db->sql_freeresult($result); -} - -/** -* Is user member of this league -*/ -function user_is_member($userid, $season, $league) -{ - global $db; - $sql = 'SELECT COUNT(*) AS counter - FROM ' . FOOTB_BETS . " - WHERE season = $season AND league = $league AND user_id = $userid"; - $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 -*/ -function count_existing_matches($season, $league, $matchday) -{ - global $db; - $where_matchday = ($matchday) ? " AND matchday = $matchday" : ''; - $sql = 'SELECT COUNT(*) AS counter - FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league $where_matchday"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - return $row['counter']; - $db->sql_freeresult($result); - } - else - { - return 0; - } -} - -/** -* Determinate if join to league is allowed -*/ -function join_allowed($season, $league) -{ - global $db; - $league_info = league_info($season, $league); - if (! $league_info['join_by_user']) - { - return false; - } - else - { - if ($league_info['join_in_season']) - { - return true; - } - else - { - $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND matchday = 1 AND status = 0 - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - return true; - } - else - { - return false; - } - } - } -} - -/** -* Calculate status or delivery of matchday -*/ -function delivery($season, $league, $matchday) -{ - global $db, $user; - $delivery = ''; - $lang_dates = $user->lang['datetime']; - $sql = "SELECT *, - CONCAT( - CASE DATE_FORMAT(delivery_date,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(delivery_date,' %d.%m.%Y %H:%i') - ) AS deliverytime - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - switch($row['status']) - { - case 0: - $delivery = '' . sprintf($user->lang['STATUS_TEXT0']) . $row['deliverytime'] . ''; - break; - case 1: - $delivery = '' . sprintf($user->lang['STATUS_TEXT1']) . ''; - break; - case 2: - $delivery = '' . sprintf($user->lang['STATUS_TEXT2']) . ''; - break; - case 3: - $delivery = '' . sprintf($user->lang['STATUS_TEXT3']) . ''; - break; - } - $db->sql_freeresult($result); - } - return $delivery; -} - -/** -* Calculate next delivery und return delivery string -*/ -function next_delivery($season, $league) -{ - global $db, $user; - $next_delivery = ''; - $lang_dates = $user->lang['datetime']; - $sql = "SELECT - CONCAT( - CASE DATE_FORMAT(delivery_date,'%w') - WHEN 0 THEN '" . $lang_dates['Sun'] . "' - WHEN 1 THEN '" . $lang_dates['Mon'] . "' - WHEN 2 THEN '" . $lang_dates['Tue'] . "' - WHEN 3 THEN '" . $lang_dates['Wed'] . "' - WHEN 4 THEN '" . $lang_dates['Thu'] . "' - WHEN 5 THEN '" . $lang_dates['Fri'] . "' - WHEN 6 THEN '" . $lang_dates['Sat'] . "' - ELSE 'Error' END, - DATE_FORMAT(delivery_date,' %d.%m.%Y %H:%i') - ) AS deliverytime - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND status = 0 - ORDER BY matchday ASC - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $next_delivery = "
". sprintf($user->lang['NEXT_DELIVERY_UNTIL']) . ' ' . $row['deliverytime'] . "
"; - $db->sql_freeresult($result); - } - return $next_delivery; -} - -/** -* Calculate first delivery of matchday for bet in time -*/ -function first_delivery($season, $league, $matchday) -{ - global $db, $user; - $sql = "SELECT MIN(match_datetime) AS min_match_datetime - FROM " . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND matchday = $matchday AND status = 0 - ORDER BY min_match_datetime ASC - "; - $result = $db->sql_query($sql); - $first_delivery = ''; - if ($row = $db->sql_fetchrow($result)) - { - $first_delivery = $row['min_match_datetime']; - $db->sql_freeresult($result); - } - return $first_delivery; -} - -/** -* Set matchday delivery to first open match -*/ -function set_bet_in_time_delivery($season, $league) -{ - global $db, $user, $config; - $sql = "SELECT * - FROM " . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND status < 3 - "; - $result = $db->sql_query($sql); - $first_delivery = ''; - while ($row = $db->sql_fetchrow($result)) - { - $new_status = $row['status']; - - // match-status maybe changed - $sql_ary = array( - 'status' => 0, - 'goals_home' => '', - 'goals_guest' => '', - 'goals_overtime_home' => '', - 'goals_overtime_guest' => '', - ); - $local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday =" . $row['matchday'] . " AND match_datetime > FROM_UNIXTIME('$local_board_time')"; - $db->sql_query($sql); - - if ($db->sql_affectedrows()) - { - // an open match exist, so set status 0 - $new_status = 0; - } - $first_delivery = first_delivery($season, $league, $row['matchday']); - if ( $first_delivery <> '') - { - // Matchday has open matches so set matchday status = 0 and first delivery - $sql_ary = array( - 'status' => $new_status, - 'delivery_date' => $first_delivery, - 'delivery_date_2' => '', - 'delivery_date_3' => '', - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday =" . $row['matchday']; - $db->sql_query($sql); - } - } - $db->sql_freeresult($result); -} - - -/** -* return current season. The minimal seasons value with a open matchday (status = 0). -*/ -function curr_season() -{ - global $db, $lang, $user; - $user_spec = ''; - if ($user->data['user_type']==0 OR $user->data['user_type']==3) - { - $curr_user = $user->data['user_id']; - $user_spec = 'AND b.user_id = ' . $curr_user; - } - - $sql = 'SELECT DISTINCT s.season - FROM ' . FOOTB_SEASONS . ' AS s - INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) - INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = s.season AND m.league = l.league) - INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league ' . $user_spec . ') - WHERE m.status IN (0,1,2) - ORDER BY s.season ASC'; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $curr_season = $row['season']; - $db->sql_freeresult($result); - } - else - { - $sql = 'SELECT DISTINCT s.season FROM ' . FOOTB_SEASONS . ' AS s - INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) - INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = s.season AND m.league = l.league) - WHERE 1 - ORDER BY s.season DESC'; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $curr_season = $row['season']; - } - else - { - $sql = 'SELECT * FROM ' . FOOTB_SEASONS; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $curr_season = $row['season']; - } - else - { - $curr_season = 0; - } - } - $db->sql_freeresult($result); - } - return $curr_season; -} - -/** -* return first (minmal) league of season -*/ -function first_league($season, $complete = true) -{ - global $db, $lang; - $join_matchday = ''; - if ($complete) - { - $join_matchday = 'INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = l.season AND m.league = l.league) '; - } - $sql = 'SELECT * - FROM ' . FOOTB_LEAGUES . ' AS l ' . - $join_matchday . " - WHERE l.season = $season - ORDER BY l.league ASC"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $first_league = $row['league']; - } - else - { - $first_league = 0; - } - $db->sql_freeresult($result); - return $first_league; -} - -/** -* return current (wait for results) league of season -*/ -function current_league($season) -{ - global $db, $lang, $user; - $user_spec = ''; - if ($user->data['user_type']==0 OR $user->data['user_type']==3) - { - $curr_user = $user->data['user_id']; - $user_spec = 'AND b.user_id = ' . $curr_user; - } - $sql = 'SELECT m.league - FROM ' . FOOTB_MATCHES . ' AS m - INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league ' . $user_spec . ") - WHERE m.season = $season - AND m.status in (0,1,2) - ORDER BY m.match_datetime ASC"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $current_league = $row['league']; - } - else - { - $current_league = first_league($season); - } - $db->sql_freeresult($result); - return $current_league; -} - -/** -* return next free team-id -*/ -function nextfree_teamid() -{ - global $db, $lang; - $sql = 'SELECT Max(team_id) AS lastid FROM ' . FOOTB_TEAMS; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - return ($row['lastid'] + 1); - } - else - { - return 0; - } - $db->sql_freeresult($result); -} - -/** -* return current (in order to play) matchday of league -*/ -function curr_matchday($season, $league) -{ - global $db, $lang; - $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND status < 3 - ORDER BY status DESC, delivery_date ASC - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $curr_matchday = $row['matchday']; - $db->sql_freeresult($result); - } - else - { - $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " - WHERE season = $season AND league = $league AND status = 3 - ORDER BY matchday DESC - "; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $curr_matchday = $row['matchday']; - } - else - { - $curr_matchday = 0; - } - $db->sql_freeresult($result); - } - return $curr_matchday; -} - - -/** -* Initialize user bets. Adds s user to a league. -*/ -function join_league($season, $league, $user_id) -{ - global $db, $lang; - - $league_info = league_info($season, $league); - $matchdays = $league_info['matchdays']; - if ($league_info['league_type'] == LEAGUE_CHAMP) - { - $matches_on_matchdays = $league_info['matches_on_matchday']; - } - else - { - $matches_on_matchdays = 0; - } - - $count_updates = 0; - $matches = $matches_on_matchdays; - $match_id = 1; - for($m_day = 1; $m_day <= $matchdays; $m_day++) - { - if ($matches_on_matchdays == 0) - { - $sql = 'SELECT matches from ' . FOOTB_MATCHDAYS . " WHERE season = $season AND league = $league AND matchday = $m_day"; - $result = $db->sql_query($sql); - if( $row = $db->sql_fetchrow($result)) - { - $matches = $row['matches']; - $db->sql_freeresult($result); - } - else - { - // Matchday doesnt exist - $matches = 0; - } - } - for($i = 1; $i<= $matches; $i++) - { - $sqlup = 'REPLACE INTO ' . FOOTB_BETS . " VALUES($season, $league, $match_id, $user_id, '', '', 0)"; - $resultup = $db->sql_query($sqlup); - $match_id++; - $count_updates++; - } - } - return $count_updates; -} - -// Close matchday -/** -* Close all open matches. -*/ -function close_open_matchdays() -{ - global $db, $lang, $config; - - $local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); - $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " WHERE status = 0 AND delivery_date < FROM_UNIXTIME('$local_board_time')"; - $result = $db->sql_query($sql); - $toclose = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - foreach ($toclose as $close) - { - // Matchday to close - $season = $close['season']; - $league = $close['league']; - $matchday = $close['matchday']; - $league_info = league_info($season, $league); - - if ($league_info['bet_in_time'] == 1) - { - $sql_ary = array( - 'status' => 1, - ); - $sql = 'UPDATE ' . FOOTB_MATCHES . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday AND status = 0 AND match_datetime < FROM_UNIXTIME('$local_board_time')"; - $db->sql_query($sql); - - // Check remaining open matches - $first_delivery = first_delivery($season, $league, $close['matchday']); - if ($first_delivery <> '') - { - // Matchday has open matches so set matchday status = 0 and first delivery - $sql_ary = array( - 'status' => 0, - 'delivery_date' => first_delivery($season, $league, $close['matchday']), - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - } - else - { - // Matchday has no open match so close the matchday with setting status = 1 - $sql_ary = array( - 'status' => 1, - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - } - } - else - { - if ($close['delivery_date_2'] != '') - { - // More open matches exists, so shift delivery and status lower Null - $sql_ary = array( - 'delivery_date' => $close['delivery_date_2'], - 'delivery_date_2' => $close['delivery_date_3'], - 'delivery_date_3' => '', - ); - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FOOTB_MATCHES . " - SET status = status + 1 - WHERE season = $season AND league = $league AND matchday = $matchday AND status <= 0"; - $db->sql_query($sql); - } - else - { - // Close all matches of the matchday and matchday - $sql = 'UPDATE ' . FOOTB_MATCHDAYS . " - SET status = 1 - WHERE season = $season AND league = $league AND matchday = $matchday"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FOOTB_MATCHES . " - SET status = status + 1 - WHERE season = $season AND league = $league AND matchday = $matchday AND status <= 0"; - $db->sql_query($sql); - } - } - // close extra bets - $sql = 'UPDATE ' . FOOTB_EXTRA . " - SET extra_status = extra_status + 1 - WHERE season = $season AND league = $league AND matchday = $matchday AND extra_status <= 0"; - $db->sql_query($sql); - } -} - -/** -* return matchday wins in array. -*/ -function matchday_wins($season, $league) -{ - global $db, $lang; - $matchday_wins = array(); - - $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - $matchday_wins = explode(';',"0;" . $row['win_matchday']); - $db->sql_freeresult($result); - } - return $matchday_wins; -} - -/** -* return season wins in array. -*/ -function season_wins($season, $league, $matchday) -{ - global $db, $lang; - $season_wins = array(); - $season_user_wins = array(); - $league_info = league_info($season, $league); - if (sizeof($league_info)) - { - $season_wins = explode(';',"0;" . $league_info['win_season']); - $maxmatchday = $league_info['matchdays']; - } - else - { - $season_user_wins[0]['win'] = 0; - return $season_user_wins; - } - - $sql = 'SELECT - 1 AS rank, - user_id, - SUM(points) AS points - FROM ' . FOOTB_RANKS . " - WHERE season = $season - AND league = $league - AND matchday <= $matchday - AND status IN (2,3) - GROUP by user_id - ORDER BY points DESC, user_id ASC - "; - $result = $db->sql_query($sql); - $ranking_ary = array(); - while( $row = $db->sql_fetchrow($result)) - { - $ranking_ary[$row['user_id']] = $row; - } - $db->sql_freeresult($result); - - if ( sizeof($ranking_ary) > 0 ) - { - $sql = 'SELECT - eb.user_id, - SUM(eb.bet_points) AS points - FROM ' . FOOTB_EXTRA . ' AS e - INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) - WHERE e.season = $season - AND e.league = $league - AND e.matchday <> e.matchday_eval - AND e.matchday_eval <= $matchday - AND e.extra_status > 1 - GROUP BY eb.user_id"; - - $result = $db->sql_query($sql); - while( $row = $db->sql_fetchrow($result)) - { - $ranking_ary[$row['user_id']]['points'] += $row['points']; - } - $db->sql_freeresult($result); - // sort the ranking by points - usort($ranking_ary, '_sort_points'); - - $last_points = -1; - $last_rank = 1; - $equal_rank = array(); - $money = array(); - $i = 0; - foreach( $ranking_ary AS $curr_user => $curr_rank) - { - if ( $curr_rank['points'] != $last_points) - { - $ranking_ary[$curr_user]['rank'] = $i + 1; - $last_rank = $i + 1; - $equal_rank[$last_rank] = 1; - $last_points = $curr_rank['points']; - if ($last_rank < sizeof($season_wins)) - { - $money[$last_rank] = $season_wins[$last_rank]; - } - else - { - $money[$last_rank] = 0; - } - } - else - { - $ranking_ary[$curr_user]['rank'] = $last_rank; - $equal_rank[$last_rank] += 1; - if ($i + 1 < sizeof($season_wins)) - { - $money[$last_rank] += $season_wins[$i + 1]; - } - } - $i++; - } - foreach( $ranking_ary AS $curr_rank) - { - if ( round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2) <> 0 ) - { - $season_user_wins[$curr_rank['user_id']]['win'] = round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2); - } - else - { - $season_user_wins[$curr_rank['user_id']]['win'] = 0; - } - $season_user_wins[$curr_rank['user_id']]['rank'] = $curr_rank['rank']; - } - return $season_user_wins; - } - else - { - $season_user_wins[0]['win'] = 0; - return $season_user_wins; - } -} - -/** -* return win most hits in array. -*/ -function win_user_most_hits($season, $league, $matchday) -{ - global $db, $lang; - - $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $win_most_hits = $row['win_result']; - $last_matchday = $row['matchdays']; - $db->sql_freeresult($result); - } - - $sql = 'SELECT - b.user_id AS userid, - COUNT(*) AS hits - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - WHERE m.season = $season AND m.league = $league AND m.matchday <= $matchday AND m.goals_home = b.goals_home AND - m.goals_guest = b.goals_guest AND m.status IN (2,3) - GROUP BY b.user_id - ORDER BY hits DESC - "; - $result = $db->sql_query($sql); - - $last_count_hits = -1; - $count_user = 0; - $userid_ary = array(); - $hits = array(); - $rank = array(); - $equal_rank = array(); - $win_pos_most_hits = array(); - while( $row = $db->sql_fetchrow($result)) - { - $userid_ary[$count_user] = $row['userid']; - $hits[$count_user] = $row['hits']; - if ($count_user == 0) - { - $rank[$count_user] = 1; - $equal_rank[$rank[$count_user]] = 1; - $win_pos_most_hits[$rank[$count_user]] = $win_most_hits; - } - else - { - if ( $row['hits'] != $last_count_hits) - { - $rank[$count_user] = $count_user + 1; - $equal_rank[$rank[$count_user]] = 1; - $win_pos_most_hits[$rank[$count_user]] = 0; - } - else - { - $rank[$count_user] = $rank[$count_user-1]; - $equal_rank[$rank[$count_user]] += 1; - } - } - $last_count_hits = $row['hits']; - $count_user++; - } - $db->sql_freeresult($result); - $win_user_most_hits = array(); - for($i = 0; $i < $count_user; $i++) - { - $win_user_most_hits[$userid_ary[$i]]['direct_hit'] = $hits[$i]; - if ($matchday == $last_matchday) - { - if (round($win_pos_most_hits[$rank[$i]]/$equal_rank[$rank[$i]],2) <> 0) - { - $win_user_most_hits[$userid_ary[$i]]['win'] = round($win_pos_most_hits[$rank[$i]]/$equal_rank[$rank[$i]],2); - } - else - { - $win_user_most_hits[$userid_ary[$i]]['win'] = 0; - } - } - else - { - $win_user_most_hits[$userid_ary[$i]]['win'] = 0; - } - } - if ($count_user > 0) - { - return $win_user_most_hits; - } - else - { - $win_user_most_hits[0]['win'] = 0; - return $win_user_most_hits; - } -} - -/** -* return win most hits away in array. -*/ -function win_user_most_hits_away($season, $league, $matchday) -{ - global $db, $lang; - - $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $win_most_hits_away = $row['win_result_02']; - $last_matchday = $row['matchdays']; - $db->sql_freeresult($result); - } - - $sql = 'SELECT - b.user_id AS userid, - SUM(IF(m.goals_home <= m.goals_guest,1,0)) AS hits_away - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) - WHERE m.season = $season AND m.league = $league AND m.matchday <= $matchday AND m.goals_home = b.goals_home AND - m.goals_guest = b.goals_guest AND m.status IN (2,3) - GROUP BY b.user_id - ORDER BY hits_away DESC - "; - $result = $db->sql_query($sql); - - $last_hits_away = -1; - $count_user = 0; - $userid_ary = array(); - $hits_away = array(); - $rank = array(); - $equal_rank = array(); - $win_pos_most_hits_away = array(); - while( $row = $db->sql_fetchrow($result)) - { - $userid_ary[$count_user] = $row['userid']; - $hits_away[$count_user] = $row['hits_away']; - if ($count_user == 0) - { - $rank[$count_user] = 1; - $equal_rank[$rank[$count_user]] = 1; - $win_pos_most_hits_away[$rank[$count_user]] = $win_most_hits_away; - } - else - { - if ( $row['hits_away'] != $last_hits_away) - { - $rank[$count_user] = $count_user + 1; - $equal_rank[$rank[$count_user]] = 1; - $win_pos_most_hits_away[$rank[$count_user]] = 0; - } - else - { - $rank[$count_user] = $rank[$count_user-1]; - $equal_rank[$rank[$count_user]] += 1; - } - } - $last_hits_away = $row['hits_away']; - $count_user++; - } - $db->sql_freeresult($result); - $win_user_most_hits_away = array(); - for($i = 0; $i < $count_user; $i++) - { - $win_user_most_hits_away[$userid_ary[$i]]['direct_hit'] = $hits_away[$i]; - if ($matchday == $last_matchday) - { - if (round($win_pos_most_hits_away[$rank[$i]]/$equal_rank[$rank[$i]],2) <> 0) - { - $win_user_most_hits_away[$userid_ary[$i]]['win'] = round($win_pos_most_hits_away[$rank[$i]]/$equal_rank[$rank[$i]],2); - } - else - { - $win_user_most_hits_away[$userid_ary[$i]]['win'] = 0; - } - } - else - { - $win_user_most_hits_away[$userid_ary[$i]]['win'] = 0; - } - } - if ($count_user > 0) - { - return $win_user_most_hits_away; - } - else - { - $win_user_most_hits_away[0]['win'] = 0; - return $win_user_most_hits_away; - } -} - -/** -* return colorstyle to status. -*/ -function color_style($status) -{ - switch ($status) - { - case 2: - $colorstyle = 'color_provisionally'; - break; - case 3: - $colorstyle = 'color_finally'; - break; - case 4: - case 5: - case 6: - $colorstyle = 'color_not_rated'; - break; - default: - $colorstyle = ''; - break; - } - return $colorstyle; -} - - -/** -* color text on match status. -*/ -function color_match($text, $status) -{ - switch($status) - { - case 2: - $colormatch = "". $text. ''; - break; - case 3: - $colormatch = "". $text. ''; - break; - case 4: - case 5: - case 6: - $colormatch = "". $text. ''; - break; - default: - $colormatch = $text; - break; - } - return $colormatch; -} - -/** -* color text on points status. -*/ -function color_points($text, $status) -{ - switch($status) - { - case 2: - $color_points = "". $text. ''; - break; - case 3: - $color_points = "". $text. ''; - break; - default: - $color_points = $text; - break; - } - return $color_points; -} - -/** -* get table order on teams with equal points. -*/ -function get_order_team_compare($team_ary, $season, $league, $group, $ranks, $matchday = 999, $first = true) -{ - global $db; - $sql = " - SELECT - t.*, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), - IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) - ) - ) - IF(t.team_id = 20 AND t.season = 2011 AND $matchday > 7, 2, 0) AS points, - SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goals_diff, - SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals - FROM " . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND - (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) - WHERE t.season = $season - AND t.league = $league - AND m.matchday <= $matchday - AND m.status IN (2,3,5,6) - AND m.group_id = '$group' - AND (m.team_id_home='" . implode("' OR m.team_id_home='", $team_ary) . "') - AND (m.team_id_guest='" . implode("' OR m.team_id_guest='", $team_ary) . "') - GROUP BY t.team_id - ORDER BY t.group_id ASC, points DESC, goals_diff DESC, goals DESC"; - - $result = $db->sql_query($sql); - - $tmp = array(); - $rank_ary = array(); - $rank = 0; - $last_points = 0; - $last_goals_diff = 0; - $last_goals = 0; - - while( $row = $db->sql_fetchrow($result)) - { - if ($last_points <> $row['points'] OR $last_goals_diff <> $row['goals_diff'] OR $last_goals <> $row['goals']) - { - $rank++; - } - $rank_ary[$rank][]=$row['team_id']; - $last_points = $row['points']; - $last_goals_diff = $row['goals_diff']; - $last_goals = $row['goals']; - } - foreach($rank_ary as $rank => $teams) - { - if(count($teams) > 1) - { - if ($first) - { - // Compare teams with equal ranks - $teams = get_order_team_compare($teams, $season, $league, $group, $ranks, $matchday, false); - } - else - { - // Second compare is still equal, so look on total rank - $teams = array_intersect($ranks, $teams); - } - } - foreach($teams as $key => $team) - { - $tmp[] = $team; - } - } - return (sizeof($tmp) == 0) ? $team_ary: $tmp; -} - -/** -* determine team items from formula. -*/ -function get_team($season, $league, $matchnumber, $field, $formula) -{ - global $db, $lang, $user; - $first_letter = substr($formula, 0, 1); - $para = substr($formula, 2, 7); - $para_ary = explode(";",$para); - - switch($first_letter) - { - case '3': - // 3. Place Euro 2106 - $groups = substr($para_ary[0], 0, 5); - $sql = ' - SELECT - SUM(1) AS matches, - SUM(IF(m.status = 3, 1, 0)) AS played - FROM ' . FOOTB_MATCHES . " AS m - WHERE m.season = $season AND m.league = $league AND m.group_id <> '' - GROUP BY m.group_id - "; - $result = $db->sql_query($sql); - - if ( $row = $db->sql_fetchrow($result)) - { - if ($row['matches'] == $row['played']) - { - $rank = 0; - // Get table-information - $sql = "SELECT - t.*, - SUM(1) AS matches, - SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 > goals_guest, 1, 0), IF(goals_home + 0 < goals_guest, 1, 0))) AS win, - SUM(IF(goals_home = goals_guest, 1, 0)) AS draw, - SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 < goals_guest, 1, 0), IF(goals_home + 0 > goals_guest, 1, 0))) AS lost, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), - IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) - ) - ) AS points, - SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest , goals_guest - goals_home)) AS goals_diff, - SUM(IF(m.team_id_home = t.team_id, goals_home , goals_guest)) AS goals, - SUM(IF(m.team_id_home = t.team_id, goals_guest , goals_home)) AS goals_against - FROM " . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league - AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) - WHERE t.season = $season - AND t.league = $league - AND m.status IN (2,3,5,6) - GROUP BY t.team_id - ORDER BY t.group_id ASC, points DESC, goals_diff DESC, goals DESC, t.team_name ASC"; - - $result = $db->sql_query($sql); - - $table_ary = array(); - $points_ary = array(); - $ranks_ary = array(); - $third_team = array(); - $third_group = array(); - $points3 = array(); - $diff3 = array(); - $goals3 = array(); - $rank = 0; - while( $row = $db->sql_fetchrow($result)) - { - $rank++; - $table_ary[$row['team_id']] = $row; - $points_ary[$row['group_id']][$row['points']][]=$row['team_id']; - $ranks_ary[] = $row['team_id']; - } - - foreach($points_ary as $group_id => $points) - { - $rank = 0; - - //sort on points descending - krsort($points); - - foreach($points as $point => $teams) - { - if(count($teams) > 1) - { - // Compare teams with equal points - $teams = get_order_team_compare($teams, $season, $league, $group_id, $ranks_ary); - } - foreach($teams as $key => $team) - { - $row = $table_ary[$team]; - $rank++; - if ($rank == 3) - { - $points3[$team] = $row['points']; - $diff3[$team] = $row['goals_diff']; - $goals3[$team] = $row['goals']; - $third_team[$team]= $team; - $third_group[$team]= $row['group_id']; - } - } - } - } - // Sort 3. Place on points, diff, goals - array_multisort($points3, SORT_DESC, $diff3, SORT_DESC, $goals3, SORT_DESC, $third_team, $third_group); - $qualified_groups = array(); - for($i = 0; $i < 4; $i++) - { - $qualified_groups[$i] = $third_group[$i]; - $team_of[$third_group[$i]] = $third_team[$i]; - } - asort($qualified_groups); - $qualified_groups_string = ''; - foreach($qualified_groups as $key => $letter) - { - $qualified_groups_string .= $letter; - } - $modus = array('ABCD' => 'CDAB', 'ABCE' => 'CABE', 'ABCF' => 'CABF', 'ABDE' => 'DABE', 'ABDF' => 'DABF', - 'ABEF' => 'EABF', 'ACDE' => 'CDAE', 'ACDF' => 'CDAF', 'ACEF' => 'CAFE', 'ADEF' => 'DAFE', - 'BCDE' => 'CDBE', 'BCDF' => 'CDBF', 'BCEF' => 'ECBF', 'BDEF' => 'EDBF', 'CDEF' => 'CDFE'); - $form_para = array('CDE', 'ACD', 'ABF', 'BEF'); - $mode = $modus[$qualified_groups_string]; - for($i = 0; $i < 4; $i++) - { - $team = $team_of[substr($mode, $i, 1)]; - - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET team_id_guest = $team WHERE season = $season AND league = $league AND formula_guest = '3 $form_para[$i]'"; - $resultup = $db->sql_query($sqlup); - $sqlup = 'UPDATE ' . FOOTB_TEAMS . ' SET matchday = (SELECT max(matchday) FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND (team_id_home= $team OR team_id_guest = $team)) - WHERE season = $season AND league = $league AND team_id = $team"; - $resultup = $db->sql_query($sqlup); - if ($form_para[$i] == $groups) - { - $team_id = $team; - $row = $table_ary[$team]; - $team_symbol = $row['team_symbol']; - $team_name = $row['team_name']; - $team_name_short = $row['team_name_short']; - } - } - return $team_symbol . '#' . $team_id . '#' . $team_name . '#' . $team_name_short; - - } - else - { - return '#0#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups . '#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups; - } - } - else - { - return '#0#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups . '#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups; - } - break; - case 'D': - // Drawing - return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); - break; - case 'G': - // GROUP - $group = substr($para_ary[0], 0, 1); - $place = substr($para_ary[0], 1, 1); - $sql = ' - SELECT - SUM(1) AS matches, - SUM(IF(m.status = 3, 1, 0)) AS played - FROM ' . FOOTB_MATCHES . " AS m - WHERE m.season = $season AND m.league = $league AND m.group_id = '$group' - GROUP BY m.group_id - "; - $result = $db->sql_query($sql); - - if ( $row = $db->sql_fetchrow($result)) - { - if ($row['matches'] == $row['played']) - { - $rank = 0; - $sql = ' - SELECT - t.*, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), - IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) - ) - ) AS points, - SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goals_diff, - SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals, - SUM(IF(m.team_id_home = t.team_id, goals_guest, goals_home)) AS goals_get - FROM ' . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND - (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) - WHERE t.season = $season AND t.league = $league AND m.group_id = '$group' - GROUP BY t.team_id - ORDER BY points DESC, goals_diff DESC, goals DESC - "; - $result = $db->sql_query($sql); - $table_ary = array(); - $points_ary = array(); - $ranks_ary = array(); - while( $row = $db->sql_fetchrow($result)) - { - $table_ary[$row['team_id']] = $row; - $points_ary[$row['points']][]=$row['team_id']; - $ranks_ary[] = $row['team_id']; - } - $db->sql_freeresult($result); - - //sort on points descending - krsort($points_ary); - - foreach($points_ary as $point => $teams) - { - if(count($teams) > 1) - { - // Compare teams with equal points - $teams = get_order_team_compare($teams, $season, $league, $group, $ranks_ary); - } - foreach($teams as $key => $team) - { - $row = $table_ary[$team]; - $rank++; - if ($rank == $place) - { - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $team WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - $sqlup = 'UPDATE ' . FOOTB_TEAMS . ' SET matchday = (SELECT max(matchday) FROM ' . FOOTB_MATCHES . " - WHERE season = $season AND league = $league AND (team_id_home= $team OR team_id_guest = $team)) - WHERE season = $season AND league = $league AND team_id = $team"; - $resultup = $db->sql_query($sqlup); - return $row['team_symbol'] . '#' . $team . '#' . $row['team_name'] . '#' . $row['team_name_short']; - } - } - } - } - else - { - return '#0#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group . '#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group; - } - } - else - { - return '#0#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group . '#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group; - } - break; - case 'L': - // Looser - switch(sizeof($para_ary)) - { - case 1: - $sql = 'SELECT - m.status, - m.team_id_home AS home_id, - m.team_id_guest AS guest_id, - t1.team_symbol AS home_symbol, - t2.team_symbol AS guest_symbol, - t1.team_name AS home_name, - t2.team_name AS guest_name, - t1.team_name_short AS home_sname, - t2.team_name_short AS guest_sname, - m.goals_overtime_home, - m.goals_overtime_guest, - m.goals_home, - m.goals_guest - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) - WHERE m.season = $season AND m.league = $league AND m.match_no = $para_ary[0]"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - if ((3 == $row['status']) OR (6 == $row['status'])) - { - if ($row['goals_home'] > $row['goals_guest'] OR $row['goals_overtime_home'] > $row['goals_overtime_guest']) - { - $new_id = $row['guest_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $row['guest_symbol'] . '#' . $row['guest_id'] . '#' . $row['guest_name'] . '#' . $row['guest_sname']; - } - if ($row['goals_home'] < $row['goals_guest'] OR $row['goals_overtime_home'] < $row['goals_overtime_guest']) - { - $new_id = $row['home_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $row['home_symbol'] . '#' . $row['home_id'] . '#' . $row['home_name'] . '#' . $row['home_sname']; - } - } - else - { - return '#0#' . sprintf($user->lang['LOOSER_MATCH_NO']) . $para_ary[0] . '#' . sprintf($user->lang['LOOSER']) . ' ' . $para_ary[0]; - } - } - break; - default: - return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); - break; - } - break; - case 'W': - // Winner - switch(sizeof($para_ary)) - { - case 1: - $sql = 'SELECT - m.status, - m.team_id_home AS home_id, - m.team_id_guest AS guest_id, - t1.team_symbol AS home_symbol, - t2.team_symbol AS guest_symbol, - t1.team_name AS home_name, - t2.team_name AS guest_name, - t1.team_name_short AS home_sname, - t2.team_name_short AS guest_sname, - m.goals_overtime_home, - m.goals_overtime_guest, - m.goals_home, - m.goals_guest - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) - WHERE m.season = $season AND m.league = $league AND m.match_no = $para_ary[0]"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - if ((3 == $row['status']) OR (6 == $row['status'])) - { - if ($row['goals_home'] > $row['goals_guest'] OR $row['goals_overtime_home'] > $row['goals_overtime_guest']) - { - $new_id = $row['home_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $row['home_symbol'] . '#' . $row['home_id'] . '#' . $row['home_name'] . '#' . $row['home_sname']; - } - if ($row['goals_home'] < $row['goals_guest'] OR $row['goals_overtime_home'] < $row['goals_overtime_guest']) - { - $new_id = $row['guest_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $row['guest_symbol'] . '#' . $row['guest_id'] . '#' . $row['guest_name'] . '#' . $row['guest_sname']; - } - } - else - { - if ($row['home_sname'] != '' AND $row['guest_sname'] != '') - { - return '#0#' . $row['home_sname'] . ' / ' . $row['guest_sname'] . '#' . $row['home_sname'] . '+' . $row['guest_sname']; - } - else - { - return '#0#' . sprintf($user->lang['WINNER_MATCH_NO']) . $para_ary[0] . '#' . sprintf($user->lang['WINNER']) . ' ' . $para_ary[0]; - } - } - } - break; - case 2: - - $sql = 'SELECT - m.status, - m.team_id_home AS home_id, - m.team_id_guest AS guest_id, - t1.team_symbol AS home_symbol, - t2.team_symbol AS guest_symbol, - t1.team_name AS home_name, - t2.team_name AS guest_name, - t1.team_name_short AS home_sname, - t2.team_name_short AS guest_sname, - m.goals_overtime_home, - m.goals_overtime_guest, - m.goals_home, - m.goals_guest - FROM ' . FOOTB_MATCHES . ' AS m - LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) - LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) - WHERE m.season = $season AND m.league = $league AND (m.match_no = $para_ary[0] OR m.match_no = $para_ary[1]) - ORDER BY m.match_no ASC"; - $result = $db->sql_query($sql); - - if ($firstleg = $db->sql_fetchrow($result)) - { - if ($replay = $db->sql_fetchrow($result)) - { - if (((3 == $firstleg['status']) OR (6 == $firstleg['status'])) AND ((3 == $replay['status']) OR (6 == $replay['status']))) - { - if ($firstleg['home_id'] == $replay['guest_id'] AND $firstleg['guest_id'] == $replay['home_id']) - { - if ($firstleg['goals_home'] + $replay['goals_guest'] > $firstleg['goals_guest'] + $replay['goals_home'] OR $replay['goals_overtime_guest'] > $replay['goals_overtime_home'] OR - ($firstleg['goals_home'] + $replay['goals_guest'] == $firstleg['goals_guest'] + $replay['goals_home'] AND $replay['goals_guest'] > $firstleg['goals_guest'])) - { - $new_id = $firstleg['home_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $firstleg['home_symbol'] . '#' . $firstleg['home_id'] . '#' . $firstleg['home_name'] . '#' . $firstleg['home_sname']; - } - if ($firstleg['goals_home'] + $replay['goals_guest'] < $firstleg['goals_guest'] + $replay['goals_home'] OR $replay['goals_overtime_guest'] < $replay['goals_overtime_home'] OR - ($firstleg['goals_home'] + $replay['goals_guest'] == $firstleg['goals_guest'] + $replay['goals_home'] AND $firstleg['goals_guest'] > $replay['goals_guest'])) - { - $new_id = $firstleg['guest_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $firstleg['guest_symbol'] . '#' . $firstleg['guest_id'] . '#' . $firstleg['guest_name'] . '#' . $firstleg['guest_sname']; - } - } - else if ($firstleg['home_id'] == $replay['home_id'] AND $firstleg['guest_id'] == $replay['guest_id']) - { - if ($firstleg['goals_home'] + $replay['goals_home'] <= $firstleg['goals_guest'] + $replay['goals_guest'] OR $replay['goals_overtime_home'] < $replay['goals_overtime_guest']) - { - $new_id = $firstleg['guest_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $firstleg['guest_symbol'] . '#' . $firstleg['guest_id'] . '#' . $firstleg['guest_name'] . '#' . $firstleg['guest_sname']; - } - else - { - $new_id = $firstleg['home_id']; - $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; - $resultup = $db->sql_query($sqlup); - return $firstleg['home_symbol'] . '#' . $firstleg['home_id'] . '#' . $firstleg['home_name'] . '#' . $firstleg['home_sname']; - } - } - else - { - return '#0#' . sprintf($user->lang['MATCH_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; - } - } - else - { - if ($firstleg['home_sname'] != '' AND $firstleg['guest_sname'] != '') - { - return '#0#' . $firstleg['home_sname'] . ' / ' . $firstleg['guest_sname'] . '#' . $firstleg['home_sname'] . '+' . $firstleg['guest_sname']; - } - else - { - return '#0#' . sprintf($user->lang['WINNER_MATCH_NO']) . ' ' . $para_ary[0] . '+' . $para_ary[1] . '#S. ' . $para_ary[0] . '+' . $para_ary[1]; - } - } - } - else - { - return '#0#' . sprintf($user->lang['SEC_LEG_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; - } - } - else - { - return '#0#' . sprintf($user->lang['FIRSTLEG_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; - } - break; - default: - return '#0#Los#Los'; - break; - } - break; - default: - return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); - break; - } -} - -/** -* KO-matches: Set team to next round. -*/ -function ko_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new) -{ - global $db, $user; - $sql = 'SELECT - t.team_id, - t.team_name, - SUM(1) AS matches, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_home, - goals_home - ), - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_guest, - goals_guest - ) - ) - ) AS goals, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_guest, - goals_guest - ), - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_home, - goals_home - ) - ) - ) AS goals_get, - SUM(IF(m.team_id_home = t.team_id, - 0, - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_guest, - goals_guest - ) - ) - ) AS goals_away, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_overtime_home + goals_overtime_guest > 0, - goals_overtime_guest, - goals_guest - ), - 0 - ) - ) AS goals_away_opp - FROM ' . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id)) - WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status IN (3,6) - GROUP BY t.team_id"; - $result = $db->sql_query($sql); - - $message = sprintf($user->lang['KO_NEXT']) . ':

'; - while ($row = $db->sql_fetchrow($result)) - { - if (($matchday_to == $matchday_from AND $row['matches'] == 1) OR ($matchday_to != 0 AND $row['matches'] == 2)) - { - if (($row['goals'] > $row['goals_get']) OR - (($row['goals'] == $row['goals_get']) AND ($row['goals_away'] > $row['goals_away_opp']))) - { - $team_id = $row['team_id']; - $sqlup = 'UPDATE ' . FOOTB_TEAMS . " SET matchday = $matchday_new WHERE season = $season AND league = $league AND team_id = $team_id"; - $resultup = $db->sql_query($sqlup); - $message .= $row['team_name'] . '
'; - } - } - } - $db->sql_freeresult($result); - - $message .= '
'; - return $message; -} - -/** -* KO-matches: Set groupleaders next round. -*/ -function ko_group_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new, $rank, $move_rank, $move_league, $move_matchday) -{ - global $db, $user; - $sql = ' - SELECT - t.*, - SUM(1) AS matches - FROM ' . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) - WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status NOT IN (3,6) - GROUP BY t.team_id - "; - $result = $db->sql_query($sql); - $rowset = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - if (sizeof($rowset) > 0) - { - $message = sprintf($user->lang['NO_KO_NEXT']); - $messag_moved = ''; - } - else - { - $sql = ' - SELECT - t.*, - SUM(1) AS matches, - SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 > goals_guest, 1, 0), IF(goals_home + 0 < goals_guest, 1, 0))) AS win, - SUM(IF(goals_home = goals_guest, 1, 0)) AS draw, - SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 < goals_guest, 1, 0), IF(goals_home + 0 > goals_guest, 1, 0))) AS lose, - SUM(IF(m.team_id_home = t.team_id, - IF(goals_home + 0 > goals_guest, - 3, - IF(goals_home = goals_guest, - 1, - 0 - ) - ), - IF(goals_home + 0 < goals_guest, - 3, - IF(goals_home = goals_guest, - 1, - 0 - ) - ) - ) - ) AS points, - SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goal_diff, - SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals, - SUM(IF(m.team_id_home = t.team_id, goals_guest, goals_home)) AS goals_get - FROM ' . FOOTB_TEAMS . ' AS t - LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) - WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status IN (3,6) - GROUP BY t.team_id - ORDER BY group_id ASC,points DESC, goal_diff DESC, goals DESC - "; - $result = $db->sql_query($sql); - - $table_ary = array(); - $points_ary = array(); - $ranks_ary = array(); - while( $row = $db->sql_fetchrow($result)) - { - $table_ary[$row['team_id']] = $row; - $points_ary[$row['group_id']][$row['points']][]=$row['team_id']; - $ranks_ary[] = $row['team_id']; - } - - $message = sprintf($user->lang['KO_NEXT_CHECK']) . ':

'; - $message .= sprintf($user->lang['KO_NEXT']) . ':

'; - $messag_moved = '

' . sprintf($user->lang['KO_MOVED']) . ':
'; - $group_id = 'XX'; - foreach($points_ary as $group_id => $points) - { - $place = 1; - foreach($points as $point => $teams) - { - if(count($teams) > 1) - { - // Compare teams with equal points - $teams = get_order_team_compare($teams, $season, $league, $group_id, $ranks_ary); - } - foreach($teams as $key => $team_id) - { - $row = $table_ary[$team_id]; - - if ($place <= $rank) - { - $sqlup = 'UPDATE ' . FOOTB_TEAMS . " SET matchday = $matchday_new WHERE season = $season AND league = $league AND team_id = $team_id"; - $resultup = $db->sql_query($sqlup); - $message .= $row['team_name'] . '
'; - } - if ($move_rank > 0 AND $move_league > 0 AND $place == $move_rank) - { - $team_name = $row['team_name']; - $short_name = $row['team_name_short']; - $team_sign = $row['team_symbol']; - $sqlinsert = 'INSERT INTO ' . FOOTB_TEAMS . " VALUES($season, $move_league, $team_id, '$team_name', '$short_name', '$team_sign', '', $move_matchday)"; - $resultinsert = $db->sql_query($sqlinsert); - $messag_moved .= $row['team_name'] . '
'; - } - $place++; - } - } - } - } - $db->sql_freeresult($result); - - $message .= '

'; - return $message. $messag_moved; -} - -/** -* return SQL statement part to calculate points depending to mode. -*/ -function select_points($creator = 'm', $sum = false) -{ - global $league_info; - - $points_result = $league_info['points_result']; - $points_tendency = $league_info['points_tendency']; - $points_diff = $league_info['points_diff']; - - switch ($league_info['points_mode']) - { - // hit = points_result - // right tendency (not draw) = points_result - difference between bet und result but minimal points_tendency - // right tendency (draw) = points_result - difference between bet goals home und result goals home - case 1: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - IF((b.goals_home = b.goals_guest), - $points_result - ABS(b.goals_home - $creator.goals_home), - IF((($points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest)) < $points_tendency), - $points_tendency, - $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest) - ) - ) - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - // hit = points_result, - // right tendency = points_result - difference between bet und result but minimal points_tendency - case 2: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - IF((b.goals_home = b.goals_guest), - $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest), - IF((($points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest)) < $points_tendency), - $points_tendency, - $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest) - ) - ) - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - // hit = points_result, - // right tendency = points_tendency - case 3: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - $points_tendency - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - // hit = points_result, - // right goal-difference = points_diff, - // right tendency = points_tendency - case 4: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - IF((b.goals_home - b.goals_guest = $creator.goals_home - $creator.goals_guest), - $points_diff, - $points_tendency - ) - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - // hit = points_result, - // right goal-difference (not draw) = points_diff, - // right tendency = points_tendency - case 5: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - IF(((b.goals_home - b.goals_guest = $creator.goals_home - $creator.goals_guest) - AND ($creator.goals_home <> $creator.goals_guest)) , - $points_diff, - $points_tendency - ) - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - // hit = points_result, - // right tendency draw = points_diff, - // right tendency (not draw) = points_tendency - case 6: - $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . - "IF(b.goals_home <> '' AND b.goals_guest <> '', - IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) - OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) - OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), - " .($sum ? '0' : "''") . ", - IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), - $points_result, - IF(((b.goals_home = b.goals_guest) AND ($creator.goals_home = $creator.goals_guest) ) , - $points_diff, - $points_tendency - ) - ) - ), - " .($sum ? '0' : "''") . ' - ), - ' .($sum ? '0' : "''") . " - ) " .($sum ? ')' : '') . 'AS points'; - break; - } - return $select_part; -} + 0 + $where_status"; + $result = $db->sql_query($sql); + + $result_ary = array(); + $extra_points_error = true; + while($row = $db->sql_fetchrow($result)) + { + $extra_no = $row['extra_no']; + if ($row['result'] <> '') + { + switch($row['question_type']) + { + case '2': + case '4': + // multiple results + { + $bet_points = 'CASE bet '; + $result_ary = explode(';', $row['result']); + foreach($result_ary AS $result_value) + { + if ($result_value <> '') + { + $result_value = (is_numeric($result_value)) ? $result_value : "'" . $result_value . "'"; + $bet_points .= ' WHEN ' . $result_value . ' THEN ' . $row['extra_points'] . ' '; + $extra_points_error = false; + } + } + $bet_points .= ' ELSE 0 END'; + } + break; + case '5': + // difference to result + { + if (is_numeric($row['result'])) + { + $bet_points = 'IF(' . $row['extra_points'] . '- ABS(bet - ' . $row['result'] . ') > 0, ' . $row['extra_points'] . '- ABS(bet - ' . $row['result'] . ')' . ', 0)'; + $extra_points_error = false; + } + else + { + $extra_points_error = true; + } + } + break; + default: + // Case 1 and 3 and other + // correct result + { + $result_value = (is_numeric($row['result'])) ? $row['result'] : "'" . $row['result'] . "'"; + $bet_points = 'CASE bet WHEN ' . $result_value . ' THEN ' . $row['extra_points'] . ' ELSE 0 END'; + $extra_points_error = false; + } + break; + } + if (!$extra_points_error) + { + $sql = 'UPDATE ' . FOOTB_EXTRA_BETS . ' + SET bet_points = ' . $bet_points . " + WHERE season = $season + AND league = $league + AND extra_no = $extra_no"; + $db->sql_query($sql); + } + } + } + $db->sql_freeresult($result); +} + + +/** +* Save matchday-ranking in database (table FOOTB_RANKS). +*/ +function save_ranking_matchday($season, $league, $matchday, $cash = false) +{ + global $db, $config, $lang, $league_info; + $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " WHERE season = $season AND league = $league AND matchday = $matchday"; + $result = $db->sql_query($sql); + + if ( $row = $db->sql_fetchrow($result)) + { + $matchday_status = $row['status']; + if ($row['delivery_date_2'] != '' OR ($league_info['bet_in_time'] AND $matchday_status <> 3)) + // We set status to 2 to skip deleting the ranking + $matchday_status = 2; + $db->sql_freeresult($result); + if ($matchday_status < 2) + { + $sql = 'SELECT * FROM ' . FOOTB_MATCHES . " WHERE season = $season AND league = $league AND matchday = $matchday AND status IN (2,3)"; + $result = $db->sql_query($sql); + if ( $row = $db->sql_fetchrow($result)) + { + $matchday_status = 2; + } + } + + if ($matchday_status == 0 OR $matchday_status == 1) + { + // No matches played, so we can delete the ranking + $sql = 'DELETE FROM ' . FOOTB_RANKS . " WHERE season = $season AND league = $league AND matchday = $matchday"; + $result = $db->sql_query($sql); + } + else + { + $matchday_wins = array(); + $matchday_wins = matchday_wins($season, $league); + $sql = " + SELECT + 1 AS rank, + 0.00 AS win, + u.user_id, + u.username AS username, + SUM(IF(m.match_no > 0, 1, 0)) AS matches, + SUM(IF(b.goals_home = '' OR b.goals_guest = '', 1, 0)) AS nobet, + SUM(IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home = m.goals_home) AND (b.goals_guest = m.goals_guest) + , 1 + , 0 + ) + , 0 + ) + ) AS direct_hit, + SUM(IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> (m.goals_home + 0 < m.goals_guest) + OR (b.goals_home = b.goals_guest) <> (m.goals_home = m.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> (m.goals_home + 0 > m.goals_guest) + , 0 + , 1 + ) + , 0 + ) + ) AS tendency, + " . select_points('m',true) . ' + FROM ' . FOOTB_MATCHES . ' AS m + INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + INNER JOIN ' . USERS_TABLE . " AS u ON (b.user_id = u.user_id) + WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday AND m.status IN (2,3) + GROUP BY b.user_id + ORDER BY points DESC, nobet ASC, username ASC + "; + + $result = $db->sql_query($sql); + + $ranking_ary = array(); + while( $row = $db->sql_fetchrow($result)) + { + $ranking_ary[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + if ( sizeof($ranking_ary) > 0 ) + { + $sql = ' + SELECT + eb.user_id, + SUM(eb.bet_points) AS points + FROM ' . FOOTB_EXTRA . ' AS e + INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) + WHERE e.season = $season + AND e.league = $league + AND e.matchday = $matchday + AND e.matchday_eval = $matchday + AND e.extra_status > 1 + GROUP BY eb.user_id"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + $ranking_ary[$row['user_id']]['points'] += $row['points']; + } + $db->sql_freeresult($result); + + // sort the ranking by points + usort($ranking_ary, '_sort_points'); + } + + $last_points = -1; + $last_rank = 1; + $equal_rank = array(); + $money = array(); + $i = 0; + foreach( $ranking_ary AS $curr_user => $curr_rank) + { + if ($curr_rank['nobet'] == $curr_rank['matches'] and $league_info['points_last'] == 1) + { + if ($last_points <> -1) + { + $ranking_ary[$curr_user]['points'] = $last_points; + } + else + { + $ranking_ary[$curr_user]['points'] = 0; + $last_points = 0; + $equal_rank[$last_rank] = 0; + } + } + if ( $ranking_ary[$curr_user]['points'] != $last_points) + { + $ranking_ary[$curr_user]['rank'] = $i + 1; + $last_rank = $i + 1; + $equal_rank[$last_rank] = 1; + if ($last_rank < sizeof($matchday_wins)) + { + $money[$last_rank] = $matchday_wins[$last_rank]; + } + else + { + $money[$last_rank] = 0; + } + $last_points = $ranking_ary[$curr_user]['points']; + } + else + { + $ranking_ary[$curr_user]['rank'] = $last_rank; + $equal_rank[$last_rank] += 1; + if ($i + 1 < sizeof($matchday_wins)) + { + $money[$last_rank] += $matchday_wins[$i + 1]; + } + } + $i++; + } + foreach( $ranking_ary AS $curr_user => $curr_rank) + { + if ( round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2) <> 0 ) + { + $win = round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2); + $ranking_ary[$curr_user]['win'] = $win; + } + else + { + $win = 0; + $ranking_ary[$curr_user]['win'] = 0; + } + $sql = 'REPLACE INTO ' . FOOTB_RANKS . " + VALUES ($season + , $league + , $matchday + , " . $curr_rank['user_id'] . " + , $matchday_status + , " . $curr_rank['rank'] . " + , " . $curr_rank['points'] . " + , $win + , 0 + , " . $curr_rank['tendency'] . " + , " . $curr_rank['direct_hit'] . " + ,0 + ,0 + )"; + $result = $db->sql_query($sql); + } + if ( sizeof($ranking_ary) == 0 ) + { + $sql = 'DELETE FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league + AND matchday = $matchday"; + $result = $db->sql_query($sql); + } + else + { + // Calculate total ranking + $rank_total_ary = array(); + $sql = 'SELECT + user_id , + SUM(points) AS points, + SUM(win) AS wins_total + FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league + AND matchday <= $matchday + GROUP by user_id + ORDER BY points DESC, user_id ASC"; + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + $rank_total_ary[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + + // add extra tipp points total ranking + $league_info = league_info($season, $league); + if ( sizeof($rank_total_ary) > 0 ) + { + if ( $matchday == $league_info['matchdays']) + { + $win_user_most_hits = win_user_most_hits($season, $league, $matchday); + $win_user_most_hits_away = win_user_most_hits_away($season, $league, $matchday); + $season_wins = season_wins($season, $league, $matchday); + } + $sql = 'SELECT + eb.user_id, + SUM(eb.bet_points) AS points + FROM ' . FOOTB_EXTRA . ' AS e + INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) + WHERE e.season = $season + AND e.league = $league + AND e.matchday <> e.matchday_eval + AND e.matchday_eval <= $matchday + AND e.extra_status > 1 + GROUP BY eb.user_id"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + $rank_total_ary[$row['user_id']]['points'] += $row['points']; + } + $db->sql_freeresult($result); + + // sort the ranking by points + usort($rank_total_ary, '_sort_points'); + } + + $index = 0; + $last_rank = 0; + $last_points = -1; + foreach( $rank_total_ary AS $curr_user => $curr_rank) + { + $index++; + if ( $curr_rank['points'] == $last_points) + { + $rank_total = $last_rank; + } + else + { + $rank_total = $index; + $last_points = $curr_rank['points']; + $last_rank = $rank_total; + } + if ($matchday == $league_info['matchdays']) + { + // if someone didn't bet the hole Season + if (!isset($win_user_most_hits[$curr_rank['user_id']]['win'])) + { + $win_user_most_hits[$curr_rank['user_id']]['win'] = 0; + } + if (!isset($win_user_most_hits_away[$curr_rank['user_id']]['win'])) + { + $win_user_most_hits_away[$curr_rank['user_id']]['win'] = 0; + } + if (!isset($season_wins[$curr_rank['user_id']]['win'])) + { + $season_wins[$curr_rank['user_id']]['win'] = 0; + } + $rank_total_ary[$curr_user]['wins_total'] = sprintf('%01.2f',$curr_rank['wins_total'] + $win_user_most_hits[$curr_rank['user_id']]['win'] + $win_user_most_hits_away[$curr_rank['user_id']]['win'] + $season_wins[$curr_rank['user_id']]['win']); + } + else + { + $rank_total_ary[$curr_user]['wins_total'] = sprintf('%01.2f',$curr_rank['wins_total']); + } + $curr_userid = $curr_rank['user_id']; + $points_total = $curr_rank['points']; + $win_total = $rank_total_ary[$curr_user]['wins_total']; + $sql = 'UPDATE ' . FOOTB_RANKS . " + SET rank_total = $rank_total, + points_total = $points_total, + win_total = $win_total + WHERE season = $season AND league = $league AND matchday = $matchday AND user_id = $curr_userid"; + $result = $db->sql_query($sql); + } + } + } + if ($config['football_bank']) + { + if ($matchday_status < 3) + { + //Delete points + if ($matchday == $league_info['matchdays']) + { + // On last matchday + rollback_points(POINTS_MOST_HITS, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); + rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); + rollback_points(POINTS_SEASON, $season, $league, $matchday, $cash && ($config['football_ult_points'] == 1)); + } + rollback_points(POINTS_MATCHDAY, $season, $league, $matchday, $cash && ($config['football_ult_points'] > 0)); + } + else + { + //Set points on played matchday + if ($matchday == $league_info['matchdays'] AND $config['football_bank']) + { + // On last matchday + set_points_most_hits($season, $league, $matchday, $win_user_most_hits, $cash && ($config['football_ult_points'] == 1)); + set_points_most_hits_away($season, $league, $matchday, $win_user_most_hits_away, $cash && ($config['football_ult_points'] == 1)); + set_points_season($season, $league, $matchday, $season_wins, $cash && ($config['football_ult_points'] == 1)); + } + set_points_matchday($season, $league, $matchday, $ranking_ary, $cash && ($config['football_ult_points'] > 0)); + } + } + $sql = 'SELECT matchday FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league + AND matchday > $matchday"; + $result = $db->sql_query($sql); + if ( $next_matchday = (int) $db->sql_fetchfield('matchday')) + { + $db->sql_freeresult($result); + save_ranking_matchday($season, $league, $next_matchday, $cash); + } + } +} + +function set_points_most_hits($season, $league, $matchday, $win_user_most_hits, $cash) +{ + rollback_points(POINTS_MOST_HITS, $season, $league, $matchday, $cash); + set_footb_points(POINTS_MOST_HITS, $season, $league, $matchday, $win_user_most_hits, $cash); +} + +function set_points_most_hits_away($season, $league, $matchday, $win_user_most_hits_away, $cash) +{ + rollback_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $cash); + set_footb_points(POINTS_MOST_HITS_AWAY, $season, $league, $matchday, $win_user_most_hits_away, $cash); +} + +function set_points_season($season, $league, $matchday, $season_wins, $cash) +{ + rollback_points(POINTS_SEASON, $season, $league, $matchday, $cash); + set_footb_points(POINTS_SEASON, $season, $league, $matchday, $season_wins, $cash); +} + +function set_points_matchday($season, $league, $matchday, $ranking_ary, $cash) +{ + rollback_points(POINTS_MATCHDAY, $season, $league, $matchday, $cash); + set_footb_points(POINTS_MATCHDAY, $season, $league, $matchday, $ranking_ary, $cash); +} + +function rollback_points($points_type, $season, $league, $matchday, $cash) +{ + global $db, $functions_points; + if ($cash) + { + $where_matchday = ($matchday) ? " AND matchday = $matchday" : ''; + $sql = 'SELECT * + FROM ' . FOOTB_POINTS . " AS p + WHERE season = $season + AND league = $league + $where_matchday + AND points_type = $points_type + AND cash = 1"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + $functions_points->substract_points($row['user_id'], $row['points']); + } + $db->sql_freeresult($result); + + } + $sql = 'DELETE FROM ' . FOOTB_POINTS . " WHERE season = $season AND league = $league AND matchday = $matchday AND points_type = $points_type"; + $result = $db->sql_query($sql); +} + +function set_footb_points($points_type, $season, $league, $matchday, $wins, $cash) +{ + global $db, $user, $config, $functions_points; + switch($points_type) + { + case 1: + $points_comment = sprintf($user->lang['BET_POINTS']); + break; + case 2: + $points_comment = sprintf($user->lang['DEPOSIT']); + break; + case 3: + $points_comment = ''; + break; + case 4: + $points_comment = ''; + break; + case 5: + $points_comment = sprintf($user->lang['WIN_HITS']); + break; + case 6: + $points_comment = sprintf($user->lang['WIN_HITS02']); + break; + case 7: + $points_comment = sprintf($user->lang['PAYOUT_WIN']); + break; + } + + foreach( $wins AS $curr_user => $curr_ary) + { + if ($config['football_ult_points'] == 2 AND $points_type == 3) + { + // points mode + + if ($curr_ary['points'] > 0 AND $curr_ary['points'] <> NULL) + { + $userid = (!isset($curr_ary['user_id'])) ? $curr_user : $curr_ary['user_id']; + $points_comment = sprintf($user->lang['POINTS']); + $factor_points = round($config['football_ult_points_factor'] * $curr_ary['points'],2); + if ($cash) + { + $functions_points->add_points($userid, $factor_points); + } + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $matchday, + 'points_type' => (int) $points_type, + 'user_id' => (int) $userid, + 'points' => $factor_points, + 'points_comment'=> $points_comment, + 'cash' => $cash, + ); + $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + if ($config['football_ult_points'] <= 1 OR ($config['football_ult_points'] == 2 AND $points_type == 1)) + { + if ($curr_ary['win'] > 0) + { + switch($points_type) + { + case 3: + $points_comment = sprintf($user->lang['WIN_MATCHDAY']) . ' ' . $curr_ary['rank'] . '.' . sprintf($user->lang['PLACE']); + break; + case 4: + $points_comment = sprintf($user->lang['WIN_SEASON']) . ' ' . $curr_ary['rank'] . '.' . sprintf($user->lang['PLACE']); + break; + } + $userid = (!isset($curr_ary['user_id'])) ? $curr_user : $curr_ary['user_id']; + if ($cash) + { + if ($points_type == 1 OR $points_type == 7) + { + // substract bets and payouts + $functions_points->substract_points($userid, round($curr_ary['win'],2)); + } + else + { + $functions_points->add_points($userid, round($curr_ary['win'],2)); + } + } + $sql_ary = array( + 'season' => (int) $season, + 'league' => (int) $league, + 'matchday' => (int) $matchday, + 'points_type' => (int) $points_type, + 'user_id' => (int) $userid, + 'points' => round($curr_ary['win'],2), + 'points_comment'=> $points_comment, + 'cash' => $cash, + ); + $sql = 'INSERT INTO ' . FOOTB_POINTS . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + } +} + +function _sort_points($value_a, $value_b) +{ + if ($value_a['points'] > $value_b['points']) + { + return -1; + } + else + { + if ($value_a['points'] == $value_b['points']) + { + if (isset($value_a['nobet'])) + { + if ($value_a['nobet'] < $value_b['nobet']) + { + return -1; + } + else + { + if ($value_a['nobet'] == $value_b['nobet']) + { + return 0; + } + else + { + return 1; + } + } + } + else + { + return 0; + } + } + else + { + return 1; + } + } +} + + +/** +* Return season-array +*/ +function season_info($season) +{ + global $db; + $sql = 'SELECT * FROM ' . FOOTB_SEASONS . " WHERE season = $season"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + return $row; + } + else + { + return array(); + } + $db->sql_freeresult($result); +} + +/** +* Return league-array +*/ +function league_info($season, $league) +{ + global $db; + $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " + WHERE season = $season AND league = $league + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + return $row; + } + else + { + return array(); + } + $db->sql_freeresult($result); +} + +/** +* Return team-array +*/ +function team_info($season, $league, $team_id) +{ + global $db; + $sql = 'SELECT * FROM ' . FOOTB_TEAMS . " + WHERE season = $season AND league = $league AND team_id = $team_id + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + return $row; + } + else + { + return array(); + } + $db->sql_freeresult($result); +} + +/** +* Is user member of this league +*/ +function user_is_member($userid, $season, $league) +{ + global $db; + $sql = 'SELECT COUNT(*) AS counter + FROM ' . FOOTB_BETS . " + WHERE season = $season AND league = $league AND user_id = $userid"; + $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 +*/ +function count_existing_matches($season, $league, $matchday) +{ + global $db; + $where_matchday = ($matchday) ? " AND matchday = $matchday" : ''; + $sql = 'SELECT COUNT(*) AS counter + FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league $where_matchday"; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + return $row['counter']; + $db->sql_freeresult($result); + } + else + { + return 0; + } +} + +/** +* Determinate if join to league is allowed +*/ +function join_allowed($season, $league) +{ + global $db; + $league_info = league_info($season, $league); + if (! $league_info['join_by_user']) + { + return false; + } + else + { + if ($league_info['join_in_season']) + { + return true; + } + else + { + $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND matchday = 1 AND status = 0 + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $db->sql_freeresult($result); + return true; + } + else + { + return false; + } + } + } +} + +/** +* Calculate status or delivery of matchday +*/ +function delivery($season, $league, $matchday) +{ + global $db, $user; + $delivery = ''; + $lang_dates = $user->lang['datetime']; + $sql = "SELECT *, + CONCAT( + CASE DATE_FORMAT(delivery_date,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(delivery_date,' %d.%m.%Y %H:%i') + ) AS deliverytime + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + switch($row['status']) + { + case 0: + $delivery = '' . sprintf($user->lang['STATUS_TEXT0']) . $row['deliverytime'] . ''; + break; + case 1: + $delivery = '' . sprintf($user->lang['STATUS_TEXT1']) . ''; + break; + case 2: + $delivery = '' . sprintf($user->lang['STATUS_TEXT2']) . ''; + break; + case 3: + $delivery = '' . sprintf($user->lang['STATUS_TEXT3']) . ''; + break; + } + $db->sql_freeresult($result); + } + return $delivery; +} + +/** +* Calculate next delivery und return delivery string +*/ +function next_delivery($season, $league) +{ + global $db, $user; + $next_delivery = ''; + $lang_dates = $user->lang['datetime']; + $sql = "SELECT + CONCAT( + CASE DATE_FORMAT(delivery_date,'%w') + WHEN 0 THEN '" . $lang_dates['Sun'] . "' + WHEN 1 THEN '" . $lang_dates['Mon'] . "' + WHEN 2 THEN '" . $lang_dates['Tue'] . "' + WHEN 3 THEN '" . $lang_dates['Wed'] . "' + WHEN 4 THEN '" . $lang_dates['Thu'] . "' + WHEN 5 THEN '" . $lang_dates['Fri'] . "' + WHEN 6 THEN '" . $lang_dates['Sat'] . "' + ELSE 'Error' END, + DATE_FORMAT(delivery_date,' %d.%m.%Y %H:%i') + ) AS deliverytime + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND status = 0 + ORDER BY matchday ASC + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $next_delivery = "
". sprintf($user->lang['NEXT_DELIVERY_UNTIL']) . ' ' . $row['deliverytime'] . "
"; + $db->sql_freeresult($result); + } + return $next_delivery; +} + +/** +* Calculate first delivery of matchday for bet in time +*/ +function first_delivery($season, $league, $matchday) +{ + global $db, $user; + $sql = "SELECT MIN(match_datetime) AS min_match_datetime + FROM " . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND matchday = $matchday AND status = 0 + ORDER BY min_match_datetime ASC + "; + $result = $db->sql_query($sql); + $first_delivery = ''; + if ($row = $db->sql_fetchrow($result)) + { + $first_delivery = $row['min_match_datetime']; + $db->sql_freeresult($result); + } + return $first_delivery; +} + +/** +* Set matchday delivery to first open match +*/ +function set_bet_in_time_delivery($season, $league) +{ + global $db, $user, $config; + $sql = "SELECT * + FROM " . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND status < 3 + "; + $result = $db->sql_query($sql); + $first_delivery = ''; + while ($row = $db->sql_fetchrow($result)) + { + $new_status = $row['status']; + + // match-status maybe changed + $sql_ary = array( + 'status' => 0, + 'goals_home' => '', + 'goals_guest' => '', + 'goals_overtime_home' => '', + 'goals_overtime_guest' => '', + ); + $local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday =" . $row['matchday'] . " AND match_datetime > FROM_UNIXTIME('$local_board_time')"; + $db->sql_query($sql); + + if ($db->sql_affectedrows()) + { + // an open match exist, so set status 0 + $new_status = 0; + } + $first_delivery = first_delivery($season, $league, $row['matchday']); + if ( $first_delivery <> '') + { + // Matchday has open matches so set matchday status = 0 and first delivery + $sql_ary = array( + 'status' => $new_status, + 'delivery_date' => $first_delivery, + 'delivery_date_2' => '', + 'delivery_date_3' => '', + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday =" . $row['matchday']; + $db->sql_query($sql); + } + } + $db->sql_freeresult($result); +} + + +/** +* return current season. The minimal seasons value with a open matchday (status = 0). +*/ +function curr_season() +{ + global $db, $lang, $user; + $user_spec = ''; + if ($user->data['user_type']==0 OR $user->data['user_type']==3) + { + $curr_user = $user->data['user_id']; + $user_spec = 'AND b.user_id = ' . $curr_user; + } + + $sql = 'SELECT DISTINCT s.season + FROM ' . FOOTB_SEASONS . ' AS s + INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) + INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = s.season AND m.league = l.league) + INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league ' . $user_spec . ') + WHERE m.status IN (0,1,2) + ORDER BY s.season ASC'; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $curr_season = $row['season']; + $db->sql_freeresult($result); + } + else + { + $sql = 'SELECT DISTINCT s.season FROM ' . FOOTB_SEASONS . ' AS s + INNER JOIN ' . FOOTB_LEAGUES . ' AS l ON (l.season = s.season) + INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = s.season AND m.league = l.league) + WHERE 1 + ORDER BY s.season DESC'; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $curr_season = $row['season']; + } + else + { + $sql = 'SELECT * FROM ' . FOOTB_SEASONS; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $curr_season = $row['season']; + } + else + { + $curr_season = 0; + } + } + $db->sql_freeresult($result); + } + return $curr_season; +} + +/** +* return first (minmal) league of season +*/ +function first_league($season, $complete = true) +{ + global $db, $lang; + $join_matchday = ''; + if ($complete) + { + $join_matchday = 'INNER JOIN ' . FOOTB_MATCHDAYS . ' AS m ON (m.season = l.season AND m.league = l.league) '; + } + $sql = 'SELECT * + FROM ' . FOOTB_LEAGUES . ' AS l ' . + $join_matchday . " + WHERE l.season = $season + ORDER BY l.league ASC"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $first_league = $row['league']; + } + else + { + $first_league = 0; + } + $db->sql_freeresult($result); + return $first_league; +} + +/** +* return current (wait for results) league of season +*/ +function current_league($season) +{ + global $db, $lang, $user; + $user_spec = ''; + if ($user->data['user_type']==0 OR $user->data['user_type']==3) + { + $curr_user = $user->data['user_id']; + $user_spec = 'AND b.user_id = ' . $curr_user; + } + $sql = 'SELECT DISTINCT m.league + FROM ' . FOOTB_MATCHES . ' AS m + INNER JOIN ' . FOOTB_BETS . ' AS b ON (b.season = m.season AND b.league = m.league ' . $user_spec . ") + WHERE m.season = $season + AND m.status in (0,1,2) + ORDER BY m.match_datetime ASC + LIMIT 1"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $current_league = $row['league']; + } + else + { + $current_league = first_league($season); + } + $db->sql_freeresult($result); + return $current_league; +} + +/** +* return next free team-id +*/ +function nextfree_teamid() +{ + global $db, $lang; + $sql = 'SELECT Max(team_id) AS lastid FROM ' . FOOTB_TEAMS; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + return ($row['lastid'] + 1); + } + else + { + return 0; + } + $db->sql_freeresult($result); +} + +/** +* return current (in order to play) matchday of league +*/ +function curr_matchday($season, $league) +{ + global $db, $lang; + $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND status < 3 + ORDER BY status DESC, delivery_date ASC + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $curr_matchday = $row['matchday']; + $db->sql_freeresult($result); + } + else + { + $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " + WHERE season = $season AND league = $league AND status = 3 + ORDER BY matchday DESC + "; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $curr_matchday = $row['matchday']; + } + else + { + $curr_matchday = 0; + } + $db->sql_freeresult($result); + } + return $curr_matchday; +} + + +/** +* Initialize user bets. Adds s user to a league. +*/ +function join_league($season, $league, $user_id) +{ + global $db, $lang; + + $league_info = league_info($season, $league); + $matchdays = $league_info['matchdays']; + if ($league_info['league_type'] == LEAGUE_CHAMP) + { + $matches_on_matchdays = $league_info['matches_on_matchday']; + } + else + { + $matches_on_matchdays = 0; + } + + $count_updates = 0; + $matches = $matches_on_matchdays; + $match_id = 1; + for($m_day = 1; $m_day <= $matchdays; $m_day++) + { + if ($matches_on_matchdays == 0) + { + $sql = 'SELECT matches from ' . FOOTB_MATCHDAYS . " WHERE season = $season AND league = $league AND matchday = $m_day"; + $result = $db->sql_query($sql); + if( $row = $db->sql_fetchrow($result)) + { + $matches = $row['matches']; + $db->sql_freeresult($result); + } + else + { + // Matchday doesnt exist + $matches = 0; + } + } + for($i = 1; $i<= $matches; $i++) + { + $sqlup = 'REPLACE INTO ' . FOOTB_BETS . " VALUES($season, $league, $match_id, $user_id, '', '', 0)"; + $resultup = $db->sql_query($sqlup); + $match_id++; + $count_updates++; + } + } + return $count_updates; +} + +// Close matchday +/** +* Close all open matches. +*/ +function close_open_matchdays() +{ + global $db, $lang, $config; + + $local_board_time = time() + (($config['board_timezone'] - $config['football_host_timezone']) * 3600); + $sql = 'SELECT * FROM ' . FOOTB_MATCHDAYS . " WHERE status = 0 AND delivery_date < FROM_UNIXTIME('$local_board_time')"; + $result = $db->sql_query($sql); + $toclose = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + foreach ($toclose as $close) + { + // Matchday to close + $season = $close['season']; + $league = $close['league']; + $matchday = $close['matchday']; + $league_info = league_info($season, $league); + + if ($league_info['bet_in_time'] == 1) + { + $sql_ary = array( + 'status' => 1, + ); + $sql = 'UPDATE ' . FOOTB_MATCHES . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday AND status = 0 AND match_datetime < FROM_UNIXTIME('$local_board_time')"; + $db->sql_query($sql); + + // Check remaining open matches + $first_delivery = first_delivery($season, $league, $close['matchday']); + if ($first_delivery <> '') + { + // Matchday has open matches so set matchday status = 0 and first delivery + $sql_ary = array( + 'status' => 0, + 'delivery_date' => first_delivery($season, $league, $close['matchday']), + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + } + else + { + // Matchday has no open match so close the matchday with setting status = 1 + $sql_ary = array( + 'status' => 1, + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + } + } + else + { + if ($close['delivery_date_2'] != '') + { + // More open matches exists, so shift delivery and status lower Null + $sql_ary = array( + 'delivery_date' => $close['delivery_date_2'], + 'delivery_date_2' => $close['delivery_date_3'], + 'delivery_date_3' => '', + ); + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . FOOTB_MATCHES . " + SET status = status + 1 + WHERE season = $season AND league = $league AND matchday = $matchday AND status <= 0"; + $db->sql_query($sql); + } + else + { + // Close all matches of the matchday and matchday + $sql = 'UPDATE ' . FOOTB_MATCHDAYS . " + SET status = 1 + WHERE season = $season AND league = $league AND matchday = $matchday"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . FOOTB_MATCHES . " + SET status = status + 1 + WHERE season = $season AND league = $league AND matchday = $matchday AND status <= 0"; + $db->sql_query($sql); + } + } + // close extra bets + $sql = 'UPDATE ' . FOOTB_EXTRA . " + SET extra_status = extra_status + 1 + WHERE season = $season AND league = $league AND matchday = $matchday AND extra_status <= 0"; + $db->sql_query($sql); + } +} + +/** +* return matchday wins in array. +*/ +function matchday_wins($season, $league) +{ + global $db, $lang; + $matchday_wins = array(); + + $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + $matchday_wins = explode(';',"0;" . $row['win_matchday']); + $db->sql_freeresult($result); + } + return $matchday_wins; +} + +/** +* return season wins in array. +*/ +function season_wins($season, $league, $matchday) +{ + global $db, $lang; + $season_wins = array(); + $season_user_wins = array(); + $league_info = league_info($season, $league); + if (sizeof($league_info)) + { + $season_wins = explode(';',"0;" . $league_info['win_season']); + $maxmatchday = $league_info['matchdays']; + } + else + { + $season_user_wins[0]['win'] = 0; + return $season_user_wins; + } + + $sql = 'SELECT + 1 AS rank, + user_id, + SUM(points) AS points + FROM ' . FOOTB_RANKS . " + WHERE season = $season + AND league = $league + AND matchday <= $matchday + AND status IN (2,3) + GROUP by user_id + ORDER BY points DESC, user_id ASC + "; + $result = $db->sql_query($sql); + $ranking_ary = array(); + while( $row = $db->sql_fetchrow($result)) + { + $ranking_ary[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + + if ( sizeof($ranking_ary) > 0 ) + { + $sql = 'SELECT + eb.user_id, + SUM(eb.bet_points) AS points + FROM ' . FOOTB_EXTRA . ' AS e + INNER JOIN ' . FOOTB_EXTRA_BETS . " AS eb ON (eb.season = e.season and eb.league = e.league and eb.extra_no = e.extra_no) + WHERE e.season = $season + AND e.league = $league + AND e.matchday <> e.matchday_eval + AND e.matchday_eval <= $matchday + AND e.extra_status > 1 + GROUP BY eb.user_id"; + + $result = $db->sql_query($sql); + while( $row = $db->sql_fetchrow($result)) + { + $ranking_ary[$row['user_id']]['points'] += $row['points']; + } + $db->sql_freeresult($result); + // sort the ranking by points + usort($ranking_ary, '_sort_points'); + + $last_points = -1; + $last_rank = 1; + $equal_rank = array(); + $money = array(); + $i = 0; + foreach( $ranking_ary AS $curr_user => $curr_rank) + { + if ( $curr_rank['points'] != $last_points) + { + $ranking_ary[$curr_user]['rank'] = $i + 1; + $last_rank = $i + 1; + $equal_rank[$last_rank] = 1; + $last_points = $curr_rank['points']; + if ($last_rank < sizeof($season_wins)) + { + $money[$last_rank] = $season_wins[$last_rank]; + } + else + { + $money[$last_rank] = 0; + } + } + else + { + $ranking_ary[$curr_user]['rank'] = $last_rank; + $equal_rank[$last_rank] += 1; + if ($i + 1 < sizeof($season_wins)) + { + $money[$last_rank] += $season_wins[$i + 1]; + } + } + $i++; + } + foreach( $ranking_ary AS $curr_rank) + { + if ( round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2) <> 0 ) + { + $season_user_wins[$curr_rank['user_id']]['win'] = round($money[$curr_rank['rank']] / $equal_rank[$curr_rank['rank']], 2); + } + else + { + $season_user_wins[$curr_rank['user_id']]['win'] = 0; + } + $season_user_wins[$curr_rank['user_id']]['rank'] = $curr_rank['rank']; + } + return $season_user_wins; + } + else + { + $season_user_wins[0]['win'] = 0; + return $season_user_wins; + } +} + +/** +* return win most hits in array. +*/ +function win_user_most_hits($season, $league, $matchday) +{ + global $db, $lang; + + $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $win_most_hits = $row['win_result']; + $last_matchday = $row['matchdays']; + $db->sql_freeresult($result); + } + + $sql = 'SELECT + b.user_id AS userid, + COUNT(*) AS hits + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + WHERE m.season = $season AND m.league = $league AND m.matchday <= $matchday AND m.goals_home = b.goals_home AND + m.goals_guest = b.goals_guest AND m.status IN (2,3) + GROUP BY b.user_id + ORDER BY hits DESC + "; + $result = $db->sql_query($sql); + + $last_count_hits = -1; + $count_user = 0; + $userid_ary = array(); + $hits = array(); + $rank = array(); + $equal_rank = array(); + $win_pos_most_hits = array(); + while( $row = $db->sql_fetchrow($result)) + { + $userid_ary[$count_user] = $row['userid']; + $hits[$count_user] = $row['hits']; + if ($count_user == 0) + { + $rank[$count_user] = 1; + $equal_rank[$rank[$count_user]] = 1; + $win_pos_most_hits[$rank[$count_user]] = $win_most_hits; + } + else + { + if ( $row['hits'] != $last_count_hits) + { + $rank[$count_user] = $count_user + 1; + $equal_rank[$rank[$count_user]] = 1; + $win_pos_most_hits[$rank[$count_user]] = 0; + } + else + { + $rank[$count_user] = $rank[$count_user-1]; + $equal_rank[$rank[$count_user]] += 1; + } + } + $last_count_hits = $row['hits']; + $count_user++; + } + $db->sql_freeresult($result); + $win_user_most_hits = array(); + for($i = 0; $i < $count_user; $i++) + { + $win_user_most_hits[$userid_ary[$i]]['direct_hit'] = $hits[$i]; + if ($matchday == $last_matchday) + { + if (round($win_pos_most_hits[$rank[$i]]/$equal_rank[$rank[$i]],2) <> 0) + { + $win_user_most_hits[$userid_ary[$i]]['win'] = round($win_pos_most_hits[$rank[$i]]/$equal_rank[$rank[$i]],2); + } + else + { + $win_user_most_hits[$userid_ary[$i]]['win'] = 0; + } + } + else + { + $win_user_most_hits[$userid_ary[$i]]['win'] = 0; + } + } + if ($count_user > 0) + { + return $win_user_most_hits; + } + else + { + $win_user_most_hits[0]['win'] = 0; + return $win_user_most_hits; + } +} + +/** +* return win most hits away in array. +*/ +function win_user_most_hits_away($season, $league, $matchday) +{ + global $db, $lang; + + $sql = 'SELECT * FROM ' . FOOTB_LEAGUES . " WHERE season = $season AND league = $league"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $win_most_hits_away = $row['win_result_02']; + $last_matchday = $row['matchdays']; + $db->sql_freeresult($result); + } + + $sql = 'SELECT + b.user_id AS userid, + SUM(IF(m.goals_home <= m.goals_guest,1,0)) AS hits_away + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_BETS . " AS b ON (b.season = m.season AND b.league = m.league AND b.match_no = m.match_no) + WHERE m.season = $season AND m.league = $league AND m.matchday <= $matchday AND m.goals_home = b.goals_home AND + m.goals_guest = b.goals_guest AND m.status IN (2,3) + GROUP BY b.user_id + ORDER BY hits_away DESC + "; + $result = $db->sql_query($sql); + + $last_hits_away = -1; + $count_user = 0; + $userid_ary = array(); + $hits_away = array(); + $rank = array(); + $equal_rank = array(); + $win_pos_most_hits_away = array(); + while( $row = $db->sql_fetchrow($result)) + { + $userid_ary[$count_user] = $row['userid']; + $hits_away[$count_user] = $row['hits_away']; + if ($count_user == 0) + { + $rank[$count_user] = 1; + $equal_rank[$rank[$count_user]] = 1; + $win_pos_most_hits_away[$rank[$count_user]] = $win_most_hits_away; + } + else + { + if ( $row['hits_away'] != $last_hits_away) + { + $rank[$count_user] = $count_user + 1; + $equal_rank[$rank[$count_user]] = 1; + $win_pos_most_hits_away[$rank[$count_user]] = 0; + } + else + { + $rank[$count_user] = $rank[$count_user-1]; + $equal_rank[$rank[$count_user]] += 1; + } + } + $last_hits_away = $row['hits_away']; + $count_user++; + } + $db->sql_freeresult($result); + $win_user_most_hits_away = array(); + for($i = 0; $i < $count_user; $i++) + { + $win_user_most_hits_away[$userid_ary[$i]]['direct_hit'] = $hits_away[$i]; + if ($matchday == $last_matchday) + { + if (round($win_pos_most_hits_away[$rank[$i]]/$equal_rank[$rank[$i]],2) <> 0) + { + $win_user_most_hits_away[$userid_ary[$i]]['win'] = round($win_pos_most_hits_away[$rank[$i]]/$equal_rank[$rank[$i]],2); + } + else + { + $win_user_most_hits_away[$userid_ary[$i]]['win'] = 0; + } + } + else + { + $win_user_most_hits_away[$userid_ary[$i]]['win'] = 0; + } + } + if ($count_user > 0) + { + return $win_user_most_hits_away; + } + else + { + $win_user_most_hits_away[0]['win'] = 0; + return $win_user_most_hits_away; + } +} + +/** +* return colorstyle to status. +*/ +function color_style($status) +{ + switch ($status) + { + case 2: + $colorstyle = 'color_provisionally'; + break; + case 3: + $colorstyle = 'color_finally'; + break; + case 4: + case 5: + case 6: + $colorstyle = 'color_not_rated'; + break; + default: + $colorstyle = ''; + break; + } + return $colorstyle; +} + + +/** +* color text on match status. +*/ +function color_match($text, $status) +{ + switch($status) + { + case 2: + $colormatch = "". $text. ''; + break; + case 3: + $colormatch = "". $text. ''; + break; + case 4: + case 5: + case 6: + $colormatch = "". $text. ''; + break; + default: + $colormatch = $text; + break; + } + return $colormatch; +} + +/** +* color text on points status. +*/ +function color_points($text, $status) +{ + switch($status) + { + case 2: + $color_points = "". $text. ''; + break; + case 3: + $color_points = "". $text. ''; + break; + default: + $color_points = $text; + break; + } + return $color_points; +} + +/** +* get table order on teams with equal points. +*/ +function get_order_team_compare($team_ary, $season, $league, $group, $ranks, $matchday = 999, $first = true) +{ + global $db; + $sql = " + SELECT + t.*, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), + IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) + ) + ) - IF(t.team_id = 20 AND t.season = 2011 AND $matchday > 7, 2, 0) AS points, + SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goals_diff, + SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals + FROM " . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND + (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) + WHERE t.season = $season + AND t.league = $league + AND m.matchday <= $matchday + AND m.status IN (2,3,5,6) + AND m.group_id = '$group' + AND (m.team_id_home='" . implode("' OR m.team_id_home='", $team_ary) . "') + AND (m.team_id_guest='" . implode("' OR m.team_id_guest='", $team_ary) . "') + GROUP BY t.team_id + ORDER BY t.group_id ASC, points DESC, goals_diff DESC, goals DESC"; + + $result = $db->sql_query($sql); + + $tmp = array(); + $rank_ary = array(); + $rank = 0; + $last_points = 0; + $last_goals_diff = 0; + $last_goals = 0; + + while( $row = $db->sql_fetchrow($result)) + { + if ($last_points <> $row['points'] OR $last_goals_diff <> $row['goals_diff'] OR $last_goals <> $row['goals']) + { + $rank++; + } + $rank_ary[$rank][]=$row['team_id']; + $last_points = $row['points']; + $last_goals_diff = $row['goals_diff']; + $last_goals = $row['goals']; + } + foreach($rank_ary as $rank => $teams) + { + if(count($teams) > 1) + { + if ($first) + { + // Compare teams with equal ranks + $teams = get_order_team_compare($teams, $season, $league, $group, $ranks, $matchday, false); + } + else + { + // Second compare is still equal, so look on total rank + $teams = array_intersect($ranks, $teams); + } + } + foreach($teams as $key => $team) + { + $tmp[] = $team; + } + } + return (sizeof($tmp) == 0) ? $team_ary: $tmp; +} + +/** +* determine team items from formula. +*/ +function get_team($season, $league, $matchnumber, $field, $formula) +{ + global $db, $lang, $user; + $first_letter = substr($formula, 0, 1); + $para = substr($formula, 2, 7); + $para_ary = explode(";",$para); + + switch($first_letter) + { + case '3': + // 3. Place Euro 2106 + $groups = substr($para_ary[0], 0, 5); + $sql = ' + SELECT + SUM(1) AS matches, + SUM(IF(m.status = 3, 1, 0)) AS played + FROM ' . FOOTB_MATCHES . " AS m + WHERE m.season = $season AND m.league = $league AND m.group_id <> '' + GROUP BY m.group_id + "; + $result = $db->sql_query($sql); + + if ( $row = $db->sql_fetchrow($result)) + { + if ($row['matches'] == $row['played']) + { + $rank = 0; + // Get table-information + $sql = "SELECT + t.*, + SUM(1) AS matches, + SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 > goals_guest, 1, 0), IF(goals_home + 0 < goals_guest, 1, 0))) AS win, + SUM(IF(goals_home = goals_guest, 1, 0)) AS draw, + SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 < goals_guest, 1, 0), IF(goals_home + 0 > goals_guest, 1, 0))) AS lost, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), + IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) + ) + ) AS points, + SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest , goals_guest - goals_home)) AS goals_diff, + SUM(IF(m.team_id_home = t.team_id, goals_home , goals_guest)) AS goals, + SUM(IF(m.team_id_home = t.team_id, goals_guest , goals_home)) AS goals_against + FROM " . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league + AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) + WHERE t.season = $season + AND t.league = $league + AND m.status IN (2,3,5,6) + GROUP BY t.team_id + ORDER BY t.group_id ASC, points DESC, goals_diff DESC, goals DESC, t.team_name ASC"; + + $result = $db->sql_query($sql); + + $table_ary = array(); + $points_ary = array(); + $ranks_ary = array(); + $third_team = array(); + $third_group = array(); + $points3 = array(); + $diff3 = array(); + $goals3 = array(); + $rank = 0; + while( $row = $db->sql_fetchrow($result)) + { + $rank++; + $table_ary[$row['team_id']] = $row; + $points_ary[$row['group_id']][$row['points']][]=$row['team_id']; + $ranks_ary[] = $row['team_id']; + } + + foreach($points_ary as $group_id => $points) + { + $rank = 0; + + //sort on points descending + krsort($points); + + foreach($points as $point => $teams) + { + if(count($teams) > 1) + { + // Compare teams with equal points + $teams = get_order_team_compare($teams, $season, $league, $group_id, $ranks_ary); + } + foreach($teams as $key => $team) + { + $row = $table_ary[$team]; + $rank++; + if ($rank == 3) + { + $points3[$team] = $row['points']; + $diff3[$team] = $row['goals_diff']; + $goals3[$team] = $row['goals']; + $third_team[$team]= $team; + $third_group[$team]= $row['group_id']; + } + } + } + } + // Sort 3. Place on points, diff, goals + array_multisort($points3, SORT_DESC, $diff3, SORT_DESC, $goals3, SORT_DESC, $third_team, $third_group); + $qualified_groups = array(); + for($i = 0; $i < 4; $i++) + { + $qualified_groups[$i] = $third_group[$i]; + $team_of[$third_group[$i]] = $third_team[$i]; + } + asort($qualified_groups); + $qualified_groups_string = ''; + foreach($qualified_groups as $key => $letter) + { + $qualified_groups_string .= $letter; + } + $modus = array('ABCD' => 'CDAB', 'ABCE' => 'CABE', 'ABCF' => 'CABF', 'ABDE' => 'DABE', 'ABDF' => 'DABF', + 'ABEF' => 'EABF', 'ACDE' => 'CDAE', 'ACDF' => 'CDAF', 'ACEF' => 'CAFE', 'ADEF' => 'DAFE', + 'BCDE' => 'CDBE', 'BCDF' => 'CDBF', 'BCEF' => 'ECBF', 'BDEF' => 'EDBF', 'CDEF' => 'CDFE'); + $form_para = array('CDE', 'ACD', 'ABF', 'BEF'); + $mode = $modus[$qualified_groups_string]; + for($i = 0; $i < 4; $i++) + { + $team = $team_of[substr($mode, $i, 1)]; + + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET team_id_guest = $team WHERE season = $season AND league = $league AND formula_guest = '3 $form_para[$i]'"; + $resultup = $db->sql_query($sqlup); + $sqlup = 'UPDATE ' . FOOTB_TEAMS . ' SET matchday = (SELECT max(matchday) FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND (team_id_home= $team OR team_id_guest = $team)) + WHERE season = $season AND league = $league AND team_id = $team"; + $resultup = $db->sql_query($sqlup); + if ($form_para[$i] == $groups) + { + $team_id = $team; + $row = $table_ary[$team]; + $team_symbol = $row['team_symbol']; + $team_name = $row['team_name']; + $team_name_short = $row['team_name_short']; + } + } + return $team_symbol . '#' . $team_id . '#' . $team_name . '#' . $team_name_short; + + } + else + { + return '#0#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups . '#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups; + } + } + else + { + return '#0#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups . '#' . '3. ' . sprintf($user->lang['GROUP']) . ' ' . $groups; + } + break; + case 'D': + // Drawing + return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); + break; + case 'G': + // GROUP + $group = substr($para_ary[0], 0, 1); + $place = substr($para_ary[0], 1, 1); + $sql = ' + SELECT + SUM(1) AS matches, + SUM(IF(m.status = 3, 1, 0)) AS played + FROM ' . FOOTB_MATCHES . " AS m + WHERE m.season = $season AND m.league = $league AND m.group_id = '$group' + GROUP BY m.group_id + "; + $result = $db->sql_query($sql); + + if ( $row = $db->sql_fetchrow($result)) + { + if ($row['matches'] == $row['played']) + { + $rank = 0; + $sql = ' + SELECT + t.*, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)), + IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0)) + ) + ) AS points, + SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goals_diff, + SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals, + SUM(IF(m.team_id_home = t.team_id, goals_guest, goals_home)) AS goals_get + FROM ' . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND + (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) + WHERE t.season = $season AND t.league = $league AND m.group_id = '$group' + GROUP BY t.team_id + ORDER BY points DESC, goals_diff DESC, goals DESC + "; + $result = $db->sql_query($sql); + $table_ary = array(); + $points_ary = array(); + $ranks_ary = array(); + while( $row = $db->sql_fetchrow($result)) + { + $table_ary[$row['team_id']] = $row; + $points_ary[$row['points']][]=$row['team_id']; + $ranks_ary[] = $row['team_id']; + } + $db->sql_freeresult($result); + + //sort on points descending + krsort($points_ary); + + foreach($points_ary as $point => $teams) + { + if(count($teams) > 1) + { + // Compare teams with equal points + $teams = get_order_team_compare($teams, $season, $league, $group, $ranks_ary); + } + foreach($teams as $key => $team) + { + $row = $table_ary[$team]; + $rank++; + if ($rank == $place) + { + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $team WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + $sqlup = 'UPDATE ' . FOOTB_TEAMS . ' SET matchday = (SELECT max(matchday) FROM ' . FOOTB_MATCHES . " + WHERE season = $season AND league = $league AND (team_id_home= $team OR team_id_guest = $team)) + WHERE season = $season AND league = $league AND team_id = $team"; + $resultup = $db->sql_query($sqlup); + return $row['team_symbol'] . '#' . $team . '#' . $row['team_name'] . '#' . $row['team_name_short']; + } + } + } + } + else + { + return '#0#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group . '#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group; + } + } + else + { + return '#0#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group . '#' . $place . '. ' . sprintf($user->lang['GROUP']) . ' ' . $group; + } + break; + case 'L': + // Looser + switch(sizeof($para_ary)) + { + case 1: + $sql = 'SELECT + m.status, + m.team_id_home AS home_id, + m.team_id_guest AS guest_id, + t1.team_symbol AS home_symbol, + t2.team_symbol AS guest_symbol, + t1.team_name AS home_name, + t2.team_name AS guest_name, + t1.team_name_short AS home_sname, + t2.team_name_short AS guest_sname, + m.goals_overtime_home, + m.goals_overtime_guest, + m.goals_home, + m.goals_guest + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) + WHERE m.season = $season AND m.league = $league AND m.match_no = $para_ary[0]"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + if ((3 == $row['status']) OR (6 == $row['status'])) + { + if ($row['goals_home'] > $row['goals_guest'] OR $row['goals_overtime_home'] > $row['goals_overtime_guest']) + { + $new_id = $row['guest_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $row['guest_symbol'] . '#' . $row['guest_id'] . '#' . $row['guest_name'] . '#' . $row['guest_sname']; + } + if ($row['goals_home'] < $row['goals_guest'] OR $row['goals_overtime_home'] < $row['goals_overtime_guest']) + { + $new_id = $row['home_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $row['home_symbol'] . '#' . $row['home_id'] . '#' . $row['home_name'] . '#' . $row['home_sname']; + } + } + else + { + return '#0#' . sprintf($user->lang['LOOSER_MATCH_NO']) . $para_ary[0] . '#' . sprintf($user->lang['LOOSER']) . ' ' . $para_ary[0]; + } + } + break; + default: + return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); + break; + } + break; + case 'W': + // Winner + switch(sizeof($para_ary)) + { + case 1: + $sql = 'SELECT + m.status, + m.team_id_home AS home_id, + m.team_id_guest AS guest_id, + t1.team_symbol AS home_symbol, + t2.team_symbol AS guest_symbol, + t1.team_name AS home_name, + t2.team_name AS guest_name, + t1.team_name_short AS home_sname, + t2.team_name_short AS guest_sname, + m.goals_overtime_home, + m.goals_overtime_guest, + m.goals_home, + m.goals_guest + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) + WHERE m.season = $season AND m.league = $league AND m.match_no = $para_ary[0]"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + if ((3 == $row['status']) OR (6 == $row['status'])) + { + if ($row['goals_home'] > $row['goals_guest'] OR $row['goals_overtime_home'] > $row['goals_overtime_guest']) + { + $new_id = $row['home_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $row['home_symbol'] . '#' . $row['home_id'] . '#' . $row['home_name'] . '#' . $row['home_sname']; + } + if ($row['goals_home'] < $row['goals_guest'] OR $row['goals_overtime_home'] < $row['goals_overtime_guest']) + { + $new_id = $row['guest_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $row['guest_symbol'] . '#' . $row['guest_id'] . '#' . $row['guest_name'] . '#' . $row['guest_sname']; + } + } + else + { + if ($row['home_sname'] != '' AND $row['guest_sname'] != '') + { + return '#0#' . $row['home_sname'] . ' / ' . $row['guest_sname'] . '#' . $row['home_sname'] . '+' . $row['guest_sname']; + } + else + { + return '#0#' . sprintf($user->lang['WINNER_MATCH_NO']) . $para_ary[0] . '#' . sprintf($user->lang['WINNER']) . ' ' . $para_ary[0]; + } + } + } + break; + case 2: + + $sql = 'SELECT + m.status, + m.team_id_home AS home_id, + m.team_id_guest AS guest_id, + t1.team_symbol AS home_symbol, + t2.team_symbol AS guest_symbol, + t1.team_name AS home_name, + t2.team_name AS guest_name, + t1.team_name_short AS home_sname, + t2.team_name_short AS guest_sname, + m.goals_overtime_home, + m.goals_overtime_guest, + m.goals_home, + m.goals_guest + FROM ' . FOOTB_MATCHES . ' AS m + LEFT JOIN ' . FOOTB_TEAMS . ' AS t1 ON (t1.season = m.season AND t1.league = m.league AND t1.team_id = m.team_id_home) + LEFT JOIN ' . FOOTB_TEAMS . " AS t2 ON (t2.season = m.season AND t2.league = m.league AND t2.team_id = m.team_id_guest) + WHERE m.season = $season AND m.league = $league AND (m.match_no = $para_ary[0] OR m.match_no = $para_ary[1]) + ORDER BY m.match_no ASC"; + $result = $db->sql_query($sql); + + if ($firstleg = $db->sql_fetchrow($result)) + { + if ($replay = $db->sql_fetchrow($result)) + { + if (((3 == $firstleg['status']) OR (6 == $firstleg['status'])) AND ((3 == $replay['status']) OR (6 == $replay['status']))) + { + if ($firstleg['home_id'] == $replay['guest_id'] AND $firstleg['guest_id'] == $replay['home_id']) + { + if ($firstleg['goals_home'] + $replay['goals_guest'] > $firstleg['goals_guest'] + $replay['goals_home'] OR $replay['goals_overtime_guest'] > $replay['goals_overtime_home'] OR + ($firstleg['goals_home'] + $replay['goals_guest'] == $firstleg['goals_guest'] + $replay['goals_home'] AND $replay['goals_guest'] > $firstleg['goals_guest'])) + { + $new_id = $firstleg['home_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $firstleg['home_symbol'] . '#' . $firstleg['home_id'] . '#' . $firstleg['home_name'] . '#' . $firstleg['home_sname']; + } + if ($firstleg['goals_home'] + $replay['goals_guest'] < $firstleg['goals_guest'] + $replay['goals_home'] OR $replay['goals_overtime_guest'] < $replay['goals_overtime_home'] OR + ($firstleg['goals_home'] + $replay['goals_guest'] == $firstleg['goals_guest'] + $replay['goals_home'] AND $firstleg['goals_guest'] > $replay['goals_guest'])) + { + $new_id = $firstleg['guest_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $firstleg['guest_symbol'] . '#' . $firstleg['guest_id'] . '#' . $firstleg['guest_name'] . '#' . $firstleg['guest_sname']; + } + } + else if ($firstleg['home_id'] == $replay['home_id'] AND $firstleg['guest_id'] == $replay['guest_id']) + { + if ($firstleg['goals_home'] + $replay['goals_home'] <= $firstleg['goals_guest'] + $replay['goals_guest'] OR $replay['goals_overtime_home'] < $replay['goals_overtime_guest']) + { + $new_id = $firstleg['guest_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $firstleg['guest_symbol'] . '#' . $firstleg['guest_id'] . '#' . $firstleg['guest_name'] . '#' . $firstleg['guest_sname']; + } + else + { + $new_id = $firstleg['home_id']; + $sqlup = 'UPDATE ' . FOOTB_MATCHES . " SET $field = $new_id WHERE season = $season AND league = $league AND match_no = $matchnumber"; + $resultup = $db->sql_query($sqlup); + return $firstleg['home_symbol'] . '#' . $firstleg['home_id'] . '#' . $firstleg['home_name'] . '#' . $firstleg['home_sname']; + } + } + else + { + return '#0#' . sprintf($user->lang['MATCH_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; + } + } + else + { + if ($firstleg['home_sname'] != '' AND $firstleg['guest_sname'] != '') + { + return '#0#' . $firstleg['home_sname'] . ' / ' . $firstleg['guest_sname'] . '#' . $firstleg['home_sname'] . '+' . $firstleg['guest_sname']; + } + else + { + return '#0#' . sprintf($user->lang['WINNER_MATCH_NO']) . ' ' . $para_ary[0] . '+' . $para_ary[1] . '#S. ' . $para_ary[0] . '+' . $para_ary[1]; + } + } + } + else + { + return '#0#' . sprintf($user->lang['SEC_LEG_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; + } + } + else + { + return '#0#' . sprintf($user->lang['FIRSTLEG_ERROR']) . '#' . sprintf($user->lang['FORMULA']) . '!'; + } + break; + default: + return '#0#Los#Los'; + break; + } + break; + default: + return '#0#' . sprintf($user->lang['DRAWING']) . '#' . sprintf($user->lang['DRAWING']); + break; + } +} + +/** +* KO-matches: Set team to next round. +*/ +function ko_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new) +{ + global $db, $user; + $sql = 'SELECT + t.team_id, + t.team_name, + SUM(1) AS matches, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_home, + goals_home + ), + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_guest, + goals_guest + ) + ) + ) AS goals, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_guest, + goals_guest + ), + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_home, + goals_home + ) + ) + ) AS goals_get, + SUM(IF(m.team_id_home = t.team_id, + 0, + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_guest, + goals_guest + ) + ) + ) AS goals_away, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_overtime_home + goals_overtime_guest > 0, + goals_overtime_guest, + goals_guest + ), + 0 + ) + ) AS goals_away_opp + FROM ' . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id)) + WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status IN (3,6) + GROUP BY t.team_id"; + $result = $db->sql_query($sql); + + $message = sprintf($user->lang['KO_NEXT']) . ':

'; + while ($row = $db->sql_fetchrow($result)) + { + if (($matchday_to == $matchday_from AND $row['matches'] == 1) OR ($matchday_to != 0 AND $row['matches'] == 2)) + { + if (($row['goals'] > $row['goals_get']) OR + (($row['goals'] == $row['goals_get']) AND ($row['goals_away'] > $row['goals_away_opp']))) + { + $team_id = $row['team_id']; + $sqlup = 'UPDATE ' . FOOTB_TEAMS . " SET matchday = $matchday_new WHERE season = $season AND league = $league AND team_id = $team_id"; + $resultup = $db->sql_query($sqlup); + $message .= $row['team_name'] . '
'; + } + } + } + $db->sql_freeresult($result); + + $message .= '
'; + return $message; +} + +/** +* KO-matches: Set groupleaders next round. +*/ +function ko_group_next_round($season, $league, $matchday_from, $matchday_to, $matchday_new, $rank, $move_rank, $move_league, $move_matchday) +{ + global $db, $user; + $sql = ' + SELECT + t.*, + SUM(1) AS matches + FROM ' . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) + WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status NOT IN (3,6) + GROUP BY t.team_id + "; + $result = $db->sql_query($sql); + $rowset = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + if (sizeof($rowset) > 0) + { + $message = sprintf($user->lang['NO_KO_NEXT']); + $messag_moved = ''; + } + else + { + $sql = ' + SELECT + t.*, + SUM(1) AS matches, + SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 > goals_guest, 1, 0), IF(goals_home + 0 < goals_guest, 1, 0))) AS win, + SUM(IF(goals_home = goals_guest, 1, 0)) AS draw, + SUM(IF((m.team_id_home = t.team_id), IF(goals_home + 0 < goals_guest, 1, 0), IF(goals_home + 0 > goals_guest, 1, 0))) AS lose, + SUM(IF(m.team_id_home = t.team_id, + IF(goals_home + 0 > goals_guest, + 3, + IF(goals_home = goals_guest, + 1, + 0 + ) + ), + IF(goals_home + 0 < goals_guest, + 3, + IF(goals_home = goals_guest, + 1, + 0 + ) + ) + ) + ) AS points, + SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest, goals_guest - goals_home)) AS goal_diff, + SUM(IF(m.team_id_home = t.team_id, goals_home, goals_guest)) AS goals, + SUM(IF(m.team_id_home = t.team_id, goals_guest, goals_home)) AS goals_get + FROM ' . FOOTB_TEAMS . ' AS t + LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id) + WHERE t.season = $season AND t.league = $league AND m.matchday >= $matchday_from AND m.matchday <= $matchday_to AND m.status IN (3,6) + GROUP BY t.team_id + ORDER BY group_id ASC,points DESC, goal_diff DESC, goals DESC + "; + $result = $db->sql_query($sql); + + $table_ary = array(); + $points_ary = array(); + $ranks_ary = array(); + while( $row = $db->sql_fetchrow($result)) + { + $table_ary[$row['team_id']] = $row; + $points_ary[$row['group_id']][$row['points']][]=$row['team_id']; + $ranks_ary[] = $row['team_id']; + } + + $message = sprintf($user->lang['KO_NEXT_CHECK']) . ':

'; + $message .= sprintf($user->lang['KO_NEXT']) . ':

'; + $messag_moved = '

' . sprintf($user->lang['KO_MOVED']) . ':
'; + $group_id = 'XX'; + foreach($points_ary as $group_id => $points) + { + $place = 1; + foreach($points as $point => $teams) + { + if(count($teams) > 1) + { + // Compare teams with equal points + $teams = get_order_team_compare($teams, $season, $league, $group_id, $ranks_ary); + } + foreach($teams as $key => $team_id) + { + $row = $table_ary[$team_id]; + + if ($place <= $rank) + { + $sqlup = 'UPDATE ' . FOOTB_TEAMS . " SET matchday = $matchday_new WHERE season = $season AND league = $league AND team_id = $team_id"; + $resultup = $db->sql_query($sqlup); + $message .= $row['team_name'] . '
'; + } + if ($move_rank > 0 AND $move_league > 0 AND $place == $move_rank) + { + $team_name = $row['team_name']; + $short_name = $row['team_name_short']; + $team_sign = $row['team_symbol']; + $sqlinsert = 'INSERT INTO ' . FOOTB_TEAMS . " VALUES($season, $move_league, $team_id, '$team_name', '$short_name', '$team_sign', '', $move_matchday)"; + $resultinsert = $db->sql_query($sqlinsert); + $messag_moved .= $row['team_name'] . '
'; + } + $place++; + } + } + } + } + $db->sql_freeresult($result); + + $message .= '

'; + return $message. $messag_moved; +} + +/** +* return SQL statement part to calculate points depending to mode. +*/ +function select_points($creator = 'm', $sum = false) +{ + global $league_info; + + $points_result = $league_info['points_result']; + $points_tendency = $league_info['points_tendency']; + $points_diff = $league_info['points_diff']; + + switch ($league_info['points_mode']) + { + // hit = points_result + // right tendency (not draw) = points_result - difference between bet und result but minimal points_tendency + // right tendency (draw) = points_result - difference between bet goals home und result goals home + case 1: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + IF((b.goals_home = b.goals_guest), + $points_result - ABS(b.goals_home - $creator.goals_home), + IF((($points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest)) < $points_tendency), + $points_tendency, + $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest) + ) + ) + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + // hit = points_result, + // right tendency = points_result - difference between bet und result but minimal points_tendency + case 2: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + IF((b.goals_home = b.goals_guest), + $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest), + IF((($points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest)) < $points_tendency), + $points_tendency, + $points_result - ABS(b.goals_home - $creator.goals_home) - ABS(b.goals_guest - $creator.goals_guest) + ) + ) + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + // hit = points_result, + // right tendency = points_tendency + case 3: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + $points_tendency + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + // hit = points_result, + // right goal-difference = points_diff, + // right tendency = points_tendency + case 4: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + IF((b.goals_home - b.goals_guest = $creator.goals_home - $creator.goals_guest), + $points_diff, + $points_tendency + ) + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + // hit = points_result, + // right goal-difference (not draw) = points_diff, + // right tendency = points_tendency + case 5: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + IF(((b.goals_home - b.goals_guest = $creator.goals_home - $creator.goals_guest) + AND ($creator.goals_home <> $creator.goals_guest)) , + $points_diff, + $points_tendency + ) + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + // hit = points_result, + // right tendency draw = points_diff, + // right tendency (not draw) = points_tendency + case 6: + $select_part = ($sum ? "SUM(IF(b.goals_home <> '' AND b.goals_guest <> ''," : 'IF(((m.status = 2) OR (m.status = 3)),') . + "IF(b.goals_home <> '' AND b.goals_guest <> '', + IF((b.goals_home + 0 < b.goals_guest) <> ($creator.goals_home + 0 < $creator.goals_guest) + OR (b.goals_home = b.goals_guest) <> ($creator.goals_home = $creator.goals_guest) + OR (b.goals_home + 0 > b.goals_guest) <> ($creator.goals_home + 0 > $creator.goals_guest), + " .($sum ? '0' : "''") . ", + IF((b.goals_home = $creator.goals_home) AND (b.goals_guest = $creator.goals_guest), + $points_result, + IF(((b.goals_home = b.goals_guest) AND ($creator.goals_home = $creator.goals_guest) ) , + $points_diff, + $points_tendency + ) + ) + ), + " .($sum ? '0' : "''") . ' + ), + ' .($sum ? '0' : "''") . " + ) " .($sum ? ')' : '') . 'AS points'; + break; + } + return $select_part; +} ?> \ No newline at end of file diff --git a/language/de/info_acp_football.php b/language/de/info_acp_football.php index 3ce2857..f9531b7 100644 --- a/language/de/info_acp_football.php +++ b/language/de/info_acp_football.php @@ -1,205 +1,206 @@ - 'Fussball', - 'ACP_FOOTBALL_MANAGEMENT' => 'Tipprunde-Verwalten', - 'ACP_FOOTBALL_OPERATION' => 'Spielbetrieb', - 'ACP_FOOTBALL_MANAGE' => 'Spielplan Verwaltung', - - 'ACP_FOOTBALL_CONFIGURATION' => 'Tipprunden-Konfiguration', - 'ACP_FOOTBALL_SETTINGS' => 'Tipprunden-Einstellungen', - 'ACP_FOOTBALL_SETTINGS_EXPLAIN' => 'Hier kannst du einige grundlegende Einstellungen der Tipprunde vornehmen, ihr einen passenden Namen und eine Beschreibung geben und, neben anderen Werten, die Standard-Einstellungen für die Anzeige anpassen. ', - - 'DISABLE_FOOTBALL' => 'Tipprunde deaktivieren', - 'DISABLE_FOOTBALL_EXPLAIN' => 'Hiermit sperrst du die Tipprunde für alle Benutzer. Wenn du möchtest, kannst du eine kurze Nachricht (bis zu 255 Zeichen) angeben. ', - 'DISPLAY_RANKS' => 'Anzahl angezeigter Tipper in den Übersichts-Ranglisten', - 'DISPLAY_RANKS_EXPLAIN' => 'Limitiert die Anzeige der Spieltags- und Gesamtrangliste in der Hauptansicht. Die eigene Platzierung wird ggf. unten angehängt. ', - - 'FOOTBALL_CODE' => 'Tipprunden Code', - 'FOOTBALL_CODE_EXPLAIN' => 'Zugangscode zur Tipprunde z.B. für Cronjobs. ', - 'FOOTBALL_FULLSCREEN' => 'Tipprunden-Seiten im Fullscreen-Modus', - 'FOOTBALL_FULLSCREEN_EXPLAIN' => 'Hiermit kannst Du, abweichend vom Forum, die Tipprundenseiten mit minimalen Seitenrändern anzeigen lassen. ', - 'FOOTBALL_HEADER_ENABLE' => 'Header-Bild je Liga verwenden', - 'FOOTBALL_HEADER_ENABLE_EXPLAIN' => 'Hiermit kannst Du festlegen, ob je Liga die zugehöriges Bild im Header angezeigt werden soll. ', - 'FOOTBALL_INFO' => 'Tipprunden Information anzeigen', - 'FOOTBALL_INFO_EXPLAIN' => 'Hiermit kannst Du eine kurze Information (bis zu 255 Zeichen) oberhalb der Tippdaten anzeigen lassen. ', - 'FOOTBALL_NAME' => 'Name der Tipprunde', - 'FOOTBALL_NAME_EXPLAIN' => 'Name der im Tipprunden-Menu verwendet wird, um zur Hauptseite zu gelangen. ', - 'FOOTBALL_OVERRIDE_STYLE' => 'Style überschreiben', - 'FOOTBALL_OVERRIDE_STYLE_EXPLAIN' => 'Verwendet für die Tipprunde immer den Standard-Tipprunden-Style. ', - 'FOOTBALL_STYLE' => 'Standard Tipprunden Style', - 'FOOTBALL_UPDATE_SOURCE' => 'Update Quelle', - 'FOOTBALL_UPDATE_SOURCE_EXPLAIN' => 'Link zur Quelle des Updates. Falls leer, wird automatisch http://football.bplaced.net/football/xml/football_xml_season.php gewählt. ', - 'FOOTBALL_UPDATE_CODE' => 'Update Code', - 'FOOTBALL_UPDATE_CODE_EXPLAIN' => 'Nur mit diesem Code können Updates von dieser Seite heruntergeladen werden. ', - - 'GUEST_VIEW' => 'Tipprunde für Gäste sichtbar', - 'GUEST_VIEW_EXPLAIN' => 'Soll die Tipprunde für Gäste sichtbar sein?', - - 'USER_VIEW' => 'Tipprunde nur für Teilnehmer sichtbar', - 'USER_VIEW_EXPLAIN' => 'Soll die Tipprunde nur für Tipprunden-Teilnehmer sichtbar sein?', - - 'HOST_TIMEZONE' => 'Host Zeitzone', - 'HOST_TIMEZONE_EXPLAIN' => 'Differenz zur Board Zeitzone wenn dein Host in einer anderen Zeitzone steht, damit die Tippabgabe korrekt funktioniert. ', - - 'LEFT_COLUMN' => 'Spaltenbreite Links in Pixeln', - 'LEFT_COLUMN_EXPLAIN' => 'Optimale Breite 180 Pixel. Dieser Wert sollte nicht unterschritten werden. ', - - 'PREDICTION_LEAGUE' => 'Tipprunde', - - 'RIGHT_COLUMN' => 'Spaltenbreite Rechts in Pixeln', - 'RIGHT_COLUMN_EXPLAIN' => 'Optimal 180 Pixel. Dieser Wert wird durch externe Einblendungen ggf. übersteuert. ', - - 'USERS_PAGE' => 'Tipper pro Seite', - 'USERS_PAGE_EXPLAIN' => 'Anzahl der Tipper je Seite in der Hauptrangliste und Alle Tipps. ', - - 'WIN_NAME' => 'Gewinn Name (oder Währung)', - 'WIN_NAME_EXPLAIN' => 'Der Name, der für die Gewinne in der Tipprunde angezeigt werden soll', - - 'ANNOUNCEMENT_TOPIC' => 'Release Ankündigung', - 'CURRENT_VERSION' => 'Derzeitige Version', - 'DOWNLOAD_LATEST' => 'Neueste Version herunterladen', - 'LATEST_VERSION' => 'Neueste Version', - 'NOT_UP_TO_DATE' => '%s ist nicht aktuell', - 'RELEASE_ANNOUNCEMENT' => 'Ankündigungsthema', - 'UP_TO_DATE' => '%s ist aktuell', - 'FOOTBALL_VERSION_CHECK' => 'Football Prediction League Extension Version Check', - -)); - -// Football Features -$lang = array_merge($lang, array( - 'ACP_FOOTBALL_FEATURES' => 'Tipprunden-Funktionalitäten', - 'ACP_FOOTBALL_FEATURES_EXPLAIN' => 'Hier kannst du einige Funktionen der Tipprunde aktivieren bzw. deaktivieren', - - 'AUTO' => 'Auto', - - 'BANK' => 'Tipprunden Konto verwalten', - 'BANK_EXPLAIN' => 'Sollen Tipprunden Konten mit Einsätzen und Gewinnen gepflegt werden?', - - 'FOOTBALL_SEASON_START' => 'Starte in Saison', - 'FOOTBALL_SEASON_START_EXPLAIN' => 'Starte in dieser oder in der automatisch ermittelten Saison, wenn noch keine ausgewählt wurde. ', - - 'FOOTBALL_REMEMBER_ENABLE' => 'Cronjob für die Tipp-Erinnerungsmail aktivieren', - 'FOOTBALL_REMEMBER_ENABLE_EXPLAIN' => 'Hier kannst Du angeben, ob 1 Tag vor Tippabgabe eine Erinnerungsmail versendet werden soll.', - - 'FOOTBALL_REMEMBER_NEXT_RUN' => 'Nächster Cronjoblauf für die Tipp-Erinnerungsmail', - 'FOOTBALL_REMEMBER_NEXT_RUN_EXPLAIN'=> 'Hier kannst Du einstellen, wann der Cronjob für die Tipp-Erinnerungsmail frühestens wieder aufgerufen wird. Nach Ausführung wird der Cronjob für den Folgetag zur gleichen Uhrzeit neu eingeplant.', - - 'FOUNDER_DELETE' => 'Nur Gründungsmitglieder dürfen löschen', - 'FOUNDER_DELETE_EXPLAIN' => 'Löschung von Spielplandaten wie Saisons, Ligen, Teams, Spieltage und Spielpläne nur auf Gründungsmitglieder beschränken. ', - - 'RESULTS_AT_TIME' => 'Eingabe endgültiger Spielergebnisse erst nach Spielende', - 'RESULTS_AT_TIME_EXPLAIN' => 'Eingabe der endgültigen Spielergebnisse im Adminbereich erst nach Spielende freigeben. Die Eingabe von vorläufigen Spielergebnissen durch die Tipper ist hiervon unabhängig. ', - - 'SAME_ALLOWED' => 'Alle Tipps an einem Spieltag gleich', - 'SAME_ALLOWED_EXPLAIN' => 'Identische Tipps (Oma-Tipps) bei allen Spielen eines Spieltags erlauben bzw. verbieten. ', - - 'ULT_POINTS' => 'Ultimate Points einbinden', - 'ULT_POINTS_EXPLAIN' => 'Soll es möglich sein, die Punkte oder Gewinne in Ultimate Points verrechnen zu lassen? Dazu muss Ultimate Points installiert sein. ', - 'ULT_POINTS_FACTOR' => 'Ultimate Points Faktor', - 'ULT_POINTS_FACTOR_EXPLAIN' => 'Faktor mit dem die Punkte je Spieltag in Ultimate Points gutgeschrieben werden. ', - 'UP_NONE' => 'Keine', - 'UP_POINTS' => 'Punkte', - 'UP_WINS' => 'Gewinne', - - 'VIEW_BETS' => 'Tipps immer Anzeigen', - 'VIEW_BETS_EXPLAIN' => 'Sollen alle Tipps sofort angezeigt werden? Wenn Nein, dann werden sie erst nach Tippabgabeschluss angezeigt. ', - 'VIEW_CURRENT' => 'Anzeige startet in aktueller Liga', - 'VIEW_CURRENT_EXPLAIN' => 'Soll beim ersten Aufruf die Liga angezeigt werden, in der die nächsten Spiele stattfinden? Sonst wird immer die erste Liga angezeigt', - 'VIEW_TENDENCIES' => 'Tipp-Tendenzen immer Anzeigen', - 'VIEW_TENDENCIES_EXPLAIN' => 'Sollen alle Tipp-Tendenzen sofort angezeigt werden? Wenn Nein, dann werden sie erst nach Tippabgabeschluss angezeigt. ', - - 'WIN_HITS02' => 'Gewinne Volltreffer-Wertung mit Auswärtspunkten', - 'WIN_HITS02_EXPLAIN' => 'Sollen Gewinne der Volltreffer-Wertung mit Auswärtspunkten angezeigt werden? Wenn Nein, muss sichergestellt werden, dass dazu keine Gewinne in den bestehenden Ligen hinterlegt wurden. ', -)); - -// Football Menu -$lang = array_merge($lang, array( - 'ACP_FOOTBALL_MENU' => 'Tipprunden-Menu', - 'ACP_FOOTBALL_MENU_EXPLAIN' => 'Hier kannst du Links für das Tipprunden-Menu hinterlegen. Die Linkbeschriftung kannst du frei wählen. ', - - 'FOOTBALL_BREADCRUMB' => 'Tipprunden breadcrumb anzeigen', - 'FOOTBALL_BREADCRUMB_EXPLAIN' => 'Soll ein Breadcrumb-Link für die Tipprunden angezeigt werden? ', - 'FOOTBALL_SIDE' => 'Tipprunden Sidebar anzeigen', - 'FOOTBALL_SIDE_EXPLAIN' => 'Soll die Tipprunden Sidebar mit den Menüeinträgen angezeigt werden? ', - 'FOOTBALL_MENU' => 'Tipprunden Menu anzeigen', - 'FOOTBALL_MENU_EXPLAIN' => 'Soll das Tipprunden Dropdown Menü in der Navigationsleiste angezeigt werden? ', - 'MENU_DESC1' => 'Beschriftung http-Link 1', - 'MENU_DESC1_EXPLAIN' => 'Die Beschriftung des Links darf keine unzulässigen Sonderzeichen enthalten und höchsten 20 Zeichen lang sein. ', - 'MENU_DESC2' => 'Beschriftung http-Link 2', - 'MENU_DESC3' => 'Beschriftung http-Link 3', - 'MENU_LINK1' => 'Http-Link 1', - 'MENU_LINK1_EXPLAIN' => 'Bitte hier nur http Links eingeben. ', - 'MENU_LINK2' => 'Http-Link 2', - 'MENU_LINK3' => 'Http-Link 3', - 'MENU_NO_LINK' => 'Kein Link hinterlegt', -)); - - -// Football Help -$lang = array_merge($lang, array( - 'ACP_FOOTBALL_USERGUIDE' => 'Benutzerhilfe', - 'ACP_FOOTBALL_USERGUIDE_EXPLAIN' => 'Hier findest du Hilfe für die Einstellungen des phpBB3 Football MODs.
Wenn du Fragen hast, dann schaue bitte immer zuerst hier!', -)); - - -#// Football Logs -$lang = array_merge($lang, array( - 'LOG_FOOTBALL_FEATURES' => 'Tipprunden-Funktionalitäten geändert', - 'LOG_FOOTBALL_MENU' => 'Tipprunden-Menu geändert', - 'LOG_FOOTBALL_SETTINGS' => 'Tipprunde-Einstellungen geändert', - - 'LOG_FOOTBALL_MSG_TEST' => 'Aufruf am %s.', - 'LOG_FOOTBALL_MSG_TEST_TRAVEL' => 'Aufruf mit Zeitreise zum %s.', - - 'LOG_FOOTBALL_REMEMBER_CRON' => 'Cronjob Football remember ausgeführt
» %s', - 'LOG_FOOTBALL_REMEMBER_CRON_TEST' => 'Cronjob Football remember Testaufruf
» %s', - - 'FOOTBALL_REMEMBER_SUBJECT' => 'Bitte %1$s %2$d. Spieltag tippen', - 'FOOTBALL_REMEMBER_SUBJECT_BOARD' => 'Versendete Erinnerungs-Mails %1$s %2$d', - 'FOOTBALL_REMEMBER_ERROR_EMAIL' => '%1$s Erinnerungs-Mail an: %2$s gescheitert', - 'FOOTBALL_REMEMBER_ERROR_EMAIL_BOARD'=> '%1$s Versandliste Erinnerungs-Mail an: %2$s gescheitert', - 'FOOTBALL_REMEMBER_NOBODY' => 'Es muss niemand erinnert werden.', - 'FOOTBALL_REMEMBER_NO_DELIVERY' => 'Keine anstehende Tippabgabe im Zeitraum.', - 'FOOTBALL_REMEMBER_SEND' => '%1$s Erinnerungs-Mail an: %2$s', - -)); - + 'Fussball', + 'ACP_FOOTBALL_MANAGEMENT' => 'Tipprunde-Verwalten', + 'ACP_FOOTBALL_OPERATION' => 'Spielbetrieb', + 'ACP_FOOTBALL_MANAGE' => 'Spielplan Verwaltung', + + 'ACP_FOOTBALL_CONFIGURATION' => 'Tipprunden-Konfiguration', + 'ACP_FOOTBALL_SETTINGS' => 'Tipprunden-Einstellungen', + 'ACP_FOOTBALL_SETTINGS_EXPLAIN' => 'Hier kannst du einige grundlegende Einstellungen der Tipprunde vornehmen, ihr einen passenden Namen und eine Beschreibung geben und, neben anderen Werten, die Standard-Einstellungen für die Anzeige anpassen. ', + + 'DISABLE_FOOTBALL' => 'Tipprunde deaktivieren', + 'DISABLE_FOOTBALL_EXPLAIN' => 'Hiermit sperrst du die Tipprunde für alle Benutzer. Wenn du möchtest, kannst du eine kurze Nachricht (bis zu 255 Zeichen) angeben. ', + 'DISPLAY_RANKS' => 'Anzahl angezeigter Tipper in den Übersichts-Ranglisten', + 'DISPLAY_RANKS_EXPLAIN' => 'Limitiert die Anzeige der Spieltags- und Gesamtrangliste in der Hauptansicht. Die eigene Platzierung wird ggf. unten angehängt. ', + + 'FOOTBALL_CODE' => 'Tipprunden Code', + 'FOOTBALL_CODE_EXPLAIN' => 'Zugangscode zur Tipprunde z.B. für Cronjobs. ', + 'FOOTBALL_FULLSCREEN' => 'Tipprunden-Seiten im Fullscreen-Modus', + 'FOOTBALL_FULLSCREEN_EXPLAIN' => 'Hiermit kannst Du, abweichend vom Forum, die Tipprundenseiten mit minimalen Seitenrändern anzeigen lassen. ', + 'FOOTBALL_HEADER_ENABLE' => 'Header-Bild je Liga verwenden', + 'FOOTBALL_HEADER_ENABLE_EXPLAIN' => 'Hiermit kannst Du festlegen, ob je Liga die zugehöriges Bild im Header angezeigt werden soll. ', + 'FOOTBALL_INFO' => 'Tipprunden Information anzeigen', + 'FOOTBALL_INFO_EXPLAIN' => 'Hiermit kannst Du eine kurze Information (bis zu 255 Zeichen) oberhalb der Tippdaten anzeigen lassen. ', + 'FOOTBALL_NAME' => 'Name der Tipprunde', + 'FOOTBALL_NAME_EXPLAIN' => 'Name der im Tipprunden-Menu verwendet wird, um zur Hauptseite zu gelangen. ', + 'FOOTBALL_OVERRIDE_STYLE' => 'Style überschreiben', + 'FOOTBALL_OVERRIDE_STYLE_EXPLAIN' => 'Verwendet für die Tipprunde immer den Standard-Tipprunden-Style. ', + 'FOOTBALL_STYLE' => 'Standard Tipprunden Style', + 'FOOTBALL_UPDATE_SOURCE' => 'Update Quelle', + 'FOOTBALL_UPDATE_SOURCE_EXPLAIN' => 'Link zur Quelle des Updates. Falls leer, wird automatisch http://football.bplaced.net/football/xml/football_xml_season.php gewählt. ', + 'FOOTBALL_UPDATE_CODE' => 'Update Code', + 'FOOTBALL_UPDATE_CODE_EXPLAIN' => 'Nur mit diesem Code können Updates von dieser Seite heruntergeladen werden. ', + + 'GUEST_VIEW' => 'Tipprunde für Gäste sichtbar', + 'GUEST_VIEW_EXPLAIN' => 'Soll die Tipprunde für Gäste sichtbar sein?', + + 'USER_VIEW' => 'Tipprunde nur für Teilnehmer sichtbar', + 'USER_VIEW_EXPLAIN' => 'Soll die Tipprunde nur für Tipprunden-Teilnehmer sichtbar sein?', + + 'HOST_TIMEZONE' => 'Host Zeitzone', + 'HOST_TIMEZONE_EXPLAIN' => 'Differenz zur Board Zeitzone wenn dein Host in einer anderen Zeitzone steht, damit die Tippabgabe korrekt funktioniert. ', + + 'LEFT_COLUMN' => 'Spaltenbreite Links in Pixeln', + 'LEFT_COLUMN_EXPLAIN' => 'Optimale Breite 180 Pixel. Dieser Wert sollte nicht unterschritten werden. ', + + 'PREDICTION_LEAGUE' => 'Tipprunde', + + 'RIGHT_COLUMN' => 'Spaltenbreite Rechts in Pixeln', + 'RIGHT_COLUMN_EXPLAIN' => 'Optimal 180 Pixel. Dieser Wert wird durch externe Einblendungen ggf. übersteuert. ', + + 'USERS_PAGE' => 'Tipper pro Seite', + 'USERS_PAGE_EXPLAIN' => 'Anzahl der Tipper je Seite in der Hauptrangliste und Alle Tipps. ', + + 'WIN_NAME' => 'Gewinn Name (oder Währung)', + 'WIN_NAME_EXPLAIN' => 'Der Name, der für die Gewinne in der Tipprunde angezeigt werden soll', + + 'ANNOUNCEMENT_TOPIC' => 'Release Ankündigung', + 'CURRENT_VERSION' => 'Derzeitige Version', + 'DOWNLOAD_LATEST' => 'Neueste Version herunterladen', + 'LATEST_VERSION' => 'Neueste Version', + 'NOT_UP_TO_DATE' => '%s ist nicht aktuell', + 'RELEASE_ANNOUNCEMENT' => 'Ankündigungsthema', + 'UP_TO_DATE' => '%s ist aktuell', + 'FOOTBALL_VERSION_CHECK' => 'Football Prediction League Extension Version Check', + +)); + +// Football Features +$lang = array_merge($lang, array( + 'ACP_FOOTBALL_FEATURES' => 'Tipprunden-Funktionalitäten', + 'ACP_FOOTBALL_FEATURES_EXPLAIN' => 'Hier kannst du einige Funktionen der Tipprunde aktivieren bzw. deaktivieren', + + 'AUTO' => 'Auto', + + 'BANK' => 'Tipprunden Konto verwalten', + 'BANK_EXPLAIN' => 'Sollen Tipprunden Konten mit Einsätzen und Gewinnen gepflegt werden?', + + 'FOOTBALL_SEASON_START' => 'Starte in Saison', + 'FOOTBALL_SEASON_START_EXPLAIN' => 'Starte in dieser oder in der automatisch ermittelten Saison, wenn noch keine ausgewählt wurde. ', + + 'FOOTBALL_REMEMBER_ENABLE' => 'Cronjob für die Tipp-Erinnerungsmail aktivieren', + 'FOOTBALL_REMEMBER_ENABLE_EXPLAIN' => 'Hier kannst Du angeben, ob 1 Tag vor Tippabgabe eine Erinnerungsmail versendet werden soll.', + + 'FOOTBALL_REMEMBER_NEXT_RUN' => 'Nächster Cronjoblauf für die Tipp-Erinnerungsmail', + 'FOOTBALL_REMEMBER_NEXT_RUN_EXPLAIN'=> 'Hier kannst Du einstellen, wann der Cronjob für die Tipp-Erinnerungsmail frühestens wieder aufgerufen wird. Nach Ausführung wird der Cronjob für den Folgetag zur gleichen Uhrzeit neu eingeplant.', + + 'FOUNDER_DELETE' => 'Nur Gründungsmitglieder dürfen löschen', + 'FOUNDER_DELETE_EXPLAIN' => 'Löschung von Spielplandaten wie Saisons, Ligen, Teams, Spieltage und Spielpläne nur auf Gründungsmitglieder beschränken. ', + + 'RESULTS_AT_TIME' => 'Eingabe endgültiger Spielergebnisse erst nach Spielende', + 'RESULTS_AT_TIME_EXPLAIN' => 'Eingabe der endgültigen Spielergebnisse im Adminbereich erst nach Spielende freigeben. Die Eingabe von vorläufigen Spielergebnissen durch die Tipper ist hiervon unabhängig. ', + + 'SAME_ALLOWED' => 'Alle Tipps an einem Spieltag gleich', + 'SAME_ALLOWED_EXPLAIN' => 'Identische Tipps (Oma-Tipps) bei allen Spielen eines Spieltags erlauben bzw. verbieten. ', + + 'ULT_POINTS' => 'Ultimate Points einbinden', + 'ULT_POINTS_EXPLAIN' => 'Soll es möglich sein, die Punkte oder Gewinne in Ultimate Points verrechnen zu lassen? Dazu muss Ultimate Points installiert sein. ', + 'ULT_POINTS_FACTOR' => 'Ultimate Points Faktor', + 'ULT_POINTS_FACTOR_EXPLAIN' => 'Faktor mit dem die Punkte je Spieltag in Ultimate Points gutgeschrieben werden. ', + 'UP_NONE' => 'Keine', + 'UP_POINTS' => 'Punkte', + 'UP_WINS' => 'Gewinne', + + 'VIEW_BETS' => 'Tipps immer Anzeigen', + 'VIEW_BETS_EXPLAIN' => 'Sollen alle Tipps sofort angezeigt werden? Wenn Nein, dann werden sie erst nach Tippabgabeschluss angezeigt. ', + 'VIEW_CURRENT' => 'Anzeige startet in aktueller Liga', + 'VIEW_CURRENT_EXPLAIN' => 'Soll beim ersten Aufruf die Liga angezeigt werden, in der die nächsten Spiele stattfinden? Sonst wird immer die erste Liga angezeigt', + 'VIEW_TENDENCIES' => 'Tipp-Tendenzen immer Anzeigen', + 'VIEW_TENDENCIES_EXPLAIN' => 'Sollen alle Tipp-Tendenzen sofort angezeigt werden? Wenn Nein, dann werden sie erst nach Tippabgabeschluss angezeigt. ', + + 'WIN_HITS02' => 'Gewinne Volltreffer-Wertung mit Auswärtspunkten', + 'WIN_HITS02_EXPLAIN' => 'Sollen Gewinne der Volltreffer-Wertung mit Auswärtspunkten angezeigt werden? Wenn Nein, muss sichergestellt werden, dass dazu keine Gewinne in den bestehenden Ligen hinterlegt wurden. ', +)); + +// Football Menu +$lang = array_merge($lang, array( + 'ACP_FOOTBALL_MENU' => 'Tipprunden-Menu', + 'ACP_FOOTBALL_MENU_EXPLAIN' => 'Hier kannst du Links für das Tipprunden-Menu hinterlegen. Die Linkbeschriftung kannst du frei wählen. ', + + 'FOOTBALL_BREADCRUMB' => 'Tipprunden breadcrumb anzeigen', + 'FOOTBALL_BREADCRUMB_EXPLAIN' => 'Soll ein Breadcrumb-Link für die Tipprunden angezeigt werden? ', + 'FOOTBALL_SIDE' => 'Tipprunden Sidebar anzeigen', + 'FOOTBALL_SIDE_EXPLAIN' => 'Soll die Tipprunden Sidebar mit den Menüeinträgen angezeigt werden? ', + 'FOOTBALL_MENU' => 'Tipprunden Menu anzeigen', + 'FOOTBALL_MENU_EXPLAIN' => 'Soll das Tipprunden Dropdown Menü in der Navigationsleiste angezeigt werden? ', + 'MENU_DESC1' => 'Beschriftung http-Link 1', + 'MENU_DESC1_EXPLAIN' => 'Die Beschriftung des Links darf keine unzulässigen Sonderzeichen enthalten und höchsten 20 Zeichen lang sein. ', + 'MENU_DESC2' => 'Beschriftung http-Link 2', + 'MENU_DESC3' => 'Beschriftung http-Link 3', + 'MENU_LINK1' => 'Http-Link 1', + 'MENU_LINK1_EXPLAIN' => 'Bitte hier nur http Links eingeben. ', + 'MENU_LINK2' => 'Http-Link 2', + 'MENU_LINK3' => 'Http-Link 3', + 'MENU_NO_LINK' => 'Kein Link hinterlegt', +)); + + +// Football Help +$lang = array_merge($lang, array( + 'ACP_FOOTBALL_USERGUIDE' => 'Benutzerhilfe', + 'ACP_FOOTBALL_USERGUIDE_EXPLAIN' => 'Hier findest du Hilfe für die Einstellungen des phpBB3 Football MODs.
Wenn du Fragen hast, dann schaue bitte immer zuerst hier!', +)); + + +#// Football Logs +$lang = array_merge($lang, array( + 'LOG_FOOTBALL_FEATURES' => 'Tipprunden-Funktionalitäten geändert', + 'LOG_FOOTBALL_MENU' => 'Tipprunden-Menu geändert', + 'LOG_FOOTBALL_SETTINGS' => 'Tipprunde-Einstellungen geändert', + 'LOG_PL_BACKUP' => 'Tipprunden Backup', + + 'LOG_FOOTBALL_MSG_TEST' => 'Aufruf am %s.', + 'LOG_FOOTBALL_MSG_TEST_TRAVEL' => 'Aufruf mit Zeitreise zum %s.', + + 'LOG_FOOTBALL_REMEMBER_CRON' => 'Cronjob Football remember ausgeführt
» %s', + 'LOG_FOOTBALL_REMEMBER_CRON_TEST' => 'Cronjob Football remember Testaufruf
» %s', + + 'FOOTBALL_REMEMBER_SUBJECT' => 'Bitte %1$s %2$d. Spieltag tippen', + 'FOOTBALL_REMEMBER_SUBJECT_BOARD' => 'Versendete Erinnerungs-Mails %1$s %2$d', + 'FOOTBALL_REMEMBER_ERROR_EMAIL' => '%1$s Erinnerungs-Mail an: %2$s gescheitert', + 'FOOTBALL_REMEMBER_ERROR_EMAIL_BOARD'=> '%1$s Versandliste Erinnerungs-Mail an: %2$s gescheitert', + 'FOOTBALL_REMEMBER_NOBODY' => 'Es muss niemand erinnert werden.', + 'FOOTBALL_REMEMBER_NO_DELIVERY' => 'Keine anstehende Tippabgabe im Zeitraum.', + 'FOOTBALL_REMEMBER_SEND' => '%1$s Erinnerungs-Mail an: %2$s', + +)); + ?> \ No newline at end of file diff --git a/language/en/info_acp_football.php b/language/en/info_acp_football.php index 802e8f2..55e01b6 100644 --- a/language/en/info_acp_football.php +++ b/language/en/info_acp_football.php @@ -146,6 +146,7 @@ $lang = array_merge($lang, array( 'LOG_FOOTBALL_MSG_TEST_TRAVEL' => 'Call with time travel to %s.', 'LOG_FOOTBALL_REMEMBER_CRON' => 'Cronjob Football remember running %s', 'LOG_FOOTBALL_REMEMBER_CRON_TEST' => 'Cronjob Football remember test call %s', + 'LOG_PL_BACKUP' => 'Prediction League backup', 'FOOTBALL_REMEMBER_SUBJECT' => 'Please bet %1$s %2$d. matchday', 'FOOTBALL_REMEMBER_SUBJECT_BOARD' => 'Sent reminder mails %1$s %2$d', 'FOOTBALL_REMEMBER_ERROR_EMAIL' => '%1$s reminder email to: %2$d failed', diff --git a/migrations/v094_beta_update.php b/migrations/v094_beta_update.php index 365d5f6..f3104db 100644 --- a/migrations/v094_beta_update.php +++ b/migrations/v094_beta_update.php @@ -58,23 +58,13 @@ class v094_beta_update extends \phpbb\db\migration\migration { return array( 'drop_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_teampage', - ), $this->table_prefix . 'sessions' => array( + 'football_season', + 'football_league', + 'football_matchday', 'football_mobile', 'football_mobile_device', ), - $this->table_prefix . 'footb_bets' => array( - 'bet_time', - ), - $this->table_prefix . 'footb_matches' => array( - 'trend', - 'odd_1', - 'odd_x', - 'odd_2', - 'rating', - ), ) ); } diff --git a/migrations/v098_beta.php b/migrations/v098_beta.php new file mode 100644 index 0000000..f5e2755 --- /dev/null +++ b/migrations/v098_beta.php @@ -0,0 +1,30 @@ +config['football_version']) && version_compare($this->config['football_version'], '0.9.8', '>='); + } + + static public function depends_on() + { + return array('\football\football\migrations\v097_beta'); + } + + public function update_data() + { + return array( + array('config.update', array('football_version', '0.9.8', '0')), + ); + } +} diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html index b824949..588d391 100644 --- a/styles/prosilver/template/event/overall_header_head_append.html +++ b/styles/prosilver/template/event/overall_header_head_append.html @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/styles/prosilver/template/event/overall_header_page_body_before.html b/styles/prosilver/template/event/overall_header_page_body_before.html index b5ea2a4..21d0a2b 100644 --- a/styles/prosilver/template/event/overall_header_page_body_before.html +++ b/styles/prosilver/template/event/overall_header_page_body_before.html @@ -1,64 +1,64 @@ - - - + + + \ No newline at end of file diff --git a/styles/prosilver/template/football_body.html b/styles/prosilver/template/football_body.html index 4a382f2..5edd0e3 100644 --- a/styles/prosilver/template/football_body.html +++ b/styles/prosilver/template/football_body.html @@ -1,220 +1,220 @@ - - - - - - - -
- {L_INFORMATION}: {S_FOOTBALL_INFO} -
- - -
- -
-
- - -
- - - -

{S_SIDENAME}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- - -
- - - - - - - - - - - - - -
- - -
- - - -
- -
-
+ + + + + + + +
+ {L_INFORMATION}: {S_FOOTBALL_INFO} +
+ + +
+ +
+
+ + +
+ + + +

{S_SIDENAME}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ + + + + + + + + + + + + +
+ + +
+ + + +
+ +
+
\ No newline at end of file diff --git a/styles/prosilver/template/mobile_football_body.html b/styles/prosilver/template/mobile_football_body.html index ba28567..721e91d 100644 --- a/styles/prosilver/template/mobile_football_body.html +++ b/styles/prosilver/template/mobile_football_body.html @@ -1,179 +1,179 @@ - - - -
- {L_INFORMATION}: {S_FOOTBALL_INFO} -
- - -
- - -
-
-
- -
- - {S_DELIVERY} - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - + + + +
+ {L_INFORMATION}: {S_FOOTBALL_INFO} +
+ + +
+ + +
+
+
+ +
+ + {S_DELIVERY} + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file