-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-post.php
174 lines (134 loc) · 3.67 KB
/
new-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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
include('include/connection.php');
include('include/header.php');
if (isset($_POST['title']))
{
$pTitle = $_POST['title'];
}
if (isset($_POST['category']))
{
$pCat = $_POST['category'];
}
if (isset($_POST['content']))
{
$pContent = $_POST['content'];
}
if (isset($_POST['pAuthor']))
{
$pAuthor = $_POST['pAuthor'];
}
if (isset($_POST['add']))
{
$pAdd = $_POST['add'];
}
// Image
if (isset($_FILES['postImage']['name']))
{
$imageName = $_FILES['postImage']['name'];
}
if (isset($_FILES['postImage']['tmp_name']))
{
$imageTmp = $_FILES['postImage']['tmp_name'];
}
if(isset($pAdd)){
if(empty($pTitle) || empty($pContent)){
echo "<div class='alert alert-danger'>"."الرجاء ملء الحقول أدناه"."</div>";
}elseif(strlen($pContent) > 10000){
echo "<div class='alert alert-danger'>"."محتوي المنشور كبير جدا"."</div>";
}else{
$postImage = rand(0,1000)."_".$imageName;
move_uploaded_file($imageTmp,"uploads\\".$postImage);
$query = "INSERT INTO posts(postTitle,postCat,postImage,postContent,postAuthor)
VALUES('$pTitle','$pCat','$postImage','$pContent','$pAuthor')";
$res = mysqli_query($con,$query);
if(isset($res)){
echo "<div class='alert alert-success'>"."تمت إضافة المنشور بنجاح"."</div>";
}else{
echo "<div class='alert alert-danger'>"."حدث خطأ ما"."</div>";
}
}
}
?>
<!-- Start Container -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-2" id="side-area">
<h4>لوحة التحكم</h4>
<ul>
<li><a href="categories.php">
<span class=""> <i class="fas fa-tags"></i> </span>
<span class="">التصنيفات</span>
</a></li>
<!-- المقالات -->
<li data-toggle="collapse" data-target="#menu">
<a href="#">
<span class=""> <i class="far fa-newspaper"></i> </span>
<span class="">المقالات</span>
</a>
</li>
<ul class="collapse" id="menu">
<li>
<a href="new-post.php">
<span><i class="fas fa-edit"></i></span>
<span>مقال جديد</span>
</a>
</li>
<li>
<a href="posts.php">
<span><i class="fas fa-th-large"></i></span>
<span>كل المقالات</span>
</a>
</li>
</ul>
<!-- المقالات -->
<li><a href="index.php" target="_blank">
<span class=""> <i class="fas fa-window-restore"></i> </span>
<span class="">عرض الموقع</span>
</a></li>
<li><a href"logout.php">
<span class=""> <i class="fas fa-sign-out-alt"></i> </span>
<span class="">تسجيل الخروج</span>
</a></li>
</ul>
</div>
<!-- -->
<div class="col-md-10" id="main-area">
<button class="btn-custom">مقال جديد</button>
<div class="add-category">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="title">عنوان المقال</label>
<input type="text" name="title" class="form-control">
</div>
<div class="form-group">
<label for="cate">التصنيف</label>
<select name="category" class="form-control" id="cate">
<?php
$query = "SELECT * FROM categories";
$res = mysqli_query($con,$query);
while ($row = mysqli_fetch_assoc($res)) {
?>
<option >
<?php echo $row['categoryName']; ?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="image">صورة المقال</label>
<input type="file" id="image" class="form-control" name="postImage">
</div>
<div class="form-group">
<label for="content">نص المقال</label>
<textarea class="form-control" rows="10" cols="30" name="content"></textarea>
</div>
<button class="btn-custom form-control" name="add">نشر المقال</button>
</form>
</div>
</div>
<?php
include('include/footer.php');
?>