<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';

?>
<html>
<head>
	<title>Set Comm For All Retailers</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:;
			width:98%;
			margin:1%;
			padding:10px;
		}
		.div1 input, .div1 select{
			height:40px;
			width:180px;
			font-size:18px;
			padding:2px 10px;
			border-radius:5px;
			border:solid #6b5127 1px;
			overflow:hidden;
			margin:10px 10px 0 10px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			cursor:pointer;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#883333;
			border:solid #6b5127 1px;
			transition:1s;
		}
		.div2{
			background:#f7f7f7;
			width:100%;
			float:left;
			text-align:center;
			padding:0 10px;
			overflow:auto;
		}
		.div2 table{
			width:96%;
			text-align:center;
			font-size:16px;
			border-collapse:collapse;
			padding:2px 10px;
			margin:2%;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
			padding:2px 5px;
		}
		#inpDataList{display:none;}
		#commInp{width:70px; height:25px; padding:1px 4px; font-size:16px; text-align:center;}
		
		.fa-check, .fa-ban{font-size:20px;}
		@media(max-width:768px)
		{
			.div1{
				background:;
				width:100%;
				height:auto;
				margin:10px 0 0 0;
				padding:0;
				text-align:center;
			}
			.div1 input, .div1 select{
				width:90%;
				margin:10px;
			}
			.div2{
				width:100%;
				margin:10px 0 0 0;
				padding:0px;
				text-align:center;
			}
		}
	</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';
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>All Ret Set Comm :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
					<div class="div1">
					    <?php
						        if(isset($_POST['submit']))
						        {
						            $quGetRet="SELECT * FROM retailer WHERE Parentid='$userid'";
						            $reGetRet=mysqli_query($con,$quGetRet);
						            while($dataGetRet=mysqli_fetch_array($reGetRet))
						            {
						                $retId=$dataGetRet['Userid'];
						                
						                $quOp="SELECT * FROM operator";
								        $reOp=mysqli_query($con,$quOp);
								        while($dataOp=mysqli_fetch_array($reOp))
								        {
									        $sl=$sl+1;
									        $opName=$dataOp['Operator'];
									        $OPCode=$dataOp['OwnApiCode'];
									        
									        $inpComm=$_POST[$OPCode];
									        
									        if(!empty($inpComm))
									        {
									            $quUpdateComm="UPDATE CommSlab SET Comm='$inpComm' WHERE Userid='$retId' AND OpCode='$OPCode'";
									            mysqli_query($con,$quUpdateComm);
									        }
									        elseif($inpComm=="0")
									        {
									            $quUpdateComm="UPDATE CommSlab SET Comm='$inpComm' WHERE Userid='$retId' AND OpCode='$OPCode'";
									            mysqli_query($con,$quUpdateComm);
									        }
								        }
								
						            }
						            
						            echo "<div class='msg-div'>
				                            <form method='post'>
					                            <h3>Commission Set Successfully !</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>";
						            
						        }
						        
						        
						    ?>
					
				<form method="post">	
						<input type="submit" name="submit" value="Set Commission"  onclick='showLoader()'>
					</div>
				<div class="div2" id="downlinePlace">
					<table cellpadding="20" border="2"> 
						<tr>
							<th>Sl.</th>
							<th>Op. Name</th>
							<th>My Comm</th>
							<th>Ret. Comm.</th>
						</tr>
						<?php
								$quOp="SELECT * FROM operator";
								$reOp=mysqli_query($con,$quOp);
								while($dataOp=mysqli_fetch_array($reOp))
								{
									$sl=$sl+1;
									$opName=$dataOp['Operator'];
									$OPCode=$dataOp['OwnApiCode'];
									
									$quSelfComm="SELECT * FROM CommSlab WHERE Userid='$userid' AND OpCode='$OPCode'";
									$reSelfComm=mysqli_query($con,$quSelfComm);
									$dataSelfComm=mysqli_fetch_array($reSelfComm);
									$myComm=$dataSelfComm['Comm'];
									
									echo "<tr>";
										echo "<td>".$sl."</td>";
										echo "<td>".$opName."</td>";
										echo "<td>".$myComm."</td>";
										echo "<td><input type='number' id='commInp' name='".$OPCode."' step='0.01'></td>";
									echo "</tr>";
								}
							
						?>
					</table>
				</div>
				</form>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>