'post', 'mode' => 'mode', 'valsubm' => 'valsubm', 'cansubm' => 'cansubm');
while( list($var, $param) = @each($params) )
{
if ( !empty($HTTP_POST_VARS[$param]) || !empty($HTTP_GET_VARS[$param]) )
{
$$var = ( !empty($HTTP_POST_VARS[$param]) ) ? htmlspecialchars($HTTP_POST_VARS[$param]) : htmlspecialchars($HTTP_GET_VARS[$param]);
}
else
{
$$var = '';
}
}
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
if ( !$userdata['session_logged_in'] )
{
if (($mode == "stats") || ($mode == "running") || ($mode == "validate") || ($mode == "played") || ($mode == "mygames") || ($mode == "challenge") || ($mode == "cancel"))
{
switch( $mode )
{
case 'stats':
$redirect = "mode=stats";
break;
case 'running':
$redirect = "mode=running";
break;
case 'validate':
$redirect = "mode=validate";
break;
case 'played':
$redirect = "mode=played";
break;
case 'mygames':
$redirect = "mode=mygames";
break;
case 'challenge':
$redirect = "mode=challenge";
break;
case 'cancel':
$redirect = "mode=cancel";
break;
}
redirect(append_sid("login.$phpEx?redirect=games.$phpEx&" . $redirect, true));
exit;
}
else
{
$mode = "scores";
}
}
if ( empty($mode) )
{
$mode = "scores";
}
//
// Check if the users is authorised to moderate stuff in the games mod
//
if ( $userdata['user_level'] == ADMIN )
{
$is_mod = TRUE;
}
else
{
$is_mod = 0;
// Get groups authorised to moderate
$sql = "SELECT group_id
FROM " . GROUPS_TABLE . "
WHERE group_auth_mod_games = 1";
if ( $result = $db->sql_query($sql) )
{
$auth_mod_group_ids = array();
while ( $row = $db->sql_fetchrow($result) )
{
$auth_mod_group_ids[] = $row['group_id'];
}
}
// Get users who are in a group authorised to moderate
if ( !empty($auth_mod_group_ids) )
{
for($i = 0; $i < count($auth_mod_group_ids); $i++)
{
$sql = "SELECT user_id
FROM " . USER_GROUP_TABLE . "
WHERE group_id = " . $auth_mod_group_ids[$i];
if ( $result = $db->sql_query($sql) )
{
while ( $row = $db->sql_fetchrow($result) )
{
// If users is in a group authorised to moderate
if ( $userdata['user_id'] == $row['user_id'] )
{
$is_mod = TRUE;
}
}
}
}
}
}
//
// Start get all authorised users and their info
//
// Get all authorised users, when all registered users may play games (no particular order)
$auth_users = array();
if ( $board_config['games_auth_mode'] == '1' )
{
$order_by = "user_id";
$auth_users = get_users_ids($order_by);
}
// Get all authorised users, when only 1 (or more) group(s) may play games
else if ( $board_config['games_auth_mode'] == '2' )
{
// Get authorised groups
$sql = "SELECT group_id
FROM " . GROUPS_TABLE . "
WHERE group_auth_games = 1";
if ( $result = $db->sql_query($sql) )
{
$auth_group_ids = array();
while ( $row = $db->sql_fetchrow($result) )
{
$auth_group_ids[] = $row['group_id'];
}
}
// Get users who are in an authorised group
if ( !empty($auth_group_ids) )
{
for($i = 0; $i < count($auth_group_ids); $i++)
{
$sql = "SELECT user_id
FROM " . USER_GROUP_TABLE . "
WHERE group_id = " . $auth_group_ids[$i];
if ( $result = $db->sql_query($sql) )
{
while ( $row = $db->sql_fetchrow($result) )
{
// Add user if he is not yet in the array of authorised users (prevent adding twice)
$add = '1';
for($j = 0; $j < count($auth_users); $j++)
{
if ( $row['user_id'] == $auth_users[$j] )
{
$add = '0';
}
}
if ( $add == '1' )
{
$auth_users[] = $row['user_id'];
}
}
}
}
}
}
// Give error message when no users are authorised to play games (nothing to display)
if (count($auth_users) == 0)
{
message_die(GENERAL_MESSAGE, $lang['Games_No_Auth_Users'] );
}
// Select all authorised users and all available gamers
$j = 0;
for($i = 0; $i < count($auth_users); $i++)
{
if ($i == 0)
{
$sql_where = "user_id = " . $auth_users[$i];
}
else
{
$sql_where .= " OR user_id = " . $auth_users[$i];
}
if ( $userdata['user_id'] != $auth_users[$i] )
{
if ($j == 0)
{
$sql_2_where = "user_id = " . $auth_users[$i];
$j++;
}
else
{
$sql_2_where .= " OR user_id = " . $auth_users[$i];
}
}
}
// Get all info of authorised users
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE " . $sql_where . "
ORDER BY games_points DESC, games_won DESC, games_lost ASC, username";
if ( $result = $db->sql_query($sql) )
{
$auth_users_info = array();
while ( $row = $db->sql_fetchrow($result) )
{
$auth_users_info[] = $row;
}
}
// Get all info of users available for playing a new game
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE (" . $sql_2_where . ")
AND games_current_game = '-1'";
if ( $result = $db->sql_query($sql) )
{
$auth_users_not_ingame = array();
while ( $row = $db->sql_fetchrow($result) )
{
$auth_users_not_ingame[] = $row;
}
}
//
// End get all authorised users and their info
//
switch( $mode )
{
//
//===========================[ SHOW SCORES ]====================================
//
case 'scores':
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_scores_body.tpl'
)
);
$page_title = $lang['Games_Scores_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Assign the vars
//
for ($i = 0; $i < count($auth_users_info); $i++)
{
$j = $i + 1;
if ( $auth_users_info[$i]['games_current_game'] == '-1' )
{
$in_game = $lang['No'];
}
else
{
$in_game = $lang['Yes'];
}
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('scores', array(
'SCORES_NUMBER' => $j,
'SCORES_USERNAME' => $auth_users_info[$i]['username'],
'SCORES_INGAME' => $in_game,
'SCORES_POINTS' => $auth_users_info[$i]['games_points'],
'SCORES_WON' => $auth_users_info[$i]['games_won'],
'SCORES_LOST' => $auth_users_info[$i]['games_lost'],
'SCORES_RANK' => get_games_rank($auth_users_info[$i]['games_points']),
'SCORES_ROW_COLOR' => '#' . $row_color,
'SCORES_ROW_CLASS' => $row_class
)
);
}
$template->assign_vars(array(
'L_SCORES_USERNAME' => $lang['Games_Scores_Username'],
'L_SCORES_INGAME' => $lang['Games_Scores_Ingame'],
'L_SCORES_POINTS' => $lang['Games_Scores_Points'],
'L_SCORES_WON' => $lang['Games_Scores_Won'],
'L_SCORES_LOST' => $lang['Games_Scores_Lost'],
'L_SCORES_RANK' => $lang['Games_Scores_Rank'],
'L_GAMES_SCORES' => $lang['Games_Scores']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
//
//===========================[ SHOW STATISTICS ]========================================
//
case 'stats':
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_stats_body.tpl'
)
);
$page_title = $lang['Games_Stats_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Pull some general stats/settings
//
// Get total played games
$sql = "SELECT COUNT(game_id) AS total
FROM " . GAMES_TABLE . "
WHERE winner_id != ''
AND winner_b_id != ''";
if ($result = $db->sql_query($sql))
{
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$total_played_games = $row['total'];
}
// Get total running games
$sql = "SELECT COUNT(game_id) AS total
FROM " . GAMES_TABLE . "
WHERE winner_id = ''
OR winner_b_id = ''";
if ($result = $db->sql_query($sql))
{
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$total_running_games = $row['total'];
}
$win_lost_perc = $board_config['games_win_lost_percentage'] . "%";
//
// Calculate some stats
//
$sql_where = implode(' OR user_id = ', $auth_users);
$sql_where = "user_id = " . $sql_where;
$sql_limit = 5;
//
// Top 5 Points
$sql_order = "games_points DESC, games_won DESC, games_lost ASC, username";
$stats_top5_points = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Worst 5 Points
$sql_order = "games_points ASC, games_won ASC, games_lost DESC, username";
$stats_worst5_points = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Top 5 Number Played Games
$sql_order = "games_won + games_lost DESC, games_won DESC, games_lost ASC, username";
$stats_top5_played = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Worst 5 Number Played Games
$sql_order = "games_won + games_lost ASC, games_won ASC, games_lost DESC, username";
$stats_worst5_played = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Top 5 Games Won
$sql_order = "games_won DESC, games_lost ASC, username";
$stats_top5_won = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Top 5 Games Lost
$sql_order = "games_lost DESC, games_won ASC, username";
$stats_top5_lost = get_games_stats($sql_where, $sql_order, $sql_limit);
//
// Assign the vars
//
for ($i = 0; $i < count($stats_top5_points); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('points', array(
'TOP5_NUMBER' => $i + 1,
'TOP5_USERNAME' => $stats_top5_points[$i]['username'],
'TOP5_POINTS' => $stats_top5_points[$i]['games_points'],
'TOP5_WON' => $stats_top5_points[$i]['games_won'],
'TOP5_LOST' => $stats_top5_points[$i]['games_lost'],
'WORST5_NUMBER' => $i + 1,
'WORST5_USERNAME' => $stats_worst5_points[$i]['username'],
'WORST5_POINTS' => $stats_worst5_points[$i]['games_points'],
'WORST5_WON' => $stats_worst5_points[$i]['games_won'],
'WORST5_LOST' => $stats_worst5_points[$i]['games_lost'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class
)
);
}
for ($i = 0; $i < count($stats_top5_played); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('played', array(
'TOP5_NUMBER' => $i + 1,
'TOP5_USERNAME' => $stats_top5_played[$i]['username'],
'TOP5_TOTAL' => $stats_top5_played[$i]['games_won'] + $stats_top5_played[$i]['games_lost'],
'TOP5_WON' => $stats_top5_played[$i]['games_won'],
'TOP5_LOST' => $stats_top5_played[$i]['games_lost'],
'WORST5_NUMBER' => $i + 1,
'WORST5_USERNAME' => $stats_worst5_played[$i]['username'],
'WORST5_TOTAL' => $stats_worst5_played[$i]['games_won'] + $stats_worst5_played[$i]['games_lost'],
'WORST5_WON' => $stats_worst5_played[$i]['games_won'],
'WORST5_LOST' => $stats_worst5_played[$i]['games_lost'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class
)
);
}
for ($i = 0; $i < count($stats_top5_won); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('winlost', array(
'TOP5_WON_NUMBER' => $i + 1,
'TOP5_WON_USERNAME' => $stats_top5_won[$i]['username'],
'TOP5_WON_WON' => $stats_top5_won[$i]['games_won'],
'TOP5_WON_LOST' => $stats_top5_won[$i]['games_lost'],
'TOP5_LOST_NUMBER' => $i + 1,
'TOP5_LOST_USERNAME' => $stats_top5_lost[$i]['username'],
'TOP5_LOST_LOST' => $stats_top5_lost[$i]['games_lost'],
'TOP5_LOST_WON' => $stats_top5_lost[$i]['games_won'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class
)
);
}
$template->assign_vars(array(
'L_GEN_SET_STATS' => $lang['Games_Stats_Set_Stats'],
'L_TOTAL_PLAYED_GAMES' => $lang['Games_Stats_Total_Played'],
'L_TOTAL_RUNNING_GAMES' => $lang['Games_Stats_Total_Running'],
'L_WIN_LOST_PERC' => $lang['Games_Stats_Win_Lost_Perc'],
'L_MIN_POINTS' => $lang['Games_Stats_Minimum_Points'],
'L_MAX_CHALLENGES' => $lang['Games_Stats_Max_Challenges'],
'L_USERNAME' => $lang['Games_Scores_Username'],
'L_POINTS' => $lang['Games_Scores_Points'],
'L_WON' => $lang['Games_Scores_Won'],
'L_LOST' => $lang['Games_Scores_Lost'],
'L_TOTAL' => $lang['Games_Stats_Total'],
'L_TOP5' => $lang['Games_Stats_Top5'],
'L_WORST5' => $lang['Games_Stats_Worst5'],
'L_TOP5_WIN' => $lang['Games_Stats_Top5_Win'],
'L_TOP5_LOST' => $lang['Games_Stats_Top5_Lost'],
'L_POINTS' => $lang['Games_Stats_Points'],
'L_PLAYED' => $lang['Games_Stats_Played'],
'L_WIN_LOST' => $lang['Games_Stats_Win_Lost'],
'TOTAL_PLAYED_GAMES' => $total_played_games,
'TOTAL_RUNNING_GAMES' => $total_running_games,
'WIN_LOST_PERC' => $win_lost_perc,
'MIN_POINTS' => $board_config['games_minimum'],
'MAX_CHALLENGES' => $board_config['games_max_challenges']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
//
//===========================[ SHOW RUNNING GAMES ]=============================
//
case 'running':
//
// Get some database information
//
$forum_id = GAMES_FORUM;
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_running_body.tpl'
)
);
$page_title = $lang['Games_Running_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Get some information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE;
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] != $row['winner_b_id']) || (empty($row['winner_id']) && empty($row['winner_b_id'])) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_No_Running_Games'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
while ( $row = $db->sql_fetchrow($result) )
{
$player_id = $row['player_id'];
$player_b_id = $row['player_b_id'];
$player_name = get_games_username($player_id);
$player_b_name = get_games_username($player_b_id);
$winner_id = $row['winner_id'];
$winner_b_id = $row['winner_b_id'];
$winner_name = get_games_username($winner_id);
$winner_b_name = get_games_username($winner_b_id);
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$player_name = '' . $player_name . '';
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$player_b_name = '' . $player_b_name . '';
if ( empty($winner_id) )
{
if ( $player_id == $userdata['user_id'] )
{
$winner_text_or_button = '
';
}
else
{
$winner_text_or_button = $lang['Games_Not_Validated_Yet'];
}
}
else
{
$winner_text_or_button = $winner_name;
}
if ( empty($winner_b_id) )
{
if ( $player_b_id == $userdata['user_id'] )
{
$winner_b_text_or_button = '
';
}
else
{
$winner_b_text_or_button = $lang['Games_Not_Validated_Yet'];
}
}
else
{
$winner_b_text_or_button = $winner_b_name;
}
$row_color = ( ($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( ($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('runningrow', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'ROW_NUMBER' => $row['game_id'],
'START_DATE' => $msg_date,
'PLAYER_NAME' => $player_name,
'PLAYER_B_NAME' => $player_b_name,
'WINNER' => $winner_text_or_button,
'WINNER_B' => $winner_b_text_or_button,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
if ( $is_mod )
{
$mod_validate_button = '
';
$template->assign_block_vars('runningrow.ismod', array(
'MOD_VALIDATE_WINNER' => $mod_validate_button,
)
);
}
}
$db->sql_freeresult($result);
if ( $is_mod )
{
$template->assign_block_vars('ismod', array());
}
else
{
$template->assign_block_vars('isnotmod', array());
}
}
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_No_Running_Games'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
//
// Assign the vars
//
$template->assign_vars(array(
'L_GAME_INFO' => $lang['Games_Check_Info'],
'L_START_DATE' => $lang['Date'],
'L_CHALLENGER' => $lang['Games_Challenger'],
'L_OPPONENT' => $lang['Games_Opponent'],
'L_VALIDATE_WINNER' => $lang['Games_Validate_Winner_By_Challenger'],
'L_VALIDATE_WINNER_B' => $lang['Games_Validate_Winner_By_Opponent'],
'L_MOD_VALIDATE' => $lang['Games_Mod_Validate'],
'L_GO_TO_GAME_INFO' => $lang['Games_Go_To_Game_Info']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
//
//===========================[ SHOW VALIDATE PAGE ]============================= !!!!!!nog opkuisen, bv reply enkel maken als topic nog bestaat, zoniet moet alles toch kunnen doorlopen
//
case 'validate':
//
// Check if topic and forum still excist
//
if ( !empty($HTTP_POST_VARS['validate_single_user']) )
{
$game_id = $HTTP_POST_VARS['validate_single_user'];
}
else if ( !empty($HTTP_POST_VARS['validate_game']) )
{
$game_id = $HTTP_POST_VARS['validate_game'];
}
else
{
die('Hacking attempt');
}
$sql = "SELECT topic_id
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$game_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$topic_id = $game_info['topic_id'];
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']);
}
// Check if the topic still excists and if forum is not locked,
// so we would know if it is still possible to post a reply
$post_reply = TRUE;
$sql = "SELECT topic_id, forum_id
FROM " . TOPICS_TABLE . "
WHERE topic_id = " . $topic_id;
if ( $result = $db->sql_query($sql) )
{
$topic_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql = "SELECT *
FROM " . FORUMS_TABLE . "
WHERE forum_id = " . $topic_info['forum_id'];
if ( $result = $db->sql_query($sql) )
{
$forum_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ( $forum_info['forum_status'] == FORUM_LOCKED )
{
$post_reply = 0;
}
}
else
{
$post_reply = 0;
}
}
else
{
$post_reply = 0;
}
// --------------------
// What shall we do?
//
if ( $valsubm )
{
$message = ( !empty($HTTP_POST_VARS['message']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['message']))) : '';
$winner_id = ( !empty($HTTP_POST_VARS['winner_id']) ) ? $HTTP_POST_VARS['winner_id'] : '';
$sql='';
// When a player is validating
if ( !empty($HTTP_POST_VARS['validate_single_user']) && empty($HTTP_POST_VARS['validate_game']) )
{
$game_id = $HTTP_POST_VARS['validate_single_user'];
$sql = "SELECT player_id, player_b_id, winner_id, winner_b_id
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$game_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']);
}
$sql = '';
if ( empty($game_info['winner_id']) && empty($game_info['winner_b_id']) )
{
if ( $userdata['user_id'] == $game_info['player_id'] )
{
$sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", comment = '" . $message . "' WHERE game_id = " . $game_id;
}
else if ( $userdata['user_id'] == $game_info['player_b_id'] )
{
$sql = "UPDATE " . GAMES_TABLE . " SET winner_b_id = " . $winner_id . ", comment_b = '" . $message . "' WHERE game_id = " . $game_id;
}
}
else if ( empty($game_info['winner_id']) && !empty($game_info['winner_b_id']) )
{
if ( $userdata['user_id'] == $game_info['player_id'] )
{
$sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", comment = '" . $message . "' WHERE game_id = " . $game_id;
}
}
else if ( !empty($game_info['winner_id']) && empty($game_info['winner_b_id']) )
{
if ( $userdata['user_id'] == $game_info['player_b_id'] )
{
$sql = "UPDATE " . GAMES_TABLE . " SET winner_b_id = " . $winner_id . ", comment_b = '" . $message . "' WHERE game_id = " . $game_id;
}
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Validated_Yet']);
}
}
// When moderator is validating
else if ( !empty($HTTP_POST_VARS['validate_game']) && empty($HTTP_POST_VARS['validate_single_user']) )
{
$game_id = $HTTP_POST_VARS['validate_game'];
if ( !$is_mod )
{
die('Hacking attempt');
}
$sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", winner_b_id = " . $winner_id . ", comment = '" . $message . "', comment_b = '" . $message . "' WHERE game_id = " . $game_id;
}
if ( empty($sql) )
{
die('Hacking attempt');
}
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in games table update', '', __LINE__, __FILE__, $sql);
}
// If both winners are validated, end the game (= make reply in topic and change some database stuff)
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$game_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']);
}
if ( $game_info['winner_id'] == $game_info['winner_b_id'] )
{
//
// Set some vars
//
$post_data = array();
$post_data['first_post'] = false;
$post_data['last_post'] = true;
$post_data['has_poll'] = false;
$post_data['edit_poll'] = false;
$post_data['last_topic'] = false;
$bbcode_on = 1;
$bbcode_uid = 0;
$html_on = 0;
$smilies_on = 0;
$error_msg = '';
$notify_user = TRUE;
$attach_sig = 0;
$temp_mode = "reply";
$return_meta = '';
$return_message = $lang['Games_Finished'] . '
' . $lang['Games_Corresp_Topic_Not_Excists'] . '
' . sprintf($lang['Games_Click_Played_Games'], '', '');
$topic_type = POST_NORMAL;
$username = $userdata['username'];
$post_username = $username;
$poll_title = '';
$subject = '';
$forum_id = GAMES_FORUM;
// Change by both players their currentgame, won, lost and points
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = " . $game_info['player_id'];
if ( $result = $db->sql_query($sql) )
{
$player_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = " . $game_info['player_b_id'];
if ( $result = $db->sql_query($sql) )
{
$player_b_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
if ( $player_info['user_id'] == $game_info['winner_id'] )
{
$games_points = $game_info['player_points_before'] + (( $game_info['player_b_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 );
$games_b_points = $game_info['player_b_points_before'] - (( $game_info['player_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 );
$games_won = $player_info['games_won'] + 1;
$games_lost = $player_info['games_lost'];
$games_b_won = $player_b_info['games_won'];
$games_b_lost = $player_b_info['games_lost'] + 1;
}
else if ( $player_b_info['user_id'] == $game_info['winner_id'] )
{
$games_points = $game_info['player_points_before'] - (( $game_info['player_b_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 );
$games_b_points = $game_info['player_b_points_before'] + (( $game_info['player_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 );
$games_won = $player_info['games_won'];
$games_lost = $player_info['games_lost'] + 1;
$games_b_won = $player_b_info['games_won'] + 1;
$games_b_lost = $player_b_info['games_lost'];
}
if ( $games_points < $board_config['games_minimum'] )
{
$games_points = $board_config['games_minimum'];
}
if ( $games_b_points < $board_config['games_minimum'] )
{
$games_b_points = $board_config['games_minimum'];
}
$sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_points . ", games_won = " . $games_won . ", games_lost = " . $games_lost . ", games_current_game = '-1' WHERE user_id = " . $game_info['player_id'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = " . $game_info['player_id'];
if ( $result = $db->sql_query($sql) )
{
$player_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
$sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_b_points . ", games_won = " . $games_b_won . ", games_lost = " . $games_b_lost . ", games_current_game = '-1' WHERE user_id = " . $game_info['player_b_id'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = " . $game_info['player_b_id'];
if ( $result = $db->sql_query($sql) )
{
$player_b_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
// Reply in the topic of the game if it is still possible
if ( $post_reply )
{
// use reason of moderator as message
if ( !empty($HTTP_POST_VARS['validate_game']) )
{
$reason = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : '';
$message = "[color=green][u]" . $lang['Games_Has_Won'] . "[/u][/color] " . get_games_username($game_info['winner_id']) . "\n\r\n\r[color=green][u]" . $lang['Games_Points_After'] . "[/u][/color]\n\r";
$message .= get_games_username($player_info['user_id']) . ": " . $player_info['games_points'] . " punten,\n\r";
$message .= get_games_username($player_b_info['user_id']) . ": " . $player_b_info['games_points'] . " punten,\n\r";
$message .= "[color=green][u]" . $lang['Games_Comment_Reason'] . "[/u][/color]\n\r" . $reason;
}
// use combination of comments of both players as message
if ( !empty($HTTP_POST_VARS['validate_single_user']) )
{
$message = "[color=green][u]" . $lang['Games_Has_Won'] . "[/u][/color] " . get_games_username($game_info['winner_id']) . "\n\r\n\r[color=green][u]" . $lang['Games_Points_After'] . "[/u][/color]\n\r";
$message .= get_games_username($player_info['user_id']) . ": " . $player_info['games_points'] . " punten,\n\r";
$message .= get_games_username($player_b_info['user_id']) . ": " . $player_b_info['games_points'] . " punten,\n\r";
$message .= "[color=green][u]" . $lang['Games_Comment_Challenger'] . "[/u][/color]\n\r" . $game_info['comment'] . "\n\r[color=green][u]" . $lang['Games_Comment_Opponent'] . "[/u][/color]\n\r" . $game_info['comment_b'];
}
prepare_post($temp_mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
if ( $error_msg == '' )
{
// First post in topic of the to-validate-game: change subject
$sql = "SELECT games_first_post_id, topic_id
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$game_first_post_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$game_first_post_id = $game_first_post_info['games_first_post_id'];
$topic_id = $game_first_post_info['topic_id'];
$sql = "SELECT post_subject
FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = " . $game_first_post_id;
if ( $result = $db->sql_query($sql) )
{
$post_first_post_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$post_first_post_info['post_subject'] = str_replace($lang['Games_Subject_Prefix_Running'], '', $post_first_post_info['post_subject']);
$post_first_post_subject = $lang['Games_Subject_Prefix_Played'];
$post_first_post_subject .= $post_first_post_info['post_subject'];
$sql_1 = "UPDATE " . POSTS_TEXT_TABLE . " SET post_subject = '" . $post_first_post_subject . "' WHERE post_id = " . $game_first_post_id;
$sql_2 = "UPDATE " . TOPICS_TABLE . " SET topic_title = '" . $post_first_post_subject . "' WHERE topic_id = " . $topic_id;
if (!$db->sql_query($sql_1, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
if (!$db->sql_query($sql_2, END_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$post_first_post_message = "";
// add_search_words('single', $game_first_post_id, stripslashes($post_first_post_message), stripslashes($post_first_post_subject));
}
}
submit_post($temp_mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
make_post_autom($post_id);
$user_id = $userdata['user_id'];
update_post_stats($temp_mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
user_notification($temp_mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
// Change cookies
$tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
$tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) )
{
asort($tracking_topics);
unset($tracking_topics[key($tracking_topics)]);
}
$tracking_topics[$topic_id] = time();
setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
// Show message with link to topic after posting new game
$return_meta = '';
$return_message = $lang['Games_Finished'] . '
' . sprintf($lang['Games_Click_View_Reply'], '', '') . '
' . sprintf($lang['Games_Click_Played_Games'], '', '');
}
}
// $template->assign_vars(array(
// 'META' => $return_meta)
// );
message_die(GENERAL_MESSAGE, $return_message);
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_Validated_Other_Not'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
// $template->assign_vars(array(
// 'META' => $confirm_meta)
// );
message_die(GENERAL_MESSAGE, $confirm_message);
}
}
else
{
//
// User default entry point
//
// When a user wants to validate a game
if ( !empty($HTTP_POST_VARS['validate_single_user']) && empty($HTTP_POST_VARS['validate_game']) )
{
$game_id = $HTTP_POST_VARS['validate_single_user'];
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$row = $db->sql_fetchrow($result);
$games_player_vs_player = $lang['Games_Subject_part1'];
$games_player_vs_player .= $row['game_id'];
$games_player_vs_player .= ': ';
$games_player_vs_player .= get_games_username($row['player_id']);
$games_player_vs_player .= $lang['Games_Subject_part2'];
$games_player_vs_player .= get_games_username($row['player_b_id']);
$select_winner_list = '';
$message = '';
$hidden_form_fields = '';
$hidden_form_fields .= '';
$db->sql_freeresult($result);
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']);
}
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_validate_body.tpl')
);
$page_title = $lang['Games_Validate_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Output the data to the template
//
$template->assign_vars(array(
'COMMENT' => $message,
'L_POST_A' => $games_player_vs_player,
'L_WINNER' => $lang['Games_Select_Winner'],
'L_COMMENT_BODY' => $lang['Games_Comment_Body'],
'L_EMPTY_MESSAGE' => $lang['Games_Validate_Comment_Tip'],
'L_GAMES_COMMENT_TIP' => $lang['Games_Posting_Tip'],
'L_SUBMIT' => $lang['Submit'],
'S_WINNER_SELECT' => $select_winner_list,
'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields,
'S_POST_ACTION' => append_sid("games.$phpEx?mode=validate"))
);
}
// When an moderator wants to validate a game
else if ( !empty($HTTP_POST_VARS['validate_game']) && empty($HTTP_POST_VARS['validate_single_user']) )
{
$game_id = $HTTP_POST_VARS['validate_game'];
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$row = $db->sql_fetchrow($result);
$games_player_vs_player = $lang['Games_Subject_part1'];
$games_player_vs_player .= $row['game_id'];
$games_player_vs_player .= ': ';
$games_player_vs_player .= get_games_username($row['player_id']);
$games_player_vs_player .= $lang['Games_Subject_part2'];
$games_player_vs_player .= get_games_username($row['player_b_id']);
$select_winner_list = '';
$message = '';
$hidden_form_fields = '';
$hidden_form_fields .= '';
$db->sql_freeresult($result);
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']);
}
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_validate_mod_body.tpl')
);
$page_title = $lang['Games_Validate_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Output the data to the template
//
$template->assign_vars(array(
'REASON' => $message,
'L_POST_A' => $games_player_vs_player,
'L_WINNER' => $lang['Games_Select_Winner'],
'L_REASON_BODY' => $lang['Games_Reason_Body'],
'L_EMPTY_MESSAGE' => $lang['Games_Validate_Comment_Tip'],
'L_GAMES_REASON_TIP' => $lang['Games_Reason_Tip'],
'L_SUBMIT' => $lang['Submit'],
'S_WINNER_SELECT' => $select_winner_list,
'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields,
'S_POST_ACTION' => append_sid("games.$phpEx?mode=validate"))
);
}
else
{
die('Hacking attempt');
}
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
break;
//
//===========================[ SHOW PLAYED GAMES ]==============================
//
case 'played':
//
// Get some common database information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE;
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] == $row['winner_b_id']) && !empty($row['winner_id']) && !empty($row['winner_b_id']) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
else
{
message_die(GENERAL_MESSAGE, "Problems getting users out of database" );
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
$player_id = $row['player_id'];
$player_b_id = $row['player_b_id'];
$challenger = get_games_username($player_id);
$opponent = get_games_username($player_b_id);
$winner = get_games_username($row['winner_id']);
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$challenger = '' . $challenger . '';
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$opponent = '' . $opponent . '';
$row_color = ( !($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( !($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('playedrow', array(
'ROW_NUMBER' => $row['game_id'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'START_DATE' => $msg_date,
'CHALLENGER' => $challenger,
'OPPONENT' => $opponent,
'WINNER' => $winner,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
$i++;
}
$db->sql_freeresult($result);
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_No_Played_Games'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_No_Played_Games'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_played_body.tpl'
)
);
$page_title = $lang['Games_Played_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Assign the vars
//
$template->assign_vars(array(
'L_GAME_INFO' => $lang['Games_Check_Info'],
'L_START_DATE' => $lang['Date'],
'L_CHALLENGER' => $lang['Games_Challenger'],
'L_OPPONENT' => $lang['Games_Opponent'],
'L_WINNER' => $lang['Games_Winner'],
'L_GO_TO_GAME_INFO' => $lang['Games_Go_To_Game_Info']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
//
//===========================[ SHOW MY GAMES ]==================================
//
case 'mygames':
//=====[ RUNNING GAME PART ]=====
//
// Get some database information
//
$forum_id = GAMES_FORUM;
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_my_games_body.tpl'
)
);
$page_title = $lang['Games_My_Games_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Get some information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE . "
WHERE player_id = " . $userdata['user_id'] . "
OR player_b_id = " . $userdata['user_id'];
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] != $row['winner_b_id']) || (empty($row['winner_id']) && empty($row['winner_b_id'])) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
$row = $db->sql_fetchrow($result);
$player_name = get_games_username($row['player_id']);
$player_b_name = get_games_username($row['player_b_id']);
$player_id = $row['player_id'];
$player_b_id = $row['player_b_id'];
$winner_name = get_games_username($row['winner_id']);
$winner_b_name = get_games_username($row['winner_b_id']);
$winner_id = $row['winner_id'];
$winner_b_id = $row['winner_b_id'];
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$player_name = '' . $player_name . '';
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$player_b_name = '' . $player_b_name . '';
if ( empty($winner_id) )
{
if ( $player_id == $userdata['user_id'] )
{
$winner_text_or_button = '
';
}
else
{
$winner_text_or_button = $lang['Games_Not_Validated_Yet'];
}
}
else
{
$winner_text_or_button = $winner_name;
}
if ( empty($winner_b_id) )
{
if ( $player_b_id == $userdata['user_id'] )
{
$winner_b_text_or_button = '
';
}
else
{
$winner_b_text_or_button = $lang['Games_Not_Validated_Yet'];
}
}
else
{
$winner_b_text_or_button = $winner_b_name;
}
$row_color = ( ($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( ($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('runningyes', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'ROW_NUMBER' => $row['game_id'],
'START_DATE' => $msg_date,
'PLAYER_NAME' => $player_name,
'PLAYER_B_NAME' => $player_b_name,
'WINNER' => $winner_text_or_button,
'WINNER_B' => $winner_b_text_or_button,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
$db->sql_freeresult($result);
}
}
else
{
$template->assign_block_vars('runningno.row', array(
'ROW_COLOR' => '#' . $theme['td_color1'],
'ROW_CLASS' => $theme['td_class1'],
'L_NO_PENDING_GAME' => $lang['Games_No_My_Running_Game'],
)
);
}
//=====[ PLAYED GAMES PART ]=====
//
// Get some database information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE . "
WHERE player_id = " . $userdata['user_id'] . "
OR player_b_id = " . $userdata['user_id'];
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] == $row['winner_b_id']) && !empty($row['winner_id']) && !empty($row['winner_b_id']) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
$player_id = $row['player_id'];
$player_b_id = $row['player_b_id'];
$challenger = get_games_username($player_id);
$opponent = get_games_username($player_b_id);
$winner = get_games_username($row['winner_id']);
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
if ( $player_id != '-2')
{
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$challenger = '' . $challenger . '';
}
if ( $player_b_id != '-2')
{
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$opponent = '' . $opponent . '';
}
$row_color = ( !($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( !($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('playedyes', array(
'ROW_NUMBER' => $row['game_id'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'START_DATE' => $msg_date,
'CHALLENGER' => $challenger,
'OPPONENT' => $opponent,
'WINNER' => $winner,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
$i++;
}
$db->sql_freeresult($result);
}
}
else
{
$template->assign_block_vars('playedno.row', array(
'ROW_COLOR' => '#' . $theme['td_color1'],
'ROW_CLASS' => $theme['td_class1'],
'L_NO_PLAYED_GAMES' => $lang['Games_No_My_Played_Games'],
)
);
}
//
// Assign the vars
//
$template->assign_vars(array(
'L_GAME_INFO' => $lang['Games_Check_Info'],
'L_START_DATE' => $lang['Date'],
'L_CHALLENGER' => $lang['Games_Challenger'],
'L_OPPONENT' => $lang['Games_Opponent'],
'L_VALIDATE_WINNER' => $lang['Games_Validate_Winner_By_Challenger'],
'L_VALIDATE_WINNER_B' => $lang['Games_Validate_Winner_By_Opponent'],
'L_GO_TO_GAME_INFO' => $lang['Games_Go_To_Game_Info'],
'L_WINNER' => $lang['Games_Winner']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
//
//===========================[ SHOW CHALLENGE PAGE ]============================
//
case 'challenge':
//
// Start check authorised to start new games + flood control
//
$user_auth_games = 0;
for($i = 0; $i < count($auth_users); $i++)
{
if ( $userdata['user_id'] == $auth_users[$i] )
{
$user_auth_games = 1;
}
}
if ($user_auth_games == 0)
{
$confirm_meta = '';
$confirm_message = $lang['Games_Not_Authorised'];
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
// Flood control. Check if user has not exceeded the max allowed number of challenges PER MONTH.
if ( intval($board_config['games_max_challenges']) != 0 )
{
$current_time = time();
$flood_time = $current_time - 2592000;
$sql = "SELECT COUNT(game_id) AS total
FROM " . GAMES_TABLE . "
WHERE player_name = " . $userdata['username'] . "
AND game_date > " . $flood_time;
if ($result = $db->sql_query($sql))
{
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ( $row['total'] >= intval($board_config['games_max_challenges']) )
{
$message = sprintf($lang['Games_Flood_Error'], $board_config['games_max_challenges']);
$message .= '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
message_die(GENERAL_MESSAGE, $message);
}
}
}
//
// End check authorised to start new games + flood control
//
//
// Check if the forum id is still correct and if the forum is unlocked
//
$forum_id = GAMES_FORUM;
$sql = "SELECT *
FROM " . FORUMS_TABLE . "
WHERE forum_id = " . $forum_id;
if ( $result = $db->sql_query($sql) )
{
$post_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ( $post_info['forum_status'] == FORUM_LOCKED )
{
message_die(GENERAL_MESSAGE, $lang['Games_Forum_locked']);
}
}
else
{
message_die(GENERAL_MESSAGE, $lang['Games_Forum_not_exist']);
}
//
// Set some vars
//
$topic_id = '';
$post_id = '';
$poll_id = '';
$bbcode_on = 1;
$bbcode_uid = 0;
$html_on = 0;
$smilies_on = 0;
$error_msg = '';
$notify_user = TRUE;
$attach_sig = 0;
$post_data = array();
$post_data['first_post'] = true;
$post_data['last_post'] = false;
$post_data['has_poll'] = false;
$post_data['edit_poll'] = false;
$post_data['last_topic'] = true;
// --------------------
// What shall we do?
//
if ( $submit )
{
//
// Submit the new game (newtopic)
//
$return_message = '';
$return_meta = '';
$username = $userdata['username'];
$opponent_id = ( !empty($HTTP_POST_VARS['opponent']) ) ? $HTTP_POST_VARS['opponent'] : '';
$opponent_name = get_games_username($opponent_id);
$opponent_points = get_games_user_points($opponent_id);
$subject = $lang['Games_Subject_Prefix_Running'] . " ";
$subject .= $lang['Games_Subject_part1'];
$subject .= get_next_game_id();
$subject .= ': ';
$subject .= $username;
$subject .= $lang['Games_Subject_part2'];
$subject .= $opponent_name;
$game_description = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : '';
$message = "\n\r\n\r[color=green][u]" . $lang['Games_Description'] . "[/u][/color]\n\r" . $game_description . "\n\r\n\r[color=green][u]" . $lang['Games_Points_Before_Match'] . "[/u][/color]\n\r" . $username . ": " . $userdata['games_points'] . " punten, " . $opponent_name . ": " . $opponent_points . " punten.";
$topic_type = POST_NORMAL;
$poll_title = $lang['Games_Poll_Question'];
$poll_length = '';
$poll_option_text = array();
$poll_option_text[] = htmlspecialchars(trim(stripslashes($username)));
$poll_option_text[] = htmlspecialchars(trim(stripslashes($opponent_name)));
$poll_options = array();
while( list($option_id, $option_text) = @each($poll_option_text) )
{
$poll_options[$option_id] = htmlspecialchars(trim(stripslashes($option_text)));
}
prepare_new_game($post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $opponent_name, $opponent_id, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
if ( $error_msg == '' )
{
submit_new_game($post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), $userdata['user_id'], $userdata['games_points'], str_replace("\'", "''", $opponent_name), $opponent_id, $opponent_points, str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
make_post_autom($post_id);
// Notify opponent of new challenge by PM and EMAIL him of this new PM
notify_opponent($opponent_name);
$user_id = $userdata['user_id'];
$temp_mode = "newtopic";
update_post_stats($temp_mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
user_notification($temp_mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
// Change cookies
$tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
$tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) )
{
asort($tracking_topics);
unset($tracking_topics[key($tracking_topics)]);
}
$tracking_topics[$topic_id] = time();
setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
// Show message with link to topic after posting new game
$template->assign_vars(array(
'META' => $return_meta
)
);
message_die(GENERAL_MESSAGE, $return_message);
}
else if ( $error_msg != '' )
{
// Show error page if there's an error
$template->set_filenames(array(
'reg_header' => 'error_body.tpl'
)
);
$template->assign_vars(array(
'ERROR_MESSAGE' => $error_msg
)
);
$template->assign_var_from_handle('ERROR_BOX', 'reg_header');
}
}
else
{
//
// User default entry point
//
$username = $userdata['username'];
$message = '';
$user_sig = '';
$poll_title = '';
$poll_length = '';
// Check if user isn't self in a game
check_ingame($userdata['user_id']);
if ( count($auth_users_not_ingame) != 0 )
{
$select_opponent_list = '';
}
else
{
$confirm_meta = '';
$confirm_message = $lang['Games_No_Available_Opponents'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_challenge_body.tpl'
)
);
$page_title = $lang['Games_Challenge_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Output the data to the template
//
$template->assign_vars(array(
'SUBJECT' => $lang['Games_Subject'],
'MESSAGE' => $message,
'L_POST_A' => $lang['Games_Challenge_Title'],
'L_OPPONENT_NAME' => $lang['Games_Opponent'],
'L_SUBJECT' => $lang['Subject'],
'L_MESSAGE_BODY' => $lang['Games_Message_Body'],
'L_EMPTY_MESSAGE' => $lang['Empty_message'],
'L_GAMES_POSTING_TIP' => $lang['Games_Posting_Tip'],
'L_SUBMIT' => $lang['Submit'],
'S_OPPONENT_SELECT' => $select_opponent_list,
'S_POST_ACTION' => append_sid("games.$phpEx?mode=challenge")
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
break;
//
//===========================[ SHOW CANCEL GAMES ]==============================
//
case 'cancel':
if ( !$is_mod )
{
message_die(GENERAL_MESSAGE, $lang['Games_No_Auth_Cancel'] );
}
// --------------------
// What shall we do?
//
if ( $cansubm )
{
$game_id = $HTTP_POST_VARS[$cansubm];
$running_or_played = $HTTP_POST_VARS[$cansubm];
// Get info of the game we want to cancel
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_MESSAGE, $lang['Games_Not_Excists'] );
}
$game_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Check if the topic still excists and if forum is not locked,
// so we would know if it is still possible to post a reply
$post_reply = TRUE;
$sql = "SELECT topic_id, forum_id
FROM " . TOPICS_TABLE . "
WHERE topic_id = " . $game_info['topic_id'];
if ( $result = $db->sql_query($sql) )
{
$topic_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql = "SELECT *
FROM " . FORUMS_TABLE . "
WHERE forum_id = " . $topic_info['forum_id'];
if ( $result = $db->sql_query($sql) )
{
$forum_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ( $forum_info['forum_status'] == FORUM_LOCKED )
{
$post_reply = 0;
}
}
else
{
$post_reply = 0;
}
}
else
{
$post_reply = 0;
}
if ( $running_or_played == "running" || $running_or_played == "played" )
{
if ( $running_or_played == "running")
{
// Make both users available for gaming if they still excist
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$sql = "UPDATE " . USERS_TABLE . " SET games_current_game = '-1' WHERE username = " . $game_info['player_name'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$sql = "UPDATE " . USERS_TABLE . " SET games_current_game = '-1' WHERE username = " . $game_info['player_b_name'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
// Delete game in games table
$sql = "DELETE FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error deleting game in games table', '', __LINE__, __FILE__, $sql);
}
// Make a message for the reply posting
if ( $post_reply )
{
$message = "[color=green][u]" . $lang['Games_Game_Deleted_By'] . ": " . $userdata['username'] . "[/u][/color] ";
$message .= "\n\r\n\r[color=green][u]" . $lang['Games_Points_Change_After_Delete'] . "[/u][/color]";
$message .= "\n\r" . $lang['Games_Scores_Not_Changed_Yet'];
}
}
else if ( $running_or_played == "played")
{
// Change by both players their currentgame, won, lost and points
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE username = " . $game_info['player_name'];
if ( $result = $db->sql_query($sql) )
{
$player_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE username = " . $game_info['player_b_name'];
if ( $result = $db->sql_query($sql) )
{
$player_b_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
}
if ( $player_info['username'] == $game_info['winner_name'] )
{
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$points_change = $game_info['player_points_after'] - $game_info['player_points_before'];
$points_change_text = " - " . $points_change;
$games_points = $player_info['games_points'] - $points_change;
$games_won = $player_info['games_won'] - 1;
$games_lost = $player_info['games_lost'];
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$points_b_change = $game_info['player_b_points_before'] - $game_info['player_b_points_after'];
$points_b_change_text = " + " . $points_b_change;
$games_b_points = $player_b_info['games_points'] + $points_change;
$games_b_won = $player_b_info['games_won'];
$games_b_lost = $player_b_info['games_lost'] - 1;
}
}
else if ( $player_b_info['username'] == $game_info['winner_name'] )
{
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$points_change = $game_info['player_points_before'] - $game_info['player_points_after'];
$points_change_text = " + " . $points_change;
$games_points = $player_info['games_points'] + $points_change;
$games_won = $player_info['games_won'];
$games_lost = $player_info['games_lost'] - 1;
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$points_b_change = $game_info['player_b_points_after'] - $game_info['player_b_points_before'];
$points_b_change_text = " - " . $points_b_change;
$games_b_points = $player_b_info['games_points'] - $points_change;
$games_b_won = $player_b_info['games_won'] - 1;
$games_b_lost = $player_b_info['games_lost'];
}
}
if ( get_games_user_id($game_info['player_name']) != '-2')
{
if ( $games_points < $board_config['games_minimum'] )
{
$games_points = $board_config['games_minimum'];
} }
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
if ( $games_b_points < $board_config['games_minimum'] )
{
$games_b_points = $board_config['games_minimum'];
}
}
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_points . ", games_won = " . $games_won . ", games_lost = " . $games_lost . ", games_current_game = '-1' WHERE username = " . $game_info['player_name'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_b_points . ", games_won = " . $games_b_won . ", games_lost = " . $games_b_lost . ", games_current_game = '-1' WHERE username = " . $game_info['player_b_name'];
if (!$db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
// Delete game in games table
$sql = "DELETE FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Error deleting game in games table', '', __LINE__, __FILE__, $sql);
}
// Make a message for the reply posting
if ( $post_reply )
{
$message = "[color=green][u]" . $lang['Games_Game_Deleted_By'] . ": " . $userdata['username'] . "[/u][/color] ";
$message .= "\n\r\n\r[color=green][u]" . $lang['Games_Points_Change_After_Delete'] . ":[/u][/color]";
if ( get_games_user_id($game_info['player_name']) != '-2')
{
$message .= "\n\r" . $player_info['username'] . ": " . $points_change_text . " punten.";
}
else
{
$message .= "\n\r" . $game_info['player_name'];
$message .= $lang['Games_Cannot_Change_Points'];
}
if ( get_games_user_id($game_info['player_b_name']) != '-2')
{
$message .= "\n\r" . $player_b_info['username'] . ": " . $points_b_change_text . " punten.";
}
else
{
$message .= "\n\r" . $game_info['player_b_name'];
$message .= $lang['Games_Cannot_Change_Points'] . ".";
}
}
}
// Reply on the corresponding topic and change topic subject in the games forum if still possible
if ( !$post_reply )
{
$confirm_meta = '';
$confirm_message = $lang['Games_Game_Cancelled'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
else
{
// First post in topic of the to-cancel-game: change subject
$sql = "SELECT games_first_post_id
FROM " . GAMES_TABLE . "
WHERE game_id = " . $game_id;
if ( $result = $db->sql_query($sql) )
{
$game_first_post_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$game_first_post_id = $game_first_post_info['games_first_post_id'];
$sql = "SELECT post_subject
FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = " . $game_first_post_id;
if ( $result = $db->sql_query($sql) )
{
$post_first_post_info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$post_first_post_info['post_subject'] = str_replace($lang['Games_Subject_Prefix_Played'], '', $post_first_post_info['post_subject']);
$post_first_post_info['post_subject'] = str_replace($lang['Games_Subject_Prefix_Running'], '', $post_first_post_info['post_subject']);
$post_first_post_subject = $lang['Games_Subject_Prefix_Cancelled'];
$post_first_post_subject .= $post_first_post_info['post_subject'];
$sql_1 = "UPDATE " . POSTS_TEXT_TABLE . " SET post_subject = '" . $post_first_post_subject . "' WHERE post_id = " . $game_first_post_id;
$sql_2 = "UPDATE " . TOPICS_TABLE . " SET topic_title = '" . $post_first_post_subject . "' WHERE topic_id = " . $topic_id;
if (!$db->sql_query($sql_1, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
if (!$db->sql_query($sql_2, END_TRANSACTION))
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$post_first_post_message = "";
// add_search_words('single', $game_first_post_id, stripslashes($post_first_post_message), stripslashes($post_first_post_subject));
}
}
//
// Post a reply with cancel information
//
$post_data = array();
$post_data['first_post'] = false;
$post_data['last_post'] = true;
$post_data['has_poll'] = false;
$post_data['edit_poll'] = false;
$post_data['last_topic'] = false;
$bbcode_on = 1;
$bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : '';
$html_on = 0;
$smilies_on = 0;
$error_msg = '';
$notify_user = TRUE;
$attach_sig = 0;
$temp_mode = "reply";
$return_message = '';
$return_meta = '';
$topic_type = POST_NORMAL;
$username = $userdata['username'];
$post_username = $username;
$poll_title = '';
$subject = '';
$return_message = '';
$return_meta = '';
$forum_id = GAMES_FORUM;
prepare_post($temp_mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
if ( $error_msg == '' )
{
submit_post($temp_mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
make_post_autom($post_id);
$user_id = $userdata['user_id'];
update_post_stats($temp_mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
user_notification($temp_mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
// Change cookies
$tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
$tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) )
{
asort($tracking_topics);
unset($tracking_topics[key($tracking_topics)]);
}
$tracking_topics[$topic_id] = time();
setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}
}
$confirm_meta = '';
$confirm_message = $lang['Games_Game_Cancelled'] . '
' . sprintf($lang['Games_Click_Return_Games'], '', '');
$template->assign_vars(array(
'META' => $confirm_meta)
);
message_die(GENERAL_MESSAGE, $confirm_message);
}
else
{
message_die(GENERAL_MESSAGE, "You must specify if the game is still running or played yet." );
}
}
else
{
//=====[ RUNNING GAMES ]=====
// Get some database information
//
$forum_id = GAMES_FORUM;
//
// Load template & Set page title & Output page header
//
$template->set_filenames(array(
'body' => 'games_my_games_body.tpl'
)
);
$page_title = $lang['Games_My_Games_Title'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// Get some information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE;
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] != $row['winner_b_id']) || (empty($row['winner_id']) && empty($row['winner_b_id'])) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
$player_id = $row['player_name'];
$player_b_id = $row['player_b_name'];
$player_name = get_games_username($player_id);
$player_b_name = get_games_username($player_b_id);
$winner_id = $row['winner_id'];
$winner_b_id = $row['winner_b_id'];
$winner_name = get_games_username($winner_id);
$winner_b_name = get_games_username($winner_b_id);
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$player_name = '' . $player_name . '';
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$player_b_name = '' . $player_b_name . '';
if ( empty($winner_id) )
{
$winner_name = $lang['Games_Not_Validated_Yet'];
}
if ( empty($winner_b_id) )
{
$winner_b_name = $lang['Games_Not_Validated_Yet'];
}
$mod_cancel_button = '
';
$row_color = ( ($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( ($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('runningyes', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'ROW_NUMBER' => $row['game_id'],
'START_DATE' => $msg_date,
'PLAYER_NAME' => $player_name,
'PLAYER_B_NAME' => $player_b_name,
'WINNER' => $winner_name,
'WINNER_B' => $winner_b_name,
'CANCEL_GAME' => $mod_cancel_button,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
$i++;
}
$db->sql_freeresult($result);
}
}
else
{
$template->assign_block_vars('runningno.row', array(
'ROW_COLOR' => '#' . $theme['td_color1'],
'ROW_CLASS' => $theme['td_class1'],
'L_NO_PENDING_GAME' => $lang['Games_No_Running_Games'],
)
);
}
//=====[ PLAYED GAMES ]======
// Get some database information
//
$sql = "SELECT game_id, winner_id, winner_b_id
FROM " . GAMES_TABLE;
if ( $result = $db->sql_query($sql) )
{
$where_sql = '';
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( ($row['winner_id'] == $row['winner_b_id']) && !empty($row['winner_id']) && !empty($row['winner_b_id']) )
{
if ( $i == 0 )
{
$where_sql .= "game_id = " . $row['game_id'];
$i = 1;
}
else
{
$where_sql .= " OR game_id = " . $row['game_id'];
}
}
}
}
if ( !empty($where_sql) )
{
$sql = "SELECT *
FROM " . GAMES_TABLE . "
WHERE " . $where_sql . "
ORDER BY game_id DESC";
if ( $result = $db->sql_query($sql) )
{
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{
$player_id = $row['player_id'];
$player_b_id = $row['player_b_id'];
$challenger = get_games_username($player_id);
$opponent = get_games_username($player_b_id);
$winner = get_games_username($row['winner_id']);
$msg_date = create_date($board_config['default_dateformat'], $row['game_date'], $board_config['board_timezone']);
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_id);
$challenger = '' . $challenger . '';
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $player_b_id);
$opponent = '' . $opponent . '';
$mod_cancel_button = '
';
$row_color = ( !($i % 2) ) ? $theme['td_color2'] : $theme['td_color1'];
$row_class = ( !($i % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('playedyes', array(
'ROW_NUMBER' => $row['game_id'],
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'START_DATE' => $msg_date,
'CHALLENGER' => $challenger,
'OPPONENT' => $opponent,
'WINNER' => $winner,
'CANCEL_GAME' => $mod_cancel_button,
'U_VIEWTOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $row['topic_id'])
)
);
$i++;
}
$db->sql_freeresult($result);
}
}
else
{
$template->assign_block_vars('playedno.row', array(
'ROW_COLOR' => '#' . $theme['td_color1'],
'ROW_CLASS' => $theme['td_class1'],
'L_NO_PLAYED_GAMES' => $lang['Games_No_My_Played_Games'],
)
);
}
//
// Assign the vars
//
$template->assign_vars(array(
'L_GAME_INFO' => $lang['Games_Check_Info'],
'L_START_DATE' => $lang['Date'],
'L_CHALLENGER' => $lang['Games_Challenger'],
'L_OPPONENT' => $lang['Games_Opponent'],
'L_VALIDATE_WINNER' => $lang['Games_Validate_Winner_By_Challenger'],
'L_VALIDATE_WINNER_B' => $lang['Games_Validate_Winner_By_Opponent'],
'L_GO_TO_GAME_INFO' => $lang['Games_Go_To_Game_Info'],
'L_WINNER' => $lang['Games_Winner'],
'L_CANCEL_GAMES' => $lang['Games_Cancel_Games']
)
);
//
// Include the html part
//
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
break;
}
?>