<?php
 session_start();
if(isset($_SESSION['Admin']))
{
    // $db=mysqli_connect("localhost","root","","behniwal") or die('Unable To connect');
    include "connection.php";
?>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <title>Add Furniture</title>
    <!-- Favicon-->
    <link rel="icon" href="favicon.ico" type="image/x-icon">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">

    <!-- Bootstrap Core Css -->
    <link href="admin_plugins/bootstrap/css/bootstrap.css" rel="stylesheet">

    <!-- Waves Effect Css -->
    <link href="admin_plugins/node-waves/waves.css" rel="stylesheet" />

    <!-- Animation Css -->
    <link href="admin_plugins/animate-css/animate.css" rel="stylesheet" />

    <!-- Morris Chart Css-->
    <link href="admin_plugins/morrisjs/morris.css" rel="stylesheet" />

    <!-- Custom Css -->
    <link href="admin_css/style.css" rel="stylesheet">

    <!-- AdminBSB Themes. You can choose a theme from css/themes instead of get all themes -->
    <link href="admin_css/themes/all-themes.css" rel="stylesheet" />
   
    <style>
       .container{
            justify-content: center;
            margin-top:20px;
        }
        #cn{
           
            border:1px solid silver;
            border-radius: 5px;
            text-justify: center;
            width:400px;
            height:cover;
            box-shadow:3px 3px 5px 6px #ccc; 
            margin-top:80px; 

        }
.form-group{
    font-size: 14px;
    font-family:Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
    
    
}
.l{
   font-size:medium; 
}
#h{
    padding:10px;
}
.btn{
    cursor:pointer;
    width:140px;
    margin-left:110px;
    font-weight:200px;
}
.btn:hover{
    color:orangered;
}
h6{
    font-family:cursive;
    color:red;
}
h5{
    color:green;
}
    </style>
</head>

<body class="theme-red">
  <!-- header -->
    <?php
        include "admin_header.php";
    ?>
  <!-- header -->
  <section >
        <div class="container">
            
            <div class="container" id="cn">
                <div class="form-group ">
                
                    <center><h2 id="h">Add Furniture</h2></center><hr>
                </div>
   
  <?php
                include 'connection.php';
        if(isset ($_POST['submit']))
           {
                           
                    $type = $_POST['type'];
                    $name = $_POST['name'];
                    $tf = "projectimage/furniture/".basename($_FILES['FileToUpload']['name']);
                    $image = $tf;
                    $price = $_POST['price'];
                    $description = $_POST['description'];
                    $query2 = "INSERT INTO `furniture`(`type`,`name`,`image`,`price`,`description`) VALUES('$type','$name','$image','$price','$description')";
                    $flag = "";

                if($_FILES['FileToUpload']['name'] != "" )
                {
                    $fileType = pathinfo($tf,PATHINFO_EXTENSION);
                    $check = getimagesize($_FILES['FileToUpload']['tmp_name']);	

                    if($check == true) {
                        $flag = 1;
                    }	
                    else
                    {
                        echo "<h6> File is not an Image</h6>";
                        $flag = 0;
                    }
                    if($fileType != "jpg" && $fileType != "JPG" && $fileType != "png" && $fileType != "jpeg" && $fileType != "gif" && $fileType != "jfif")
                    {
                        echo "<h6>This Type of File is Not allowed</h6>";
                        $flag = 0;
                    }
                    else
                    {
                        $flag = 1;
                    }
                    if(file_exists($tf))
                    {
                        echo "<h6>File is Already Exists.....!!!</h6>";
                        $flag = 0;
                    }
                    else
                    {
                         $flag = 1;
                    }

                    if($flag == 1)
                    {
                            move_uploaded_file($_FILES['FileToUpload']['tmp_name'], $tf) or die( "Could not Move file!");

                            mysqli_query($db,$query2) or die("Failed to load data in database");
                            echo "<h5>Successfully Submit['For new Addition Firstly refresh the url']</h5>";
                    }
                    else
                    {

                         echo "</br> <h6>Failed to Upload file....!!!!</h6>";

                    }

                }
                else
                {
                    echo "<h6> No file Selected....<h6>";
                }
        }
                        
                ?>	
     		
    
                <div class="form-group" >

                    <form name="form" method="post" action="add_furniture.php" enctype="multipart/form-data"> 
                    <input type="hidden" name="new" value="1" />
                    <p>
                        <label>Choose Furniture Type</label><br>
                        <input list="furniture" name="type" placeholder="Select---" required>
                        <datalist id="furniture">
                            <option value="Bed">Bed</option>
                            <option value="Sofa">Sofa</option>
                            <option value="Kitchen">Kitchen</option>
                            <option value="Cupboard">Cupboard</option>
                        </datalist>
                    </p>
                    <br>
                   
                   <div class="form-group">
                        <label for="name">Name</label><br>
                        <input type="text"  name="name" class="form-control " required placeholder="Product Name" required>
                   </div>
                   <div class="form-group">
                        <label for="file">Image</label>
                        <input type="file" name="FileToUpload"class="form-control l" >
                    </div>
                   <div class="form-group">
                       <label for="price">Price</label><br>
                       <input type="price" name="price" class="form-control l"  placeholder="Price">
                   </div>
                   <div class="form-group">
                       <label for="description">Description</label><br>
                       <input type="text"  name="description" class="form-control l"  placeholder="Description....."  aria-describedby="description">
                   </div>
                     <br><input type="submit" class="btn  col-md-4 offset-md-4" id="submit" name="submit">
                   
                    </form>
                    
                </div>
            </div>
        </div>
    </section>

<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    
    <!-- Jquery Core Js -->
    <script src="admin_plugins/jquery/jquery.min.js"></script>

    <!-- Bootstrap Core Js -->
    <script src="admin_plugins/bootstrap/js/bootstrap.js"></script>

    <!-- Select Plugin Js -->
    <script src="admin_plugins/bootstrap-select/js/bootstrap-select.js"></script>

    <!-- Slimscroll Plugin Js -->
    <script src="admin_plugins/jquery-slimscroll/jquery.slimscroll.js"></script>

    <!-- Waves Effect Plugin Js -->
    <script src="admin_plugins/node-waves/waves.js"></script>

    <!-- Jquery CountTo Plugin Js -->
    <script src="admin_plugins/jquery-countto/jquery.countTo.js"></script>

    <!-- Morris Plugin Js -->
    <script src="admin_plugins/raphael/raphael.min.js"></script>
    <script src="admin_plugins/morrisjs/morris.js"></script>

    <!-- ChartJs -->
    <script src="admin_plugins/chartjs/Chart.bundle.js"></script>

    <!-- Flot Charts Plugin Js -->
    <script src="admin_plugins/flot-charts/jquery.flot.js"></script>
    <script src="admin_plugins/flot-charts/jquery.flot.resize.js"></script>
    <script src="admin_plugins/flot-charts/jquery.flot.pie.js"></script>
    <script src="admin_plugins/flot-charts/jquery.flot.categories.js"></script>
    <script src="admin_plugins/flot-charts/jquery.flot.time.js"></script>

    <!-- Sparkline Chart Plugin Js -->
    <script src="admin_plugins/jquery-sparkline/jquery.sparkline.js"></script>

    <!-- Custom Js -->
    <script src="admin_js/admin.js"></script>
    <script src="admin_js/pages/index.js"></script>

    <!-- Demo Js -->
    <script src="admin_js/demo.js"></script>
</body>

</html>
               					
<?php
}
else
{
	echo "<br>";
}
?>