<?php

/**

* WDC Like Dislike

* @author WDC <contact@web-designs-company.com>

* @link http://www.web-designs-company.com/

* @copyright (C) 2011 - 2012 JExtension

* @license GNU/GPL, see LICENSE.php for full license.

**/



// Check to ensure this file is included in Joomla!

defined('_JEXEC') or die('Restricted access');



jimport('joomla.application.component.controller');



class wdclikedislikeControllerwdclikedislike extends JController

{

	function __construct( $config = array() )

	{

		parent::__construct( $config );

		$this->registerTask( 'add',	'edit' );

		$this->registerTask( 'new',	'edit' );

		$this->registerTask( 'apply', 'save' );

		$this->registerTask( 'unpublish',	'publish' );

	}



	function display()

	{

		JRequest::setVar( 'view', 'wdclikedislike');

		parent::display();

	}



	function edit()

	{

		JRequest::setVar( 'view', 'wdclikedislike');

		JRequest::setVar( 'layout', 'form'  );

		JRequest::setVar('hidemainmenu', 1);

		parent::display();

	}

	function cancel()

	{

		$msg = JText::_( 'JEXT_MSG_CANCELED' );

		$this->setRedirect( 'index.php?option=com_wdclikedislike&c=wdclikedislike', $msg );

	}

	// save the subscriber

	function save()

	{

		$model = $this->getModel('wdclikedislike');



		if ($cid = $model->store())

		{

			$msg = JText::_( 'JEXT_ITEM_SAVE_SUCCESS' );

		}

		else {

			$msg = JText::_( 'JEXT_ITEM_SAVE_FAILED' );

		}

		if($this->_task == 'apply')

		{

			$link 	= 'index.php?option=com_wdclikedislike&c=wdclikedislike&task=edit&cid[]='. $cid;

		}

		else

		{

			$link = 'index.php?option=com_wdclikedislike&c=wdclikedislike';

		}

		$this->setRedirect($link, $msg);

	}

	// delete a subscriber

	function remove()

	{

		$model = $this->getModel('wdclikedislike');



		$this->setRedirect( 'index.php?option=com_wdclikedislike&c=wdclikedislike');



		if($model->remove()) {

			$msg = JText::_( 'JEXT_ITEM_DELETE_SUCCESS' );

		}

		else {

			return JError::raiseWarning( 500, JText::_( 'JEXT_ITEM_DELETE_FAILURE' ));

		}



		$this->setRedirect( 'index.php?option=com_wdclikedislike&c=wdclikedislike', $msg );

	}

	function publish()

	{

		$model = $this->getModel('wdclikedislike');



		$result = $model->publish();



		$this->setRedirect( 'index.php?option=com_wdclikedislike&c=wdclikedislike');



		if($result ==  1) {

			$msg = JText::_( 'JEXT_ITEM_PUBLSIH_SUCCESS' );

		}

		else if ($result == -1) {

			return JError::raiseWarning( 500, JText::_( 'JEXT_ITEM_PUBLSIH_FAILURE' ));

		}

		else if($result ==  2) {

			$msg = JText::_( 'JEXT_ITEM_UNPUBLSIH_SUCCESS' );

		}

		else if ($result == -2) {

			return JError::raiseWarning( 500, JText::_( 'JEXT_ITEM_UNPUBLSIH_FAILURE' ));

		}

		else if ($result == 0) {

			return JError::raiseNotice( 500, JText::_( 'JEXT_NO_ITEM_SELECTED' ));

		}

		$this->setRedirect( 'index.php?option=com_wdclikedislike&c=wdclikedislike', $msg);

	}

}

?>