<?php
include('../config/setup.php'); 

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
    $action = $_POST['action'];

// logo_master
    // logo update query starts
    if($action == 'edit'){
        $id = $_POST['id'];
        $key = $_POST['key'];
        $token = $_POST['token'];
        $status = $_POST['status'];
        
        $sql = "UPDATE payment_settings SET payment_key = '$key' , payment_token = '$token', status = '$status' WHERE id = '$id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Updated successfully" ;
            $_SESSION['alert'] = "success" ;
        }else{
            $_SESSION['status'] = "Update Failed" ;
            $_SESSION['alert'] = "success" ;
        }
    }
    // logo update query ends

}


?>
<?php include "head.php" ?>

	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php');?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php');?>
			 <!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php');?>
		
		
		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title">Online Payment Settings</h4> 
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-body">
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover" >
											<thead>
												<tr>
													<th>S.No</th>
													<th>Payment Gateway</th>
													<!--<th>Payment API Key</th>-->
													<!--<th>Payment Token</th>-->
													<th>Status</th>
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
												<?php 
												    $sno = 1;
													$sql = "SELECT * FROM payment_settings ";
													$res = $config->query($sql);
													while($row = $res->fetch_assoc()){
													$status = $row['status'];
												?>
												<tr>
													<td><?= $sno; ?></td>
													<td><?= $row['payment_gateway'] ?></td>
													<!--<td><?= $row['payment_key'] ?></td>-->
													<!--<td><?= $row['payment_token'] ?></td>-->
												    <td>
													    <?php if($status == 1){ ?>
													    <button class="btn btn-success">Active</button>
													    <?php }else{ ?>
													        <button class="btn btn-danger">In-Active</button>
													    <?php } ?>
                                                    </td>
													<td>
													    <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#edit<?= $row['id'] ?>"> <i class="fas fa-pencil-alt"></i>  </a>
                                                    </td>

                                                    <!-- Modal -->
                                                    <div class="modal fade" id="edit<?= $row['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                        <div class="modal-dialog" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="exampleModalLabel">Edit</h5>
                                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">&times;</span>
                                                                    </button>
                                                                </div>
                                                                <div class="modal-body">
                                                            	    <form method="post" enctype="multipart/form-data">
                                                                        <div class="form-group">
                                                            			    <label for="logo_name">Payment Gateway</label>
                                                            			    <input type="text" class="form-control" id="logo_name" name="logo_name"  value="<?= $row['payment_gateway'] ?>" readonly>
                                                            			    <input type="hidden" class="form-control" id="id" name="id" value="<?= $row['id'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="key">Payment API Key</label>
                                                            			    <input type="text" class="form-control" id="key" name="key"  value="<?= $row['payment_key'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="token">Payment Token</label>
                                                            			    <input type="text" class="form-control" id="token" name="token"  value="<?= $row['payment_token'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                        												    <label for="status">Status</label>
                        												    <select class="form-control" id="status" name="status">
                        												    <?php if($status == 1){ ?>
                            													<option value="1" selected>Active</option>
                            													<option value="0">In-Active</option>
                        													<?php }else{?>
                            													<option value="0" selected>In-Active</option>
                            													<option value="1" >Active</option>
                        													<?php } ?>
                            												</select>
                            											</div>	
                                                                        <div class="form-group">
                                        									<input type="hidden" name="action" value="edit">
                                        									<button class="btn btn-warning" type="submit" name="submit">Submit</button>
                                         								</div>
                                                        		    </form>	
                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </tr>
                                                <?php } ?>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
	                </div>
				</div>
			</div>
		<?php include('footer.php');?>	
		 
		</div>
		<!-- End Custom template -->
	</div>
	<script>
	<?php if(isset($_SESSION['status']) && !empty($_SESSION['status'])){ ?>
	    swal({
          title: "<?= $_SESSION['status'] ?>",
          text: "",
          icon: "<?= $_SESSION['alert'] ?>",
        });
    <?php unset($_SESSION['status']); } ?>
	</script>
	<!--   Core JS Files   -->
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>
	
	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script >
		$(document).ready(function() {
			$('#basic-datatables').DataTable({
			});

		 
 
			 
		});
	</script>
</body>
</html>