<?php
    session_start();
    if(isset($_SESSION['user_id']) && isset($_SESSION['user_name']) && $_SESSION['user_cate'] === "user"){
        $user_id = $_SESSION['user_id'] ;
        $username = $_SESSION['user_name'] ;
        $email = $_SESSION['user_email'] ;
        $phone = $_SESSION['user_phone'] ;
        // $ticket = $_SESSION['last_ticket'] ;
        // $company = $_SESSION['company'] ;
        $user_image = $_SESSION['user_image'] ;
    }else{
        header("Location:login.php") ;
    }
?>
<?php 
    if(isset($_POST['event_id']) || isset($_GET['event_id'])){
        $event_id = $_POST['event_id'];
    }
    else{
        header("Location:dashboard.php") ;
    }
?> 
<?php include "head.php" ; ?>
<?php
    $sql = $config->query("SELECT * FROM event_post WHERE e_status = 2 AND event_id = '$event_id' ") ;
    if($sql){
        $row = $sql->fetch_assoc();
        $title = $row['e_title'];
        $v_id = $row['vendor_id'];
        $event_id = $row['event_id'];
        $entry = $row['entry'];
        $entry_fees = $row['entry_fees'];
        $entry_type = explode(',',$row['entry_type']);
        $m_entry = explode(',',$row['m_entry_fees']);
    }else{
        
    }
?>
<style>
    .event-box img {
        height: 300px;
        width: 100%;
    }
    .event-title {
        font-weight: 500;
        color: #4b94e5;
        /*width: 40%;*/
    }
    .event-para {
        /*width: 60%;*/
        margin-left: 10px;
    }
