-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_user.php
More file actions
60 lines (44 loc) · 1.77 KB
/
delete_user.php
File metadata and controls
60 lines (44 loc) · 1.77 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
<?php
include "functions.php";
session_start();
$connection = mysqli_connect("localhost", "root", "", "workmanagement");
$current_date = date('Y-m-d');
$current_timestamp = time();
$current_user_privilege = $_SESSION['privilege'];
$user_id = $_GET['id'];
$user_privilege = GetUserPrivilege($user_id);
if ($current_user_privilege != 'superuser' OR $user_privilege == 'superuser') {
echo "Nemate ovlasti za ovu akciju.";
header( "Refresh:1; url=users.php" );
exit;
}
$user = GetUser($user_id);
if ($user['is_active']) {
$active_ticket = GetActiveTicket($user_id);
if (!empty($active_ticket) AND $active_ticket != NULL) {
$time_spent = 0;
$ticket_timestamp = GetTicketStartTime($active_ticket, $user_id);
if (!empty($ticket_timestamp) AND $ticket_timestamp != NULL) {
$time_spent = $current_timestamp - $ticket_timestamp;
}
if (!empty($time_spent)) {
$sql = "INSERT INTO task_hours(task_id,user_id,time_spent,date_created) VALUES (?,?,?,'$current_date')";
$statement = $connection->prepare($sql);
$statement->bind_param('iii', $active_ticket, $user_id, $time_spent);
$statement->execute();
}
}
$sql = "UPDATE user_tasks SET user_id = ? WHERE user_id = '$user_id'";
$statement = $connection->prepare($sql);
$statement->bind_param('i', $_SESSION['user']);
$statement->execute();
$sql = "UPDATE users SET is_active = false,active_ticket_id = NULL,time_started = NULL WHERE id = '$user_id'";
$statement = $connection->prepare($sql);
$statement->execute();
} else {
$sql = "UPDATE users SET is_active = true WHERE id = '$user_id'";
$statement = $connection->prepare($sql);
$statement->execute();
}
header("Location: users.php");
?>