function makePlayerUrl($playerid, $single = true)
{
    global $db;
    global $user;
    require_once "./mod/default/tournament/participant.interface.php";
    require_once "./mod/default/tournament/singlePlayer.class.php";
    if ($single) {
        if ($playerid <= 0) {
            $p = newUnknown();
            $playerUrl = $p->getName();
        } else {
            $p = new singlePlayer($user->getUserById($playerid));
            $playerUrl = makeHTMLUrl($p->getName(), $p->getUrl());
        }
    } else {
        if ($playerid <= 0) {
            $p = newUnknown();
            $playerUrl = $p->getName();
        } else {
            $p = $db->selectOneRow("tournamentgroups", "*", "`groupid`=" . $playerid);
            $playerUrl = makeHTMLUrl($p['name'], makeURL('tournament', array('mode' => 'viewgroup', 'tournamentid' => $p['tournamentid'], 'groupid' => $playerid)));
        }
    }
    return $playerUrl;
}
 function tournamentTable()
 {
     global $smarty;
     global $template_dir;
     global $config;
     $size = pow(2, $this->roundCount() - 1);
     for ($i = 0; $i < $size; $i++) {
         for ($j = 0; $j < $this->roundCount(); $j++) {
             if ($i % pow(2, $j) == 0) {
                 $encId = $i / pow(2, $j);
                 $curEnc = new EliminationEncounter($this->tournamentId, $j, $encId);
                 if ($curEnc->getPlayer1id() == -1) {
                     $player1 = newDummy();
                 }
                 if ($curEnc->getPlayer2id() == -1) {
                     $player2 = newDummy();
                 }
                 if ($curEnc->getPlayer1id() == 0) {
                     $player1 = newUnknown();
                 }
                 if ($curEnc->getPlayer2id() == 0) {
                     $player2 = newUnknown();
                 }
                 foreach ($this->participants as $participant) {
                     if ($participant->getId() == $curEnc->getPlayer1id()) {
                         $player1 = $participant;
                     }
                     if ($participant->getId() == $curEnc->getPlayer2id()) {
                         $player2 = $participant;
                     }
                 }
                 $field[$i][$j]['round'] = $j;
                 $field[$i][$j]['encNr'] = $i + 1;
                 $field[$i][$j]['rowspan'] = pow(2, $j);
                 if ($curEnc->getPlayer1id() > 0 && $curEnc->getPlayer2id() > 0) {
                     $field[$i][$j]['link'] = makeUrl('tournament', array('tournamentid' => $this->tournamentId, 'encid' => $encId, 'roundid' => $j, 'mode' => 'view'));
                 }
                 $field[$i][$j]['p1name'] = $player1->getName();
                 $field[$i][$j]['p1url'] = $player1->getUrl();
                 $field[$i][$j]['p2name'] = $player2->getName();
                 $field[$i][$j]['p2url'] = $player2->getUrl();
                 $field[$i][$j]['timestatus'] = $curEnc->getEncTimeState();
                 if ($curEnc->isFinished()) {
                     $field[$i][$j]['p1points'] = $curEnc->getPoints1();
                     $field[$i][$j]['p2points'] = $curEnc->getPoints2();
                     $field[$i][$j]['winner'] = $curEnc->winner();
                 }
             }
         }
     }
     if ($this->thirdplayoff) {
         $thirdplayoff = array();
         $curEnc = new EliminationEncounter($this->tournamentId, $this->roundCount() - 1, 1);
         if ($curEnc->getPlayer1id() == -1) {
             $player1 = newDummy();
         }
         if ($curEnc->getPlayer2id() == -1) {
             $player2 = newDummy();
         }
         if ($curEnc->getPlayer1id() == 0) {
             $player1 = newUnknown();
         }
         if ($curEnc->getPlayer2id() == 0) {
             $player2 = newUnknown();
         }
         foreach ($this->participants as $participant) {
             if ($participant->getId() == $curEnc->getPlayer1id()) {
                 $player1 = $participant;
             }
             if ($participant->getId() == $curEnc->getPlayer2id()) {
                 $player2 = $participant;
             }
         }
         $thirdplayoff['round'] = $this->roundCount() - 1;
         $thirdplayoff['encNr'] = $curEnc->getId() + 1;
         if ($curEnc->getPlayer1id() > 0 && $curEnc->getPlayer2id() > 0) {
             $thirdplayoff['link'] = makeUrl('tournament', array('tournamentid' => $this->tournamentId, 'encid' => $curEnc->getId(), 'roundid' => $this->roundCount() - 1, 'mode' => 'view'));
         }
         $thirdplayoff['p1name'] = $player1->getName();
         $thirdplayoff['p1url'] = $player1->getUrl();
         $thirdplayoff['p2name'] = $player2->getName();
         $thirdplayoff['p2url'] = $player2->getUrl();
         $thirdplayoff['timestatus'] = $curEnc->getEncTimeState();
         $thirdplayoff['tdnbsp'] = ($this->roundCount() - 1) * 2;
         if ($curEnc->isFinished()) {
             $thirdplayoff['p1points'] = $curEnc->getPoints1();
             $thirdplayoff['p2points'] = $curEnc->getPoints2();
             $thirdplayoff['winner'] = $curEnc->winner();
         }
         $smarty->assign('thirdplayoff', $thirdplayoff);
     }
     $smarty->assign('roundsandmaps', $this->getRoundsAndMaps($this->roundCount()));
     $smarty->assign('path', $template_dir . '/singleelimination.tpl');
     $smarty->assign('field', $field);
     $smarty->assign('encounterWidth', $config->get('tournament', 'tree-encounter-width'));
     $smarty->assign('encTempl', $template_dir . '/eliminationencounter.tpl');
 }
 function tournamentTable()
 {
     global $smarty;
     global $template_dir;
     global $db;
     global $config;
     $encList = $db->selectList('tournamentencounters', '*', "`tournamentid`=" . $this->tournamentId, "`roundid` ASC, `encounterid` ASC");
     foreach ($encList as $encounter) {
         $y = $encounter['roundid'];
         $x = $encounter['encounterid'];
         $curEnc = new EliminationEncounter($this->tournamentId, $y, $x);
         $finalList[$x][$y]['round'] = $x;
         $finalList[$x][$y]['encid'] = $y;
         foreach ($this->participants as $participant) {
             if ($participant->getId() == $curEnc->getPlayer1id()) {
                 $player1 = $participant;
             }
             if ($participant->getId() == $curEnc->getPlayer2id()) {
                 $player2 = $participant;
             }
         }
         // Only player 2 (in the last enc) could be a dummy
         if ($curEnc->getPlayer2id() == -1) {
             $player2 = newDummy();
         }
         if ($curEnc->getPlayer1id() == 0) {
             $player1 = newUnknown();
         }
         if ($curEnc->getPlayer2id() == 0) {
             $player2 = newUnknown();
         }
         if ($curEnc->getPlayer1id() > 0 && $curEnc->getPlayer2id() > 0) {
             $finalList[$x][$y]['link'] = makeUrl('tournament', array('tournamentid' => $this->tournamentId, 'encid' => $x, 'roundid' => $y, 'mode' => 'view'));
         }
         $finalList[$x][$y]['p1name'] = $player1->getName();
         $finalList[$x][$y]['p1url'] = $player1->getUrl();
         $finalList[$x][$y]['p2name'] = $player2->getName();
         $finalList[$x][$y]['p2url'] = $player2->getUrl();
         $finalList[$x][$y]['timestatus'] = $curEnc->getEncTimeState();
         if ($curEnc->isFinished()) {
             $finalList[$x][$y]['p1points'] = $curEnc->getPoints1();
             $finalList[$x][$y]['p2points'] = $curEnc->getPoints2();
             $finalList[$x][$y]['winner'] = $curEnc->winner();
         }
     }
     $smarty->assign('roundsandmaps', $this->getRoundsAndMaps($y + 1));
     $smarty->assign('table', $finalList);
     $smarty->assign('encounterWidth', $config->get('tournament', 'tree-encounter-width'));
     $smarty->assign('encTempl', $template_dir . '/kothencounter.tpl');
     $smarty->assign('path', $template_dir . '/koth.tpl');
 }
 private function addEncounter(&$field, $i, $j, $enc, $noLinkToArrow = false)
 {
     if ($enc->getPlayer1id() == -1) {
         $player1 = newDummy();
     }
     if ($enc->getPlayer2id() == -1) {
         $player2 = newDummy();
     }
     if ($enc->getPlayer1id() == 0) {
         $player1 = newUnknown();
     }
     if ($enc->getPlayer2id() == 0) {
         $player2 = newUnknown();
     }
     foreach ($this->participants as $participant) {
         if ($participant->getId() == $enc->getPlayer1id()) {
             $player1 = $participant;
         }
         if ($participant->getId() == $enc->getPlayer2id()) {
             $player2 = $participant;
         }
     }
     $field[$i][$j]['round'] = $j + 1;
     $field[$i][$j]['encNr'] = $enc->getId() + 1;
     if ($i < $this->numberOfEncounters(1, DOUBLEELIMINATION_UPPER)) {
         if ($j >= $this->lastRound() - 2) {
             $field[$i][$j]['rowspan'] = $this->numberOfEncounters(1, DOUBLEELIMINATION_UPPER) * 2;
         } else {
             $field[$i][$j]['rowspan'] = pow(2, floor(($j + 1) / 2));
         }
         if ($j == 0 || $j >= $this->lastRound() - 2) {
             $field[$i][$j]['colspan'] = 1;
         } else {
             $field[$i][$j]['colspan'] = 3;
         }
     } else {
         $field[$i][$j]['colspan'] = 1;
         $field[$i][$j]['rowspan'] = pow(2, floor(($j + 1) / 2));
         if ($j % 2 == 1) {
             $field[$i][$j]['haslink'] = 2;
             $field[$i][$j]['linktext'] = 'L' . ($j + 1) . '.' . floor(($i - $this->numberOfEncounters(1, DOUBLEELIMINATION_UPPER)) / ($j + 1) + 1);
         } else {
             $field[$i][$j]['fromlink'] = TRUE;
         }
     }
     $field[$i][$j]['timestatus'] = $enc->getEncTimeState();
     if ($player1->getId() > 0 && $player2->getId() > 0) {
         $field[$i][$j]['link'] = makeUrl('tournament', array('tournamentid' => $this->tournamentId, 'encid' => $enc->getId(), 'roundid' => $j + 1, 'mode' => 'view'));
     } else {
         $field[$i][$j]['link'] = null;
     }
     $field[$i][$j]['p1name'] = $player1->getName();
     $field[$i][$j]['p1url'] = $player1->getUrl();
     $field[$i][$j]['p2name'] = $player2->getName();
     $field[$i][$j]['p2url'] = $player2->getUrl();
     $field[$i][$j]['nolink'] = $noLinkToArrow;
     if ($enc->isFinished()) {
         $field[$i][$j]['p1points'] = $enc->getPoints1();
         $field[$i][$j]['p2points'] = $enc->getPoints2();
         $field[$i][$j]['winner'] = $enc->winner();
     }
 }