Exemple #1
0
mysql_select_db("war3", $con);
$dirPath = '/Users/michael/war3/WarcraftReplays/';
$dh = opendir($dirPath);
$counter = 0;
while (($file = readdir($dh)) !== false) {
    if ($file[0] == '.') {
        continue;
    }
    if (!is_dir($dirPath . $file)) {
        continue;
    }
    echo "directory={$file}\n";
    //ok, go into the directory
    $dh2 = opendir($dirPath . $file);
    while (($warfile = readdir($dh2)) !== false) {
        if ($warfile[0] == '.') {
            continue;
        }
        $filename = $dirPath . $file . '/' . $warfile;
        if (is_dir($filename)) {
            continue;
        }
        echo "{$counter}: file=" . $filename . "\n";
        $counter++;
        $game = new game($filename);
        $game->insert($con);
    }
    closedir($dh2);
}
closedir($dh);
mysql_close($con);
        // insert the team_before to the database, then reset the team_before
        // add the score into the team_before.
        // var_dump($team_before);
        $score1 = current($team_before);
        $key1 = key($team_before);
        next($team_before);
        $score2 = current($team_before);
        $key2 = key($team_before);
        if ($score1 >= $score2) {
            $winner = [$key1 => $score1];
            $loser = [$key2 => $score2];
        } else {
            $winner = [$key2 => $score2];
            $loser = [$key1 => $score1];
        }
        $result = game::insert(key($winner), key($loser), current($winner), current($loser), $team_before[0]);
        // var_dump($result);
        $result = (array) $result;
        $game_id = $result["game_id"];
        $team1 = $result["Team1"];
        $team2 = $result["Team2"];
        printf("insert Game " . "{$game_id}: " . "{$team1}" . " and " . "{$team2}" . " succeeded!");
        ?>
		<br>
		<?php 
        // start to store the new game. Skip the last empty $game_i
        if (count($game_i) > 1) {
            unset($team_before);
            $team_before = [$game_i[2] => 0, $game_i[3] => 0, $game_i[4]];
            if ($game_i[5] == "fieldgoal") {
                $team_before[$game_i[2]] += 3;