function section_register_validate(&$se) { if (($msg = $se->validateName($se->callsign, 'Callsign')) != '') { $se->setError('callsign', $msg); } else { if (sqlQuerySingle("select callsign from l_player where callsign='{$se->callsign}' and status!='deleted'")) { $se->setError('callsign', 'That callsign is already used by another player.'); } } if ($se->password != $se->password2) { $se->setError('password', 'The passwords do not match!'); $se->password = $se->password2 = ''; } else { if (strlen($se->password) < 3) { $se->setError('password', 'Password must be at least 3 characters long'); $se->password = $se->password2 = ''; } } if ($se->country == null) { $se->setError('country', 'Please select your location (country)'); } if (!$se->validateEmail($se->email)) { $se->setError('email', 'Enter a valid email address'); } }
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; }
function section_fights_pageStartSeasonal($season_id) { $now = nowDateTime(); $season = sqlQuerySingle("SELECT startdate,enddate FROM l_season WHERE id = {$season_id}"); $season_next = 0; $season_prev = 0; $season_prev = sqlQuerySingle("select id from l_season where enddate < '{$season->startdate}' ORDER BY enddate desc limit 1"); if ($season_prev) { $season_prev = $season_prev->id; } $season_next = sqlQuerySingle("select id from l_season where startdate > '{$season->enddate}' and startdate <= '{$now}' ORDER BY startdate asc limit 1"); if ($season_next) { $season_next = $season_next->id; } echo "<TABLE align=center><TR class=contTitle>"; if ($season_prev > 1) { echo "<TD width=60px align=left>" . matchesLink($season_prev, "previous") . "</td>"; } else { echo "<TD width=60px align=left></td>"; } echo "<TD>Showing matches for the "; if (strtotime($season->startdate) <= strtotime($now) && strtotime($season->enddate) >= strtotime($now)) { echo "current "; } echo "season {$season->startdate} - {$season->enddate}</td>"; echo "<TD width=60px align=right> " . seasonLink("season", $season_id, 1) . "</td>"; if ($season_next > 1) { echo "<TD width=60px align=right>" . matchesLink($season_next, "next") . "</td>"; } else { echo "<TD width=60px align=right></td>"; } echo '</tr>'; echo "<tr><td colspan=4>"; }