-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManageAdmins.php
131 lines (115 loc) · 3.49 KB
/
ManageAdmins.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
<?php
require_once("UserDAO.php");
require_once("functions.php");
if(!checkSession() || $_SESSION["username"]!='admin')
{
redirect_to("index.php");
}
$message="";
if(isset($_POST["adminName"]) && isset($_POST["adminUsername"]) && isset($_POST["adminPassword"]))
{
$name=$_POST["adminName"];
$username=$_POST["adminUsername"];
$password=$_POST["adminPassword"];
try
{
$user=new User();
$user->name=$name;
$user->password=$password;
$user->username=$username;
$valid=true;
if(strlen($username)>15)
{
$message="username allowed <= 15 char";
$valid=false;
}
if(strlen($password)>20)
{
$message=$message."<br/> "."password allowed <= 15 char";
$valid=false;
}
if($valid==true)
{
if(UserDAO::checkUsernameAvailable($user->username))
{
UserDAO::addUser($user);
redirect_to("ManageAdmins.php");
}else
{
$message = "Username not available";
}
}
}
catch(Exception $exception)
{
echo "{\"success\":false}";
}
}
require("partials/header.php");
$admins=UserDAO::getAll();
?>
<div class="table-responsive" style="padding-top:200px;margin-left:150px;width:70%; ">
<h4>Manage admins</h4>
<h5 style="color:red">
<?php
echo $message;
?>
</h5>
<button class="btn btn-success btn-sm pull-right" data-target="#AddAdminModal" data-toggle="modal">Add Admin </button>
<br><br/>
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>S.No.</td>
<td>Name</td>
<td>Username</td>
<td>Options</td>
</tr>
</thead>
<tbody>
<?php
$x=1;
foreach ($admins as $row) {
echo "<tr>";
echo "<td>".$x."</td>";
echo "<td>".$row->name."</td>";
echo "<td>".$row->username."</td>";
echo "<td><a href='RemoveAdmin.php?code=".$row->code."'>Delete</a> ";
echo "</tr>";
$x++;
}
?>
</tbody>
</table>
</div>
<div class="portfolio-modal modal fade" id="AddAdminModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-offset-3 col-lg-6">
<div class="modal-body">
<form action="" method="post" id="AddAdminForm">
<label>Name</label>
<input class="form-control" type="text" name="adminName" id="adminName" required>
<label>Username</label>
<input class="form-control" type="text" name="adminUsername" id="adminUsername" required maxlength="15">
<label>Password</label>
<input class="form-control" type="password" name="adminPassword" id="adminPassword" required maxlength="20">
<hr class="star-primary">
<button type="submit" id="AddAdminButton" class="btn btn-default" ><i class="fa fa-plus"></i> Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include("partials/footer.php");
?>