public function PageNewArgument($row)
 {
     global $sDB, $sRequest, $sTemplate, $sUser, $sNotify;
     parent::Page($row);
     $questionTitle = $sRequest->getString("title");
     $this->question = false;
     $this->view = VIEW_NEW_ARGUMENT;
     $this->faction = $sRequest->getInt("faction");
     validateFaction($this->faction);
     $res = $sDB->exec("SELECT * FROM `questions` WHERE `url` = '" . mysql_real_escape_string($questionTitle) . "' LIMIT 1;");
     while ($row = mysql_fetch_object($res)) {
         $this->question = new Question($row->questionId, $row);
     }
     if (!$this->question) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_QUESTION"));
     }
     if ($sRequest->getInt("new_argument")) {
         $argumentId = $this->handleNewArgument();
         if ($argumentId) {
             $argument = new Argument($argumentId);
             $sNotify->notifyNewArgument($this->question, $argument);
             $sUser->follow($this->question->questionId());
             header("Location: " . $this->redirectUrl);
             exit;
         }
     }
 }
 public function PageNewCounterArgument($row)
 {
     global $sDB, $sRequest, $sUser;
     parent::Page($row);
     $questionTitle = $sRequest->getString("title");
     $this->question = false;
     $argumentTitle = $sRequest->getString("argument");
     $this->view = VIEW_NEW_COUNTER_ARGUMENT;
     $this->argument = false;
     $this->faction = $sRequest->getInt("faction");
     validateFaction($this->faction);
     $res = $sDB->exec("SELECT * FROM `questions` WHERE `url` = '" . mysql_real_escape_string($questionTitle) . "' LIMIT 1;");
     while ($row = mysql_fetch_object($res)) {
         $this->question = new Question($row->questionId, $row);
     }
     if (!$this->question) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_QUESTION"));
     }
     foreach ($this->question->arguments() as $k => $v) {
         if ($v->urlPlain() == $argumentTitle) {
             $this->argument = $v;
             break;
         }
     }
     if (!$this->argument) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_ARGUMENT"));
     }
     if ($sRequest->getInt("new_counter_argument")) {
         if ($this->handleNewCounterArgument()) {
             header("Location: " . $this->redirectUrl);
             exit;
         }
     }
 }
 public function PageQuestion($row)
 {
     global $sDB, $sRequest, $sStatistics, $sUser, $sTemplate;
     parent::Page($row);
     $questionTitle = $sRequest->getString("title");
     $this->question = false;
     $this->view = $sRequest->getInt("view");
     $res = $sDB->exec("SELECT * FROM `questions` WHERE `url` = '" . mysql_real_escape_string($questionTitle) . "' LIMIT 1;");
     while ($row = mysql_fetch_object($res)) {
         $this->question = new Question($row->questionId, $row);
     }
     if (!$this->question) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_QUESTION"));
     }
     if ($sRequest->getInt("vote_select")) {
         if ($this->question->group() && $this->question->group()->getPermission($sUser, ACTION_VOTE) == PERMISSION_DISALLOWED) {
         } else {
             $vote = $sRequest->getInt("vote");
             $questionId = $sRequest->getInt("questionId");
             $argumentId = $sRequest->getInt("argumentId");
             $sStatistics->vote($this->question, $argumentId, $vote);
             //header("Location: ".$this->question->url()."#argument_wrapper_".$questionId."_".$argumentId);
             header("Location: " . $this->question->url());
             exit;
         }
     }
     if ($this->view == VIEW_DETAILS) {
         $this->setShortUrl($this->question->shortUrlDetails());
     } else {
         $this->setShortUrl($this->question->shortUrl());
     }
     if ($sRequest->getInt("faction_select") && ($sUser->isLoggedIn() || $this->question->hasFlag(QUESTION_FLAG_PART_ALL))) {
         if ($this->question->group() && $this->question->group()->getPermission($sUser, ACTION_VOTE) == PERMISSION_DISALLOWED) {
         } else {
             $faction = $sRequest->getInt("faction");
             validateFaction($faction);
             $sUser->setFactionByQuestionId($this->question->questionId(), $faction);
             $sStatistics->updateQuestionStats($this->question->questionId());
             header("Location: " . $this->question->url());
             exit;
         }
     }
 }
 public function PageCounterArgument($row)
 {
     global $sDB, $sRequest, $sStatistics, $sTemplate, $sUser;
     parent::Page($row);
     $questionTitle = $sRequest->getString("title");
     $this->question = false;
     $this->view = VIEW_ARGUMENT;
     $this->faction = $sRequest->getInt("faction");
     validateFaction($this->faction);
     $argumentTitle = $sRequest->getString("argument");
     $res = $sDB->exec("SELECT * FROM `questions` WHERE `url` = '" . mysql_real_escape_string($questionTitle) . "' LIMIT 1;");
     while ($row = mysql_fetch_object($res)) {
         $this->question = new Question($row->questionId, $row);
     }
     if (!$this->question) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_ARGUMENT"));
     }
     foreach ($this->question->arguments() as $k => $v) {
         if ($v->urlPlain() == $argumentTitle) {
             $this->argument = $v;
             break;
         }
     }
     if (!$this->argument) {
         $sTemplate->error($sTemplate->getString("ERROR_INVALID_ARGUMENT"));
     }
     if ($sRequest->getInt("vote_select")) {
         if ($this->question->group() && $this->question->group()->getPermission($sUser, ACTION_VOTE) == PERMISSION_DISALLOWED) {
         } else {
             $vote = $sRequest->getInt("vote");
             $questionId = $sRequest->getInt("questionId");
             $argumentId = $sRequest->getInt("argumentId");
             $sStatistics->vote($this->question, $argumentId, $vote);
             //header("Location: ".$this->argument->urlCounterArguments($this->question->url())."#argument_wrapper_".$questionId."_".$argumentId);
             header("Location: " . $this->argument->urlCounterArguments($this->question->url()));
             exit;
         }
     }
     $this->setShortUrl($this->argument->shortUrlCA());
 }
 public function setFactionByQuestionId($questionId, $faction)
 {
     global $sDB, $sStatistics;
     validateFaction($faction);
     if ($this->getFactionByQuestionId($questionId) == $faction) {
         return;
     }
     $question = new Question($questionId);
     if ($this->isLoggedIn()) {
         $sDB->exec("DELETE FROM `user_factions` WHERE `userId` = '" . $this->getUserId() . "' AND `questionId` = '" . i($questionId) . "';");
         $res = $sDB->exec("SELECT * FROM `user_votes` WHERE `userId` = '" . i($this->getUserId()) . "' AND `questionId` = '" . i($questionId) . "' AND `argumentId` != 0;");
         while ($row = mysql_fetch_object($res)) {
             $sStatistics->vote($question, $row->argumentId, VOTE_NONE, $this, true);
         }
     } else {
         $oldFaction = FACTION_NONE;
         $factionData = $_COOKIE['factionData'];
         if ($factionData) {
             $factionData = unserialize($factionData);
             if (is_array($factionData) && $factionData[$questionId]) {
                 validateFaction($factionData[$questionId]);
                 $oldFaction = $factionData[$questionId];
             }
         }
         // remove old faction
         if ($oldFaction != FACTION_NONE) {
             $sDB->exec("DELETE FROM `user_factions` WHERE `userId` = '" . $this->getUserId() . "' AND `questionId` = '" . i($questionId) . "' AND `state` = '" . $oldFaction . "';");
             unset($factionData[$questionId]);
         }
         // check if a vote state exists in the user's cookie
         $cookieData = $_COOKIE['voteData'];
         if ($cookieData) {
             $cookieData = unserialize($cookieData);
             if (is_array($cookieData) && is_array($cookieData[$questionId])) {
                 foreach ($cookieData[$questionId] as $k => $v) {
                     validateVote($v);
                     $sStatistics->vote($question, $k, VOTE_NONE, $this, true);
                 }
                 unset($cookieData[$questionId]);
             }
             setcookie("voteData", serialize($cookieData));
         }
         if ($faction != FACTION_NONE) {
             $factionData[$questionId] = $faction;
         }
         setcookie("factionData", serialize($factionData));
     }
     if ($faction == FACTION_NONE) {
         return;
     }
     $sDB->exec("INSERT INTO `user_factions` (`factionId`, `userId`, `questionId`, `state`) VALUES\n                                                (NULL, '" . i($this->getUserId()) . "', '" . i($questionId) . "', '" . i($faction) . "');");
 }
 public function handlePacket()
 {
     global $sUser, $sDB, $sTemplate, $sLog;
     $requestObj = $this->_requestObj;
     $response = $this->_response;
     $qId = $requestObj->getInt(array("data", "qId"));
     $faction = $requestObj->getInt(array("data", "faction"));
     $response->data->result = 0;
     $response->opcode = SMSG_SELECT_FACTION_RESPONSE;
     if (!validateFaction($faction, false)) {
         return false;
     }
     $question = new Question($qId);
     if ($question->questionId() == 0) {
         return false;
     }
     $sUser->setFactionByQuestionId($qId, $faction);
     $sStatistics->updateQuestionStats($qId);
     $response->data->result = 1;
 }