<?php 
session_start();
$host = 'localhost';
$username = 'mdsoftwareco_rns';
$password = 'w&S8zzGMx]QI';
$database = 'mdsoftwareco_rns';
$dbconfig = mysqli_connect($host,$username,$password,$database);
if($_SERVER["REQUEST_METHOD"] == "POST")
 {
// username and password received from loginform 
$username=mysqli_real_escape_string($dbconfig,$_POST['username']);
$password=mysqli_real_escape_string($dbconfig,$_POST['password']);
$type=mysqli_real_escape_string($dbconfig,$_POST['type']);
$code=$_POST['code'];
$session=$_POST['session'];

$sql_query="SELECT id FROM user WHERE username='$username' and password='$password' and type='$type' and code='$code'";
$result=mysqli_query($dbconfig,$sql_query);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
echo $count=mysqli_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count!="")
{
$_SESSION['login_user']=$username;
$_SESSION['login_type']=$type;
$_SESSION['code']=$code;
$_SESSION['session']=$session;
$browser=$_SERVER['HTTP_USER_AGENT'];
$user_ip = $_SERVER['REMOTE_ADDR'];
$url=$_SERVER['HTTP_REFERER'];
$username = $_POST['username'];
$pass = $_POST['password'];
$code = $_POST['code'];
$session = $_POST['session'];
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Kolkata');
}

$sql_insert = "INSERT into `track_login` (username,pass,code,session,ip,browser,status,url,details)VALUES('$username','$pass','$code','$session','$user_ip','$browser','Sucess','$url','Success')";
mysqli_query($dbconfig,$sql_insert) or die("Insertion Failed:" . mysqli_error());

header("location: welcome-home.php");
?>
<script type="text/javascript">

   	// Javascript URL redirection

    window.location.replace("welcome-home.php");

</script><?php /*?>
<script type="text/javascript">
   window.open('welcome-home.php','College Management Software',' menubar=0, resizable=0,dependent=0,status=0,width=1000,height=900,left=10,top=10')
</script><?php */?>
<?php
}
else
{
$browser=$_SERVER['HTTP_USER_AGENT'];
$user_ip = $_SERVER['REMOTE_ADDR'];
$url=$_SERVER['HTTP_REFERER'];
$username = $_POST['username'];
$pass = $_POST['password'];
$code = $_POST['code'];
$session = $_POST['session'];
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Kolkata');
}
$dt=date('Y-m-d H:i:sP');
$sql_insert = "INSERT into `track_login` (username,pass,code,session,ip,browser,status,url,details)VALUES('$username','$pass','$code','$session','$user_ip','$browser','Fail','$url','Login Error')";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());

$error="Username or Password is invalid";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<title>Advance College Management System - Developed By MD SOFTWARE - Faizabad</title>
<style>
body {
    background-size: cover;
    font-family: Montserrat;
	
	
	margin: 0;
			padding: 0;
			height: 100%;
			
			background: url(login_bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.logo {
    width: 213px;
    height: 36px;
    margin: 30px auto;
}

.login-block {
    width: 320px;
    padding: 20px;
    background: #003399;
    border-radius: 5px;
    border-top: 5px solid #ff656c;
    margin: 0 auto;
}

.login-block h1 {
    text-align: center;
    color: #000;
    font-size: 18px;
    text-transform: uppercase;
    margin-top: 0;
    margin-bottom: 20px;
}

.login-block input{
    width: 100%;
    height: 42px;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    font-size: 14px;
    font-family: Montserrat;
    padding: 0 20px 0 50px;
    outline: none;
}
.login-block select{
    width: 100%;
    height: 42px;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    font-size: 14px;
    font-family: Montserrat;
    padding: 0 20px 0 50px;
    outline: none;
}

.login-block select#type{
     background: #fff url('u0XmBmv.png') 20px top no-repeat;
    background-size: 16px 80px;
}
.login-block select#type:focus{
     background: #fff url('u0XmBmv.png') 20px bottom no-repeat;
    background-size: 16px 80px;
}

.login-block input#username {
    background: #fff url('u0XmBmv.png') 20px top no-repeat;
    background-size: 16px 80px;
}

.login-block input#username:focus {
    background: #fff url('u0XmBmv.png') 20px bottom no-repeat;
    background-size: 16px 80px;
}

.login-block input#password {
    background: #fff url('Qf83FTt.png') 20px top no-repeat;
    background-size: 16px 80px;
}

.login-block input#password:focus {
    background: #fff url('Qf83FTt.png') 20px bottom no-repeat;
    background-size: 16px 80px;
}

.login-block input:active, .login-block input:focus {
    border: 1px solid #ff656c;
}

.login-block button {
    width: 100%;
    height: 40px;
    background: #ff656c;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #e15960;
    color: #fff;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 14px;
    font-family: Montserrat;
    outline: none;
    cursor: pointer;
}

.login-block button:hover {
    background: #ff7b81;
}

</style><script language="javascript" type="text/javascript">document.oncontextmenu = function() {
  return false;
}</script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
document.onkeydown = function(e) {
        if (e.ctrlKey && 
            (e.keyCode === 67 || 
             e.keyCode === 86 || 
             e.keyCode === 85 || 
             e.keyCode === 117)) {
            return false;
        } else {
            return true;
        }
};
$(document).keypress("u",function(e) {
  if(e.ctrlKey)
  {
return false;
}
else
{
return true;
}
});
$(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
}); 

