<?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"> 
    <link rel="stylesheet" href="vendor/croppie/croppie.css" /> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
 
    
</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">Review Article</h1>
                            <hr>

                            <a href="blog.php" class="btn btn-success mt-2 mb-4"> Write New Article <i class="fas fa-newspaper"></i> </a>

                            <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>Blog Index</th>
                                                   
                                                    <th >Action</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                    $sql = "SELECT * FROM blog  WHERE bby = '$_SESSION[uid]' ORDER BY bid DESC";
                                                    $run = mysqli_query($con, $sql);

                                                    $c = 1;
                                                    while ( $rows = mysqli_fetch_assoc($run) )
                        {
                           $trimmedTitle = mb_strimwidth($rows['btitle'], 0, 20, "...");    
                                                        echo "
                                                        <tr>
                                                            
                                                            <td class='text-center align-middle small'>

                                                     <a href='blog-details.php?id=$rows[bid]' cl ass='btn btn-primary btn-sm'>    $trimmedTitle</a>
                                                            <br>
                                                        
                                                        ";
                                                            $fetch_user = mysqli_query($con, "SELECT cname FROM category WHERE cid = '$rows[bcat]'");
                                                            $fetch_u_row = mysqli_fetch_assoc($fetch_user);

                                                            echo ucwords($fetch_u_row["cname"]);

                                                            echo" 
                                
                                                                <br>
                                                                      
                                                              $rows[bcreated]<br>
                                                              $rows[bupdated]<br>





                                                         
                               <a href='http://www.facebook.com/share.php?u=";
   $fetch_user = mysqli_query($con, "SELECT uweburl FROM users WHERE uid = '$rows[badmin2]'");
       $fetch_u_row = mysqli_fetch_assoc($fetch_user);
               echo ucwords($fetch_u_row["uweburl"]);
 echo"/Single_allCat.php?id=$rows[bid]$rows[btag]/'  target='_blank' style='padding:2px 7px 2px 7px; margin-top: 5px; center;text-decoration: none;  
 background: #3B5998; color: white;' class='btn btn-succe ss mt -2 mb -4'><i class='fa fa-facebook'></i> </a>
&nbsp;
  <a href='https://api.whatsapp.com/send?text=";  echo"$rows[btitle]            ";
   $fetch_user = mysqli_query($con, "SELECT uweburl FROM users WHERE uid = '$rows[badmin2]'");
       $fetch_u_row = mysqli_fetch_assoc($fetch_user);
     
               echo ucwords($fetch_u_row["uweburl"]);
 echo"/Single_allCat.php?id=$rows[bid]$rows[btag]/'  target='_blank' style='padding:2px 5px 2px 5px;margin-top: 5px; center;text-decoration: none;  
 background: #25d366; color: white;' class='btn btn-succe ss mt -2 mb -4'> <i class='fa fa-whatsapp'></i> </a>

                                  <a href='";
                                                            $fetch_user = mysqli_query($con, "SELECT uweburl FROM users WHERE uid = '$rows[badmin2]'");
                                                            $fetch_u_row = mysqli_fetch_assoc($fetch_user);

                                                            echo ucwords($fetch_u_row["uweburl"]);

                                                            echo"/Single_allCat.php?id=$rows[bid]$rows[btag]/'  target='_blank' style='padding:0px 5px 2px 5px; margin-top: 5px; center;text-decoration: none;  background: #3B5998;; color: white;' class='btn btn-succe ss mt -2 mb -4'> <i class='fa fa-globe'></i> </a>
                                           &nbsp;
<i class='fa fa-eye' aria-hidden='true'></i>   $rows[bcount]
                                                           
                                
                                                            </td>
                                                            
                                                            <td class='text-center align-middle'>
                                                                <a href='edit-blog.php?edit_id=$rows[bid]' class='m-2 btn btn-success btn-sm rounded-circle' title='Click to Edit'> <i class='fas fa-pencil-alt'></i> </a>
<br>
                                                                <a href='review-blog.php?del_id=$rows[bid]&path=$rows[bimage]' 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>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
         </div>      
</div>

               <?php include "includes/ft.php"; ?>

 <!--==========================
    Footer
  ============================-->

  
  <!-- #footer -->

    <div class="modal fade" id="show-img" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <img src="" alt="sliderImage" id="image_modal" class="w-100">
                    <p class="small mt-3 mb-2" id="dimension"> <span class="font-weight-bold"> Name </span> : </p>
                    <p class="small mb-2" id="dimension"> <span class="font-weight-bold"> Dimension </span> : </p>
                    <p class="small mb-2" id="dimension"> <span class="font-weight-bold"> Size </span> : </p>
                </div>
                <div class="modal-footer">
                    <button type="close" class="btn btn-secondary" data-dismiss="modal"> Close </button>
                </div>
            </div>
        </div>
    </div>





    <script>
        function checkFileDetails() {
            var fi = document.getElementById('file');
            if (fi.files.length > 0) {
                for (var i = 0; i <= fi.files.length - 1; i++) {
                    var fileName, fileExtension, fileSize, fileType, dateModified;
                    fileName = fi.files.item(i).name;
                    fileExtension = fileName.replace(/^.*\./, '');
                    if (fileExtension == 'png' || fileExtension == 'jpg' || fileExtension == 'jpeg') {
                        readImageFile(fi.files.item(i));
                    }
                }
                function readImageFile(file) {
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        var img = new Image();
                        img.src = e.target.result;
                        img.onload = function () {
                            var imgWidth = this.width;
                            var imgHeight = this.height;

                            if ( imgWidth == 1200 && imgHeight == 512 || imgWidth == 1500 && imgHeight == 640 ) {
                                var imgCheck = "<i class='fas fa-check-circle text-success'></i>";
                            } else {
                                var imgCheck = "<i class='fas fa-times-circle text-danger'></i>";
                            }
                            document.getElementById('fileInfo').innerHTML =
                                document.getElementById('fileInfo').innerHTML + '<br> ' +
                                'Name: <b>' + file.name + '</b> <br>' +
                                'Size: <b>' + Math.round((file.size / 1024)) + '</b> KB <br>' +
                                'Dimension: <b>' + imgWidth + '</b> x <b>' + imgHeight + '</b> ' + imgCheck + ' <br>';
                        }
                    };
                    reader.readAsDataURL(file);
                }
            }
        }
    </script>



 
    <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="vendor/croppie/croppie.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["del_id"]) ) {

        unlink($_GET["path"]);
        $del_sql = "DELETE FROM blog WHERE bid = '$_GET[del_id]'";
 
        if ( mysqli_query($con, $del_sql) ) {
            ?>
            <script>window.location = "review-blog.php";</script>
            <?php
        } else {
            ?>
            <script>
                alert('OOPS !!!!');
                setTimeout(() => {
                    window.location = 'review-blog.php';
                }, 1200);
            </script>
            <?php
        }
    }
    if(isset($_POST['edit_users'])){
        $uname = mysqli_real_escape_string($con, strip_tags($_POST['uname']));
        $uphone = mysqli_real_escape_string($con, strip_tags($_POST['uphone']));
        $upass = mysqli_real_escape_string($con, strip_tags($_POST['upass']));
        $uabout = mysqli_real_escape_string($con, strip_tags($_POST['uabout']));
        $chk_ph = mysqli_query($con, "SELECT uphone FROM users WHERE uname != '$uname' AND uphone = '$uphone'");
        $chk_ph_count = mysqli_num_rows($chk_ph);
        if ( $chk_ph_count < 1 ) {
            $up_sql = "UPDATE users SET uname = '$uname', uphone = '$uphone', upass = '$upass', uabout = '$uabout' WHERE uid = '$_GET[edit_id]'";
    
            if(mysqli_query($con, $up_sql)){
                ?>
                <script>window.location = 'review-blog.php';</script>
                <?php
            }
            else{
                ?>
                <script>
                    alert('OOPS !!!!');
                    setTimeout(() => {
                        window.location = 'review-blog.php';
                    }, 1200);
                </script>
                <?php
            }
        } else {
            ?>
            <script>
                alert('Mobile Number Exists');
                setTimeout(() => {
                    window.location = 'admin_lvl2.php?edit_id=<?php echo $_GET["edit_id"]; ?>';
                }, 500);
            </script>
            <?php
        }
    }

?>