diff options
author | Snap <snapwilliam@gmail.com> | 2015-05-03 23:00:34 -0700 |
---|---|---|
committer | Snap <snapwilliam@gmail.com> | 2015-05-03 23:00:34 -0700 |
commit | 35e1a863f6404d5630c3000b720f6ba99bf8548e (patch) | |
tree | 1401db6f72771799600ac047db762bbb6f64696f | |
parent | 54c56f33f32dd01dc02182e80f0e5e79f3c8e62a (diff) | |
download | pathery-35e1a863f6404d5630c3000b720f6ba99bf8548e.tar.xz |
Login fixes and matches progress
-rw-r--r-- | ajax/match.ajax.php | 63 | ||||
-rw-r--r-- | pages/login.php | 20 | ||||
-rw-r--r-- | pages/matches.php | 140 |
3 files changed, 209 insertions, 14 deletions
diff --git a/ajax/match.ajax.php b/ajax/match.ajax.php index 391c69e..3a4bfae 100644 --- a/ajax/match.ajax.php +++ b/ajax/match.ajax.php @@ -8,11 +8,19 @@ session_start(); //header_remove();
-
require_once('../includes/sqlEmbedded.php');
+//Prep response
$r = '';
+//Gamelist request?
+if (isset($_REQUEST['getGameList'])) {
+ $r['matches'] = getMatchList();
+ echo json_encode($r);
+ exit;
+}
+
+
if (is_int($_GET['matchID'])) {
$matchID = $_GET['matchID'];
}
@@ -129,6 +137,59 @@ function getPlayersForMatch($matchID) { return $array;
}
+function getMatchList() {
+ global $mysqli;
+
+ if (!is_object($mysqli)) die("mysqli is not an object");
+
+ if ($res = $mysqli->query("
+ SELECT
+ matches.ID,
+ matches.creatorUserID,
+ matches.mapID,
+ matches.isComplete,
+ matches.isStarted,
+
+ TIME_TO_SEC(TIMEDIFF(NOW(), matches.dateCreated)) as secondsSinceCreated,
+
+ matches.dateExpires,
+ matches.dateStarted,
+ matches.requiredPlayers,
+
+ COUNT(matchUsers.matchID) as currentPlayers,
+
+ matches.secondsGiven,
+ matches.useSmartTime,
+
+ users.displayName,
+ users.displayColor,
+ users.wallColor,
+ users.wallEmblem,
+ users.wallOrientation
+ FROM `matches`
+ JOIN `matchUsers`
+ ON matchUsers.matchID = matches.ID
+ JOIN `users`
+ ON matches.creatorUserID = users.ID
+ GROUP BY matches.ID
+ ")) {
+ $array = array();
+ if ($res->num_rows == 0) {
+ $res->close();
+ return false;
+ }
+ while ($response = $res->fetch_assoc()) {
+ $array[] = $response;
+ }
+ $res->close();
+ if (count($array) < 1) return false;
+ return $array;
+ } else {
+ printf("DB Error: %s\n", $mysqli->error);
+ return false;
+ }
+}
+
function getMatchStatus($matchID) {
global $mysqli;
diff --git a/pages/login.php b/pages/login.php index d698527..b0caf07 100644 --- a/pages/login.php +++ b/pages/login.php @@ -19,13 +19,14 @@ include_once('./includes/HybridAuth/Auth.php'); $hybrid_config_file = 'includes/HybridAuth/HybridAuthConfig.php';
+//TODO: SQL needs to be updated to sqli instead.
+
try {
+
//OpenID 2.0 Method
-
if (!$_GET['op'] || $_GET['op'] == 'steam' || $_GET['op'] == 'yahoo') {
$openid = new LightOpenID;
-
//Require Email, and first name.
$openid->required = array('namePerson/first', 'contact/email');
@@ -68,26 +69,19 @@ try { DoRedirect("Login failed. Back to the home page with you!");
}
- //Google's OpenID Connect method
+ //Google's OpenID Connect method
} else if ($_GET['op'] == 'google') {
-
- echo "ello...";
-
include_once('./includes/google-api-php-client-master/src/Google/autoload.php');
$redirect_uri = $mydomain . "login?op=google";
- //echo "$redirect_uri $google_client_id $google_client_secret ";
-
$client = new Google_Client();
$client->setClientId($google_client_id);
$client->setClientSecret($google_client_secret);
$client->setRedirectUri($redirect_uri);
$client->setScopes('email');
- //echo 'Tests running';
-
if (isset($_GET['code'])) {
//echo 'code recpt';
$client->authenticate($_GET['code']);
@@ -174,7 +168,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) $sql = "SELECT `ID`, `isAdmin`, `openID`, `displayName`, `dateJoined` FROM `users`
WHERE `openID` = '$claimedid' OR `email` = '$email'";
if (isset($oldID)) {
- $sql = $sql." OR `openID` = '$oldID'";
+ $sql = $sql." OR `openID` = '" . $oldID . "'";
}
$result = mysql_query($sql);
@@ -237,7 +231,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) if ($result) {
$userID = mysql_insert_id();
$dateJoined = date(DateTime::ISO8601);
-
+
//Tutorial done?
if (isset($_SESSION['preCompletedTutorial'])) {
if ($_SESSION['preCompletedTutorial'] == true) {
@@ -280,7 +274,7 @@ function createNewUser($claimedid, $display, $email, $oldID = NULL) $refTo = $_GET['ref'];
//DoRedirect("Thank you $display.", $_GET['ref']);
DoRedirect("", $refTo, 0);
- exit;
+ return true;
}
function sendNewUserEmail($userID, $email, $display, $dateJoined) {
diff --git a/pages/matches.php b/pages/matches.php new file mode 100644 index 0000000..7fd8559 --- /dev/null +++ b/pages/matches.php @@ -0,0 +1,140 @@ +<?PHP
+htmlHeader(
+ array('stats'), 'Matches',
+ 'View available games',
+ array('scores', 'dateformat')
+);
+?>
+
+<?php
+topbar($headerLinks);
+?>
+
+<script>
+ // javascript:membersShowPage(1);
+
+//
+
+
+updateGameList();
+
+function updateGameList() {
+ var dataString = 'getGameList=1';
+
+ $.ajax({
+ //type: "POST",
+ url: "ajax/match.ajax.php?" + dataString,
+ error: function() {
+ console.log('Error: Failed updateGameList');
+ },
+ success: function(data) {
+ console.log("Data recieved", data);
+ updateGameListDone(data);
+ }
+ });
+}
+
+function updateGameListDone(data) {
+
+ console.log('data recieved:', data);
+ if (data.length < 3 || data == 'false') return;
+ json = jQuery.parseJSON(data);
+
+ $('#games').html(gamesFormat(json));
+
+}
+
+
+
+function gamesFormat(JO) {
+
+ var p = "<table class='score'>";
+/*
+ var localTime = new Date();
+ var updatedLocalTime = new Date();
+ updatedLocalTime.setTime(JO.updateTime * 1000);
+
+ p = p+"<tr title='Last-Update: "+updatedLocalTime.format("mmm d, h:MM TT")+"'>";
+ p = p+"<th>Rank</th>";
+ p = p+"<th style='width:125px; overflow:hidden; text-align:left; padding-left:42px;'>Name</th>";
+ p = p+"<th>Moves</th>";
+ p = p+"</tr>";
+ */
+
+ p = p+"<tr>";
+ p = p+"<th style='width:125px; overflow:hidden; text-align:left; padding-left:42px;'>Created By</th>";
+ p = p+"<th>Made</th>";
+ p = p+"<th>link to join</th>";
+ p = p+"<th>Players</th>";
+
+ p = p+"</tr>";
+
+
+ var showedLastUser = true;
+ var x = 0;
+
+ var previousI = 0;
+ for (var i in JO.matches) {
+ var u = JO.matches[i];
+
+ var createdLocalTime = new Date();
+ createdLocalTime.setTime(createdLocalTime.getTime() - u.secondsSinceCreated * 1000);
+ createdLocalTime = createdLocalTime.format("h:MM:ss TT");
+
+ var styleClass = '';
+
+ if (previousI != i + 1 && previousI < i - 1 && previousI != 0) {
+ styleClass = 'border-top: 6px solid #777799;';
+ }
+ //var wasLongAgo = localTime.getTime() > (scoredLocalTime.getTime() + 43200000); //12*60*60*1000
+ //var scoredTimeFormat = (wasLongAgo ? "mmm d, h:MM:ss TT" : "h:MM:ss TT");
+ //var scoredTimeStr = scoredLocalTime.format(scoredTimeFormat);
+
+ var rowclass = 'scoreRow'+((i % 2)+1);
+ //Wall Avatar
+ p = p+ "<td style='vertical-align: middle;'>";
+ p = p+ " <div class='grid_td' style='float:left; width:35px; height:35px; background:"+u.wallColor+" url("+linkEmblem(u.wallEmblem, u.wallOrientation)+");'>";
+ p = p+ " <div style='background-color:transparent;' class='grid_td_inner grid_td_rocks'>";
+ p = p+ " </div>";
+ p = p+ " </div>";
+ p = p+ "";
+ p = p+ "<span class='scoreName'><a href='achievements?id="+u.creatorUserID+"' style='color:"+u.displayColor+"'>"+u.displayName+"</a></span>";
+ p = p+ "</td>";
+
+ p = p+ "<td class='scoreMedal' style='color:"+u.displayColor+"'>";
+ p = p+ createdLocalTime+ "</td>";
+
+ p = p+ "<td><a href='#NotYetSry!" + u.ID + "'>Join Game</a></td>";
+ p = p+ "<td>" + u.currentPlayers + "/" + u.requiredPlayers + "</td>";
+
+
+ p = p+ "</tr>";
+
+ previousI = i;
+ }
+
+ p = p+"</table>";
+
+ p = "<div class='scoreContainer1'>"+p+"</div>";
+ return p;
+}
+
+
+
+
+</script>
+
+<div class='wrapper'>
+ <h2>Available Matches</h2>
+
+ <div id='games'>
+
+ </div>
+</div>
+<br />
+<br />
+<?
+
+htmlfooter();
+
+?>
|