<?php
/**
 * Chess Tournament Results File
 *
 * This file automatically generates an XML file listing links to Tournament Results on the WHSCA website.
 * 
 * @author Joshua Stewardson <joshua@covenantdesign.com>
 * @package Chess4Life
 * @subpackage XML
 */

header("Content-type: application/xml");

print '<?xml version="1.0" ?>'."\n";
print '<rss version="2.0">'."\n\n";
print '<channel>'."\n\n";
print '<title>Chess4Life WA Tournament Results</title>'."\n";
print '<description>Results and new ratings from recent Western Washington State tournaments.</description>'."\n";
print '<link>http://www.chess4life.com/chess-tournament-results.php</link>'."\n\n";

/**
 * This file contains the neccessary login information and functions to access the database.
 */
include_once("../functions/db_fns.php");
/**
 * The functions in this file display common page elements like the side navigation, showcase pages, Google Maps, and others as added.
 */
include_once("../functions/display_fns.php");

// Create database object
$db = db_connect();

$result = display_whsca_results(5);
foreach($result as $line) {
	$line = substr($line, 9);
	$line = explode('" class="external-link">', $line);
	$link = $line[0];
	$line = explode('</a> - ', $line[1]);
	$title = $line[0];
	$line = explode(' in ', $line[1]);
	$date = $line[0];
	$location = $line[1];
	
	print '<item>'."\n";
	print '<title>'.$title.'</title>'."\n";
	print '<pubDate>'.$date.'</pubDate>'."\n";
	print '<description>Tournament took place in '.$location.'</description>'."\n";
	print '<link>'.$link.'</link>'."\n";
	print '</item>'."\n\n";
}

print '</channel>'."\n\n";
print '</rss>';

?>
