-
Notifications
You must be signed in to change notification settings - Fork 0
/
applications.php
85 lines (59 loc) · 2.03 KB
/
applications.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
<?php
include_once 'config.php';
require_once 'mail-functions.php';
if (isset($_POST['employeeSubm'])) {
userApplication($pdo);
} elseif (isset($_POST['applist'])) {
listApplications($pdo);
}
function userApplication($pdo) {
$date_from_init = $_POST['date_from'];
$date_to_init = $_POST['date_to'];
$date_from = date_format(date_create_from_format('d/m/Y', $_POST['date_from']), 'Y-m-d');
$date_to = date_format(date_create_from_format('d/m/Y', $_POST['date_to']), 'Y-m-d');
$current_date = date("l jS \of F Y h:i:s A");
$reason = $_POST['comments'];
$user_id = $_SESSION['user']['user_id'];
$userData = $_SESSION['user'];
$sql = 'INSERT INTO application (date_created,date_from,date_to,reason,status_id,user_id) VALUES(now(),:date_from,:date_to,:reason,:status_id,:user_data_id)';
$stmt = $pdo->prepare($sql);
$stmt->execute([
':date_from' => $date_from,
':date_to' => $date_to,
':reason' => $reason,
':status_id' => 1,
':user_data_id' => $user_id
]);
$inserted_id = $pdo->lastInsertId();
sendMailToAdmin($userData,$date_from_init,$date_to_init,$reason,$inserted_id,$current_date);
exit;
$_SESSION['import_success']=1;
header("Location: dashboard.php");
}
function listApplications($pdo) {
$user_data_id = $_SESSION['user']['user_id'];
// $z= '"System Architect",
// "Edinburgh",
// "5421",
// "2011/04/25",
// "$320,800"';
// echo $z;
$stmt = $pdo->prepare("SELECT
DATE_FORMAT(date_created, '%d/%m/%Y %H:%i') as date_created,
CONCAT (DATE_FORMAT(date_from, '%d/%m/%Y'),'-',DATE_FORMAT(date_to, '%d/%m/%Y')) as dates_requested,
DATEDIFF(date_from,date_to) as days_diff,
name as status
FROM application
inner join status
ON status.status_id=application.status_id
WHERE user_id=:user_data_id");
$stmt->execute([':user_data_id' => $user_data_id ]);
if ($stmt->rowCount() > 0) {
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$z = json_encode($result);
print_r($z);
return $z;
} else {
return '[]';
}
}