示例#1
0
function section_entermatch_recalcSeasonRatings($season_id = -1)
{
    $now = nowDateTime();
    $INDEX_ZELO = array();
    $INDEX_MATCHES = array();
    $INDEX_WIN = array();
    $INDEX_LOST = array();
    $INDEX_DRAW = array();
    $INDEX_DATE = array();
    $SEASON_RECALC = array();
    $dirty = false;
    // select a season to update
    if ($season_id < 0) {
        $season = sqlQuerySingle("select * from l_season where startdate <= '{$now}' and fdate >= '{$now}' and id > 1 limit 1");
        if (!$season) {
            $season = sqlQuerySingle("select * from l_season where active='yes' and id > 1 limit 1");
        }
        if (!$season) {
            $season = sqlQuerySingle("select * from l_season where finished='yes' and id > 1 ORDER by fdate desc limit 1");
        }
        $season_id = $season ? $season->id : -1;
    } else {
        if ($season_id > 1) {
            $season = sqlQuerySingle("select * from l_season where id = {$season_id}");
        }
    }
    if (!$season || $season_id < 2 || !$season->enddate) {
        echo "<tr><td colspan=4><font class=feedback><BR>No season found to update [#{$season_id}]</font></td></tr>";
        return;
    }
    echo "<tr><td colspan=4><font class=feedback><BR>Update season ranking: {$season->startdate} - {$season->enddate} [id={$season->id}]</font></td></tr>\n        <tr class=tabhead><td colspan=4>Check matches</td></tr>";
    $matches = sqlQuery($sql = "select * from " . TBL_MATCH . " where season = {$season_id} or (tsactual >= '{$season->startdate} 00:00:00' and tsactual <= '{$season->enddate} 23:59:59') order by tsactual");
    while ($row = mysql_fetch_object($matches)) {
        $team1 = null;
        $team2 = null;
        // 1. check if season id is ok
        if ($row->season != $season_id) {
            if (!$team1) {
                $team1 = queryGetTeamName($row->team1);
            }
            if (!$team2) {
                $team2 = queryGetTeamName($row->team2);
            }
            echo "<tr><td>{$team1} vs {$team2}</td><td><nobr>{$row->tsactual}</nobr></td><td colspan=2><nobr> changed season [{$row->season} to {$season_id}]</nobr></td></tr>";
            sqlQuery("update " . TBL_MATCH . " set season = {$season_id} where id = {$row->id}");
            $SEASON_RECALC[$new_season] = true;
            next;
        } else {
            // 2. startdate check if match is in season
            // OR 3. enddate: check if match is in season
            if (strtotime($row->tsactual) < strtotime($season->startdate) || strtotime($row->tsactual) > strtotime($season->enddate)) {
                if (!$team1) {
                    $team1 = queryGetTeamName($row->team1);
                }
                if (!$team2) {
                    $team2 = queryGetTeamName($row->team2);
                }
                $new_season = sqlQuerySingle("select * from l_season where startdate <= '{$row->tsactual}' and enddate >= '{$row->tsactual}' and id > 1 limit 1");
                $new_season = $new_season ? $new_season->id : 1;
                if ($season_id != $new_season) {
                    echo "<tr><td>{$team1} vs {$team2}</td><td><nobr>{$row->tsactual}</nobr></td><td colspan=2><nobr> changed season due to seasondates [{$season_id} -> {$new_season}]</nobr></td></tr>";
                    sqlQuery("update " . TBL_MATCH . " set season = {$new_season} where id = {$row->id}");
                    $SEASON_RECALC[$new_season] = true;
                    next;
                }
            }
        }
        // 4. update values
        $INDEX_ZELO[$row->team1] = $INDEX_ZELO[$row->team1] ? $INDEX_ZELO[$row->team1] : 1200;
        $INDEX_ZELO[$row->team2] = $INDEX_ZELO[$row->team2] ? $INDEX_ZELO[$row->team2] : 1200;
        $INDEX_DATE[$row->team1] = $row->tsactual;
        $INDEX_DATE[$row->team2] = $row->tsactual;
        $INDEX_MATCHES[$row->team1] = $INDEX_MATCHES[$row->team1] ? $INDEX_MATCHES[$row->team1] + 1 : 1;
        $INDEX_MATCHES[$row->team2] = $INDEX_MATCHES[$row->team2] ? $INDEX_MATCHES[$row->team2] + 1 : 1;
        if ($row->score1 > $row->score2) {
            $INDEX_WIN[$row->team1] = $INDEX_WIN[$row->team1] ? $INDEX_WIN[$row->team1] + 1 : 1;
            $INDEX_LOST[$row->team2] = $INDEX_LOST[$row->team2] ? $INDEX_LOST[$row->team2] + 1 : 1;
        } else {
            if ($row->score1 < $row->score2) {
                $INDEX_LOST[$row->team1] = $INDEX_LOST[$row->team1] ? $INDEX_LOST[$row->team1] + 1 : 1;
                $INDEX_WIN[$row->team2] = $INDEX_WIN[$row->team2] ? $INDEX_WIN[$row->team2] + 1 : 1;
            } else {
                $INDEX_DRAW[$row->team1] = $INDEX_DRAW[$row->team1] ? $INDEX_DRAW[$row->team1] + 1 : 1;
                $INDEX_DRAW[$row->team2] = $INDEX_DRAW[$row->team2] ? $INDEX_DRAW[$row->team2] + 1 : 1;
            }
        }
        section_entermatch_calculateRating($row->score1, $row->score2, $INDEX_ZELO[$row->team1], $INDEX_ZELO[$row->team2], &$newA, &$newB);
        $INDEX_ZELO[$row->team1] = $newA;
        $INDEX_ZELO[$row->team2] = $newB;
    }
    echo "<tr><td colspan=4><hr></td></tr>\n        <tr class=tabhead><td colspan=4>Check team scores</td></tr>\n        <tr class=tabhead>\n          <td>Team</td>\n          <td>Action</td>\n          <td>Old</td>\n          <td>New</td>\n        </tr>";
    // now update all teams for which a match was found
    $keys = array_keys($INDEX_MATCHES);
    for ($x = 0; $x < count($keys); $x++) {
        $teamId = $keys[$x];
        $matches = $INDEX_MATCHES[$teamId];
        $won = $INDEX_WIN[$teamId] ? $INDEX_WIN[$teamId] : 0;
        $lost = $INDEX_LOST[$teamId] ? $INDEX_LOST[$teamId] : 0;
        $draw = $INDEX_DRAW[$teamId] ? $INDEX_DRAW[$teamId] : 0;
        $date = $INDEX_DATE[$teamId] ? $INDEX_DATE[$teamId] : null;
        $zelo = $INDEX_ZELO[$teamId] ? $INDEX_ZELO[$teamId] : 1200;
        $row = sqlQuerySingle("select 1 from l_teamscore where team = {$teamId} and season = {$season_id}");
        if (!$row) {
            sqlQuery("insert into l_teamscore (team,season,tsedit,tsmatch) values ({$teamId},{$season_id},'{$now}','{$date}')");
        }
        $row = sqlQuerySingle("select won,lost,draw,matches,zelo from l_teamscore where team = {$teamId} and season = {$season_id}");
        if ($won != $row->won || $lost != $row->lost || $draw != $row->draw || $zelo != $row->zelo) {
            $team1 = queryGetTeamName($teamId);
            $dirty = true;
            echo "<tr><td>{$team1}</td><td>Update</td><td>{$row->won} -  {$row->lost} - {$row->draw} ({$row->zelo})</td><td>{$won} - {$lost} - {$draw} ({$zelo})</td></tr>";
            sqlQuery("update l_teamscore \n                  set won     = {$won},\n                      lost    = {$lost},\n                      draw    = {$draw},\n                      zelo    = {$zelo},\n                      matches = {$matches},   \n                      tsedit  = '{$now}',\n                      tsmatch = '{$date}'\n                  where team  = {$teamId} and season = {$season_id}");
        }
    }
    echo "<tr><td colspan=4><hr></td></tr>\n        <tr class=tabhead><td colspan=4>Remove teams with no matches</td></tr>\n        <tr class=tabhead>\n          <td>Team</td>\n          <td>Action</td>\n          <td colspan=2>Reason</td>\n        </tr>";
    // now check if in the season we have teams that didn't play a match
    //  - question: how to do an intelligent query when MySQL 4.0 doesn't allow EXIST statements
    $tscores = sqlQuery("select * from l_teamscore where season = {$season_id}");
    while ($row = mysql_fetch_object($tscores)) {
        $exists = sqlQuerySingle("select * from " . TBL_MATCH . " where (team1 = {$row->team}  OR team2 = {$row->team}) AND season = {$season_id} limit 1");
        if (!$exists) {
            $team1 = queryGetTeamName($row->team);
            echo "<tr><td>{$team1}</td><td>Delete</td><td colspan=2>Didn't play any matches</td></tr>";
            $dirty = true;
            sqlQuery("DELETE FROM l_teamscore WHERE season = {$season_id} AND team = {$row->team}");
        }
    }
    # seasion id 1 is not a real season.
    foreach (array_keys($SEASON_RECALC) as $i) {
        if ($i != 1) {
            section_entermatch_recalcSeasonRatings($i);
        }
    }
    if ($dirty) {
        if ($season->finished == 'yes') {
            echo "<tr><td colspan=4><hr></td></tr>";
            echo '<tr><td colspan=4>Match change has an effect on season ' . $season->startdate . ' - ' . $season->enddate . '. Update season score manually</td></tr>';
            sqlQuery("UPDATE l_season SET dirty = 'yes' WHERE id= {$season_id}");
            return true;
        }
    }
    return false;
}
示例#2
0
function section_playerinfo_displayPlayer(&$se)
{
    $s_level = $_SESSION['level'];
    $s_logedin = isAuthenticated();
    $s_playerid = $_SESSION['playerid'];
    $s_leader = $_SESSION['leader'];
    $s_teamid = $_SESSION['teamid'];
    $editAny = isFuncAllowed('edit_any_players');
    echo '<table width=90% align=center border=0 cellspacing=0 cellpadding=1>
    <tr><td class=playername align=center>' . $se->callsign . '<BR><BR></td></tr>';
    // Logo if any
    if ($se->logo != "") {
        echo '<tr><td align=center>' . section_playerinfo_dispLogo($se->logo, $se->logobg) . '<hr></td></tr>';
    }
    // Bio if any
    if ($se->comment != "") {
        echo "<tr><td class=playerbio>" . nl2br($se->comment) . "<hr></td></tr>";
    }
    // misc info ....
    echo '</td></tr><TR><TD><table align=center><TR><TD width=100 valign=top align=left>';
    if ($se->flagname) {
        echo '<img src="' . FLAG_DIR . "c-{$se->flagname}.gif\">";
    }
    echo '</td><TD><TABLE>';
    // Team if any
    if ($se->teamname != "") {
        echo "<tr><td>";
        if ($se->leader == $se->id) {
            $d = '<nobr>Leader (<img src="' . THEME_DIR . 'leader.gif">) of team</nobr>';
        } else {
            $d = "<nobr>Member of team</nobr>";
        }
        section_playerinfo_tab2($d, htmlLink($se->teamname, 'teaminfo', "id={$se->teamid}"));
    } else {
        echo "<tr><td align=center colspan=2>Does not belong to any team</td></tr>";
    }
    if ($se->altnik1 || $se->altnik2) {
        if ($se->altnik1 && $se->altnik2) {
            $plural = 's';
            $niks = $se->altnik1 . ', &nbsp;&nbsp;' . $se->altnik2;
        } else {
            if ($se->altnik1) {
                $niks = $se->altnik1;
            } else {
                $niks = $se->altnik2;
            }
        }
        section_playerinfo_tab2("<nobr>Alternate callsign{$plural}</nobr>", $niks);
    }
    if ($se->countryname) {
        $loc = $se->countryname;
        if ($se->stateabbr) {
            $loc .= '&nbsp;&nbsp;(';
            if ($se->city) {
                $loc .= $se->city . ', ';
            }
            $loc .= "{$se->stateabbr})";
        }
        section_playerinfo_tab2('Location', $loc);
    }
    if ($se->utczone || $se->zonename) {
        section_playerinfo_tab2('Time zone', 'GMT ' . section_playerinfo_numPlus($se->utczone) . "&nbsp;&nbsp;({$se->zonename})");
    }
    section_playerinfo_tab2('Site Member Since', date('Y-m-d', $se->created));
    if (isset($se->last_login)) {
        section_playerinfo_tab2('Last login', date('Y-m-d H:i', $se->last_login));
    }
    echo '<TR><TD colspan=2><HR></td></tr>';
    if ($se->emailpub == 'Y') {
        section_playerinfo_tab2('email', section_playerinfo_obsMail($se->email));
    }
    section_playerinfo_tab2('AIM', $se->aim);
    section_playerinfo_tab2('IRC', $se->ircnik1);
    section_playerinfo_tab2('ICQ', $se->icq);
    section_playerinfo_tab2('YIM', $se->yim);
    section_playerinfo_tab2('MSM', $se->msm);
    section_playerinfo_tab2('Jabber', $se->jabber);
    echo '</table></td><TD width=50></td></tr></table></tr>';
    // Frequentation statistics
    if ($se->status != 'deleted') {
        echo '<tr><td><BR><BR>';
        section_playerinfo_Frequentation($se->id);
        echo '<BR></td></tr>';
    }
    if ($se->status != 'deleted') {
        // Send a message to this player (but not to myself!)
        if ($s_logedin && $s_playerid != $se->id) {
            echo '<tr><td><hr></td></tr><tr align=center><td><TABLE><TR><TD>' . htmlURLbutton('SEND BZmessage', 'sendmessage', "pid={$se->id}");
            // If I am a team leader, and my team is not full, I can invite him
            if (isAuthenticated() && $_SESSION['leader']) {
                // Check if my team full
                $team = mysql_fetch_object(mysql_query("select count(*) as num from l_player where team={$s_teamid}"));
                if ($team->num < 20) {
                    $mytn = queryGetTeamName($s_teamid);
                    echo '<TD width=5></td><TD>' . htmlURLbutton("INVITE to {$mytn}", 'invite', "id={$se->id}") . '</td>';
                }
            }
            echo '</tr></table></td></tr>';
        }
        // Administrators and owner can edit a player
        if ($s_logedin && ($editAny || $s_playerid == $se->id)) {
            if ($editAny && $s_playerid != $se->id) {
                $class = ADMBUT;
            }
            echo '<tr><td align=center><hr><TABLE><TR><TD>' . htmlURLbutton('Edit Profile', 'playeradmin', "id={$se->id}&edt_st=1", $class);
            if (isFuncAllowed('visitlog::visit_log')) {
                echo '</td><TD width=5></td><TD>' . htmlURLbutton('Visits', 'visitlog', "id={$se->id}", ADMBUT);
            }
            if (isFuncAllowed('deleteplayer::delete_player') && $se->role_id != ADMIN_PERMISSION) {
                echo '</td><TD width=5></td><TD>' . htmlURLbutton('DELETE Player', 'deleteplayer', "id={$se->id}", ADMBUT);
            }
            echo '</td></tr></table></td></tr>';
        }
    }
    echo "</table>";
}