"; foreach ($ac3 as $c3) { echo ""; foreach ($ac1 as $c1) { foreach ($ac2 as $c2) { $c = "#$c1$c2$c3"; if ($_GET['showcolor'] == 'all') { echo ""; } //if ($c2 == 'f') break 2; } } } echo ""; $debug = false; if ($_GET['debuglevels'] == 'yes') { $debug = true; } if ($_GET['showemblems'] == 'all') { echo ""; $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 ""; $i++; echo ""; // echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } } echo "
"; } $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 "
$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 ""; 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( ''); $c = toColor(($grn * 256) + ($red * (256 * 256)) + $blu); echo ""; } echo "
"; } function toColor($n) { return("#".substr("000000".dechex($n),-6)); } // TODO: END TESTING AREA; //Self-healing code for unlocks. if (!$viewer) { applyAchievements($userID, ACHIEVEMENT_MOVES_CAREER); applyAchievements($userID, ACHIEVEMENT_MAZE_CAREER); applyAchievements($userID, ACHIEVEMENT_MAZE_MASTERY); applyAchievements($userID, ACHIEVEMENT_CHAMPION_POINTS); applyAchievements($userID, ACHIEVEMENT_PERFECT_DAY); } ?> 0, 'subtype' => 0, 'name' => 'Default Charcoal', 'value' => '#666666', 'aType' => -1); $unlocks[2][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default Blank', 'value' => 'blank.png', 'aType' => -1); $unlocks[3][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default', 'value' => '#cccccc', 'aType' => -1); $unlocks[4][0] = array('id' => 0, 'subtype' => 0, 'name' => 'Default: (0*)', 'value' => '0', 'aType' => -1); $sql = "SELECT unlocks.id, unlocks.type, IfNull(subtype, 0) as subtype, name, value, dateUnlocked, achievements.type as aType, achievements.level as aLevel FROM `unlocks` LEFT JOIN `achievements` ON achievements.ID = unlocks.id WHERE unlocks.userID = '$userID' ORDER BY `dateUnlocked` ASC"; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_assoc($result)) $unlocks[$row['type']][$row['id']] = $row; } //Destroy some defaults to make them not show up. if (count($unlocks[3]) == 1) unset($unlocks[3]); if (count($unlocks[4]) == 1) unset($unlocks[4]); //print_R($_POST); //Validate selection and then update. if (isset($_POST['doupdate']) AND !$viewer) { //print_R($unlocks); $unlockIDC = $_POST['selectColorID']; $unlockColor = $unlocks[1][$unlockIDC]['value']; $unlockIDE = $_POST['selectEmblemID']; $unlockEmblem = $unlocks[2][$unlockIDE]['value']; $unlockIDNC = $_POST['selectNameColorID']; $unlockNameColor = $unlocks[3][$unlockIDNC]['value']; $orientationUnlockID = $_POST['selectOrientationID']; $orientationNewValue = $unlocks[UNLOCK_WALL_ORIENTATION][$orientationUnlockID]['value']; //Default values if ($unlockIDC == 0) $unlockColor = '#666666'; if ($unlockIDE == 0) $unlockEmblem = 'blank.png'; if ($unlockIDNC == 0) $unlockNameColor = '#cccccc'; if ($orientationUnlockID == 0) $orientationNewValue = '0'; if ($unlockColor == $_POST['selectColor']) { $sql = "UPDATE `users` SET `wallColor` = '$unlockColor' WHERE `ID` = '$userID'"; $result = mysql_query($sql); if (!$result) { echo "Error updating wall color"; $data = array(); $data['error'] = "Error when updating wall color"; $data['session'] = print_r($_SESSION, true); $data['post'] = print_r($_POST, true); EmailError($data); } } if ($unlockEmblem == $_POST['selectEmblem']) { $sql = "UPDATE `users` SET `wallEmblem` = '$unlockEmblem' WHERE `ID` = '$userID'"; $result = mysql_query($sql); if (!$result) { echo "Error updating wall color"; $data = array(); $data['error'] = "Error when updating wall color"; $data['session'] = print_r($_SESSION, true); $data['post'] = print_r($_POST, true); EmailError($data); } } if ($unlockNameColor == $_POST['selectNameColor']) { $sql = "UPDATE `users` SET `displayColor` = '$unlockNameColor' WHERE `ID` = '$userID'"; $result = mysql_query($sql); if (!$result) { echo "Error updating wall color"; $data = array(); $data['error'] = "Error when updating wall color"; $data['session'] = print_r($_SESSION, true); $data['post'] = print_r($_POST, true); EmailError($data); } } if ($orientationNewValue == $_POST['selectOrientation']) { $sql = "UPDATE `users` SET `wallOrientation` = '$orientationNewValue' WHERE `ID` = '$userID'"; $result = mysql_query($sql); if (!$result) { echo "Error updating wall Orientation"; $data = array(); $data['error'] = "Error when updating wall orientation"; $data['session'] = print_r($_SESSION, true); $data['post'] = print_r($_POST, true); EmailError($data); } } } $achievements = array(); //Fetch data //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)) { $achievements[$row['type']] = $row; } } //Get user information to display. $sql = " SELECT users.displayName, users.isAdmin, users.totalMoves, users.totalMazes AS totalSolutions, users.wallColor, users.displayColor, users.wallEmblem, users.wallOrientation FROM `users` LEFT JOIN `solutions` ON users.ID = solutions.userID WHERE users.ID = '$userID' GROUP BY solutions.userID "; $result = mysql_query($sql); //No user found? if (!$result OR mysql_num_rows($result) <= 0) { echo "

