-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendRequestMessageProcess.php
33 lines (30 loc) · 1.42 KB
/
sendRequestMessageProcess.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
<?php
session_start();
require "connection.php";
if (isset($_SESSION["user"]) & !empty($_SESSION["user"])) {
if (isset($_POST["recvrMl"]) & !empty($_POST["recvrMl"])) {
if ($_SESSION["user"]["email"] != $_POST["recvrMl"]) {
$chatResultset = Database::search("SELECT * FROM `chat` WHERE
(`from_user`='" . $_SESSION["user"]["email"] . "' AND `to_user`='" . $_POST["recvrMl"] . "') OR
(`from_user`='" . $_POST["recvrMl"] . "' AND `to_user`='" . $_SESSION["user"]["email"] . "')");
$chatRownumber = $chatResultset->num_rows;
if ($chatRownumber < 1) {
$dateTime = new DateTime();
$timeZone = new DateTimeZone("Asia/colombo");
$dateTime->setTimezone($timeZone);
$newDateTimeString = $dateTime->format("Y-m-d H:i:s");
Database::insertUpdateDelete("INSERT INTO `chat` (`from_user`,`to_user`,`chat_content`,`chat_status_id`,`send_date_time`) VALUES
('" . $_SESSION["user"]["email"] . "','" . $_POST["recvrMl"] . "','Hello there!!','4','" . $newDateTimeString . "')");
echo ("success");
} else {
echo ("The chat is already available");
}
} else {
echo ("Can not chat with yourself");
}
} else {
echo ("Something went wrong");
}
} else {
echo ("user rejected");
}