134 lines
4.4 KiB
PHP
Executable File
134 lines
4.4 KiB
PHP
Executable File
<?php
|
|
|
|
include_once '../models/Database.php';
|
|
include_once '../models/User.php';
|
|
include_once '../models/Post.php';
|
|
include_once '../models/Category.php';
|
|
include_once '../Config.php';
|
|
|
|
|
|
$database = new Database();
|
|
$db = $database->getConnection();
|
|
|
|
$user = new User($db);
|
|
$post = new Post($db);
|
|
$category = new Category($db);
|
|
|
|
if(!$user->loggedIn()) {
|
|
header("location: index.php");
|
|
}
|
|
|
|
$post = new Post($db);
|
|
|
|
$categories = $post->getCategories();
|
|
|
|
$post->id = (isset($_GET['id']) && $_GET['id']) ? $_GET['id'] : '0';
|
|
$saveMessage = '';
|
|
if(!empty($_POST["savePost"]) && $_POST["title"]!=''&& $_POST["message"]!='') {
|
|
|
|
$post->title = $_POST["title"];
|
|
$post->message = $_POST["message"];
|
|
$post->category = $_POST["category"];
|
|
$post->status = $_POST["status"];
|
|
if($post->id) {
|
|
$post->updated = date('Y-m-d H:i:s');
|
|
if($post->update()) {
|
|
$saveMessage = "Post updated successfully!";
|
|
}
|
|
} else {
|
|
$post->userid = $_SESSION["userid"];
|
|
$post->created = date('Y-m-d H:i:s');
|
|
$post->updated = date('Y-m-d H:i:s');
|
|
$lastInserId = $post->insert();
|
|
if($lastInserId) {
|
|
$post->id = $lastInserId;
|
|
$saveMessage = "Post saved successfully!";
|
|
}
|
|
}
|
|
}
|
|
|
|
$postdetails = $post->getPost();
|
|
|
|
include('../template/header.php');
|
|
?>
|
|
<title>Admin - <?= Config::WEBSITE_NAME ?></title>
|
|
<script src="js/jquery.dataTables.min.js"></script>
|
|
<script src="js/dataTables.bootstrap.min.js"></script>
|
|
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css" />
|
|
<script src="js/posts.js"></script>
|
|
<link href="css/style.css" rel="stylesheet" type="text/css" >
|
|
</head>
|
|
<body>
|
|
<header id="header">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-md-10">
|
|
<h1><span class="glyphicon glyphicon-cog" aria-hidden="true"></span> Article <small>Editation</small></h1>
|
|
</div>
|
|
<br>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<br>
|
|
<section id="main">
|
|
<div class="container">
|
|
<div class="row">
|
|
<?php include "left_menus.php"; ?>
|
|
<div class="col-md-9">
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Add New Post</h3>
|
|
</div>
|
|
<div class="panel-body">
|
|
|
|
<form method="post" id="postForm">
|
|
<?php if ($saveMessage != '') { ?>
|
|
<div id="login-alert" class="alert alert-success col-sm-12"><?php echo $saveMessage; ?></div>
|
|
<?php } ?>
|
|
<div class="form-group">
|
|
<label for="title" class="control-label">Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" value="<?php echo $postdetails['title']; ?>" placeholder="Post title..">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="lastname" class="control-label">Message</label>
|
|
<textarea class="form-control" rows="5" id="message" name="message" placeholder="Post message.."><?php echo $postdetails['message']; ?></textarea>
|
|
</div>
|
|
|
|
|
|
<div class="form-group">
|
|
<label for="sel1">Category</label>
|
|
<select class="form-control" id="category" name="category">
|
|
<?php
|
|
foreach ($categories as $category) {
|
|
$selected = '';
|
|
if($category['name'] ==$postdetails['name']) {
|
|
$selected = 'selected=selected';
|
|
}
|
|
echo "<option value='".$category['id']."' $selected>".$category['name']."</option>";
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="status" class="control-label"></label>
|
|
<label class="radio-inline">
|
|
<input type="radio" name="status" id="publish" value="published" <?php if($postdetails['status'] == 'published') { echo "checked";} ?>>Publish
|
|
</label>
|
|
<label class="radio-inline">
|
|
<input type="radio" name="status" id="draft" value="draft" <?php if($postdetails['status'] == 'draft') { echo "checked";} ?>>Draft
|
|
</label>
|
|
<label class="radio-inline">
|
|
<input type="radio" name="status" id="archived" value="archived" <?php if($postdetails['status'] == 'archived') { echo "checked";} ?>>Archive
|
|
</label>
|
|
</div>
|
|
<input type="submit" name="savePost" id="savePost" class="btn btn-info" value="Save" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<?php include('../template/footer.php');?>
|