-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_handler.php
More file actions
58 lines (47 loc) · 2.32 KB
/
request_handler.php
File metadata and controls
58 lines (47 loc) · 2.32 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
<?php
session_start();
if (!isset($_SESSION["user_id"])){
exit("Page ERROR!");
}
require_once("sql_connect.php");
if (isset($_POST["request"])){
$time = date("l h:i:sa");
$sql1 = "SELECT * FROM users WHERE userID='{$_POST["request"]}'";
$result1 = $conn->query($sql1);
if($result1->num_rows > 0){
$valid = $result1->fetch_assoc();
if($valid["userID"] == $_SESSION["user_id"]){
exit("Cannot link self!");
}else{
$sql2 = "SELECT * FROM linked WHERE person1='{$_SESSION["user_id"]}' AND person2='{$_POST["request"]}' OR person1='{$_POST["request"]}' AND person2='{$_SESSION["user_id"]}'";
$result2 = $conn->query($sql2);
if($result2->num_rows > 0){
exit("Already Linked!");
}else{
$sql3 = "SELECT * FROM requests WHERE request_from='{$_SESSION["user_id"]}' AND request_to='{$_POST["request"]}' OR request_from='{$_POST["request"]}' AND request_to='{$_SESSION["user_id"]}'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0){
exit("Already sent!");
}
$data = $conn->prepare("INSERT INTO requests(request_from, request_to, request_date)VALUES(?, ?, ?)");
$data->bind_param("sss", $_SESSION["user_id"], $_POST["request"], $time);
$data->execute() or die("Error tryagain!");
// SEND A NOTIFICATION
$sql3 = "SELECT * FROM users WHERE userID='{$_SESSION["user_id"]}'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0){
$valid3 = $result3->fetch_assoc();
$mesg = "You have a new link request from ".$valid3["username"]."";
$time2 = date("l h:i:sa");
$data2 = $conn->prepare("INSERT INTO notifications(notification_from, notification_to, message, time)VALUES(?, ?, ?, ?)");
$data2->bind_param("ssss", $_SESSION["user_id"], $_POST["request"],$mesg, $time2);
$data2->execute();
}
exit("Sent");
}
}
}else{
exit("Cannot find host!");
}
}
?>