/** * this function allows to add a choice to a give poll * @post all parameters from argpost * returns true if choice was added with success **/ function AddChoice($post) { $words = new MOD_words(); $IdPoll = $post['IdPoll']; $rPoll = $this->singleLookup("select * from polls where id=" . $IdPoll . " /* Add Choice */"); if (!(isset($_SESSION["IdMember"]) and $rPoll->IdCreator == $_SESSION["IdMember"] and $rPoll->Status == "Projet" or MOD_right::get()->HasRight("Poll", "update"))) { MOD_log::get()->write("Forbidden to add poll choice for poll #" . $IdPoll, "polls"); die("Sorry forbidden for you"); } $ss = "insert into polls_choices(IdPoll,IdChoiceText,Counter,created) values(" . $rPoll->id . ",0,0,now())"; $result = $this->dao->query($ss); if (!$result) { throw new PException('AddChoice::Failed to add back the insert the choice '); } $IdChoice = $result->insertId(); $ss = $this->dao->escape($post['ChoiceText']); $IdChoiceText = $words->InsertInFTrad($ss, "polls_choices.IdChoiceText", $IdChoice, $_SESSION["IdMember"], 0); $ss = "update polls_choices set IdChoiceText={$IdChoiceText} where id={$IdChoice}"; $result = $this->dao->query($ss); if (!$result) { throw new PException('AddChoice::Failed update the IdChoiceText '); } MOD_log::get()->write("pollchoice : <b>" . $post["ChoiceText"] . "</b> created IdPollChoice=#" . $IdChoice . " for poll #" . $IdPoll, "polls"); return true; }