<?php
include('config.php');
checkSession();
checkadmin($sdata['usertype']);
$success = false;

if(isset($_GET['key']) && $_GET['key']!=NULL){
    $id = base64_decode($_GET['key']);
    $res = mysqli_query($conn,"DELETE FROM 	child WHERE id='$id'");
    if($res){
        $success = true;
        ?>
        <script>
            setTimeout(() => {
                window.location.href='admin-child-data.php';
            }, 1200);
        </script>
        <?php
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Main Admin - View Customers Data | <?php echo $webdata['webname']; ?></title>
    <link rel="icon" type="image/png" sizes="16x16" href="assets/img/icon.png">
    <!-- Common Plugins -->
    <link href="assets/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- Vector Map Css-->
    <link href="assets/lib/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet" />
    <!-- Chart C3 -->
    <link href="assets/lib/chart-c3/c3.min.css" rel="stylesheet">
    <link href="assets/lib/chartjs/chartjs-sass-default.css" rel="stylesheet">
    <!-- Sweet Alerts -->
    <link href="assets/lib/sweet-alerts2/sweetalert2.min.css" rel="stylesheet">
    <!-- DataTables -->
    <link href="assets/lib/datatables/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
    <link href="assets/lib/datatables/responsive.bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/lib/datatables/buttons.dataTables.css" rel="stylesheet" type="text/css">
    <link href="assets/lib/toast/jquery.toast.min.css" rel="stylesheet">
    <!-- DataTimePicker -->
    <link href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" rel="stylesheet">
    <!-- Custom Css-->
    <link href="assets/scss/style.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <![endif]-->
    <style>
    @media print {

        html,
        body {
            display: none;
        }
    }
    </style>
</head>

<body>
    <?php 
        include('nav.php');
      ?>
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- 						Content Start	 						-->
    <!-- ============================================================== -->
    <div class="row page-header">
        <div class="col-lg-6 align-self-center ">
            <h2>View Child Data</h2>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item active">View Child Data</li>
            </ol>
        </div>
    </div>
    <section class="main-content">
                                   <?php if($success ==true){
                        ?>
                        <p style="color:green;font-size:16px;font-weight:bold;">Child Data Deleted Success!</p>
                        <?php
                     } ?> 
        <div class="row">
            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card">
                    <div class="card-header card-default">
</div>
                    <div class="card-body">
                        <table id="datatable1" class="table table-striped dt-responsive nowrap">
                            <thead>
                                <tr>
                                    <th style="width:50px">SNo.</th>
                                    <th >Applied By</th>
                                    <th>Aadhaar Card Details</th>
                                    <th>Purpose & Status</th>
                                    <th>Admin Remark</th>
                                    <th>Created On</th>
									 <th>Action</th>
                                </tr>
                            </thead>

                            <tbody>
                                <?php
                                $x =0;
								$calldata = mysqli_query($conn,"SELECT * FROM child  order by id ASC");
                                if(mysqli_num_rows($calldata)>0){
                                    $x =0;
                                    while($data = mysqli_fetch_assoc($calldata)){
                                          $x ++;
                                          ?>
                                            <tr>
                                    <td align="center"><?php echo $x;?></td>
                                    <td><?php echo $data['appliedby']; ?></td>
                                    <td>Name : <?php echo $data['name']; ?><br>
                                   Father Name :  <?php echo $data['fname']; ?><br>
                                   DOB : <?php echo $data['dob']; ?><br>
                                    Aadhaar No : <?php echo $data['aadhaar_no']; ?><br>
                                   Mobile No : <?php echo $data['mobile_no']; ?><br>
                                   E-mail : <?php echo $data['email']; ?><br>
                                   Address : <?php echo $data['address']; ?></td>

                                    <td><?php echo $data['purpose']; ?><br><span class="label <?php if($data['status'] == 'In-Progress' || $data['status'] == 'Pending-POI' || $data['status'] == 'Pending-POA' || $data['status'] == 'Pending-POB' ){echo "label-warning";}else if($data['status'] == 'Completed'){echo "label-success";}else if($data['status'] == 'Rejected'){echo "label-danger";} ?> label-danger"><?php echo $data['status']; ?></span></p></td>
                                    <td><?php echo $data['remark']; ?></td>
                                    <?php
                                    $timestamp = strtotime($data['date']);
                                    $new_date_format = date('Y-m-d H:i:s', $timestamp);
                                    ?>
                                    <td><?php echo $data['date']; ?></td>


                                    <td class="text-center">
                                    <a href="child-admin-edit-c.php?key=<?php echo base64_encode($data['id']); ?>" class="btn btn-sm btn-success">
                                                        <i class="fa fa-edit"></i>
                                                        </a>
                                    <!-- <a href="finger/index.php?key=<?php echo base64_encode($data['id']); ?>" class="btn btn-sm btn-success">
                                    <img src="assets/img/icon.png" height="20px" alt="H">
                                                        </a> -->
                                    <a href="finger/childNewUser.php?key=<?php echo base64_encode($data['id']); ?>" class="btn btn-sm btn-success">
                                    <img src="assets/img/icon.png" height="20px" alt="H">
                                                        </a>
                                    <a href="admin-child-download-finger.php?key=<?php echo base64_encode($data['id']); ?>" class="btn btn-sm btn-success">
                                                        <i class="fa fa-eye"></i>
                                                        </a>
                                 <a href="admin-child-data.php?key=<?php echo base64_encode($data['id']); ?>" class="btn btn-sm btn-danger">
                                                        <i class="fa fa-trash"></i>
                                                        </a>
                                    <button class="btn btn-success" id="upload" data="" onclick="upload('<?php echo ($data['id']); ?>')">Upload</button>


                                    </td>
                                </tr>
                                            <?php
                                    }

                                }
                                
                                   ?>
                                
                                


                            </tbody>

                        </table>
                    </div>
                </div>
            </div>
        </div>

        <?php 
        include('footer.php');
      ?>
    </section>
    <!-- ============================================================== -->
    
    <!-- Modal Upload  start -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
       
       <h3 class="modal-title" id="exampleModalLabel">Upload Acknowledgement Slip</h3>
      <div class="col-sm-4">
      
      <div class="p-2 text-light" style="border-radius:10px;" id="status"></div>
        </div>
                                            
        <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 m-5">
      <input type="file" class="input" name="cert" id="cert">
      <input type="hidden" id="bspdf">
      <button class="btn btn-success disabled" id="uploadcert" >Upload</button>
      </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
         
      </div>
    </div>
  </div>
</div>


<!-- Modal Upload Start -->
<!-- modal view start -->
        
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Applicant Information</h5>
      
        </button>
      </div>
      <div class="modal-body">
       <div class="row p-3">
       <div class="col-sm-4">
        <h4><b>Name:</b></h4>
       </div>
       </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        
      </div>
    </div>
  </div>
</div>
<script>
function upload(name){
    $('#exampleModal').modal('show');
    $('#cert').on('change',()=>{
        // upload file here 
        $('#uploadcert').removeClass('disabled');
        filereader  = new FileReader();
        filereader.onload = function(){
           //   alert(filereader.result);
              
              $('#bspdf').val(filereader.result);
            
       
        }
        filereader.readAsDataURL(document.getElementById('cert').files[0]);

    });

    $('#uploadcert').on('click',()=>{
        $('#status').addClass('alert-danger');
        $('#status').text("Please Wait");
        var formdata = new FormData();
        
        formdata.append('name',name);
        formdata.append('file',$('#bspdf').val());
        
        //console.log(formdata.get('name')+"file "+formdata.get('file'));
       
        $.ajax({
        url: 'upload.php', // point to server-side PHP script 
        dataType: 'text',  // what to expect back from the PHP script, if anything
        cache: false,
        contentType: false,
        processData: false,
        data: formdata,                         
        type: 'post',
        success: function(php_script_response){
           console.log(php_script_response); // display response from the PHP script, if any
           $('#status').addClass('alert-success');
        $('#status').text("CPDF Uploaded");
        window.location.href="user-all-customer-data.php";
        
        }
     });

        
    })


}
$('#upload').on('click',()=>{
    //alert("upload");
    console.log(this.event.target.getAttribute('data'));
    var name = this.event.target.getAttribute('data');

   


});
</script>

<!-- modal view -->
		<style>
		tbody tr td
		{
			padding:6px !important;
		}
		thead tr th
		{
			text-align:center !important;
		}
		</style>						-->
    <!-- ============================================================== -->
    <!-- Common Plugins -->

    <script src="assets/lib/jquery/dist/jquery.min.js"></script>
    <script src="assets/lib/bootstrap/js/popper.min.js"></script>
    <script src="assets/lib/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/lib/pace/pace.min.js"></script>
    <script src="assets/lib/jasny-bootstrap/js/jasny-bootstrap.min.js"></script>
    <script src="assets/lib/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="assets/lib/nano-scroll/jquery.nanoscroller.min.js"></script>
    <script src="assets/lib/metisMenu/metisMenu.min.js"></script>
    <script src="assets/js/custom.js"></script>
    <!-- Datatables-->
    <script src="assets/lib/datatables/jquery.dataTables.min.js"></script>
    <script src="assets/lib/datatables/dataTables.responsive.min.js"></script>
    <script src="assets/lib/datatables/dataTables.buttons.min.js"></script>
    <script src="assets/lib/datatables/jszip.min.js"></script>
    <script src="assets/lib/datatables/pdfmake.min.js"></script>
    <script src="assets/lib/datatables/vfs_fonts.js"></script>
    <script src="assets/lib/datatables/buttons.html5.min.js"></script>
   <script>
    $(document).ready(function() {
        $('#datatable1').DataTable({
            dom: 'Bfrtip',
            pageLength: 100,
            buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                'pdfHtml5'
            ]
        });
    });

    </script>
</body>

</html>