<?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
*/
// SET DEBUGGING ON
// error_reporting(E_ALL);

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

// REVISION
DEFINE('RST_REVISION','14');

// ADAPTER
require_once(dirname(__FILE__).'/adapter.php');
$RST_adapter = new RST_adapter();
$GLOBALS['RST_adapter'] = $RST_adapter;

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

// DATABASE INFO
$dbhost = $RST_adapter->getConfig('host');
$dbuser = $RST_adapter->getConfig('user');
$dbpass = $RST_adapter->getConfig('password');
$dbused = $RST_adapter->getConfig('db');

// CONNECT
// if (!mysql_connect($dbhost,$dbuser,$dbpass)) die('Please check config.php for connection settings.');
// if (!mysql_select_db($dbused)) die('Please check config.php for database settings.');

// START SESSION
@session_start();

// START OUTPUT BUFFER
ob_start();

// SET LANGUAGE
$rst_lang = $RST_adapter->getLanguage();
if (file_exists(RST_FRONTEND_ABS_PATH.'/lang/'.$rst_lang.'.php'))
	include(RST_FRONTEND_ABS_PATH.'/lang/'.$rst_lang.'.php');
else
	include(RST_FRONTEND_ABS_PATH.'/lang/english.php');

// SET REQUIRED TABLES
define('RST_TBL_PREFIX', $RST_adapter->getConfig('dbprefix'));
define('RST_TBL_USERS', RST_TBL_PREFIX.'users');
define('RST_TBL_CUSTOM_FIELDS',RST_TBL_PREFIX.'rstickets_custom_fields');
define('RST_TBL_CUSTOM_FIELDS_VALUE',RST_TBL_PREFIX.'rstickets_custom_fields_value');
define('RST_TBL_DEPARTMENTS',RST_TBL_PREFIX.'rstickets_departments');
define('RST_TBL_FILES',RST_TBL_PREFIX.'rstickets_files');
define('RST_TBL_GROUPS',RST_TBL_PREFIX.'rstickets_groups');
define('RST_TBL_SEARCHES',RST_TBL_PREFIX.'rstickets_searches');
define('RST_TBL_STAFF',RST_TBL_PREFIX.'rstickets_staff');
define('RST_TBL_STAFF_TO_DEPARTMENT',RST_TBL_PREFIX.'rstickets_staff_to_department');
define('RST_TBL_TICKETS',RST_TBL_PREFIX.'rstickets_tickets');
define('RST_TBL_TICKET_MESSAGE',RST_TBL_PREFIX.'rstickets_ticket_message');
define('RST_TBL_TICKET_NOTES',RST_TBL_PREFIX.'rstickets_ticket_notes');
define('RST_TBL_SETTINGS',RST_TBL_PREFIX.'rstickets_settings');
define('RST_TBL_EVENTS',RST_TBL_PREFIX.'rstickets_events');
define('RST_TBL_PLUGINS',RST_TBL_PREFIX.'rstickets_plugins');

// READ CONFIGURATION
global $T_SETTINGS;
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM `#__rstickets_settings` ORDER BY `setting` ASC");
$rows = $db->loadAssocList();
foreach ($rows as $row)
	$T_SETTINGS[$row['setting']] = $row['value'];
	
// UTF-8
if ($T_SETTINGS['RStickets_MySQL_UTF8'] == 1)
	$db->setUTF();
	
// TIMEZONE UPDATE
if (function_exists('date_default_timezone_set') && $T_SETTINGS['Date_Timezone'] != '')
	@date_default_timezone_set($T_SETTINGS['Date_Timezone']);
	
// LOAD FUNCTIONS
include(RST_FRONTEND_ABS_PATH.'/errors.php');
include(RST_FRONTEND_ABS_PATH.'/functions.php');

// EVENTS
if (file_exists(RST_FRONTEND_ABS_PATH.'/plugins/events.php'))
	include(RST_FRONTEND_ABS_PATH.'/plugins/events.php');

// EMAIL CRON
if (file_exists(RST_FRONTEND_ABS_PATH.'/plugins/cron.php'))
	include(RST_FRONTEND_ABS_PATH.'/plugins/cron.php');

// AUTOCLOSE CRON
if (time() > ($T_SETTINGS['Autoclose_Cron_Lastcheck'] + $T_SETTINGS['Autoclose_Cron_Interval']*60) && $T_SETTINGS['Autoclose_Email_Interval'] > 0 && $T_SETTINGS['Autoclose_Interval'] > 0)
	include(RST_FRONTEND_ABS_PATH.'/plugins/autoclose.php');

// CAPTCHA
if (file_exists(RST_FRONTEND_ABS_PATH.'/plugins/captcha.php'))
	include(RST_FRONTEND_ABS_PATH.'/plugins/captcha.php');
?>