<?php
	if (!$UserSession or !$UserSession->IsLoggedIn()) { echo "attack!"; exit; }
	unset($_SESSION['loadedPlugin']);
	unset($_SESSION['addedTabs']);
	$_SESSION['UserInfo']['mc_rootpath'] = WARPIT_WEBPROJECTS;


	$dbConfigCapi = configLoader::loadConfig('capi');
	$dbConfigPaths = configLoader::loadConfig('paths');
	//var_dump();
	$sql = "SELECT  translate_key, translate_text
				FROM  ".DB_WARPIT_MAIN."._languagePack
					WHERE id_programme = 2 AND id_language = ".$dbConfigCapi['default-language']." AND sub_page = 'capi'";
	//echo $sql;
	$res = $db->SQLexecute($sql);
	while ($zad = $db->fetchAssoc($res)) $languagePack[$zad['translate_key']] = $zad['translate_text'];

	// if we have defined auto live update, we check for internet connection and if exists to server we do live update
	$loadLiveUpdadte 	= false;
	$loadCapiConfig 	= false;

	if ($dbConfigPaths['live_update_www'] == "http://") {
		$loadCapiConfig = true;
 	} else {
		$checkUrl = @parse_url($dbConfigPaths['live_update_www']);
		//$checkUrl['host'] = "192.168.10.10";
		if (@fsockopen($checkUrl['host'],80,$errno, $errstr, 1)){
	   	 	$loadLiveUpdadte = true;
	   	 	//echo "working";
		}
 	}
	//exit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
  <title>Warpit</title>
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/resources/css/ext-all.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>capi_html/_css/mainCapi.css" />
	<script src="<?php echo PATH_TO_ROOT;?>_support/jquery.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT; ?>capi_html/js/designJquery.js?cacheclear=<?php echo time(); ?>"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT; ?>capi_html/js/jquery.alerts.js?cacheclear=<?php echo time(); ?>"></script>
	<link rel="stylesheet" href="<?php echo PATH_TO_ROOT; ?>capi_html/_css/jquery.alerts.css">

    <!-- Empty script file...copy into it any response for easier debuging! -->

</head>
<body>
	<div id="showMenuButton"></div>
	<div class="menuLeft">
		<table>
			<tr>
				<td class="button" id="hideMenu">Hide</td>
			</tr>
			<tr>
				<tr class="logoutRow">
					<td class="button" id="logoutButton">Logout</td>
				</tr>
				<td class="emptyButton">
				<?php
					if(strlen($_SESSION['UserInfo']['Firstname']) && strlen($_SESSION['UserInfo']['Surname']))
					{
						if(strlen($_SESSION['UserInfo']['Firstname']) > 8)
							$user = substr($_SESSION['UserInfo']['Firstname'],0,8);
						else
							$user = $_SESSION['UserInfo']['Firstname'];

						if(strlen($_SESSION['UserInfo']['Surname']) > 8)
							$user .= " ".substr($_SESSION['UserInfo']['Surname'],0,8);
						else
							$user .= " ".$_SESSION['UserInfo']['Surname'];

						echo $user;
					}
					else
						echo "<i>Username</i>"
				?>
				</td>

					<tr>
						<td class="button" id="startProjectButton">Start<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/inter.png" /></td>
					</tr>
					<tr>
						<td class="button" id="projectsButton">Projects <img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/projects.png" />
						</td>
					</tr>
					<tr>
						<td class="button" id="liveUpdateButton">Live U<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/live-update.png" /></td>
					</tr>
					<tr>
						<td class="button" id="quotasButton">Quotas<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/show_quotas.png" /></td>
					</tr>
					<tr>
						<td class="button" id="infoButton">Info<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/projects.png"/></td>
					</tr>
			<!--		<tr>
						<td class="button" id="brokenQuestions">Broken Q<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/show_quotas.png" /></td>
					</tr> -->
					<tr>
						<td class="button" id="startTestSurveyButton">Test survey<img class="buttonIcon" src="<?php echo PATH_TO_ROOT;?>capi_html/_img/inter.png" /></td>
					</tr>
			</tr>
		</table>
	</div>
	<div id="projectsList">
	</div>
	<iframe id="liveUpdateIframe" src="" width="100%" height="100%"></iframe>
	<div id="closeLUIframe">X</div>

	<iframe id="quotaIframe" src="" width="100%" height="100%"></iframe>
	<div id="closeQuotaIframe">X</div>
</body>
</html>
