function makeWWCLExport($eventid, $tournamentids, $eventinformation)
{
    require_once "participant.interface.php";
    require_once "singlePlayer.class.php";
    require_once "group.class.php";
    require_once "register.class.php";
    $register = new Register();
    require_once "tournament.abstract.class.php";
    global $db;
    $userinfo = array(-1 => 'F', 0 => 'F');
    $br = "\n";
    $event_info = $db->selectOneRow(MYSQL_TABLE_PREFIX . "events", "*", "eventid=" . $eventid);
    $tourneys = array();
    $allusers = array('C' => array(), 'P' => array());
    $tmpplayer = array();
    $tmpid = 1;
    //The upcounting id
    foreach ($tournamentids as $tournamentid) {
        $tournament = $db->selectOneRow(MYSQL_TABLE_PREFIX . "tournamentlist", "*", "tournamentid=" . $tournamentid);
        $playermode = $tournament['playerperteam'] > 1 ? "C" : "P";
        if ($playermode == 'P') {
            $tourneyusers = $db->selectList(MYSQL_TABLE_PREFIX . "tournamentregister", "*", "tournamentid=" . $tournamentid);
            foreach ($tourneyusers as $tourneyuser) {
                if (!array_key_exists($tourneyuser['memberid'], $allusers[$playermode])) {
                    $info = $db->selectOneRow(MYSQL_TABLE_PREFIX . "users", "nickname as name, email", "userid=" . $tourneyuser['memberid']);
                    // If a userfield has been selected for containing the wwcluserid
                    if ($eventinformation['wwcliduserfield'] >= 0) {
                        $wwclfield = $db->selectOneRow(MYSQL_TABLE_PREFIX . "personal_data", "*", "`userid`=" . $tourneyuser['memberid'] . " AND `fieldid`=" . $eventinformation['wwcliduserfield']);
                        if (preg_match("/^[0-9]+/", $wwclfield['value']) > 0) {
                            $curtmpid = $playermode . $wwclfield['value'];
                        } else {
                            $curtmpid = $playermode . 'T' . $tmpid++;
                        }
                    } else {
                        $curtmpid = $playermode . 'T' . $tmpid++;
                    }
                    $allusers[$playermode][$tourneyuser['memberid']] = array('tmpid' => $curtmpid);
                    $tmpplayer[] = array('id' => $tourneyuser['memberid'], 'tmpid' => $curtmpid, 'email' => $info['email'], 'name' => $info['name']);
                }
            }
        } else {
            $tourneygroups = $db->selectList(MYSQL_TABLE_PREFIX . "tournamentgroups", "*", "tournamentid=" . $tournamentid);
            foreach ($tourneygroups as $tourneyuser) {
                if (!array_key_exists($tourneyuser['groupid'], $allusers[$playermode])) {
                    $clanemail = $db->selectOneRow(MYSQL_TABLE_PREFIX . "users", "*", "userid=" . $tourneyuser['founderid']);
                    $setplayers[$playermode][] = $tourneyuser['groupid'];
                    $allusers[$playermode][$tourneyuser['groupid']] = array('tmpid' => $playermode . 'T' . $tmpid);
                    $tmpplayer[] = array('id' => $tourneyuser['groupid'], 'tmpid' => $playermode . 'T' . $tmpid++, 'email' => $clanemail['email'], 'name' => $tourneyuser['name']);
                }
            }
        }
    }
    foreach ($tournamentids as $tourneyid) {
        $dummy = $db->selectOneRow(MYSQL_TABLE_PREFIX . "tournamentlist", "*", "tournamentid=" . $tourneyid);
        $encounters = $db->selectList(MYSQL_TABLE_PREFIX . "tournamentencounters", "roundid, player1id, player2id, points1, points2, encounterid", "tournamentid=" . $tourneyid, "roundid ASC");
        $enc = array();
        $playermode = $dummy['playerperteam'] > 1 ? "C" : "P";
        switch ($dummy['mode']) {
            case 1:
                // Single Elimination
                $dummy['mode'] = 'S';
                $lastRound = $db->selectOneRow(MYSQL_TABLE_PREFIX . "tournamentencounters", "roundid, encounterid", "tournamentid=" . $tourneyid, "roundid DESC");
                foreach ($encounters as $encounter) {
                    if ($lastRound['roundid'] == $encounter['roundid'] && $encounter['encounterid'] == 1) {
                    } else {
                        $winner = ($encounter['player2id'] < 0 or $encounter['points1'] > $encounter['points2']) ? 1 : 2;
                        $winner_id = $winner == 1 ? $encounter['player1id'] : $encounter['player2id'];
                        $winner_tmpid = $winner_id > 0 ? $allusers[$playermode][$winner_id] : 'F';
                        $looser_id = $winner == 1 ? $encounter['player2id'] : $encounter['player1id'];
                        $looser_tmpid = $looser_id > 0 ? $allusers[$playermode][$looser_id] : 'F';
                        $enc['winner' . $encounter['roundid']][] = array('winner' => $winner_tmpid, 'looser' => $looser_tmpid);
                    }
                }
                // Adjust maxplayers
                $finalEnc = $db->selectOneRow('tournamentencounters', '*', "`tournamentid`=" . $tourneyid, "`roundid` DESC ");
                $dummy['playerlimit'] = pow(2, $finalEnc['roundid'] + 1);
                break;
            case 2:
                // Double Elimination
                $dummy['mode'] = 'D';
                $offset = $db->num_rows("tournamentencounters", "`tournamentid`=" . $tourneyid . " AND `roundid`=1");
                foreach ($encounters as $encounter) {
                    if (!($encounter['player1id'] <= 0 && $encounter['player2id'] <= 0)) {
                        $winner = ($encounter['player2id'] < 0 or $encounter['points1'] > $encounter['points2']) ? 1 : 2;
                        $winner_id = $winner == 1 ? $encounter['player1id'] : $encounter['player2id'];
                        $winner_tmpid = $winner_id > 0 ? $allusers[$playermode][$winner_id] : 'F';
                        $looser_id = $winner == 1 ? $encounter['player2id'] : $encounter['player1id'];
                        $looser_tmpid = $looser_id > 0 ? $allusers[$playermode][$looser_id] : 'F';
                        if ($encounter['encounterid'] >= $offset) {
                            $roundNr = $encounter['roundid'] - 1;
                        } else {
                            $roundNr = $encounter['roundid'] > 1 ? ceil($encounter['roundid'] / 2) : 0;
                        }
                        $bracket = $encounter['encounterid'] >= $offset ? 'looser' : 'winner';
                        $enc[$bracket . $roundNr][] = array('winner' => $winner_tmpid, 'looser' => $looser_tmpid);
                    }
                }
                // Adjust maxplayers
                $finalEnc = $db->selectOneRow('tournamentencounters', '*', "`tournamentid`=" . $tourneyid, "`roundid` DESC ");
                $dummy['playerlimit'] = pow(2, (int) ($finalEnc['roundid'] / 2));
                break;
                // Groups
                // Points
                // Randomize
                // King of the Hill
            // Groups
            // Points
            // Randomize
            // King of the Hill
            default:
                $tournament_obj = getTournamentObject($dummy);
                $ranking = $tournament_obj->ranking();
                $dummy['mode'] = 'M';
                foreach ($ranking as $players) {
                    foreach ($players['participants'] as $player) {
                        $enc[] = array('rank' => $players['rank'], 'user' => $allusers[$playermode][$player['userid']]);
                    }
                }
                break;
        }
        $dummy['enc'] = $enc;
        $tourneys[] = $dummy;
    }
    $e = '<wwcl>' . $br;
    $e .= spaceTabs(1) . '<submit>' . $br;
    $e .= spaceTabs(2) . '<tool>' . $br . spaceTabs(3) . 'LAN Party Manager IV' . $br . spaceTabs(2) . '</tool>' . $br;
    $e .= spaceTabs(2) . '<timestamp>' . $br . spaceTabs(3) . time() . $br . spaceTabs(2) . '</timestamp>' . $br;
    $e .= spaceTabs(2) . '<party_name>' . $br . spaceTabs(3) . $eventinformation['eventname'] . $br . spaceTabs(2) . '</party_name>' . $br;
    $e .= spaceTabs(2) . '<pid>' . $br . spaceTabs(3) . $eventinformation['partyid'] . $br . spaceTabs(2) . '</pid>' . $br;
    $e .= spaceTabs(2) . '<pvdid>' . $br . spaceTabs(3) . $eventinformation['organizerid'] . $br . spaceTabs(2) . '</pvdid>' . $br;
    $e .= spaceTabs(2) . '<stadt>' . $br . spaceTabs(3) . $eventinformation['partycity'] . $br . spaceTabs(2) . '</stadt>' . $br;
    $e .= spaceTabs(1) . '</submit>' . $br;
    $e .= spaceTabs(1) . '<tmpplayer>' . $br;
    foreach ($tmpplayer as $user) {
        $e .= spaceTabs(2) . '<data>' . $br;
        $e .= spaceTabs(3) . '<tmpid>' . $br . spaceTabs(4) . $user['tmpid'] . $br . spaceTabs(3) . '</tmpid>' . $br;
        $e .= spaceTabs(3) . '<name>' . $br . spaceTabs(4) . $user['name'] . $br . spaceTabs(3) . '</name>' . $br;
        $e .= spaceTabs(3) . '<email>' . $br . spaceTabs(4) . $user['email'] . $br . spaceTabs(3) . '</email>' . $br;
        $e .= spaceTabs(2) . '</data>' . $br;
    }
    $e .= spaceTabs(1) . '</tmpplayer>' . $br;
    foreach ($tourneys as $tourney) {
        $e .= spaceTabs(1) . '<tourny>' . $br;
        $e .= spaceTabs(2) . '<name>' . $br . spaceTabs(3) . wwclGameIdToString($tourney['wwclgameid']) . $br . spaceTabs(2) . '</name>' . $br;
        $e .= spaceTabs(2) . '<gid>' . $br . spaceTabs(3) . $tourney['wwclgameid'] . $br . spaceTabs(2) . '</gid>' . $br;
        $e .= spaceTabs(2) . '<maxplayer>' . $br . spaceTabs(3) . $tourney['playerlimit'] . $br . spaceTabs(2) . '</maxplayer>' . $br;
        $e .= spaceTabs(2) . '<mode>' . $br . spaceTabs(3) . $tourney['mode'] . $br . spaceTabs(2) . '</mode>' . $br;
        switch ($tourney['mode']) {
            case 'S':
            case 'D':
                foreach ($tourney['enc'] as $roundname => $round) {
                    $e .= spaceTabs(2) . '<' . $roundname . '>' . $br;
                    foreach ($round as $encounter) {
                        $e .= spaceTabs(3) . '<match>' . $br;
                        $e .= spaceTabs(4) . '<win>' . $br . spaceTabs(5) . $encounter['winner']['tmpid'] . $br . spaceTabs(4) . '</win>' . $br;
                        $e .= spaceTabs(4) . '<loose>' . $br . spaceTabs(5) . $encounter['looser']['tmpid'] . $br . spaceTabs(4) . '</loose>' . $br;
                        $e .= spaceTabs(3) . '</match>' . $br;
                    }
                    $e .= spaceTabs(2) . '</' . $roundname . '>' . $br;
                }
                break;
            case 'M':
                foreach ($tourney['enc'] as $data) {
                    $e .= spaceTabs(2) . '<data>' . $br;
                    $e .= spaceTabs(3) . '<rank>' . $br . spaceTabs(4) . $data['rank'] . $br . spaceTabs(3) . '</rank>' . $br;
                    $e .= spaceTabs(3) . '<id>' . $br . spaceTabs(4) . $data['user']['tmpid'] . $br . spaceTabs(3) . '</id>' . $br;
                    $e .= spaceTabs(2) . '</data>' . $br;
                }
                break;
        }
        $e .= spaceTabs(1) . '</tourny>' . $br;
    }
    $e .= '</wwcl>';
    return $e;
}
Beispiel #2
0
         $breadcrumbs->addElement($event['name'], makeURL($mod, array('eventid' => $eventid)));
     }
     if ($tournamentid == 0) {
         // Show tournament list
         $smarty->assign('path', $template_dir . "/overview.tpl");
         $smarty->assign('tournamentList', $tournamentList->getList($eventid));
         $smarty->assign('modenames', $modes);
     }
 } else {
     // Show tournament overview
     $tournament['event']['url'] = makeURL('events', array('eventid' => $tournament['event']['eventid']));
     $tournament['playerperteam_str'] = $tournament['playerperteam'] . " (" . $tournament['playerperteam'] . " on " . $tournament['playerperteam'] . ")";
     $tournament['mode_str'] = $modes[$tournament['mode']];
     $tournament['state_str'] = tournamentStateToString($tournament['state']);
     $tournament['start_str'] = date("d.m.Y H:i", $tournament['start']) . ' ' . timeLeft($tournament['start']);
     $tournament['wwclgameid_str'] = wwclGameIdToString($tournament['wwclgameid']);
     $tournament['mappool_str'] = str_replace(";", ", ", $tournament['mappool']);
     // add tree submenu
     if (($tournament['state'] == 2 || $tournament['state'] == 3) && $tournament['mode'] != 5) {
         $menu->addSubElement($mod, $lang->get('tournament_table'), 'table', array('tournamentid' => $tournamentid));
     }
     @$breadcrumbs->addElement($tournament['event']['name'], makeURL($mod, array('eventid' => $tournament['event']['eventid'])));
     $breadcrumbs->addElement($tournament['title'], makeURL($mod, array('tournamentid' => $tournamentid)));
     // Create a new instance of tournament class
     require_once $mod_dir . "/tournament.abstract.class.php";
     require_once $mod_dir . "/participant.interface.php";
     require_once $mod_dir . "/singlePlayer.class.php";
     require_once $mod_dir . "/group.class.php";
     require_once $mod_dir . "/tournament.eliminationencounter.class.php";
     global $tournament_obj;
     switch ($tournament['mode']) {