-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.php
265 lines (224 loc) · 11.9 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!doctype html>
<?php
include("config.php");
if(empty($_SESSION['id'])){
header('location:login.html');
exit;
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="60">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="manifest" href="favicon/site.webmanifest">
<link rel="mask-icon" href="favicon/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="favicon/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="favicon/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<title>Chat</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="common.css" rel="stylesheet">
<link href="messages.css" rel="stylesheet">
<link href="fonts.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top">
<div class="navbar-collapse collapse w-100 order-1 order-md-0 dual-collapse2">
<a class="navbar-brand" href="index.php" style="font-weight: 700;">Konnect.ed</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="profile.php">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="network.php">Network</a>
</li>
<li class="nav-item">
<a class="nav-link" href="messages.php">Messages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="jobs.php">Jobs</a>
</li>
</ul>
</div>
<div class="mx-auto order-2">
<form class="navbar-brand mx-auto form-inline" method="post">
<input class="form-control multitext" name="information" type="text" placeholder="Who are you looking for?" aria-label="Search">
<button class="btn btn-default" formaction="search.php" style="" type="submit">Search</button>
</form>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<form class="form-inline nav-item">
<button class="btn btn-default" formaction="logout.php" style="font-weight:600;" type="submit">Disconnect</button>
</form>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
<div class='container'>
<h3 style='color:white; font-weight:700; font-size:3em;'>My messages</h3><br>
</div>
<?php
$id = $_SESSION["id"];
$requete = "SELECT g.ID, g.Name, g.Notif FROM chatgroups g JOIN chatmessages m on m.ID_Conv = g.ID ";
$requete .= " JOIN objectposts o on o.ID = m.ID_Post WHERE g.ID_User = ? GROUP BY g.ID ORDER by MAX(o.Date_Post) DESC";
$req = mysqli_prepare($db, $requete);
mysqli_stmt_bind_param($req, "i", $id);
mysqli_stmt_execute($req);
mysqli_stmt_store_result($req);
mysqli_stmt_bind_result($req, $col_ID, $col_Name, $col_Notif);
echo "<h2 style='color:white;font-weight:600;'>Ongoing discussions</h2>";
$i = 0;
echo "<div>";
while(mysqli_stmt_fetch($req)){
$i += 1;
if($i == 5){
echo "</div>
<div id='otherDiscussions' style ='display: none;'> ";
}
echo "<button class='btn btn-lg btn-primary btn-block' " ;
if($col_Notif == "new"){
echo "style='background-color : #cc8400;'";
}
echo "onclick=\"window.location.href='discussion.php?idDiscussion={$col_ID}'\" type='submit' > $col_Name </button><br>";
}
echo "</div>";
if($i>4){
echo "<button class='btn btn-sm btn-success btn-block' onclick='showhide()' id='hidebutton' >Show More</button><br>";
}
$requete = "SELECT DISTINCT us.ID, us.Firstname, us.Lastname, us.Pseudo FROM users us, friendships fs WHERE fs.ID_User1 = ?";
$requete .=" AND us.ID = fs.ID_User2 AND fs.Status = 'Accepted' AND fs.Relationship = 'Friend'";
$req = mysqli_prepare($db, $requete);
mysqli_stmt_bind_param($req, "i", $id);
mysqli_stmt_execute($req);
mysqli_stmt_store_result($req);
mysqli_stmt_bind_result($req, $col_IDUser, $col_FirstName, $col_LastName, $col_Pseudo);
echo "<br><h2 style='color:white;font-weight:600;'>Start a new discussion</h2>";
echo "<h3 style='color:white;'>Friends</h3>";
while(mysqli_stmt_fetch($req)){
echo "<form action='discussion.php' class='form-post' method='post' >";
echo "<input type='hidden' name='idUser' value='$col_IDUser' > ";
echo "<input type='hidden' name='firstname' value='$col_FirstName' > ";
echo "<input type='hidden' name='lastname' value='$col_LastName' > ";
echo "<button class='btn btn-lg btn-primary btn-block' type='submit' >$col_FirstName $col_LastName</button><br>";
echo "</form><br>";
}
$requete = "SELECT DISTINCT us.ID, us.Firstname, us.Lastname, us.Pseudo FROM users us, friendships fs WHERE fs.ID_User1 = ?";
$requete .=" AND us.ID = fs.ID_User2 AND fs.Status = 'Accepted' AND fs.Relationship = 'Pro'";
$req = mysqli_prepare($db, $requete);
mysqli_stmt_bind_param($req, "i", $id);
mysqli_stmt_execute($req);
mysqli_stmt_store_result($req);
mysqli_stmt_bind_result($req, $col_IDUser, $col_FirstName, $col_LastName, $col_Pseudo);
echo "<h3 style='color:white;'>Professionals</h3>";
while(mysqli_stmt_fetch($req)){
echo "<form action='discussion.php' class='form-post' method='post' >";
echo "<input type='hidden' name='idUser' value='$col_IDUser' > ";
echo "<input type='hidden' name='firstname' value='$col_FirstName' > ";
echo "<input type='hidden' name='lastname' value='$col_LastName' > ";
echo "<button class='btn btn-lg btn-primary btn-block' type='submit' >$col_FirstName $col_LastName </button> <br>";
echo "</form>";
}
echo"</div>";
echo"<div class='col-sm-6' style=''>";
if(!empty($_SESSION["idDiscussion"])){
$idDiscussion = $_SESSION["idDiscussion"];
$req = mysqli_prepare($db, "SELECT Name FROM chatgroups WHERE ID = ? and ID_User = ?" );
mysqli_stmt_bind_param($req, "ii", $idDiscussion, $id);
mysqli_stmt_execute($req);
mysqli_stmt_store_result($req);
mysqli_stmt_bind_result($req, $Name);
while (mysqli_stmt_fetch($req)) {
// code...
}
$requete = "SELECT us.ID, us.FirstName, us.LastName, ob.Url_Media, ob.Description FROM users us,";
$requete .=" objectposts ob, chatmessages me, chatgroups gr WHERE gr.ID = ? AND gr.ID_User = ob.ID_User AND ";
$requete .=" ob.ID_User = us.ID AND ob.ID = me.ID_Post AND me.ID_Conv = gr.ID ORDER BY ob.Date_Post DESC";
$req = mysqli_prepare($db, $requete);
mysqli_stmt_bind_param($req, "i", $idDiscussion);
mysqli_stmt_execute($req);
mysqli_stmt_store_result($req);
mysqli_stmt_bind_result($req, $col_IDChatter, $col_FirstName, $col_LastName, $col_UrlMedia, $col_Descri);
echo "<div class='holder' ><form class='form-inline' method='post'>";
echo "<h3 style='color:white; font-weight:700; font-size:2em; border-radius:15px' id='nameChat' name='nameChat' contenteditable='false'>$Name</h3>";
echo "<input class='form-control multitext mr-sm-2' style='display:none; color:black: background-color:white' name='name2' id='name2' type='text' placeholder='$Name' aria-label='Write a message'>";
echo "<button class='btn btn-primary' formaction='updateName.php' id='submit' type='submit' name='submit' style='display:none;'>Validate</button>";
echo "</form>";
echo "<button class='btn btn-primary' onclick=\"hideEdit('$Name')\" id='cancel' style='display:none;' >Cancel</button>";
echo "<button class='btn btn-primary' id='edit' onclick=\"showEdit()\">Edit Chat name</button>";
echo "</div>";
echo "<form action='postMessage.php' class='form-post' method='post' enctype='multipart/form-data'>";
echo "<input class='form-control multitext mr-sm-2' style=''name='description' id='description' type='text' placeholder='Write a message' aria-label='Write a message'>";
echo "<input type='hidden' name='idDiscussion' value='$idDiscussion' id='idpost'> ";
echo "<label for='fileToUpload' class='btn btn-lg btn-default mr-sm-2' style='cursor: pointer;'>Add a photo</label>
<input type='file' name='fileToUpload' value='fileToUpload' id='fileToUpload' accept='.jpg, .jpeg, .png'>";
echo "<button class='btn btn-primary' type='submit' name='submit' >Send Message</button>";
echo "</form>";
echo "<div class='preview' style='color:white;'>
<p>No photo added to the post</p>
</div>";
echo "<main role='main' class='holder'>";
echo "<div class='jumbotron message'>";
while(mysqli_stmt_fetch($req)){
echo "<div class='col-sm-12' style='overflow: hidden;padding: 0px;'>";
if($col_IDChatter != $id){
echo "<div class='jumbotron float-left text-left other-person'>";
//echo "<h4 align='left'>$col_FirstName $col_LastName</h4>";
echo "<p class='message' align='left'>$col_Descri</p>";
if(!empty($col_UrlMedia)){
echo "<img src ='$col_UrlMedia' alt ='LinkedMedia'/>";
}
}
else {
echo "<div class='jumbotron float-right text-left my-person'>";
//echo "<h4 align='right' style=''>$col_FirstName $col_LastName</h4>";
echo "<p class='message' align='right' style=''>$col_Descri</p>";
if(!empty($col_UrlMedia)){
echo "<img src='$col_UrlMedia' class='' alt ='LinkedMedia'/>";
}
}
echo "</div></div>";
}
echo "</div>";
echo "</main>";
}
else if(isset($_SESSION['firstname']) && isset($_SESSION['lastname'])){
$firstname = isset($_SESSION['firstname'])?$_SESSION['firstname']:"";
$lastname = isset($_SESSION['lastname'])?$_SESSION['lastname']:"";
echo "<div class='container'><h3 style='color:white; font-weight:700; font-size:2em;'>$firstname $lastname</h3><br></div>";
echo "<form action='postMessage.php' class='form-post' method='post' enctype='multipart/form-data'>";
echo "<input class='form-control multitext mr-sm-2' name='description' id='description' type='text' placeholder='Write a message' aria-label='Write a message'>";
echo "<label for='fileToUpload' class='btn btn-lg btn-default mr-sm-2' style='cursor: pointer;'>Add a photo</label>
<input type='file' name='fileToUpload' value='fileToUpload' id='fileToUpload' accept='.jpg, .jpeg, .png'>";
echo "<button class='btn btn-primary' type='submit' name='submit' >Send Message</button>";
echo "</form>";
echo "<div class='preview' style='color:white;>
<p>No photo added to the post</p>
</div>";
}
echo "</div>";
echo "</div>";
echo "</div>";
//w3schools
?>
<footer class="mastfoot mt-auto">
<div class="inner">
<p>Konnect.ed<br>A. Prat, M. Michel and S. Caddeo</p>
</div>
</footer>
<script src="index.js"></script>
<script src="show.js"></script>
<script src="messages.js"></script>
</body>
</html>