<?php
/*
Copyright (C) 2010 Luis Eduardo da Silva Dias. All rights reserved.
Version Beta 1.0
jcontrollerlesd.php is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jcontrollerlesd.php is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class JControllerLesd extends JController
{
var $_controller_name = null;
function __construct()
{
parent::__construct();
$this->registerTask( 'add' , 'edit' );
$this->_controller_name = $this->getControllerName();
}
function edit()
{
$model = $this->getModel($this->_controller_name);
JRequest::setVar( 'view', $this->_controller_name );
JRequest::setVar( 'layout', 'form' );
JRequest::setVar('hidemainmenu', 1);
$document =& JFactory::getDocument();
$view = &$this->getView($this->_controller_name, $document->getType());
$view->ref =& $lists;
$view->setLayout('form');
$view->setModel($model);
$view->display();
}
function display()
{
$model = $this->getModel($this->_controller_name);
$document =& JFactory::getDocument();
$view = &$this->getView($this->_controller_name, $document->getType());
$view->setLayout('default');
$view->setModel($model);
$view->display(null);
}
function save()
{
$user =& JFactory::getUser();
$model = $this->getModel($this->_controller_name);
if ($model->store()) {
$msg = JText::_( ucfirst($this->_controller_name) . ' Saved!' );
} else {
$msg = JText::_( 'Error Saving '.ucfirst($this->_controller_name) );
}
if (!$model->unlock($user->get('id'))) {
$msg = JText::_( 'Error unlocking item' );
}
$link = 'index.php?option=com_'.$this->getName().'&controller=' . $this->_controller_name;
$this->setRedirect($link, $msg);
}
function remove()
{
$model = $this->getModel($this->_controller_name);
if(!$model->delete()) {
$msg = JText::_( 'Error: One or More Items Could not be Deleted' );
} else {
$msg = JText::_( 'Item(s) Deleted' );
}
$this->setRedirect( 'index.php?option='.$this->getName(), $msg );
}
function cancel()
{
$user =& JFactory::getUser();
$model = $this->getModel($this->_controller_name);
$model->unlock($user->get('id'));
$msg = JText::_( 'Operation Cancelled' );
$this->setRedirect( 'index.php?option=com_'.$this->getName().'&controller='.$this->_controller_name, $msg );
}
function getControllerName()
{
$r = null;
if (!preg_match('/Controller(.*)/i', get_class($this), $r)) {
JError::raiseError (500, "JControllerLesd::getControllerName() : Can't get or parse class name.");
}
$name = strtolower( $r[1] );
return $name;
}
}