public static function accept($data) { $out = array(); if (!MyUser::isloggedin()) { throw new APIException("User ist nicht angemeldet.", 100); } if (!isset($data["answer"])) { throw new APIException("Benötigter Parameter fehlt (answer).", 50); } $db = new SQL(0); $info = $db->cmdrow(0, 'SELECT * FROM answers WHERE id={0} LIMIT 0,1', array($data["answer"] + 0)); if (!isset($info["id"])) { throw new APIException("Diese Antwort existiert nicht (mehr)", 300); } if ($info["right_answer"] == "1") { throw new APIException("Dies ist bereits die beste Antwort", 330); } $qinfo = $db->cmdrow(0, 'SELECT * FROM questions WHERE id={0} LIMIT 0,1', array($info["question"] + 0)); if (!isset($qinfo["id"])) { throw new APIException("Diese Frage existiert nicht (mehr)", 300); } if ($qinfo["is_closed"] == "1") { throw new APIException("Diese Frage ist bereits geschlossen", 310); } if ($qinfo["author"] != MyUser::id()) { throw new APIException("Dies ist nicht ihre Frage", 320); } if ($info["author"] == MyUser::id() and MyUser::getKarmaPoints() < 50) { throw new APIException("Deine eigene Antwort darf erst ab 50 Karma Punkten die beste Antwort sein", 210); } $db->cmd(0, 'UPDATE answers SET right_answer = "1" WHERE id={0} LIMIT 1', true, array($info["id"])); $db->cmd(0, 'UPDATE questions SET is_answered = "1" WHERE id={0} LIMIT 1', true, array($info["question"])); if (MyUser::id() != $info["author"]) { Karma::RuleAction("ACCEPT_ANSWER", array("user" => $info["author"], "question" => $info["question"], "answer" => $info["id"])); } if (MyUser::id() != $info["author"] && $info["is_bounty"] == "1") { Bounty::Release($info["question"], $info["author"]); } //Gib dem Autor die Bounty return true; }