<?php 
if(!isset($_GET['event']) && empty($_GET['event'])){
    header("Location:index.php");
}else{
    $sid = $_GET['event'];
}
    $page = "index";
    include('head.php');
?>
<?php 
session_start();
    if(isset($_SESSION['user_id']) && isset($_SESSION['user_cate']) && $_SESSION['user_cate'] == "user"){
        $user_id = $_SESSION['user_id'];
        $user_name = $_SESSION['user_name'];
        $sql = "SELECT * FROM ewallet_master WHERE user_id = '$user_id' " ;
        $res = $config->query($sql);
        $row = $res->fetch_assoc();
        $user_wallet = $row['total_amount'];
    }
?>
<body>
	<!-- Main Wrapper -->

	<div class="main-wrapper">

		<!-- Header -->

		<?php include('./header.php') ?>

		<!-- /Header -->

		<!-- Home Banner -->	
        <?php 
            $sub_cate_sql = "SELECT * FROM sub_category WHERE Sub_Category_id = '$sid' " ;
	        $sub_cate_res = $config->query($sub_cate_sql);
	        $sub_cate_row = $sub_cate_res->fetch_assoc();
        ?>
		<div class="breadcrumb-bar banner">
        	<div class="container-fluid">
        		<div class="row align-items-center">
        			<div class="col-md-12 col-12 d-flex justify-content-between">
            			<div>
            				<nav aria-label="breadcrumb" class="page-breadcrumb">
            					<ol class="breadcrumb">
            						<li class="breadcrumb-item"><a href="index.php">Home</a></li>
            						<li class="breadcrumb-item active" aria-current="page"><?= $sub_cate_row['Sub_Category_Name'] ?></li>
            					</ol>
            				</nav>
            			</div>
            			<?php
        			        $sql = "SELECT * FROM ewallet_master WHERE vendor_id = '$user_id' " ;
        			        $res = $config->query($sql);
        			        $row = $res->fetch_assoc();
        			    ?>
        			</div>
        		</div>
        	</div>
        </div>

		<!-- /Home Banner -->

		<!-- Popular Section -->

		<section class="section section-doctor">

			<div class="container-fluid">

				<div class="row">

					<div class="col-lg-12">
						<div class="doctor-slider slider">
					    <?php 
					        $sql = "SELECT * FROM event_post WHERE sub_cate_id = '$sid' AND e_status = 2 ORDER BY event_id DESC" ;
					        $res = $config->query($sql);
					        while($row = $res->fetch_assoc()){
					            $v_id = $row['vendor_id'];
					            $event_id = $row['event_id'];
					            $entry = $row['entry_fees'];
					    ?>       

							<!-- Doctor Widget -->
							<div class="profile-widget">
								<div class="doc-img">
									<a href="#" class="ad-image">
										<img class="img-fluid" alt="User Image" src="assets/img/event/<?= $row['e_image'] ?>">
									</a>
									<a href="javascript:void(0)" class="fav-btn">
										<i class="far fa-bookmark"></i>
									</a>
								</div>
								<div class="pro-content">
									<h3 class="title">
										<a href="#"><?= $row['e_title'] ?></a>
									</h3>
									<p class="speciality"><?= $row['sub_title'] ?></p>
									<ul class="available-info">
										<li>
											<i class="fas fa-map-marker-alt"></i> <?= $row['address'] ?>, <?= $row['area'] ?>, <?= $row['city'] ?>
										</li>
										<li><i class="far fa-clock"></i> 
                                            <?php 
                                                        $entry_sql = $config->query("SELECT * FROM entry_master WHERE event_id = '$event_id' ");
                                                        foreach($entry_sql as $entry_res){
                                                        echo $entry_res['entry_type'].' - Rs.'.$entry_res['entry_price'].',';
                                                    ?>
                                                    <?php } ?></li>
										<li><i class="far fa-clock"></i> <?= $row['e_type'] ?></li>
										<?php
    										$sub_sql = "SELECT * FROM v_profile WHERE v_id = '$v_id' " ;
                					        $sub_res = $config->query($sub_sql);
                					        $sub = $sub_res->fetch_assoc();
										?>
										<li><i class="far fa-money-bill-alt"></i>Organized by <?= $sub['company'] ?></li>
										<h3 class="title">
											<a href="#">Mr. <?= $sub['v_name'] ?></a>
											<i class="fas fa-check-circle verified"></i>
										</h3>
									</ul>
									<div class="row row-sm">
									    <?php
									        if(empty($row['e_desc'])){
									   ?>
										<div class="col-6">
											<a href="assets/img/broucher/<?= $row['e_broucher'] ?>" class="btn view-btn" style="background: #FA6100;border: 2px solid #FA6100;color:#fff;" download>Download</a>
										</div>
										<div class="col-6">
											<?php 
											 if(isset($_SESSION['user_cate']) && $_SESSION['user_cate'] == "user"){
											      $sql = $config->query("SELECT * FROM apply_request WHERE user_id = '$user_id' AND event_id = '$event_id' ") ;
											          if($row['disabled']==0){ ?>
                                                         <a href="#" class="btn book-btn" style="background: #ddd;color:#000;border: 2px solid #ddd;" >Closed</a>
                                                   <?php }elseif($sql->num_rows > 0){ ?>
											            <a href="#" class="btn book-btn " style="background: #e32625;border: 2px solid #e32625;" onclick="applied()">Applied</a>
    										 <?php   }else{   ?>
											            <a href="#" class="btn book-btn" onclick="ebook(<?= $event_id; ?>,<?= $user_id; ?>,<?= $entry ?>)" style="background: #2dd304;border: 2px solid #2dd304;">Apply</a>
											<?php   } 
											    }else{ ?>
											        <a href="#" class="btn book-btn" style="background: #0de0fe;color:#fff;border: 2px solid #0de0fe;" onclick="window.location.href='login.php';">Book Now</a>
											<?php } ?>
										</div>
									    <?php }else{ ?>
									        <div class="col-4">
    											<a href="assets/img/broucher/<?= $row['e_broucher'] ?>" class="btn view-btn" style="font-size: 12px;padding: 6px 4px;background: #FA6100;border: 2px solid #FA6100;color:#fff;" download >Download</a>
    										</div>
									        <div class="col-4">
    											<a href="#" class="btn view-btn" style="background: #007bff;color:#fff;border: none;padding: 8px;" data-toggle="modal" data-target="#details<?= $row['event_id'] ?>">View</a>
    										</div>
    										<div class="col-4">
    											<?php 
    											    if(isset($_SESSION['user_cate']) && $_SESSION['user_cate'] == "user"){
    											         $sql = $config->query("SELECT * FROM apply_request WHERE user_id = '$user_id' AND event_id = '$event_id' ") ;
                                                           $sql = $config->query("SELECT * FROM apply_request WHERE user_id = '$user_id' AND event_id = '$event_id' GROUP BY player_id ") ;
                                                            $player = $config->query("SELECT * FROM players WHERE user_id = '$user_id' ");
                                                              if($row['disabled']==0){ ?>
                                                         <a href="#" class="btn book-btn" style="background: #ddd;color:#000;border: 2px solid #ddd;" >Closed</a>
                                                      <?php }
											             elseif($sql->num_rows == $player->num_rows){ ?>
											                <a href="#" class="btn book-btn" style="background: #e32625;border: 2px solid #e32625;" onclick="applied()">Applied</a>
    										    <?php   }else{   ?>
											            <a href="#" class="btn book-btn" onclick="ebook(<?= $event_id; ?>,<?= $user_id; ?>,<?= $entry ?>)" style="background: #2dd304;border: 2px solid #2dd304;">Apply</a>
											    <?php   }
											        }else{ ?>
    											        <a href="#" class="btn book-btn" style="background: #0de0fe;color:#fff;border: 2px solid #0de0fe;" onclick="window.location.href='login.php';">Book</a>
    											<?php } ?>
    										</div>
									    <?php } ?>
									</div>
								</div>
							</div>
							<!-- /Doctor Widget -->
                        <?php  } ?>
						</div>
					</div>

				</div>

			</div>

		</section>

		<!-- /Popular Section -->

		<!-- Footer -->

		<?php include('./footer.php') ?>

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

	<!-- /Main Wrapper -->
	<!-- Details Modal -->
	<?php 
        $sub_sql = "SELECT * FROM event_post WHERE e_status = 2 " ;
        $sub_res = $config->query($sub_sql);
        while($sno = $sub_res->fetch_assoc()){
            $vendor_id=$sno['vendor_id'];
         $sub_sql1 = "SELECT * FROM master_login WHERE Master_id ='$vendor_id'" ;
         $sub_res1 = $config->query($sub_sql1);
          $sub_res1=$sub_res1->fetch_assoc();
    ?>  
	<div class="modal fade custom-modal" id="details<?= $sno['event_id'] ?>">
		<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"><?= $sno['e_title'] ?></h5>
					<p class="text-capitalize" style="margin-bottom:8px;"><?= $sno['sub_title'] ?></p>
                    <p class="text-capitalize" style="margin-bottom:8px;">Name - <?=$sub_res1['Master_Name']?></p>

                    <p class="text-capitalize" style="margin-bottom:8px;">Mobile Number - <?=$sub_res1['Master_phone']?></p>

					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
				    <p class="text-justify"><?= substr($sno['e_desc'],0,700); ?></p>
				    <a href="#" class="btn book-btn" data-dismiss="modal">Back</a>
				</div>
			</div>
		</div>
	</div>
	<?php } ?>
	<!-- Details Modal -->
	<!-- jQuery -->
    <style>
        .slick-prev, .slick-next {
            top: 34%;
        }
        .profile-widget .fav-btn {
            background-color: #fb1612;
            color: #fff;
        }
        .banner{
            background:url('assets/img/banner.jpg') no-repeat center;
            background-size:cover;
            height:100px;
        }
        .page-breadcrumb ol li a {
            color: #fff;
            font-weight: 700;
            font-size: 17px;
        }
        .page-breadcrumb ol li.active {
            color: #422714;
            font-weight: 700;
            font-size: 17px;
        }
    </style>
    <script>
		<?php if(isset($_SESSION['check']) && !empty($_SESSION['check'])) { ?>
		    swal({
                title: "<?= $_SESSION['check'] ?>", 
                text: "<?= $_SESSION['text'] ?>",
                icon: "<?= $_SESSION['alert'] ?>",
                button: {
                    className: "agree",
                },
            });
        <?php unset($_SESSION['check']) ; } ?>
    </script>
	<script src="assets/js/jquery.min.js"></script>

	<!-- Bootstrap Core JS -->

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

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

	<!-- Slick JS -->

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

	<!-- Custom JS -->

	<script src="assets/js/script.js"></script>
    <script>
        function ebook(eid,uid,entry){
            let wallet = <?= $user_wallet ?>;
            let entryFees = entry;
            // if(wallet > 0 ){
                if(wallet >= entryFees){
                    swal({
                        title: "Give me a confirmation to apply",
                        text: "Amount will be debited to your wallet",
                        icon: "info",
                        buttons: true,
                        dangerMode: true,
                    }).then((value) => {
                        if(value) {
                            $.ajax({
                                type: "POST",
                                url: "order_confirm.php",
                                data:{eid:eid,uid:uid},
                                success: function(data){
                                    swal({
                                        title: "Applied Successfully", 
                                        text: "",
                                        icon: "success",
                                        button: {
                                            className: "agree",
                                        },
                                    });
                                    $('.agree').on('click', function() {
                                        window.location.href="dashboard.php";
                                    });
                                }
                            });
                      } else {
                        swal("Request Cancelled.",{
                            icon: "error",
                        });
                      }
                    });
                }else{
                    $.ajax({
                        type:"POST",
                        data:{lid:300,check:"Purchase Package",text:"Your wallet balance is low",alert:"warning"},
                        url:"alert.php",
                        success: function(data){
                            window.location.reload();
                        }
                    });
                }    
            // }else{
            //     $.ajax({
            //         type:"POST",
            //         data:{fid:200,check:"Purchase Package",alert:"warning"},
            //         url:"alert.php",
            //         success: function(data){
            //             window.location.reload();
            //         }
            //     });
            // }
        }
    </script>
    <script>
        function applied(){
            $.ajax({
                type:"POST",
                data:{aid:100,check:"Already Applied",text:"Kindly Check with Your Dashboard.",alert:"warning"},
                url:"alert.php",
                success: function(data){
                    window.location.reload();
                }
            });
        }
    </script>
</body>

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

</html>