$lat1 = $row["lat"]; $long1 = $row["longg"]; $color = $row["color"]; $ans = $row["answer"]; $game_id = $row["game_id"]; $questionNum = $row["questionNum"]; $loc = new LatLong($lat1, $long1); $points = $row["points"]; //echo $questionNum; $qID = findQID($game_id, $questionNum); if ($ans == -999) { //meaning they didnt submit $distanceAway = null; } else { if ($qID->type == "geo") { $distanceAway = LatLong::findDistance($qID->location, $loc); } else { $distanceAway = abs($ans - $qID->answer); } } if ($ans > 100000) { $distanceAway = round($distanceAway, -5); } //echo $qID->type." ".$qID->answer. " ". $distanceAway."<br>"; if ($distanceAway != "") { $sql2 = "UPDATE `answers` SET question_id='" . $qID->type . $qID->id . "', distanceAway='" . $distanceAway . "' WHERE game_id='" . $game_id . "' AND questionNum='" . $questionNum . "' AND color='" . $color . "'"; } else { $sql2 = "UPDATE `answers` SET question_id='" . $qID->type . $qID->id . "' WHERE game_id='" . $game_id . "' AND questionNum='" . $questionNum . "' AND color='" . $color . "'"; } echo $sql2; $result2 = $conn->query($sql2);
if ($long == "") { $long = 0; } $color = User::getColor(); //die ($color); if ($_SESSION["user_id"] == 0) { die("Sorry this shouldnt happen - tell me about it..."); } $correct = Answer::loadCorrect($questionNumber); //place currently is true or false if they could submit (meaning 1st time) //die ($questionNumber); //echo $sql; //die(); $game = Game::findGame(); if ($game->type == "geo" || $game->type == "places" || $game->type == "pt") { $distanceAway = LatLong::findDistance($correct->location, new LatLong($lat, $long)); } else { $distanceAway = abs($answer - $correct->value); } if ($answer > 100000) { $distanceAway = round($distanceAway, -5); } //die ($questionNumber); $questionNumberSite = $game->round; //if ($questionNumberSite!=$questionNumber) if ($questionNumberSite < 0) { header('Location: waitingScreen.php?message=' . "Submit your answer in time"); } $place = Answer::addAnswer($_SESSION["user_id"], $questionNumber, $lat, $long, $answer, $distanceAway, $color, $game->type); //NOW WE FIND THE OVERALL PERCENT PLACE THAT PERCENT DID ON THAT question_id //Answer::findPercentPlace()
public static function addUser($qID, $loc, $ans, $userID, $correct, $points, $color) { $answer = new self(); $answer->user_id = $userID; $answer->location = $loc; $answer->ans = $ans; $answer->qID = $qID; $answer->color = $color; if ($ans == -999) { //meaning they didnt submit $answer->distanceAway = -999.99; } else { if (!is_object($correct)) { //meaning end of game $answer->distanceAway = -999.99; } else { if (Game::findGame()->type == "geo" || Game::findGame()->type == "pt" || Game::findGame()->type == "places") { $answer->distanceAway = LatLong::findDistance($correct->location, $loc); } else { $answer->distanceAway = abs($ans - $correct->value); } } } if ($ans > 100000) { $answer->distanceAway = round($answer->distanceAway, -5); } $answer->getUserInfo(); $answer->updateUser(); $answer->roundPoints = $points; return $answer; }