File "assign_installation_request.php"

Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/assign_installation_request.php
File size: 4.73 KB
MIME-type: text/x-php
Charset: utf-8

<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Start session if not already started
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 installation request details
if (!isset($_GET['id'])) {
    die("ID parameter is missing.");
}
$id = $_GET['id'];
$sql = "SELECT * FROM installation_request WHERE ID = ?";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
    die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows != 1) {
    die("Record not found.");
}
$request = $result->fetch_assoc();

// Handle form submission for assigning a technician
if (isset($_POST['assign'])) {
    $tech_id = $_POST['technician_id'];
    $Remark = $_POST['Remark'];
    $status = 'Assigned';

    // Fetch the technician's name
    $tech_sql = "SELECT tech_name FROM technician WHERE id = ?";
    $tech_stmt = $conn->prepare($tech_sql);
    if ($tech_stmt === false) {
        die("Error preparing statement: " . $conn->error);
    }
    $tech_stmt->bind_param('i', $tech_id);
    $tech_stmt->execute();
    $tech_result = $tech_stmt->get_result();
    if ($tech_result->num_rows != 1) {
        die("Technician not found.");
    }
    $technician = $tech_result->fetch_assoc();
    $tech_name = $technician['tech_name'];

    // Update the installation request
    $update_sql = "UPDATE installation_request SET TechName = ?, Remark = ?, status = ?, UpdateDate = NOW() WHERE ID = ?";
    $update_stmt = $conn->prepare($update_sql);
    if ($update_stmt === false) {
        die("Error preparing statement: " . $conn->error);
    }
    $update_stmt->bind_param('sssi', $tech_name, $Remark, $status, $id);

    if ($update_stmt->execute()) {
        echo "<script>alert('Installation request assigned successfully.'); window.location.href = 'https://fastlinkinternet.com/administrator/data-provider/admin/?page=installation_request';</script>";
    } else {
        echo "Error updating record: " . $conn->error;
    }
}

// Fetch the list of technicians
$tech_sql = "SELECT id, tech_name FROM technician";
$tech_result = $conn->query($tech_sql);
if (!$tech_result) {
    die("Error fetching technicians: " . $conn->error);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Assign Installation 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 Installation Request</h2>
    <form method="post" action="">
        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" id="name" value="<?php echo htmlspecialchars($request['Name']); ?>" disabled>
        </div>
        <div class="form-group">
            <label for="mobileNumber">Mobile Number</label>
            <input type="text" class="form-control" id="mobileNumber" value="<?php echo htmlspecialchars($request['MobileNumber']); ?>" disabled>
        </div>
        <div class="form-group">
            <label for="address">Address</label>
            <input type="text" class="form-control" id="address" value="<?php echo htmlspecialchars($request['Address']); ?>" disabled>
        </div>
        <div class="form-group">
            <label for="date">Date</label>
            <input type="text" class="form-control" id="date" value="<?php echo htmlspecialchars($request['Date']); ?>" disabled>
        </div>
        <div class="form-group">
            <label for="technician_id">Assign to Technician</label>
            <select class="form-control" id="technician_id" name="technician_id" required>
                <?php while ($tech = $tech_result->fetch_assoc()): ?>
                    <option value="<?php echo htmlspecialchars($tech['id']); ?>"><?php echo htmlspecialchars($tech['tech_name']); ?></option>
                <?php endwhile; ?>
            </select>
        </div>
        
        <button type="submit" name="assign" class="btn btn-primary">Assign</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();
?>