<?php
    session_start();
   
    include "../../../db.php";
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('M j, Y g:i a');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) )
        header("Location: logout.php");
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php include "includes/meta.php"; ?>
    <?php include "includes/css.php"; ?>
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link href="css/alltable.css" rel="stylesheet">


</head>

<body>

    <!--==========================
  Header
  ============================-->
    <?php include "includes/header2.php"; ?>

    <!-- #header -->

    <!--==========================
    Intro Section
  ============================-->
    <div class="container">
        <div class="row mx-0 just ify-content-center">
            <div class="col-12 col-sm-12 col-md-12">
                <div class="card-body">
                    <h1 class="h3 mb-2 text-gray-800 text-center text-sm-left" style="margin-top: 90px">Submited
                        Testimonial
                    </h1>
                    <hr>



                    <div class="row m-0">

                        <div class="col-md-12 p-0">
                            <div class="table-responsive">
                                <table class="table table-hover table-bordered table-sm" id="thisismytable">
                                    <thead>
                                        <tr>
                                            <th style='max-width:100px'>No.</th>
                                            <th>Details</th>
                                            <th>Message</th>

                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            $sql = "SELECT * FROM data_table  WHERE refid = '$_SESSION[uid]' AND recycle = '3' ORDER BY id DESC";
                                            $run = mysqli_query($con, $sql);

                                            $c = 1;
                                            while ( $rows = mysqli_fetch_assoc($run) )
                                                {
                            
                                                echo "
                                                    <tr>
                                                        <td>
                                                            <span class='badge badge-info badge-pill'>$c</span>
                                                        </td>
                                                        <td class='text-center align-middle small'>
                                                         
                                                        <br>
                                                        Date -: $rows[up_date]<br>
                                                        Name : $rows[title]
                                                        <br>
                                                        Designation : $rows[title_two]
                                                        <br>
                                                        Contact : $rows[seo_title]
                                                        <br>
                                                        Email id :  $rows[seo_alt]
                                
                                                        </td>
                                                        <td class='text-center align-middle small'>
                                                        Message :   $rows[short_des]
                                                            </td>
                                                            
                                                            <td class='text-center align-middle'>  
                                                            <br>
                                                                <a href='testimonial-submit.php?update_id=$rows[id]' class='m-2 btn btn-success btn-sm rounded-circle' title='Click to Add Testimonial'> <i class='fas fa-plus'></i> </a> 
                                                            <br>
                                                                <a href='testimonial-submit.php?update_id=$rows[id]' class='delete m-2 btn btn-danger btn-sm rounded-circle' title='Click to Delete'> <i class='fas fa-trash'></i> </a>
                                                                
                                                            </td>
                                                        </tr>
                                                        ";
                                                        $c++;
                                                    }
                                                ?>
                                    </tbody>
                                </table><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>



    <!--==========================
    Footer
  ============================-->
    <?php include "includes/ft.php"; ?>

    <!-- #footer -->

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.easing.min.js"></script>
    <script src="js/sb-admin-2.min.js"></script>
    <script src="js/sweetalert2.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap4.min.js"></script>
    <script src="js/datatables.mark.min.js"></script>
    <script src="js/jquery-ui-custom.min.js"></script>
    <script src="js/custom.js"></script>

    <script src="js/mobile-nav/mobile-nav.js"></script>


    <script>
    $(document).ready(function() {
        $('#thisismytable').DataTable();
        $('#show-img').on('show.bs.modal', function(e) {
            var src = $(e.relatedTarget).attr('src');
            $(this).find('.modal-body > img').attr('src', src);
        });
    });

    var $sortable = $("#thisismytable > tbody");

    $sortable.sortable({
        stop: function(event, ui) {
            var parameters = $sortable.sortable("toArray");
            $.post("slider_position.php", {
                value: parameters
            }, function(result) {
                $(document).ready(function() {
                    const Toast = Swal.mixin({
                        toast: true,
                        position: 'bottom',
                        showConfirmButton: false,
                        timer: 2000
                    });
                    Toast.fire({
                        type: 'success',
                        title: result
                    });
                });
            });
        }
    });
    </script>
</body>

</html>




<?php
    if ( isset($_GET["update_id"]) ) {

       
        unlink($_GET["path"]);
        $del_sql = "UPDATE data_table SET recycle = '1' WHERE id = '$_GET[update_id]'";
        // echo '<pre>';print_r($del_sql);exit();
        if ( mysqli_query($con, $del_sql) ) {
            ?>
<script>
window.location = "index.php";
</script>
<?php
        } else {
            ?>
<script>
alert('OOPS !!!!');
setTimeout(() => {
    window.location = 'testimonial-submit.php';
}, 1200);
</script>
<?php
        }
    }
    

?>

<?php
    if ( isset($_GET["del_id"]) ) {

       
        unlink($_GET["path"]);
        $del_sql = "DELETE FROM data_table WHERE id = '$_GET[del_id]'";
        // echo '<pre>';print_r($del_sql);exit();
        if ( mysqli_query($con, $del_sql) ) {
            ?>
<script>
window.location = "testimonial-submit.php";
</script>
<?php
        } else {
            ?>
<script>
alert('OOPS !!!!');
setTimeout(() => {
    window.location = 'testimonial-submit.php';
}, 1200);
</script>
<?php
        }
    }
    

?>