-
Notifications
You must be signed in to change notification settings - Fork 4
/
Admins.php
233 lines (218 loc) · 10.4 KB
/
Admins.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
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
232
233
<?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"])){ //setting connection of name submit
$UserName = $_POST["Username"];
$Name = $_POST["Name"];
$Password = $_POST["Password"];
$ConfirmPassword = $_POST["ConfirmPassword"];
$Admin = $_SESSION["UserName"];
date_default_timezone_set("Asia/Kolkata");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H: %M: %S",$CurrentTime);
if(empty($UserName)||empty($Password)||empty($ConfirmPassword)){ //assigning variable to name of "CatagoryTitle"
$_SESSION["ErrorMessage"] = "All fields must be filled out";
Redirect_to("Admins.php");
}elseif (strlen($Password)<4){
$_SESSION["ErrorMessage"] = "Password should be greater than 3 character";
Redirect_to("Admins.php");
}elseif ($Password !== $ConfirmPassword) {
$_SESSION["ErrorMessage"] = "Password and confirm password should match";
Redirect_to("Admins.php");
}elseif (CheckUserNameExistsOrNot($UserName)) {
$_SESSION["ErrorMessage"] = "Username Exists. Try Another One!";
Redirect_to("Admins.php");
}
else{
//Query to insert new admin in database when everything is good
global $ConnectingDB;
$sql = "INSERT INTO admins(datetime,username,password,aname,addedby)VALUES(:dateTime,:userName,:password,:aName,:adminName)";
$stmt = $ConnectingDB->prepare($sql);
//binding the values
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':userName',$UserName);
$stmt->bindValue(':password',$Password);
$stmt->bindValue(':aName',$Name);
$stmt->bindValue(':adminName',$Admin);
$Execute=$stmt->execute();
if($Execute){
$_SESSION["SuccessMessage"]="New Admin with the username of ".$UserName." added Successfully";
Redirect_to("Admins.php");
}else{
$_SESSION["ErrorMessage"]= "something went wrong... Try Again !";
Redirect_to("Admins.php");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scal=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://kit.fontawesome.com/7f6ee3d237.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
<title>Admin </title>
</head>
<body>
<?php ?>
<!--NAVIGATION BAR-->
<div class="navbar navbar-expand-lg navbar-dark bg-custom">
<div class="container">
<a href="#" class="navbar-brand " style= "color:aliceblue; font-family: mindsagacustom;">MindSaga</a>
<button class="navbar-toggler ml-auto custom-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#Rcollapse" aria-controls="Rcollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="Rcollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="MyProfile.php" class="nav-link" style= "color:white ; font-weight: bolder;">My Profile</a>
</li>
<li class="nav-item">
<a href="Dashboard.php" class="nav-link" style= "color:white ; font-weight: bolder;">Dashboard</a>
</li>
<li class="nav-item">
<a href="Posts.php" class="nav-link" style= "color:white ; font-weight: bolder;">Posts</a>
</li>
<li class="nav-item">
<a href="Categories.php" class="nav-link" style= "color:white ; font-weight: bolder;">Categories</a>
</li>
<li class="nav-item">
<a href="Admins.php" class="nav-link" style= "color:white ; font-weight: bolder;">Manage-Admins</a>
</li>
<li class="nav-item">
<a href="Comments.php" class="nav-link" style= "color:white ; font-weight: bolder;">Comments</a>
</li>
<li class="nav-item">
<a href="index.php" class="nav-link" style= "color:white ; font-weight: bolder;">GO Live</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a href="Logout.php" class="nav-link text-warning"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
</div>
</div>
</div>
<!--NAVBAR-->
<!--HEADER-->
<header class="text-white py-3"style="background-image:linear-gradient(360deg, #1B80B2 ,#1B0039);">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><i class="fas fa-user" style="color:#27aae1;"></i> Manage-Admins</h1>
</div>
</div>
</div>
</header>
<!--HEADER-->
<!--MAIN AREA-->
<section class="container py-2 mb-4">
<div class="row">
<div class="offset-lg-1 col-lg-10" style="min-height: 540px;">
<?php echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="Admins.php" method="post">
<div class="card mb-3" style=" box-shadow: 0 8px 14px 0 rgb(159 171 255), 0 16px 20px 0 rgb(121 255 255 / 19%) " >
<div class="card-header" style="background-color:rgb(235 242 255);;">
<h1 style="
font-family: Montserrat;
text-align: left;
color: #FFF;
display: flex;
flex-direction: column;
letter-spacing: 1px;
background-image: url(https://media.giphy.com/media/26BROrSHlmyzzHf3i/giphy.gif);
background-size: cover;
color: transparent;
-moz-background-clip: text;
-webkit-background-clip: text;
text-transform: uppercase;
font-size: 60px;
line-height: .75;
">Add New Admin</h1>
</div>
<div class="card-body " style="background-image:linear-gradient(270deg,#310265,#1B80B2);">
<div class="form-group">
<label for="username"><span class="fieldinfo"> Username:</span></label>
<input class="form-control" type="text" name="Username" id="username" value="">
</div>
<div class="form-group">
<label for="Name"><span class="fieldinfo"> Name:</span></label>
<input class="form-control" type="text" name="Name" id="Name" value="">
<small class="text-warning text-muted" style="color:#f4f4f4!important">Optional</small>
</div>
<div class="form-group">
<label for="Password"><span class="fieldinfo"> Password:</span></label>
<input class="form-control" type="password" name="Password" id="Password" value="">
</div>
<div class="form-group">
<label for="ConfirmPassword"><span class="fieldinfo"> Confirm Password:</span></label>
<input class="form-control" type="Password" name="ConfirmPassword" id="ConfirmPassword" value="">
</div>
<div class="row">
<div class="col-lg-6 mb-2">
<a href="Dashboard.php" class="btn btn-warning btn-block"> <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-success btn-block">
<i class="fas fa-check"></i> Publish
</button>
</div>
</div>
</div>
</div>
</form>
<!-- deleting admins-->
<h2>Existing Admins</h2>
<div class="table-responsive">
<table class="table custom-thead">
<thead class="">
<tr>
<th>No. </th>
<th>Date&Time</th>
<th>Username</th>
<th>Admin name</th>
<th>Added by</th>
<th>Action</th>
</tr>
</thead>
<?php
global $ConnectingDB;
$sql = "SELECT * FROM admins ORDER BY id desc";
$Execute = $ConnectingDB->query($sql);
$SrNo = 0;
while ($DataRows=$Execute->fetch()){
$AdminId = $DataRows["id"];
$DateTime= $DataRows["datetime"];
$AdminUsername = $DataRows["username"];
$AdminName = $DataRows["aname"];
$AddedBy = $DataRows["addedby"];
$SrNo++;
?>
<tbody>
<tr>
<td><?php echo htmlentities($SrNo); ?></td>
<td><?php echo htmlentities($DateTime); ?></td>
<td><?php echo htmlentities($AdminUsername); ?></td>
<td><?php echo htmlentities($AdminName); ?></td>
<td><?php echo htmlentities($AddedBy); ?></td>
<td><a href="DeleteAdmin.php?id=<?php echo $AdminId;?>" class="btn btn-danger">Delete</a></td>
</tr>
</tbody>
<?php }?>
</table>
</div>
</div>
</div>
</section>
<!--FOOTER-->
<?php require_once ("Backendfooter.php");?>