<?php
function PrintTable()
{
$xmlDoc =& new MiniXMLDoc();
$xmlDoc->fromFile('database.xml'); // rename to match your database file
$xmlRoot =& $xmlDoc->getRoot();
$players =& $xmlRoot->getElement('players'); // Get the "players" element from the database
$player = $players->getAllChildren(); // Separate individual player element to the array $player[x]
$playeramount = $players->numChildren(); // Get a variable for defining a table for visual results
$tournaments =& $xmlRoot->getElement('tournaments');
$tournament = $tournaments->getAllChildren();
$tournamentNumber = $tournaments->numChildren();
//
// Table creation
//
//print '<table ' . $tableStyle . '>';
print '<table width="90%" border="3" cellpadding="5" cellspacing="2" background="background.jpg">';
// The first row defines Player Name, Tournament Name & Date for each tournament (only 1 for now)
print '<td '. $cellStyle . '><u>Name</u></td>';
for($i=0; $i < $tournamentNumber; $i++)
{
$tourneyName = $tournament[$i]->getElement('name');
print '<td ' . $cellStyle . '><center><u>' . $tourneyName->getValue() . "<br>VP / GA</u></center></td>";
}
print '<center><td '. $cellStyle . '><u>Cumulative<br>score</u></td>';
print '<td '. $cellStyle . '><u>Victory<br>Percentage</td></u></center>';
print '<td '. $cellStyle . '><u>Modified<br>Victory Percentage</u></td></center>';
//
// Now to create new rows for each player in the database
//
for($i=0; $i < $players->numChildren(); $i++)
{
print "<TR>"; // new row
$name = $player[$i]->getElement('name');
print '<TD ' . $cellStyle . '>' . $name->getValue() . '</TD>';
// variables for cumulative scores
$numTourneys = 0;$roundSum=0;
$cumVP = 0;
$cumGA = 0;
$tourMaxGa = 0;
$bonusVPMod = 1;
for ($tourId=0; $tourId < $tournamentNumber; $tourId++)
{
print '<td ' . $cellStyle . '><center>';
$checkBoolean = FALSE; // boolean variable that changes into true if participation positive
$tourneys = $player[$i]->getElement('tourneys');
$tourney = $tourneys->getAllChildren();
for ($partCheck=0; $partCheck < $tourneys->numChildren(); $partCheck++)
{
$idCheck1 = $tourney[$partCheck]->getElement('id');
$idCheck2 = $tournament[$tourId]->getElement('id');
if ($idCheck1->getValue() == $idCheck2->getValue())
{
$idValue = $idCheck2->getValue(); // current processed tournament id
$VP = $tourney[$partCheck]->getElementByPath('scores/VP');
$GA = $tourney[$partCheck]->getElementByPath('scores/GA');
$numTourneys++;
$cumVP += $VP->getValue();
$cumGA += $GA->getValue();
// Add up cumulative # of rounds
$tourRounds=$tournament[$tourId]->getElement('rounds');
$tourMaxGa_element = $tournament[$tourId]->getElement('maxga');
$tourMaxGa += $tourMaxGa_element->getValue();
$roundSum += $tourRounds->getValue();
print $VP->getValue() . "/" . $GA->getValue();
$checkBoolean = TRUE;
// TODO: Check for awards regarding top 3
//
// Check whether player has awards
//
// Tournament Specific Awards
$awards = $tournament[$tourId]->getElement('awards');
$award = $awards->getAllChildren();
$awardBoolean = FALSE;
for ($a=0; $a < $awards->numChildren(); $a++)
{
$aName = $award[$a]->name();
if ($award[$a]->getValue() == $name->getValue())
{
if ($awardBoolean == FALSE)
{
$awardBoolean = TRUE;
print "<br>";
}
AwardPrint ($aName);
}
}
// Awards related to ranking
$rankElement = $tourney[$partCheck]->getElementByPath('scores/rank');
$rank = $rankElement->getValue();
if ($rank > 0)
{
if ($rank <= 10)
{
// Print awards for 1st to 3rd place and add bonus VP%-modifier for winner
if ($rank == 1)
{
$bonusVPMod *= 1.01;
if ($awardBoolean == FALSE)
{
$awardBoolean = TRUE;
print "<br>";
}
AwardPrint("first");
}
if ($rank == 2)
{
if ($awardBoolean == FALSE)
{
$awardBoolean = TRUE;
print "<br>";
}
AwardPrint("second");
}
if ($rank == 3)
{
if ($awardBoolean == FALSE)
{
$awardBoolean = TRUE;
print "<br>";
}
AwardPrint("third");
}
// Check whether relevant tournament is an open
$openstatus = $tournament[$tourId]->getElement('open');
if ($openstatus->getValue() == "yes")
{
$bonusVPMod *= 1.01;
}
}
}
}
}
if ($checkBoolean !== TRUE) // if the player has not participated in a tournament, show n/a
{
print "n/a";
}
print "</center></td>";
}
// Show Cumulative VP/GA
if ($numTourneys != 0)
{
print '<center><td '. $cellStyle . '>' . $cumVP . '/' . $cumGA . '</td></center>';
// Show unmodified VP%
if ($roundSum != 0)
{
$victoryPercentage = $cumVP / ($roundSum * 9);
print '<center><td '. $cellStyle . '>' . round(($victoryPercentage * 100), 2) . '% </td></center>';
}
// Calculate modified VP% and GA%
if ($numTourneys < 7) // malus for < 7 tournaments
{
$VicPerModifier = 1 - (1/(2 * $numTourneys));
}
if ($numTourneys > 7) // bonus for > 7 tournaments
{
$VicPerModifier = ($numTourneys - 7) * (1+(1/200));
}
$GaPercent = $cumGA / $tourMaxGa;
print '<center><td '. $cellStyle . '>'. round(($bonusVPMod * $victoryPercentage * 100 * $VicPerModifier), 2) .' % / '. round(($GaPercent * 100), 2) . ' % </td></center>';
}
else
{
print "<center><td $cellStyle >n/a</td></center>";
print "<center><td $cellStyle >n/a</td></center>";
print "<center><td $cellStyle >n/a</td></center>";
}
print "</TR>"; // end of row
}
print '</table><center><a href="process.php">Modify</a></center>';
}
?>