
<?php session_start();
 
?>
<html>
<head><title>Login Check</title>

<?php include('main/core/connect.php');

$result_elf = $dbh->prepare("select * from scrap where type='pathtorivendell'");
$result_elf->execute();
$row_elf  = $result_elf->fetchObject();
$systempath=$row_elf->item;

//path to complete system path including /pages
$result_dir = $dbh->prepare("select * from scrap where type='elvenpath'");
$result_dir->execute();
$row_dir  = $result_dir->fetchObject();
$systemdir=$row_dir->item;

?>

 <link href='<?php echo $systemdir; ?>/css/bootstrap.min.css' rel='stylesheet'>
	 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script>
function goBack() {
 window.history.back();
}
</script>
</head>
<body>

<?php include('main/core/includes.php');
 similar_text($mencdna,$dnaneed,$percentagekufanagana);

 $mypassword=$_POST['mypassword'];
 $myusername=$_POST['myusername'];
$wasgoinghere="";
 $myusername = stripslashes($myusername);
 $mypassword = stripslashes($mypassword);
 $result = $dbh->query("SELECT * FROM users WHERE username='$myusername' and password='$mypassword'");
 $row = $result->fetchObject();
 $count=$result->rowCount();
 if($count==1){ include ('main/core/connect.php');
 $ip_ad=$_SERVER['REMOTE_ADDR'];
 $previouspage=$_SERVER['HTTP_REFERER'];
 $kbrowser=$_SERVER['HTTP_USER_AGENT'];
 $currentpage=$_SERVER['SCRIPT_NAME'];
 $stage = "40";
 $activity = "Log in";
 $userid = $row->rolenumber;
 $insertactivity = $dbh->exec("insert into useractivity (activity,userid,deviceid,browser,previouspage,currentpage,stage) 
	values('$activity','$userid','$ip_ad','$kbrowser','$previouspage','$currentpage','$stage')");
 $_SESSION["username"] = $myusername;
 $_SESSION["password"] = $mypassword;
 $_SESSION["firstname"]= $row->firstname;
 $_SESSION["lastname"]= $row->lastname;
 $_SESSION["role"] = $row->role;
 $_SESSION["adminid"] = $row->adminid;
 $_SESSION["rolenumber"] = $row->rolenumber;
 if ($wasgoinghere!==""){echo "<script>window.location='".$wasgoinghere."'</script>";
 } else { $finalrole = $_SESSION["role"];
 if(($finalrole == "priadmin")||($finalrole == "secadmin")||($finalrole == "overadmin")){$roleoutput = "admin";
} elseif(($finalrole == "priaccount")||($finalrole == "secaccount")){$roleoutput = "bursar";
} elseif(($finalrole == "priaccount2")||($finalrole == "secaccount2")){$roleoutput = "bursar";
} else{$roleoutput = "tech";
} echo "<script>window.location='main/gentools/".$roleoutput.".php".$wasgoinghere."'</script>";
} }else { include ('main/core/connect.php');
 $ip_ad=$_SERVER['REMOTE_ADDR'];
 $previouspage=$_SERVER['HTTP_REFERER'];
 $kbrowser=$_SERVER['HTTP_USER_AGENT'];
 $currentpage=$_SERVER['SCRIPT_NAME'];
 $stage = "-1";
 $activity = "Wrong username or password";
 $userid = "";
 $insertactivity = $dbh->exec("insert into useractivity (activity,userid,deviceid,browser,previouspage,currentpage,stage) 
	values('$activity','$userid','$ip_ad','$kbrowser','$previouspage','$currentpage','$stage')");
 echo "
<div style='margin-left:30%;
' class='col-lg-4'>
			<div class='panel-body'>
<div class='panel panel-danger'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Alert..!!!</h3></div>
<div style='text-align:center;
' class='panel-body'>";
 include ("main/core/connect.php");
 $result100 = $dbh->query("select * from scrap where type='title'");
 $row100 = $result100->fetchObject();
 echo "<strong>".$row100->item."</strong>";
 echo "
<br><br>
			Wrong Username or Password......<br>
			<a style='float:left;
' class='btn btn-danger' href='index.php'>Back</a>
			</div>
			</div>
			</div>
			</div>";
} 
?>
<script src="<?php echo $systemdir; ?>/js/bootstrap.min.js"></script>
 <script src="<?php echo $systemdir; ?>/js/jquery-1.8.3.min.js"></script>
</body>
</html>