Achievements Page

No selection.
"; htmlFooter(); exit; } list($UDisplay, $UAdmin, $UTotalMoves, $UTotalSolutions, $wallColor, $nameColor, $wallEmblem, $wallOrientation) = mysql_fetch_row($result); if ($wallEmblem == '') $wallEmblem = 'blank.png'; $DUTotalMoves = number_format($UTotalMoves); $UTotalSolutions = number_format($UTotalSolutions); $uStats[1] = $UTotalMoves; $uStats[2] = $UTotalSolutions; echo "
"; if ($viewer) echo "

Viewing

"; $badgeURL = linkEmblem($wallEmblem, $wallOrientation); echo "

$UDisplay

"; function unlockItemAsTD($uType, $item) { $aLevel = $item['aLevel']; $aCompleted = $item['dateUnlocked']; $aTypeNames[ACHIEVEMENT_MOVES_CAREER] = "Path Career Level $aLevel"; $aTypeNames[ACHIEVEMENT_MAZE_CAREER] = "Mazes Career Level $aLevel"; $aTypeNames[ACHIEVEMENT_MAZE_MASTERY] = "Maze Mastery Level $aLevel"; $aTypeNames[ACHIEVEMENT_CHAMPION_POINTS] = "Champion Level $aLevel"; $aTypeNames[ACHIEVEMENT_PERFECT_DAY] = "Perfect Days $aLevel"; $aTypeNames[ACHIEVEMENT_TUTORIAL] = 'Completing Tutorial'; $by = $aTypeNames[$item['aType']]; $on = relative_date(strtotime($aCompleted)); $unlockTitle = "{$item['name']}. From $by $on"; if ($item['aType'] == -1) { $unlockTitle = $item['name']; } //$border = 'border: 1px solid #000; border-width: 2px 0px 2px 0px;'; //$border = 'border: 1px solid #000;'; $class = 'grid_td_walls'; $class = 'displayWallUnlock'; $r = ''; $border = ''; //depreciate switch ($uType) { case UNLOCK_WALL_COLOR: if ($GLOBALS['wallColor'] == $item[value]) { $class .= ' active'; } else $class .= ' inactive'; $r .= "
"; // USE THIS ? $style = "background-image: url(../images/marks/{$item['value']});"; break; case UNLOCK_DISPLAY_COLOR: if ($GLOBALS['nameColor'] == $item[value]) $border = 'border: 1px solid #26b;'; $r .= ""; $r .= " {$item['name']} "; $r .= ""; break; case UNLOCK_WALL_ORIENTATION: $checked = ''; if (intval($GLOBALS['wallOrientation']) == intval($item['value'])) $checked = 'checked'; //$r .= ""; $r .= ""; $r .= "{$item['name']} "; $r .= ""; break; case UNLOCK_EXTRAS: $r .= "{$item['name']}"; break; } return $r; } if (isset($unlocks)) { echo "

