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

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : All Contacts</title>
    <link href="docs/assets/img/favicon.ico" rel="shortcut icon" type="images/x-icon">
    <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 layout-fixed">
    <div class="wrapper">

        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>

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


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

        <div class="content-wrapper">

            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-bold text-uppercase">Phonebook</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 active">Phonebook</li>
                                <li class="breadcrumb-item active">View All</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <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; ">
                                    <h3 class="card-title text-white text-bold text-uppercase">All Contacts</h3>
                                </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 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 table-bordered table-hover dataTable dtr-inline display"
                                                        aria-describedby="example2_info">
                                                        <thead>
                                                            <tr>
                                                                <th>Date &amp; time</th>
                                                                <th>Purpose to add</th>
                                                                <th>Name</th>
                                                                <th>Number</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php

                                                            include('connection.php');
                                                            $sql = "SELECT * FROM add_contact ";
                                                            $query = mysqli_query($conn, $sql);
                                                            while ($row = mysqli_fetch_assoc($query)) {
                                                            ?>
                                                            <tr>
                                                                <td><?php echo $row['datetime']?></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['purpose_to_add']?>
                                                                </td>
                                                                <td><?php echo $row['name']?></td>
                                                                <td><?php echo $row['number1']?></td>

                                                            </tr>
                                                            <?php }?>
                                                        </tbody>

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

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>

        </div>
    </div>


    <?php 
    $query = "SELECT * FROM add_contact"; 
    $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; ">
                    <h5 class="modal-title fw-bold text-uppercase text-white">Name : <?php echo $row['name'];?></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 action="update_contact_code.php" method="POST">
                        <div class="card-body">
                            <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                            <div class="row">
                                <div class="col-lg-6 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputName">Name</label>
                                        <input type="text" name="name" class="form-control" id="exampleInputName"
                                            placeholder="Name" value="<?php echo $row['name']; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-6 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputPurpose">Purpose to Add</label>
                                        <input type="text" name="add" class="form-control" id="exampleInputPurpose"
                                            placeholder="Purpose to Purpose"
                                            value="<?php echo $row['purpose_to_add']; ?>">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-lg-8 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputCompany">Company Name</label>
                                        <input type="text" name="company_name" class="form-control"
                                            id="exampleInputCompany" placeholder="Company Name"
                                            value="<?php echo $row['company_name']; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-4 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputDesignation">GMB Page</label>
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <a href="<?php echo $row['gmb_page']; ?>" target="_blank"
                                                    class="input-group-text">
                                                    <i class="fab fa-google"></i>
                                                </a>
                                            </div>
                                            <input type="text" value="<?php echo $row['gmb_page']; ?>"
                                                name="gmb_page_username" class="form-control" placeholder="Google">
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-lg-4 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputContact1">Contact Number 1</label>
                                        <input type="text" class="form-control" value="<?php echo $row['number1']; ?>"
                                            id="exampleInputName" placeholder="Contact Number" name="number1"
                                            oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                    </div>
                                </div>
                                <div class="col-lg-4 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Contact Number 2</label>
                                        <input type="text" class="form-control" value="<?php echo $row['number2']; ?>"
                                            id="exampleInputName" placeholder="Contact Number" name="number2"
                                            oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                    </div>
                                </div>
                                <div class="col-lg-4 col-sm-12">
                                    <div class="form-group">
                                        <label for="exampleInputContact3">Contact Number 3</label>
                                        <input type="text" class="form-control" value="<?php echo $row['number3']; ?>"
                                            id="exampleInputName" placeholder="Contact Number" name="number3"
                                            oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                    </div>
                                </div>
                            </div>
                            <label for="exampleInputEmail1">Social Handels</label>
                            <div class="row">
                                <div class="col-lg-3 col-sm-12">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <a href="<?php echo $row['fb']; ?>" target="_blank"
                                                class="input-group-text">
                                                <i class="fab fa-facebook"></i>
                                            </a>
                                        </div>
                                        <input type="text" name="facebook_username" value="<?php echo $row['fb']; ?>"
                                            class="form-control" placeholder="Facebook">
                                    </div>
                                </div>
                                <div class="col-lg-3 col-sm-12">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <a href="<?php echo $row['twitter']; ?>" target="_blank"
                                                class="input-group-text">
                                                <i class="fab fa-twitter"></i>
                                            </a>
                                        </div>
                                        <input type="text" name="twitter_username"
                                            value="<?php echo $row['twitter']; ?>" class="form-control"
                                            placeholder="Twitter">
                                    </div>
                                </div>
                                <div class="col-lg-3 col-sm-12">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend ">
                                            <a href="<?php echo $row['insta']; ?>" target="_blank"
                                                class="input-group-text ">
                                                <i class="fab fa-instagram fw-bold"></i>
                                            </a>
                                        </div>
                                        <input type="text" name="instagram_username"
                                            value="<?php echo $row['insta']; ?>" class="form-control"
                                            placeholder="Instagram">
                                    </div>
                                </div>
                                <div class="col-lg-3 col-sm-12">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <a href="<?php echo $row['youtube']; ?>" target="_blank"
                                                class="input-group-text">
                                                <i class="fab fa-youtube"></i>
                                            </a>
                                        </div>
                                        <input type="text" name="youtube_username"
                                            value="<?php echo $row['youtube']; ?>" class="form-control"
                                            placeholder="Youtube">
                                    </div>
                                </div>
                            </div>

                        </div>


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

            </div>

        </div>

    </div>
    <?php }?>
    <?php include("footer.php")?>
    <?php include("footerlink.php")?>

    <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>
    var $j = jQuery.noConflict();
    $j(document).ready(function() {
        $j('#example2').DataTable();
    });
    </script>
</body>

</html>