<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : View Resume</title>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
    <?php include("headerlink.php") ?>
</head>

<body class="hold-transition sidebar-mini">
    <div class="wrapper">

        <?php include("navbar.php") ?>

        <?php include("sidebar.php") ?>

        <div class="content-wrapper">

            <section class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class=" text-bold text-uppercase">Resume</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item"><a href="#">Resume</a></li>
                                <li class="breadcrumb-item active">View All</li>
                            </ol>
                        </div>
                    </div>

                </div>

            </section>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="card shadow">
                                <div class="card-header" style="background: #343a40; ">
                                <div class="row">
                                    <div class="col-10">
                                    <h3 class="card-title text-white text-bold text-uppercase pt-1">All Resume</h3>
                                    </div>
                                    <div class="col-2 text-end">
                                    <button class="btn btn-danger btn-sm fw-bold" onclick="downloadCSV()">Download CSV</button>

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


                                <div class="card-body">
                                    <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                                        <div class="row">
                                            <div class="col-sm-12 col-md-6">
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <table class="table-responsive">
                                                <table id="example2" class="table text-center table-bordered table-hover dataTable dtr-inline display" aria-describedby="example2_info">
                                                        <thead>
                                                            <tr>
                                                                <th>Sr No.</th>
                                                                <th>Date</th>
                                                                <th>Name</th>
                                                                <th>Number</th>
                                                                <th>Email</th>
                                                                <th>Profile</th>
                                                                <th>Salary Expectations</th>
                                                                <th>Experience</th>
                                                                <th>Location</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php

                                                            include('connection.php');

                                                            $sql = "SELECT * FROM add_resume ";
                                                            $query = mysqli_query($conn, $sql);
                                                            while ($row = mysqli_fetch_assoc($query)) {

                                                            ?>
                                                                <tr>
                                                                    <td><?php echo $row['id']?></td>
                                                                    <td> <?php echo $row['date'] ?></td>
                                                                    <td><?php echo $row['full_name'] ?></td>
                                                                    <td><?php echo $row['number'] ?></td>
                                                                    <td><?php echo $row['email'] ?></td>

                                                                    <td class="view-details-button fw-bold text-danger text-uppercase" style="text-decoration: none; " data-toggle="modal" data-target="#detailsModal<?php echo $row['id']; ?>">
                                                                        <?php echo $row['work_profile'] ?>
                                                                    </td>
                                                                    <td><?php echo $row['salary_expectations'] ?></td>
                                                                    <td><?php echo $row['work_experience'] ?></td>
                                                                    <td><?php echo $row['location'] ?></td>

                                                                </tr>

                                                            <?php } ?>
                                                        </tbody>

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

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>
        </div>

        <?php include("footer.php") ?>

    </div>

    <?php
    $query = "SELECT * FROM add_resume";
    $result = mysqli_query($conn, $query);
    while ($row = mysqli_fetch_assoc($result)) {
    ?>

        <div class="modal fade" id="detailsModal<?php echo $row['id']; ?>">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header" style="background: #343a40; ">
                        <h4 class="modal-title text-white fw-bold text-uppercase">Name : <?php echo $row['full_name'] ?></h4>
                        <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" action="update_resume_code.php" enctype="multipart/form-data">
                            <div class="card-body">
                                <div class="row">
                                    <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">First Name</label>
                                            <input type="text" class="form-control" name="first_name" placeholder="First Name" value="<?php echo $row['full_name']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Marital Status</label>
                                            <select name="marital_status" class="form-control">
                                                <option value="Single" <?php if ($row['marital_status'] == "Single") echo "selected"; ?>>Single
                                                </option>
                                                <option value="Married" <?php if ($row['marital_status'] == "Married") echo "selected"; ?>>
                                                    Married</option>
                                                <option value="Divorced" <?php if ($row['marital_status'] == "Divorced") echo "selected"; ?>>
                                                    Divorced</option>
                                                <option value="Widowed" <?php if ($row['marital_status'] == "Widowed") echo "selected"; ?>>
                                                    Widowed</option>
                                                <option value="Other" <?php if ($row['marital_status'] == "Other") echo "selected"; ?>>Other
                                                </option>
                                            </select>
                                        </div>
                                    </div>


                                </div>

                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Contact Email</label>
                                            <input type="email" class="form-control" name="email" placeholder="Contact Email" value="<?php echo $row['email'] ?>">
                                        </div>
                                    </div>

                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Contact Number</label>
                                            <input type="text" class="form-control" id="exampleInputName" placeholder="Contact Number" value="<?php echo $row['number'] ?>" name="number" oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                        </div>
                                    </div>

                                </div>
                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Work Profile</label>
                                            <input type="text" class="form-control" name="profile" placeholder="Work Profile" value="<?php echo $row['work_profile'] ?>">
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Work Experience</label>
                                            <input type="text" class="form-control" name="experience" placeholder="Work Experience" value="<?php echo $row['work_experience'] ?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputName">Current Location</label>
                                            <input type="text" class="form-control" placeholder="Current Location" name="location" value="<?php echo $row['location'] ?>">
                                        </div>
                                    </div>

                                    <div class="col-6">
                                        <label for="exampleInputName">Upload Resume</label>

                                        <div class="custom-file">
                                            <input type="file" class="custom-file-input" id="file" name="file" onchange="displayFileName()">
                                            <label class="custom-file-label" for="file"><?php echo $row['resume']; ?></label>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-12  ">
                                        <div class="form-group">
                                            <label for="exampleInputName">Salary Expectations </label>
                                            <input type="text" value="<?php echo $row['salary_expectations'] ?>" name="salary_expectations" class="form-control" placeholder="Salary Expectations">
                                        </div>
                                    </div>
                                </div>



                                <label for="exampleInputEmail1">Social Icons</label>
                                <div class="row">
                                    <div class="col-6">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <a href="<?php echo $row['linkedin']; ?>" target="_blank" class="input-group-text">
                                                    <i class="nav-icon fa fa-linkedin"></i>
                                                </a>
                                            </div>

                                            <input type="text" class="form-control" value="<?php echo $row['linkedin']; ?>" name="linkedin_username" placeholder="LinkedIn Username">
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <a href="<?php echo $row['whatsapp_username']; ?>" target="_blank" class="input-group-text">
                                                    <i class="nav-icon fa fa-whatsapp fw-bold"></i>
                                                </a>
                                            </div>

                                            <input type="text" class="form-control" value="<?php echo $row['whatsapp_username']; ?>" name="whatsapp_username" placeholder="LinkedIn Username">
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="submit" class="btn text-white fw-bold" style="background: #343a40;">Update
                                    changes</button>
                            </div>
                        </form>


                    </div>

                </div>

            </div>

        </div>
    <?php } ?>


    <?php include("footerlink.php") ?>
    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
    <script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
    <script src="../../plugins/jszip/jszip.min.js"></script>
    <script src="../../plugins/pdfmake/pdfmake.min.js"></script>
    <script src="../../plugins/pdfmake/vfs_fonts.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.print.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>

    <script>
        $(document).ready(function() {
            <?php if (isset($_GET['error'])) { ?>
                Swal.fire({
                    title: 'Error',
                    text: '<?php echo $_GET['error']; ?>',
                    icon: 'error',
                    confirmButtonText: 'OK',
                    confirmButtonClass: 'btn btn-success btn-lg',
                });
            <?php } ?>
            <?php if (isset($_GET['success'])) { ?>
                Swal.fire({
                    title: 'Success',
                    text: '<?php echo $_GET['success']; ?>',
                    icon: 'success',
                    confirmButtonText: 'OK',
                    confirmButtonClass: 'btn btn-success btn-lg',
                });
            <?php } ?>
        });
    </script>

<script>
  function downloadCSV() {
    // Prepare data to be exported as CSV
    const table = document.querySelector('#example2');

    const rows = Array.from(table.querySelectorAll('tbody tr'));
    const headers = Array.from(table.querySelectorAll('thead th'));
    
    const csvData = [headers.map(header => `"${header.textContent.trim().replace(/"/g, '""')}"`).join(',')]; // Include table headers
    
    csvData.push(...rows.map(row => {
        const cols = Array.from(row.querySelectorAll('td'));
        return cols.map(col => {
            return `"${col.textContent.trim().replace(/"/g, '""')}"`;
        }).join(',');
    }));

    // Create a Blob containing the CSV data
    const blob = new Blob([csvData.join('\n')], {
        type: 'text/csv'
    });

    // Create a link to trigger the download
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'resume_data.csv';
    a.style.display = 'none';

    // Trigger the click event to download the file
    document.body.appendChild(a);
    a.click();

    // Clean up
    window.URL.revokeObjectURL(url);
}

</script>
    
    <script>
        // Use noConflict to avoid conflicts with other scripts
        var $j = jQuery.noConflict();
        $j(document).ready(function() {
            $j('#example2').DataTable();
        });
    </script>
</body>

</html>