$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 { // check already try pass $stmt_check_tryanswer = $conn->prepare('select count(*) as cnt from tryanswer where answer_try = ? and iduser = ? and idquest = ?'); $stmt_check_tryanswer->execute(array($answer, $userid, intval($questid))); if ($row_check_tryanswer = $stmt_check_tryanswer->fetch()) { $count = intval($row_check_tryanswer['cnt']); $response['checkanswer'] = array($answer, $userid, intval($questid)); if ($count > 0) { APIHelpers::showerror(1318, 'Your already try this answer. Levenshtein distance: ' . $levenshtein); } } APIAnswerList::addTryAnswer($conn, $questid, $answer, $real_answer, $levenshtein, 'No'); APIHelpers::showerror(1216, 'Answer incorrect. Levenshtein distance: ' . $levenshtein); }
APIHelpers::showerror(1116, 'you what change nick for another user, it can do only admin ' . APISecurity::userid()); } $result = array('result' => 'fail', 'data' => array()); // todo check if changed is current user // if (isset($config['profile']) && isset($config['profile']['change_nick']) && $config['profile']['change_nick'] == 'yes') { /*include dirname(__FILE__)."/../config/config.php"; if (isset($config['profile']) && isset($config['profile']['change_nick']) && $config['profile']['change_nick'] == 'no') { return; }*/ $conn = APIHelpers::createConnection($config); if (!APIHelpers::issetParam('nick')) { APIHelpers::showerror(1115, 'Not found parameter "nick"'); } $nick = APIHelpers::getParam('nick', ''); $nick = htmlspecialchars($nick); $oldnick = APISecurity::nick(); if ($nick == $oldnick) { APIHelpers::showerror(1112, 'New nick equal with old nick'); } $result['data']['nick'] = htmlspecialchars($nick); $result['data']['userid'] = $userid; $result['currentUser'] = $userid == APISecurity::userid(); if (strlen($nick) <= 3) { APIHelpers::showerror(1113, '"nick" must be more then 3 characters'); } try { $query = 'UPDATE users SET nick = ? WHERE id = ?'; $stmt = $conn->prepare($query); if ($stmt->execute(array($nick, $userid))) { $result['result'] = 'ok'; if ($userid == APISecurity::userid()) {