-
Notifications
You must be signed in to change notification settings - Fork 2
/
message.php
159 lines (123 loc) · 5.58 KB
/
message.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
149
150
151
152
153
154
155
156
157
158
159
<?php
if(session_status()!=PHP_SESSION_ACTIVE)
session_start();
if (!isset($_SESSION['user']) or $_SESSION['user']==""){
session_unset();
session_destroy();
echo "<script>location.replace('login.php?next=message.php');</script>";
}
include "db_connect.php";
$con=Connect();
$name=$_SESSION['user'];
$xyz=mysqli_query($con,"SELECT * from messages where user1='".$name['username']."' or user2='".$name['username']."' order by time desc");
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style/main.css">
<link rel="stylesheet" type="text/css" href="style/form.css">
<link rel="stylesheet" type="text/css" href="style/popup.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- IMPORT FONTS -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Lato&display=swap" rel="stylesheet">
<!-- ICONS !-->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.7.0/css/all.css'>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Menu -->
<script type="text/javascript">
function ToggleNav(){
$('ul.nav').slideToggle("slow");
}
</script>
<title>MESSAGES | <?php echo $_SESSION['user']['name']?></title>
<style type="text/css">
a.btn{
min-width: 0;
display: inline-block;
user-select: none;
cursor: pointer;
}
</style>
<script type="text/javascript">
// Close opup when user clicks outside the content area
window.onclick = function(event) {
if (event.target == document.getElementById('msg')) {
document.getElementById('msg').style.display = "none";
}
}
setInterval(function(){
$('#msg-box').load('message.php #msg-box');
}, 30000);
$(function(){
$('.banner').slideDown("slow");
})
</script>
</head>
<body>
<header>
<div id="toggle"><a onclick="$('ul.nav').slideToggle('slow');"><i class="material-icons" style="font-size:1.5em;color:#fff">menu</i></a></div>
<div class="profile">
<img src="prof-pic/<?php echo $_SESSION['user']['username'];?>.png" onerror="this.src='prof-pic/default.png';" class="prof-pic">
<div class="prof-name"><?php echo $_SESSION['user']['name']; ?></div>
</div>
<ul class="nav">
<li><a href="index.php">Home</a></li>
<li><a href="assg.php">Assignments</a></li>
<li><a href="message.php" class="selected">Messages</a></li>
<li><a href="news.php">Announcements</a></li>
<li><a href="search.php">Find user</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</header>
<div class="banner">
<i class="fas fa-exclamation-circle" style="color: #888"></i> An update to this page will be available in the next release
<span class="banner-close" onclick="$('.banner').slideUp();">×</span>
</div>
<div class="container">
<span class="title">Messages</span>
<a class="btn" style="border-radius: 50%; position: fixed; right: 1ch; z-index: 1; box-shadow: -3px 3px 3px #666666; " onclick="$('#msg-box').load('message.php #msg-box');"><i class="fas fa-redo"></i></a>
<br><a class="btn" onclick="document.getElementById('msg').style.display='block'" style="width:auto;"><i class="fas fa-plus"></i> COMPOSE</a><br><br>
<div id="msg-box" class="msg">
<?php while ($msg=mysqli_fetch_assoc($xyz)) {
if ($msg['user1']==$_SESSION['user']['username']){ ?>
<div class="msg-sent" align="right">
<div class="msg-rec"><a href="search.php?id=<?php echo $msg['user2']; ?>&by=username"><?php echo $msg['user2']; ?></a></div>
<?php } else { ?>
<div class="msg-received">
<div class="msg-rec"><a href="search.php?id=<?php echo $msg['user1']; ?>&by=username"><?php echo $msg['user1']; ?></a></div>
<?php } ?>
<div class="msg-desc"><?php echo nl2br($msg['msg']); ?></div>
<div class="msg-time"><?php echo $msg['time']; ?></div>
</div>
<?php }
Close($con);?>
</div>
</div>
<div class="popup" id="msg">
<form class="popup-content animate" action="scripts/post-msg.php" method="POST">
<div class="box">
<div class="h">Compose Message<span onclick="document.getElementById('msg').style.display='none'" class="close" style=" float: right;">×</span></div>
<div><input type="text" readonly="True" value="<?php echo $_SESSION['user']['username'] ?>" name="user1"></div>
<div><input type="text" name="user2" value="<?php echo $_REQUEST['user2']?>" required="True" placeholder="To" pattern="[a-zA-Z0-9]+"></div>
<?php if (isset($_POST['post-fail']) and $_POST['post-fail']!=''){ ?>
<div style="color: red; font-style: italic; font-size: 0.8em;"><?php echo $_POST['post-fail'];?></div>
<?php }?>
<div><textarea name="msg" rows="5" maxlength="1024" placeholder="Enter the Announcement here..." required="True"><?php echo $_POST['msg']?></textarea></div>
<div><input type="submit"></div>
</div>
</form>
</div>
<?php if (isset($_POST['post-fail']) and $_POST['post-fail']!='')
echo "<script>document.getElementById('msg').style.display='block'</script>"
?>
<?php if (isset($_REQUEST['user2']) and $_REQUEST['user2']!='')
echo "<script>document.getElementById('msg').style.display='block'</script>"
?>
<footer>
<div class="copy">© All Rights Reserved</div>
<div class="last-login"><?php echo "Last Logout: ".$_SESSION['user']['active'];?></div>
</footer>