-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.php
108 lines (97 loc) · 3.38 KB
/
messages.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
<?php
session_start();
if((!isset($_SESSION['loggedin'])) && (!isset($_SESSION['drloggedin']))){
header("location: login.php");
}
?>
<?php include "partials/connection.php";
$sql="CREATE TABLE `ihealth`.`messages` ( `srno` INT NOT NULL AUTO_INCREMENT , `roomname` VARCHAR(20) NOT NULL , `sender` VARCHAR(20) NOT NULL , `receiver` VARCHAR(20) NOT NULL , `msg` VARCHAR(50) NOT NULL , `date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`srno`)) ENGINE = InnoDB;
";
$result=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="partials/navbar.css">
<link rel="stylesheet" href="partials/footer.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Messages</title>
<style>
*{
margin:0px;
padding:0px;
}
.container{
height: 500px;
/* border: 2px solid red; */
width: 400px;
margin: auto;
padding: 20px;
background: black;
color: white;
margin: 20px auto;
overflow-y:scroll;
border-radius: 10px;
}
.box{
margin: 10px;
border: 2px solid black;
padding: 5px 10px;
background: beige;
border-radius: 10px;
color:black;
}
#image {
position: fixed;
z-index: -1;
width: 30%;
top: 100px;
}
</style>
</head>
<body>
<?php require "partials/navbar.php";?>
<img id="image" src="images/chat.svg">
<div class="content">
<br>
<div class="container">
<h1>Your Messages</h1>
<?php
$list=array();
function alreadyPresent($roomname,$list){
$size = count($list);
for($i=0;$i<$size;$i++){
if($list[$i]==$roomname){
return true;
}
}
return false;
}
$sql="SELECT * FROM `messages` WHERE `sender` LIKE '".$_SESSION["username"]."' OR `receiver` LIKE '".$_SESSION["username"]."'";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($result)){
if(!alreadyPresent($row["roomname"],$list)){
array_push($list,$row["roomname"]);
echo '<div class="box">
<div><a href="http://localhost/iHealth/chats/chat.php?roomname='.$row["roomname"].'&receiver='.$row["receiver"].'">Chat Room: '.$row["roomname"].'</a></div>
</div>';
}
}
?>
<!-- <div class="box">
<div><a href="http://localhost/iHealth/chats/chat.php?roomname=sammeer-rashid&receiver=rashid">username:Rashid</a></div>
</div>
<div class="box">
<div>username:Rashid</div>
</div>
<div class="box">
<div>username:Rashid</div>
</div> -->
</div>
<?php require 'partials/footer.html'?>
</div>
</body>
</html>