<?php
include 'classes/database.class.php';
include 'classes/admin.class.php';

if (isset($_POST['submit'])) {

    $name = $_POST['name'];
    $description = $_POST['description'];
    $second_description = $_POST['second_description'];

    if ($second_description == "") {
        $second_description = "empty";
    }
    $id = uniqid();
    $filename = $_FILES["image1"]["name"];
    $tempname = $_FILES["image1"]["tmp_name"];
    $folder = "product_images/" . $id . $filename;
    $image1 = $id . $filename;
    $uploaded = move_uploaded_file($tempname, $folder);

    if ($uploaded) {
        $product_id = $admin->createProduct($name, $description, $second_description, $image1);
        $db->setQuery("INSERT INTO products_second_descriptions (product_id, description) VALUES ('$product_id', '$second_description');");

        $admin->goTo("upload-product", "success");
    } else {
        $admin->goTo("upload-product", "error");
    }
}

?>
<!doctype html>
<html lang="zxx">


<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="keywords" content="" />
    <title>Upload Product</title>
    <link href="http://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;600&amp;display=swap" rel="stylesheet">
    <!-- Template CSS -->
    <link rel="stylesheet" href="assets/css/style-liberty.css">

    <!-- Favicon -->
    <link href="assets/images/buralogo.png" rel="shortcut icon" />
</head>

<body>


    <body>
        <!-- New toolbar-->
        <style>
            * {
                box-sizing: border-box;
                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
            }
        </style>

        <!--header-->
        <?php include 'header.php'; ?>
        <!--/header-->
        <!--/inner-page-->

        <div class="inner-banner">
        </div>
        <section class="w3l-breadcrumb">
            <div class="container">
                <ul class="breadcrumbs-custom-path">
                    <li><a href="./">Home</a></li>
                    <li class="active"><span class="fa fa-arrow-right mx-2" aria-hidden="true"></span> Contact Us</li>
                </ul>
            </div>
        </section>
        <!--//inner-page-->
        <!-- /contact-section -->
        <section class="w3l-contact-2 py-5" id="contact">
            <div class="container py-lg-5 py-md-4 py-2">

                <div style="margin: 8px auto; display: block; text-align:center;">

                    <!---728x90--->


                </div>
                <div class="header-section text-center mx-0 mb-md-5 mb-4">
                    <h6 class="title-subhny">Upload</h6>
                    <h3 class="title-w3l mt-2">Upload a new product</h3>
                </div>


                <div style="margin: 8px auto; display: block; text-align:center;">

                    <!---728x90--->

                </div>
                <?php
                if (isset($_GET['message_not_sent'])) {
                    echo "<div class='alert alert-danger' style='text-align:center'>An error occured. try again!</div>";
                }

                if (isset($_GET['message_sent'])) {
                    echo "<div class='alert alert-success' style='text-align:center'>Message sent successfully!</div>";
                }
                ?>
                <div class="contact-grids d-grid">
                    <div class="contact-left-img">
                        <img src="assets/images/img/11.jpg" class="img-fluid radius-image" alt="">
                    </div>
                    <div class="contact-right">
                        <form action="" method="POST" class="signin-form" enctype="multipart/form-data">
                            <?php
                            if (isset($_GET['success'])) {
                                echo "<div class='alert alert-success'>Product uploaded successfully!</div>";
                            }

                            if (isset($_GET['error'])) {
                                echo "<div class='alert alert-danger'>Upload error!</div>";
                            }
                            ?>
                            <div class="input-grids">

                                <input type="text" name="name" id="w3lName" placeholder="Name*" class="contact-input" />
                                <textarea type="text" id="editor" name="description" id="w3lSender" placeholder="description" class="contact-input" style="height:300px;margin-bottom:20px;" required>

                                </textarea>
                                <textarea type="text" id="second_editor" name="second_description" id="w3lSender" placeholder="Second description" class="contact-input" style="height:300px;margin-bottom:20px;" required>

                                </textarea>
                                <input type="file" name="image1" id="w3lSubect" placeholder="Subject*" class="contact-input" required />
                                <!-- <input type="text" name="w3lWebsite" id="w3lWebsite" placeholder="Website URL*" class="contact-input" required="" /> -->
                            </div>
                            <!-- <div class="form-input">
                                <textarea name="message" id="w3lMessage" placeholder="Type your message here*" required=""></textarea>
                            </div> -->
                            <div class="form-buttonhny text-lg-right">
                                <button class="btn btn-style btn-primary" name="submit">Upload</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="map-iframe mt-5 mb-lg-5 pb-lg-4">
                    <!-- <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d317718.69319292053!2d-0.3817765050863085!3d51.528307984912544!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47d8a00baf21de75%3A0x52963a5addd52a99!2sLondon%2C+UK!5e0!3m2!1sen!2spl!4v1562654563739!5m2!1sen!2spl" width="100%" height="400" frameborder="0" style="border: 0px;" allowfullscreen=""></iframe> -->
                </div>
            </div>
        </section>

        <!-- //contact-section -->

        <div style="margin: 8px auto; display: block; text-align:center;">

            <!---728x90--->

        </div>
        <!-- footer-28 block -->
        <?php include 'footer.php'; ?>

        <!-- Template JavaScript -->
        <script src="assets/js/jquery-3.3.1.min.js"></script>
        <script src="assets/js/theme-change.js"></script>
        <!--/MENU-JS-->
        <script>
            $(window).on("scroll", function() {
                var scroll = $(window).scrollTop();

                if (scroll >= 80) {
                    $("#site-header").addClass("nav-fixed");
                } else {
                    $("#site-header").removeClass("nav-fixed");
                }
            });

            //Main navigation Active Class Add Remove
            $(".navbar-toggler").on("click", function() {
                $("header").toggleClass("active");
            });
            $(document).on("ready", function() {
                if ($(window).width() > 991) {
                    $("header").removeClass("active");
                }
                $(window).on("resize", function() {
                    if ($(window).width() > 991) {
                        $("header").removeClass("active");
                    }
                });
            });
        </script>
        <!--//MENU-JS-->

        <script src="assets/js/bootstrap.min.js"></script>



        <div id="v-w3layouts"></div>
        <script src="assets/js/ckeditor.js"></script>

        <script>
            ClassicEditor.create(document.getElementById("editor"))
            ClassicEditor.create(document.getElementById("second_editor"))
        </script>

    </body>



</html>