-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplaint.php
More file actions
200 lines (166 loc) · 6.23 KB
/
complaint.php
File metadata and controls
200 lines (166 loc) · 6.23 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Complaint Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: white;
color: #fff;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
max-width: 600px;
margin: 20px auto;
background-color: rgb(222, 218, 209);
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
padding: 20px;
box-sizing: border-box;
position: relative;
}
h2 {
text-align: center;
color: black;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 8px;
color: black;
}
textarea,
input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
background-color: white;
/* Match the background color */
color: #fff;
}
button {
background-color: rgb(118, 219, 171);
color: white;
border: none;
padding: 12px;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.profile-btn,
.complaints-btn,
.signout-btn {
background-color: rgb(84, 127, 176);
color: white;
border: none;
padding: 8px 12px;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.success-message {
background-color: #4caf50;
color: white;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
}
@media only screen and (max-width: 600px) {
.container {
margin: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<?php
// Start the session
session_start();
// Include the database connection file
include 'connection.php';
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$complaintText = $_POST["complaint"];
$responseText = isset($_POST["response"]) ? $_POST["response"] : '';
// Process file upload
$targetDirectory = "uploads/";
$targetFile = $targetDirectory . basename($_FILES["photo"]["name"]);
// Validate file type and size
$allowedFileTypes = ["jpg", "jpeg", "png", "gif"];
$maxFileSize = 10 * 1024 * 1024; // 10MB
$fileExtension = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
if (!in_array($fileExtension, $allowedFileTypes)) {
die("Error: Invalid file type. Only JPG, JPEG, PNG, and GIF files are allowed.");
}
if ($_FILES["photo"]["size"] > $maxFileSize) {
die("Error: File size exceeds 10MB.");
}
move_uploaded_file($_FILES["photo"]["tmp_name"], $targetFile);
// Assuming you have a user ID stored in a session variable
$userId = isset($_SESSION["user_id"]) ? $_SESSION["user_id"] : null;
// Check if user is logged in
if (!$userId) {
echo '<p style="color: red;">Error: User not logged in.</p>';
exit();
}
// Insert into Complaints table
$query = "INSERT INTO Complaints (user_id, complaint_text, photo_path, response) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($query);
// Check if the prepare statement was successful
if ($stmt) {
// Use an empty string as the default value for the "response" column
$defaultResponse = '';
$stmt->bind_param("isss", $userId, $complaintText, $targetFile, $responseText);
$stmt->execute();
$stmt->close();
// Display success message and redirect
echo '<div class="success-message">Complaint registered successfully!</div>';
header("refresh:2;url=complaint.php"); // Redirect to the homepage after 2 seconds
exit();
} else {
// Handle the case when prepare fails
echo "Error in prepare statement: " . $conn->error;
}
}
?>
<h2>File a Complaint</h2>
<form action="complaint.php" method="post" enctype="multipart/form-data">
<label for="complaint">Complaint:</label>
<textarea id="complaint" name="complaint" placeholder="Enter your complaint" required></textarea>
<label for="photo">Upload Photo (max 10MB):</label>
<input type="file" id="photo" name="photo" accept="image/*" required>
<button type="submit">Submit Complaint</button>
</form>
<button class="profile-btn" onclick="redirectToProfile()">Profile</button>
<button class="complaints-btn" onclick="redirectToMyComplaints()">My Complaints</button>
<!-- Sign Out Button -->
<form action="login.php" method="post">
<button class="signout-btn" type="submit">Sign Out</button>
</form>
</div>
<script>
function redirectToProfile() {
// Redirect to profile.php after clicking the Profile button
window.location.href = 'profile.php';
}
function redirectToMyComplaints() {
// Redirect to mycomplaints.php after clicking the My Complaints button
window.location.href = 'mycomplaints.php';
}
</script>
</body>
</html>