From 5b23aea4a86478617dcd398a9ce57ea6cfbaac21 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Sat, 21 Apr 2012 23:29:54 -0700 Subject: Changed dating used on the scoreboard to real dates. --- pages/leaderboard.php | 53 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/pages/leaderboard.php b/pages/leaderboard.php index 968e4df..fafcb23 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -1,5 +1,5 @@ @@ -13,13 +13,41 @@ include('./includes/datas.php'); include_once ('./includes/db.inc.php'); -//Display stats for how many days ago? -$daysago = 1; -if (($_GET['daysago'] * 1) > 1) { - $daysago = ($_GET['daysago'] * 1); -} + +//Holy non-PHP included function batman. +function date_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; +} + +$dateCurrent = date('Y-m-d', strtotime("-2 days")); + +//This is only used in a strtotime function, so this should be safe. +$dateLookup = $_GET['date']; +if (!strtotime($dateLookup)) + $dateLookup = $dateCurrent; + +//!!Some validation should take place on dateLookup +$daysago = date_diff($dateLookup, date('Y-m-d')); +$dateAgo = strtotime("-$daysago days"); + +$dateAsStr = date('l F dS Y', $dateAgo); + +$dateNextDay = date('Y-m-d', strtotime("+1 day", $dateAgo)); +$datePrevDay = date('Y-m-d', strtotime("-1 day", $dateAgo)); + +//Offset the days-ago for map-lookups. +$daysago--; +if ($daysago < 1) + die("You must specify a date previous to today."); $tStats = getStat(1, $daysago); $yStats = getStat(2, $daysago); @@ -95,16 +123,17 @@ function getStat ($type, $daysago = 1) {
+
+Showing scores for the maps played on +
1) { - $nextday = $daysago - 1; - echo "Current Day"; - echo "Next Day"; + echo "Current Day"; + echo "Next Day"; } - $prevday = $daysago + 1; - echo "Previous Day"; + echo "Previous Day"; ?>
@@ -296,7 +325,7 @@ showStats(1);
- Copyright © 2011 pathery.com + Copyright © 2011-2012 pathery.com
-- cgit v1.2.3