Version 0.9.5

This commit is contained in:
football
2016-05-04 22:33:42 +02:00
commit 18fa848f6f
251 changed files with 40960 additions and 0 deletions

25
acp/all_bets_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class all_bets_info
{
function module()
{
return array(
'filename' => '\football\football\acp\all_bets_module',
'title' => 'ACP_FOOTBALL_ALL_BETS_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_ALL_BETS_VIEW', 'auth' => 'acl_a_football_editbets', 'cat' => array('ACP_FOOTBALL_ALL_BETS')),
),
);
}
}

600
acp/all_bets_module.php Normal file
View File

@@ -0,0 +1,600 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class all_bets_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template, $helper;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 . "&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $day_name . '</option>';
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 . "&amp;m=$season&amp;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 . "&amp;s=$season&amp;l=$league&amp;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'] == '') ? '&nbsp;' : $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'] == '') ? '&nbsp;' : $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'] == '') ? '&nbsp;' : $user_row['bet'];
$bet_team = ($user_row['bet_team'] == NULL) ? '&nbsp;' : $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),
)
);
}
}
?>

25
acp/bank_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class bank_info
{
function module()
{
return array(
'filename' => '\football\football\acp\bank_module',
'title' => 'ACP_FOOTBALL_BANK_MANAGEMENT',
'version' => '0.9.2',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_BANK_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_BANK')),
),
);
}
}

673
acp/bank_module.php Normal file
View File

@@ -0,0 +1,673 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class bank_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template, $phpbb_container;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
if ($selected <> '')
{
$season_name = $row['season_name'];
}
}
$db->sql_freeresult($result);
}
else
{
trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&amp;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 . '&amp;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 . '&amp;action=list&amp;s=' . $season . '&amp;l=' . $league . '&amp;t=' . $type . '&amp;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 . '&amp;action=list&amp;s=' . $season . '&amp;l=' . $league . '&amp;t=' . $type . '&amp;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 . '&amp;action=list&amp;s=' . $season . '&amp;l=' . $league . '&amp;t=' . $type . '&amp;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 .= '<option value="' . $option . '">' . $user->lang['MEMBER_' . $lang] . '</option>';
}
$curr_matchday = (curr_matchday($season, $league) > 0) ? curr_matchday($season, $league) : 1;
$matchday = ($type == 1) ? 1 : $curr_matchday;
$base_url = $this->u_action . "&amp;action=$action&amp;s=$season&amp;l=$league&amp;m=$matchday&amp;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 . "&amp;s=$season&amp;l=$league",
'U_BACK' => $this->u_action. "&amp;s=$season&amp;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&amp;action=edit&amp;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 .= '<option value="' . $option . '">' . $user->lang['MEMBER_' . $lang] . '</option>';
}
$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}&amp;action=list&amp;s=" . $season . "&amp;l=" .$row_league['league'] . "&amp;t=1",
'U_LIST_DEPOSITED' => "{$this->u_action}&amp;action=list&amp;s=" . $season . "&amp;l=" .$row_league['league'] . "&amp;t=2",
'U_LIST_WINS' => "{$this->u_action}&amp;action=list&amp;s=" . $season . "&amp;l=" .$row_league['league'] . "&amp;t=3",
'U_LIST_PAID' => "{$this->u_action}&amp;action=list&amp;s=" . $season . "&amp;l=" .$row_league['league'] . "&amp;t=7",
'U_DLOAD_BANK' => $helper->route('football_football_download', array('downside' => 'dload_bank', 's' => $season, 'l' => $row_league['league'])),
)
);
}
}
}
?>

25
acp/bets_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class bets_info
{
function module()
{
return array(
'filename' => '\football\football\acp\bets_module',
'title' => 'ACP_FOOTBALL_BETS_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_BETS_MANAGE', 'auth' => 'acl_a_football_editbets', 'cat' => array('ACP_FOOTBALL_BETS')),
),
);
}
}

753
acp/bets_module.php Normal file
View File

