Example #1
0
function updateMatches()
{
    $event = new Event($_POST['name']);
    if (isset($_POST['matchdelete'])) {
        foreach ($_POST['matchdelete'] as $matchid) {
            Match::destroy($matchid);
        }
    }
    if (isset($_POST['dropplayer'])) {
        foreach ($_POST['dropplayer'] as $playername) {
            $event->dropPlayer($playername);
        }
    }
    if (isset($_POST['hostupdatesmatches'])) {
        for ($ndx = 0; $ndx < sizeof($_POST['hostupdatesmatches']); $ndx++) {
            $result = $_POST['matchresult'][$ndx];
            $resultForA = "notset";
            $resultForB = "notset";
            if ($result == "2-0") {
                $resultForA = "W20";
                $resultForB = "L20";
            } elseif ($result == "2-1") {
                $resultForA = "W21";
                $resultForB = "L21";
            } elseif ($result == "1-2") {
                $resultForA = "L21";
                $resultForB = "W21";
            } elseif ($result == "0-2") {
                $resultForA = "L20";
                $resultForB = "W20";
            } elseif ($result == 'D') {
                // TODO: need to figure out how to enter a draw
            }
            if (strcasecmp($resultForA, 'notset') != 0 && strcasecmp($resultForB, 'notset') != 0) {
                $matchid = $_POST['hostupdatesmatches'][$ndx];
                Match::saveReport($resultForA, $matchid, 'a');
                Match::saveReport($resultForB, $matchid, 'b');
            }
        }
    }
    if (isset($_POST['newmatchplayerA'])) {
        $pA = $_POST['newmatchplayerA'];
    } else {
        $pA = "";
    }
    if (isset($_POST['newmatchplayerB'])) {
        $pB = $_POST['newmatchplayerB'];
    } else {
        $pB = "";
    }
    if (isset($_POST['newmatchresult'])) {
        $res = $_POST['newmatchresult'];
        if ($res == "2-0") {
            $pAWins = 2;
            $pBWins = 0;
            $res = 'A';
        } elseif ($res == "2-1") {
            $pAWins = 2;
            $pBWins = 1;
            $res = 'A';
        } elseif ($res == "1-2") {
            $pAWins = 1;
            $pBWins = 2;
            $res = 'B';
        } elseif ($res == "0-2") {
            $pAWins = 0;
            $pBWins = 2;
            $res = 'B';
        } elseif ($res == 'D') {
            $pAWins = 0;
            $pBWins = 0;
            $res = 'D';
        }
    } else {
        $res = "";
    }
    if (isset($_POST['newmatchround'])) {
        $rnd = $_POST['newmatchround'];
    } else {
        $rnd = "";
    }
    if (strcmp($pA, "") != 0 && strcmp($pB, "") != 0 && strcmp($res, "") != 0 && strcmp($rnd, "") != 0) {
        if ($res == "P") {
            $event->addPairing($pA, $pB, $rnd, $res);
        } else {
            $event->addMatch($pA, $pB, $rnd, $res, $pAWins, $pBWins);
        }
    }
    if (isset($_POST['newbyeplayer']) && strcmp($_POST['newbyeplayer'], "") != 0) {
        $p = $_POST['newbyeplayer'];
        $event->addMatch($p, $p, $rnd, 'BYE');
    }
}