<?php
session_start();

if(!isset($_SESSION['username']) && !isset($_SESSION['password'])){
    header('Location: login.php');
}
$pagename = 'blog';
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>ADMIN</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <!-- Morris chart -->
  <link rel="stylesheet" href="bower_components/morris.js/morris.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="bower_components/jvectormap/jquery-jvectormap.css">
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    
    <style>
        .control-label{
            text-align: left !important;
        }
        #submitbtn{
            width:100px;
        }
    </style>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

<?php include('header.php'); ?>

<span id="success_msg" style="position:fixed;top:10%;left:40%;z-index:9999;color:#2f8000;display:none;background:rgba(76,175,80,0.3);padding:4px 50px;">Added Successflully.</span>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Blog
        <small>Control panel</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Blog</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-lg-12 col-xs-12">
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Add Blog</h3>
            </div>
            
            <div class="row">
                <div class="col-lg-10 col-lg-offset-1">
                    <form id="Jobs_form" class="form-horizontal">
                      <div class="box-body">
                       <div class="form-group">
                          <label class="col-sm-4 control-label">Title</label>
                          <div class="col-sm-8">
                            <input type="text" class="form-control" id="heading" name="title" placeholder="Title">
                            <input type="hidden" name="action" value="store">
                          </div>
                        </div> 

                        <div class="form-group">
                          <label class="col-sm-4 control-label">Publish Date</label>
                          <div class="col-sm-8">
                            <input type="date" class="form-control" id="publish_date" name="publish_date">
                          </div>
                        </div> 
                        
                        <div class="form-group">
                          <label class="col-sm-4 control-label">Upload Image Size (1200px X 600px)</label>
                          <div class="col-sm-8">
                            <input type="file" class="form-control" id="imagename" name="imagename">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-sm-4 control-label">Description</label>
                          <div class="col-sm-8">
                            <textarea class="form-control" id="description" name="description"></textarea>
                          </div>
                        </div>
                       
                        <div class="form-group">
                          <label class="col-sm-4"></label>
                          <div class="col-sm-8">
                            <button type="submit" class="btn btn-info" id="submitbtn">ADD</button>
                          </div>
                        </div>
                      </div>
                    </form>
                </div>
            </div>
            
          </div>
        </div>
        <!-- ./col -->
      </div>
      <!-- /.row -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <footer class="main-footer">
    <strong> &copy; Copyright 2019. All Rights Reserved. Designed by <a href="http://bangaloreadsolutions.com">Bangalore AdSolutions</a>.</strong> 
  </footer>

  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="bower_components/raphael/raphael.min.js"></script>
<script src="bower_components/morris.js/morris.min.js"></script>
<!-- Sparkline -->
<script src="bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="bower_components/moment/min/moment.min.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
  <script src="https://cdn.ckeditor.com/4.21.0/standard-all/ckeditor.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>

<script>

$(function(){
    var dtToday = new Date();
    
    var month = dtToday.getMonth() + 1;
    var day = dtToday.getDate();
    var year = dtToday.getFullYear();
    if(month < 10)
        month = '0' + month.toString();
    if(day < 10)
        day = '0' + day.toString();
    
    var maxDate = year + '-' + month + '-' + day;

    // or instead:
    // var maxDate = dtToday.toISOString().substr(0, 10);
 
    $('#publish_date').attr('min', maxDate);
});

                $(document).ready(function () {
                    // $('textarea').wysihtml5({
                    //     "html": true,
                    //     "image": false
                    // });
                      CKEDITOR.replace( 'description' );
                    
                    $("form#Jobs_form").submit(function (event) {
                        event.preventDefault();
                        $('#submitbtn').text("ADDING...");
                        $('#submitbtn').attr('disabled',true);
                        
                        $.ajax({
                            url: './serverside/BlogCrud.php',
                            type: 'POST',
                            data: new FormData(this),
                            processData: false,
                            contentType: false,
                            success: function (response) {
                                if (response == "ok") {
                                    $('#success_msg').show();
                                    $('#submitbtn').text("ADD");
                                    $('#submitbtn').attr('disabled',false);
                                    setTimeout(function ()
                                    {
                                        window.location.href = "./index.php";
                                    }, 1000);
                                } else {
                                    alert(response);
                                    $('#submitbtn').text("ADD");
                                    $('#submitbtn').attr('disabled',false);
                                }
                            }
                        });
                    });
                });
        </script>
        
        <script>
            $('#imagename').change(function(){
                var ext = $('#imagename').val().split('.').pop().toLowerCase();
                if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
                    alert('Upload only Image!');
                    $('#imagename').val('');
                }
            });
        </script>

</body>
</html>