@@ -0,0 +1,753 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class bets_module
{
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, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 . "&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $day_name . '</option>';
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 . "&amp;s=$season&amp;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 .= '<option value="' . $row['user_id'] . '"' . $selected . '>' . $row['username'] . '</option>';
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 = "<img src=\"". $this->ext_football_path . 'images/flags/' . $homelogo . "\" alt=\"" . $homelogo . "\" width=\"28\" height=\"28\"/>" ;
}
else
{
$logoH = "<img src=\"". $this->ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ;
}
if ($guestlogo <> '')
{
$logoG = "<img src=\"". $this->ext_football_path . 'images/flags/' . $guestlogo . "\" alt=\"" . $guestlogo . "\" width=\"28\" height=\"28\"/>" ;
}
else
{
$logoG = "<img src=\"". $this->ext_football_path . "images/flags/blank.gif\" alt=\"\" width=\"28\" height=\"28\"/>" ;
}
if ($row['status'] == -1)
{
$delivertag = "<strong style='color:green'>*</strong>";
}
else
{
if ($row['status'] == -2)
{
$delivertag = "<strong style='color:green'>**</strong>";
}
else
{
$delivertag = '';
}
}
if ($row['group_id'] == '')
{
$group_id = '&nbsp;';
}
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'] == '') ? '&nbsp;' : $row['goals_home'],
'GOALS_GUEST' => ($row['goals_guest'] == '') ? '&nbsp;' : $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('<br />', $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'],
)
);
}
}
?>

25
acp/extra_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class extra_info
{
function module()
{
return array(
'filename' => '\football\football\acp\extra_module',
'title' => 'ACP_FOOTBALL_EXTRA_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_EXTRA_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_EXTRA')),
),
);
}
}

463
acp/extra_module.php Normal file
View File

@@ -0,0 +1,463 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class extra_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 . "&amp;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 . "&amp;s=$season"), E_USER_WARNING);
}
if (!$extra_no)
{
trigger_error($user->lang['NO_EXTRA'] . adm_back_link($this->u_action . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 = '<option value="0"' . ((!$matchday) ? ' selected="selected"' : '') . '>' . $user->lang['SELECT_MATCHDAY'] . '</option>';
$matchday_eval_options = '<option value="0"' . ((!$matchday_eval) ? ' selected="selected"' : '') . '>' . $user->lang['SELECT_MATCHDAY'] . '</option>';
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 .= '<option value="' . $row['matchday'] . '"' . $selected_matchday . '>' . $day_name . '</option>';
$matchday_eval_options .= '<option value="' . $row['matchday'] . '"' . $selected_eval . '>' . $day_name . '</option>';
}
}
$question_type_options = '';
for($i = 1; $i<= 5; $i++)
{
$selected = ($i == $extra_row['question_type']) ? ' selected="selected"' : '';
$question_type_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$extra_status_options = '';
for($i = 0; $i<= 3; $i++)
{
$selected = ($i == $extra_row['extra_status']) ? ' selected="selected"' : '';
$extra_status_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
// 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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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('<br />', $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}&amp;action=$action&amp;s=$season&amp;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}&amp;action=edit&amp;s=" . $season . "&amp;l=" .$league . "&amp;e=" .$row_extra['extra_no'],
'U_DELETE' => ($allow_delete) ? "{$this->u_action}&amp;action=delete&amp;s=" . $season . "&amp;l=" . $league . "&amp;e=" . $row_extra['extra_no'] : '',
)
);
}
}
}
?>

28
acp/football_info.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class football_info
{
function module()
{
return array(
'filename' => '\football\football\acp\football_module',
'title' => 'ACP_FOOTBALL_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'settings' => array('title' => 'ACP_FOOTBALL_SETTINGS', 'auth' => 'acl_a_football_config', 'cat' => array('ACP_FOOTBALL_CONFIGURATION')),
'features' => array('title' => 'ACP_FOOTBALL_FEATURES', 'auth' => 'acl_a_football_config', 'cat' => array('ACP_FOOTBALL_CONFIGURATION')),
'menu' => array('title' => 'ACP_FOOTBALL_MENU', 'auth' => 'acl_a_football_config', 'cat' => array('ACP_FOOTBALL_CONFIGURATION')),
'userguide' => array('title' => 'ACP_FOOTBALL_USERGUIDE','auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_CONFIGURATION')),
),
);
}
}

