-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMessage.php
160 lines (129 loc) · 5.66 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
160
<?php
require './conn.php';
session_start();
if($_SESSION['user_role'] == 'buyer') {
$bID = $_SESSION['buyer_ID'];
if (isset($_POST['submit'])) {
$rec = $_POST['recipient'];
$sub = $_POST['subject'];
$msg = $_POST['message'];
$query = "INSERT INTO message VALUES('', '{$rec}', '{$bID}', '{$sub}', '{$msg}', current_timestamp(), 'buyer') ";
if($con->query($query)) {
echo "<script>alert('Message send sucessfully'); window.location = 'Message.php';</script>";
}
else {
echo '<script>alert("Message send Failed"); window.location = "message.php"; </script>';
}
}
$sql = "SELECT message.*, buyer.*, seller.*
FROM message
JOIN buyer ON message.buyer_ID = buyer.buyer_ID
JOIN seller ON message.seller_ID = seller.seller_ID
WHERE sender_role = 'buyer'
";
$result = $con->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Click Cart</title>
<link rel="stylesheet" href="./css/createAccount.css">
<link rel="stylesheet" href="./css/message.css">
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@300;400;500;600;700&family=Oswald:wght@200&family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<?php
include "./header.php"
?>
<div id="newMessage">
<h2>New Message</h2>
<!-- Message Creation Form -->
<form method="POST" action="Message.php">
<select name="recipient" id="reciver" class="reciver">
<option value="">-- Select Seller --</option>
<?php
$querySeller = "SELECT * FROM seller";
$resultSeller = $con->query($querySeller);
while($row = $resultSeller->fetch_assoc()) {
?>
<option value="<?php echo $row['seller_ID'] ?>"><?php echo $row['seller_Name'] ?></option>
<?php } ?>
</select>
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">Create Message</button>
<button type="button" onclick="hide()">Close</button>
</form>
</div>
<div style="width: 90%;margin-top:40px; margin-left:auto; margin-right:auto; border: 1px solid grey; display: flex; flex-wrap: wrap; position:relative;">
<div style="width:20%; border: 1px solid grey;" class="groove1">
<p style="margin-left: 20px; padding: 5px;">
<a href="#">Inbox</a><br><br>
<a href="#">Spam</a><br><br>
<a href="#">ClickCart</a><br><br>
<a href="#">Sent</a><br><br>
<a href="#">Trash</a><br><br>
<a href="#">Archieve</a><br><br>
</p>
</div>
<div id="name" style="width:80%; padding: 5px 2px;">
<button onclick="show()">New</button>
<form class="example" action="Message.php" style="margin:auto;max-width:300px; display: inline-block;" >
<input type="text" placeholder="Search.." name="search2" style="display: inline-block;">
<button type="submit" style="display: inline; border-radius: 5px; margin-left: 2px; height:42px; width:10%;"><i class="fa fa-search"></i></button>
</form>
<a href="https://courseweb.sliit.lk/">All</a>
<span>||</span>
<a href="https://courseweb.sliit.lk/">Unread</a>
<hr>
<table style="width:100%; text-align: center;" >
<tr>
<th></th>
<th>From</th>
<th>Subject</th>
<th>Message</th>
<th>Recived</th>
</tr>
<div>
<form action="Message.php" style="display: inline;" class="detail" >
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<tr>
<td><a href="message_delete.php?id=<?php echo $row['message_ID']; ?>"><button type="button">Delete</button></a></td>
<td><?php echo $row['seller_Name']; ?></td>
<td><?php echo $row['subject']; ?></td>
<td align="left"><?php echo substr($row['message'], 0, 50); ?></td>
<td><?php echo $row['timestamp']; ?></td>
</tr>
<?php
}
} else {
echo "No messages found.";
}
?>
</form>
</div>
</table>
</div>
</div>
<?php
include "./footer.php"
?>
<script src="./js/check_online.js"></script>
<script src="./js/message.js"></script>
</body>
</html>
<?php
} else {
header('Location: login.php');
exit();
}
$con->close();
?>
<!--reference: W3Schools-->