<?php 
error_reporting(0);
ob_start();
ob_clean();
session_start();
include('inc/functions.php');
require_once("inc/class/class.admin_users.php");
require_once("inc/class/class.client_org.php");
$userObj=new admin_users;
$clientObj=new client_org;
/* Login attempt Count */
$attempt_count=1;
/* Login */
if(isset($_POST['login_submit']))
{	
	$username=sanitize($_POST['username']);
	$userObj->username=sanitize($_POST['username']);
	$userObj->password=sanitize(md5($_POST['password']));
	$checkusername=$userObj->checkuser($username);
	if($checkusername==-1)
	{
		$nouser=1;
	}
	else
	{
	if(!$userObj->login())
	{
	
		$error_msg='Invalid username or password';
	}
	}
	
}

 ?>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
	<title>Web-School Admin Login</title>
	<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/todc-bootstrap.min.css">
	<link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/custom_style.css">
	<link rel="stylesheet" href="css/theme/color_1.css" id="theme">
	<link href='http://fonts.googleapis.com/css?family=Roboto:300&amp;subset=latin,latin-ext' rel='stylesheet' type='text/css'>
	<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
	<style>
		body {padding:80px 0 0}
		textarea, input[type="password"], input[type="text"], input[type="submit"] {-webkit-appearance: none}
		.navbar-brand {font:300 15px/18px 'Roboto', sans-serif}
		.login_wrapper {position:relative;width:380px;margin:0 auto}
		.login_panel {background:#f8f8f8;padding:20px;-webkit-box-shadow: 0 0 0 4px #ededed;-moz-box-shadow: 0 0 0 4px #ededed;box-shadow: 0 0 0 4px #ededed;border:1px solid #ddd;position:relative}
		.login_head {margin-bottom:20px}
		.login_head h1 {margin:0;font:300 20px/24px 'Roboto', sans-serif}
		.login_submit {padding:10px 0}
		.login_panel label a {font-size:11px;margin-right:4px}
		
		@media (max-width: 767px) {
			body {padding-top:40px}
			.navbar {display:none}
			.login_wrapper {width:100%;padding:0 20px}
		}
	</style>
	<!--[if lt IE 9]>
		<script src="js/ie/html5shiv.js"></script>
		<script src="js/ie/respond.min.js"></script>
	<![endif]-->
</head>
<body>
	<header class="navbar navbar-default navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand" href="index.php">Web-school.in</a>
			</div>
			<div class="pull-right">
				<ul class="nav navbar-nav">
					<li class="active"><a href="index.php" >School Management Software</a></li>
				</ul>
			</div>
		</div>
    </header>
    <div class="login_wrapper">
     <?php if (isset($_REQUEST['success'])){ ?>

          <p>

          <div class='success'>School ERP Installed successfully</div><br />
          Congratulations! You have successfully installed the admin panel.You can now modify the source code as per your requirement.
          Click on the button for Admin Panel.
          <br /><br />
<br /></p>
<a href="index.php" ><div align="center" class="btn btn-primary btn-block btn-lg">Lets Go</div></a>




          <?php }else{?>
          
    
 	<?php  /*Success Message*/
	if($reg_msg==1) {?>
	<div class="success">
    Congrats, you did it!
    <p>Please check your email and verify your email address</p>
    </div>
    <?php } /*Success Message*/?>
    <?php  /*Error Message*/
	if($user_error==1) {?>
	<div class="error">
    <p>This username already exists</p>
    <p> Please enter someother username.</p>
    </div>
    <?php }
	if($nouser==1) {?>
	<div class="error">
    <p> Oh ! you have entered a invalid username </p>
    
    </div>
    <?php }
	
	if($logattempterror==1) {?>
	<div class="error">
    <p> Hello ! you are tring too often. You have been blocked from logging in.  </p>
    <p> Please contact our support team or reset your password</p>
    
    </div>
    <?php }
	 /*Error Message*/?>
	
   

		<div class="login_panel log_section">
			<div class="login_head">
				<h1>Log In to Web-school.in Admin Panel</h1>
			</div>
			<form action="#" id="login_form" method="POST">
				<div class="form-group">
					<label for="login_username">Username</label>
					<input type="text" id="username" name="username" class="form-control input-lg" data-required="true" data-minlength="2" data-required-message="Please enter a valid Username" value="" >
				</div>
				<div class="form-group">
					<label for="login_password">Password </label>
					<input type="password" id="password" name="password" class="form-control input-lg" data-required="true" data-minlength="6" data-minlength-message="Password should have at least 6 characters." data-required-message="Please enter a valid Password" value="">
                    <label > <a href="#" class="pull-right">Forgot password?</a></label>
                    <input type="hidden" value="<?php echo $attempt_count; ?>" name="login-attempt" id="login-attempt" />
                    <div class="error_message" > <?php echo $error_msg; ?> </div>
					<!--<label class="checkbox"><input type="checkbox" name="login_remember" id="login_remember"> Remember me</label>-->
				</div>
				<div class="login_submit">
					<button class="btn btn-primary btn-block btn-lg" name="login_submit" id="login_submit">Log In</button>
				</div>
				<div class="text-center">
					
				</div>
			</form>
		</div>
   
			<?php } ?>
	</div>
	
	<script src="js/jquery.min.js"></script>
	<!-- jquery cookie -->
			<script src="js/jquery_cookie.min.js"></script>
	<script src="js/lib/parsley/parsley.min.js"></script>
	<script>
		$(function() {
			
			//* validation
			$('#login_form').parsley({
				errors: {
					classHandler: function ( elem, isRadioOrCheckbox ) {
						if(isRadioOrCheckbox) {
							return $(elem).closest('.form_sep');
						}
					},
					container: function (element, isRadioOrCheckbox) {
						if(isRadioOrCheckbox) {
							return element.closest('.form_sep');
						}
					}
				}
			});
			
			
			//* Registration validation
			$('#register_form').parsley({
				errors: {
					classHandler: function ( elem, isRadioOrCheckbox ) {
						if(isRadioOrCheckbox) {
							return $(elem).closest('.form_sep');
						}
					},
					container: function (element, isRadioOrCheckbox) {
						if(isRadioOrCheckbox) {
							return element.closest('.form_sep');
						}
					}
				}
			});
			//* change form
			$('.form_toggle').on('click',function(e){
				$('.login_panel').slideToggle(function() {
					if($('.log_section').is(':visible')) {
						$('.login_toggle').closest('li').addClass('active').siblings('li').removeClass('active');
					} else {
						$('.register_toggle').closest('li').addClass('active').siblings('li').removeClass('active');
					}
				});
				e.preventDefault();
			});
			
			$('.login_toggle').on('click',function(e){
				if($('.log_section').is(':hidden')) {
					$('.reg_section').slideUp();
					$('.log_section').slideDown();
					$(this).closest('li').addClass('active').siblings('li').removeClass('active');
				}
				e.preventDefault();
			});
			$('.register_toggle').on('click',function(e){
				if($('.reg_section').is(':hidden')) {
					$('.log_section').slideUp();
					$('.reg_section').slideDown();
					$(this).closest('li').addClass('active').siblings('li').removeClass('active');
				}
				e.preventDefault();
			});
			
			// set theme from cookie
			if($.cookie('ebro_color') != undefined) {
				$('#theme').attr('href','css/theme/'+$.cookie('ebro_color')+'.css');
			}
			
		});
	</script>
</body>
</html>