-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhr_users.php
305 lines (241 loc) · 7.28 KB
/
hr_users.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<html>
<head>
<link href="CSS/simple-sidebar.css" rel="stylesheet">
<style>
table {
border-collapse: collapse;
margin-top: 15px;
width: 100%;
}
th, td {
text-align: left;
padding: 8px 0px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #292b2c;
color: white;
}
.button {
background-color: #292b2c;
border: none;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
font-size: 16px;
cursor: pointer;
}
.button:hover {
background-color: black;
}
</style>
</head>
<?php
session_start();
if (!$_SESSION['loggedIn'] || $_SESSION['user']['Role'] != 3) {
echo "<script> location.href='home.php'; </script>";
}
include "menu.php";
?>
<body>
<div class="d-flex" id="wrapper">
<div class="bg-dark border-right" id="sidebar-wrapper">
<div class="list-group list-group-flush bg-dark">
<a href="hr_users.php" class="list-group-item list-group-item-action bg-secondary text-light"><span class="text-nowrap"><i class="fa fa-user"></i> Admins</a></span>
<a href="messagesMenu.php" class="list-group-item list-group-item-action bg-dark text-light"><span class="text-nowrap"><i class="fa fa-envelope"></i> Reports</a></span>
</div>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
</nav>
<div class="container-fluid">
<?php
if(isset($_GET['Id']))
$_SESSION['$selectedSurvey'] = $_GET['Id'];
$servername = "localhost";
$username = "root";
$password = "";
$DB = "mydb";
$conn = mysqli_connect($servername, $username, $password, $DB);
if (!$conn) {
error_log(mysqli_connect_error(),3,"../errors/db-errors.log");
die("Connection failed: " .mysqli_connect_error());
}
if (isset($_GET['send'])) {
$valuesToSend = explode (",", $_GET['send']);
for ($i = 0; $i < count($valuesToSend); $i++) {
$v = $valuesToSend[$i];
//echo "<script>alert('".$v."');</script>";
$valuesToSend = explode (",", $_GET['send']);
//$surveyId = $_SESSION['$selectedSurvey'];
for ($i = 0; $i < count($valuesToSend); $i++) {
$v = $valuesToSend[$i];
//echo $v;
if(mysqli_num_rows($conn->query("SELECT * FROM salaries
WHERE userId ='$v'")) == 0)
{
$conn->query("INSERT INTO `salaries` (`userId`,`penalty`,`salary`) VALUES ('$v',1,2000)");
//$salary = mysqli_fetch($conn->query("SELECT salary FROM salaries WHERE userId = $v"));
//$conn->query("UPDATE `salaries` (`userId`,`penalty`,`salary`) VALUES ('$v',1,200)");
}
else
{
$salary = mysqli_fetch_row($conn->query("SELECT salary FROM salaries WHERE userId = $v"));
//echo $salary[0];
$newSalary = $salary[0] * 0.75;
$conn->query("UPDATE `salaries` SET `salary` = $newSalary,`penalty` = 1 WHERE userId = $v AND penalty = 0");
}
}
//unset($_SESSION['$selectedSurvey']);
echo "<script> location.href='hr_users.php'; </script>";
}
}
//depenalty
if (isset($_GET['depenalty'])) {
$valuesToSend = explode (",", $_GET['depenalty']);
for ($i = 0; $i < count($valuesToSend); $i++) {
$v = $valuesToSend[$i];
//echo "<script>alert('".$v."');</script>";
$valuesToSend = explode (",", $_GET['depenalty']);
//$surveyId = $_SESSION['$selectedSurvey'];
for ($i = 0; $i < count($valuesToSend); $i++) {
$v = $valuesToSend[$i];
//echo $v;
if(mysqli_num_rows($conn->query("SELECT * FROM salaries
WHERE userId ='$v'")) == 0)
{
}
else
{
$salary = mysqli_fetch_row($conn->query("SELECT salary FROM salaries WHERE userId = $v"));
//echo $salary[0];
$newSalary = $salary[0] / .75;
$conn->query("UPDATE `salaries` SET `salary` = $newSalary,`penalty` = 0 WHERE userId = $v AND penalty = 1");
}
}
//unset($_SESSION['$selectedSurvey']);
echo "<script> location.href='hr_users.php'; </script>";
}
}
$res = $conn->query("SELECT * FROM user u LEFT JOIN salaries s ON s.userId = u.Id WHERE u.Role = 2");
if (!$res) {
//die "Query failed: (" . $res->errno . ") " . $res->error;
}
$rownumber = 1;
$page = 1;
$where = 0;
$firstrow = 0;
echo "<table style='width:100%'>\n";
if (isset($_GET['page'])) {
$do = $_GET['page'];
if ($do <= 0) {
$page = 1;
} else if ($do > (ceil(($res->num_rows) / 10))) {
$page = ceil(($res->num_rows) / 10);
} else {
$page = $do;
}
}
while ($row = $res->fetch_assoc()) {
if (0 == $firstrow) {
/* first result set row? look at the keys=column nanes */
echo "<tr>";
foreach (array_keys($row) as $colname) {
if ($colname == "firstName") {
echo "<th>First name</th>";
} else if ($colname == "Id") {
echo "<th> #</th>";
} else if ($colname == "lastName") {
echo "<th>Last name</th>";
} else if ($colname == "password") {
} else if ($colname == "phoneNumber") {
echo "<th>Phone number</th>";
}else if ($colname == "date_of_birth") {
}
else if($colname == "userId")
{
}
else if($colname == "Role")
{
}
else
{
echo "<th>$colname</th>";
}
}
echo "</tr>\n";
}
$firstrow = 1;
echo "<tr>";
$where = 0;
$id = 0;
foreach (array_values($row) as $colval) {
if (($rownumber <= $page*10 && abs($page*10 - $rownumber < 10))) {
if ($where == 0) {
$id = $colval;
// echo $colval;
echo "<td> <input type='checkbox' id='check".$id."' onclick='checkBoxes(".$id.")' name='select' value='".$id."'></td>";
} else if ($where == 4) {
}
else if($where == 7)
{
}
else if($where == 9)
{
}
else if ($where == 8) {
}
else {
echo "<td>$colval</td>";
}
}
$where++;
}
$rownumber ++;
echo "</tr>\n";
}
echo "</table>\n";
$res->close();
?>
<?php echo '<a class="btn btn-dark" href="hr_users.php?page='.($page-1).'"><</a>' ?>
<?php echo"<a>\t".$page."\t</a>"?>
<?php echo '<a class="btn btn-dark" href="hr_users.php?page='.($page+1).'">></a>' ?>
<?php echo ' <a class="btn bg-danger text-light" id = "send" href = "">Add penalty</a>' ?>
<?php echo ' <a class="btn bg-success text-light" id = "depenalty" href = "">remove penalty</a>' ?>
</div>
</div>
</div>
<script>
var selected = [];
//adding and removing penaltyies
var addLink = document.getElementById("send");
var removeLink = document.getElementById("depenalty");
var searchBy = "Name";
addLink.setAttribute("href", "hr_users.php");
removeLink.setAttribute("href", "hr_users.php");
function checkBoxes(id) {
var check = document.getElementById("check"+id);
if (check.checked) {
selected.push(id);
} else {
var ind = selected.indexOf(id);
if (ind > -1) {
selected.splice(ind, 1);
}
}
if (selected.length > 0) {
addLink.setAttribute("href", "hr_users.php?send="+selected.join(",")+"");
removeLink.setAttribute("href", "hr_users.php?depenalty="+selected.join(",")+"");
} else {
addLink.setAttribute("href", "hr_users.php");
removeLink.setAttribute("href", "hr_users.php");
}
}
</script>
<?php
include 'footer.php'
?>
</body>
</html>