-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_edit.php
executable file
·70 lines (54 loc) · 1.57 KB
/
post_edit.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
<?php
@session_start();
include('src/Post.php');
$Post = new Post();
$id = $_GET['id'];
$result = $Post->loadPost($id);
if (!empty($_POST)) {
$data = $_POST;
$id = $data['id'];
$title = $data['title'];
$content = $data['content'];
$Post = new Post();
$Post->setTitle($title);
$Post->setContent($content);
$result = $Post->updatePost($id);
$_SESSION['msg'] = $result['msg'];
header("Location: ". $result['route'].$id );
exit;
}
?>
<?php include('header.php'); ?>
<?php if (Session::isLogged()): ?>
<div class="offset-2 col-8">
<!-- post -->
<?php
if (!empty($_SESSION["msg"])) {
$msg = $_SESSION['msg'];
echo '<div class="alert">'.$msg.'</div>';
unset($_SESSION['msg']);
}
?>
<?php if ($result->id_user == $_SESSION['currentId']): ?>
<div class="form-header">Post</div>
<form class="post" method="POST" action="post_edit.php">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input class="form-pw" type="text" name="title" placeholder="Título" value="<?php echo $result->title; ?>">
<textarea class="form-pw" name="content" placeholder="Conteúdo" rows="5" ><?php echo $result->content; ?></textarea>
<input type="hidden" name="id_user" value="<?php echo $result->id_user; ?>">
<button class="btn btn-sucess" type="submit">Salvar</button>
</form>
<?php else: ?>
<div class="col-12">
<div class="alert-login">Você não tem permissão para editar este post</div>
</div>
<?php endif; ?>
</div>
<?php else: ?>
<div class="col-12">
<div class="alert-login">Você precisa estar logado para postar</div>
</div>
<?php
endif;
include('footer.php');
?>