File "assign_request.php"

Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/assign_request.php
File size: 3.49 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 the assignment
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['assign'])) {
        $id = $_POST['id'];
        $technician_name = $_POST['technician_name'];

        $sql = "UPDATE client_complaint SET TechName=?, status='Opened', UpdateDate=NOW() WHERE ID=?";
        $stmt = $conn->prepare($sql);
        if ($stmt === false) {
            die("Query failed: " . $conn->error);
        }
        $stmt->bind_param('si', $technician_name, $id);
        if ($stmt->execute()) {
            header("Location: repair_assignment.php");
            exit();
        } else {
            die("Update failed: " . $stmt->error);
        }
    } elseif (isset($_POST['back'])) {
        header("Location: https://fastlinkinternet.com/administrator/data-provider/admin/?page=service_request_dashboard");
        exit();
    }
}

// Fetch technician data
$technicians = [];
$technician_sql = "SELECT tech_name FROM technician";
$technician_result = $conn->query($technician_sql);
if ($technician_result) {
    while ($row = $technician_result->fetch_assoc()) {
        $technicians[] = $row;
    }
}

// Fetch client_complaint data
$id = $_GET['id'];
$complaint_sql = "SELECT * FROM client_complaint WHERE ID=?";
$stmt = $conn->prepare($complaint_sql);
if ($stmt === false) {
    die("Query failed: " . $conn->error);
}
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows != 1) {
    die("Record not found");
}
$complaint = $result->fetch_assoc();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Assign Request</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">Assign Repair Request</h2>
    <form method="post" action="">
        <input type="hidden" name="id" value="<?php echo htmlspecialchars($complaint['ID']); ?>">
        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" id="name" value="<?php echo htmlspecialchars($complaint['Name']); ?>" disabled>
        </div>
        <div class="form-group">
            <label for="technician_name">Assign to Technician</label>
            <select class="form-control" id="technician_name" name="technician_name" required>
                <?php foreach ($technicians as $tech) { ?>
                    <option value="<?php echo htmlspecialchars($tech['tech_name']); ?>"><?php echo htmlspecialchars($tech['tech_name']); ?></option>
                <?php } ?>
            </select>
        </div>
        <button type="submit" name="assign" class="btn btn-primary">Assign</button>
        <button type="submit" name="back" class="btn btn-secondary">Back</button>
    </form>
</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();
?>