-
Notifications
You must be signed in to change notification settings - Fork 0
/
newpost.php
188 lines (157 loc) · 6.43 KB
/
newpost.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php require_once("db.php"); ?>
<?php require_once("session.php"); ?>
<?php require_once("functions.php"); ?>
<?php
if(isset($_POST["submit"])){
$title=$_POST["title"];
$category=$_POST["category"];
$post=$_POST["post"];
date_default_timezone_get("Asia/Kuching");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
$DateTime;
$Admin="imhphari";
$image=$_FILES["image"]["name"];
$target="img/".basename($_FILES["image"]["name"]);
if(empty($title)){
$_SESSION["ErrorMessage"]= "Title can't be empty";
echo Redirect_to("newpost.php");
}
elseif(strlen($title)<2){
$_SESSION["ErrorMessage"]="Title should have atleast 2 characters :)";
echo Redirect_to("newpost.php");
}
else{
global $link;
$query="INSERT INTO admin_panel (dateandtime,title,category,author,image,post) VALUES ('$DateTime','$title','$category','$Admin','$image','$post')";
$exec=mysqli_query($link,$query);
move_uploaded_file($_FILES["image"]["tmp_name"],$target);
if($exec){
$_SESSION["SuccessMessage"]="Post Added Successfully";
echo Redirect_to("newpost.php");
}
else{
$_SESSION["ErrorMessage"]="Something went wrong. Try Again";
echo Redirect_to("newpost.php");
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="Description" content="SVCE ACM Blog">
<meta name="author" content="imhphari">
<link rel="icon" href="assets/brandlogo.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="all.css">
<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script>
<title>Add New Post</title>
<style>
.fieldinfo{
color:#026647;
font-family: Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", "serif";
font-size: 1.2em;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
<h1>Admin</h1>
<ul id="side_menu" class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link " href="dashboard.php">
<span><img src="dash.svg"> </span> Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link active " href="newpost.php"><span><img src="baseline-list.svg"></span> Add New Post</a>
</li>
<li class="nav-item">
<a class="nav-link " href="categories.php"><span><img src="baseline-category-24px.svg"></span> Categories</a>
</li>
<li class="nav-item">
<a class="nav-link " href="#"><span><img src="baseline-supervised_user_circle-24px.svg"></span> Manage Admins</a>
</li>
<li class="nav-item">
<a class="nav-link " href="#"><span><img src="baseline-add_comment-24px.svg"></span> Comments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><span><img src="baseline-equalizer-24px.svg"></span> Live Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><span><img src="baseline-exit_to_app-24px.svg"></span> Sign Out</a>
</li>
</ul>
<!-- <ul id="side_menu" class="nav flex-column nav-pills">
<li class="active nav-item"><a href="dashboard.php">Dashboard</a></li>
<li><a href="#">Add New Post</a></li>
<li><a href="#">Categories</a></li>
<li><a href="#">Manage Admins</a></li>
<li><a href="#">Comments</a></li>
<li><a href="#">Live Blog</a></li>
<li><a href="#">Logout</a></li>
</ul>-->
</div><!--End of Side area-->
<div class="col-sm-10">
<h1>Add New Post</h1>
<?php echo Message();
echo SuccessMessage();
?>
<div>
<form action="newpost.php" method="post" enctype="multipart/form-data">
<fieldset>
<div class="form-group">
<label for="title"><span class="fieldinfo">Title :</span></label>
<input class="form-control" type="text" name="title" id="categoryname" placeholder="Title">
</div>
<div class="form-group">
<label for="categoryselect"><span class="fieldinfo">Category :</span></label>
<select class="form-control" id="categoryselect" name="category">
<?php
global $link;
$viewquery="SELECT * FROM category ORDER BY dateandtime desc";
$exec=mysqli_query($link,$viewquery);
while($DataRows=mysqli_fetch_array($exec)){
$id=$DataRows["id"];
$Category=$DataRows["name"];
?>
<option><?php echo $Category ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="imageselect"><span class="fieldinfo">Select Image :</span></label>
<input type="file" class="form-control" name="image" id="imageselect">
</div>
<div class="form-group">
<label for="postarea"><span class="fieldinfo">Post :</span></label>
<textarea class="form-control" name="post" id="postarea"></textarea>
</div>
<br>
<input class="btn btn-primary btn-block" type="submit" name="submit" value="Add New Post">
</fieldset><br>
</form>
</div>
</div><!--Ending of main area-->
</div>
</div>
<div id="footer">
<hr><p>SVCE-ACM 2018-2019 | All Rights Reserved</p>
</div>
</body>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script>
var easyMDE = new EasyMDE({element: document.getElementById('postarea')});
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</html>