コード例 #1
0
ファイル: controller.php プロジェクト: vuchannguyen/dayhoc
 function vote()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $mainframe = JFactory::getApplication();
     $poll_id = JRequest::getInt('id', 0);
     $option_id = JRequest::getInt('voteid', 0);
     $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);
     $voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
             $tom = "error";
         }
         if (!$option_id) {
             $msg = JText::_('COM_ACEPOLLS_NO_SELECTED');
             $tom = "error";
         }
     } else {
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'poll.php';
         $model = new AcepollsModelPoll();
         if ($model->vote($poll_id, $option_id)) {
             //Set cookie showing that user has voted
             setcookie($cookieName, '1', time() + 60 * $poll->lag);
         }
         $msg = JText::_('COM_ACEPOLLS_THANK_YOU');
         $tom = "";
         if (JFactory::getUser()->id != 0) {
             JPluginHelper::importPlugin('acepolls');
             $dispatcher =& JDispatcher::getInstance();
             $dispatcher->trigger('onAfterVote', array($poll, $option_id));
         }
     }
     // set Itemid id for links
     $menu =& JSite::getMenu();
     $items = $menu->getItems('link', 'index.php?option=com_acepolls');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     $this->setRedirect(JRoute::_('index.php?option=com_acepolls&view=poll&id=' . $poll_id . ':' . $poll->alias . $itemid, false), $msg, $tom);
 }
コード例 #2
0
ファイル: ajaxvote.php プロジェクト: affiliatelk/ecc
 function getVoted()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $mainframe = JFactory::getApplication();
     $poll_id = JRequest::getInt('id', 0);
     $option_id = JRequest::getInt('voteid', 0);
     $poll =& JTable::getInstance('Poll', 'Table');
     if (!$poll->load($poll_id) || $poll->published != 1) {
         $mainframe->redirect('index.php', JText::_('deneme'));
         //JError::raiseWarning(404, JText::_('ALERTNOTAUTH'));
         return;
     }
     require_once JPATH_COMPONENT . '/models/poll.php';
     $model = new AcepollsModelPoll();
     $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id);
     $voted_cookie = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
     $voted_ip = $model->ipVoted($poll, $poll_id);
     if ($voted_cookie || $voted_ip || !$option_id) {
         if ($voted_cookie || $voted_ip) {
             $msg = JText::_('COM_ACEPOLLS_ALREADY_VOTED');
             $tom = "error";
         }
         if (!$option_id) {
             $msg = JText::_('COM_ACEPOLLS_NO_SELECTED');
             $tom = "error";
         }
         $this->_voted = 0;
     } else {
         if ($model->vote($poll_id, $option_id)) {
             $this->_voted = 1;
             //Set cookie showing that user has voted
             setcookie($cookieName, '1', time() + 60 * $poll->lag);
         } else {
             $this->_voted = 0;
         }
     }
     return $this->_voted = 1;
 }