<?php
	
	/**
	* @copyright		(C)2013 DM Digital S.r.l
	* @author 			DM Digital <support@dmjoomlaextensions.com>
	* @link				http://www.dmjoomlaextensions.com
	* @license 			GNU/LGPL http://www.gnu.org/copyleft/gpl.html
	**/
	
	defined('_JEXEC') or die('Restricted access');
	jimport('joomla.application.component.controller');
	jimport('joomla.application.component.view');

    if (version_compare(JVERSION, '3.0', 'ge')) {
        define('DMVERSION',30);
    } else if (version_compare(JVERSION, '2.5', 'ge')) {
        define('DMVERSION',25);
    } else {
        define('DMVERSION',16);
    }


    /**
     * Temporaneous compatibility Classes
     **/

	if (!class_exists('DMController') && !class_exists('DMView')) {
		
		if (DMVERSION == 30) {
		    
		    class DMTempController extends JControllerLegacy {
		        
		        public function display($cachable = false, $urlparams = array()) {
		        	parent::display($cachable, $urlparams);
		        }
		    }
		    
		} else {
		    
		    class DMTempController extends JController {
		    	
		    	public function display($cachable = false, $urlparams = false) {
		        	parent::display($cachable, $urlparams);
		        }
		    }
		    
		}
		
		if (DMVERSION == 30) {
		    
		    class DMTempView extends JViewLegacy { }
		    
		} else {
		    
		    class DMTempView extends JView { }
		    
		}
		
	}

    /**
     * DM Classes
     **/

    if (!class_exists('DMController') && !class_exists('DMView')) {

        class DMController extends DMTempController { }

        class DMView extends DMTempView { }

    }

	if (!class_exists('DMHtml')) {

        class DMHtml {

            public static function tabContStart($name, $config) {

                if (DMVERSION == 30) {
                    if (!isset($config['active'])) {
                        $config['active'] = 'tab1';
                    }
                    return JHtml::_('bootstrap.startTabSet', $name, $config);
                } else {
                    return JHtml::_('tabs.start', $name, $config);
                }
            }

            public static function tabAdd($tab, $name, $text) {

                if (DMVERSION == 30) {
                    return JHtml::_('bootstrap.addTab', $tab, $name, $text);
                } else {
                    return JHtml::_('tabs.panel', $text, $name);
                }
            }

            public static function tabEnd() {

                if (DMVERSION == 30) {
                    return JHtml::_('bootstrap.endTab');
                } else {
                    return '';
                }
            }

            public static function tabContStop() {

                if (DMVERSION == 30) {
                    return JHtml::_('bootstrap.endTabSet');
                } else {
                    return JHtml::_('tabs.end');
                }
            }

            public static function buttonState($cid, $published, $controller) {

                if ($published == 1) {
                    $task = 'unpublish';
                    $icon = 'publish';
                } else {
                    $task = 'publish';
                    $icon = 'unpublish';
                }
                $url = JRoute::_('index.php?option='.JRequest::getCmd('option').'&controller='.$controller.'&task='.$task.'&cid='.$cid);
                if (DMVERSION == 30) {
                    return '<a class="btn btn-micro" href="'.$url.'"><i class="icon-'.$icon.'"></i></a>';
                } else {
                    return '<a class="jgrid" href="'.$url.'"><span class="state '.$icon.'"></span></a>';
                }
            }

        }

	}
	
?>