-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNewPost.php
More file actions
231 lines (220 loc) · 8.37 KB
/
Copy pathAddNewPost.php
File metadata and controls
231 lines (220 loc) · 8.37 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php require_once("Includes/DB.php"); ?>
<?php require_once("Includes/Functions.php"); ?>
<?php require_once("Includes/Sessions.php"); ?>
<?php $_SESSION["TrackingURL"]=$_SERVER["PHP_SELF"];
Confirm_Login(); ?>
<?php
if(isset($_POST["Submit"])){
$PostTitle = $_POST["PostTitle"];
$Category = $_POST["Category"];
$Image = $_FILES["Image"]["name"];
$Target = "Uploads/".basename($_FILES["Image"]["name"]);
$PostText = $_POST["PostDescription"];
$Admin = $_SESSION["UserName"];
date_default_timezone_set("Asia/Karachi");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($PostTitle)){
$_SESSION["ErrorMessage"]= "Title Cant be empty";
Redirect_to("AddNewPost.php");
}elseif (strlen($PostTitle)<5) {
$_SESSION["ErrorMessage"]= "Post Title should be greater than 5 characters";
Redirect_to("AddNewPost.php");
}elseif (strlen($PostText)>9999) {
$_SESSION["ErrorMessage"]= "Post Description should be less than than 1000 characters";
Redirect_to("AddNewPost.php");
}else{
// Query to insert Post in DB When everything is fine
global $ConnectingDB;
$sql = "INSERT INTO posts(datetime,title,category,author,image,post)";
$sql .= "VALUES(:dateTime,:postTitle,:categoryName,:adminName,:imageName,:postDescription)";
$stmt = $ConnectingDB->prepare($sql);
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':postTitle',$PostTitle);
$stmt->bindValue(':categoryName',$Category);
$stmt->bindValue(':adminName',$Admin);
$stmt->bindValue(':imageName',$Image);
$stmt->bindValue(':postDescription',$PostText);
$Execute=$stmt->execute();
move_uploaded_file($_FILES["Image"]["tmp_name"],$Target);
if($Execute){
$_SESSION["SuccessMessage"]="Post with id : " .$ConnectingDB->lastInsertId()." added Successfully";
Redirect_to("AddNewPost.php");
}else {
$_SESSION["ErrorMessage"]= "Something went wrong. Try Again !";
Redirect_to("AddNewPost.php");
}
}
} //Ending of Submit Button If-Condition
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="Css/Styles.css">
<link rel="stylesheet" href="Css/NavSelect.css">
<title>Add New Post</title>
</head>
<body>
<!-- NAVBAR -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-1">
<div class="container">
<a href="index.php?page=1" class="navbar-brand">CMSsite</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarcollapseCMS">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarcollapseCMS">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="MyProfile.php" class="nav-link"> <i class="fas fa-user text-info"></i> My Profile</a>
</li>
<li class="nav-item">
<a href="Dashboard.php" class="nav-link">Dashboard</a>
</li>
<li class="nav-item">
<a href="Posts.php" class="nav-link">Posts</a>
</li>
<li class="nav-item">
<a href="Categories.php" class="nav-link">Categories</a>
</li>
<li class="nav-item">
<a href="Admins.php" class="nav-link">Admins</a>
</li>
<li class="nav-item">
<a href="Comments.php" class="nav-link">Comments</a>
</li>
<li class="nav-item">
<a href="Blog.php?page=1" class="nav-link" target="_blank">Live Blog</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a href="Logout.php" class="nav-link text-danger">
<i class="fa fa-sign-out" style="font-size:18px"></i> Logout</a></li>
</ul>
</div>
</div>
</nav>
<!-- NAVBAR END -->
<!-- HEADER -->
<header class="bg-dark text-white py-3">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><i class="fas fa-edit" style="color:#27aae1;"></i> Add New Post</h1>
</div>
</div>
</div>
</header>
<!-- HEADER END -->
<!-- Main Area -->
<section class="container py-2 mb-4">
<div class="row">
<div class="offset-lg-1 col-lg-10" style="min-height:400px;">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="AddNewPost.php" method="post" enctype="multipart/form-data">
<div class="card bg-secondary text-light mb-3">
<div class="card-body bg-dark">
<div class="form-group">
<label for="title"> <span class="FieldInfo"> Post Title: </span></label>
<input class="form-control" type="text" name="PostTitle" id="title" placeholder="Type title here" value="">
</div>
<div class="form-group">
<label for="CategoryTitle"> <span class="FieldInfo"> Chose Categroy </span></label>
<select class="form-control" id="CategoryTitle" name="Category">
<?php
//Fetchinng all the categories from category table
global $ConnectingDB;
$sql = "SELECT id,title FROM category";
$stmt = $ConnectingDB->query($sql);
while ($DataRows = $stmt->fetch()) {
$Id = $DataRows["id"];
$CategoryName = $DataRows["title"];
?>
<option> <?php echo $CategoryName; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<div class="custom-file">
<input class="custom-file-input" type="File" name="Image" id="imageSelect" value="">
<label for="imageSelect" class="custom-file-label">Select Image </label>
</div>
</div>
<div class="form-group">
<label for="Post"> <span class="FieldInfo"> Post: </span></label>
<textarea class="form-control" id="Post" name="PostDescription" rows="8" cols="80"></textarea>
</div>
<div class="row">
<div class="col-lg-6 mb-2">
<a href="Dashboard.php" class="btn btn-info btn-block text-info bg-dark"><i class="fas fa-arrow-left"></i> Back To Dashboard</a>
</div>
<div class="col-lg-6 mb-2">
<button type="submit" name="Submit" class="btn btn-info btn-block text-info bg-dark">
<i class="fas fa-check"></i> Publish
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</section>
<!-- End Main Area -->
<!-- FOOTER -->
<footer class="footer-distributed bg-dark text-white ">
<div class="footer-left">
<h3>CMS<span>site</span></h3>
<p class="footer-links">
<a href="#">Home</a>
·
<a href="#">Blog</a>
·
<a href="#">Pricing</a>
·
<a href="#">About</a>
·
<a href="#">Faq</a>
·
<a href="#">Contact</a>
</p>
<p id="aboutUs" class="">About Us </p>
<p style="margin-top:-12px;" class="small text-info lead">CMSsite is a blog where you can learn</p>
<p class="lead">Copyright © <span id="year"></span> All Rights Reserved.</p>
<div class="footer-icons">
<a href="https://www.facebook.com/malikattique2"><i class="fa fa-facebook-square"></i></a>
<a href="https://www.instagram.com/malikkattik/"><i class="fa fa-instagram"></i></a>
<a href="https://www.linkedin.com/in/attiqueurrehman12/"><i class="fa fa-linkedin"></i></a>
<a href="https://github.com/malikattique1/"><i class="fa fa-github"></i></a>
</div>
</div>
<div class="footer-right">
<?php
echo ContactusPlaceMessage();
?>
<p>Contact Us</p>
<form action="Blog.php" method="post" id="contactusform">
<input type="email" name="email" placeholder="Email">
<textarea type="text" name="message" placeholder="Message"></textarea>
<button class="btn btn-sm btn-info text-light bg-info" type="submit" name="ContactUsSubmit">Send</button>
</form>
</div>
</footer>
<!-- FOOTER END-->
<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.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script>
$('#year').text(new Date().getFullYear());
</script>
<script type="text/javascript" src="js/NavSelect.js"></script>
</body>
</html>