-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.php
125 lines (119 loc) · 4.41 KB
/
posts.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
<?php
require_once 'include/connection.php';
require_once 'include/header.php';
if(isset($_GET['action'])&& $_GET['action']==='delete'){
$query = 'SELECT * FROM posts WHERE id = "' . $_GET['id'] .'"'; // select image
$res = mysqli_query($connection , $query); // generate query
@$image = $res->fetch_row()[3]; // fetch the image name from database
@unlink('uploads'.DIRECTORY_SEPARATOR .'postImage'.DIRECTORY_SEPARATOR.$image); // delete image from files
$query = 'DELETE FROM posts WHERE id= "' . $_GET['id'] .'"'; // delete post
$res1 = mysqli_query($connection , $query); //
if(isset($res1)){
$deleteMessage = 'تم المسح بنجاح';
$message =true;
}else {
$deleteMessage = 'حدث خطأ ما';
$message = false;
}
}
?>
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-2 nav-light bg-dark" id="side-area">
<h4>لوحة التحكم</h4>
<div class='text-center Admin'>
<img class="rounded-circle" src="./images/twiter.jpg" width='80px' height="80px"></img>
<h5 > مدير تطبيق </h5>
</div>
<ul>
<li>
<a href="./categorie.php">
<span><i class="fas fa-tags"></i></span>
<span>التصنيفات</span>
</a>
</li>
<!-- ARTICLES -->
<li data-toggle="collapse" data-target="#menu">
<a href="#">
<span><i class="fa-solid fa-newspaper"></i></span>
<span>المقالات</span>
</a>
</li>
<ul class="collapse" id="menu">
<li>
<a href="./newPost.php">
<span><i class="fa-solid fa-plus"></i></span>
<span> مقال جديد</span>
</a>
</li>
<li>
<a href="posts.php">
<span><i class="fa-solid fa-pager"></i></span>
<span> كل المقالات</span>
</a>
</li>
</ul>
<li>
<a href="index.php" target="_blank">
<span><i class="fa-solid fa-house"></i></span>
<span>عرض الموقع</span>
</a>
</li>
<li>
<a href="#">
<span
><i class="fa-solid fa-arrow-right-from-bracket"></i
></span>
<span>تسجيل الخروج</span>
</a>
</li>
</ul>
</div>
<div class="col-md-10" id="main-area">
<div class="add-categorie">
<form action="categorie.php" method="post">
<?php
?>
</form>
</div>
<!-- DISPLAY CATEGORIES -->
<div class="display-cat mt-4">
<div class="container">
<table class="table table-borderd">
<tr>
<td>رقم المقال</td>
<td>عنوان المقال</td>
<td>كاتب المقال</td>
<td>صورة المقال</td>
<td>تاريخ المقال</td>
<td>حذف المقال</td>
</tr>
<?php
$query = 'SELECT * FROM posts order by id desc';
$res = mysqli_query($connection , $query);
$id =0;
while($row = mysqli_fetch_assoc($res)){
$id++;
?>
<tr>
<td><?= $id?> </td>
<td><?= $row['postTitle'] ?></td>
<td><?= $row['writer'] ?></td>
<td><img src="uploads/postImage/<?= $row['postImage']?>" width="50px" height="30px"/></td>
<td><?= $row['postDate'] ?></td>
<td><a href="posts.php?action=delete&id=<?= $row['id'] ?> " class="link-danger"><i class="fa-solid fa-trash"></i></a></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once 'include/footer.php';
?>