<?php

	// a date in the past
	header("Expires: Mon, 23 Jul 1993 05:00:00 GMT");
	// always modified
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	// HTTP/1.1
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0, max-age=0", false);

	require(dirname(__FILE__).'/../../init.php');

	define('AKB_WL_LANG_FILE',			AKB_ROOT.DS.'includes/language/'.$GLOBALS['currentLanguage'].'/whitelabel.ini');
	define('AKB_LANG_FILE',				AKB_ROOT.DS.'includes/language/'.$GLOBALS['currentLanguage'].'/back_language.ini');
	define('AKB_TPL_LOAD_PATH',			AKB_ROOT.DS.'admin/templates/');
	define('AKB_TPL_PHP_PATH',			AKB_ROOT.DS.'admin/includes/display/');
	define('AKB_TPL_HTTP_PATH',			$GLOBALS['pathToKB'].'/admin/templates/');
	define('AKB_TPL_IMAGE_PATH',		AKB_TPL_HTTP_PATH.'Images');
	define('AKB_PANEL_LOAD_PATH',		AKB_TPL_LOAD_PATH.'Panels/');
	define('AKB_SNIPPET_LOAD_PATH',		AKB_TPL_LOAD_PATH.'Snippets/');
	define('CLASS_DIR',					AKB_ROOT.DS.'admin/includes/classes');

	$GLOBALS['SNIPPETS'] = '';

	require(CLASS_DIR.'/class.helper.php');
	require(CLASS_DIR.'/class.category.php');
	require(CLASS_DIR.'/class.template.php');
	require(CLASS_DIR.'/class.auth.php');
	require(CLASS_DIR.'/class.install.php');
	require(CLASS_DIR.'/class.engine.php');
	require(CLASS_DIR.'/class.admintable.php');
	require(CLASS_DIR.'/class.stats.php');
	
	$GLOBALS['AKB_CLASS_HELPER']	= new AKB_HELPER;
	$GLOBALS['AKB_CLASS_TEMPLATE']	= new AKB_TEMPLATE();
	$GLOBALS['AKB_CLASS_AUTH']		= new AKB_AUTH();

	//Make sure the user is logged in.
	if (!$GLOBALS['AKB_CLASS_AUTH']->IsLoggedIn()) {
		die(LOGGED_OUT_JS);
	}
	
	//Instanciate the correct class, then call the specified function.
	$todo = htmlspecialchars($_GET['todo'],ENT_QUOTES,$GLOBALS['charset']);

	switch ($todo) {
		case "ShowRatingsListRemote":
			require(CLASS_DIR.'/class.rating.php');
			$GLOBALS['AKB_CLASS_RATING'] = new AKB_RATING();
			$GLOBALS['AKB_CLASS_RATING']->ShowRatingsListRemote();

			break;
		case "ShowGroupsListRemote":
			require(CLASS_DIR.'/class.group.php');
			$GLOBALS['AKB_CLASS_RATING'] = new AKB_GROUP();
			$GLOBALS['AKB_CLASS_RATING']->ShowGroupsListRemote();

			break;
			
		case "ShowCustomFieldsListRemote":
			require(CLASS_DIR.'/class.customfields.php');
			$GLOBALS['AKB_CLASS_RATING'] = new AKB_CUSTOMFIELDS();
			$GLOBALS['AKB_CLASS_RATING']->ShowCustomFieldsListRemote();

			break;			
		case "ShowQuestionsListRemote":
			require(CLASS_DIR.'/class.question.php');
			$GLOBALS['AKB_CLASS_CATEGORY'] = new AKB_CATEGORY();
			$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
			$GLOBALS['AKB_CLASS_QUESTION']->ShowQuestionsListRemote();

			break;
		case "ShowWorkflowQuestionsListRemote":
			require(CLASS_DIR.'/class.question.php');
			$GLOBALS['AKB_CLASS_CATEGORY'] = new AKB_CATEGORY();
			$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
			$GLOBALS['AKB_CLASS_QUESTION']->ShowWorkflowQuestionsListRemote();

			break;
		case "ShowNewsListRemote":
			require(CLASS_DIR.'/class.news.php');
			$GLOBALS['AKB_CLASS_NEWS'] = new AKB_NEWS();
			$GLOBALS['AKB_CLASS_NEWS']->ShowNewsListRemote();

			break;
		case "MostViewedQuestionsFull":
		case "HighestRatedQuestionsFull":
		case "MostDiscussedQuestionsFull":
		case "MostPopularQuestionsFull":
		case "MostPopularAuthorsFull":
		case "TopCommenters":
		case "MostViewedCategories":
		case "MostPopularFailedSearchesFull":
		case "MostPopularSearchesFull":
		case "TopPosters":
			//For the stats remote tables we fork out to the stats class to handle more specifically.
			$GLOBALS['AKB_CLASS_STATS'] = new AKB_STATS();
			$GLOBALS['AKB_CLASS_STATS']->HandleRemoteStats();

			break;
		default:
			die("--");
	}

	die();
?>
