<?php
include_once "global.php";

$pageTitle = 'Add Ticket - ';
include_once 'header.php';
?>

<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
    <div class="breadcrumb-title pe-3">Ticket Management</div>
    <div class="ps-3">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0 p-0">
                <li class="breadcrumb-item"><a href="javascript:;"></a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Add Ticket</li>
            </ol>
        </nav>
    </div>
</div>
<!--end breadcrumb-->
<div class="card">
    <div class="card-body p-4">
        <h5 class="mb-4">Add Ticket</h5>
        <form id="ticketAddForm" class="row g-3" method="post">
            <?php if ($webUserType === 1) { ?>
                <div class="col-md-6">
                    <label for="clientId" class="form-label">Client <span>*</span></label>
                    <select id="clientId" name="clientId" class="form-select getClientProjects" required>
                        <option value="" disabled selected>Select...</option>
                        <?php
                        $clients = $productClass->AllClientsArray();
                        foreach ($clients as $client) {
                            $clientId = $client["acc_id"];
                            $clientName = $client["acc_name"];
                            echo "<option value='$clientId'>$clientName</option>";
                        }
                        ?>
                    </select>
                </div>
            <?php } else { ?>
                <input type="hidden" class="getClientProjects" name="clientId"
                    value="<?php echo $_SESSION["webUser"]["id"] ?>">
            <?php } ?>
            <div class="col-md-6">
                <label for="projectId" class="form-label">Project <span>*</span></label>
                <select class="form-select showClientProjects" disabled name="projectId" id="projectId" required>

                </select>
            </div>
            <div class="col-md-6">
                <label for="category" class="form-label">Category <span>*</span></label>
                <select id="category" name="category" class="form-select" required>
                    <option value="" disabled selected>Select...</option>
                    <?php
                    $ticketCategories = $productClass->getTicketCategories();
                    foreach ($ticketCategories as $ticketCategory) {
                        $categoryId = $ticketCategory["id"];
                        $name = $ticketCategory["category"];
                        echo "<option value='$categoryId'>$name</option>";
                    }
                    ?>
                </select>
            </div>
            <div class="col-md-6">
                <label for="deadline" class="form-label">Deadline <span>*</span></label>
                <input type="date" name="deadline" id="deadline" class="form-control" required>
            </div>
            <?php if ($webUserType === 1): ?>
                <div class="col-md-6">
                    <label for="assignto" class="form-label">Assign To</label>
                    <select id="assignto" name="assignto" class="form-select">
                        <option value="" disabled selected>Select...</option>
                        <?php
                        $employees = $productClass->AllEmployeesArray();
                        foreach ($employees as $employee) {
                            $employeeId = $employee["acc_id"];
                            $employeeName = $employee["acc_name"];
                            echo "<option value='$employeeId'>$employeeName</option>";
                        }
                        ?>
                    </select>
                </div>
            <?php endif; ?>
            <div class="col-md-3">
                <label class="form-label d-block">Status</label>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="status" id="statusOpen" value="Open" checked>
                    <label class="form-check-label" for="statusOpen">Open</label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="status" id="statusClosed" value="Closed"
                        required>
                    <label class="form-check-label" for="statusClosed">Closed</label>
                </div>
            </div>
            <div class="col-md-3">
                <label class="form-label d-block">Priority <span>*</span></label>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="priority" id="priorityNormal" value="Normal"
                        required>
                    <label class="form-check-label" for="priorityNormal">Normal</label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="priority" id="priorityUrgent" value="Urgent"
                        required>
                    <label class="form-check-label" for="priorityUrgent">Urgent</label>
                </div>
            </div>
            <div class="col-md-6">
                <label for="complaint" class="form-label">Complaint</label>
                <input type="text" name="complaint" id="complaint" class="form-control" required>
            </div>
            <div class="col-md-12">
                <label for="description" class="form-label">Description</label>
                <textarea class="form-control" id="description" name="description" rows="3"></textarea>
            </div>
            <div class="col-md-12">
                <button type="submit" class="btn btn-grd-primary px-4">Submit</button>
            </div>
        </form>
    </div>
</div>

<?php
include_once 'footer.php';
?>