forked from Chamara-g/RegionalServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddAdmin.php
More file actions
208 lines (166 loc) · 6.32 KB
/
addAdmin.php
File metadata and controls
208 lines (166 loc) · 6.32 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
<?php session_start(); ?>
<?php require_once('../inc/connection.php'); ?>
<?php
if(isset($_POST['Submit'])){
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$operational_level = $_POST['opt_level'];
$is_delete = 0;
$hashed_password = sha1($password);
$query = "INSERT INTO admin_tb(name,password,user_type,is_delete) VALUES('{$user_name}','{$hashed_password}','{$operational_level}',{$is_delete})";
$result = mysqli_query($connection,$query);
if($result){
header("Location:../Admin_search/admin_search.php");
}else{
echo $query;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Admin</title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script type="text/javascript">
function validation(arg){
var fName = arg.first_name.value;
var lName = arg.last_name.value;
var userName = arg.user_name.value;
var password = arg.password.value;
var password2 = arg.password2.value;
var optLevel = arg.optLevel.value;
var ePat = /^[a-z-._0-9]+@[a-z0-9]+\.[a-z.]{2,5}$/;
var namePatDt = /\./;
var namePatDgt = /\d/;
var spaceCheck = /\s/;
var err = "";
var errNum = 0;
if(fName == ""){
errNum++;
err += errNum + ". First name cannot be empty.\n";
}else if(fName.length< 2 || namePatDt.test(fName) || namePatDgt.test(fName)){
errNum++;
err += errNum + ". Invalid first name.\n";
}
if(lName == ""){
errNum++;
err += errNum + ". Last name cannot be empty.\n";
}else if(lName.length< 2 || namePatDt.test(lName) || namePatDgt.test(lName)){
errNum++;
err += errNum + ". Invalid last name.\n";
}
if(userName == ""){
errNum++;
err += errNum + ". User name cannot be empty.\n";
}else if(userName.length< 2 || namePatDt.test(userName) || namePatDgt.test(userName) || spaceCheck.test(userName)){
errNum++;
err += errNum + ". Invalid user name.\n";
}
if(password == ""){
errNum++;
err += errNum + ". Password cannot be empty.\n";
}
if(password2 == ""){
errNum++;
err += errNum + ". Password confirmation cannot be empty.\n";
}
if(password!="" && password2!=""){
if(password!=password2){
errNum++;
err += errNum + ". Passwords do not match.\n";
}
}
if (!arg.optLevel[0].checked && !arg.optLevel[1].checked && !arg.optLevel[2].checked && !arg.optLevel[3].checked) {
errNum++;
err += errNum + ". Select operation level.\n";
}
if (errNum>0) {
alert(err);
return false;
}else{
alert('done');
return true;
}
}
</script>
</head>
<body>
<?php require_once('../header.php'); ?>
<div class="container" style="margin-top: 153px; margin-bottom: 153px;">
<form action="addAdmin.php" class="well form-horizontal" method="post" id="contact-form" onsubmit="return validation(this);">
<fieldset>
<legend><p class="text-center"><i class="glyphicon glyphicon-plus"></i>Add Admin</p></legend>
<!--Full Name-->
<br>
<div id="col1" style="width :50%; height: 100%; float: left">
<!--User Name-->
<div class="form-group">
<label class="col-md-4 col-xs-12 control_label"><p class="text-center"><mark>User Name</mark></p></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-flag"></i></span>
<input type="text" name="user_name" placeholder="Enter your User Name here" class="form-control">
</div>
</div>
</div>
<!--Password-->
<div class="form-group">
<label class="col-md-4 col-xs-12 control_label"><p class="text-center">Enter Password</p></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="password" id="txtPassword" placeholder="Enter password here" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 col-xs-12 control_label"><p class="text-center">Re-Enter Password</p></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="password2" id="textConfirmPassword" placeholder="Re-Enter password here" class="form-control">
</div>
</div>
</div>
</div>
<div id="col2" style="width :50%; height: 100%; float: left">
<label class="col-md-4 col-md-offset-1 control_label"><p>Operational Level</p></label>
<div class="form-group col-xs-10 col-xs-push-5">
<label class="radio"><input type="radio" name="optLevel" value="Full">Full Access</label>
<label class="radio"><input type="radio" name="optLevel" value="Half">Half Access</label>
<label class="radio"><input type="radio" name="optLevel" value="Default">Default</label>
<label class="radio"><input type="radio" name="optLevel" value="Guest">Guest</label>
</div>
<br>
<!--Submit button-->
<div class="form-group">
<label class="col-sm-4 control_label"></label>
<div class="col-md-4">
<div class="input-group">
<button name="Submit" id="btnSubmit" value="Submit" style="height:50px; width: 300px" type="Submit" class="btn btn-primary">Confirm & add Admin</button>
</div>
</div>
</div>
</div>
</fieldset>
</form>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnSubmit").click(function(){
var password = $("#txtPassword").val();
var confirmPassword = $("#textConfirmPassword").val();
if(password != confirmPassword){
alert("Passwords do not match");
return false;
}
return true;
});
});
</script>
<?php require_once('../footer.php'); ?>
</body>
</html>
<?php mysqli_close($connection); ?>