-
Notifications
You must be signed in to change notification settings - Fork 4
/
edit_post_form.php
executable file
·132 lines (94 loc) · 2.88 KB
/
edit_post_form.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require 'partials/session.php';
?>
<!DOCTYPE html>
<html lang="en">
<?php
require 'head.php';
require 'partials/database.php';
require 'partials/functions.php';
$user = $_SESSION["user"]["id"];
$posttoedit = $_GET["posttoedit"];
$statement = $pdo->prepare("
SELECT id, user, title, post, category, image FROM posts WHERE id = :posttoedit
");
$statement->execute(array(
":posttoedit" => $posttoedit
));
$posts = $statement->fetchAll(PDO::FETCH_ASSOC);
// CHECKING IF SESSION ID IS MATCHING ID OF THE USER WHO WROTE THE BLOGPOST
// OR IS 1 = ID OF ADMIN. IF NOT, SHOW ERROR MESSAGE
foreach($posts as $safe_check){
if(!($_SESSION["user"]["id"] == ($safe_check["user"] || "1"))){
echo "Du har inte behörighet till denna sida.";
//header("Location: ../error.php");
}else{ ?>
<body>
<?php
require 'nav.php';
?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-12">
<?php
foreach($posts as $poster){
?>
<div class="container mt-5">
<h4>Redigera inlägg:</h4>
<form action="partials/edit_post.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<input type="hidden" name="user" value="<?= $_SESSION["user"]["id"]; ?> " class="form-control">
</div>
<div class="form-group">
<label for="post_title"> Rubrik: </label>
<input type="text" name="post_title" value="<?= $poster["title"]; ?>" class="form-control">
</div>
<div class="form-group">
<label for="new_post"> Inlägg: </label>
<textarea type="text" name="new_post" id="editor">
<?= $poster["post"]; ?>
</textarea>
</div>
<div class="form-group">
<input type="hidden" name="blog_id" value="<?= $poster["id"]; ?>" class="form-control">
</div>
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" name="category" value="<?= $poster["category"]; ?>" id="sel1">
<option>Solglasögon</option>
<option>Klockor</option>
<option>Inredning</option>
</select>
</div>
<div class="form-group">
<label for="new_post">Bild (valfritt): </label>
<input type="file" name="uploaded_file" value="<?= $poster["image"]; ?>">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary">
</div>
</form>
</div>
<?php
}
?>
</div>
</div>
</div> <!-- END DIV / CONTAINER -->
<?php
require "footer.php";
?>
<!-- Detta script är till wysiwyg editorn:-->
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.catch( error => {
console.error( error );
} );
</script>
</body>
<?php
}
}
?>
</html>