Location: PHPKode > projects > JaxBlog > JaxBlog/app/user/user_scoreboard/user_scoreboard.php
<?php

require_once('../../../config.php');
require_once(FOLDER_RELATIVE_COMMON . 'database.php');

// Check for XML request (XMLHttpRequest).
$request = isset($_GET['request']) ? $_GET['request'] : '';
if ($request == 'xml') {

	header('Content-Type: text/xml');
	$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
	$xml .= "<root>\n";
	
	$sql = 
		" SELECT " +
		"   id, played_at_home " +
		"   , " . databaseGetDate("scheduled_date", "d") . " AS scheduled_date " +
		"   , '" . TEAM . "' AS team, team_runs, team_hits, team_errors " +
		"   , opponent, opponent_runs, opponent_hits, opponent_errors" +
		" FROM Games " +
		" ORDER BY scheduled_date DESC LIMIT 1";
	$row = databaseGetRow($sql, array());

	$game_id = $row['id'];
	$played_at_home = $row['played_at_home'];
	
	if ($played_at_home == 'Y') {
		$xml .= "\t<meta>\n";
		$xml .= "\t\t<scheduled_date>" . $row['scheduled_date'] . "</scheduled_date>\n";
		$xml .= "\t\t<guest_name>" . $row['opponent'] . "</guest_name>\n";
		$xml .= "\t\t<guest_runs>" . $row['opponent_runs'] . "</guest_runs>\n";
		$xml .= "\t\t<guest_hits>" . $row['opponent_hits'] . "</guest_hits>\n";
		$xml .= "\t\t<guest_errors>" . $row['opponent_errors'] . "</guest_errors>\n";
		$xml .= "\t\t<home_name>" . $row['team'] . "</home_name>\n";
		$xml .= "\t\t<home_runs>" . $row['team_runs'] . "</home_runs>\n";
		$xml .= "\t\t<home_hits>" . $row['team_hits'] . "</home_hits>\n";
		$xml .= "\t\t<home_errors>" . $row['team_errors'] . "</home_errors>\n";
		$xml .= "\t</meta>\n";
	} else {
		$xml .= "\t<meta>\n";
		$xml .= "\t\t<scheduled_date>" . $row['scheduled_date'] . "</scheduled_date>\n";
		$xml .= "\t\t<guest_name>" . $row['team'] . "</guest_name>\n";
		$xml .= "\t\t<guest_runs>" . $row['team_runs'] . "</guest_runs>\n";
		$xml .= "\t\t<guest_hits>" . $row['team_hits'] . "</guest_hits>\n";
		$xml .= "\t\t<guest_errors>" . $row['team_errors'] . "</guest_errors>\n";
		$xml .= "\t\t<home_name>" . $row['opponent'] . "</home_name>\n";
		$xml .= "\t\t<home_runs>" . $row['opponent_runs'] . "</home_runs>\n";
		$xml .= "\t\t<home_hits>" . $row['opponent_hits'] . "</home_hits>\n";
		$xml .= "\t\t<home_errors>" . $row['opponent_errors'] . "</home_errors>\n";
		$xml .= "\t</meta>\n";
	}

	$sql = '';
	$sql .= " SELECT inning, runs_team, runs_opponent ";
	$sql .= " FROM Scores ";
	$sql .= " WHERE game_id = ? AND inning < 8 ";
	$sql .= " ORDER BY inning ";
	$rows = databaseGetRows($sql, array($game_id));
	
	$counter = 0;
	$game_id = 0;
	$guest = "\t<guest>";
	$home = "\t<home>";
	foreach($rows as $row) {
		$counter++;
		$tag_open = "<i$counter>";
		$tag_close = "</i$counter>";
		if ($played_at_home == 'Y') {
			$guest .= $tag_open . $row['runs_opponent'] . $tag_close;
			$home .= $tag_open . $row['runs_team'] . $tag_close;
		} else {
			$guest .= $tag_open . $row['runs_team'] . $tag_close;
			$home .= $tag_open . $row['runs_opponent'] . $tag_close;
		}
	}
	
	$guest .= "</guest>\n";
	$home .= "</home>\n";
	
	// If no scores, return empty xml doc.
	if ($counter == 0) {
		echo "<root></root>\n";
		exit;
	}

	$xml .= $guest . $home;
	$xml .= "</root>\n";
	
	echo $xml;
	exit;
}

?>
Return current item: JaxBlog