From 3b784cd8a8a0eb6028fd61a6ee60c39923c30bd9 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 21 Feb 2013 22:48:02 -0800 Subject: Preperation for cacheing scores. --- ajax/scores.ajax.php | 170 ++++++++------------------------------------------- do.php | 2 + js/scores.js | 8 ++- 3 files changed, 35 insertions(+), 145 deletions(-) diff --git a/ajax/scores.ajax.php b/ajax/scores.ajax.php index 1404a19..f2d38fc 100644 --- a/ajax/scores.ajax.php +++ b/ajax/scores.ajax.php @@ -10,151 +10,35 @@ require('../includes/mapclass.php'); require('../includes/datas.php'); include_once('../includes/sqlEmbedded.php'); -if ($_GET['getmap'] == 'true') { - $mapID = $_GET['mapID']; - $code = getMapCode($mapID); - $map = GenerateMapByCode($code); - echo displaymap($map, $mapID); -} - - -if ($_GET['getscores'] == 'true') { - -} - -if ($_GET['getmaplist'] == 'true') { - $daysAgo = $_GET['daysago']; - //echo "$daysAgo"; - $todaysScoreMaps = getMapsPlayed($daysAgo); - echo getMapNavigation($todaysScoreMaps); -} - -if (isset($_GET['getmapidsbydate'])) { - //TODO: SANATIZE - $requestDate = $_GET['getmapidsbydate']; - echo json_encode(getMapIDsByDate($requestDate)); -} - -// Here is that SQL for you -// SELECT correctMapIds.mapType, maps.ID, maps.code -// FROM maps -// INNER JOIN -// ( - // SELECT MIN(mapOfTheDay.mapId) AS mapId, mapOfTheDay.mapType - // FROM `mapOfTheDay` - // INNER JOIN - // ( - // SELECT mapType, MIN(mapExpireTime) AS mapExpireTime - // FROM mapOfTheDay - // WHERE mapExpireTime > DATE_ADD(CURDATE(), INTERVAL -1 DAY) - // GROUP BY mapType - // ) AS expireTimes ON mapOfTheDay.mapType = expireTimes.mapType - // AND mapOfTheDay.mapExpireTime = expireTimes.mapExpireTime - // GROUP BY mapOfTheDay.mapType -// ) AS correctMapIds ON maps.ID = correctMapIds.mapId - -//TODO: SANITIZE. -function getMapIDsByDate($date) { - global $mysqli; -$sql = "SELECT MIN(mapOfTheDay.mapId) AS mapId -FROM `mapOfTheDay` -INNER JOIN -( - SELECT mapType, MIN(mapExpireTime) AS mapExpireTime - FROM mapOfTheDay - WHERE mapExpireTime > ? - GROUP BY mapType -) AS expireTimes ON mapOfTheDay.mapType = expireTimes.mapType - AND mapOfTheDay.mapExpireTime = expireTimes.mapExpireTime -GROUP BY mapOfTheDay.mapType"; - -$stmt = $mysqli->prepare($sql); -$stmt->bind_param("s", $date); -$stmt->execute(); - - $stmt->bind_result($mapID); - /* fetch values */ - while ($stmt->fetch()) { - $ids[] = $mapID; - } - - return $ids; - -var_dump($ids); - - -while ($myrow[] = $result->fetch_assoc()) {} - - $result = mysql_query($sql) or die(mysql_error()); - if (mysql_num_rows($result) == 0) return -1; - global $mapNamesByType; - $r = array(); - while($data[] = mysql_fetch_array($result)) { - $mapID = $data['mapID']; - $mapType = $data['mapType']; - $map = new map($code); - if ($map->name == '') - $map->name = $mapNamesByType[$mapType]; - $r[$mapID] = $map; +$tmp = explode('.', $_GET['r']); +$args = explode('_', $tmp[0]); +$mapID = $args[0] * 1; +$page = $args[1] * 1; + +if (!is_int($mapID) OR !is_int($page)) return; + +//Include the notification text +$json = getScores($mapID, $page, 10); +$json['mapid'] = $mapID; +$json['page'] = $page; + +//TODO: Show notifications someplace else! +$note = false; +if ($_SESSION['accepted'] == 1) { + $userID = $_SESSION['userID']; + $note = getNotified($userID); +} else { + if ($_SESSION['preCompletedTutorial'] == true && $_SESSION['preCompletedTutorialNotified'] == false) { + $_SESSION['preCompletedTutorialNotified'] = true; + $note = "Tutorial Completed!"; + $note .= "
You've unlocked: Blue Wall Color!"; + $note .= "
"; + $note .= '
Sign in to save your progress!
'; + $note .= "
"; } - return $myrow; } +if ($note !== false) $json['notificationtext'] = $note; - -function getMapsPlayed($daysAgo) { - // $sql = " - // SELECT `mapID`, `code`, `mapType` - // FROM `mapOfTheDay` - // INNER JOIN `maps` ON `mapID` = maps.ID - // WHERE DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) = - // mapDate AND - // `mapType` IN (1, 2, 3, 4, 5) - // "; - - $sql = "SELECT correctMapIds.mapType, maps.ID as mapID, maps.code -FROM maps -INNER JOIN -( - SELECT MIN(mapOfTheDay.mapId) AS mapId, mapOfTheDay.mapType - FROM `mapOfTheDay` - INNER JOIN - ( - SELECT mapType, MIN(mapExpireTime) AS mapExpireTime - FROM mapOfTheDay - WHERE mapExpireTime > DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) - GROUP BY mapType - ) AS expireTimes ON mapOfTheDay.mapType = expireTimes.mapType - AND mapOfTheDay.mapExpireTime = expireTimes.mapExpireTime - GROUP BY mapOfTheDay.mapType -) AS correctMapIds ON maps.ID = correctMapIds.mapId"; - - $result = mysql_query($sql) or die(mysql_error()); - if (mysql_num_rows($result) == 0) - return -1; - global $mapNamesByType; - $r = array(); - while($data = mysql_fetch_array($result)) { - $code = $data['code']; - $mapID = $data['mapID']; - $mapType = $data['mapType']; - $map = new map($code); - if ($map->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; -} - - +echo json_encode($json); ?> \ No newline at end of file diff --git a/do.php b/do.php index 758ee7d..b999e52 100644 --- a/do.php +++ b/do.php @@ -72,6 +72,8 @@ if ($_GET['r'] == 'reqMemberPage') { die($encoded); } + +//TODO: DEPRECIATE! if ($_GET['r'] == 'reqScorePage') { $mapID = $_GET['mapid'] + 0; $page = $_GET['reqPage'] + 0; diff --git a/js/scores.js b/js/scores.js index 161f1ae..b062c28 100644 --- a/js/scores.js +++ b/js/scores.js @@ -20,7 +20,8 @@ function scoresRequestPage(mapid, page) { //console.log("Requesting Page", mapid, page, ajax.inUse); // == Additionally, check for achievements. - ajax.requestFile = "do.php?r=reqScorePage&mapid="+mapid+"&reqPage="+page; + //ajax.requestFile = "do.php?r=reqScorePage&mapid="+mapid+"&reqPage="+page; + ajax.requestFile = "a/score/"+mapid+"_"+page+".js"; ajax.onCompletion = scoresRequestPageDone; // Specify function to be executed on response. //ajax.onLoading = ''; //ajax.onLoaded = ''; @@ -146,7 +147,10 @@ function scoresFormatPage(JO) { var rowclass = 'scoreRow'+((i % 2)+1); - if (u.isUser) { + // if (u.isUser) { + // rowclass = 'scoreRowSelf'; + // } + if (u.ID == userObj.ID) { rowclass = 'scoreRowSelf'; } -- cgit v1.2.3