-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudyrequest.php
More file actions
96 lines (94 loc) · 2.09 KB
/
studyrequest.php
File metadata and controls
96 lines (94 loc) · 2.09 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
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
<?php
header('Content-Type: application/json');
require_once "Database2.php";
$inData = getRequestInfo();
$userID = -1;
$bID = -1;
function getRequestInfo()
{
return json_decode(file_get_contents('php://input'), true);
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// $authHeader = $_SERVER['HTTP_AUTHORIZATION'];
//
// $arr = explode(" ", $authHeader);
// $jwt = $arr[1];
$userID = trim($inData["UserID"]);
$bID = trim($inData["Buddy"]);
$sql = "SELECT * FROM Request WHERE sender = ? AND reciever = ?";
if ($stmt = $mysqli->prepare($sql))
{
$stmt->bind_param("ii", $uIDParam, $bIDParam);
$uIDParam = $userID;
$bIDParam = $bID;
if ($stmt->execute())
{
$stmt->store_result();
if ($stmt->num_rows() < 1)
{
$stmt->close();
$sql = "INSERT INTO Request (sender, reciever, response) VALUES (?, ?, ?)";
if ($stmt = $mysqli->prepare($sql))
{
$stmt->bind_param("iii", $uIDParam, $bIDParam, $responseParam);
$uIDParam = $userID;
$bIDParam = $bID;
$responseParam = 0;
if ($stmt->execute())
{
$data = array(
"Error"=> ""
);
http_response_code(200);
echo json_encode($data);
exit();
}
else
{
$data = array("Error"=>"Failed to make request");
http_response_code(500);
echo json_encode($data);
exit();
}
}
else
{
$data = array(
"Error"=>"Statement Error! $stmt->error"
);
http_response_code(418);
echo json_encode($data);
}
}
else
{
$stmt->bind_result($userID, $bID, $response);
if ($stmt->fetch())
{
if ($response < 0)
{
$data = array(
"Message"=> "Request Denied",
"Error"=> ""
);
http_response_code(200);
echo json_encode($data);
exit();
}
else
{
$data = array(
"Message"=> "Request Accepted",
"Error"=> ""
);
http_response_code(200);
echo json_encode($data);
exit();
}
}
}
}
}
}
?>