Work in progress

< Previous Day Next Day > Yesterday >>
<
>
name == '') $map->name = $mapNamesByType[$mapType]; $r[$mapID] = $map; } return $r; } function getMapNavigation(&$maps) { foreach ($maps as $mapID => &$map) { $r .= "
"; $r .= $map->name; $r .= DisplayMapThumbnail($map); $r .= "
";; } return $r; } $time_start = microtime(true); $special = 'Special'; if ($specialMapName != '') $special = $specialMapName; ?>

"; $headers .= "Rank"; $headers .= "Name"; $headers .= "Moves"; $headers .= "Time taken"; $headers .= ""; //Start table //$r .= ""; //$r .= ""; //Headers on the top. including Rank. //$r .= ""; //$r .= $headers; //$r .= ""; $i = 1; $championPoints = null; while ($row = mysql_fetch_assoc($result)) { $rowcontent = ''; $mapid = $row['mapID']; $solution = $row['solution']; $wallColor = $row['wallColor']; $wallEmblem = $row['wallEmblem']; $displayColor = $row['displayColor']; $displayName = $row['Name']; $userID = $row['userID']; //Default if ($wallColor == '') $wallColor = '#666666'; $x = "\n"; $x .= ""; $x .= ""; //$x .= "'; $x .= ''; $x .= ''; $x .= ""; if ($userID == $_SESSION['userID']) { $promotedContent .= $x; $championPoints = $row['championPointsWorth']; } else { $content .= $x; } $i++; } $r = ''; if($championPoints != null && $championPoints > 0) { $r .= "
Points earned: $championPoints
"; } $r .= "
$caption
$i$displayName" . $row['Name'] . '' . $row['Moves'] . '' . $row['Timetaken'] . '
"; $r .= ""; $r .= $headers; $r .= $promotedContent; $r .= $content; $r .= "
$caption
"; return $r; } function day_diff($date1, $date2) { $current = $date1; $datetime2 = date_create($date2); $count = 0; while(date_create($current) < $datetime2){ $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current))); $count++; } return $count; } function getStat ($type, $daysAgo = 1) { switch ($type) { //Todays case 1: $where = " DATE_ADD(CURDATE(), INTERVAL -0 DAY) = DATE_FORMAT(solutions.dateModified,'%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL -0 DAY) = DATE_FORMAT(maps.dateCreated,'%Y-%m-%d') "; $statname = "Today's Best Overall:"; break; //Yesterdays case 2: $where = " DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) = DATE_FORMAT(solutions.dateModified,'%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) = DATE_FORMAT(maps.dateCreated,'%Y-%m-%d') "; $statname = "Yesterday's Best Overall:"; if ($daysAgo > 1) { $statname = "$daysAgo days ago's Best Overall."; } break; case 3: $where = " YEARweek(solutions.dateModified) = YEARweek(CURRENT_DATE) "; $statname = "This week, starting Sunday"; break; case 4: $where = " ( month(solutions.dateModified) = month(CURRENT_DATE) AND year(solutions.dateModified) = year(CURRENT_DATE) ) "; $statname = "This month's Best"; break; } $sql = "SELECT users.displayName as Name, SUM(solutions.moves) as Moves, timediff(MAX(dateModified), maps.dateCreated) as Timetaken, users.wallColor, users.wallEmblem, users.displayColor, users.ID as userID, SUM(CASE WHEN solutions.dateModified < CURDATE() THEN solutions.championPointsWorth ELSE 0 END) AS championPointsWorth FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID JOIN `users` ON solutions.userID = users.ID WHERE $where GROUP BY solutions.userID ORDER BY Moves DESC, MAX(dateModified) ASC "; $result = mysql_query($sql); return displayStats($result, $statname); } function displayPastMaze($mapType, $name, $daysAgo = 1) { //Ensure no cheating if ($daysAgo < 1) return; $pastMap = pastMap($mapType, $daysAgo); $mapID = $pastMap; $mapcode = getMapCode($mapID); $map = GenerateMapByCode($mapcode); $sql = "SELECT maps.ID as mapID, solution, users.displayName as Name, SUM(solutions.moves) as Moves, timediff(solutions.dateModified, maps.dateCreated) as Timetaken, users.wallColor, users.wallEmblem, users.displayColor, users.ID as userID, solutions.championPointsWorth FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID JOIN `users` ON solutions.userID = users.ID JOIN `mapOfTheDay` ON maps.ID = mapOfTheDay.mapID WHERE maps.ID = '$mapID' GROUP BY solutions.userID ORDER BY Moves DESC, `dateModified` ASC "; $result = mysql_query($sql) or die(mysql_error()); $statname = "Yesterday's Best $name:"; if ($daysAgo > 1) { $statname = "$daysAgo days ago's Best $name:"; } $stats = displayStats($result, $statname); //Sucky temporary solution: $GLOBALS['specialMapName'] = $map[0][6]; $sql = "SELECT `moves`, `displayName`, `solution` FROM `solutions` LEFT JOIN `users` ON solutions.userID = users.ID WHERE `mapID` = '$mapID' ORDER BY `moves` DESC, `dateModified` ASC LIMIT 1"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { list($bestMoves, $byName, $solution) = mysql_fetch_row($result); } $r = ''; $r .= '
'; $r .= "
"; $r .= '
'; $r .= $stats; $r .= '
'; $r .= '
'; $r .= "Best solution for this map: $bestMoves by $byName "; $r .= DisplayMap($map, $mapID, 'normal', 2); $r .= '
'; $r .= '
'; return $r; } ?>