<?php
/**
 * jeGroupBuy package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2010 - 2011 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.controller' );
class jeGroupBuyControllertemplates extends JController
{
    function __construct()
    {
		//Get View
        if(JRequest::getCmd('view') == '')
        {
            JRequest::setVar('view', 'templates');
		}
        parent::__construct();
		$this->registerTask( 'apply',       'save' );
    }

    function display()
	{
		JRequest::setVar( 'view', 'templates');
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);
		parent::display();
	}
	function cancel()
	{
		$link = 'index.php?option=com_jegroupbuy';
		$this->setRedirect( $link );
	}

	function save()
	{
		global $mainframe;
		$db = JFactory::getDBO();
		$model = $this->getModel('templates');
        $post	= JRequest::get( 'post',JREQUEST_ALLOWRAW );

        if ($id=$model->store($post))
        {
        	$msg = JText::_( 'JEGROUPBUY_TEMPLATE_SAVED_SUCC' );
        }
        else
        {
        	$msg = JText::_( 'JEGROUPBUY_TEMPLATE_SAVED_UNSUCC' );
        }
        if($this->_task == 'apply')
        {
        	$link 	= 'index.php?option=com_jegroupbuy&controller=templates&task=edit&cid[]='. $id;
        }
        else
        {
        	$link = 'index.php?option=com_jegroupbuy';
        }
        $this->setRedirect( $link ,$msg);
	}


}

class JHTMLInput
{
	function checkbox($name,$value,$checked='checked')
	{
		$html = "<input type=\"checkbox\" name=\"" . $name . "\" value=\"" . $value . "\"  id=\"" . $name . "\"  onClick=\"DoTheCheck('$name')\" $checked	/>";
		return $html;
	}
}

?>