summaryrefslogtreecommitdiffstats
path: root/pages/achievements.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2012-03-19 19:24:31 -0700
committerPatrick Davison <snapwilliam@gmail.com>2012-03-19 19:24:31 -0700
commit638ff8a06aae2b1bc9fcbb9406a7a1a30b741ef3 (patch)
tree5ca60c22a645aef62a951060e87a13fc0d99d22f /pages/achievements.php
parent81ae4cb1eb3eb3dc859b38d00c7c9d7700216e95 (diff)
downloadpathery-638ff8a06aae2b1bc9fcbb9406a7a1a30b741ef3.tar.xz
achievements.php debug data and some fixes.
Diffstat (limited to 'pages/achievements.php')
-rw-r--r--pages/achievements.php385
1 files changed, 327 insertions, 58 deletions
diff --git a/pages/achievements.php b/pages/achievements.php
index edcb893..6506442 100644
--- a/pages/achievements.php
+++ b/pages/achievements.php
@@ -16,13 +16,149 @@ if (is_int($_GET['id'] * 1) AND isset($_GET['id']))
else
if (isset($_SESSION['userID']))
$userID = $_SESSION['userID'];
- else
- $userID = 3;
+ //else
+ // $userID = 3;
$viewer = true;
if ($userID == $_SESSION['userID'])
$viewer = false;
+if ($_GET['apply'] == 'true') {
+ applyCareerMazesAchievements($userID);
+ applyCareerPathAchievements($userID);
+}
+if ($_GET['applyall'] == 'true') {
+ for ($x = 1; $x <= 11; $x++) {
+ for ($i = 1; $i <= 11; $i++) {
+ applyCareerMazesAchievements($i);
+ applyCareerPathAchievements($i);
+ }
+ }
+}
+
+
+// TESTING AREA !! REMOVE
+
+// echo trackMOTDstats(1);
+// echo trackMOTDstats(2);
+// echo trackMOTDstats(3);
+// echo trackMOTDstats(4);
+
+
+$colors[] = '2';
+$colors[] = '6';
+$colors[] = 'a';
+$colors[] = 'd';
+$colors[] = 'f';
+
+$ac1 = $colors;
+$ac2 = $colors;
+$ac3 = $colors;
+
+echo "<table><tr>";
+foreach ($ac3 as $c3) {
+ echo "</tr><tr>";
+ foreach ($ac1 as $c1) {
+ foreach ($ac2 as $c2) {
+
+
+ $c = "#$c1$c2$c3";
+ if ($_GET['showcolor'] == 'all') {
+ //echo "<td onclick='changeWallColor(\"#$c1$c2$c3\")' title='#$c1$c2$c3' style='background-color:#$c3$c1$c2;' class='grid_td_rocks'></td>";
+ echo "<td title='$c' onClick='colorclick(this,\"$c\", \"2\")' style='background-color:$c;' class='grid_td_walls'></td>";
+ }
+ //if ($c2 == 'f') break 2;
+ }
+ }
+}
+echo "</tr></table>";
+
+$debug = false;
+
+if ($_GET['debuglevels'] == 'yes')
+ $debug = true;
+
+
+if ($_GET['showemblems'] == 'all') {
+
+ echo "<table><tr>";
+ $dir = "./images/marks/";
+ // Open a known directory, and proceed to read its contents
+ $i = 0;
+ if (is_dir($dir)) {
+ if ($dh = opendir($dir)) {
+ while (($file = readdir($dh)) !== false) {
+ $c = $file;
+ if (strpos($file, '.png') == false)
+ continue;
+ $c = "$c";
+
+ if (($i % 20) == 0)
+ echo "</tr><tr>";
+
+ $i++;
+
+ echo "<td class='grid_td_walls' title='$c ($i)' id='' onClick='emblemclick(this,\"$c\", \"1\")' style='background: #999 url(../images/marks/$c);' >
+ <div class='grid_inner grid_td_walls'></div></td>";
+ // echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
+ }
+ closedir($dh);
+ }
+ }
+ echo "</tr></table>";
+}
+
+
+$dir = "./images/marks/tmpmarks/";
+
+// Open a known directory, and proceed to read its contents
+if (is_dir($dir)) {
+ if ($dh = opendir($dir)) {
+ while (($file = readdir($dh)) !== false) {
+ //echo "<br >$file \n";
+ }
+ closedir($dh);
+ }
+}
+
+
+
+if ($_GET['showcolor'] == 'grad') {
+ makeColorGradient(.3,.3,.3,0,2,4);
+ makeColorGradient(.3,.3,.3,0,2,4, 230,25);
+ makeColorGradient(.1,.1,.1,120,120,120,128,128);
+}
+
+ function makeColorGradient($frequency1, $frequency2, $frequency3,
+ $phase1, $phase2, $phase3,
+ $center = 128, $width = 127, $len = 30)
+ {
+ echo "<table><tr>";
+ for ($i = 0; $i < $len; $i++) {
+ $red = sin($frequency1*$i + $phase1) * $width + $center;
+ $grn = sin($frequency2*$i + $phase2) * $width + $center;
+ $blu = sin($frequency3*$i + $phase3) * $width + $center;
+ //document.write( '<font color="' + RGB2Color(red,grn,blu) + '">&#9608;</font>');
+ $c = toColor(($grn * 256) + ($red * (256 * 256)) + $blu);
+ echo "<td title='$c' onClick='colorclick(this,\"$c\", \"2\")' style='background-color:$c;' class='grid_td_walls'></td>";
+ }
+ echo "</tr></table>";
+ }
+function toColor($n)
+{
+return("#".substr("000000".dechex($n),-6));
+}
+
+// !! END TESTING AREA;
+
+//Self-healing code for unlocks.
+if (!$viewer) {
+ applyAchievements($userID, 1);
+ applyAchievements($userID, 2);
+ applyAchievements($userID, 3);
+ applyAchievements($userID, 4);
+}
+
?>
<script>
var viewer = <?
@@ -62,16 +198,23 @@ function namecolorclick(obj, color, unlockID) {
<?
-$sql = "
-SELECT
+
+
+// Get unlocks data
+//Defaults
+$unlocks[1][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default Charcoal', 'value' => '#666666');
+$unlocks[2][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default Blank', 'value' => 'blank.png');
+$unlocks[3][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default', 'value' => '#cccccc');
+$sql = "SELECT
id,
type,
+ IfNull(subtype, 0) as subtype,
name,
value,
dateUnlocked
FROM `unlocks`
WHERE userID = '$userID'
-";
+ORDER BY `value` DESC";
$result = mysql_query($sql);
if ($result) {
while ($row = mysql_fetch_assoc($result))
@@ -127,15 +270,31 @@ if (isset($_POST['doupdate']) AND !$viewer) {
}
+$achievements = array();
+//Depreciated !!
$sql = "
SELECT
type,
MAX(level) as level,
- dateCompleted
+ MAX(dateCompleted)
FROM `achievements`
WHERE userID = '$userID'
GROUP BY `type`";
+
+//Thank you ranhothchord@gmail.com
+$sql = "select maxLevel.type, maxLevel.level, achievements.dateCompleted
+from achievements
+join (
+ select userID, type, max(level) as level
+ from achievements
+ where userID = '$userID'
+ group by type) as maxLevel
+where maxLevel.type = achievements.type
+and maxLevel.userID = achievements.userID
+and maxLevel.level = achievements.level
+order by maxLevel.type";
+
$result = mysql_query($sql);
if ($result) {
while ($row = mysql_fetch_assoc($result))
@@ -176,26 +335,84 @@ $UTotalSolutions = number_format($UTotalSolutions);
$uStats[1] = $UTotalMoves;
$uStats[2] = $UTotalSolutions;
-echo "<div class='wrapper'>";
+echo "<div class='wrapper' style='width:600px;'>";
if ($viewer)
echo "<center><h3>Viewing</h3></center>";
echo "
<h1 id='badgeheader' style='margin-left:10px;color:$nameColor;'>
<div id='badge' style='margin-right:10px; background:$wallColor url(../images/marks/$wallEmblem);float:left;background-size:100%;' class='badge'>
<div style='width:100%; height:100%; background-color:transparent; background-size:100%;' class='grid_td_rocks grid_inner'></div>
-</div>
-$UDisplay</h1>";
+</div>$UDisplay</h1>";
+
+function displayUnlockItem($uType, $item) {
+ switch ($uType) {
+ case 1:
+ $r .= "<td id='color_$item[id]' title='$item[name]' onClick='colorclick(this,\"$item[value]\", \"$item[id]\")' style='background-color:$item[value];' class='grid_td_walls'></td>";
+ break;
+ case 2:
+ $r .= "<td class='grid_td_walls' title='$item[name]' id='' onClick='emblemclick(this,\"$item[value]\", \"$item[id]\")' style='background: #999 url(../images/marks/$item[value]);' >
+ <div class='grid_inner grid_td_walls'></div></td>";
+ break;
+ case 3:
+ $r .= "<td class='name_color_select'><span onClick='namecolorclick(this,\"$item[value]\", \"$item[id]\")' style='color:$item[value]; margin-right:15px;'>";
+ $r .= "&nbsp;$item[name]&nbsp;";
+ $r .= "</span></td>";
+ break;
+ }
+ return $r;
+}
+if (isset($unlocks)) {
+ echo "<h2>Unlocks</h2>";
+ //Set defaults.
+ //$defaultColor = array('id' => 0, 'subtype' => 0, 'name' => 'Default Charcoal', 'value' => '#666666');
+ //$defaultEmblem = array('id' => 0, 'subtype' => 0, 'name' => 'Default Blank', 'value' => 'blank.png');
+ //$defaultNameColor = array('id' => 0, 'subtype' => 0, 'name' => 'Default Gray', 'value' => '#cccccc');
+ //array_unshift($unlocks[1], $defaultColor);
+ //array_unshift($unlocks[2], $defaultEmblem);
+ //array_unshift($unlocks[3], $defaultNameColor);
+
+ $uTypeNames[1] = "Wall Colors";
+ $uTypeNames[2] = "Emblems";
+ $uTypeNames[3] = "Username Colors";
+
+ $uSubtypeNames[1][0] = "Darker";
+ $uSubtypeNames[1][1] = "Brighter";
+
+ $uSubtypeNames[2][0] = "Simple";
+ $uSubtypeNames[2][1] = "Complicated";
+
+ foreach ($unlocks as $uType => $unlock) {
+ $subtype = array();
+ echo "<h3>$uTypeNames[$uType] unlocked:</h3>";
+
+ foreach ($unlock as $item) {
+ $subtype[$item['subtype']] .= displayUnlockItem($uType, $item);
+ }
+ $uSubtypeNames[$uType][0];
+
+ foreach($subtype as $key => $content) {
+ $tmpName = $uSubtypeNames[$uType][$key];
+ if (count($subtype) > 1)
+ echo "<strong>$tmpName</strong>";
+ echo "<table><tr>$content</tr></table>";
+ }
+ }
+}
+
+
+echo "<br><br>";
//Type 1; wall unlocks:
-if (isset($unlocks[1])) {
- echo "<h2>Unlocks</h2>";
+if (isset($unlocks[1]) AND 1 == 2) {
+
echo "<h3>Wall colors unlocked:</h3>
<table><tr>";
//Default color:
echo "<td id='color_0' title='Default Charcoal' onClick='colorclick(this,\"#666666\", \"0\")' style='background-color:#666666;' class='grid_td_walls'></td>";
foreach ($unlocks[1] as $item) {
- echo "<td id='color_$item[id]' title='$item[name]' onClick='colorclick(this,\"$item[value]\", \"$item[id]\")' style='background-color:$item[value];' class='grid_td_walls'></td>";
+ echo displayUnlockItem(1, $item);
+ //echo "<td id='color_$item[id]' title='$item[name]' onClick='colorclick(this,\"$item[value]\", \"$item[id]\")' style='background-color:$item[value];' class='grid_td_walls'></td>";
}
echo "</tr></table>";
echo "<div id='color_data' style='visibility:hidden;display:none'>";
@@ -203,21 +420,29 @@ if (isset($unlocks[1])) {
echo "</div>";
}
//Type 2; emblem unlocks:
-if (isset($unlocks[2])) {
- echo "<h3>Emblems unlocked:</h3>
- <table><tr>";
+if (isset($unlocks[2]) AND 1 == 2) {
+
//Default Emblem
- echo "<td class='grid_td_walls' title='Default Blank' onClick='emblemclick(this,\"blank.png\", \"0\")' style='background: #999 url(../images/marks/blank.png);' >
+ $subtype[0] = "<td class='grid_td_walls' title='Default Blank' onClick='emblemclick(this,\"blank.png\", \"0\")' style='background: #999 url(../images/marks/blank.png);' >
<div class='grid_inner grid_td_walls'></div></td>";
foreach ($unlocks[2] as $item) {
- echo "<td class='grid_td_walls' title='$item[name]' id='' onClick='emblemclick(this,\"$item[value]\", \"$item[id]\")' style='background: #999 url(../images/marks/$item[value]);' >
+ $subtype[$item['subtype']] .= "<td class='grid_td_walls' title='$item[name]' id='' onClick='emblemclick(this,\"$item[value]\", \"$item[id]\")' style='background: #999 url(../images/marks/$item[value]);' >
<div class='grid_inner grid_td_walls'></div></td>";
}
- echo "</tr></table>";
+ echo "<h3>Emblems unlocked:</h3>";
+ if ($subtype[0] !== '') {
+ echo "<strong>Simple</strong>";
+ echo "<table><tr>$subtype[0]
+ </tr></table>";
+ }
+ if ($subtype[1] !== '') {
+ echo "<strong>Complicated</strong>";
+ echo "<table><tr>$subtype[1]
+ </tr></table>";
+ }
}
-
//Type 3; display-name color unlocks.
-if (isset($unlocks[3])) {
+if (isset($unlocks[3]) AND 1 == 2) {
echo "<h3>Username colors unlocked:</h3>";
echo "<div class='name_color_select'>";
@@ -262,60 +487,67 @@ foreach($achievements as $aType => $a) {
$aLevel = $a['level'];
$aCompleted = $a['dateCompleted'];
+ $aCompleted = relative_date(strtotime($aCompleted));
+
+ if (!isset($uStats[$aType]))
+ $uStats[$aType] = getAchievementCurrency($userID, $aType);
+
$uCurrent = $uStats[$aType];
+ $nUCurrent = number_format($uCurrent);
$aTypeNames[1] = "Path Career Level $aLevel!";
$aTypeNames[2] = "Mazes Career Level $aLevel!";
+ $aTypeNames[3] = "Maze Mastery Level $aLevel!";
+ $aTypeNames[4] = "Champion Level $aLevel!";
$aTypeNames[32] = 'Tutorial Complete!';
+ $aTypeCurrency[1] = "total moves mazed";
+ $aTypeCurrency[2] = "mazes played";
+ $aTypeCurrency[3] = "mazes with (tied) top score";
+ $aTypeCurrency[4] = "maze wins";
+
$name = $aTypeNames[$aType];
+ $currency = $aTypeCurrency[$aType];
echo "<h3>$name</h3>";
if ($aType >= 32) {
- echo "Completed on $aCompleted";
- break;
+ echo "Completed $aCompleted";
+ continue;
}
-
+ $lastlevel = true;
foreach ($CPD as $item) {
list($required, $unlockType, $unlockValue, $unlockName) = $item;
- $nRequired = number_format($required);
- }
- echo "Last level achieved on $aCompleted";
- echo "<br />Currently you have $uCurrent ";
- echo "<br />Next level at $nRequired will unlock:<table><tr>";
- echo displayUnlock($unlockType, $unlockValue, $unlockName);
-}
-
-
-//Type 1; Career Path:
-if (isset($achievements[1]) AND 1 == 2) {
- $CPD = getCareerPathArray();
-
- $level = $achievements[1]['level'];
- echo "<h3>Path Career level $level!</h3>
- $UTotalMoves total moves.
- ";
+
- $i = 0;
- //echo "<br />Unlocked:<table><tr>";
- foreach ($CPD as $item) {
- list($required, $unlockType, $unlockValue, $unlockName) = $item;
+ if ($debug)
+ echo "At $required: <table>".displayUnlock($unlockType, $unlockValue, $unlockName)."</table>";
$nRequired = number_format($required);
- if ($item['req'] > $UTotalMoves) {
- break;
+ if ($required > $uCurrent) {
+ $lastlevel = false;
+ if (!$debug)
+ break;
}
- //echo "<td title='Level $i: Req $nRequired'><div style='background-color:$color;' class='grid_td_walls'></div></td>";
- $i++;
}
- //echo "</tr></table>";
- echo "<br />Next level at $nRequired will unlock:<table><tr>";
- echo displayUnlock($unlockType, $unlockValue, $unlockName);
+ if ($lastlevel) {
+ echo "Completed all levels $aCompleted";
+ echo "<br />$nUCurrent $currency";
+ continue;
+ }
- //echo "<td title='Level $i: Req $nRequired'><div style='background-color:$color;' class='grid_td_rocks'></div></td>";
- //echo "</tr></table>";
-} else {
- //echo "Never played.";
+ $percent = round($uCurrent / $required * 100, 1);
+ //$percentLeft = 100 - $percent;
+
+ echo "Last level earned $aCompleted";
+ echo "<br />Currently you have $nUCurrent $currency";
+ echo "
+ <div title='$percent% to $nRequired' style='align:left;width:210px;height:16px;background-color:#222;border:1px solid #26b;'>
+ <div style='border-right:1px solid #37e;width:$percent%;height:16px;background-color:#26b;'>
+ </div>
+ </div>
+ ";
+ echo "Next level at $nRequired will unlock: ";
+ echo displayUnlock($unlockType, $unlockValue, $unlockName);
}
if (false) {
@@ -340,11 +572,11 @@ function displayUnlock($uType, $uValue, $uName) {
break;
case 2:
$r .= "$uName Emblem!";
- $r .= "<div class='grid_td_rocks' title='' onClick='emblemclick(this,\"$uValue\", \"0\")' style='background: #999 url(../images/marks/$uValue);' >";
- $r .= "<div class='grid_inner grid_td_walls'></div></div>";
+ $r .= "<div class='grid_td_rocks' title='' style='background: #999 url(../images/marks/$uValue);' >";
+ $r .= "<div class='grid_inner grid_td_gray'></div></div>";
break;
case 3:
- $r .= "<br /><span style='color:$uValue;font-weight:bold;font-size:120%;background-color:#222;'>$uName Username color!</span>";
+ $r .= "<br /><span style='color:$uValue;font-weight:bold;font-size:110%;background-color:#222;'>$uName Username color!</span>";
break;
}
return $r;
@@ -354,6 +586,8 @@ function displayUnlock($uType, $uValue, $uName) {
+
+
?>
</div>
@@ -363,4 +597,39 @@ echo "<br /><br />";
echo "<br /><br />";
echo "<br /><br />";
htmlFooter();
+
+
+// ----- Functions
+
+//Thank you:
+//http://snippets.dzone.com/posts/show/196
+function relative_date($time) {
+ $today = strtotime(date('M j, Y'));
+ $reldays = ($time - $today)/86400;
+ if ($reldays >= 0 && $reldays < 1) {
+ return 'Today';
+ } else if ($reldays >= 1 && $reldays < 2) {
+ return 'Tomorrow';
+ } else if ($reldays >= -1 && $reldays < 0) {
+ return 'Yesterday';
+ }
+ if (abs($reldays) < 7) {
+ if ($reldays > 0) {
+ $reldays = floor($reldays);
+ return 'in ' . $reldays . ' day' . ($reldays != 1 ? 's' : '');
+ } else {
+ $reldays = abs(floor($reldays));
+ return $reldays . ' day' . ($reldays != 1 ? 's' : '') . ' ago';
+ }
+ }
+ if (abs($reldays) < 182) {
+ return date('l, F j',$time ? $time : time());
+ } else {
+ return date('l, F j, Y',$time ? $time : time());
+ }
+}
+
+
+
+
?> \ No newline at end of file