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

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

<?php  include 'include/head.php'; ?>
                    
    <!-- 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 Banner</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Add Banner</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'])){
                        $code = $_POST['code'];
                        $value = $_POST['value'];
                        $image = $_FILES['image']['name'];
                        $tmp_name = $_FILES['image']['tmp_name'];
                        $image_url = 'https://bemangalam.com/MAGLAM/banner_image/' . $image;

                                        
                        //  $sql = "INSERT INTO `offer_banner`(`offer_banner_image_url`, `offer_code`, `offer_value`) VALUES ('$image_url','$code','$value')";
                            $sql = "INSERT INTO `banner_img`(`image_url`) VALUES ('$image_url')";
                        // print_r($sql);
                         $res = mysqli_query($conn,$sql);
                        if($res){
                           move_uploaded_file($tmp_name, '../banner_image/'.$image);
                            echo "<h6> Banner Submit </h6>";
                        }else{
                            echo "<h6> Not Submit Notifications</h6>";
                        }
                                        
                    }

                    // if(isset($_GET['id'])){
                    //     $id = $_GET['id'];
                    //     $url = 'update-notification.php?id='. $id ;

                    //     $sql1 = "SELECT * FROM notification WHERE id='$id' ";
                    //     $res1 = mysqli_query($conn, $sql1);
                    //     $row = mysqli_fetch_assoc($res1);
                    // }
                    ?>
                    <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">Banner Image(image Type:JPEG,PNG,Jpg)</label>
                                                        <input type="file" value="" name="image" class="form-control" placeholder="Give image">
                                                    </div>
                                                </div>
                                                
                                                <!--<div class="col-lg-12">-->
                                                    <!-- Date Range Picker With Times -->
                                                <!--    <div class="mb-3">-->
                                                <!--        <label for="example-select" class="form-label">Offer Code</label>-->
                                                <!--        <input type="text" value="" name="code" 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">Offer Value</label>-->
                                                <!--        <input type="text" value="" name="value" class="form-control" placeholder="offer value">-->
                                                <!--    </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'; 
?>
<!-- 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>