<?php
/*
 * @package Joomla 3.0
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component XMovie Component
 * @copyright Copyright (C) Dana Harris optikool.com
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */ 
defined('_JEXEC') or die('Restricted access');

if (!class_exists('JControllerLegacy')) {
    class_alias('JController', 'JControllerLegacy');
}

/**
 * XMovie Movie Controller
 *
 * @package        Joomla.Administrator
 * @subpackage    com_xmovie
 * @since        1.6
 */
class XMovieController extends JControllerLegacy
{
    /**
     * @var        string    The default view.
     * @since    1.6
     */
    protected $default_view = 'main';
    
    /**
     * Method to display a view.
     *
     * @param    boolean            $cachable    If true, the view output will be cached
     * @param    array            $urlparams    An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
     *
     * @return    JController        This object to support chaining.
     * @since    1.5
     */
    
    public function display($cachable = false, $urlparams = false) 
    {
        require_once(JPATH_COMPONENT_SITE.DS.'helpers'.DS.'movie.php');

        $view        = JRequest::getCmd('view', 'main');
        $layout     = JRequest::getCmd('layout', 'default');
        $id            = JRequest::getInt('id');

        // Check for edit form.
        if ($view == 'movie' && $layout == 'edit' && !$this->checkEditId('com_xmovie.edit.movie', $id)) {
            // Somehow the person just went to the form - we don't allow that.
            $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
            $this->setMessage($this->getError(), 'error');
            $this->setRedirect(JRoute::_('index.php?option=com_xmovie&view=main', false));

            return false;
        }

        parent::display();

        return $this;
    }
}
