-
Notifications
You must be signed in to change notification settings - Fork 4
/
deleteeventadmin.php
179 lines (145 loc) · 3.64 KB
/
deleteeventadmin.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
<?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 create an event by the Teachers or Admin staff
Author: Ameen
First Created: 19-09-2017
Last Modified: 19-09-2017 @Abhijith
*/
/**********************************
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));
}
if(!isset($_POST['id'])){
$output = array(
"status" => false,
"error" => "Event ID is not set",
"errorCode" => 102,
"response" => ""
);
die(json_encode($output));
}
if(!isset($_POST['isRecurring'])){
$output = array(
"status" => false,
"error" => "isRecurring Flag is not set",
"errorCode" => 102,
"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'];
$deleteAll = $_POST['deleteAll'];
$isRecurring = $_POST['isRecurring'];
/****************
3. MAIN LOGIC
*****************/
//3.1 CONNECTION TO CUSTOM DATABASE
define('INCLUDE_CHECK', true);
require 'connect_'.$schoolCode.'.php';
$exist = mysql_fetch_assoc(mysql_query("SELECT * FROM `d_events` WHERE `id`='{$id}'"));
if($exist)
{
if($deleteAll == 0){
mysql_query("DELETE FROM `d_events` WHERE `id`='{$id}' ");
$response=array(
"message"=>"event deleted"
);
$output = array(
"status" => true,
"error" => "",
"errorCode" => "",
"response" =>$response
);
die(json_encode($output));
}
else if(($deleteAll == 1) && ($isRecurring == 1)){
$recursionId = $_POST['recursionId'];
mysql_query("DELETE FROM `d_events` WHERE `recursionId`='{$recursionId}' ");
}
}
else
{
$response=array(
"message"=>"Such an id does not exist"
);
$output = array(
"status" => false,
"error" => "",
"errorCode" => "402",
"response" =>$response
);
die(json_encode($output));
}
?>