-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-post.php
111 lines (86 loc) · 3.48 KB
/
edit-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
@session_start();
require_once "./php/validateLogin.php";
require_once "./php/model-post.php";
if(!isset($_GET["id"])) { header("location: manage.php"); exit;}
$id = $_GET["id"];
$post = ModelPost::findById($id);
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$title = $_POST["title"] ?? false;
$content = $_POST["content"] ?? false;
$category = $_POST["category"] ?? false;
$author = $_POST["author"] ?? false;
$date = Date("Y-m-d");
if($title == false OR $content == false OR $category == false OR $author == false){
$_SESSION["msg"] = "Havias deixado um campo em falta! Tente novamente";
header("location: edit-post.php?id={$id}");
exit;
}
else
{
ModelPost::update($id, $title, $content, $author, $category, $date);
$_SESSION["msg"] = "Editado com sucesso!";
header("location: manage.php");
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="assets/css/globals.css">
<link rel="stylesheet" href="assets/css/create-post.css">
</head>
<body>
<div class="wrapper">
<header id="header-home">
<div class="container">
<div class="logo">
<img src="assets/image/logo_n.png" alt="Logo" width="50">
</div>
<div class="action-user">
<a href="index.php">Início</a>
<a href="manage.php">Gerir</a>
<a href="logout.php" class="btn-link">Sair</a>
</div>
</div>
</header>
<section class="section-form">
<div class="container">
<form action="" class="form-add-post" method="POST">
<header class="header-login">
<h1>Editar a publicação</h1>
</header>
<div class="box-input">
<label>Titulo</label>
<input type="text" name="title" placeholder="Crie um titulo" class="input" value="<?= $post["title"]?>">
</div>
<div class="box-input">
<label>Conteúo</label>
<textarea type="text" name="content" placeholder="Crie o conteúdo" class="input"><?= $post["content"]?></textarea>
</div>
<div class="box-input">
<label>Autor</label>
<input type="text" name="author" placeholder="Quem é o autor?" class="input" value="<?= $post["author"]?>">
</div>
<div class="box-input">
<label>Categoria</label>
<input type="text" name="category" placeholder="Qual é a categoria?" class="input" value="<?= $post["category"]?>">
</div>
<button type="submit" class="btn-s">Editar</button>
</form>
</div>
</section>
</div>
<div class='msg-box <?= $_SESSION["msg"] ? "show success" : "" ?>'>
<div class="msg success">
<?= $_SESSION["msg"] ?? "" ?>
<?php unset($_SESSION["msg"]) ?>
</div>
</div>
</body>
</html>