<?php
	define(CURRENT_PAGE, basename(__FILE__, ".php"));
	require_once("system.engine/system.core.php");
	$l->setPrefix(CURRENT_PAGE);
	
	global $systemHandler;
	$systemExecution = &$systemHandler->loadHandler("EXECUTION");
	
	if(isset($_GET["reset"])) {
		$mResetKey = $_GET["reset"];
		if($systemExecution->runQuery("SELECT COUNT(id) AS userCount FROM web_user WHERE lost_hash = '%s'", $mResetKey)->fetch_object()->userCount > 0) {
			$mNewPassword = "elite-".time()."-".rand(9999, 99999)."-network";
			$systemHandler->loadHandler("MAIL")->submitPasswordMail($systemExecution->runQuery("SELECT id FROM web_user WHERE lost_hash = '%s'", $mResetKey)->fetch_object()->id, $mNewPassword);
			$systemExecution->runQuery("UPDATE web_user SET lost_hash = '', password = '%s' WHERE lost_hash = '%s'", array($systemHandler->loadHandler("HASH")->hashString($mNewPassword), $mResetKey));
		}
	}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title><?php echo $systemHandler->loadHandler("CONFIG")->mSocialName ?> - <?php echo $l->getValue("title"); ?></title>
		<meta name="viewport" content="width=device-width, user-scalable=no" />
		<link href="system.assets/bootstrap/css/bootstrap.css" rel="stylesheet">
		<link href="system.assets/css/flat-ui.css" rel="stylesheet">
		<link href="system.assets/css/elitenetwork.css" rel="stylesheet">
		<link href="system.assets/css/sweet-alert.css" rel="stylesheet">
		<link rel="shortcut icon" href="system.assets/images/favicon.ico">
		<!--[if lt IE 9]>
		<script src="system.assets/js/html5shiv.js"></script>
		<script src="system.assets/js/respond.min.js"></script>
		<![endif]-->
		<link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
		<style type="text/css">
			body {
				font-family: 'Source Sans Pro', sans-serif;
				background-image: url('')
			}
			center > a {
			margin-left: 0;
			font-size: 14px;
			font-weight: bold
			}
			.form-control {
			border: #fff
			}
			
			.form-box {
				width: 100%;
				margin-top: -70px;
				margin-bottom: 30px
				}
				.form-box .header {
				-webkit-border-top-left-radius: 4px;
				-webkit-border-top-right-radius: 4px;
				-webkit-border-bottom-right-radius: 0;
				-webkit-border-bottom-left-radius: 0;
				-moz-border-radius-topleft: 4px;
				-moz-border-radius-topright: 4px;
				-moz-border-radius-bottomright: 0;
				-moz-border-radius-bottomleft: 0;
				border-top-left-radius: 4px;
				border-top-right-radius: 4px;
				border-bottom-right-radius: 0;
				border-bottom-left-radius: 0;
				background: rgb(246, 147, 132);;
				box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
				text-align: center;
				font-size: 26px;
				font-weight: 300;
				color: #fff;
				}

				.form-box .body, .form-box .footer {
				padding: 10px 10px;
				background: #fff;
				color: #444;
				}

				.bg-gray {
				background-color: #eaeaec !important;
				}

				.form-box .footer {
				-webkit-border-top-left-radius: 0;
				-webkit-border-top-right-radius: 0;
				-webkit-border-bottom-right-radius: 4px;
				-webkit-border-bottom-left-radius: 4px;
				-moz-border-radius-topleft: 0;
				-moz-border-radius-topright: 0;
				-moz-border-radius-bottomright: 4px;
				-moz-border-radius-bottomleft: 4px;
				border-top-left-radius: 0;
				border-top-right-radius: 0;
				border-bottom-right-radius: 4px;
				border-bottom-left-radius: 4px;
				}

				.form-box .body, .form-box .footer {
				padding: 10px 10px;
				background: #fff;
				color: #444;
				}

				.header {
					margin-left: 0px
				}

				.form-group:last-child {
					margin-bottom: 0px
				}
		</style>
	</head>
	<body class="bodyBackground">
		<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
			<div class="row">
				<div class="col-md-6 col-xs-10 col-md-offset-3 col-xs-offset-1">
					<div class="navbar-header">
						<a class="navbar-brand" href="#"><img src="http://elitecode.de/cc/elitenetwork/system.assets/images/logo.png" /></a>
					</div>
				</div>
			</div>
		</nav>
		<div class="row" id="rowBody">
			<div class="col-md-10 col-md-offset-1 hidden-xs">
				<center>
					<?php
						if(strlen($systemHandler->loadHandler("CONFIG")->mAds[2]) > 0)
							echo $systemHandler->loadHandler("CONFIG")->mAds[2];
					?>
				</center>
			</div>
			<div class="col-md-6 col-md-offset-3 col-xs-10 col-xs-offset-1">
				<div class="alert alert-danger" id="errorBox"><i class="glyphicon glyphicon-warning-sign"></i> <span id="errorText"></span></div>
			</div>
			<div class="col-md-4 col-xs-10 col-md-offset-3 col-xs-offset-1 hidden-sm" id="containerDesc">
				<center>
					<div class="mainTitle"><?php echo vsprintf($l->getValue("maintitle"), $systemHandler->loadHandler("CONFIG")->mSocialName); ?></div>
					<br />
					<div class="subTitle"><?php echo $l->getValue("maindesc"); ?></div>
					<?php
						$mUserQuery = $systemHandler->loadHandler("EXECUTION")->runQuery("SELECT id FROM web_user ORDER BY RAND() LIMIT 5", "");
						$mCount = 0;
						while($mRow = $mUserQuery->fetch_assoc()) {
							$mCount++;
							$mCachedUser = new systemUSER($mRow["id"]);
							echo "<img data-toggle=\"tooltip\" data-placement=\"top\" title=\"".$mCachedUser->mFullname."\" src=\"".$mCachedUser->mProfilePicture."\" class=\"indexUser ".($mCount > 3 ? "hidden-xs" : null)."\" />";
						}
						?>
					<div id="vmap" class="hidden-xs" style="width: 100%; height: 300px;"></div>
				</center>
			</div>
			<div class="col-md-2 col-xs-10 col-xs-offset-1 col-md-offset-0" id="containerForm">
				<div class="form-box" id="signInForm">
					<div class="header"><?php echo $l->getValue("signin"); ?></div>
					<form method="POST" action="javascript:;" id="formSignIn">
						<div class="body bg-gray">
							<div class="form-group">
								<div class="row">
									<div class="col-md-12 col-xs-12">
										<input type="email" value="demo@elitecode.de" name="loginMail" class="form-control" placeholder="<?php echo $l->getValue("email"); ?>">
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="row">
									<div class="col-md-12 col-xs-12">
										<input type="password" value="demo123" name="loginPass" class="form-control" placeholder="<?php echo $l->getValue("password"); ?>">
									</div>
								</div>
							</div>
						</div>
						<div class="footer">
							<div class="row">
								<div class="col-md-12 col-xs-12">
									<button style="color: white" id="loginButton" type="submit" class="btn bg-olive btn-block"><?php echo $l->getValue("login"); ?></button>
								</div>
							</div>
							<center style="margin-top: 5px; border-top: 1px solid rgba(0, 0, 0, 0.1)">
								<a id="registerLink" class="text-center"><i class="glyphicon glyphicon-plus font12"></i> <?php echo $l->getValue("registernew"); ?></a>
							</center>
						</div>
					</form>
				</div>
				
				<div class="form-box" id="signUpForm" style="display: none">
					<div class="header"><?php echo $l->getValue("signup"); ?></div>
					<form method="POST" action="javascript:;" id="formSignUp">
						<div class="body bg-gray">
							<div class="form-group">
								<div class="row">
									<div class="col-md-6 col-xs-12">
										<input type="text" name="registerFirstname" class="form-control" placeholder="<?php echo $l->getValue("firstname"); ?>">
									</div>
									<div class="col-md-6 col-xs-12">
										<input type="text" name="registerLastname" class="form-control" placeholder="<?php echo $l->getValue("lastname"); ?>">
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="row">
									<div class="col-md-12 col-xs-12">
										<input type="email" name="registerMail" class="col-md-6 col-xs-12 form-control" placeholder="<?php echo $l->getValue("email"); ?>">
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="row">
									<div class="col-md-12 col-xs-12">
										<input type="password" name="registerPass" class="form-control" placeholder="<?php echo $l->getValue("password"); ?>">
									</div>
								</div>
							</div>
							<input type="hidden" value="<?php echo $systemHandler->loadHandler("CONFIG")->mCaptchaType ?>" id="useCaptcha" />
							<?php if($systemHandler->loadHandler("CONFIG")->mCaptchaType == 1) { ?>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-12">
											<center>
												<span id="n1"><?php echo rand(0, 25); ?></span> + <span id="n2"><?php echo rand(0, 25); ?></span> =
											</center>
										</div>
										<div class="col-md-7 col-xs-12">
											<input type="text" id="captchaResult" class="form-control" placeholder="<?php echo $l->getValue("result"); ?>" />
										</div>
									</div>
								</div>
							<?php } ?>
						</div>
						<div class="footer">
							<div class="row">
								<div class="col-md-12 col-xs-12">
									<button style="color: white" id="registerButton" type="submit" class="btn bg-olive btn-block"><?php echo $l->getValue("submit"); ?></button>
								</div>
							</div>
							<center style="margin-top: 5px; border-top: 1px solid rgba(0, 0, 0, 0.1)">
								<a id="loginLink" class="text-center"><i class="glyphicon glyphicon-share-alt font12"></i> <?php echo $l->getValue("backlogin"); ?></a>
							</center>
						</div>
					</form>
				</div>
				
				<div class="forgotPassword" style="margin-top: -25px">
					<center>
						<a id="lostPassword" href="javascript:;">
							<i class="glyphicon glyphicon-record font12"></i> <?php echo $l->getValue("forgotpass"); ?>
						</a>
					</center>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-6 col-md-offset-3 col-xs-12 pageFooter">
				<a href="page.policy.php"><?php echo $l->getValue("termsofuse"); ?></a> -
				<a href="page.policy.php"><?php echo $l->getValue("disclaimer"); ?></a> -
				<a href="page.policy.php"><?php echo $l->getValue("privacypolicy"); ?></a> -
				<a href="page.policy.php"><?php echo $l->getValue("about"); ?></a> -
				<a href="javascript:;"><?php echo $l->getValue("admin"); ?></a>
					<br />
				Copyright © 2015 <?php echo $systemHandler->loadHandler("CONFIG")->mSocialName ?>. All rights reserved. Powered by <a href="http://elitecode.de">Elitecode</a>.
			</div>
		</div>
		<!-- Modal reset password-->
		<div class="modal fade" id="modalResetPassword" tabindex="-1" role="dialog" aria-labelledby="modalResetPassword" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"><?php echo $l->getValue("close"); ?></span></button>
						<h4 class="modal-title" id="myModalLabel"><?php echo $l->getValue("forgotpass"); ?></h4>
					</div>
					<div class="modal-body" style="background-color: #eaeaec">
						<div class="row">
							<div class="col-md-3 hidden-xs hidden-sm">
								<img src="system.assets/images/icons/svg/mail.svg" />
							</div>
							<div class="col-md-9 col-xs-12" id="lostContent">
								<label for="lostMail" style="margin-left: 15px"><?php echo $l->getValue("emailquestion"); ?></label>
								<div class="row">
									<div class="col-md-12">
										<input type="email" class="form-control" id="lostMail" />
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $l->getValue("close"); ?></button>
						<button type="button" class="btn btn-primary" id="submitLost"><?php echo $l->getValue("reset"); ?></button>
					</div>
				</div>
			</div>
		</div>
		<script src="system.assets/js/jquery-1.8.3.min.js"></script>
		<script src="system.assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="system.assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="system.assets/js/bootstrap.min.js"></script>
		<script src="system.assets/js/bootstrap-select.js"></script>
		<script src="system.assets/js/bootstrap-switch.js"></script>
		<script src="system.assets/js/flatui-checkbox.js"></script>
		<script src="system.assets/js/flatui-radio.js"></script>
		<script src="system.assets/js/jquery.tagsinput.js"></script>
		<script src="system.assets/js/jquery.placeholder.js"></script>
		<script src="system.assets/js/sweet-alert.js"></script>
		<script src="system.assets/jqvmap/jquery.vmap.js" type="text/javascript"></script>
		<script src="system.assets/jqvmap/maps/jquery.vmap.world.js" type="text/javascript"></script>
		<script src="system.assets/jqvmap/data/jquery.vmap.userinfo.js" type="text/javascript"></script>
		<script src="system.jquery/system.index.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$('[data-toggle="tooltip"]').tooltip();
				
				$("#vmap").vectorMap({
					map: "world_en",
					backgroundColor: "none",
					color: "#ffffff",
					hoverOpacity: 0.7,
					selectedColor: "#666666",
					enableZoom: true,
					showTooltip: true,
					values: mUserInfo,
					scaleColors: ["#FFFFFF", "#F26651"],
					normalizeFunction: "polynomial",
					showTooltip: true
				});
				
				$("#registerLink").click(function () {
					$("#signInForm").fadeOut(function () {
						$("#signUpForm").fadeIn();
					});
				});
				
				$("#loginLink").click(function () {
					$("#signUpForm").fadeOut(function () {
						$("#signInForm").fadeIn();
					});
				});
				
				$("body").on("click", "#submitLost", function () {
					$.ajax({
						url: "system.ajax/ajax.handle.lost.password.php",
						type: "POST",
						dataType: "JSON",
						data: { lostMail: $("#lostMail").val() },
						success: function(ajaxResponse) {
							if(ajaxResponse.isValid)	
								$("#lostContent").html("<center style=\"margin-top: 40px\"><i class=\"glyphicon glyphicon-thumbs-up font14\"></i> <?php echo $l->getValue("checkinbox"); ?>!</center>");
						}
					});
				});
			});
		</script>
	</body>
</html>