$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()) { APISecurity::setNick($nick); } // add to public events if ($userid != APISecurity::userid()) { APIEvents::addPublicEvents($conn, 'users', 'Admin changed nick for user #' . $userid . ' from {' . htmlspecialchars($oldnick) . '} to {' . $nick . '} '); } else { APIEvents::addPublicEvents($conn, 'users', 'User #' . $userid . ' changed nick from {' . htmlspecialchars($oldnick) . '} to {' . $nick . '} '); } } else { $result['result'] = 'fail'; } } catch (PDOException $e) { APIHelpers::showerror(1114, $e->getMessage()); } echo json_encode($result);