<?php
session_start();
include 'include/config.php';

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

<?php  include 'include/head.php'; 

// $id = $_GET['id'];
// $sel = "select * from `vidharmi` where `id`='$id'";
// $qu = mysqli_query($conn,$sel);
// $res = mysqli_fetch_array($qu);




?>
                    
    <!-- Start Content-->
    <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Add Vidharmi</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Add Vidharmi</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 

                        <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body">

                    
                    
                    <?php
       if(isset($_POST['submit'])){
    $heading = $_POST['heading'];
    $content = strip_tags($_POST['content']);

    // Check if a new image is uploaded
    if(!empty($_FILES['image']['name'])) {
        $image = $_FILES['image']['name'];
        $tmp_name = $_FILES['image']['tmp_name'];
        $image_url = 'upload/image/' . $image;

        // Update the database with the new image information
        // $sql = "UPDATE `vidharmi` SET `heading`='$heading',`discreption`='$content',`banner_img`='$image_url' WHERE `id`='$id'";
        $sql = "INSERT INTO `vidharmi`(`heading`, `discreption`, `banner_img`) VALUES ('$heading','$content','$image_url')";
        $res = mysqli_query($conn, $sql);

        if($res) {
            // Move the new image to the upload directory
            move_uploaded_file($tmp_name, '../upload/image/' . $image);
            echo "<h6> VDharmi Add successfully </h6>";
        } else {
            echo "<h6> Update Failed </h6>";
        }
    } 
}
?>
                    <form action=""  method="POST" enctype="multipart/form-data">
                                
                                    <!-- end nav-->
                                    <div class="tab-content">
                                        <div class="tab-pane show active">
                                            <div class="row">
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Image(image Type:JPEG,PNG,Jpg)</label>
                                                        <input type="file" value="" name="image" class="form-control" placeholder="Give image" required>
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Heading</label>
                                                        <input type="text" value="" name="heading" class="form-control" placeholder="offer code">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Discretion</label>
                                                          <textarea name="content" id="editor">
                                                              </textarea>                                                    
                                                              </div>
                                                </div>


                                            </div>

                                            <div class="row">
                                                <div class="clearfix"></div>
                                                <div class="col-lg-6">
                                                    <!-- Predefined Date Ranges -->
                                                    <div class="mb-3">
                                                        <input type="submit" class="btn btn-success" value="submit" name="submit">
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- end preview-->

                                        
                                        <!-- end preview code-->
                                    </div>
                                    <!-- end tab-content-->
                    </form>
                                </div>
                                <!-- end card-body -->
                            </div>
                            <!-- end card-->
                        </div>
                            <!-- end col -->
            </div> <!-- end row-->


                    
    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>
            <script src="https://cdn.ckeditor.com/ckeditor5/11.0.1/classic/ckeditor.js"></script>

<!-- editor -->
        // <script src='https://cdn.ckeditor.com/4.13.0/standard/ckeditor.js'></script>
        // <script src='https://code.jquery.com/jquery-3.4.1.min.js'></script>
        // <script id="rendered-js" >
        //     CKEDITOR.replace('editor1');
        //     CKEDITOR.on('instanceReady', function (evt)
        //     {
        //     var editor = evt.editor;

        //     editor.on('change', function (e) {
        //         var contentSpace = editor.ui.space('contents');
        //         var ckeditorFrameCollection = contentSpace.$.getElementsByTagName('iframe');
        //         var ckeditorFrame = ckeditorFrameCollection[0];
        //         var innerDoc = ckeditorFrame.contentDocument;
        //         var innerDocTextAreaHeight = $(innerDoc.body).height();
        //         console.log(innerDocTextAreaHeight);
        //     });
        //     });
            //# sourceURL=pen.js
        </script>
        
        <script>

        ClassicEditor
            .create( document.querySelector( '#editor' ) )
            .catch( error => {
                console.error( error );
            } );
    </script>