<?php
session_start();
if(!isset($_SESSION["username"])){
header("Location: index.php");
exit(); }
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <title>Add New Post</title>
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
    <link href="assets/css/style.css" rel="stylesheet" />
	
    <script src="assets/js/jquery-1.11.1.js"></script>
    <script src="assets/js/bootstrap.js"></script>
	
<!-- include summernote css/js-->
<link href="assets/dist/summernote.css" rel="stylesheet">
<script src="assets/dist/summernote.js"></script>

</head>
<body>

    <!-- HEADER END-->
    <div class="navbar navbar-inverse set-radius-zero">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="admin.php">

                    <img src="assets/img/logo.png" />
                </a>

            </div>

            <div class="left-div">
                <i class="fa fa-user-plus login-icon" ></i>
			</div>
		</div>
	</div>
	
    <section class="menu-section">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="navbar-collapse collapse ">
                        <ul id="menu-top" class="nav navbar-nav navbar-right">
						
                            <li><a  href="admin.php">Dashboard</a></li>
							<li><a  href="add.php">Add New Post</a></li>
                            <li><a href="logout.php">Log Out</a></li>

                        </ul>
                    </div>
                </div>

            </div>
        </div>
    </section>
	
	
<div class="content-wrapper">
        <div class="container">
            <div class="row">
                    <div class="col-md-12">
                        <h1 class="page-head-line"><span class="glyphicon glyphicon-pencil"></span> &nbsp;Add New Post</h1>
                    </div>
                </div>
                <div class="row">
                
				<div class="col-md-12">
                  <!--   Kitchen Sink -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Add New Post
                        </div>
						
						<div class="panel-body">
                       
<form action="../go.php" method="post" name="addpost" enctype="multipart/form-data">
  
  <div class="form-group">
    <label for="exampleInputEmail1">Post Title (H1)</label>
    <input name="title" type="text" class="form-control" id="exampleInputEmail1" placeholder="Title Here" />
  </div>
  
  <div class="form-group">
    <label for="exampleInputEmail1">Meta Title</label>
    <input name="mtitle" type="text" class="form-control" id="exampleInputEmail1" placeholder="Meta Title Here" />
  </div>
  
  <div class="form-group">
    <label for="exampleInputEmail1">Post Description</label>
    <textarea name="description" class="form-control" rows="3" placeholder="Text Area"></textarea>
  </div>
  
  
  <div class="form-group">
    <label for="exampleInputPassword1">Post keywords</label>
    <input name="keywords" type="text" class="form-control" id="exampleInputPassword1" placeholder="keyword, keywords, keywords" />
  </div>
  

  <div class="form-group">
    <label for="exampleInputEmail1">Script</label>
    <textarea name="script" id="summernote" class="form-control" rows="5"placeholder="Text Area"></textarea>
  </div>
  

  <div class="form-group">
    <label for="exampleInputFile">File input</label>
    <input name="image" type="file" id="exampleInputFile" />
    <p class="help-block">Example block-level help text here.</p>
  </div>
  
  <div class="form-group">
    <label for="exampleInputEmail1">image ALT</label>
    <input name="imgalt" type="text" class="form-control" id="exampleInputEmail1" placeholder="Title Here" />
  </div>
  
  <input name="addpost" type="submit" value="Add New Post" class="btn btn-info" />
  
</form>
                            </div>
				   </div>
                     <!-- End  Kitchen Sink -->
                </div>
               
            </div>
        </div>
    </div>
    <!-- CONTENT-WRAPPER SECTION END-->
		
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    &copy; Blog Admin
                </div>

            </div>
        </div>
    </footer>
	
  <script>
    $(document).ready(function() {
        $('#summernote').summernote();
    });
  </script>


	
<script>
        const dateToday = new Date();

        const date = new Date(dateToday);
        date.setDate(date.getDate() + 1);

        const monthName = date.toLocaleString('default', { month: 'long' });
        const currentYear = date.getFullYear();

        window.onload = function () {
            const dateSelect = document.getElementById('service_date');
            dateSelect.value = monthName;
            const yearElement = document.getElementById("service_year");
            yearElement.value = currentYear;
            AddMonthDays(monthName);
        }

        function AddMonthDays(monthNameValue) {
            let monthDays = 31;
            const currentYear = date.getFullYear();
            const dayOfMonth = date.getDate();
            if (monthNameValue == 'February') monthDays = 28;
            if (monthNameValue == 'February' && currentYear == '2028') monthDays = 29;
            if (monthNameValue == 'February' && currentYear == '2032') monthDays = 29;
            if (monthNameValue == 'February' && currentYear == '2036') monthDays = 29;
            if (monthNameValue == 'February' && currentYear == '2040') monthDays = 29;
            if (monthNameValue == 'February' && currentYear == '2044') monthDays = 29;
            if (monthNameValue == 'February' && currentYear == '2048') monthDays = 29;
            if (monthNameValue == 'April') monthDays = 30;
            if (monthNameValue == 'June') monthDays = 30;
            if (monthNameValue == 'September') monthDays = 30;
            if (monthNameValue == 'November') monthDays = 30;

            const selectElement = document.getElementById('service_day');
            selectElement.options.length = 0;
            const newOption = new Option('Pick a Day', '');
            selectElement.add(newOption);

            const monthDaysPlusOne = monthDays + 1;
            const SelectHtmlCode = '';
            for (let i = 1; i < monthDaysPlusOne; i++) {
                const newOption = new Option(i.toString(), i.toString());
                selectElement.add(newOption);
            }
            selectElement.value = dayOfMonth;
        }

        function validatePhoneNumber(phoneNumber) {
            const phoneNumberPattern = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
            const cleanedPhoneNumber = phoneNumber.replace(/\s/g, '');
            if (phoneNumberPattern.test(cleanedPhoneNumber)) {
                return;
            } else {
                alert('Please enter correct phone number format: ###-###-####');
            }
        }
    </script>
</body>
</html>

