-
Notifications
You must be signed in to change notification settings - Fork 7
/
read.php
150 lines (122 loc) · 4.79 KB
/
read.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
<?php
include 'frontend/menu.php';
include_once 'config/config.php';?>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<?php
menu();
$error='';
if(isset($_POST["markread"],$_GET['id']))
{
$clear = "UPDATE messages SET unread=0 WHERE unread=1 AND to_user='".$_SESSION['uname']."' AND id='".$_GET['id']."'";
if(!mysqli_query($conn,$clear))
{
$error .= '<p><label class="text-danger">SQL ERROR</label></p>';
} else {
echo '<center><p><label class="text-success">Message marked as "read"</label></p></center>';
echo "<meta http-equiv=\"refresh\" content=\"1;url='./inbox.php'\"/>";
}
}
else if(isset($_SESSION["uname"], $_GET['del'], $_SERVER['HTTP_REFERER'])){
$delquery = "UPDATE messages SET del_in='1' WHERE id='".$_GET['del']."' AND to_user='".$_SESSION["uname"]."' AND del_in='0'";
if(!mysqli_query($conn,$delquery))
{
echo '<center><p><label class="text-danger">MESSAGE NOT AVAILABLE</label></p></center>';
}
else
{
echo '<center><p><label class="text-success">MESSAGE DELETED</label></p></center>';
echo "<meta http-equiv=\"refresh\" content=\"1;url='./inbox.php'\"/>";
}
}
else if(isset($_SESSION["uname"], $_GET['id'])){
$query = "SELECT * from messages WHERE to_user='".$_SESSION["uname"]."' AND id='".$_GET['id']."'";
if(!mysqli_query($conn,$query))
{
$error .= '<p><label class="text-danger">SQL ERROR</label></p>';
}
else
{}
$result = $conn->query($query);
$row = $result->fetch_array(MYSQLI_NUM);
$msgid = $row[0];
$subject = $row[1];
$to = $row[2];
$from = $row[3];
$unread = $row[4];
$message = $row[5];
$date = $row[6];
// Begin of reply
if (isset($_POST['submit'])){
$reply = "INSERT INTO messages (subject, to_user, message, from_user, unread) VALUES ('RE: ".$subject."', '".$from."', '".$_POST['message']."', '".$_SESSION["uname"]."', '1')";
if ($_POST['message'] == ''){ $error .= 'Message cannot be empty';}
else if(mysqli_query($conn,$reply))
{
$error .= '<p><label class="text-succes">Reply sent to '.$from.'</label></p>';
}
}
// End of reply
if ($row){
?>
<center>
<div id="pm">
<h3>Message from "<?php echo $from;?>"</h3>
<table id="readpm" class="table-bordered" style="background-color: rgba(255, 255, 255, 0.4);">
<tbody>
<tr>
<td>Subject</td>
<td><?php echo $subject;?></td>
</tr>
<tr>
<td>Date</td>
<td><?php echo $date;?></td>
</tr>
<tr>
<td>From</td>
<td><?php echo $from;?></td>
</tr>
<tr>
<td>Message</td>
<td style="word-break:break-word;"><?php echo $message;?></td>
</tr>
<tr>
<td></td>
<td><a href="read.php?del=<?php echo $_GET['id'];?>">Delete message</a></td>
</tr>
</tbody>
</table>
<form action="<?php echo $_SERVER['PHP_SELF']?>?id=<?php echo $_GET['id'];?>" method="post">
<?php if($unread=='1'){ ?><input type="submit" name="markread" value="Mark as read"><?php }?>
</form>
<h3>Reply:</h3><form action="<?php echo $_SERVER['PHP_SELF']?>?id=<?php echo $msgid;?>" method="post" style="width:100%;">
<table id="readpm" class="table-bordered" style="background-color: rgba(255, 255, 255, 0.4);">
<tr><td colspan=2><h3>Send PM:</h3></td></tr>
<input type="hidden" name="from_user" maxlength="32" value = <?php echo $_SESSION['uname']; ?>>
</td></tr>
<tr><td>To User: </td><td>
<input type="text" name="to_user" maxlength="32" value="<?php echo $from;?>" style="width:100%;" disabled>
<p><?php if (isset($usrerror)){echo $usrerror;}?></p>
</td></tr>
<tr><td>Subject: </td><td>
<input type="text" name="subject" maxlength="255" value="RE: <?php echo $subject;?>" style="width:100%;" disabled>
<p><?php if (isset($suberror)){echo $suberror;}?></p>
</td></tr>
<tr><td>Message: </td><td>
<TEXTAREA NAME="message" COLS=50 ROWS=10 WRAP=SOFT style="width: 100%;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;resize: none;"></TEXTAREA>
<p><?php if (isset($msgerror)){echo $msgerror;}?></p>
</td></tr>
<tr><td colspan="2" align="right">
<center><input type="submit" name="submit" value="Send Message">
<?php if(isset($error)){ echo '<p><label class="text-danger">'.$error.'</label></p>';}?>
</center></td></tr>
</table>
</form>
</div>
</center>
</body>
<?php // else for 'if row'
} else { echo "<center><p><label class=\"text-danger\">Invalid ID or not allowed to view</label></p></center>";}?>
<?php // else for 'if(isset($_SESSION["uname"], $_GET['id'])){'
} else { echo "<center><p><label class=\"text-danger\">You are not allowed to view this page</label></p></center>";} ?>