-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadUsers.php
More file actions
74 lines (49 loc) · 2.48 KB
/
loadUsers.php
File metadata and controls
74 lines (49 loc) · 2.48 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
<?php
require "connection.php";
if(isset($_POST["requestJSONText"])){
$requestJSONText = $_POST["requestJSONText"];
$requestPhpObj = json_decode($requestJSONText);
$userTable = Database::search("SELECT * FROM `user` WHERE `id`!='".$requestPhpObj->id."' AND (`fname` LIKE '".$_POST["text"]."%' OR `lname` LIKE '".$_POST["text"]."%') ");
$phpResponseArray = array();
for($x=0;$x<$userTable->num_rows;$x++){
$phpArrayItemObject = new stdClass();
$userTableRow = $userTable->fetch_assoc();
$phpArrayItemObject->pic = $userTableRow["profile_url"];
$phpArrayItemObject->name = $userTableRow["fname"]." ".$userTableRow["lname"];
$phpArrayItemObject->id = $userTableRow["id"];
$userChatTable = Database::search("SELECT * FROM `chat` WHERE (`user_from_id`='".$requestPhpObj->id."' AND `user_to_id`='".$userTableRow["id"]."')
OR(`user_from_id`='".$userTableRow["id"]."' AND `user_to_id`='".$requestPhpObj->id."') ORDER BY `date_time` DESC");
if($userChatTable->num_rows == 0){
$phpArrayItemObject->msg = "";
$phpArrayItemObject->time = "";
$phpArrayItemObject->count = "0";
$phpArrayItemObject->rstatus ="0";
}else{
$userChatTable2 = Database::search("SELECT * FROM `chat` WHERE (`user_from_id`='".$userTableRow["id"]."' AND `user_to_id`='".$requestPhpObj->id."') ORDER BY `date_time` DESC");
//unseen chat count
$unseenChatCount = 0;
//first row
$lastChatRow = $userChatTable2->fetch_assoc();
if($lastChatRow["status_id"]==1){
$unseenChatCount++;
}
$phpArrayItemObject->msg = $lastChatRow["message"];
$phpDateTimeObj = strtotime($lastChatRow["date_time"]);
$timeStr = date('h:i a',$phpDateTimeObj);
$phpArrayItemObject->time = $timeStr;
for($t=0;$t<$userChatTable2->num_rows;$t++){
//other rows
$newChatRow = $userChatTable2->fetch_assoc();
if($newChatRow==1){
$unseenChatCount++;
}
}
$phpArrayItemObject->count = $unseenChatCount;
$phpArrayItemObject->rstatus ="0";
}
array_push($phpResponseArray,$phpArrayItemObject);
}
$jsonResponseObject = json_encode($phpResponseArray);
echo($jsonResponseObject);
}
?>