Ejemplo n.º 1
0
 private function getFormVote(WC_Challenge $chall, $has_solved, $userid)
 {
     $fun = $edu = $dif = 0;
     if ($has_solved) {
         if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_dif'), $userid))) {
             $dif = $vsr->getScore();
         }
         if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_edu'), $userid))) {
             $edu = $vsr->getScore();
         }
         if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_fun'), $userid))) {
             $fun = $vsr->getScore();
         }
     }
     $data = array('dif' => array(GWF_Form::INT, $dif, $this->module->lang('th_dif'), '', 2), 'edu' => array(GWF_Form::INT, $edu, $this->module->lang('th_edu'), '', 2), 'fun' => array(GWF_Form::INT, $fun, $this->module->lang('th_fun'), '', 2), 'vote' => array(GWF_Form::SUBMIT, $this->module->lang('btn_vote')));
     return new GWF_Form($this, $data);
 }
Ejemplo n.º 2
0
 private function onGuestVote()
 {
     if (!$this->votescore->isGuestVote()) {
         return $this->module->error('err_no_guest');
     }
     $ip = GWF_IP6::getIP(GWF_IP_QUICK);
     if (false === ($vsr = GWF_VoteScoreRow::getByIP($this->votescore->getID(), $ip))) {
         if (false === $this->votescore->onGuestVote($this->score, $ip)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         return $this->onVoted(false);
     } else {
         if ($vsr->isUserVote()) {
             return $this->module->message('err_vote_ip');
         }
         if (!$vsr->isGuestVoteExpired($this->module->cfgGuestTimeout())) {
             $this->votescore->revertVote($vsr, $ip, 0);
         }
         if (false === $this->votescore->onGuestVote($this->score, $ip)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         return $this->onVoted(false);
     }
 }
Ejemplo n.º 3
0
 /**
  * Vote and revert votes safely. Return false or error msg.
  * @param int $score
  * @param int $userid
  * @return error msg or false
  */
 public function onUserVoteSafe($score, $userid)
 {
     $userid = (int) $userid;
     $vsid = $this->getID();
     # Revert Guest Vote with same IP
     $ip = GWF_IP6::getIP(GWF_IP_QUICK);
     //		var_dump($ip);
     if (false !== ($vsr = GWF_VoteScoreRow::getByIP($vsid, $ip))) {
         //			echo '<div>HAVE GUEST VOTE</div>';
         //			var_dump($vsr);
         if (!$vsr->isGuestVoteExpired(GWF_Module::getModule('Votes')->cfgGuestTimeout())) {
             if (false === $this->revertVote($vsr, $ip, 0)) {
                 return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             }
         }
     }
     # Revert Users Vote
     if (false !== ($vsr = GWF_VoteScoreRow::getByUID($vsid, $userid))) {
         //			echo '<div>HAVE OLD VOTE</div>';
         if (false === $this->revertVote($vsr, 0, $userid)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # And Vote it
     if (false === $this->onUserVote($score, $userid, 0)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return false;
     # No error
 }