<?php
require("header.php")
?>
<style>
    .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
        background: black;
    }

    .btn-group>.btn-group:not(:first-child)>.btn {
        background: black;
    }

    .page-item.active .page-link {
        background: black;
    }

    .dt-button-collection .dropdown-menu .buttons-columnVisibility {
        background-color: black;
    }
</style>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <!-- <h1>Add User</h1> -->
                </div>
                <div class="col-sm-6">

                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">

                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="card card-secondary">
                        <div class="card-header" style="background-color: black;">
                            <h3 class="card-title">Telegram</h3>
                            <ol class="breadcrumb float-sm-right" style="background-color: black;">
                                <li class="breadcrumb-item">Phonebook</li>
                                <li class="breadcrumb-item active">Telegram</li>
                            </ol>
                        </div>

                        <!-- /.card-header -->
                        <!-- form start -->
                        <section class="content">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="card shadow">
                                            <form action="add_telegram_code.php" method="POST">
                                                <div class="card-body">
                                                    <div class="row">
                                                        <div class="col-12 col-sm-4">
                                                            <div class="form-group">
                                                                <label>C/G Name</label>
                                                                <input type="text" required class="form-control" placeholder="Drop Shipper" name="cg_name">
                                                            </div>
                                                        </div>
                                                        <div class="col-12 col-sm-3">
                                                            <div class="form-group">
                                                                <label>C/G URL</label>
                                                                <input type="text" required class="form-control" placeholder="https://t.me/ghjvkkb" name="cg_url">
                                                            </div>
                                                        </div>
                                                        <div class="col-12 col-sm-2">
                                                            <div class="form-group">
                                                                <label>C/G Type</label>
                                                                <input type="text" required class="form-control" placeholder="Public" name="cg_type">
                                                            </div>
                                                        </div>
                                                        <div class="col-12 col-sm-2">
                                                            <div class="form-group">
                                                                <label>C/G Subscriber</label>
                                                                <input type="text" required class="form-control" placeholder="102515" name="cg_subscriber">
                                                            </div>
                                                        </div>
                                                        <div class="col-12 col-sm-1" style="margin-top: 23px;">
                                                            <button type="submit" class="btn btn-danger mt-2" style="background:black; border: none;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </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:black ; ">
                                                <h3 class="card-title text-white text-bold text-uppercase"> View All
                                                    Telegram
                                                </h3>
                                            </div>
                                            <!-- /.card-header -->
                                            <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 id="example2" class="table table-bordered table-hover dataTable dtr-inline display" aria-describedby="example2_info">
                                                                <thead>
                                                                    <tr>
                                                                        <th>Date &amp; time</th>
                                                                        <th>C/G Name</th>
                                                                        <th>C/G URL</th>
                                                                        <th>C/G Type</th>
                                                                        <th>C/G Subscriber</th>
                                                                        <th>Action</th>

                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php
                                                                    include('connection.php');

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


                                                                    ?>
                                                                        <tr>
                                                                            <td><?php echo $row['date_time'] ?></td>
                                                                            <td><?php echo $row['cg_name'] ?></td>
                                                                            <td><?php echo $row['cg_url'] ?></td>
                                                                            <td><?php echo $row['cg_type'] ?></td>
                                                                            <td><?php echo $row['cg_subscriber'] ?></td>

                                                                            <td class="project-actions">

                                                                                <a class="btn btn-info btn-sm" data-toggle="modal" data-target="#editContactModal<?php echo $row['id']; ?>" href="#">
                                                                                    <i class="fas fa-pencil-alt">
                                                                                    </i>
                                                                                    Edit
                                                                                </a>
                                                                                <a class="btn btn-danger btn-sm" href="delete_telegram.php?id=<?php echo $row['id']; ?>">
                                                                                    <i class="fas fa-trash">
                                                                                    </i>
                                                                                    Delete
                                                                                </a>
                                                                            </td>

                                                                        </tr>
                                                                        <!-- moadal start  -->
                                                                        <div class="modal fade" id="editContactModal<?php echo $row['id']; ?>">
                                                                            <div class="modal-dialog modal-lg">
                                                                                <div class="modal-content">
                                                                                    <div class="modal-header" style="background-color: black;">
                                                                                        <h4 class="modal-title"> Telegram Update</h4>
                                                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                                            <span aria-hidden="true">×</span>
                                                                                        </button>
                                                                                    </div>
                                                                                    <div class="modal-body">
                                                                                        <form action="add_telegram_channel.php" method="POST">
                                                                                            <div class="row">
                                                                                                <div class="col-12 col-md-6 col-lg-6">
                                                                                                    <div class="form-group">
                                                                                                        <label>C/G Name</label>
                                                                                                        <input type="text" required class="form-control mb-1" placeholder="Enter Channel Name" name="cg_name" value="<?php echo $tele_channel_row['tele_channel']; ?>">
                                                                                                    </div>
                                                                                                </div>
                                                                                                <div class="col-12 col-md-6 col-lg-6">
                                                                                                    <div class="form-group">
                                                                                                        <label>C/G URL</label>
                                                                                                        <input type="text" required class="form-control mb-1" name="cg_url" placeholder="Enter Channel Url" value="<?php echo $tele_channel_row['channel_url']; ?>">
                                                                                                    </div>
                                                                                                </div>
                                                                                            </div>
                                                                                            <div class="row">
                                                                                                <div class="col-12 col-md-6 col-lg-6">
                                                                                                    <div class="form-group">
                                                                                                        <label>C/G Type</label>
                                                                                                        <input type="text" required class="form-control mb-1" placeholder="Enter Channel Name" name="cg_type" value="<?php echo $tele_channel_row['tele_channel']; ?>">
                                                                                                    </div>
                                                                                                </div>
                                                                                                <div class="col-12 col-md-6 col-lg-6">
                                                                                                    <div class="form-group">
                                                                                                        <label>C/G Subscriber</label>
                                                                                                        <input type="text" required class="form-control mb-1" name="cg_subscriber" placeholder="Enter Channel Url" value="<?php echo $tele_channel_row['channel_url']; ?>">
                                                                                                    </div>
                                                                                                </div>
                                                                                            </div>

                                                                                            <div class="modal-footer justify-content-between">
                                                                                                <button type="button" class="btn btn-dark btn-sm" style="background-color: black;" data-dismiss="modal">Close</button>
                                                                                                <button type="submit" class="btn btn-dark btn-sm" style="background-color: black;" name="add"> <i class="fa fa-book"></i> Add Data</button>
                                                                                            </div>
                                                                                        </form>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                        <!-- moadal end -->




                                                                    <?php } ?>
                                                                    <!-- Add more rows as needed -->
                                                                </tbody>

                                                            </table>


                                                            <!-- /.modal-content -->
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>
                                            <!-- /.card-body -->
                                        </div>

                                    </div>
                                    <!-- /.col -->
                                </div>

                            </div>

                        </section>
                    </div>
                    <!-- /.card -->




                </div>

            </div>

            <!-- /.col -->
        </div>
        <!-- /.row -->

        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>
<!-- for searching -->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>

<script>
    $().ready(function() {
        $("#gnrt_pass").click(function() {
            var randomstring = Math.random().toString(36).slice(-8);
            $("input[name=password]").val(randomstring);
        })
    })
</script>
<!-- searching end -->

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<script>
    <?php if (isset($_GET['error'])) { ?>
        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: '<?php echo $_GET['error']; ?>',
        }).then(function() {
            window.location.href = 'add_telegram.php'; // Reload the page
        });
    <?php } ?>

    <?php if (isset($_GET['success'])) { ?>
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: '<?php echo $_GET['success']; ?>',
        }).then(function() {
            window.location.href = 'add_telegram.php'; // Reload the page
        });
    <?php } ?>
</script>
<!-- pagination -->


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