if ($row['dt_passed'] == null) { $status = 'open'; } else { $status = 'completed'; } $response['data'] = array('questid' => $row['idquest'], 'dt_passed' => $row['dt_passed']); $response['quest'] = $row['idquest']; $real_answer = $row['answer']; $levenshtein = levenshtein(strtoupper($real_answer), strtoupper($answer)); if ($status == 'open') { // check answer if (md5(strtoupper($real_answer)) == md5(strtoupper($answer))) { $response['result'] = 'ok'; $stmt_users_quests = $conn->prepare("INSERT INTO users_quests(userid, questid, dt_passed) VALUES(?,?,NOW())"); $stmt_users_quests->execute(array(APISecurity::userid(), $questid)); $new_user_score = APIHelpers::calculateScore($conn); $response['new_user_score'] = intval($new_user_score); if (APISecurity::score() != $response['new_user_score']) { APISecurity::setUserScore($response['new_user_score']); $query2 = 'UPDATE users_games SET date_change = NOW(), score = ? WHERE userid = ? AND gameid = ?;'; $stmt2 = $conn->prepare($query2); $stmt2->execute(array(intval($new_user_score), APISecurity::userid(), APIGame::id())); } APIQuest::updateCountUserSolved($conn, $questid); APIAnswerList::addTryAnswer($conn, $questid, $answer, $real_answer, $levenshtein, 'Yes'); APIAnswerList::movedToBackup($conn, $questid); // add to public events if (!APISecurity::isAdmin()) { APIEvents::addPublicEvents($conn, "users", 'User #' . APISecurity::userid() . ' {' . APISecurity::nick() . '} passed quest #' . $questid . ' {' . $questname . '} from game #' . APIGame::id() . ' {' . APIGame::title() . '} (new user score: ' . $new_user_score . ')'); } } else {