-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatAccountLoadProcess.php
148 lines (137 loc) · 9.34 KB
/
chatAccountLoadProcess.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
<?php
session_start();
require "connection.php";
if (isset($_SESSION["user"]) & !empty($_SESSION["user"])) {
$chatAccountResultset = Database::search("SELECT * FROM `chat` INNER JOIN `chat_status` ON
`chat`.`chat_status_id`=`chat_status`.`id` WHERE `from_user`='" . $_SESSION["user"]["email"] . "' OR `to_user`='" . $_SESSION["user"]["email"] . "' ORDER BY `send_date_time` DESC");
$chatAccountRownumber = $chatAccountResultset->num_rows;
$chatAccountArray = array();
$isFromUserAvailable;
if ($chatAccountRownumber > 0) {
for ($c = 0; $c < $chatAccountRownumber; $c++) {
$chatAccountData = $chatAccountResultset->fetch_assoc();
if ($chatAccountData["from_user"] != $_SESSION["user"]["email"]) {
$isFromUserAvailable = true;
} else if ($chatAccountData["to_user"] != $_SESSION["user"]["email"]) {
$isFromUserAvailable = false;
}
if ($isFromUserAvailable) {
if (!in_array($chatAccountData["from_user"], $chatAccountArray)) {
array_push($chatAccountArray, $chatAccountData["from_user"]);
$chatUserResultset = Database::search("SELECT * FROM `user` WHERE `email`='" . $chatAccountData["from_user"] . "'");
$chatUserData = $chatUserResultset->fetch_assoc();
?>
<!-- message card -->
<button class="def-popular-post rounded-5 border-0 text-decoration-none w-100" onclick="privateChatContentLoad('<?php echo ($chatUserData['email']); ?>');">
<div class="col-12">
<div class="row">
<div class="col-3 p-2 d-flex flex-row justify-content-end align-items-start my-auto">
<?php
$isUserProfileImageSet;
$allProfileImageNameArray = scandir("resources/images/profile_images/");
$targetProfileImageName = explode("@", $chatUserData['email'])[0] . ".jpeg";
foreach ($allProfileImageNameArray as $imageFileName) {
if ($imageFileName == $targetProfileImageName) {
$isUserProfileImageSet = true;
break;
} else {
$isUserProfileImageSet = false;
}
}
if ($isUserProfileImageSet) {
?>
<img src="resources/images/profile_images/<?php echo ($targetProfileImageName); ?>" class="img-fluid popular-post-img" alt="chat-profile-image" />
<?php
} else {
?>
<img src="resources/images/profile_images/def-profile.svg" class="img-fluid popular-post-img" alt="chat-profile-image" />
<?php
}
?>
</div>
<div class="col-9 my-auto">
<div class="row">
<div class="col-12 d-flex flex-row justify-content-start">
<span class="popular-post-header text-capitalize"><?php echo ($chatUserData["first_name"] . " " . $chatUserData["last_name"]);
if ($chatAccountData["c_type"] == "unseen") {
?>
<i class="bi bi-circle-fill required-symbol" data-bs-toggle="tooltip" data-bs-title="New Message" data-bs-custom-class="custom-tooltip"></i>
<?php
} ?></span>
</div>
<div class="col-12 d-flex flex-row justify-content-between my-auto pe-4">
<span class="my-auto"><?php echo ($chatAccountData["chat_content"]); ?></span>
<span class="post-date-text my-auto"><?php echo (date("h:i a", strtotime($chatAccountData["send_date_time"]))); ?></span>
</div>
</div>
</div>
</div>
</div>
</button>
<!-- message card -->
<?php
}
} else {
if (!in_array($chatAccountData["to_user"], $chatAccountArray)) {
array_push($chatAccountArray, $chatAccountData["to_user"]);
$chatUserResultset2 = Database::search("SELECT * FROM `user` WHERE `email`='" . $chatAccountData["to_user"] . "'");
$chatUserData2 = $chatUserResultset2->fetch_assoc();
?>
<!-- message card -->
<button class="def-popular-post rounded-5 border-0 text-decoration-none w-100" onclick="privateChatContentLoad('<?php echo ($chatUserData2['email']); ?>');">
<div class="col-12">
<div class="row">
<div class="col-3 p-2 d-flex flex-row justify-content-end align-items-start my-auto">
<?php
$isUserProfileImageSet2;
$allProfileImageNameArray2 = scandir("resources/images/profile_images");
$targetProfileImageName2 = explode("@", $chatUserData2['email'])[0] . ".jpeg";
foreach ($allProfileImageNameArray2 as $imageFileName2) {
if ($imageFileName2 == $targetProfileImageName2) {
$isUserProfileImageSet2 = true;
break;
} else {
$isUserProfileImageSet2 = false;
}
}
if ($isUserProfileImageSet2) {
?>
<img src="resources/images/profile_images/<?php echo ($targetProfileImageName2); ?>" class="img-fluid popular-post-img" alt="chat-profile-image" />
<?php
} else {
?>
<img src="resources/images/profile_images/def-profile.svg" class="img-fluid popular-post-img" alt="chat-profile-image" />
<?php
}
?>
</div>
<div class="col-9 my-auto">
<div class="row">
<div class="col-12 d-flex flex-row justify-content-start">
<span class="popular-post-header text-capitalize"><?php echo ($chatUserData2["first_name"] . " " . $chatUserData2["last_name"]);
if ($chatAccountData["c_type"] == "unseen") {
?>
<i class="bi bi-circle-fill required-symbol" data-bs-toggle="tooltip" data-bs-title="New Message" data-bs-custom-class="custom-tooltip"></i>
<?php
} ?>
</span>
</div>
<div class="col-12 d-flex flex-row justify-content-between my-auto pe-4">
<span class="my-auto"><?php echo ($chatAccountData["chat_content"]); ?></span>
<span class="post-date-text my-auto"><?php echo (date("h:i a", strtotime($chatAccountData["send_date_time"]))); ?></span>
</div>
</div>
</div>
</div>
</div>
</button>
<!-- message card -->
<?php
}
}
}
}
} else {
echo ("user rejected");
}
?>