[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_poll/ -> controller.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: controller.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @subpackage    Polls
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.controller');
  19  
  20  /**
  21   * Static class to hold controller functions for the Poll component
  22   *
  23   * @static
  24   * @package        Joomla
  25   * @subpackage    Poll
  26   * @since        1.5
  27   */
  28  class PollController extends JController
  29  {
  30      /**
  31       * Method to show the search view
  32       *
  33       * @access    public
  34       * @since    1.5
  35       */
  36  	function display()
  37      {
  38          JRequest::setVar('view','poll'); // force it to be the polls view
  39          parent::display();
  40      }
  41  
  42      /**
  43        * Add a vote to an option
  44        */
  45  	function vote()
  46      {
  47          global $mainframe;
  48  
  49          // Check for request forgeries
  50          JRequest::checkToken() or jexit( 'Invalid Token' );
  51  
  52          $db            =& JFactory::getDBO();
  53          $poll_id    = JRequest::getVar( 'id', 0, '', 'int' );
  54          $option_id    = JRequest::getVar( 'voteid', 0, 'post', 'int' );
  55  
  56          $poll =& JTable::getInstance('poll','Table');
  57          if (!$poll->load( $poll_id ) || $poll->published != 1) {
  58              JError::raiseWarning( 404, JText::_('ALERTNOTAUTH') );
  59              return;
  60          }
  61  
  62          $cookieName    = JUtility::getHash( $mainframe->getName() . 'poll' . $poll_id );
  63          // ToDo - may be adding those information to the session?
  64          $voted = JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT');
  65  
  66          if ($voted || !$option_id )
  67          {
  68              if($voted) {
  69                  $msg = JText::_('You already voted for this poll today!');
  70              }
  71  
  72              if(!$option_id){
  73                  $msg = JText::_('WARNSELECT');
  74              }
  75          }
  76          else
  77          {
  78              setcookie( $cookieName, '1', time() + $poll->lag );
  79  
  80              require_once (JPATH_COMPONENT.DS.'models'.DS.'poll.php');
  81              $model = new PollModelPoll();
  82              $model->vote( $poll_id, $option_id );
  83  
  84              $msg = JText::_( 'Thanks for your vote!' );
  85          }
  86  
  87          // set Itemid id for links
  88          $menu = &JSite::getMenu();
  89          $items    = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
  90  
  91          $itemid = isset($items[0]) ? '&Itemid='.$items[0]->id : '';
  92  
  93          $this->setRedirect( JRoute::_('index.php?option=com_poll&id='. $poll_id.':'.$poll->alias.$itemid, false), $msg );
  94      }
  95  }
  96  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1