<?php include('../config/setup.php'); ?>
<?php 
session_start();
    date_default_timezone_set('Asia/Kolkata');
    
    // order_master reject update query starts
    if(isset($_POST['reject'])){
        $event_id = $_POST['event_id'];

        $sql = "UPDATE event_post SET e_status = 0 WHERE event_id = '$event_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Moved To Rejected events";
		    $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Failed";
		    $_SESSION['alert'] = "error";
        }
    }

    // order_master reject update query ends
    if(isset($_POST['disabled'])){
        $event_id = $_POST['event_id'];
        $disabled = $_POST['disabled_s'];
        // print_r($disabled);exit;
        $sql = "UPDATE event_post SET disabled ='$disabled'  WHERE event_id = '$event_id' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Status Updated";
            $_SESSION['alert'] = "success";
        } else {
            $_SESSION['status'] = "Failed";
            $_SESSION['alert'] = "error";
        }
    }

?>

<?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 d-flex justify-content-between">
						<h4 class="page-title">Approved Events</h4>
						<div class="d-flex justify-content-between" style="column-gap:10px;">
						    <?php
						        $req_sql = $config->query("SELECT count(event_id) as total FROM event_post WHERE e_status = 1 ") ;
						        $req = $req_sql->fetch_assoc();
						        $requested = $req['total'];
						    ?>
						    <a href="listing.php" class="btn btn-info text-white">Request <span class="badge text-white"><?= $requested; ?></span></a>
						    <?php
						        $app_sql = $config->query("SELECT count(event_id) as total FROM event_post WHERE e_status = 2 ") ;
						        $app = $app_sql->fetch_assoc();
						        $approved = $app['total'];
						    ?>
						    <a href="listing_approve.php" class="btn btn-success text-white">Approval <span class="badge text-white"><?= $approved; ?></span></a>
						    <?php
						        $rej_sql = $config->query("SELECT count(event_id) as total FROM event_post WHERE e_status = 0 ") ;
						        $rej = $rej_sql->fetch_assoc();
						        $rejected = $rej['total'];
						    ?>
						    <a href="listing_reject.php" class="btn btn-danger text-white">Rejected <span class="badge text-white"><?= $rejected; ?></span></a>
						</div>
					</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>Company Name</th>
													<th>Category</th>
													<th>Cost</th>
                                                    <th>Player Count (export)</th>
                                                    <th>Admin Commission</th>
													<th>Last Date</th>
													<th>Event Date</th>
													<th>View</th>
                                                    <th>Status</th>
                                                    <!-- <th>Status</th> -->
													<th>Disabled</th>
												</tr>
											</thead>
											<tbody>
											    <?php
											        $sno = 1;
											        $sql = "SELECT * FROM event_post WHERE e_status = 2 ORDER BY event_id DESC " ;
											        $res = $config->query($sql);
											        while($row = $res->fetch_assoc()){
											            $cus_id = $row['vendor_id'];
											            $sub_id = $row['sub_cate_id'];
											            $status = $row['e_status'];
											            $event_id = $row['event_id'];
                                                        $disabled = $row['disabled'];
											    ?>
											    <tr>
											        <td><?= $sno ?></td>
											        <?php
    											        $cus_sql = "SELECT * FROM v_profile WHERE v_id = '$cus_id' " ;
    											        $cus_res = $config->query($cus_sql);
    											        $cus = $cus_res->fetch_assoc();
											        ?>
											        <td><?= $cus['company'] ?></td>
										            <?php
    											        $sub_sql = "SELECT * FROM sub_category WHERE Sub_Category_Id = '$sub_id' AND Sub_Category_status = 1 " ;
    											        $sub_res = $config->query($sub_sql);
    											        $sub = $sub_res->fetch_assoc();
                                                        $entry = "SELECT sum(entry_price) as entryfees FROM entry_master WHERE event_id = '$event_id' " ;
                                                        $entry = $config->query($entry);
                                                        $entry = $entry->fetch_assoc();

                                                         $r_entry = "SELECT sum(comm_amt) as commAmt, count(apply_id) as applayCount FROM apply_request WHERE event_id = '$event_id' " ;
                                                        $r_entry = $config->query($r_entry);
                                                        $r_entry = $r_entry->fetch_assoc();
                                                         // print_r($r_entry);exit;
											        ?>
											        <td><?= $sub['Sub_Category_Name'] ?></td>
											        <td><?= $row['pack_comm']?></td>
                                                    <td><a class="btn btn-sm btn-outline-secondary" href="/exportCsv.php?event=<?=$event_id?>"><?= $r_entry['applayCount']?></a> </td>
                                                    <td><?= $r_entry['commAmt']?></td>

											        <td><?= date('d-m-Y',strtotime($row['l_date'])) ?></td>
											        <td><?= date('d-m-Y',strtotime($row['e_date'])) ?></td>
											        <td><a class="btn btn-primary text-white" data-target="#view<?= $sno; ?>" data-toggle="modal"><i class="fas fa-eye"></i> View</a></td>
											        <td>
											        <?php 
                								        if($status == 1){
                								            $cur_stauts = "Requested";
                								            $btn_color = "secondary" ;
                								        }else if($status == 2){
                								            $cur_stauts = "Approved";
                								            $btn_color = "success" ;
                								        }else if($status == 0){
                								            $cur_stauts = "Rejected";
                								            $btn_color = "danger" ;
                								        }
                								    ?>
											            <a class="btn btn-<?= $btn_color; ?> text-white" data-target="#event<?= $sno; ?>" data-toggle="modal"><?= $cur_stauts; ?></a>
											        </td>
                                                     <td>
                                                    <?php 
                                                        if($disabled == 0){
                                                            $cur_stauts1 = "Inactive";
                                                            $btn_color1 = "secondary" ;
                                                        }else if($disabled == 1){
                                                            $cur_stauts1 = "Active";
                                                            $btn_color1 = "success" ;
                                                        }else if($disabled == 0){
                                                            $cur_stauts1 = "Rejected";
                                                            $btn_color1 = "danger" ;
                                                        }
                                                    ?>
                                                        <a class="btn btn-<?= $btn_color1; ?> text-white" data-target="#disabled<?= $sno; ?>" data-toggle="modal"><?= $cur_stauts1; ?></a>
                                                    </td>
											    </tr>


                                                <div class="modal fade" id="disabled<?= $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header bg-info">
                                                                <h5 class="modal-title" id="exampleModalLabel">Status View</h5>
                                                                <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                            </div>
                                                            <div class="modal-body">
                                                                <form method="post">
                                                                    <div class="form-group">
                                                                        <label for="order_status">Current Status</label>

                                                                         <select class="form-control"  name="disabled_s">
                                                                             <option <?=($disabled==1)?"selected":""?> value="1">Active</option>
                                                                             <option <?=($disabled==0)?"selected":""?> value="0">Inactive</option>
                                                                         </select>
                                                                        <input type="hidden"  id="event_id" name="event_id" value="<?= $row['event_id']; ?>" >
                                                                    </div>
                                                                    <!--<div class="form-group">-->
                                                                    <!--    <label for="order_status">Amount</label>-->
                                                                    <!--    <input type="text" class="form-control" id="order_price" name="order_price" value="<?= $row['order_price']; ?>" readonly>-->
                                                                    <!--</div>-->
                                                                    <!--<div class="form-group">-->
                                                                    <!--    <label for="add_on">Add On</label>-->
                                                                    <!--    <input type="text" class="form-control" id="add_on" name="add_on" >-->
                                                                    <!--</div>-->
                                                                    <div class="form-group d-flex" style="column-gap:10px;">
                                                                        <button class="btn btn-success btn-lg btn-block" type="submit" name="disabled"> Sumbit</button>                                                                        
                                                                        <button class="btn btn-muted btn-lg btn-block" type="button" data-dismiss="modal"> Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
											    <!-- Modal -->
                                    			<div class="modal fade" id="view<?= $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    				<div class="modal-dialog modal-lg" role="document">
                                    					<div class="modal-content">
                                    						<div class="modal-header">
                                    							<h5 class="modal-title" id="exampleModalLabel">Event Details</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="row px-3">
                                    						        <div class="col-md-6">
                                    									<h3>Event Name</h3>
                                    									<p><?= $row['e_title']; ?></p>
                                    									<?php if($row['sub_title'] != ''){ ?>
                                    									<h3>Sub Title</h3>
                                    									<p><?= $row['sub_title']; ?></p>
                                    									<?php } ?>
                                    									<h3>Category</h3>
                                    									<p><?= $sub['Sub_Category_Name'] ?></p>
                                    									<div class="row">
                                    									    <div class="col-md-4">
                                        									    <h3>Type</h3>
                                        									    <p><?= $row['e_type']; ?></p>
                                    									    </div>
                                    									    <div class="col-md-4">
                                        									    <h3>Enrty</h3>
                                        									    <p class="text-capitalize"><?= $row['entry']; ?></p>
                                    									    </div>
                                    									    <div class="col-md-6">
                                        									    <h3>Enrty Type</h3>
                                        									    <?php 
                                        									        $entry_sql = $config->query("SELECT * FROM entry_master WHERE event_id = '$event_id' ");
                                        									        foreach($entry_sql as $entry_res){
                                        									    ?>
                                        									    <p class="text-primary"><?= $entry_res['entry_type'] ?></p>
                                        									    <?php } ?>
                                    									    </div>
                                    									    <div class="col-md-6">
                                        									    <h3>Enrty Fees</h3>
                                        									    <?php 
                                        									        foreach($entry_sql as $entry_res){
                                        									    ?>
                                        									    <p class="text-primary"><?= $entry_res['entry_price'] ?></p>
                                        									    <?php } ?>
                                    									    </div>
                                    									</div>
                                    						        </div>
                                    						        <div class="col-md-6">
                                    						            <h3>Image</h3>
                                    						            <img class="img-fluid" src="../../assets/img/event/<?= $row['e_image']; ?>">
                                    						        </div>
                                    						        <?php if($row['sub_title'] != ''){ ?>
                                    						        <div class="col-md-12">
                                    									<h3>Description</h3>
                            									        <p class="text-justify"><?= $row['e_desc']; ?></p>
                                    						        </div>
                                    						        <?php } ?>
                                    						        <div class="col-md-6">
                                    									<h3>Address</h3>
                                    									<p><?= $row['address']; ?></p>
                                    									<h3>Area</h3>
                                    									<p><?= $row['area']; ?></p>
                                    									<h3>City</h3>
                                    									<p><?= $row['city']; ?></p>
                                    						        </div>
                                    						        <div class="col-md-6">
                                    									<h3>Event Start Date : <span class="badge bg-success text-white"><?= date('d-m-Y',strtotime($row['e_date'])); ?></span></h3>
                                    									<h3>Event End Date : <span class="badge bg-info text-white"><?= date('d-m-Y',strtotime($row['end_date'])); ?></span></h3>
                                    									<h3>Last Enrollment Date : <span class="badge bg-danger text-white"><?= date('d-m-Y',strtotime($row['l_date'])); ?></span></h3>
                                    									<?php if($row['e_broucher'] != ''){ ?>
                                    									<h3>Broucher
                                        									<a class="btn btn-warning" href="../../assets/img/broucher/<?= $row['e_broucher']; ?>" target="_blank">
                                        									    <i class="fas fa-eye"></i> View
                                        									</a>
                                    									</h3>
                                    									<?php } ?>
                                    						        </div>
                                    						    </div>

                                    						</div>
                                    						<div class="modal-footer">
                                        						<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                    						</div>
                                    					</div>
                                    				</div>
                                    			</div>

											    <!-- Modal -->
                                    			<div class="modal fade" id="event<?= $sno; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    				<div class="modal-dialog" role="document">
                                    					<div class="modal-content">
                                    						<div class="modal-header bg-info">
                                    							<h5 class="modal-title" id="exampleModalLabel">Status Approval</h5>
                                    							<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                                    								<span aria-hidden="true">&times;</span>
                                    							</button>
                                    						</div>
                                    						<div class="modal-body">
                                    							<form method="post">
                                    								<div class="form-group">
                                    									<label for="order_status">Current Status</label>
                                    									<input type="text" class="form-control" id="e_status" name="e_status" value="<?= $cur_stauts; ?>" readonly >
                                    									<input type="hidden"  id="event_id" name="event_id" value="<?= $row['event_id']; ?>" >
                                    								</div>
                                    								<!--<div class="form-group">-->
                                    								<!--	<label for="order_status">Amount</label>-->
                                    								<!--	<input type="text" class="form-control" id="order_price" name="order_price" value="<?= $row['order_price']; ?>" readonly>-->
                                    								<!--</div>-->
                                    								<!--<div class="form-group">-->
                                    								<!--	<label for="add_on">Add On</label>-->
                                    								<!--	<input type="text" class="form-control" id="add_on" name="add_on" >-->
                                    								<!--</div>-->
                                    								<div class="form-group d-flex" style="column-gap:10px;">
																		<button class="btn btn-danger btn-lg btn-block" type="submit" name="reject"><i class="fas fa-trash-alt"></i> Delete</button>                                    									
                                    									<button class="btn btn-muted btn-lg btn-block" type="button" data-dismiss="modal"> Cancel</button>
                                    								</div>
                                    							</form>
                                    						</div>
                                    					</div>
                                    				</div>
                                    			</div>
											    <?php $sno++; } ?>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>




			<?php include('footer.php'); ?>
		</div>
		<!-- End Custom template -->
	</div>
	<!--   Core JS Files   -->
	<style>
	    .badge{
            border-radius: 50px;
            margin-left: auto;
            line-height: 1;
            padding: 6px 10px;
            vertical-align: middle;
            font-weight: 800;
            font-size: 15px;
            border: unset; 
        }
        .btn-block+.btn-block{
            margin-top: unset;
        }
	</style>
	<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({
				 buttons: [
               'copy', 'excel', 'pdf'
             ]
			});
		});
	</script>
</body>

</html>