2022-12-30 03:25:40 +00:00
|
|
|
<?php
|
|
|
|
include "partials/header.php";
|
2023-03-07 01:23:47 +00:00
|
|
|
|
|
|
|
// fetch categories from database
|
|
|
|
$query = "SELECT * FROM categories";
|
|
|
|
$categories=mysqli_query($connection,$query);
|
|
|
|
|
|
|
|
// get back form data if form was invalid
|
|
|
|
|
|
|
|
$title= $_SESSION['add-post-data']['title'] ?? null;
|
|
|
|
$body= $_SESSION['add-post-data']['body'] ?? null;
|
|
|
|
unset($_SESSION['add-post-data']);
|
2022-12-30 03:25:40 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section class="form__section">
|
|
|
|
<div class="container form__section-container">
|
|
|
|
<h2>Add Post</h2>
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php if(isset($_SESSION['add-post'])) : ?>
|
2022-12-30 03:25:40 +00:00
|
|
|
<div class="alert__message error">
|
2023-03-07 01:23:47 +00:00
|
|
|
<p>
|
|
|
|
<?=
|
|
|
|
$_SESSION['add-post'];
|
|
|
|
unset($_SESSION['add-post']);
|
|
|
|
?>
|
|
|
|
</p>
|
2022-12-30 03:25:40 +00:00
|
|
|
</div>
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php endif ?>
|
|
|
|
<form action="<?= ROOT_URL ?>admin/add-post-logic.php" enctype="multipart/form-data" method="POST">
|
|
|
|
<input type="text" name="title" value ="<?= $title ?>" placeholder="Title">
|
|
|
|
<select name="category_id">
|
|
|
|
<?php while($category = mysqli_fetch_assoc($categories)) : ?>
|
|
|
|
<option value="<?= $category['id'] ?>"><?= $category['title'] ?></option>
|
|
|
|
<?php endwhile?>
|
2022-12-30 03:25:40 +00:00
|
|
|
</select>
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php if(isset($_SESSION["user_is_admin"])) : ?>
|
2022-12-30 03:25:40 +00:00
|
|
|
<div class="form__control inline">
|
2023-03-07 01:23:47 +00:00
|
|
|
<input type="checkbox" name="is_featured" value='1' id="is_featured" checked>
|
2022-12-30 03:25:40 +00:00
|
|
|
<label for="is_featured" >Featured</label>
|
|
|
|
</div>
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php endif ?>
|
|
|
|
<textarea rows="8" name="body" placeholder="Body"><?=$body?></textarea>
|
2022-12-30 03:25:40 +00:00
|
|
|
|
|
|
|
<div class="form__control">
|
|
|
|
<label for="thumbnail">Add Thumbnail</label>
|
2023-03-07 01:23:47 +00:00
|
|
|
<input type="file" name="thumbnail" id="thumbnail">
|
2022-12-30 03:25:40 +00:00
|
|
|
</div>
|
2023-03-07 01:23:47 +00:00
|
|
|
<button type="submit" name="submit" class="btn">Add Post</button>
|
2022-12-30 03:25:40 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<?php
|
2023-03-07 01:23:47 +00:00
|
|
|
include '../partials/footer.php';
|
|
|
|
?>
|