[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @version        $Id: controller.php 15096 2010-02-27 14:16:40Z ian $
   4   * @package        Joomla
   5   * @subpackage    Config
   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 to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport( 'joomla.application.component.controller' );
  19  
  20  /**
  21   * @package        Joomla
  22   * @subpackage    Config
  23   */
  24  class PollController extends JController
  25  {
  26      /**
  27       * Custom Constructor
  28       */
  29  	function __construct( $default = array())
  30      {
  31          parent::__construct( $default );
  32  
  33          $this->registerTask( 'apply',         'save');
  34          $this->registerTask( 'unpublish',     'publish');
  35          $this->registerTask( 'preview',     'display');
  36          $this->registerTask( 'edit',         'display');
  37          $this->registerTask( 'add' ,         'display' );
  38  
  39      }
  40  
  41  	function display( )
  42      {
  43          switch($this->getTask())
  44          {
  45              case 'add'     :
  46              {
  47                  JRequest::setVar( 'hidemainmenu', 1 );
  48                  JRequest::setVar( 'layout', 'form'  );
  49                  JRequest::setVar( 'view', 'poll'  );
  50                  JRequest::setVar( 'edit', false  );
  51              } break;
  52              case 'edit'    :
  53              {
  54                  JRequest::setVar( 'hidemainmenu', 1 );
  55                  JRequest::setVar( 'layout', 'form'  );
  56                  JRequest::setVar( 'view', 'poll'  );
  57                  JRequest::setVar( 'edit', true  );
  58              } break;
  59  
  60              case 'preview' :
  61              {
  62                  JRequest::setVar( 'tmpl', 'component' );
  63                  JRequest::setVar( 'view', 'poll'  );
  64              } break;
  65          }
  66  
  67          //Set the default view, just in case
  68          $view = JRequest::getCmd('view');
  69          if(empty($view)) {
  70              JRequest::setVar('view', 'polls');
  71          };
  72  
  73          parent::display();
  74      }
  75  
  76  	function save()
  77      {
  78          // Check for request forgeries
  79          JRequest::checkToken() or jexit( 'Invalid Token' );
  80  
  81          $db        =& JFactory::getDBO();
  82  
  83          // save the poll parent information
  84          $row    =& JTable::getInstance('poll', 'Table');
  85          $post    = JRequest::get( 'post' );
  86          if (!$row->bind( $post ))
  87          {
  88              JError::raiseError(500, $row->getError() );
  89          }
  90          $isNew = ($row->id == 0);
  91  
  92          if (!$row->check())
  93          {
  94              JError::raiseError(500, $row->getError() );
  95          }
  96  
  97          if (!$row->store())
  98          {
  99              JError::raiseError(500, $row->getError() );
 100          }
 101          $row->checkin();
 102          // save the poll options
 103          $options = JArrayHelper::getValue( $post, 'polloption', array(), 'array' );
 104  
 105          foreach ($options as $i=>$text)
 106          {
 107              $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
 108              if ($isNew)
 109              {
 110                  $obj = new stdClass();
 111                  $obj->pollid = (int)$row->id;
 112                  $obj->text   = $text;
 113                  $db->insertObject('#__poll_data', $obj);
 114              }
 115              else
 116              {
 117                  $obj = new stdClass();
 118                  $obj->id     = (int)$i;
 119                  $obj->text   = $text;
 120                  $db->updateObject('#__poll_data', $obj, 'id');
 121              }
 122          }
 123  
 124          switch ($this->_task)
 125          {
 126              case 'apply':
 127                  $msg = JText::_( 'Changes to Poll saved' );
 128                  $link = 'index.php?option=com_poll&view=poll&task=edit&cid[]='. $row->id .'';
 129                  break;
 130  
 131              case 'save':
 132              default:
 133                  $msg = JText::_( 'Poll saved' );
 134                  $link = 'index.php?option=com_poll';
 135                  break;
 136          }
 137  
 138          $this->setRedirect($link, $msg);
 139      }
 140  
 141  	function remove()
 142      {
 143          // Check for request forgeries
 144          JRequest::checkToken() or jexit( 'Invalid Token' );
 145  
 146          $db        =& JFactory::getDBO();
 147          $cid    = JRequest::getVar( 'cid', array(), '', 'array' );
 148  
 149          JArrayHelper::toInteger($cid);
 150          $msg = '';
 151  
 152          for ($i=0, $n=count($cid); $i < $n; $i++)
 153          {
 154              $poll =& JTable::getInstance('poll', 'Table');
 155              if (!$poll->delete( $cid[$i] ))
 156              {
 157                  $msg .= $poll->getError();
 158              }
 159          }
 160          $this->setRedirect( 'index.php?option=com_poll', $msg );
 161      }
 162  
 163      /**
 164      * Publishes or Unpublishes one or more records
 165      * @param array An array of unique category id numbers
 166      * @param integer 0 if unpublishing, 1 if publishing
 167      * @param string The current url option
 168      */
 169  	function publish()
 170      {
 171          global $mainframe;
 172  
 173          // Check for request forgeries
 174          JRequest::checkToken() or jexit( 'Invalid Token' );
 175  
 176          $db     =& JFactory::getDBO();
 177          $user     =& JFactory::getUser();
 178  
 179          $cid        = JRequest::getVar( 'cid', array(), '', 'array' );
 180          $publish    = ( $this->getTask() == 'publish' ? 1 : 0 );
 181  
 182          JArrayHelper::toInteger($cid);
 183  
 184          if (count( $cid ) < 1)
 185          {
 186              $action = $publish ? 'publish' : 'unpublish';
 187              JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
 188          }
 189  
 190          $cids = implode( ',', $cid );
 191  
 192          $query = 'UPDATE #__polls'
 193          . ' SET published = ' . (int) $publish
 194          . ' WHERE id IN ( '. $cids .' )'
 195          . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
 196          ;
 197          $db->setQuery( $query );
 198          if (!$db->query())
 199          {
 200              JError::raiseError(500, $db->getErrorMsg() );
 201          }
 202  
 203          if (count( $cid ) == 1)
 204          {
 205              $row =& JTable::getInstance('poll', 'Table');
 206              $row->checkin( $cid[0] );
 207          }
 208          $mainframe->redirect( 'index.php?option=com_poll' );
 209      }
 210  
 211  	function cancel()
 212      {
 213          // Check for request forgeries
 214          JRequest::checkToken() or jexit( 'Invalid Token' );
 215  
 216          $id        = JRequest::getVar( 'id', 0, '', 'int' );
 217          $db        =& JFactory::getDBO();
 218          $row    =& JTable::getInstance('poll', 'Table');
 219  
 220          $row->checkin( $id );
 221          $this->setRedirect( 'index.php?option=com_poll' );
 222      }
 223  }


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