rendered paste body<?php
##############################################################
# FILENAME : acp_rivals_report_match.php
# COPYRIGHT : (c) 2008, Tyler N. King <aibotca@yahoo.ca>
# http://opensource.org/licenses/gpl-license.php GNU Public License
##############################################################
if ( !defined ( 'IN_PHPBB' ) )
{
exit;
}
/**
* Report a Match
* Called from acp_rivals with mode == 'report_match'
*/
function acp_rivals_report_match ( $id, $mode, $u_action )
{
global $config, $db, $user, $auth, $template;
global $phpbb_root_path, $phpbb_admin_path, $phpEx;
$clan = new clan ( );
$ladder = new ladder ( );
$submit = request_var ( 'submit', '' );
$ladder_id = request_var ( 'ladder_id', 0 );
// Are we submitting a form?
if ( !empty ( $submit ) )
{
// Yes, handle the form.
$tie = request_var ( 'tie', 0 );
$clan_winner = request_var ( 'clan_winner', 0 );
$clan_looser = request_var ( 'clan_looser', 0 );
// Insert the match into the database.
$sql = "INSERT INTO " . MATCHES_TABLE . " (match_challenger, match_challengee, match_finishtime, match_tie, match_ladder, match_details) VALUES ($clan_winner, $clan_looser, " . time ( ) . ", $tie, $ladder_id, '')";
$db->sql_query ( $sql );
// Is this a tie?
if ( !empty ( $tie ) )
{
// Yes, update the clan's data.
$sql = "UPDATE " . CLANDATA_TABLE . " SET clan_ties = clan_ties + 1, clan_streak = 0 WHERE clan_id = $clan_winner AND clan_ladder = " . $ladder_id;
$db->sql_query ( $sql );
$sql = "UPDATE " . CLANDATA_TABLE . " SET clan_ties = clan_ties + 1, clan_streak = 0 WHERE clan_id = $clan_looser AND clan_ladder = " . $ladder_id;
$db->sql_query ( $sql );
}
else
{
// ELO scoring system.
$score_winner = calculate_elo ( $clan->data ( 'clan_score', $clan_winner, $ladder_id ), $clan->data ( 'clan_score', $clan_looser, $ladder_id ), true );
$score_looser = calculate_elo ( $clan->data ( 'clan_score', $clan_looser, $ladder_id ), $clan->data ( 'clan_score', $clan_winner, $ladder_id ), false );
// Calculate the new streaks.
$streak_winner = ( $clan->data ( 'clan_streak', $clan_winner, $ladder_id ) < 0 ) ? 'clan_streak = 0' : 'clan_streak = clan_streak + 1';
$streak_looser = ( $clan->data ( 'clan_streak', $clan_winner, $ladder_id ) < 0 ) ? 'clan_streak = clan_streak - 1' : 'clan_streak = 0';
$sql = "UPDATE " . CLANDATA_TABLE . " SET clan_wins = clan_wins + 1, clan_lastscore = clan_score, clan_score = $score_winner, $streak_winner WHERE clan_id = $clan_winner AND clan_ladder = " . $ladder_id;
$db->sql_query ( $sql );
$sql = "UPDATE " . CLANDATA_TABLE . " SET clan_losses = clan_losses + 1, clan_lastscore = clan_score, clan_score = $score_looser, $streak_looser WHERE clan_id = $clan_looser AND clan_ladder = " . $ladder_id;
$db->sql_query ( $sql );
}
// Completed. Let the user know.
trigger_error ( 'MATCH_REPORTED' );
}
else
{
// Load the clan data?
if ( !empty ( $ladder_id ) )
{
// Yes. A ladder was selected.
// Get the clans for the ladder_id.
$sql = "SELECT * FROM " . CLANDATA_TABLE . " WHERE clan_ladder = " . $ladder_id;
$result = $db->sql_query ( $sql );
while ( $row = $db->sql_fetchrow ( $result ) )
{
// Assign the clans to the template.
$template->assign_block_vars ( 'block_clans', array (
'CLAN_NAME' => $clan->data ( 'clan_name', $row[ 'clan_id' ] ),
'CLAN_ID' => $row[ 'clan_id' ] )
);
}
$template->assign_vars ( array ( 'LADDER_ID' => $ladder_id ) );
}
else
{
// No. No ladder was selected.
$has_ladderid = false;
// Loop through the ladder list.
$ladders = $ladder->ladder_list ( );
foreach ( $ladders AS $key => $value )
{
$sql = "SELECT * FROM " . PLATFORMS_TABLE . " WHERE platform_id = " . $ladders[ $key ][ 'PLATFORM' ];
$result = $db->sql_query ( $sql );
$row = $db->sql_fetchrow ( $result );
// Assign it to the template.
$template->assign_block_vars ( 'block_ladders', array (
'LADDER_NAME' => $ladders[ $key ][ 'NAME' ],
'PLATFORM' => $row[ 'platform_name' ] )
);
// Loop through the ladder's sub-ladders.
foreach ( $ladders[ $key ][ 'SUBLADDERS' ] AS $key_2 => $value_2 )
{
// Assign them to the template.
$template->assign_block_vars ( 'block_ladders.block_subladders', array (
'LADDER_NAME' => $ladders[ $key ][ 'SUBLADDERS' ][ $key_2 ][ 'NAME' ],
'LADDER_ID' => $key_2 )
);
}
}
}
// Assign the other variables to the template.
$template->assign_vars ( array (
'U_ACTION' => $u_action,
'HAS_LADDERID' => $has_ladderid )
);
}
}
?>