426
acp/football_module.php Normal file
View File

@@ -0,0 +1,426 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class football_module
{
var $new_config = array();
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log, $phpbb_container, $version_check;
public function __construct()
{
global $db, $user, $request, $template, $phpbb_container;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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' => '<img src="' . $phpbb_admin_path . 'images/icon_up.gif" style="vertical-align: middle;" alt="' . $user->lang['BACK_TO_TOP'] . '" title="' . $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('<br />', $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) . '<br /><input id="' . $key . '" type="text" name="config[football_disable_msg]" maxlength="255" size="80" value="' . $this->new_config['football_disable_msg'] . '" />';
}
/**
* 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) . '<br /><input id="' . $key . '" type="text" name="config[football_info]" maxlength="255" size="80" value="' . $this->new_config['football_info'] . '" />';
}
/**
* 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 = '<option value="0"' . $selected . '>' . $user->lang['AUTO'] . '</option>';
while ($row = $db->sql_fetchrow($result))
{
$selected = ($row['season'] == $default) ? ' selected="selected"' : '';
$season_options .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
}
$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 = '<select name="next_run_day" id="next_run_day">';
for ($i = 1; $i < 32; $i++)
{
$selected = ($i == $next_run['mday']) ? ' selected="selected"' : '';
$day_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$day_options .= '</select>';
// Months
$month_options = '<select name="next_run_month" id="next_run_month">';
for ($i = 1; $i < 13; $i++)
{
$selected = ($i == $next_run['mon']) ? ' selected="selected"' : '';
$month_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$month_options .= '</select>';
// Years
$year_options = '<select name="next_run_year" id="next_run_year">';
for ($i = date("Y"); $i < (date("Y") + 1); $i++)
{
$selected = ($i == $next_run['year']) ? ' selected="selected"' : '';
$year_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$year_options .= '</select>';
// Hours
$hour_options = '<select name="next_run_hour" id="next_run_hour">';
for ($i = 0; $i < 24; $i++)
{
$selected = ($i == $next_run['hours']) ? ' selected="selected"' : '';
$hour_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$hour_options .= '</select>';
// Minutes
$minute_options = '<select name="next_run_minute" id="next_run_minute">';
for ($i = 0; $i < 60; $i++)
{
$selected = ($i == $next_run['minutes']) ? ' selected="selected"' : '';
$minute_options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
$minute_options .= '</select>';
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;
}
}
?>

25
acp/ko_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class ko_info
{
function module()
{
return array(
'filename' => '\football\football\acp\ko_module',
'title' => 'ACP_FOOTBALL_KO_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_KO_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_KO')),
),
);
}
}

257
acp/ko_module.php Normal file
View File

@@ -0,0 +1,257 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class ko_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 = '<option value="0" selected="selected">' . sprintf($user->lang['CHOOSE_LEAGUE']) . '</option>';
}
else
{
$league_move_options = '<option value="0">' . sprintf($user->lang['CHOOSE_LEAGUE']) . '</option>';
}
while ($row = $db->sql_fetchrow($result))
{
// Grab current league
if (!$league)
{
$league = $row['league'];
}
$selected = ($league && $row['league'] == $league) ? ' selected="selected"' : '';
$league_options .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected_move . '>' . $row['league_name'] . '</option>';
}
}
$db->sql_freeresult($result);
if (!$league)
{
trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected_from . '>' . $day_name . '</option>';
$matchday_to_options .= '<option value="' . $row['matchday'] . '"' . $selected_to . '>' . $day_name . '</option>';
$matchday_new_options .= '<option value="' . $row['matchday'] . '"' . $selected_new . '>' . $day_name . '</option>';
}
$db->sql_freeresult($result);
if ($matchday_from_options == '')
{
trigger_error(sprintf($user->lang['NO_MATCHDAY'], $league_name, $season) . adm_back_link($this->u_action . "&amp;s=$season&amp;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('<br />', $error) : '',
'S_SUCCESS' => (sizeof($success)) ? true : false,
'SUCCESS_MSG' => (sizeof($success)) ? implode('<br />', $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'],
)
);
}
}
?>

25
acp/leagues_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class leagues_info
{
function module()
{
return array(
'filename' => '\football\football\acp\leagues_module',
'title' => 'ACP_FOOTBALL_LEAGUES_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_LEAGUES_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_LEAGUES')),
),
);
}
}

736
acp/leagues_module.php Normal file
View File

@@ -0,0 +1,736 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class leagues_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
if ($selected <> '')
{
$season_name = $row['season_name'];
}
}
$db->sql_freeresult($result);
}
else
{
trigger_error($user->lang['NO_SEASON'] . adm_back_link($this->u_action . "&amp;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 . "&amp;action=list&amp;s=$season&amp;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 . "&amp;action=list&amp;s=$season&amp;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 . '&amp;action=list&amp;s=' . $season . '&amp;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 . "&amp;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 . "&amp;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 . '&amp;action=list&amp;s=' . $season . '&amp;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 .= '<option value="' . $option . '">' . $user->lang['MEMBER_' . $lang] . '</option>';
}
// 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 = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
$select_list .= group_select_options($group_id, $exclude);
$base_url = $this->u_action . "&amp;action=list&amp;s=$season&amp;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 . "&amp;s=$season&amp;l=$league",
'U_BACK' => $this->u_action. "&amp;s=$season&amp;l=$league",
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=list&amp;field=usernames'),
'U_DEFAULT_ALL' => "{$this->u_action}&amp;action=addmembers&amp;s=$season&amp;l=$league&amp;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&amp;action=edit&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
}
// check if matches created
$existing_matches_on_league = count_existing_matches($season, $league, 0);
$u_back = $this->u_action . "&amp;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('<br />', $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}&amp;action=$action&amp;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}&amp;action=list&amp;s=" . $season . "&amp;l=" .$row_league['league'],
'U_EDIT' => "{$this->u_action}&amp;action=edit&amp;s=" . $season . "&amp;l=" .$row_league['league'],
'U_DELETE' => ($allow_delete) ? "{$this->u_action}&amp;action=delete&amp;s=" . $season . "&amp;l=" . $row_league['league'] : '',
)
);
}
}
}
?>

25
acp/matchdays_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class matchdays_info
{
function module()
{
return array(
'filename' => '\football\football\acp\matchdays_module',
'title' => 'ACP_FOOTBALL_MATCHDAYS_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_MATCHDAYS_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_MATCHDAYS')),
),
);
}
}

1134
acp/matchdays_module.php Normal file

File diff suppressed because it is too large Load Diff

25
acp/matches_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class matches_info
{
function module()
{
return array(
'filename' => '\football\football\acp\matches_module',
'title' => 'ACP_FOOTBALL_MATCHES_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_MATCHES_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_MATCHES')),
),
);
}
}

767
acp/matches_module.php Normal file
View File

@@ -0,0 +1,767 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class matches_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 . "&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $day_name . '</option>';
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 . "&amp;s=$season&amp;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 . "&amp;s=$season"), E_USER_WARNING);
}
if (!$matchday)
{
trigger_error($user->lang['NO_MATCHDAY'] . adm_back_link($this->u_action . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 . "&amp;s=$season&amp;l=$league&amp;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 = '<option value="0"' . ((!$data['mday_day']) ? ' selected="selected"' : '') . '>--</option>';
for ($i = 1; $i < 32; $i++)
{
$selected = ($i == $data['mday_day']) ? ' selected="selected"' : '';
$s_matchday_day_options .= "<option value=\"" . sprintf('%02d',$i) . "\"$selected>" . sprintf('%02d',$i) . "</option>";
}
$s_matchday_month_options = '<option value="0"' . ((!$data['mday_month']) ? ' selected="selected"' : '') . '>--</option>';
for ($i = 1; $i < 13; $i++)
{
$selected = ($i == $data['mday_month']) ? ' selected="selected"' : '';
$s_matchday_month_options .= "<option value=\"" . sprintf('%02d',$i) . "\"$selected>" . sprintf('%02d',$i) . "</option>";
}
$s_matchday_year_options = '';
$s_matchday_year_options = '<option value="0"' . ((!$data['mday_year']) ? ' selected="selected"' : '') . '>--</option>';
for ($i = $season - 1 ; $i <= $season; $i++)
{
$selected = ($i == $data['mday_year']) ? ' selected="selected"' : '';
$s_matchday_year_options .= "<option value=\"$i\"$selected>$i</option>";
}
$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 .= "<option value=\"" . sprintf('%02d',$i) . "\"$selected>" . sprintf('%02d',$i) . "</option>";
}
$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 .= "<option value=\"" . sprintf('%02d',($i * 5)) . "\"$selected>" . sprintf('%02d',($i * 5)) . "</option>";
}
// Selection status
$edit_status = false;
if ($match_row['status'] < 1)
{
$edit_status = true;
$selected_status = ($match_row['status'] == 0) ? ' selected="selected"' : '';
$status_options = '<option value="0"' . $selected_status . '>0</option>';
if ($delivery2 != '')
{
$selected_status = ($match_row['status'] == -1) ? ' selected="selected"' : '';
$status_options .= '<option value="-1"' . $selected_status . '>-1</option>';
if ($delivery3 != '')
{
$selected_status = ($match_row['status'] == -2) ? ' selected="selected"' : '';
$status_options .= '<option value="-2"' . $selected_status . '>-2</option>';
}
}
}
else
{
$status_options = '<option value="' . $row['status'] . '" selected="selected">' . $row['status'] . '</option>';
}
// 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 = '<option value=" ;0">' . sprintf($user->lang['UNKNOWN']) . '</option>';
$team_home_options = '<option value=" ;0">' . sprintf($user->lang['UNKNOWN']) . '</option>';
$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 .= '<option value="' . $row['group_id'] . ';' . $row['team_id'] . '"' . $selected_guest . '>' . $row['team_name'] . '</option>';
$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 .= '<option value="' . $row['group_id'] . ';' . $row['team_id'] .'"' . $selected_home . '>' . $row['team_name'] . '</option>';
}
$u_back = $this->u_action . "&amp;s=$season&amp;l=$league&amp;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('<br />', $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}&amp;action=$action&amp;s=$season&amp;l=$league&amp;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}&amp;action=edit&amp;s=" . $season . "&amp;l=" .$league . "&amp;m=" .$matchday . "&amp;g=" .$row_match['match_no'],
'U_DELETE' => ($allow_delete) ? "{$this->u_action}&amp;action=delete&amp;s=" . $season . "&amp;l=" . $league . "&amp;m=" . $matchday . "&amp;g=" . $row_match['match_no'] : '',
)
);
}
}
}
?>

25
acp/results_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class results_info
{
function module()
{
return array(
'filename' => '\football\football\acp\results_module',
'title' => 'ACP_FOOTBALL_RESULTS_MANAGEMENT',
'version' => '1.0.0',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_RESULTS_MANAGE', 'auth' => 'acl_a_football_results', 'cat' => array('ACP_FOOTBALL_RESULTS')),
),
);
}
}

819
acp/results_module.php Normal file
View File

@@ -0,0 +1,819 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class results_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
if ($selected <> '')
{
$league_info = $row;
}
}
$db->sql_freeresult($result);
}
else
{
trigger_error(sprintf($user->lang['NO_LEAGUE'], $season) . adm_back_link($this->u_action . "&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $day_name . '</option>';
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 . "&amp;s=$season&amp;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'] == '') ? '&nbsp;' : $row['result'];
$result_extra = ($row['result_team'] == NULL) ? '&nbsp;' : $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('<br />', $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'],
)
);
}
}
?>

25
acp/seasons_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class seasons_info
{
function module()
{
return array(
'filename' => '\football\football\acp\seasons_module',
'title' => 'ACP_FOOTBALL_SEASONS_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_SEASONS_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_SEASONS')),
),
);
}
}

396
acp/seasons_module.php Normal file
View File

@@ -0,0 +1,396 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class seasons_module
{
public $u_action;
protected $db, $user, $template, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
protected $root_path, $request, $php_ext, $log;
public function __construct()
{
global $db, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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('<br />', $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}&amp;action=$action&amp;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}&amp;action=edit&amp;s=" .$row_season['season'],
'U_DELETE' => ($allow_delete) ? "{$this->u_action}&amp;action=delete&amp;s=" . $row_season['season'] : '',
)
);
}
}
}
?>

25
acp/teams_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class teams_info
{
function module()
{
return array(
'filename' => '\football\football\acp\teams_module',
'title' => 'ACP_FOOTBALL_TEAMS_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_TEAMS_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_TEAMS')),
),
);
}
}

659
acp/teams_module.php Normal file
View File

@@ -0,0 +1,659 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class teams_module
{
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, $user, $request, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$user->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 .= '<option value="' . $row['season'] . '"' . $selected . '>' . $row['season_name_short'] . '</option>';
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 .= '<option value="' . $row['league'] . '"' . $selected . '>' . $row['league_name'] . '</option>';
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 . "&amp;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 = '<option value="0" selected="selected">' . sprintf($user->lang['NEW_TEAM']) . '</option>';
while ($row = $db->sql_fetchrow($result))
{
$selected = '';
$team_options .= '<option value="' . $row['team_id'] . '"' . $selected . '>' . $row['team_name'] . '</option>';
}
$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 = '<option value="blank.gif">blank.gif</option>';
$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 .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
}
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 . "&amp;s=$season"), E_USER_WARNING);
}
if (!$team)
{
trigger_error($user->lang['NO_TEAM'] . adm_back_link($this->u_action . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $day_name . '</option>';
$matchdays++;
}
$db->sql_freeresult($result);
if (!$matchdays)
{
trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&amp;s=$season&amp;l=$league"), E_USER_WARNING);
}
}
// Grab all teamsymbol for selection
$teamsymbol_options = '<option value="blank.gif">blank.gif</option>';
$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 .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
}
closedir($directory);
$u_back = $this->u_action . "&amp;s=$season&amp;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('<br />', $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}&amp;action=add&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 . "&amp;s=$season&amp;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 .= '<option value="' . $row['matchday'] . '"' . $selected . '>' . $matchday_name . '</option>';
$matchdays++;
}
$db->sql_freeresult($result);
if (!$matchdays)
{
trigger_error($user->lang['NO_MATCHDAYS'] . adm_back_link($this->u_action . "&amp;s=$season&amp;l=$league"), E_USER_WARNING);
}
}
$u_back = $this->u_action . "&amp;s=$season&amp;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('<br />', $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}&amp;action=$action&amp;s=$season&amp;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}&amp;action=edit&amp;s=" . $season . "&amp;l=" .$league . "&amp;t=" .$row_team['team_id'],
'U_DELETE' => ($allow_delete) ? "{$this->u_action}&amp;action=delete&amp;s=" . $season . "&amp;l=" . $league . "&amp;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 : '',
)
);
}
}
?>

25
acp/update_info.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
*
* @package phpBB Extension - Football Football
* @copyright (c) 2016 football (http://football.bplaced.net)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace football\football\acp;
class update_info
{
function module()
{
return array(
'filename' => '\football\football\acp\update_module',
'title' => 'ACP_FOOTBALL_UPDATE_MANAGEMENT',
'version' => '0.9.4',
'modes' => array(
'manage' => array('title' => 'ACP_FOOTBALL_UPDATE_MANAGE', 'auth' => 'acl_a_football_plan', 'cat' => array('ACP_FOOTBALL_UPDATE')),
),
);
}
}

1462
acp/update_module.php Normal file

File diff suppressed because it is too large Load Diff