private function onVote(GWF_VoteMulti $poll, $user) { $opts = Common::getPostArray('opt', array()); $taken = array(); $max = $poll->getNumChoices(); foreach ($opts as $i => $stub) { $i = (int) $i; if ($i < 1 || $i > $max) { continue; } if (!in_array($i, $taken, true)) { $taken[] = $i; } } $count = count($taken); // if ($count === 0) { // return $this->module->error('err_no_options'); // } if (!$poll->isMultipleChoice() && $count !== 1) { return $this->module->error('err_no_multi'); } if (false === $poll->onVote($user, $taken)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_voted', array(htmlspecialchars(GWF_Session::getLastURL()))); }
private function templatePoll($pollid) { if (false === ($poll = GWF_VoteMulti::getByID($pollid))) { return $this->module->error('err_poll') . $this->templatePolls(); } return $poll->showResults(300); }
public function validate_pollid(Module_Forum $m, $arg) { if (false === ($p = GWF_VoteMulti::getByID($arg))) { return $m->lang('err_poll'); } if ($p->getUserID() !== $this->user->getID()) { return $m->lang('err_poll'); } return false; }
private function statsVoteMulti($vmid) { if (false === ($poll = GWF_VoteMulti::getByID($vmid))) { return $this->module->error('err_poll'); } }
public function validate_view(Module_Votes $m, $arg) { return GWF_VoteMulti::isValidViewFlag($arg) ? false : $m->lang('err_multiview'); }
public function getPoll() { return GWF_VoteMulti::getByID($this->getPollID()); }
private function onAddPoll() { $form = $this->getForm(); if (false !== ($errors = $form->validate($this->module))) { return $errors . $this->templateAddPoll(); } $opts = Common::getPostArray('opt', array()); if (count($opts) === 0) { return $this->module->error('err_no_options') . $this->templateAddPoll(); } $user = GWF_Session::getUser(); $name = GWF_VoteMulti::createPollName(GWF_Session::getUser()); $title = $form->getVar('title'); $gid = $form->getVar('gid'); $level = $form->getVar('level'); $reverse = isset($_POST['reverse']); $is_multi = isset($_POST['multi']); $guest_votes = isset($_POST['guests']); $is_public = isset($_POST['public']); $result = (int) $form->getVar('view'); if ($is_public && !$this->module->mayAddGlobalPoll($user)) { return $this->module->error('err_global_poll') . $this->templateAddPoll(); } GWF_Session::remove(self::SESS_OPTIONS); return Module_Votes::installPollTable($user, $name, $title, $opts, $gid, $level, $is_multi, $guest_votes, $is_public, $result, $reverse); }
public static function installPollTableB($user, $name, $title, array $options, $gid = 0, $level = 0, $is_multi, $guest_votes, $is_public = false, $result = GWF_VoteMulti::SHOW_RESULT_ALWAYS, $reverse = true) { if (false === ($module = GWF_Module::getModule('Votes'))) { return GWF_HTML::err('ERR_MODULE_MISSING', array('Votes')); } // Poll exists if (false !== ($poll = GWF_VoteMulti::getByName($name))) { return $module->error('err_pollname_taken'); } // View flag ok if (!GWF_VoteMulti::isValidViewFlag($result)) { return $module->error('err_multiview'); } $taken = array(); $errors = array(); foreach ($options as $i => $option) { if ('' === ($option = trim($option))) { $errors[] = $module->lang('err_option_empty', array($i + 1)); } elseif (in_array($option, $taken, true)) { $errors[] = $module->lang('err_option_twice', array(GWF_HTML::display($option))); } else { $taken[] = $option; } } if (count($taken) === 0) { $errors[] = $module->lang('err_no_options'); } if (count($errors) > 0) { return GWF_HTML::error('Votes', $errors); } $flags = 0; $flags |= GWF_VoteMulti::ENABLED; $flags |= $is_multi ? GWF_VoteMulti::MULTIPLE_CHOICE : 0; $flags |= $guest_votes ? GWF_VoteMulti::GUEST_VOTES : 0; $flags |= $is_public ? 0 : GWF_VoteMulti::INTERNAL_VOTE; $flags |= $reverse === false ? GWF_VoteMulti::IRREVERSIBLE : 0; $flags |= $result; if (false === ($poll = GWF_VoteMulti::fakePoll($name, $title, $user, $flags, $gid, $level))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $poll->insertPoll($taken)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return ''; }