<?php

$sessionHandling = true;
include_once("../init.php");
include_once(PATH_TO_ROOT."/TGI/initLogin.php");
include_once(PATH_TO_ROOT."/TGI/_class/class.permissions.php");

$tgi_perm = new tgi_permissions($db);

$loginFlag = false;

$db->ChangeDatabase(DB_WARPIT_USERSPOOL);
// check if user is added to TGI pool users
if ($tgi_perm->checkUser($_REQUEST['TGIuser'],$_REQUEST['TGIpass'])) {
	$TGIuser = $tgi_perm->get_TGIuser();
	//echo "I found user: $TGIuser<br>";
	
	// add user to warpit
	$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
	$tgi_perm->addInterviwer2Warpit($TGIuser,$dbConfigTGI['default-language']);
	
	// set user to TGI project
	$db->ChangeDatabase(DB_WARPIT_TGI);
	$tgi_perm->setTGIinterviwer();
	
	//check login if available user inside pool
	if ($UserSession->Login($_REQUEST['TGIuser'],$_REQUEST['TGIpass'],0,true)) {
		if($UserSession->IsLoggedIn()) {
			//echo "I guess I manage to login...<br>";
			$loginFlag = true;
		} else {
			$loginFlag = false; 
		}
	} else {
		$loginFlag = false;
	}

} else {
	$loginFlag = false;
}

echo "<script>document.location = 'index.php';</script>";

?>