-
Notifications
You must be signed in to change notification settings - Fork 4
/
rejectleave.php
152 lines (122 loc) · 3.12 KB
/
rejectleave.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
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Credentials: true');
error_reporting(0);
$_POST = json_decode(file_get_contents('php://input'), true);
/*******************
0. DOCUMENTATION
********************/
/*
Version: 1.0
Admin API: YES
Brief: To reject a leave request
Author: Shafeef
First Created: 19-09-2017
Last Modified: 28-11-2017 @Shafeef
*/
/**********************************
1.1 AUTHENTICATION STANDARD PART
***********************************/
//Encryption Credentials
define('SECURE_CHECK', true);
require 'secure.php';
//Encryption Validation
if(!isset($_POST['token'])){
$output = array(
"status" => false,
"error" => "Access Token Missing",
"errorCode" => 103,
"response" => ""
);
die(json_encode($output));
}
$token = $_POST['token'];
$decryptedtoken = openssl_decrypt($token, $encryptionMethod, $secretHash);
$tokenid = json_decode($decryptedtoken, true);
//Expiry Validation
date_default_timezone_set('Asia/Calcutta');
$dateStamp = date_create($tokenid['date']);
$today = date_create(date("Y-m-j"));
$interval = date_diff($dateStamp, $today);
$interval = $interval->format('%a');
if($interval > $tokenExpiryDays){
$output = array(
"status" => false,
"error" => "Login Expired",
"errorCode" => 401,
"response" => ""
);
die(json_encode($output));
}
/**********************************
1.2 AUTHENTICATION CUSTOM PART
***********************************/
//Check if the token is valid
if(!($tokenid['schoolCode'] == "")){
$schoolCode = $tokenid['schoolCode'];
$admin_mobile = $tokenid['mobile'];
$admin_role = $tokenid['role'];
}
else{
$output = array(
"status" => false,
"error" => "Invalid Token",
"errorCode" => 402,
"response" => ""
);
die(json_encode($output));
}
//Check if the user has permission to access this API
if($admin_role != "ADMIN" && $admin_role != "TEACHER"){
$output = array(
"status" => false,
"error" => "Access Restricted",
"errorCode" => 403,
"response" => ""
);
die(json_encode($output));
}
//Validations
if(!isset($_POST['id'])){
$output = array(
"status" => false,
"error" => "id is not set",
"errorCode" => 103,
"response" => ""
);
die(json_encode($output));
}
if(!isset($_POST['comments'])){
$output = array(
"status" => false,
"error" => "Comments is not set",
"errorCode" => 103,
"response" => ""
);
die(json_encode($output));
}
//REQUIRED PARAMETERS
date_default_timezone_set('Asia/Kolkata');
$date = date('m/d/Y h:i:s a', time());
$id = $_POST['id'];
$comments = $_POST['comments']
/****************
3. MAIN LOGIC
*****************/
//3.1 CONNECTION TO CUSTOM DATABASE
define('INCLUDE_CHECK', true);
require 'connect_'.$schoolCode.'.php';
mysql_query("UPDATE `d_leaves` SET `status`= 2, `comments`='{$comments}' WHERE `id`='{$id}'");
$response = array(
"message" => "Leave Rejected Sucessfully"
);
$output = array(
"status" => true,
"error" => "",
"errorCode" => "",
"response" => $response
);
die(json_encode($output));
?>