File "repair_assignment.php"
Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/repair_assignment.php
File size: 11.96 KB
MIME-type: text/x-php
Charset: utf-8
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Check if a session is already started before starting one
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch the logged-in user's details
$logged_in_user_type = isset($_SESSION['userdata']['type']) ? $_SESSION['userdata']['type'] : '';
$logged_in_user_id = isset($_SESSION['userdata']['id']) ? $_SESSION['userdata']['id'] : '';
// Fetch the full name of the logged-in user by concatenating firstname and lastname from the users table
$full_name_sql = "SELECT CONCAT(firstname, ' ', lastname) as full_name FROM users WHERE id = ?";
$full_name_stmt = $conn->prepare($full_name_sql);
if ($full_name_stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$full_name_stmt->bind_param('i', $logged_in_user_id);
$full_name_stmt->execute();
$full_name_result = $full_name_stmt->get_result();
$logged_in_user_name = $full_name_result->fetch_assoc()['full_name'];
// Handle form submission for marking as completed
if (isset($_POST['mark_completed'])) {
$id = $_POST['id'];
$remark = $_POST['remark'];
$update_sql = "UPDATE client_complaint SET status = 'Closed', Remark = ?, UpdateDate = NOW() WHERE ID = ?";
$stmt = $conn->prepare($update_sql);
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param('si', $remark, $id);
if ($stmt->execute()) {
echo "<script>alert('Marked as Completed successfully.'); window.location.href = 'https://fastlinkinternet.com/administrator/data-provider/admin/?page=repair_assignment';</script>";
} else {
echo "Error updating record: " . $conn->error;
}
}
// Handle form submission for deleting a repair assignment
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('Deleted successfully.'); window.location.href = 'https://fastlinkinternet.com/administrator/data-provider/admin/?page=repair_assignment';</script>";
} else {
echo "Error deleting record: " . $conn->error;
}
}
// Fetch repair assignments
if ($logged_in_user_type == 4) {
// Technician view
$repair_assignment_sql = "SELECT * FROM client_complaint WHERE status = 'Opened' AND TechName = ?";
$stmt = $conn->prepare($repair_assignment_sql);
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param('s', $logged_in_user_name);
} else {
// Admin or other user types view
$repair_assignment_sql = "SELECT * FROM client_complaint WHERE status = 'Opened'";
$stmt = $conn->prepare($repair_assignment_sql);
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
}
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Repair Assignments</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script>
function printJobOrder(row) {
var jobOrderForm = `
<div style="font-family: Arial, sans-serif; padding: 20px; border: 1px solid #000; max-width: 800px; margin: auto;">
<div style="text-align: center; margin-bottom: 20px;">
<img src="https://fastlinkinternet.com/administrator/data-provider/uploads/fastlink.png" alt="Logo" style="max-width: 120px;">
<h2 style="margin: 0;">FASTLINK INTERNET</h2>
<p style="margin: 0;"></p>
<p style="margin: 0;">Contact: 0945-330-6374</p>
</div>
<table style="width: 100%; margin-bottom: 20px;">
<tr>
<td><strong>Assigned to:</strong> ${row.TechName}</td>
<td style="text-align: right;"><strong>Job Order No.:</strong> _____________________</td>
</tr>
</table>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;">
<tr>
<td style="border: 1px solid #000; padding: 10px;"><strong>Subscriber's Acct. Name:</strong><br>${row.Name}</td>
<td style="border: 1px solid #000; padding: 10px;"><strong>Package Service:</strong><br></td>
</tr>
<tr>
<td style="border: 1px solid #000; padding: 10px;"><strong>Subscriber UserName:</strong><br></td>
<td style="border: 1px solid #000; padding: 10px;"><strong>Subscriber Password:</strong><br></td>
</tr>
<tr>
<td style="border: 1px solid #000; padding: 10px;"><strong>Service Address:</strong><br>${row.City}</td>
<td style="border: 1px solid #000; padding: 10px;"><strong>Contact No:</strong><br>${row.MobileNumber}</td>
</tr>
</table>
<table style="width: 100%; margin-bottom: 20px;">
<tr>
<td><strong>Remarks:</strong> ${row.Remark}</td>
</tr>
<tr>
<td><input type="checkbox"> New Repair <input type="checkbox"> Maintenance <input type="checkbox"> Others:</td>
</tr>
</table>
<table style="width: 100%; margin-bottom: 20px;">
<tr>
<td><strong>Date Time Started:</strong></td>
<td><strong>Date Time Finished:</strong></td>
</tr>
</table>
<table style="width: 100%; margin-bottom: 20px;">
<tr>
<td style="border: 1px solid #000; padding: 10px; width: 50%;"><strong>House Drop Wire Reading/Beaming:</strong></td>
<td style="border: 1px solid #000; padding: 10px; width: 50%;"><strong>Satisfied with service?</strong> <input type="checkbox"> Yes <input type="checkbox"> No</td>
</tr>
<tr>
<td colspan="2" style="border: 1px solid #000; padding: 10px;">
<strong>If No, Why? Quality of service:</strong>
<input type="checkbox"> Excellent
<input type="checkbox"> V. Good
<input type="checkbox"> Good
<input type="checkbox"> Poor
</td>
</tr>
</table>
<p style="border-top: 1px solid #000; padding-top: 10px; font-size: 12px;">
Attested that both parties agreed that the subscriber checked his/her belongings and nothing is missing.
</p>
<table style="width: 100%; margin-top: 40px;">
<tr>
<td style="border-top: 1px solid #000; text-align: center; padding-top: 10px;">
<strong>Signature over printed name</strong><br>TECHNICIAN
</td>
<td style="border-top: 1px solid #000; text-align: center; padding-top: 10px;">
<strong>Signature over printed name</strong><br>SUBSCRIBER
</td>
</tr>
</table>
<!-- QR Code Section -->
<div class="text-center mt-4">
<h4>Scan this QR code to login to your account:</h4>
<img id="qrImage" src="https://fastlinkinternet.com/administrator/data-provider/uploads/fastlinkapp.png" alt="Mobile App QR Code" style="max-width: 150px;">
</div>
</div>
`;
var newWindow = window.open("", "_blank", "width=900,height=650");
newWindow.document.write(jobOrderForm);
newWindow.document.close();
// Ensure the image is loaded before printing
var qrImage = newWindow.document.getElementById('qrImage');
qrImage.onload = function() {
newWindow.focus();
newWindow.print();
newWindow.close();
};
}
</script>
</head>
<body>
<div class="container mt-5">
<h2 class="mb-4">Repair Assignments</h2>
<?php if ($logged_in_user_type != 4) { ?>
<?php } ?>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Mobile Number</th>
<th>Complete Address</th>
<th>Message</th>
<th>Complaint Date</th>
<th>Update Date</th>
<th>Technician Name</th>
<th>Remark</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if ($result->num_rows > 0) {
$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>
<form method="post" action="" style="display:inline-block;">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($row['ID'] ?? ''); ?>">
<textarea name="remark" class="form-control mb-2" placeholder="Enter remark" required></textarea>
<button type="submit" name="mark_completed" class="btn btn-success">Mark as Completed</button>
</form>
<?php if ($logged_in_user_type != 4) { ?>
<form method="post" action="" style="display:inline-block;">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($row['ID'] ?? ''); ?>">
<button type="submit" name="delete" class="btn btn-danger">Delete</button>
</form>
<button onclick="printJobOrder(<?php echo htmlspecialchars(json_encode($row)); ?>)" class="btn btn-primary">Print</button>
<?php } ?>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="11" class="text-center">No repair assignments found.</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="mb-4">
<a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=service_request_dashboard" class="btn btn-secondary">Back</a>
</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
$full_name_stmt->close();
$conn->close();
?>