<?php
require_once "common/header.php";
require_once "include/db_handler.php";
$db = new DbHandler();

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

    $about = $_POST['about'];

    $aboutPhoto = $_FILES['post_photo']['name'];
    move_uploaded_file($_FILES['post_photo']['tmp_name'], 'assets/img/about_pic/' . $_FILES['post_photo']['name']);

    if ($about != '') {

        $response = $db->addAbout($about, $aboutPhoto);
        if ($response["error"] == false) {

            $response["message"] = '<div class="alert alert-success" style="text-align:center;">
                    <a href="published_article.php" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Success!</strong> Description added successfully
                  </div>';
        }

    } else {
        $response["message"] = '<div class="alert alert-danger" style="text-align:center;">
                    <a href="published_article.php" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Sorry!</strong> All fields are required 
                                
                  </div>';
    }
}
?>

<body>

<div class="container-fluid">
    <div class="row">
        <?php
        require_once "common/sidebar.php";
        ?>
        <div class="right-column">
            <?php
            require_once "common/navbar.php";
            ?>
            <main class="main-content p-5" role="main">

                <div class="row mb-4">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-mailbox">
                                <div class="row mx-0">

                                    <div class="col-lg-12">

                                        <h2>Add About Me Section</h2>

                                        <?php if (isset($response['message'])) echo $response["message"];?>

                                        <div class="mailbox-container mailbox-message-compose">

                                            <form method="post" enctype="multipart/form-data" action="about.php">
                                                <div class="modal-body">

                                                    <div class="form-group my_form">
                                                        <label>Content:</label>
                                                        <textarea name="about" id="mytextarea"></textarea>
                                                    </div>

                                                    <div class="form-group" style="margin-top: 20px!important;">
                                                        <label for="exampleFormControlFile1">Upload Photo</label>
                                                        <input type="file" class="form-control-file" name="post_photo">
                                                    </div>

                                                </div>
                                                <div class="modal-footer">
                                                    <button type="submit" name="submit_art" class="btn btn-info">
                                                        Submit
                                                    </button>
                                                </div>
                                            </form>

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

            </main>
        </div>
    </div>
</div>

<?php
require_once "modals/add_article.php";
require_once "modals/logout.php";
require_once "modals/add_category.php";
require_once "common/footer.php";
?>

