<?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'] ;
        // $ticket = $_SESSION['last_ticket'] ;
        // $company = $_SESSION['company'] ;
        $user_image = $_SESSION['user_image'] ;
    }else{
        header("Location:login.php") ;
    }
?>

<?php include "head.php" ; ?>
<style>
    .event-box img {
        height: 300px;
        width: 100%;
        min-height: 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">
									<div class="card dash-card">
										<div class="card-body">
											<div class="row">
												<div class="col-md-12 col-lg-4">
													<div class="dash-widget dct-border-rht">
														<div class="circle-bar circle-bar1">
															<div class="circle-graph1" data-percent="75">
																<img src="assets/img/icon-01.png" class="img-fluid" alt="patient">
															</div>
														</div>
														<div class="dash-widget-info">
															<h6>Applied</h6>
															<h3>
															<?php
            											        $post_sql = "SELECT COUNT(DISTINCT event_id) as tot FROM apply_request WHERE user_id = '$user_id' " ;
            											        $post_res = $config->query($post_sql);
            											        $post = $post_res->fetch_assoc();
            											        echo $post['tot'];
            											    ?>
															</h3>
														</div>
													</div>
												</div>
												
												<div class="col-md-12 col-lg-4">
													<div class="dash-widget dct-border-rht">
														<div class="circle-bar circle-bar2">
															<div class="circle-graph2" data-percent="65">
																<img src="assets/img/icon-02.png" class="img-fluid" alt="Patient">
															</div>
														</div>
														<div class="dash-widget-info">
															<h6>Wallet</h6>
															<h3><?= empty($row['total_amount']) ? 0 : $row['total_amount']; ?></h3>
														</div>
													</div>
												</div>
												
												<div class="col-md-12 col-lg-4">
													<div class="dash-widget dct-border-rht">
														<div class="circle-bar circle-bar3">
															<div class="circle-graph3" data-percent="50">
																<img src="assets/img/icon-03.png" class="img-fluid" alt="Patient">
															</div>
														</div>
														<div class="dash-widget-info">
															<h6>Notification</h6>
															<h3>0</h3>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							
							<div class="row d-none">
								<div class="col-md-12">
									<h4 class="mb-4">Applied Events</h4>
									<div class="appointment-tab">
										
										<div class="tab-content">
										
											<!-- Upcoming Appointment Tab -->
											<div class="tab-pane show active" id="upcoming-appointments">
												<div class="card card-table mb-0">
													<div class="card-body">
														<div class="table-responsive">
															<table class="table table-hover table-center mb-0">
																<thead>
																	<tr>
																		<th>S.No</th>
																		<th>Event Date</th>
																		<th>Event Name</th>
																		<th>Prize</th>
																		<th>Entry</th>
																		<th>Applied Date</th>
																	</tr>
																</thead>
																<tbody>
																    <?php
																        $sno = 1;
                     											        $sql = "SELECT * FROM apply_request WHERE user_id = '$user_id' GROUP BY event_id ORDER BY apply_id DESC " ;
                    											        $res = $config->query($sql);
                       											        while($row = $res->fetch_assoc()){
                        											      $event_id = $row['event_id'];
                        											      $e_sql = $config->query("SELECT * FROM event_post WHERE event_id = '$event_id' ") ;  
                        											      $e_res = $e_sql->fetch_assoc();
                  											        ?>
																	<tr>
																		<td><?= $sno; ?></td>
																		<td><?= date('d-m-Y',strtotime($e_res['e_date'])); ?></td>
																		<!--<td><?#= $p_row['ticket']; ?></td>-->
																		<!--<td><?#= $p_row['transaction_id']; ?></td>-->
																		<td><?= $e_res['e_title'] ?></td>
																		<td><?= $e_res['e_type'] ?></td>
																		<td><?= ($row['entry'] == 'free') ? "Free" : $row['entry_fees'] ; ?></td>
																		<td><?= date('d-m-Y',strtotime($row['apply_on'])); ?></td>
																	</tr>
																	<?php $sno++; } ?>
																</tbody>
															</table>		
														</div>
													</div>
												</div>
											</div>
											<!-- /Upcoming Appointment Tab -->
									   
											
										</div>
									</div>
								</div>
							</div>
							<div class="row">
							    <?php 
        					        $sql = "SELECT * FROM event_post WHERE 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'];
        					    ?>  
								<div class="col-md-12 card shadow event-box">
                                    <div class="card-body row p-0">
                                        <div class="col-md-3 p-0">
                                            <img class="img-fluid" alt="User Image" src="assets/img/event/<?= $row['e_image'] ?>">
                                        </div>
                                        <div class="col-md-9">
                                            <h3 class="card-title mt-3"><?= $row['e_title'] ?></h3>
                                            <p class="speciality"><?= $row['sub_title'] ?></p>
                                            <div class="row">
                                                <div class="col-md-6 d-flex mb-3">
                                                    <div class="event-title">Venue : </div>
                                                    <address class="event-para mb-0"><?= $row['address'] ?></address>
                                                </div>
                                                <div class="col-md-6 d-flex mb-3">
                                                    <div class="event-title">Prizes : </div>
                                                    <div class="event-para"><?= $row['e_type'] ?></div>
                                                </div>
                                                <div class="col-md-6 d-flex mb-3">
                                                    <div class="event-title">Date : </div>
                                                    <div class="event-para"><?= date('d-m-Y',strtotime($row['e_date'])) ?><?= !empty($row['end_date']) ? ' To '.date('d-m-Y',strtotime($row['end_date'])) : '' ; ?></div>
                                                </div>
                                                <div class="col-md-6 d-flex mb-3">
                                                    <div class="event-title" style="width: 40%;">Entry Fees : </div>
                                                    <div class="event-para">
                                                    <?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 } ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-6 d-flex mb-3">
                                                    <div class="event-title">Last Date : </div>
                                                    <div class="event-para"><?= date('d-m-Y',strtotime($row['l_date'])) ?></div>
                                                </div>
                                                <div class="col-md-12 d-flex justify-content-end mb-3" style="column-gap: 15px;">
                                                    
                                                </div>
                                            </div>
                                             <div class="row d-flex justify-content-end mb-3">
                                                <form method="POST" action="apply.php" class="col-md-2 pl-0">
                                                    <input type="hidden" name="event_id" value="<?= $row['event_id'] ?>">
													<?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' 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){ ?>
													  <button type="button" class="btn book-btn w-100" style="background: #e32625;border: 2px solid #e32625;" onclick="applied()">Applied</button>
    										        <?php   } else {   ?>
                                                    <button type="submit" class="btn book-btn w-100" style="background: #2dd304;border: 2px solid #2dd304;">Apply</button>
													<?php } } ?>
                                                </form>
                                                <?php
                                                    if(!empty($row["e_broucher"])) $link =  'assets/img/broucher/'.$row["e_broucher"];
                                                    else $link =  'javascript:void(0);' ; 
                                                ?>
                                                <div class="col-md-2 pl-0">
                                                    <a href="<?= $link ?>" target="_blank" class="btn view-btn" style="background: #007bff;color:#fff;border: none;padding: 8px;">View</a>
                                                </div>
                                                <div class="col-md-2 pl-0">
                                                    <a href="<?= $link ?>" class="btn view-btn" style="font-size: 12px;padding: 6px 4px;background: #FA6100;border: 2px solid #FA6100;color:#fff;" download >Download</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
								</div>
								<?php } ?>
							</div>

						</div>
					</div>

				</div>

			</div>		
			<!-- /Page Content -->
   	<!-- Footer -->

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

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

	<!-- /Main Wrapper -->

	<!-- jQuery -->

	<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>

	<!-- 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>
<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']) ; } ?>
        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>
<!-- doccure/  30 Nov 2019 04:11:53 GMT -->

</html>