-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.php
144 lines (126 loc) · 3.4 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
<?php
/**
* @Author: Shivam Singhal
*/
error_reporting(0);
require_once 'inc/connection.inc.php';
require_once 'inc/func.inc.php';
if(!loggedin()){
header('Location: login.php');
}
if(isset($_POST['reciever'])){
$message = clean_string($_POST['message']);
$sender_id = (int)($_SESSION['id']);
$reciever_id = (int)$_POST['reciever'];
$query = "INSERT INTO `messages` (`sender_id`,`reciever_id`,`message`) VALUES ('$sender_id','$reciever_id','$message')";
if(mysqli_query($connection, $query)){
$error = 0;
} else {
$error = 1;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include 'layout/meta.inc.php';
?>
</head>
<body class="skin-black">
<?php
include 'layout/header.inc.php';
?>
<div class="wrapper row-offcanvas row-offcanvas-left">
<?php
include 'layout/leftpanel.inc.php';
?>
<aside class="right-side">
<section class="content">
<div class="row" style="margin-bottom:5px;">
<div class="col-lg-8 col-lg-offset-2">
<?php
$color = array(
'success',
'danger',
);
$error_messages = array(
'Message <strong>successfully</strong> sent!',
'<strong>Error</strong> in sending message',
);
if(isset($error))
echo'
<div class="alert alert-' . $color[$error] . ' ">
<button data-dismiss="alert" class="close close-sm" type="button">
<i class="fa fa-times"></i>
</button>
' . $error_messages[$error] . '
</div>';
?>
<section class="panel">
<header class="panel-heading">Send a message</header>
<div class="panel-body">
<form role="form" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">Reciever ID</label>
<input name="reciever" class="form-control" type="text" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Message</label>
<textarea name="message" required class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-info">Submit</button>
</form>
</div>
</section>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<section class="panel">
<header class="panel-heading">inbox</header>
<div class="panel-body">
<table class="table table-bordered">
<tbody>
<tr>
<th style="width: 10px">#</th>
<th>Sender <small>(Sender ID)</small></th>
<th>Message</th>
<th style="width: 120px">Time</th>
</tr>
<?php
$receiver_id = (int)($_SESSION['id']);
$query_fetch = "SELECT * FROM `messages` WHERE `reciever_id`=$receiver_id";
$query_fetch_run = mysqli_query($connection, $query_fetch);
/**
* used to show count of messages to the user
* @var integer
*/
$i = 0;
$true = 0;
while($query_row = mysqli_fetch_assoc($query_fetch_run)){
echo '<tr>
<td>' . ++$i . '</td>
<td>' . $query_row['name'] . ' <small>' . $query_row['sender_id'] . '</small></td>
<td>' . $query_row['message'] . '</td>
<td>' . return_display_time(strtotime($query_row['timestamp'])) . '</td>
</tr>';
$true =1;
}
if($true == 0)
echo 'No New Messages';
?>
</tbody>
</table>
</div>
</section>
</div>
</div>
</section>
</aside>
</div>
<?php
include 'layout/scripts.inc.php';
?>
</body>
</html>