<?php
/**
* @version 1.0.0
* @package RStickets! 1.0.0
* @copyright (C) 2007-2008 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

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

class RST_adapter
{
        
    function RST_adapter()
    {
       $this->version = 'j15x';
	   if (defined('_JEXEC') && !defined('_VALID_RSTICKETS')) define('_VALID_RSTICKETS','1');
    }
    
    function getConfig($param){
		$JCONFIG = new JConfig();
    	$return = '';
    	switch($param)
    	{
    		case 'db' :  			$return	= $JCONFIG->db;break;
    		case 'dbprefix' :  		$return	= $JCONFIG->dbprefix;break;
    		case 'user' :  			$return	= $JCONFIG->user;break;
    		case 'password' :		$return	= $JCONFIG->password;break;
    		case 'host' :			$return	= $JCONFIG->host;break;
    		case 'live_site' :		$return	= JURI :: root();break;
    		case 'live_site_no_slash' :		$return	= substr(JURI :: root(), 0, -1);break;
    		case 'absolute_path' :	$return	= JPATH_SITE;break;
    	}
           
    	return $return;
    }
    
	function getLanguage()
	{
		$lg = &JFactory::getLanguage();
		$language = $lg->getBackwardLang();
		return $language;
	}
	
	function getMenuParam($var,$default)
	{
	    if (isset($_GET[$var]))
	       return $_GET[$var];
	    
	    $config =& JComponentHelper::getParams('com_rstickets');
	    return $config->get($var);
	}
	
    function getParam($array, $name, $default_value = null)
    {
        if(isset($array[$name])) $val = $array[$name];
        else $val = $default_value;
        
        return $val;
    }
    
    function user($id = null)
    {
    	$my = & JFactory::getUser();
    	$acl =& JFactory::getACL();
		    	
    	$user = array('id'=>'','username'=>'','fullname'=>'','email'=>'', 'admin' => 0);
    	
    	if(!$id)
    	{    	
    		$is_admin = $my->authorize('com_components', 'manage');
    		
    		$user['id'] = $my->id;
    		$user['username'] = $my->username;
    		$user['name'] = $my->name;
    		$user['email'] = $my->email;
    		$user['admin'] = $is_admin;
    	}
    	else 
    	{
    		$is_admin = $my->authorize('com_components', 'manage');
    		
    		$user['id'] = $my->id;
    		$user['username'] = $my->username;
    		$user['name'] = $my->name;
    		$user['email'] = $my->email;
    		$user['admin'] = $is_admin;
    	}
    			
    	return $user;
    }
    
    function mail($from, $fromname, $recipient, $subject, $body, $mode = 0, $cc = null, $bcc = null, $attachment = null)
    {
    	JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment);
    }
    
    function addHeadTag($str, $type, $destination = 'head')
    {
    	$document =& JFactory::getDocument();
    	switch($type)
    	{
    		case 'css':
    			$document->addStyleSheet($str);	
    		break;
    		case 'js':
    			$document->addScript($str);
    		break;
    	}
    }
    
    
    
    //Menu
    function menuStartTable()
    {
    	
    }
    
    function menuSpacer()
    {
    	JToolBarHelper::spacer();
    }
        
    function menuCustom($task,$icon,$iconOver,$alt,$listSelect=true, $onclick='')
    {
    	if($onclick=='')JToolBarHelper::custom($task,$icon,$iconOver,$alt,$listSelect);
    	else JToolBarHelper::custom($task."');".$onclick.";void('",$icon,$iconOver,$alt,$listSelect);
    }
    
    function menuCancel($task = 'cancel', $alt = 'Cancel')
    {
    	JToolBarHelper::cancel($task, $alt);
    }
    
    function menuBack($alt = 'Back', $href = '')
    {
    	JToolBarHelper::back($alt, $href);
    }
    
    function menuAddNewX($task = 'new', $alt = 'New')
    {
    	JToolBarHelper::addNewX($task, $alt);
    }
    
    function menuDeleteList($msg = '',$task = 'remove',$alt = 'Delete')
    {
    	JToolBarHelper::deleteList($msg, $task, $alt);
    }
    
    function menuSave($task='save',$alt='Save')
    {
    	JToolBarHelper::save($task, $alt);
    }
    
    function menuApply($task='apply',$alt='Apply')
    {
    	JToolBarHelper::apply($task, $alt);
    }
    
    function menuPublishList($task='publish',$alt='Publish')
    {
    	JToolBarHelper::publishList($task, $alt);
    }
    
    function menuUnpublishList($task='unpublish',$alt='Unpublish')
    {
    	JToolBarHelper::unpublishList($task, $alt);
    }
    
    function menuEndTable(){
    	
    }
    
    
    //TABS
    
    function initTabs($number)
    {
    	jimport('joomla.html.pane');
    	$this->tabs = & JPane::getInstance('Tabs',array(),true);
    }
    function startPane($id)
    {
    	echo $this->tabs->startPane($id);
    }
    function startTab($title, $id)
    {
    	echo $this->tabs->startPanel($title, $id);
    }
    function endTab()
    {
    	echo $this->tabs->endPanel();
    }
    function endPane()
    {
    	echo $this->tabs->endPane();
    }
    
    function processPath($p_path,$p_addtrailingslash = true)
    {
    	jimport('joomla.filesystem.path');
		$path = JPath::clean($p_path);
		if ($p_addtrailingslash) {
			$path = rtrim($path, DS) . DS;
		}
		return $path;
    }
    
    function readDirectory($path, $filter = '.', $recurse = false, $fullpath = false)
    {
    	return JFolder::files($path, $filter, $recurse, $fullpath);
    }
    
    function chmod($path)
    {
    	JPath::setPermissions($path);
    }
    function redirect($url, $msg = null)
    {
    	global $mainframe;
    	$mainframe->redirect($url, $msg);
    }
}

// SET PATHS
define('RST_BACKEND_SCRIPT_PATH',JURI :: root().'administrator/index.php');
define('RST_FRONTEND_SCRIPT_PATH',JURI :: root().'index.php');

define('RST_BACKEND_ABS_PATH',JPATH_SITE.'/administrator/components/com_rstickets');
define('RST_BACKEND_REL_PATH',JURI :: root().'administrator/components/com_rstickets');
define('RST_FRONTEND_ABS_PATH',JPATH_SITE.'/components/com_rstickets');
define('RST_FRONTEND_REL_PATH',JURI :: root().'components/com_rstickets');


//Other paths
define('RST_JOOMLA_XML_PATH', JPATH_SITE . '/libraries/domit/xml_domit_lite_include.php');


?>