<?php
$errorMessage="";
if(isset($_POST["username"])){
  $pass = new password();
  $password = $pass->password(POST("password"));
	$user=$db->getRow("SELECT id,roll,school_id,password,token,last_login FROM users WHERE status=1 and userid='".trim(POST("username"))."'");
	if(is_array($user) && count($user)>0){
    $lastLogin = $db->getVal("SELECT count(id) FROM user_detail WHERE user_id='".$user["id"]."' and status=0 and login_time >= (now() - interval 1 minute)");
    if($lastLogin>=3){
      loginLog($user["id"],0);
      $errorMessage="You have already cross login attempt limit(3) please try after 1 min ";
      $body = "Dear sir,
      $errorMessage
      Time : ".date("Y-m-d H:i:s")."
      IP : ".$_SERVER['REMOTE_ADDR']."
      Process by : ".POST("username")."
      
      Thanks";
      mymail("",$LinksDetails["admin_email"],$errorMessage,$body);
    }else{
      if($user["token"]!=""){
        $errorMessage="You are alreay login from other system plesae login first ";
        $body = "Dear sir,
        $errorMessage
        Time : ".date("Y-m-d H:i:s")."
        IP : ".$_SERVER['REMOTE_ADDR']."
        Process by : ".POST("username")."
        
        Thanks";
        mymail("",$LinksDetails["admin_email"],$errorMessage,$body);
        loginLog($user["id"],2);
      }else if($password!=$user["password"]){
        $errorMessage="Invalid password attempt ".($lastLogin+1)." time max attempt limit 3 in per min ";
        $body = "Dear sir,
        $errorMessage
        Time : ".date("Y-m-d H:i:s")."
        IP : ".$_SERVER['REMOTE_ADDR']."
        Process by : ".POST("username")."
        
        Thanks";
        mymail("",$LinksDetails["admin_email"],$errorMessage,$body);
        loginLog($user["id"],0);
      }else{
        $db->updateAry("users",array("token"=>md5(microtime()),"last_login"=>date("Y-m-d H:i:s"))," where id=".$user["id"]);
        $_SESSION["first"]="yes";
        $_SESSION["admin"]["login"]="Yes";
        $_SESSION["admin"]["uid"]=$user["id"];
        $_SESSION["admin"]["school_id"]=$user["school_id"];
        $_SESSION["admin"]["roll"]=$user["roll"];
        $_SESSION["admin"]["session"]=$_POST["session"];
        $body = "Dear sir,
        $errorMessage
        Time : ".date("Y-m-d H:i:s")."
        IP : ".$_SERVER['REMOTE_ADDR']."
        Process by : ".POST("username")."
        
        Thanks";
        mymail("",$LinksDetails["admin_email"],$errorMessage,$body);
        loginLog($user["id"],1);
        $cookie_name = "user_session";
        $cookie_value = json_encode($_SESSION);
        setcookie($cookie_name, $cookie_value, time() + (86400 * 360), "/");
        redirect("./");
      }
    }
	}else{
    $errorMessage="invalid user id please try again ";
    $body = "Dear sir,
    $errorMessage
    Time : ".date("Y-m-d H:i:s")."
    IP : ".$_SERVER['REMOTE_ADDR']."
    Process by : ".POST("username")."
    
    Thanks";
    mymail("",$LinksDetails["admin_email"],$errorMessage,$body);
    
  }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <title><?php echo $LinksDetails["site_name"]; ?></title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- Styles -->
  <link href='<?php echo URL_ROOT ?>assets/css/chosen.css' rel='stylesheet' tyle="text/css">
  <link href="<?php echo URL_ROOT ?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <link href="<?php echo URL_ROOT ?>assets/css/theme/avocado.css" rel="stylesheet" type="text/css" id="theme-style">
  <link href="<?php echo URL_ROOT ?>assets/css/prism.css" rel="stylesheet/less" type="text/css">
  <link href='<?php echo URL_ROOT ?>assets/css/fullcalendar.css' rel='stylesheet' tyle="text/css">
  <style type="text/css">
    body { padding-top: 102px; }
  </style>
  <link href="<?php echo URL_ROOT ?>assets/css/bootstrap-responsive.css" rel="stylesheet">
  
  <!-- JavaScript/jQuery, Pre-DOM -->
  <script src="<?php echo URL_ROOT ?>js/jquery.min.js"></script> 
  <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/charts/excanvas.min.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/charts/jquery.flot.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/jquery.jpanelmenu.min.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/jquery.cookie.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/avocado-custom-predom.js"></script>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <!-- HTML5, for IE6-8 support of HTML5 elements -->
  <!--[if lt IE 9]>
    <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
 <script>
	function sendSMS(id,no){
		$.post( "ajax.php", { type: "smsBirthday" ,id: id ,no:no} , function( data ) {
			alert(data);
		});
	}
</script>
</head>

<!--<body style="background-image:url(<?php echo URL_ROOT ?>assets/img/school.png); background-repeat:repeat-x; background-position:bottom center;">-->
<body style="background-image:url(<?php echo URL_ROOT ?>assets/img/school.png); background-repeat:repeat-x; background-position:bottom center;padding:0px">
 <div class="navbar-inner login">
   <h3> <a class="brand" href="#"><i class="icon-leaf"></i>  <?php echo substr($LinksDetails["site_name"],0,50); ?></a></h3>
    </div>
  <?php
 /*$alerts=$db->getRows("select * from alert where school_id='".$_SESSION["admin"]["school_id"]."' and status=2 and DATE(alert_date) = CURDATE()");
if(is_array($alerts) && count($alerts)>0){
	?>
<script>
  $(function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
</script>
    <div id="dialog-message" style="display:none" title="Todays Alert"><?php
	foreach($alerts as $al){
		$stdetail=$db->getRow("select * from student where status=1 and  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$al["idno"]."'");
		$alt="<strong>Name :</strong> ".$stdetail["name"];
		$alt.="<br/> <strong>Father Name :</strong> ".$stdetail["fname"]; 
		$alt.="<br/> <strong>Class :</strong> ".$stdetail["class"];
		$alt.="<br/> <strong>Medium :</strong> ".$stdetail["medium"];
		$alt.="<br/> <strong>Mobile :</strong> ".$stdetail["mobile"];
		$alt.="<br/> <strong>Message :</strong> ".$al["msg"]; ?><hr/>
        <?php echo $alt; ?><?php
	}
	?></div><?php
}*/

?>
     <div class="container">
     	<!--<div style=" margin:0 auto; width:592px">--> 
        <!--<div class="alert alert-danger" role="alert" id="err1">User name or Password is incorrect..!</div>-->
        <div style="position: relative;float: left;padding: 15px;min-width:600px;margin:10px">
        
        	<h3 class="heading1">Easy <span>ERP</span></h3>
      		<h5 class="heading2">Easy ERP modules</h5>
                <ul class="listfront1">
               		 <li>Student Registration Module</li>
                     <li>Fee Collection module</li>
                     <li>Marksheet Module</li>
                     <li>Examination Module</li>
                     <li>Transfer Certificate Module</li>
                     <li>Student Alert Module</li>
                     <li>Identity Card Module</li>
                     <li>Staff Registration Module</li>
                     <li>Staff Salary Module</li>
                     <li>Attendence Module</li>
                     <li>Account Module</li>
                     <li>Library Module</li>
                 </ul>
                <ul class="listfront2">
               		 
                     
                     <li>Calender Management Module</li>
                     <li>Exam TimeTable Module</li>
                     <li>Class TimeTable Module</li>
                     <li>Transport Module</li>
                     <li>Hostel Module</li>
                     <li>Data Management Module</li>
                     <li>SMS Alert Module</li>
                     <li>Voice Calling Module</li>
                     <li>Report Section Module</li>
                     <li>Schedule & Reminder Module</li>
                     <li>CBSE Exam Pattern Module</li>
                     <li>BirthDay Module</li>
                </ul>
            </div>
            
         	<div style=" margin:0 auto; width:592px;padding-top:80px;">
            
      	<form class="form-login form-horizontal" style="display:inline-block" action="" method="post">
        <div class="top-bar">
          <h3><i class="icon-leaf"></i> <?php echo substr($LinksDetails["site_name"],0,35); ?></h3>
        </div>
        <div class="well no-padding" style="overflow:inherit">

          <div class="control-group">
            <label class="control-label" for="inputName"><i class="icon-user"></i></label>
            <div class="controls">
              <input type="text" id="inputName" name="username" placeholder="Username" value="<?php echo $_POST["username"] ?>">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputUsername"><i class="icon-key"></i></label>
            <div class="controls">
              <input type="password" name="password" id="inputUsername" placeholder="Password">
            </div>
          </div>
		<div class="control-group">
            <label class="control-label" for="session"><i class="icon-random"></i></label>
            <div class="controls">
                <select name="session" id="session">
                    <?php 
                        $class=$db->getRows("select * from session");
						if(is_array($class) && count($class)>0){
                        foreach($class as $cla){
                            ?>
                            <option <?php if($_POST && $cla["session"]==$_POST["session"])echo 'selected';?> value="<?php echo $cla["session"] ?>">
                                <?php echo $cla["session"] ?>
                            </option>
                            <?php
                        }
						}
                    ?>
                </select>
            </div>
        </div>
        <div class="padding">
          <button class="btn btn-danger" type="submit">Sign in</button>
          <button class="btn" type="button">Forgot Password</button>
          <?php 
          if($errorMessage!=""){
            echo "<div class='error'>$errorMessage</div>";
          }
          ?>
        </div>
        </div>
      </form>
      <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- top 728X90 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-3971326739074589"
     data-ad-slot="5802957354"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
    </div> 

</body>

	<!-- Javascript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src='<?php echo URL_ROOT ?>assets/js/jquery.hotkeys.js'></script>
	<script src='<?php echo URL_ROOT ?>assets/js/calendar/fullcalendar.min.js'></script>
	<script src="<?php echo URL_ROOT ?>assets/js/jquery-ui-1.10.2.custom.min.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/jquery.pajinate.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/jquery.prism.min.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/jquery.dataTables.min.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/charts/jquery.flot.time.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/charts/jquery.flot.pie.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/charts/jquery.flot.resize.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/bootstrap/bootstrap.min.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/bootstrap/bootstrap-wysiwyg.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/bootstrap/bootstrap-typeahead.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/jquery.easing.min.js"></script>
  <script src="<?php echo URL_ROOT ?>assets/js/jquery.chosen.min.js"></script>
	<script src="<?php echo URL_ROOT ?>assets/js/avocado-custom.js"></script> 
</html>