</style>
<body>
	<!-- Main Wrapper -->

	<div class="main-wrapper">

		<!-- Header -->

		<?php include "header.php" ; ?>

		<!-- /Header -->
	<body>

		
			<!-- Breadcrumb -->
			<?php include "breadcrumbuser.php" ; ?>
			<!-- /Breadcrumb -->
			
			<!-- Page Content -->
			<div class="content">
				<div class="container-fluid">

					<div class="row">
						<div class="col-md-5 col-lg-4 col-xl-3 theiaStickySidebar">
							
							<!-- Profile Sidebar -->
							<?php include "sidebar.php" ; ?>
							<!-- /Profile Sidebar -->
							
						</div>
						
						<div class="col-md-7 col-lg-8 col-xl-9">
							<div class="row">
								<div class="col-md-12 card shadow event-box">
                                    <div class="p-3 h4"><?= $title ?></div>
                                    <div class="card-body row p-0">
                                        <div class="table-responsive">
    										<table class="table table-hover table-center mb-0">
    											<thead>
    												<tr>
    													<th>S.No</th>
    													<th>Name</th>
    													<th>Age </th>
    													<th>Category</th>
    													<th>Amount</th>
    												</tr>
    											</thead>
    											<tbody>
    											    <?php
    											        $sno = 1;
     											        $ply_sql = "SELECT * FROM players WHERE user_id = '$user_id' " ;
    											        $ply_res = $config->query($ply_sql);
       											        while($ply = $ply_res->fetch_assoc()){
       											            $dob = new DateTime(date('d-m-Y',strtotime($ply['dob'])));
                                                            $now = new DateTime();  // current date
                                                            $diff = $now->diff($dob);
        											        $age = $diff->y;
      										        ?>
    												<tr>
    													<td><input type="checkbox" class="form-check selectPlayer" name="player" value="<?= $ply['id'] ?>" onclick="selectPr(<?= $ply['id'] ?>,<?= $entry_fees ?>)"></td>
    													<td><?= $ply['name'] ?></td>
    													<td><?= $age ?></td>
    													<td>
    													    <?php if($entry == 'multi'){ ?>
													        <select class="form-control" name="cate" id="cate" style="border: none;border-bottom: 1px solid #b8c1a7;border-radius: unset !important;">
													        <?php foreach($entry_type as $val){ ?>
													            <option value="<?= $val ?>"><?= $val ?></option>
													        <?php } ?>
													        </select>
													        <?php }else if($entry == 'paid'){ ?>
													        <span class="text-success">Rs. <?= $entry_fees ?> /-</span>
													        <?php }else if($entry == 'free'){ ?>
													        <span class="text-success">Free</span>
													        <?php } ?>
    													</td>
    													<td id="amount<?= $ply['id'] ?>"></td>
    												</tr>
    												<?php $sno++; } ?>
    											</tbody>
    										</table>		
    									</div>
                                    </div>
								</div>
								<div class="col-md-12 card shadow event-box">
                                    <div class="p-3 h4 text-center">Total Amount</div>
                                    <div class="card-body row flex-column align-items-center justify-content-center">
                                        <div id="total_amount" class="text-center my-3" style="font-size: 24px;font-weight: 500;"></div>
                                        <!--<form action="payment.php" method="POST">-->
                                            <button type="button" class="btn btn-info disabled" data-toggle="modal" data-target="#apply_tour" id="apply">Apply</button>
                                        <!--</form>-->
                                    </div>
								</div>
							</div>
						</div>
					</div>
				</div>

			</div>	
			<?php if($entry == 'paid'){ ?>
			<input type="hidden" name="paid_entry" id="paid_entry" value="<?= $entry_fees ?>"> 
			<?php } ?>
			<!-- /Page Content -->
   	<!-- Footer -->

		<?php include "footer.php" ; ?>

		<!-- /Footer -->
	</div>

	<!-- /Main Wrapper -->
	<div class="modal fade custom-modal" id="apply_tour">
		<div class="modal-dialog modal-dialog-centered">
			<div class="modal-content">
				<div class="modal-header flex-column" style="padding-bottom:0;">
					<h5 class="modal-title text-capitalize">Pay Now</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
				    <div class="d-flex justify-content-center align-items-center my-3" style="column-gap: 10px;">
				        <img class="img-fluid" src="assets/img/rupee.png" style="width: 50px;">
				        <p style="font-weight: 600;font-size: 35px;margin-bottom: 0;" id="pay_amount"></p>
				    </div>
				    <div class="d-flex justify-content-center align-items-center" style="gap: 15px;">
    				    <!--<form action="payment.php" method="POST">-->
    				        <input type="hidden" name="wallet_amount" id="wallet_amount" value="<?= $row['total_amount'] ?>">
                            <button type="button" class="btn btn-primary" name="apply" id="wallet-apply"><i class="fas fa-wallet"></i> Wallet</button>
                        <!--</form>-->
    				    <form action="payment.php" method="POST">
                            <button type="button" class="btn btn-success" name="apply" id="apply"><i class="fas fa-money-check"></i> Pay Online</button>
                        </form>
				    </div>
				</div>
			</div>
		</div>
	</div>
	<!--Topup Wallet-->
	<div class="modal fade custom-modal" id="topup_wallet">
		<div class="modal-dialog modal-dialog-centered">
			<div class="modal-content">
				<div class="flex-column" style="padding-bottom:0;">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
				    <div class="d-flex align-items-center flex-column my-3">
				        <img class="img-fluid" src="assets/img/exclamation.png" style="width: 50px;">
				        <p style="font-weight: 600;font-size: 18px;margin-bottom: 0;">Your Wallet Balance Is Low.</p>
				    </div>
                    <div class="d-flex justify-content-center" style="gap: 15px;">
                        <button type="button" class="btn btn-primary" data-target="#buypack" data-toggle="modal" onclick="mclose()"><i class="fas fa-wallet"></i>TopUp Wallet</button>
    				    <form action="payment.php" method="POST">
                            <button type="button" class="btn btn-success" name="apply" id="apply"><i class="fas fa-money-check"></i> Pay Online</button>
                        </form>
                    </div>
				</div>
			</div>
		</div>
	</div>
	<!-- Appointment Details Modal -->
	<div class="modal fade custom-modal" id="buypack">
		<div class="modal-dialog modal-dialog-centered">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title">Topup Wallet</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 action="payment.php" method="POST">
					    <div class="row">
					        <div class="col-md-12 mb-3">
					            <label class="form-label">Email</label>
					            <input type="email" class="form-control" name="email" value="<?= $email ?>" readonly>
					        </div>
					        <div class="col-md-12 mb-3">
					            <label class="form-label">Phone</label>
					            <input type="number" class="form-control" name="phone" value="<?= $phone ?>" readonly>
					        </div>
					        <div class="col-md-12 mb-3">
					            <label class="form-label" >Topup Amount</label>
					            <input type="number" class="form-control" name="amount" min="" max="" step="0.01" required >
					            <input type="hidden" name="purpose" value="Package Purchase" >
					            <input type="hidden" name="name" value="<?= $username ?>" >
					            <input type="hidden" name="bid" value="<?= $user_id ?>" >
					            <input type="hidden" name="type" value="1" >
					        </div>
					        <div class="col-md-12 d-flex justify-content-end">
					            <input type="submit" name="pay" class="btn btn-info" value="Pay">
					        </div>
					    </div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- jQuery -->

	<script src="assets/js/jquery.min.js"></script>

	<script>
	    function selectPr(pid,efees){
            let selectPlayer = $('.selectPlayer:checked').val();
            $.ajax({
                method: 'POST',
                url: 'ajax/ajaxcall.php',
                data: {
                    selectPlayer: pid,
                    paid_entry:efees
                },
                dataType: "JSON",
                success: function(data) {
                    $('#amount'+data.player).text(data.amount)
                    if(data.total != ''){
                         $('#apply').removeClass('disabled')
                         $('#apply').attr('type','submit')
                    }else{
                        $('#apply').addClass('disabled')
                        $('#apply').attr('type','button')
                    }
                    $('#total_amount').text(data.total)
                    $('#pay_amount').text(data.total)
                     
                }
            })
	    }
	    $('#wallet-apply').click(function(){
	         let wal = $('#wallet_amount').val();
	         let total_amount = $('#total_amount').text();
	         if(wal >= total_amount){
	             window.location.href = "event-apply.php?apply=<?= $event_id ?>";
	         }else{
	             $('#topup_wallet').modal('show');
	             $('#apply_tour').modal('hide');
	         }
	    });
	    function mclose(){
	        $('#topup_wallet').modal('hide');
	    }
	    
	    $(document).ready(function(){
	        
            // $('.selectPlayer').click(function(){
            //     let selectPlayer = $('.selectPlayer:checked').val();
            //     let paid_entry = $('#paid_entry').val();
            //     // alert(selectPlayer);
            //     $.ajax({
            //         method: 'POST',
            //         url: 'ajax/ajaxcall.php',
            //         data: {
            //             selectPlayer: selectPlayer,
            //             paid_entry:paid_entry
            //         },
            //         dataType: "JSON",
            //         success: function(data) {
            //              $('#amount'+data.player).text(data.amount)
            //         }
            //     })
            // })
            // var countChecked = function() {
            //     var n = $( "input:checked" ).length;
            //     $( "#amount" ).text( n + (n === 1 ? " is" : " are") + " checked!" );
            // };
            // countChecked();
             
            // $( "input[type=checkbox]" ).on( "click", countChecked );
        });
	</script>
	<script>
		<?php if(isset($_SESSION['check']) && !empty($_SESSION['check'])) { ?>
		    swal({
                title: "<?= $_SESSION['check'] ?>", 
                text: "",
                icon: "<?= $_SESSION['alert'] ?>",
                button: {
                    className: "agree",
                },
            });
        <?php unset($_SESSION['check']) ; } ?>
    </script>
	<!-- Bootstrap Core JS -->

	<script src="assets/js/popper.min.js"></script>

	<script src="assets/js/bootstrap.min.js"></script>

	<!-- Sticky Sidebar JS -->
    <script src="assets/plugins/theia-sticky-sidebar/ResizeSensor.js"></script>
    <script src="assets/plugins/theia-sticky-sidebar/theia-sticky-sidebar.js"></script>
	
	<!-- Circle Progress JS -->
	<script src="assets/js/circle-progress.min.js"></script>
		
	<!-- Slick JS -->

	<script src="assets/js/slick.js"></script>

	<!-- Custom JS -->

	<script src="assets/js/script.js"></script>
		

</body>

<!-- doccure/  30 Nov 2019 04:11:53 GMT -->

</html>