// Prevent F12      
$(document).keydown(function (event) {
    if (event.keyCode == 123) { // Prevent F12
        return false;
    } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // Prevent Ctrl+Shift+I        
        return false;
    }
});

//stop copy of content
function killCopy(e){
    return false
}
function reEnable(){
    return true
}
document.onselectstart=new Function ("return false")
    if (window.sidebar){
    document.onmousedown=killCopy
    document.onclick=reEnable
}

// prevent ctrl + s
$(document).bind('keydown', function(e) {
  if(e.ctrlKey && (e.which == 83)) {
    e.preventDefault();
    return false;
  }
});
$(window).bind('keydown', 'ctrl+s', function () {
      $('#save').click(); return false;
  });var message="Function Disabled!"; 
     function clickIE4()
       if(event.button==2){
          alert(message);
          return false; 
       }
    } 
    function clickNS4(e){
      if(document.layers||document.getElementById&&!document.all){
        if (e.which==2||e.which==3){  
          alert(message);
          return false; 
        } 
     } 
   } 
   if (document.layers){  
     document.captureEvents(Event.MOUSEDOWN);
     document.onmousedown=clickNS4;
   } 
   else if(document.all&&!document.getElementById){
       document.onmousedown=clickIE4; 
   }  
   document.oncontextmenu=new Function("alert(message);return false")
document.onkeydown = function(e) {
  if(event.keyCode == 123) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
     return false;
  }
  if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
     return false;
  }
    if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)) {
     return false;
  }
}
</script>
</head>

<body>
<?php
	 
$sql_query="SELECT * FROM news order by id ASC";
$result=mysqli_query($dbconfig,$sql_query);

?>
<marquee behavior="scroll" direction="left" bgcolor="#FFFFFF" style="padding-top:5px; padding-bottom:5px;"><span style="color:#FF0000; font-weight:bold;">
<?php
while ( $a_row=mysqli_fetch_array($result,MYSQLI_ASSOC) )
 {?>
||
 <?php echo $a_row['name']; ?>
 <?php } ?> || </span></marquee>
<br/>
<div class="login-block">
    <h1 style="color:#FFFFFF">Login : Portal C.M.S.</h1>
    <?php if($error!=""){?>
    <p style="color:#FF0000; text-align:center;"><?php echo $error; ?></p>
    <?php } ?>
    <?php $codet=$_GET['codet']; if($codet==""){?>
     
    <form method="get" action="" name="loginform">
    <input type="number" value="" placeholder="College code" id="code" name="codet" required />
    <button type="submit">Proceed</button>
    </form>
    <h1 style="color:#FFFFFF">Developed By : <a href="http://www.mdsoftech.com/" target="_blank" style="color:#FFFFFF">MD SOFTWARE</a></h1>
       <h1 style="color:#FF0000">Help : 8004902000</h1>
	<?php }else{  
	$sql_query="SELECT * FROM session where code='$codet'";
$result=mysqli_query($dbconfig,$sql_query);
$numrows=mysqli_num_rows($result);
$sql_queryr="SELECT * FROM suspended where code='$codet'";
$resultr=mysqli_query($dbconfig,$sql_queryr);
$numrowsr=mysqli_num_rows($resultr);
$a_rowr = mysqli_fetch_row($resultr);
$status=$a_rowr[2];
	?>
    <a href="login.php">
     <button type="button">Back : Enter College Code</button>
    </a>
    <?php if($status==$codet){ ?>
    <br/><br/>
    <h1 style="color:#FFFFFF"><?php echo $a_rowr[1]; ?></h1>
    <br/><br/>
    <?php }elseif($numrows!=""){ ?>
    <form method="post" action="" name="loginform">
    <select name="session" required>
    <option value="">Session</option>
    <?php
while ( $a_row = mysqli_fetch_row( $result ) )
 {?>
    <option value="<?php echo $a_row[1]; ?>"><?php echo $a_row[1]; ?></option>
    <?php }?>
    </select>
    
    <input type="number" readonly placeholder="College code" id="code" name="code" required value="<?php echo $codet; ?>" />
    
    <input type="text" value="" placeholder="Username" id="username" name="username" required />
    <input type="password" value="" placeholder="Password" id="password" name="password" required/>
   <select name="type" required id='type'>
   <option value="">Select</option>
    <option value="admin">Administrative</option>
    <option value="counter">College Counter</option>
    <option value="teacher">Teachers - Login</option></select>
    <button type="submit">Submit</button>
    </form>
    <?php }else{ ?><br/><br/>
    <h1 style="color:#FF0000">Your College not Register in our System.<span style="color:#FFFFFF">Please Enter Correct College Code..</span></h1>
    <br/><br/>
    <?php } ?>
    <h1 style="color:#FFFFFF">Developed By : <a href="http://www.mdsoftech.com/" target="_blank" style="color:#FFFFFF">MD SOFTWARE</a></h1>
       <h1 style="color:#FF0000">Help : 8004902000</h1>
       <?php } ?>
</div>
</body>

</html>