Unlocks

"; //Define some names $uTypeNames[UNLOCK_WALL_COLOR] = "Wall Colors"; $uTypeNames[UNLOCK_WALL_EMBLEM] = "Emblems"; $uTypeNames[UNLOCK_DISPLAY_COLOR] = "Username Colors"; $uTypeNames[UNLOCK_WALL_ORIENTATION] = "Emblem Rotations"; $uTypeNames[UNLOCK_EXTRAS] = "Extras"; $uSubtypeNames[UNLOCK_WALL_COLOR][0] = "Darker"; $uSubtypeNames[UNLOCK_WALL_COLOR][1] = "Brighter"; $uSubtypeNames[UNLOCK_WALL_EMBLEM][0] = "Simple"; $uSubtypeNames[UNLOCK_WALL_EMBLEM][1] = "Complicated"; $uSubtypeNames[UNLOCK_DISPLAY_COLOR][0] = ""; $uSubtypeNames[UNLOCK_WALL_ORIENTATION][0] = ""; $uSubtypeNames[UNLOCK_EXTRAS][0] = ""; //For every unlock type that the user has. foreach ($unlocks as $uType => $unlock) { $subtype = array(); echo "

$uTypeNames[$uType] unlocked:

"; foreach ($unlock as $item) { $subtype[$item['subtype']][] = unlockItemAsTD($uType, $item); if ((sizeof($subtype[$item['subtype']]) + 1) % 14 == 0) $subtype[$item['subtype']][] = ''; } echo "
"; foreach($subtype as $key => $content) { $content = implode($content); $tmpName = $uSubtypeNames[$uType][$key]; if (count($subtype) > 1) echo "
$tmpName"; echo "$content"; } echo "
"; } } echo "
"; if (!$viewer) { //TODO add wall orientation echo "
"; } echo "
"; echo "

Achievements

"; foreach($achievements as $aType => $a) { $CPD = getAchievementsArray($aType); $aLevel = $a['level']; $aCompleted = $a['dateCompleted']; $aCompleted = relative_date(strtotime($aCompleted)); if (!isset($uStats[$aType])) $uStats[$aType] = getAchievementCurrency($userID, $aType); $uStats[$aType] = str_replace(",", "", $uStats[$aType]); $uCurrent = $uStats[$aType]; $nUCurrent = number_format((double)$uCurrent); $aTypeNames[1] = "Path Career Level $aLevel!"; $aTypeNames[2] = "Mazes Career Level $aLevel!"; $aTypeNames[3] = "Maze Mastery Level $aLevel!"; $aTypeNames[ACHIEVEMENT_CHAMPION_POINTS] = "Champion Level $aLevel!"; $aTypeNames[ACHIEVEMENT_PERFECT_DAY] = "Perfect Day level $aLevel!"; $aTypeNames[32] = 'Tutorial Complete!'; $aTypeCurrency[1] = "total moves mazed"; $aTypeCurrency[2] = "mazes played"; $aTypeCurrency[3] = "mazes with (tied) top score"; $aTypeCurrency[ACHIEVEMENT_CHAMPION_POINTS] = "champion points"; $name = $aTypeNames[$aType]; $currency = $aTypeCurrency[$aType]; echo "

$name

"; if ($aType >= 32) { echo "Completed $aCompleted"; continue; } $lastlevel = true; foreach ($CPD as $item) { list($required, $unlockType, $unlockValue, $unlockName) = $item; if ($debug) echo "At $required: ".displayUnlock($unlockType, $unlockValue, $unlockName)."
"; $nRequired = number_format($required); if ($required > $uCurrent) { $lastlevel = false; if (!$debug) break; } } if ($lastlevel) { echo "Completed all levels $aCompleted"; echo "
$nUCurrent $currency"; continue; } $percent = round($uCurrent / $required * 100, 1); //$percentLeft = 100 - $percent; $pronoun = "you have"; if ($viewer) $pronoun = "$UDisplay has"; echo "Last level earned $aCompleted"; echo "
Currently $pronoun $nUCurrent $currency"; echo "
"; echo "Next level at $nRequired will unlock: "; echo displayUnlock($unlockType, $unlockValue, $unlockName); } ?>

"; echo "

"; echo "

"; 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()); } } ?>