<?php 
ini_set('display_errors', 0);

// error_reporting(~E_ALL);

ob_start();

session_start();

// $_SESSION['TER']['admin'] = true;

if(!$_SESSION['TER']['admin'])
{
	$cwd = str_replace("\\","/",getcwd())."/";
	
	$root = $_SERVER['DOCUMENT_ROOT'];
	
	$fld = substr($cwd, 0, -1);
	
	$pos = strcmp($root, $fld)-1;
	
	$fld = substr($fld, strrpos($fld,"/"));
	
	$fld = substr($fld, $pos)."/";
	
	if($_SERVER['REQUEST_URI'] != $fld)
		$_SESSION['prvs_url'] = $_SERVER['REQUEST_URI'];
	else
		unset($_SESSION['prvs_url']);
	
	echo '<!DOCTYPE html>
<html>
<head>
<title>HRMSM</title>
';
	
	include("includes/config.php");
	include("includes/header.php");
	include_once("includes/common_functions.php");
    $common = new General_Functions();
	//include("includes/top.php");
	
	$msg_ary = false;
	if(is_array($_SESSION['msg']))
	{
		$msg_ary = true;
		$msg_link = $_SESSION['msg'][1];
		$_SESSION['msg'] = $_SESSION['msg'][0];
	}
	?>
		<script>
			$(document).ready(function() {
				$("#delete_img").hide();
				<?php if(isset($_SESSION['msg'])) { ?>
					$(".message span").html('<?php echo $_SESSION['msg']; ?>');
					$(".message").show();
					$(".message").fadeOut(15000);
					<?php if($msg_ary) { ?>
						setTimeout('open_win("<?php echo $msg_link; ?>")', 5000);
					<?php } ?>
					<?php unset($_SESSION['msg']); ?>
				<?php } ?>
			} );
			
			function open_win(url)
			{
				window.open(url);
			}
		</script>
	<?php
	
	echo '<div class="content">
			<div class="logo">'.APP_NAME.'</div>';
	
	echo '
		<div class="message">
				<img src="includes/images/close.gif" style="float: right; padding-left: 40px; cursor: pointer;" onclick="javascript: $(\'.message\').hide();">
				<span></span>
		</div>';
	
	if($_REQUEST['page'] != "forgot_password")
		include("modules/login/index.php");
	else
		include("modules/forgot_password/index.php");
	// header("location:login.php");
	include("includes/bottom.php");
	echo '</div>
</body>
</html>';
}
else
{
	if($_SESSION['prvs_url'] != '')
	{
		$url = $_SESSION['prvs_url'];
		unset($_SESSION['prvs_url']);
		header("location:".$url);
	}
	elseif($_REQUEST['mode'] != 'pdf')
	{
		include("content.php");
	}
	else
	{
		include($_REQUEST['page'].".php");
	}
}
?>