<div class="row">
    <div class="col-xl-12">
        <div class="card border border-info">
            <div class="card-body">
            <h4 class="card-title"><i class="fas fa-plus"></i> Tambahkan Panduan</h4>
                <form method="POST" action="config/add-panduan.php" class="form-horizontal">
                        <button type="submit" class="btn btn-primary"><i class="fas fa-check"></i> Tambah Baru</button>
                </form>
            </div>
        </div>
    </div>
    </div>

        <?php
        
        $results_per_page = 10;
        $sql= "SELECT * FROM panduan_post WHERE category_panduan = 'panduan'";
        $result = mysqli_query($data, $sql);
        $number_of_results = mysqli_num_rows($result);
        
        $number_of_pages = ceil($number_of_results/$results_per_page);
        
        if (!isset($_GET['no'])) {
          $page = 1;
        } else {
          $page = $_GET['no'];
        }
        
        $this_page_first_result = ($page-1)*$results_per_page;

            $spromo = "SELECT * FROM panduan_post WHERE category_panduan = 'panduan' ORDER BY tanggal_panduan DESC LIMIT ".$this_page_first_result." ,".$results_per_page;
            $qpromo = mysqli_query($data, $spromo);

            if(mysqli_num_rows($qpromo) > 0) {

                $x2 = 1;
                $x3 = 1;
                $x4 = 1;

                while($fpromo = mysqli_fetch_assoc($qpromo)) {

                    $imgpromo = $fpromo['thumbnail_panduan'];
                    $title = $fpromo['title_panduan'];
                    $shortd = $fpromo['short_dec_panduan'];
                    $promo = $fpromo['content_panduan'];
                    $tglpromo = $fpromo['tanggal_panduan'];
                    $idpromo = $fpromo['id'];
                    $stat = $fpromo['panduan_status'];

                    echo '<div>
                    <div class="card my-2 border border-info">
                        <form method="POST" action="config/update-panduantxt.php?row='.$idpromo.'" class="form-horizontal">
                            <div class="card-body position-relative">
                                    <h4 class="card-title"><i class="fas fa-dollar-sign"></i> Panduan #'.$x2++.'</h4>
                                        <div style="position:absolute; right: 0; top: 0;">';
                                            if($stat == 0){
                                                echo '<a href="config/up-panduan.php?stat=1&row='.$idpromo.'" class="btn btn-success"><i class="fas fa-check"></i> Publikasikan Artikel #'.$x4++.'?</a>';
                                            } else {
                                                echo '<a href="config/up-panduan.php?stat=0&row='.$idpromo.'" class="btn btn-warning"><i class="fas fa-times"></i> Sembunyikan Artikel #'.$x4++.'?</a>';
                                            }
                                        
                                         echo'   <a href="config/delete-panduan.php?row='.$idpromo.'" class="btn btn-danger"><i class="fas fa-times"></i> Hapus Panduan #'.$x3++.'</a>
                                        </div>
                                        <div class="clear-fix"></div>
                                        <div class="input-group my-3">
                                            <span class="input-group-text"><i class="fas fa-font"></i></span>
                                            <input type="text" name="title-panduan" class="form-control" value="'.$title.'" placeholder="Judul Postingan.." required />
                                        </div>

                                        <div class="input-group my-3">
                                            <span class="input-group-text"><i class="fas fa-image"></i></span>
                                            <input type="text" name="img-panduan" class="form-control" value="'.$imgpromo.'" placeholder="Link Gambar Utama Postingan.." required />
                                        </div>

                                        <div class="input-group my-3">
                                            <span class="input-group-text"><i class="fas fa-list"></i></span>
                                            <input type="text" name="desc" class="form-control" value="'.$shortd.'" placeholder="Deskripsi Singkat.." required />
                                        </div>
                                        
                                        <small class="text-success font-weight-bold">Update pada : '.$tglpromo.' WIB</small><br />
                                        <img src="'.$imgpromo.'" width="500" alt="tidak ada gambar promo" /> <br />
                                        <small>'.$uploadgambar.'</small> <br />
                                        <textarea class="editor" name="panduan-page-text" style="height: 300px; width: 100%;">'.html_entity_decode($promo).'</textarea>
            
                                    <button type="submit" class="btn mt-3 btn-block btn-primary">Simpan Panduan</button>
                                       
                                    </form>
                             </div>
                             </div>';
                }
            } else {
                echo 'tidak ada promo!!';
            }
        ?>

      


<div class="row">
<div class="col-12">
                <div>
                    <nav>
                        <ul class="pagination" style="display: flex; flex-wrap: wrap;">
                            <?php 
                            // display the links to the pages
                                for ($page=1;$page<=$number_of_pages;$page++) {
                                echo ' <li class="page-item"><a class="page-link font-weight-bold" href="?hal=panduan&no=' . $page . '">' . $page . '</a></li>';
                                }

                            ?>
                            
                        </ul>
                    </nav>
                </div>
        </div>
</div>


<?php
        if(!isset($_SESSION['nama_pengguna'])) {
        echo '<script>
        window.location.replace("/");
        </script>';
        }
    ?>