<?
include ('config.php');

ob_start();
// Check for valid cookie
$sql = mysql_query("SELECT * FROM ava_cats ORDER BY id");
	if(isset($_COOKIE["ava_username"]))
	{
		$user = $_COOKIE['ava_username'];
		$code = $_COOKIE['ava_code'];
		$userid = intval($_COOKIE['ava_userid']);
		$code2 = ereg_replace("[^A-Za-z0-9]", "", $code );
		
		$sql = mysql_query("SELECT * FROM ava_users WHERE id='$userid' AND password='$code2'");
		$login_check = mysql_num_rows($sql);
			if($login_check <= 0)
			{
				echo 'Your cookie is not valid, please <a href='.$site_url.'/login.php?action=logout>logout</a>';
				exit();
			}
	}

// If valid cookie and not logged in, find out if logged in or not
	if(isset($_COOKIE["ava_username"]))
	{
		// Store all cookie data in variables
		$user = $_COOKIE['ava_username'];
		$code = $_COOKIE['ava_code'];
		$userid = intval($_COOKIE['ava_userid']);
	}
// Include language file
include ('language/'.$language.'.php');

// Include the template
  $string = $template_url;
  if(!stristr($string, 'http') === FALSE) {
    echo '#01 You have entered an invalid template url';
	exit();
  }
 if (file_exists('.'.$template_url.'/index.php')) {
    include ('.'.$template_url.'/index.php');}
	else {echo '#02 You have entered an invalid template url'; }
	
ob_end_flush();	
?>
