-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonnel.php
134 lines (113 loc) · 4.13 KB
/
personnel.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
<?php
session_start();
$title = "P&O";
require "includes/header.php";
if ($_SESSION['role'] != 1) {
if ($_SESSION['role'] != 5) {
header("location:".ROOT);
die();
}
}
if (!isset($_GET['uid'])) {
$userQuery = $db->select("SELECT * FROM users WHERE active = 1");
}
if (isset($_GET['uid']) && !isset($_GET['action'])) {
$bind = ["id" => $_GET['uid']];
$userPortQuery = $db->select("SELECT * FROM portfolios WHERE uid = :id", $bind);
}
if (isset($_GET['uid']) && isset($_GET['action']) && $_GET['action'] == "add") {
$bind = ["id" => $_GET['uid']];
$portQuery = $db->select("SELECT * FROM portfolios WHERE uid = :id", $bind);
if (isset($_POST['portAddSubmit']) &&
!empty($_POST['portType']) &&
!empty($_POST['portDesc']) &&
!empty($_POST['portBegin']) &&
!empty($_POST['portEnd'])
) {
if (empty($_POST['portCmnts'])) {
$_POST['portCmnts'] = "";
}
$begin = strtotime($_POST['portBegin']);
$end = strtotime($_POST['portEnd']);
if ($end <= $begin) {
setMsg("The starting date must be before the ending date.", 3);
header("location:".ROOT."/personnel/".$_GET['uid']."/add/");
die();
}
if ( !$end || !$begin) {
setMsg("Please fill in a valid date.", 3);
header("location:".ROOT."/personnel/".$_GET['uid']."/add/");
die();
}
$bind = [
"uid" => $_GET['uid'],
"type" => htmlspecialchars($_POST['portType']),
"descr" => htmlspecialchars($_POST['portDesc']),
"begin_dt" => strtotime($_POST['portBegin']),
"end" => strtotime($_POST['portEnd']),
"cmnt" => htmlspecialchars($_POST['portCmnts'])
];
$addPortQuery = $db->insert("INSERT INTO portfolios (uid, type, descr, begin_date, end_date, comments)
VALUES (:uid, :type, :descr, :begin_dt, :end, :cmnt)", $bind);
if ($addPortQuery) {
setMsg("Successfully added portfolio for user number <b>".$bind['uid']."</b>", 1);
header("location:".ROOT."/personnel/".$bind['uid']."/");
die();
} else {
setMsg("Something went wrong while trying to add portfolio for that user. Please try again.", 3);
header("location:".ROOT."/personnel/".$bind['uid']."/add/");
die();
}
}
}
if (isset($_GET['uid']) && isset($_GET['action']) && $_GET['action'] == "edit" && isset($_GET['port'])) {
$bind = ["id" => $_GET['port']];
$portQuery = $db->select("SELECT * FROM portfolios WHERE id = :id", $bind);
if (isset($_POST['portEditSubmit']) &&
!empty($_POST['portType']) &&
!empty($_POST['portDesc']) &&
!empty($_POST['portBegin']) &&
!empty($_POST['portEnd'])
) {
if (empty($_POST['portCmnts'])) {
$_POST['portCmnts'] = "";
}
$begin = strtotime($_POST['portBegin']);
$end = strtotime($_POST['portEnd']);
if ($end <= $begin) {
setMsg("The starting date must be before the ending date.", 3);
header("location:".ROOT."/personnel/".$_GET['uid']."/edit/".$_GET['port']."/");
die();
}
if ( !$end|| !$begin) {
setMsg("Please fill in a valid date.", 3);
header("location:".ROOT."/personnel/".$_GET['uid']."/edit/".$_GET['port']."/");
die();
}
$bind = [
"id" => $_GET['port'],
"uid" => htmlspecialchars($_GET['uid']),
"type" => htmlspecialchars($_POST['portType']),
"descr" => htmlspecialchars($_POST['portDesc']),
"begin_dt" => strtotime($_POST['portBegin']),
"end" => strtotime($_POST['portEnd']),
"cmnt" => htmlspecialchars($_POST['portCmnts'])
];
$editPortQuery = $db->update("UPDATE portfolios SET uid = :uid, type = :type, descr = :descr, begin_date = :begin_dt,
end_date = :end, comments = :cmnt WHERE id = :id", $bind);
if ($editPortQuery) {
setMsg("Successfully edited portfolio for user number <b>".$bind['uid']."</b>", 1);
header("location:".ROOT."/personnel/".$bind['uid']."/");
die();
} else {
setMsg("Something went wrong while trying to add portfolio for that user. Please try again.", 3);
header("location:".ROOT."/personnel/".$bind['uid']."/edit/".$_GET['port']."/");
die();
}
}
}
require "views/personnel.view.php";
require "includes/footer.php";
unset($_SESSION['msg']);
unset($_SESSION['msglvl']);
?>