File "client_complaint.php"
Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/client_complaint.php
File size: 7.77 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start(); // Start the session
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create the table if it does not exist
$create_table_sql = "CREATE TABLE IF NOT EXISTS completed_repair_request (
id INT AUTO_INCREMENT PRIMARY KEY,
client_complaint_ID INT NOT NULL,
TechnicianName VARCHAR(255),
Remark TEXT,
FOREIGN KEY (client_complaint_ID) REFERENCES client_complaint(ID)
)";
if ($conn->query($create_table_sql) === FALSE) {
die("Error creating table: " . $conn->error);
}
// Initialize response message
$response_message = '';
// Handle Add Complaint (Admin)
if (isset($_POST['submit_admin'])) {
$name = $_POST['name'];
$mobnum = $_POST['mobnum'];
$city = $_POST['city'];
$message = $_POST['message'];
$sql = "INSERT INTO client_complaint (Name, MobileNumber, City, Message, status) VALUES ('$name', '$mobnum', '$city', '$message', 'pending')";
if ($conn->query($sql) === TRUE) {
$response_message = "Repair request added successfully!";
} else {
$response_message = "Something went wrong. Please try again. Error: " . $conn->error;
}
// Redirect to avoid form resubmission on refresh
echo "<script>
alert('$response_message');
window.location.href = '" . $_SERVER['PHP_SELF'] . "';
</script>";
exit();
}
// Handle Add Complaint (Client)
if (isset($_POST['submit_client'])) {
$name = isset($_SESSION['userdata']['firstname']) && isset($_SESSION['userdata']['lastname'])
? $_SESSION['userdata']['firstname'] . ' ' . $_SESSION['userdata']['lastname']
: ''; // Get the full name from the session
$mobnum = $_POST['mobnum'];
$city = $_POST['city'];
$message = $_POST['message'];
$sql = "INSERT INTO client_complaint (Name, MobileNumber, City, Message, status) VALUES ('$name', '$mobnum', '$city', '$message', 'pending')";
if ($conn->query($sql) === TRUE) {
$response_message = "Your complaint was sent successfully!";
} else {
$response_message = "Something went wrong. Please try again. Error: " . $conn->error;
}
// Redirect to avoid form resubmission on refresh
echo "<script>
alert('$response_message');
window.location.href = '" . $_SERVER['PHP_SELF'] . "';
</script>";
exit();
}
?>
<!DOCTYPE html>
<html lang="zxx">
<head>
<title>Client Complaint Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h2 class="mb-4">Need help? We're here for you!</h2>
<h4 class="mb-4">Help at hand!</h4>
<p>We aim to provide our customers with the best possible services. In case you have any suggestion/feedback,
we would be delighted to assist you at the earliest.</p>
<div class="card mb-4">
<div class="card-header">Report to us...</div>
<div class="card-body">
<form method="post" action="">
<div class="form-group">
<label for="name">Name<span>*</span> WARNING: If you don't see your name automatically written below, click first your STATEMENT OF ACCOUNT and go back to this page.</label>
<input type="text" class="form-control" name="name" required placeholder="" value="<?php echo isset($_SESSION['userdata']['firstname']) && isset($_SESSION['userdata']['lastname'])
? htmlspecialchars($_SESSION['userdata']['firstname'] . ' ' . $_SESSION['userdata']['lastname'])
: ''; ?>" readonly>
</div>
<div class="form-group">
<label for="mobnum">Mobile no.<span>*</span></label>
<input type="text" class="form-control" name="mobnum" required pattern="[0-9]+" maxlength="11" placeholder="Mobile Number">
</div>
<div class="form-group">
<label for="city">Enter Full Address<span>*</span></label>
<input type="text" class="form-control" name="city" required placeholder="Full Address">
</div>
<div class="form-group">
<label for="message">What would you like us to assist you with?<span>*</span></label>
<textarea class="form-control" name="message" required placeholder="What would you like us to assist you with?"></textarea>
</div>
<input type="submit" name="submit_client" class="btn btn-primary" value="Submit">
<p><span>*</span> marked fields are mandatory</p>
</form>
</div>
</div>
<div class="card mb-4">
<div class="card-header">Your Report Records: WARNING: If you see an Opened Status, do not send anymore another report ticket. Someone from our technical team will surely visit you to fix the issue. Thank you!</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Report Submitted</th>
<th>Name</th>
<th>Mobile Number</th>
<th>City</th>
<th>Message</th>
<th>Status</th>
<th>Technician Name</th>
<th>Remark</th>
</tr>
</thead>
<tbody>
<?php
$full_name = isset($_SESSION['userdata']['firstname']) && isset($_SESSION['userdata']['lastname'])
? $_SESSION['userdata']['firstname'] . ' ' . $_SESSION['userdata']['lastname']
: '';
$stmt = $conn->prepare("SELECT cc.*, cc.TechName as TechnicianName, cc.Remark
FROM client_complaint cc
WHERE cc.Name = ?");
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param("s", $full_name);
$stmt->execute();
$result = $stmt->get_result();
$counter = 1;
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$counter}</td>
<td>{$row['ComplaintDate']}</td>
<td>{$row['Name']}</td>
<td>{$row['MobileNumber']}</td>
<td>{$row['City']}</td>
<td>{$row['Message']}</td>
<td>{$row['status']}</td>
<td>{$row['TechnicianName']}</td>
<td>{$row['Remark']}</td>
</tr>";
$counter++;
}
$stmt->close();
?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
<?php
$conn->close();
?>