Esempio n. 1
0
 /**
  * Add a vote to an option
  */
 function vote()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Captcha Controller Patch rev. 4.5.0 Stable
     $dispatcher =& JDispatcher::getInstance();
     $results = $dispatcher->trigger('onCaptchaRequired', array('user.poll'));
     if ($results[0]) {
         $captchaparams = array(JRequest::getVar('captchacode', '', 'post'), JRequest::getVar('captchasuffix', '', 'post'), JRequest::getVar('captchasessionid', '', 'post'));
         $results = $dispatcher->trigger('onCaptchaVerify', $captchaparams);
         if (!$results[0]) {
             JError::raiseWarning('CAPTHCA', JText::_('CAPTCHACODE_DO_NOT_MATCH'));
             $this->display();
             return false;
         }
     }
     $db =& JFactory::getDBO();
     $poll_id = JRequest::getVar('id', 0, '', 'int');
     $option_id = JRequest::getVar('voteid', 0, 'post', 'int');
     $poll =& JTable::getInstance('poll', 'Table');
     if (!$poll->load($poll_id) || $poll->published != 1) {
         JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('You already voted for this poll today!');
         }
         if (!$option_id) {
             $msg = JText::_('WARNSELECT');
         }
     } else {
         setcookie($cookieName, '1', time() + $poll->lag);
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new PollModelPoll();
         $model->vote($poll_id, $option_id);
         $msg = JText::_('Thanks for your vote!');
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg);
 }
Esempio n. 2
0
 /**
  * Add a vote to an option
  */
 function vote()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $db =& JFactory::getDBO();
     $poll_id = JRequest::getVar('id', 0, '', 'int');
     $option_id = JRequest::getVar('voteid', 0, 'post', 'int');
     $poll =& JTable::getInstance('poll', 'Table');
     if (!$poll->load($poll_id) || $poll->published != 1) {
         JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('You already voted for this poll today!');
         }
         if (!$option_id) {
             $msg = JText::_('WARNSELECT');
         }
     } else {
         setcookie($cookieName, '1', time() + $poll->lag);
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new PollModelPoll();
         $model->vote($poll_id, $option_id);
         $msg = JText::_('Thanks for your vote!');
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg);
 }