<?php
include_once"include/db.php";
				
?>
<html dir="ltr" lang="en"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="robots" content="noindex,nofollow">
    <title>Discounts | Travelobien</title>
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="css/style.min.css" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.searchBx .fleft{
 float:left;
 padding-bottom:35px;
 margin-left:1%;
}
.searchBx .fleft input{
 border:1px solid #999;
 padding:4px;
}
.searchBx .fleft select{
 border:1px solid #999;
 padding:4px;
}
.searchBx .fleft span{
	font-weight:600;
}
.searchBx .fleft button{
 margin:18px 25px;	
}
.card{
	position:relative;
	top:-190px;
}
.card input{
	border:1px solid #999;
	padding:4px;
	background:#eee;
}
.fa-trash{
	color:#ff0000 !important;
}
#datas #success{color:green;font-size:16px;}
#datas #fail{color:#ff0000;font-size:16px;}
</style>
</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <div class="preloader" style="display: none;">
        <div class="lds-ripple">
            <div class="lds-pos"></div>
            <div class="lds-pos"></div>
        </div>
    </div>
   
    <div id="main-wrapper" data-layout="vertical" data-navbarbg="skin5" data-sidebartype="full" data-sidebar-position="absolute" data-header-position="absolute" data-boxed-layout="full">
        
      <?php include"include/header.php"; ?>
        
        <div class="page-wrapper">
            <div class="page-breadcrumb">
                <div class="row align-items-center">
                    <div class="col-md-6 col-8 align-self-center">
                        <h3 class="page-title mb-0 p-0">Discounts</h3>
                        <div class="d-flex align-items-center">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                                    <li class="breadcrumb-item active" aria-current="page">Discount</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                   
                </div>
            </div>
            
           
            <div class="container-fluid" id="datas">
                <div class="row">
				 <div class="col-lg-12 searchBx" style="background:white;">
				 <form action="" method="post">
				 <br>
				 <h2>Add Discounts</h2>
				<?php
				/*$price = '500';
				$amount = '10';
				$newprice = round($price * ((100 - $amount) / 100), 2);
				echo $newprice;*/
				?>
				  <center>
				  <span id="success"><?php echo @$_GET['success']; ?></span>
				  <span id="fail"><?php echo @$_GET['fail']; ?></span>
				  </center>
				 <div class="clearfix"></div><hr><br>
				 
				 <div class="clearfix"></div>
					<div class="col-md-3 fleft">
					    <span>Enter Class</span>
						<input type="text" name="class" placeholder="Enter Class" class="form-control">
					</div>
					<div class="col-md-3 fleft">
					    <span>Enter Discount(%)</span>
						<input type="text" name="discount" placeholder="Enter Discount" class="form-control">
					</div>
					
					
					<div class="col-md-2 fleft">
                    <button type="submit" name="submit" class="btn btn-danger d-none d-md-inline-block text-white">
					SUBMIT
                    </button>
                        </div>
				 </form>
				 </div>
			</div>
			</div>
			<?php
			    
				if(isset($_POST['submit'])){
					$class    = $_POST['class'];
					$discount = $_POST['discount'];
					
					$checkCode = "SELECT * FROM discounts_by_class WHERE class='$class'";
					$queryCode = mysqli_query($conn, $checkCode);
					$codes      = mysqli_num_rows($queryCode);
					if($codes == 1){
					echo "<script>alert('This Class Already Exists..Enter Another Class')</script>";
					echo "<script>window.open('discounts','_self')</script>";
					exit();
					}
					
					$insert = "INSERT INTO discounts_by_class(class,discount)VALUES('$class','$discount')";
					
					$query = mysqli_query($conn, $insert);
					if($query){
					echo"<script>window.open('discounts?success=Data Submitted Successfully','_self')</script>";
					}else{
					echo"<script>window.open('discounts?fail=Something went wrong..try again','_self')</script>";	
					}
				
				}
			?>
               
                    <!-- column -->
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-body">
                                
                                <div class="table-responsive">
                                    <table class="table user-table">
                                        <thead>
                                            <tr>
                                                <th>S.No</th>
                                                <th>Class</th>
                                                <th>Discount(%)</th>
												<th>Action</th>
												 
                                            </tr>
                                        </thead>
                                        <tbody>
										<?php
										$i=1;
										$selectClass = "SELECT * FROM discounts_by_class";
										$classQuery  = mysqli_query($conn, $selectClass);
										while($dis = mysqli_fetch_array($classQuery)){	
										$id       = $dis['id'];
										$class    = $dis['class'];
										$discount = $dis['discount'];
										
												
										?>
                                            <tr>
                                                <td><?php echo $i++; ?></td>
                                                <td><?php echo $class; ?></td>
                                                <td><?php echo $discount; ?>%</td>
												<td><a href="delete_data?delClass=<?php echo $id; ?>"><i class="fa fa-trash"></i></a></td>
                                            </tr>
										<?php } ?> 
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
              
                
           
            <footer class="footer"> © 2022 | Travelobien.com</a>
            </footer>
           
        </div>
      
    </div>
    <script src="assets/plugins/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/plugins/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="js/app-style-switcher.js"></script>
    <!--Wave Effects -->
    <script src="js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="js/custom.js"></script>


</body></html>