-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgstream.php
293 lines (253 loc) · 9.91 KB
/
msgstream.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
include'/accessctrl.php';
$sentStatus = "";
$errJar = "";
$msgRecepient = "";
$msgBody = "";
$emailAddress = "";
$errJar = "";
if(isset($_POST['SignOut']) == "SignOut"){
//$_SESSION['login_status'] = '';
unset($_SESSION['login_status']);
unset($_SESSION['uEmail']);
unset($_SESSION['uPassword']);
header("Location:signin.php");
exit;
}
//retreiving some of the user's data
$usersOtherNames = explode(" ", mysqli_result($result, 0,'user_other_names'));
$firstName = $usersOtherNames[0];
$useremail = mysqli_result($result, 0,'user_Email');
//function to check that all form variables are set.
function SetCheck(){
if( isset($_POST['msgSend']) == "Submit"){
return isset($_POST['msgRecepient'], $_POST['msgBody']);
}
}
//function for ensuring that recepient's email is registered on the network.
function emailcheck($emailAddress){
//TEST POINT.
//echo $emailAddress;
$query3 = sprintf("SELECT * FROM users_details WHERE user_Email ='%s'",
mysqli_real_escape_string($dblink, $emailAddress)
);
$result3 = mysqli_query($dblink, $query3);
if(mysqli_num_rows($result3) > 0){
return TRUE;
}else{
global $errJar;
$errJar .= "<li>The <b>email</b> you're attempting to send a message to, is <b>not registered on Pyruscape</b>.</li>";
return FALSE;
}
}
//function to screen out sender's email address.
function eCheck($emailAddress){
//TEST POINTS.
//echo $_SESSION['uEmail'];
//echo $emailAddress;
if($emailAddress != $_SESSION['uEmail']){
return TRUE;
}else{
global $errJar;
$errJar .= "<li>You are <b>attempting to send an email to yourself</b>.</li>";
return FALSE;
}
}
// check all our variables are set and move their value to database.
if(SetCheck() == TRUE)
{
if(!empty($_POST['msgRecepient']) && emailcheck($_POST['msgRecepient']) == TRUE && eCheck($_POST['msgRecepient']) == TRUE)
{
$msgRecepient = $_POST['msgRecepient'];
}
else
{
$errJar .= '<li>Please enter the <b>email address</b> of the intended recepient of your message.</li>.';
}
if(!empty($_POST['msgBody']))
{
$msgBody = $_POST['msgBody'];
}
else
{
$errJar .= '<li>The <b>body of your message</b> seems to be <b>empty</b>.</li>.';
}
//moving data to database.
if($msgRecepient!="" && $msgBody!=""){
$sendntime = date('h:i:sA');
$sendndate = date('d-m-Y');
include_once("/doc_cabinet_connect.php");
$query2 = sprintf("INSERT INTO msgs_log (msg_body, msg_sendr, msg_recievr, doc_related_to, msg_sent_date, msg_sent_time)
VALUES ('%s','%s','%s','%s','%s','%s')",
mysqli_real_escape_string($dblink, $msgBody),
mysqli_real_escape_string($dblink, $useremail),
mysqli_real_escape_string($dblink, $msgRecepient),
"none",
mysqli_real_escape_string($dblink, $sendndate),
mysqli_real_escape_string($dblink, $sendntime)
);
$result2 = mysqli_query($dblink, $query2) or die("result2 related error: ". mysqli_error($dblink));
if($result2 == FALSE ){
$errJar = "<li><b>Your message was not sent.</b> please try again.</li>";
}else{
$sentStatus = "You <b>message</b> has been <b>sent</b>";
}
}else{
if(!empty($errJar)){
$errorMsg = "<p>Oops! looks like you didn't type anything into one of the fields or you entered a wrong value.</p>";
$errorMsg .= "<ul>" .$errJar. "</ul>";
}
}
}
if($_SESSION['login_status'] != ''){
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $firstName;?>'s Messages - Pyruscape™</title>
<link rel = "stylesheet" type ="text/css" href = "css/bootstrap.min.css">
<link rel = "stylesheet" type = "text/css" href = "css/codedoc.css">
<link rel = "stylesheet" type ="text/css" href = "css/bootstrap-fileupload.min.css">
</head>
<body>
<script src="js/jquery-1.8.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<!--HEADER SECTION-->
<div class="headr">
<div class="container">
<div class="span12">
<div class="row-fluid">
<!--SITE LOGO-->
<div class="span4"><img src = "img/pyrusclogo v4.gif"></div>
<!--LOGIN FORM ON HEADER-->
<div class="span8">
<form class="form-inline" method="post" action="yourdocstream.php">
<div id ="headr-logout">
<button type="submit" class="btn" name ="SignOut" value = "SignOut">Sign out</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!--FLAG SECTION-->
<?php
if(!empty($errorMsg)){
echo('<div class = "redflag"><div class ="container"><div class = "row-fluid"><div class = "errFlagMgr">'.$errorMsg.'</div></div></div></div>');
}
if(!empty($sentStatus)){
echo('<div class = "greenflag"><div class = "container"><div class = "row-fluid"><div class = "successFlag">'.$sentStatus.'</div></div></div></div>');
}
?>
<!--MENU SECTION-->
<div class="menu">
<div class="container">
<div class ="span12">
<div class = "menuLinks">
<div class="menulist">
<a href ="yourdocstream.php"><i class = ' icon-list-alt'></i> <?php echo $firstName;?>'s Document Stream</a>
<a href ="profilepage.php?uemail=<?php echo $useremail;?>"><i class = 'icon-user'></i> <?php echo $firstName;?>'s Profile</a>
<a href ="notifier.php"><i class = ' icon-bell'></i> Notifications</a>
<a href ="reminder.php"><i class = ' icon-check'></i> Reminders</a>
</div>
</div>
</div>
</div>
</div>
<!--CONTENT SECTION-->
<div class = "container">
<div class = "row-fluid">
<div class = "span12">
<h2 style = "margin-left:1.3em;"><?php echo $firstName;?>'s Messages</h2>
<a href = "#msgCompArea" class = "btn btn-success" style = "margin-left:35em; margin-top:-6em;">Compose Message</a><hr>
</div>
</div>
</div>
<div class = "container">
<div class = "span12">
<div class = "row-fluid">
<!--User's document list section.-->
<div class = "span8" style = "margin-left:1.3em;">
<?php
//retieving messages directed to current user.
$query1 = sprintf("SELECT * FROM msgs_log WHERE msg_recievr ='%s' ORDER BY msg_id DESC",
mysqli_real_escape_string($dblink, $useremail)
);
$result1 = mysqli_query($dblink, $query1);
if(mysqli_num_rows($result1) > 0){
echo "<div class = 'subtitle'><h4 class = 'subtitleBit'><p class = 'docHeadr' style = 'padding-top:0.5em;'>Current Messages for ".$firstName."</p></h4><hr></div>";
for($i = 0; $i <mysqli_num_rows($result1); $i++ ){
$mSendrEmail = mysqli_result($result1, $i,'msg_sendr');
$query4 = sprintf("SELECT * FROM users_details WHERE user_Email ='%s'",
mysqli_real_escape_string($dblink, $mSendrEmail)
);
$result4 = mysqli_query($dblink, $query4);
$mSendrName = mysqli_result($result4, 0,'user_surname').", ".mysqli_result($result4, 0,'user_other_names');
$mbody = mysqli_result($result1, $i,'msg_body');
$msgSdate = mysqli_result($result1, $i,'msg_sent_date');
$msgStime = mysqli_result($result1, $i,'msg_sent_time');
$msgConversatn = "<div class ='streamunit'><div class ='streamunitBit'>
<p><b>From:</b> <a href ='profilepage.php?uemail=$mSendrEmail'><em class = 'acpnyndata' style = 'font-size:14px;'>".$mSendrName."</em></a></p>
<p>".$mbody."</p>
<p><b>On:</b> <em class = 'acpnyndata'>".$msgSdate."</em> <b>Around:</b> <em class = 'acpnyndata'>".$msgStime."</em></p>
</div><hr></div>";
echo $msgConversatn;
}
}else{
echo "<div class = 'alert'><div class = 'docHeadr' id = 'nomsg'><b>There is no message</b> that is directed to you at the moment.</div></div>";
}
?>
<!-- field for composing and sending messages-->
<div class = 'subtitle'>
<h4 class = 'subtitleBit'><p class = "docHeadr" style = 'padding-top:0.5em;'>Compose and send a message below</p></h4><hr>
</div>
<form method="post" action = "<?php echo $_SERVER['PHP_SELF'];?>" id = "msgCompArea">
<table class="table">
<tr>
<td>To:</td><td><input class="span6" type="text" placeholder="Email of document recepient" name= "msgRecepient" /></td>
</tr>
<tr>
<td>Body of Message:</td><td><textarea class="span6" rows = "6" placeholder="Write your message here" name="msgBody"></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input class="btn btn-success" type="submit" name="msgSend" value="Send"/>
</td>
</tr>
</table>
</form>
</div>
<div class = "span2">
</div>
</div>
</div>
</div>
<!--FOOTER-->
<div class="footr">
<div class="container">
<div class ="span12">
<div class = "footrLinks">
<div class="copyright">© <?php echo date("Y");?>
<a href ="">Kaelahi Technologies</a>
<a href ="">About Us</a>
<a href ="">Contact</a>
<a href ="">Career</a>
<a href ="">FAQ</a>
<a href ="">Privacy Statement</a>
<a href ="">Terms and Conditions</a>
<a href ="">Blog</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
}else{
header("Location:signin.php");
exit;
}
?>