<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Add API</title>
	<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
	<link rel="icon" href="images/logo.png" type="image/gif" sizes="16x16">
	
	<!-- Admin CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- User JAVA SCRIPT File Link -->
	<script type="text/javascript" src="js/script.js"></script>
	
	<!-- Font Awesome Icone -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	
	<style>
		.div1{
			background:#f7f7f7;
			width:50%;
			height:550px;
			float:left;
			text-align:center;
		}
		.div1 table{
			width:94%;
			text-align:center;
			font-size:17px;
			border-collapse:collapse;
			margin:10px;
			padding:2px 10px;
		}
		.div1 hr{
			margin:5px 10px;
			padding:0 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
		}
		.div1 hr{width:94%;}
		.div1 input, .div1 select{
			width:94%;
			height:45px;
			margin:8px;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:17px;
		}
		input[type=file]
		{
			border:none;
		}
		.div1 textarea{
			width:94%;
			height:100px;
			margin:10px 0;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:19px;
		}
		.divImg{
			background:white;
			width:94%;
			height:100px;
			margin:10 15px;
			padding:8px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:19px;
			text-align:left;
		}
		.divImg img{
			width:19%;
			height:80px;
			float:left;
		}
		.divImg input{
			width:70%;
			float:right;
			font-size:15px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			font-size:30px;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			border:1px solid #6b5127;
			cursor:pointer;
			transition:1s;
		}
		
		@media(max-width:768px)
		{
			.div1{
				width:100%;
				height:auto;
			}
			.nav,.container{
				height:auto;
			}
		}
	</style>
	<link rel="stylesheet" href="css/mediaStyle.css">
</head>
<body>
	<!--Header Divison-->
	<?php
		require'header.php';
	?>
	
	<!--Container Division-->
	<div class="container">
<?php
	include'menu.php';
	if(isset($_POST['submit']))
	{
	    if(empty($ApiName))
        {
            echo "<div class='msg-div'>
			            <form method='post'>
				            <h3>Please Insert User's Name !</h3><br>
				            <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				            <button type='submit' class='btnPopup'>OK</button><br><br>
			            </form>
		            </div>";
        }
        else
        {   
            $query = "INSERT INTO api(Date,ApiName,ApiUsrId,ApiToken,Api_IP)
			values('$date','$ApiName','$ApiUsrId','$ApiToken','$Api_IP')";
			if(mysqli_query($con,$query))
			{   
			        echo "<div class='msg-div'>
				        <form method='post'>
					        <h3>Registration Successfully !</h3><br>
					        <h3>Userid : ".$newUsrid."</h3><br>
					        <h3>Password : ".$pwd."</h3><br>
					        <i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
					        <button type='submit' class='btnPopup'>OK</button><br><br>
				        </form>
		            </div>";
			}
			else
			{
			    echo "<div class='msg-div'>
			            <form method='post'>
				            <h3>Something Error !</h3><br>
				            <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				            <button type='submit' class='btnPopup'>OK</button><br><br>
			            </form>
		            </div>";
			}
		}
	}
?>
		<div class="content">
			<input type="text" style="display:none;" value="<?php echo $userid; ?>" id="user">
			<div class="head">
				<div class="title"><p>Add API :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
					    <?php
					        $quOP="SELECT * FROM operator";
					        
						    echo "<input type='text' name='ApiName' placeholder='Api Name ...'  required>";
						    echo "<input type='submit' name='submit' value='Submit' onclick='showLoader()'>";
						?>
					</div>
				<div class="div1">
					<center><h1>Recent Added</h1></center><hr>
					<table cellpadding="20" border="2">
						<tr>
							<th>Api Name</th>
							<th>Userid</th>
							<th>Api Ip</th>
							<th>Status</th>
						</tr>
						<?php
							$quGetTxn="SELECT * FROM api ORDER BY Id DESC LIMIT 10";
							$reGetTxn=mysqli_query($con,$quGetTxn);
							while($dataGetTxn=mysqli_fetch_array($reGetTxn))
							{
								echo "<tr>";
									echo "<td>".$dataGetTxn['ApiName']."</td>";
									echo "<td>".$dataGetTxn['ApiUsrId']."</td>";
									echo "<td>".$dataGetTxn['Api_IP']."</td>";
									echo "<td>".$dataGetTxn['Status']."</td>";
								echo "</tr>";
							}
						?>
					</table>
				</div>
				</form>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>