File "completed_repair_request.php"
Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/completed_repair_request.php
File size: 6.89 KB
MIME-type: text/x-php
Charset: utf-8
<?php
// 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);
}
// Handle form submission for deletion
if (isset($_POST['delete'])) {
$id = $_POST['id'];
$delete_sql = "DELETE FROM client_complaint WHERE ID = ?";
$stmt = $conn->prepare($delete_sql);
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
echo "<script>alert('Repair request deleted successfully.'); window.location.href = 'completed_repair_request.php';</script>";
} else {
echo "Error deleting record: " . $stmt->error;
}
}
// Fetch years for the filter dropdown
$years = $conn->query("SELECT DISTINCT YEAR(ComplaintDate) as year FROM client_complaint ORDER BY year DESC");
// Set default year and month to current year and month
$year = isset($_GET['year']) ? $_GET['year'] : date('Y');
$month = isset($_GET['month']) ? $_GET['month'] : date('m');
// Fetch completed repair requests based on the selected year and month
$sql = "
SELECT cc.*, t.tech_name AS TechnicianName
FROM client_complaint cc
LEFT JOIN technician t ON cc.TechnicianID = t.id
WHERE cc.status = 'Closed' AND YEAR(ComplaintDate) = ? AND MONTH(ComplaintDate) = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ii', $year, $month);
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Completed Repair Requests</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
@media print {
.no-print {
display: none;
}
}
</style>
</head>
<body>
<div class="container mt-5">
<div style="text-align: center;">
<img src="https://fastlinkinternet.com/administrator/data-provider/uploads/fastlink.png" alt="Logo" style="max-width: 120px;">
</div>
<h2 class="mb-4 text-center">FASTLINK INTERNET</h2>
<h4 class="mb-4 text-center">Completed Repair Requests as of <?= date('F Y'); ?></h4> <div class="mb-4 no-print">
<a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=service_request_dashboard" class="btn btn-secondary">Back</a>
<button class="btn btn-primary" onclick="window.print()">Print</button>
</div>
<div class="mb-4 no-print">
<form method="get" action="completed_repair_request.php">
<div class="form-row">
<div class="form-group col-md-4">
<label for="year">Year</label>
<select name="year" id="year" class="form-control">
<?php while ($row = $years->fetch_assoc()): ?>
<option value="<?php echo $row['year']; ?>" <?php echo $row['year'] == $year ? 'selected' : ''; ?>>
<?php echo $row['year']; ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="month">Month</label>
<select name="month" id="month" class="form-control">
<?php for ($i = 1; $i <= 12; $i++): ?>
<option value="<?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?>" <?php echo $i == $month ? 'selected' : ''; ?>>
<?php echo date('F', mktime(0, 0, 0, $i, 1)); ?>
</option>
<?php endfor; ?>
</select>
</div>
<div class="form-group col-md-4 align-self-end">
<button type="submit" class="btn btn-primary">Filter</button>
</div>
</div>
</form>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Mobile Number</th>
<th>City</th>
<th>Message</th>
<th>Complaint Date</th>
<th>Update Date</th>
<th>Technician Name</th>
<th>Remark</th>
<th>Status</th>
<th class="no-print">Actions</th>
</tr>
</thead>
<tbody>
<?php if ($result->num_rows > 0) { ?>
<?php $counter = 1; ?>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $counter++; ?></td>
<td><?php echo htmlspecialchars($row['Name']); ?></td>
<td><?php echo htmlspecialchars($row['MobileNumber']); ?></td>
<td><?php echo htmlspecialchars($row['City']); ?></td>
<td><?php echo htmlspecialchars($row['Message']); ?></td>
<td><?php echo htmlspecialchars($row['ComplaintDate']); ?></td>
<td><?php echo htmlspecialchars($row['UpdateDate']); ?></td>
<td><?php echo htmlspecialchars($row['TechName']); ?></td>
<td><?php echo htmlspecialchars($row['Remark']); ?></td>
<td><?php echo htmlspecialchars($row['status']); ?></td>
<td class="no-print">
<form method="post" action="">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($row['ID']); ?>">
<button type="submit" name="delete" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="11" class="text-center">No completed repair requests found for the selected period.</td>
</tr>
<?php } ?>
</tbody>
</table>
</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(); ?>