<?php
    session_start();
    if(isset($_SESSION['user_id']) && isset($_SESSION['user_name']) && $_SESSION['user_cate'] === "vendor"){
        $user_id = $_SESSION['user_id'] ;
        $username = $_SESSION['user_name'] ;
        $ticket = $_SESSION['last_ticket'] ;
        $company = $_SESSION['company'] ;
        $vendor_image = $_SESSION['vendor_image'] ;
    }else{
        header("Location:vendor_login.php") ;
    }
    if(!isset($_GET['event'])){
        header("Location:listing.php") ;
    }else{
        $event_id = $_GET['event'] ;
    }
?>

<?php include "head.php" ; ?>
<?php
    $title_sql = $config->query("SELECT * FROM event_post WHERE event_id = '$event_id' AND e_status = 2 ");
    $title = $title_sql->fetch_assoc();
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<link href="https://cdn.datatables.net/v/bs5/jq-3.7.0/dt-1.13.6/b-2.4.1/b-html5-2.4.1/r-2.5.0/datatables.min.css" rel="stylesheet">
 
<script src="https://cdn.datatables.net/v/bs5/jq-3.7.0/dt-1.13.6/b-2.4.1/b-html5-2.4.1/r-2.5.0/datatables.min.js"></script>


	<!-- Main Wrapper -->

	<div class="main-wrapper">

		<!-- Header -->

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

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

		
			<!-- Breadcrumb -->
			<?php include "breadcrumb.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 "vendor_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-3">-->
								<!--					<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>Active</h6>-->
								<!--							<h3>-->
								<!--							<?php
            											     //   $post_sql = "SELECT count(event_id) as tot FROM event_post WHERE vendor_id = '$user_id' And e_status = 2 " ;
            											     //   $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-3">-->
								<!--					<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>Pending</h6>-->
								<!--							<h3>-->
								<!--							<?php
            											     //   $post_sql = "SELECT count(event_id) as tot FROM event_post WHERE vendor_id = '$user_id' And e_status = 1 " ;
            											     //   $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-3">-->
								<!--					<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>Inactive</h6>-->
								<!--							<h3>0</h3>-->
								<!--						</div>-->
								<!--					</div>-->
								<!--				</div>-->
								<!--				<div class="col-md-12 col-lg-3">-->
								<!--					<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>Rejected</h6>-->
								<!--							<h3>-->
								<!--							<?php
            											     //   $post_sql = "SELECT count(event_id) as tot FROM event_post WHERE vendor_id = '$user_id' And e_status = 0 " ;
            											     //   $post_res = $config->query($post_sql);
            											     //   $post = $post_res->fetch_assoc();
            											     //   echo $post['tot'];
            											    ?>-->
        <!--    											    </h3>-->
								<!--						</div>-->
								<!--					</div>-->
								<!--				</div>-->
												
								<!--			</div>-->
								<!--		</div>-->
								<!--	</div>-->
								<!--</div>-->
							</div>

							<div class="row">
								<div class="col-md-12">
									<div class="d-flex justify-content-between align-items-start">
									    <h4 class="mb-4">Applied List</h4>
									    <div>
									        <!-- <a class="btn btn-sm bg-info-light" id="download"><i class="fas fa-file-alt"></i> Export</a> -->
									        <a class="btn btn-sm bg-info-light" target="_blank" href="exportCsv.php?event=<?=$event_id?>"><i class="fas fa-file-alt"></i> Export</a>

									        <a href="listing.php" class="btn btn-sm bg-success-light"><i class="fas fa-arrow-alt-circle-left"></i> Back</a>
									    </div>
									</div>
									<div class="appointment-tab">

										<div class="tab-content">
										
											 <!--Upcoming Appointment Tab -->
											<div class="tab-pane show active" id="active">
												<div class="card card-table mb-0" >
													<div class="card-body" id="view-list">
														<div class="table-responsive">
															<table id="myTable" class="table table-hover table-center mb-0">
																<thead>
																    <tr>
																		<th colspan="6"><?= $title['e_title'] ?></th>
																	</tr>
																	<tr>
																		<th>S.No</th>
																		<th>E.Date</th>						
																		<th>Name</th>
																		<th>Mobile Number</th>
																		<th>Category</th>
																		<th>FIDE ID</th>
																		<th>AICF ID</th>
																		<th>TNSCA ID</th>
																		<th>CHESS ID</th>
																		<th>LICHESS ID</th>
																		<th>Entry Fee</th>
																		<th>A.Date</th>
																		
																	</tr>
																</thead>
																<tbody>
																    <?php
																        $sno = 1;
        																$sql = "SELECT * FROM apply_request WHERE event_id = '$event_id' " ;
                    											        $res = $config->query($sql);
                    											        while($list = $res->fetch_assoc()){
                    											            $user = $list['user_id'];
                    											            $player_id = $list['player_id'];
																    ?>
																	<tr>
																	    <td><?= $sno;?></td>
																		<?php
                        											        $event_sql = $config->query("SELECT * FROM event_post WHERE event_id = '$event_id' AND e_status = 2 ");
                        											        $event = $event_sql->fetch_assoc();
                        											        $cate_id = $event['sub_cate_id'];
                        											        $sub_sql = "SELECT * FROM sub_category WHERE Sub_Category_Id = '$cate_id' AND Sub_Category_status = 1 " ;
                        											        $sub_res = $config->query($sub_sql);
                        											        $sub = $sub_res->fetch_assoc();
                    											        ?>
																		<?php
                    											        ?>
											                            <td><?= date('d-m-Y',strtotime($event['e_date'])) ?></td>
											                            <?php
                        											     //   $user_sql = $config->query("SELECT * FROM master_login WHERE Master_id = '$user' AND Master_Type = 3 " );
                        											     //   $user_res = $user_sql->fetch_assoc();
                        											        $ply_sql = $config->query("SELECT * FROM players WHERE id = '$player_id' AND user_id = '$user' " );
                        											        $ply_res = $ply_sql->fetch_assoc();
    																    ?>
																		<td><?= $ply_res['name'] ?></td>
																		<td><?= $ply_res['phone'] ?></td>
																		<td><?= $list['entry_type'] ?></td>
																		<td><?= $ply_res['fide_id'] != '' ? $ply_res['fide_id'] : ' - ' ; ?></td>
																		<td><?= $ply_res['aicf_id'] != '' ? $ply_res['aicf_id'] : ' - ' ; ?></td>
																		<td><?= $ply_res['tnsca_id'] != '' ? $ply_res['tnsca_id'] : ' - ' ; ?></td>
																		<td><?= $ply_res['chess_id'] != '' ? $ply_res['chess_id'] : ' - ' ; ?></td>
																		<td><?= $ply_res['lichess_id'] != '' ? $ply_res['lichess_id'] : ' - ' ; ?></td>
																		<td><?= $list['entry'] != 'free' ? $list['entry_fees'] - $list['comm_amt'] : 'Free' ; ?> </td>
																		<td><?= date('d-m-Y h:i a',strtotime($list['apply_on'])) ?></td>
																	</tr>
																		<?php  $sno++;} ?>
																
																</tbody>
															</table>		
														</div>
													</div>
												</div>
											</div>
											 <!--/Upcoming Appointment Tab -->
											
										</div>
									</div>
								</div>
							</div>

						</div>
					</div>

				</div>

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

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

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

	<!-- /Main Wrapper -->
    <style>
        .nav-tabs.nav-tabs-solid.nav-tabs-rounded > li > a {
            border-radius: 5px;
        }
        .nav-tabs.nav-tabs-solid > li > a.active, .nav-tabs.nav-tabs-solid > li > a.active:hover, .nav-tabs.nav-tabs-solid > li > a.active:focus {
            border-radius: 5px !important;
        }
        .appointment-tab .nav-tabs {
            column-gap: 25px;
        }
    </style>
    <script type="text/javascript">

   	</script>
    <script>
        window.onload = function(){
            document.getElementById("download").addEventListener('click',()=>{
                const viewlist = document.getElementById('view-list');
                let opt = {
                  filename:     'list.pdf',
                  image:        { type: 'jpeg', quality: 0.98 },
                  html2canvas:  { scale: 2 },
                  jsPDF:        { unit: 'in', format: 'letter', orientation: 'portrait' }
                };
                html2pdf().set(opt).from(viewlist).save();
            })
        }
    </script>
	<!-- jQuery -->

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

