-
Notifications
You must be signed in to change notification settings - Fork 1
/
employee_registrations_action.php
235 lines (137 loc) · 5.88 KB
/
employee_registrations_action.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
<?php
/**
* Created by PhpStorm.
* User: BlackLion
* Date: 4/6/2018
* Time: 8:19 AM
*/
if (session_status() == PHP_SESSION_NONE) { session_start();}
require 'validator.php';
require 'db.php';
// CHECK THERE IS A LOGNG[SESSION VARIABLE WERE ONLY CREATED DURING LOGIN] &&&& CHECK USER TYPE = ADMINISTRATOR
if(isset($_SESSION['email']))
{
$email = $_SESSION['email'];
$user_id = $_SESSION['user_id']; $current_employee_type_result = $mysqli->query("select DISTINCT employee_types.title,employee_types.id from employee_types, users, employee_data where employee_data.user_id = '$user_id' and employee_types.id = employee_data.employee_type_id") or die($mysqli->error());
if($current_employee_type_result->num_rows !=0)
{
$current_employee_type_data = $current_employee_type_result->fetch_assoc();
$current_employee_type_result->free();
$type_of_employment = $current_employee_type_data['title'];
}
else
{
$_SESSION['message'] = "Not a valid email address";
header("location:error.php");
}
if(isset($type_of_employment))
{
if($type_of_employment != 'Administrator')
{
$_SESSION['message'] = "This is invalid submission";
header("location:error.php");
}
if($_SESSION['two_step'] == 0)
{
$_SESSION['message'] = "You are not completed 2nd step of registration";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "Something went wrong";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "This session has expired. Please login again!!!";
header("location:error.php");
}
if(isset($_POST))
{
if(isset($_POST['id']) && isset($_POST['action_type']))
{
$id = $_POST['id'];
$at = $_POST['action_type'];
if((is_int($id) || ctype_digit($id)) && (int)$id > 0) {
if ($at == "approve") {
$result = $mysqli->query("select * from employee_data where id='$id' and is_locked='1'");
if ($result->num_rows != 0) {
$data = $result->fetch_assoc();
$user_id = $data['user_id'];
$sql_1 = "UPDATE employee_data SET is_approved='1'"
. " WHERE id='$id'";
$sql_2 = "UPDATE users SET two_step='1'"
. " WHERE id='$user_id'";
if ($mysqli->query($sql_1) && $mysqli->query($sql_2)) {
$_SESSION['message'] = "You have successfully approved the employee";
header("location:success.php");
} else {
$_SESSION['message'] = "Database access error";
header("location:error.php");
}
} else {
$_SESSION['message'] = "Can't find the employee data for the given id or The employee profile which isn't locked yet";
header("location:error.php");
}
} elseif ($at == "disapprove") {
$result = $mysqli->query("select * from employee_data where id='$id' and is_locked='1'");
if ($result->num_rows != 0) {
$data = $result->fetch_assoc();
$user_id = $data['user_id'];
$sql_1 = "UPDATE employee_data SET is_approved='0'"
. " WHERE id='$id'";
$sql_2 = "UPDATE users SET two_step='0'"
. " WHERE id='$user_id'";
if ($mysqli->query($sql_1) && $mysqli->query($sql_2)) {
$_SESSION['message'] = "You have successfully disapproved the employee";
header("location:success.php");
} else {
$_SESSION['message'] = "Database access error";
header("location:error.php");
}
}
else {
$_SESSION['message'] = "Can't find the employee data for the given id or The employee profile which isn't locked yet";
header("location:error.php");
}
} elseif ($at == "delete") {
$result = $mysqli->query("select * from employee_data where id='$id'");
if ($result->num_rows != 0) {
$data = $result->fetch_assoc();
$user_id = $data['user_id'];
$sql_1 = "DELETE FROM employee_data WHERE id='$id'";
$sql_2 = "UPDATE users SET two_step='0'"
. " WHERE id='$user_id'";
if ($mysqli->query($sql_1) && $mysqli->query($sql_2)) {
$_SESSION['message'] = "You have successfully deleted the employee";
header("location:success.php");
} else {
$_SESSION['message'] = "Database access error";
header("location:error.php");
}
}
else {
$_SESSION['message'] = "Can't find the employee data for the given id or The employee profile which isn't locked yet";
header("location:error.php");
}
} else {
$_SESSION['message'] = "Parameters error";
header("location:error.php");
}
}
else
{
$_SESSION['message'] = "Id must be an integer";
header("location:error.php");
}
}
else
{
$_SESSION['message'] = "Parameters are missing";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "Not a valid method";
header("location:error.php");
}