require_once("db.php");
db_connect();
$db_debug = true;
$locations = db_retrieve("SELECT DISTINCT locationId FROM cm.scheduleEntities");
foreach ($locations as $locId)
{
$locId = $locId['locationid'];
$loc = db_get("SELECT *, sched.getLocationIndex($locId) AS rank FROM sched.locations WHERE id = sched.getLocationParent($locId)");
$arena = db_get("SELECT * FROM sched.arenas WHERE id = $locId");
?>
$entities = db_retrieve("SELECT * FROM cm.scheduleentities, entities WHERE id = entityid AND locationid = $locId ORDER BY starttime");
foreach ($entities as $e)
{
echo date( "d/M H:i", $e['starttime']/1000 );
echo " - ";
$id = $e['entityid'];
if ($e['class'] == 10)
{
// Round
$row = db_get("SELECT name, divisionid, stageid FROM cm.categories, cm.divisions, cm.rounds
WHERE categories.id = divisions.categoryId
AND divisions.id = rounds.divisionid
AND rounds.id = $id");
echo $row['name'] . " ";
$divisionId = $row['divisionid'];
$conference = db_get("SELECT * FROM cm.conferences WHERE id = $divisionId");
if ($conference)
{
echo $conference['name'] . " " . $conference['rank'];
} else {
// Slutspel, hitta stagename
echo db_getvalue("SELECT name FROM cm.stages WHERE id = $row[stageid]");
$roundRank = db_getvalue("select rank FROM cm.rounds WHERE id = $id");
echo " 1/" . (pow(2,$roundRank));
}
} else {
// Match
$match = db_get("SELECT * FROM cash.view_matchTable WHERE matchId = $id");
echo db_getvalue("SELECT name FROM cm.categories, cm.divisions
WHERE categories.id = categoryid
AND divisions.id = " . $match['divisionid']);
echo " - ";
echo str_replace(" i ", " in Group ", $match['homename']) . " - " . str_replace(" i ", " in Group ", $match['awayname']);
}
echo " - Slutar: " . date( "H:i", ($e['starttime']+$e['duration']) /1000 );
echo "
";
}
}
?>