Esempio n. 1
0
function replacePlayerLinks(&$news)
{
    $playertag_open = "<pl>";
    $playertag_close = "</pl>";
    while (stristr($news, $playertag_open)) {
        $startindex = strpos($news, $playertag_open);
        $endindex = strpos($news, $playertag_close);
        $startpos = $startindex + strlen($playertag_open);
        $name = substr($news, $startpos, $endindex - $startpos);
        $playerId = getIdForPlayer($name);
        if (!empty($playerId)) {
            $nameLink = getPlayerLinkId($name, $playerId);
            $news = str_replace($playertag_open . $name . $playertag_close, $nameLink, $news);
        } else {
            echo getBoxTop("Info", 0, true, '');
            echo "<p><b>Error:</b> Player <b>" . $name . "</b> not found!";
            echo getBoxBottom();
            return;
        }
    }
}
Esempio n. 2
0
function updateTeamladders()
{
    require 'variables.php';
    $playerLeader = "";
    $playerLeaderSaved = "";
    $teamLeader1 = "";
    $teamLeader1Saved = "";
    $teamLeader2 = "";
    $teamLeader2Saved = "";
    $time = time();
    // get current calculated leaders of both ladders
    // per player
    $sql = "SELECT player_id, teamWins/teamGames as percentage FROM {$playerstable} " . "WHERE teamGames > 0 AND approved='yes' ORDER BY teamPoints DESC, percentage DESC, teamLosses ASC";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if ($num > 0) {
        $row = mysql_fetch_array($result);
        $playerLeader = $row["player_id"];
    }
    // per team
    $teamStatSet = getTeamStandingsPerTeamArray();
    if (count($teamStatSet) > 0) {
        $teamLeader1 = getIdForPlayer($teamStatSet[0]->player1);
        $teamLeader2 = getIdForPlayer($teamStatSet[0]->player2);
    }
    // check current entries of teamladder table
    $sql = "SELECT playerId from {$teamladdertable} where type='player' ORDER BY timestamp DESC LIMIT 0, 1";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if ($num > 0) {
        $row = mysql_fetch_array($result);
        $playerLeaderSaved = $row["playerId"];
    }
    $sql = "SELECT playerId, playerId2 from {$teamladdertable} where type='team' ORDER BY timestamp DESC LIMIT 0, 1";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if ($num > 0) {
        $row = mysql_fetch_array($result);
        $teamLeader1Saved = $row["playerId"];
        $teamLeader2Saved = $row["playerId2"];
    }
    // update teamladder table if neccessary
    if ($playerLeader != $playerLeaderSaved) {
        // save new entry
        $sql = "INSERT INTO {$teamladdertable} (playerId, type, timestamp) VALUES ('{$playerLeader}', 'player', '{$time}')";
        mysql_query($sql);
    }
    if ($teamLeader1 != $teamLeader1Saved || $teamLeader2 != $teamLeader2Saved) {
        $sql = "INSERT INTO {$teamladdertable} (playerId, playerId2, type, timestamp) VALUES ('{$teamLeader1}', '{$teamLeader2}', 'team', '{$time}')";
        mysql_query($sql);
    }
}