<script src="https://cdn.datatables.net/v/bs4/dt-1.13.6/b-2.4.1/b-html5-2.4.1/r-2.5.0/datatables.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>
	<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>	

<script type="text/javascript">

$('#exportCsv').click(function(){
<?php 
   $sno = 1;
   $sql = "SELECT * FROM apply_request WHERE event_id = '$event_id' " ;
   $query = $config->query($sql);
   // $res->fetch_assoc();
 if($query->num_rows > 0){ 
    $delimiter = ","; 
    $filename = "members-data_" . date('Y-m-d') . ".csv"; 
     
    // Create a file pointer 
    $f = fopen('php://memory', 'w'); 
     
    // Set column headers 
    $fields = array('ID'); 
    fputcsv($f, $fields, $delimiter); 
     
    // Output each row of the data, format line as csv and write to file pointer 
    $i=1;
    while($row = $query->fetch_assoc()){ 
        $status = ($row['status'] == 1)?'Active':'Inactive'; 
        $user = $row['user_id'];
        $player_id = $row['player_id'];
        // $event_sql = $config->query("SELECT * FROM event_post WHERE event_id = '$event_id' AND e_status = 2 ");
        // $event = $event_sql->fetch_assoc();
        // $cate_id = $event['sub_cate_id'];
        //   $sub_sql = "SELECT * FROM sub_category WHERE Sub_Category_Id = '$cate_id' AND Sub_Category_status = 1 " ;
        //   $sub_res = $config->query($sub_sql);
        //   $sub = $sub_res->fetch_assoc();
           $ply_sql = $config->query("SELECT * FROM players WHERE id = '$player_id' AND user_id = '$user' " );
           $ply_res = $ply_sql->fetch_assoc();

        $lineData = array($i); 
        fputcsv($f, $lineData, $delimiter); 
    $i++; } 
     
    // Move back to beginning of file 
    fseek($f, 0); 
     
    // Set headers to download file rather than displayed 
    header('Content-Type: text/csv'); 
    header('Content-Disposition: attachment; filename="' . $filename . '";'); 
     
    //output all remaining data on a file pointer 
    fpassthru($f); 
} 
exit; 
?>
		
	})

</script>
</body>

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

</html>