<?php
/**
 * File to select template and style sheet for the site
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		Common/select_template
 * @author 		senthil_52ag05
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		Release: @package_version@
 * @since 		2008-12-12
 */
//detect requested template
$requested_template = $CFG['html']['template']['default'];
$requested_style = $CFG['html']['stylesheet']['screen']['default'];
$is_set_cookie_session = false;
if (!empty($_POST['template']))
	{
		$array = explode('__', $_POST['template']);
		$requested_template = $array[0];
		$requested_style = $array[1];
		$is_set_cookie_session = true;
	}
else if (!empty($_GET['template']))
	{
		$array = explode('__', $_GET['template']);
		$requested_template = $array[0];
		$requested_style = $array[1];
		$is_set_cookie_session = true;
	}
else if (!empty($_COOKIE['template']) and !empty($_COOKIE['style']))
	{
		$requested_template = $_COOKIE['template'];
		$requested_style = $_COOKIE['style'];
	}
else if (!empty($_SESSION['user']['pref_template']) and !empty($_SESSION['user']['pref_style']))
	{
		$requested_template = $_SESSION['user']['pref_template'];
		$requested_style = $_SESSION['user']['pref_style'];
	}

if ($is_set_cookie_session or $requested_template!=$CFG['html']['template']['default'] or $requested_style!=$CFG['html']['stylesheet']['screen']['default'])
	{
	   if (is_dir($CFG['site']['project_path']. './design/templates/'.$requested_template.'/') and is_file($CFG['site']['project_path']. './design/templates/'.$requested_template.'/members/css/'.$requested_style.'.css'))
			{
				$CFG['html']['template']['default'] = $requested_template;
				$CFG['html']['stylesheet']['screen']['default'] = $requested_style;
				//set cookie and session...
				setcookie('template', $requested_template, time()+ 4320000, '/'); //expire in 50 days (50x24x60x60)
				$_SESSION['user']['pref_template'] = $requested_template;

				//set cookie and session...
				setcookie('style', $requested_style, time()+ 4320000, '/'); //expire in 50 days (50x24x60x60)
				$_SESSION['user']['pref_style'] = $requested_style;
			}
	}
?>