<?php
include_once("../include/main.inc.php");
check_session('MyCpanel', 'index.php');
$id = $_REQUEST['id'];
$heading = "Manage Buy Enquiry Status";
$redirect_script_name = "manage-buyenquiry.php";
$script_name = "inquery_update.php";
$table_name = "crm_tbl";

if (isset($_POST["update_record"])) {
    $status_remark = $_POST['status_remark'];
    $remark = $_POST['remark'];

    updateTable($table_name, "status_remark='$status_remark', comment='$remark' where id='$id'");
    $_SESSION['session_message'] = $record_type . ' has been updated successfully';
    header("Location: " . SITE_ADMIN_URL . "/" . $redirect_script_name);
    exit;
}

admin_header("");
$res = getResult($table_name, " where id='$id'");
?>
<div class="content-wrapper">
    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link" href="<?= $redirect_script_name ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>
            </ol>
        </nav>
    </div>
    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" method="POST" action="">
                        <div class="form-group">
                            <label>Status</label>
                            <select name="status_remark" class="form-control">
                                <option value="Converted" <?= ($res['status_remark'] == "Converted") ? 'selected' : '' ?>>Converted</option>
                                <option value="Not converted" <?= ($res['status_remark'] == "Not converted") ? 'selected' : '' ?>>Not converted</option>
                                <option value="Hold" <?= ($res['status_remark'] == "Hold") ? 'selected' : '' ?>>Hold</option>
                                <option value="Direct" <?= ($res['status_remark'] == "Direct") ? 'selected' : '' ?>>Direct</option>
                                <option value="Not Responding" <?= ($res['status_remark'] == "Not Responding") ? 'selected' : '' ?>>Not Responding</option>
                                <option value="Test" <?= ($res['status_remark'] == "Test") ? 'selected' : '' ?>>Test</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Remark</label>
                            <textarea name="remark" class="form-control"><?= $res['comment'] ?></textarea>
                        </div>
                        <button type="submit" class="btn btn-primary mr-2" name="update_record">Update</button>
                        <button class="btn btn-light" onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>'">Cancel</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
admin_footer();
exit;
?>
