<?php
require ROOT . "/pages/start.php";
require ROOT . "/pages/header.php";
_selectRowNoParam(
    "SELECT fname, lname, phone, email, at, zereg FROM teacher WHERE id = $user_id",
    $fname,
    $lname,
    $phone,
    $email,
    $at,
    $zereg
);

_selectNoParam(
    $stmtz,
    $countz,
    "SELECT id, name FROM tzereg order by id desc",
    $zid,
    $zname
);
?>

<div class="page-header">
    <div class="page-header-left d-flex align-items-center">
        <div class="page-header-title">
            <h5 class="m-b-10 text-danger"><?= $this_on ?> ХИЧЭЭЛИЙН ЖИЛ</h5>
        </div>
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="/">Эхлэл</a></li>
            <li class="breadcrumb-item">Миний мэдээлэл</li>
        </ul>
    </div>
</div>
<div class="main-content">
    <div class="card stretch stretch-full">
        <div class="card-header">
            <h5 class="card-title">Миний мэдээлэл</h5>
        </div>
        <div class="card-body">
            <form id='ajax'>
                <div class="row mb-3">
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="fname" class="fw-semibold">Эцэг/эх-ийн нэр: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-user-plus"></i></div>
                                    <input type="text" class="form-control" name="fname" id="fname" class="form-control" value="<?= $fname ?>" required="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="lname" class="fw-semibold">Өөрийн нэр: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-user"></i></div>
                                    <input type="text" class="form-control" name="lname" id="lname" class="form-control" value="<?= $lname ?>" required="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="phone" class="fw-semibold">Утасны дугаар: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-phone"></i></div>
                                    <input type="number" class="form-control" name="phone" id="phone" class="form-control" value="<?= $phone ?>" required="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="email" class="fw-semibold">E-mail: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-mail"></i></div>
                                    <input type="email" class="form-control" name="email" id="email" class="form-control" value="<?= $email ?>" required="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="phone" class="fw-semibold">Албан тушаал: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-briefcase"></i></div>
                                    <input type="text" class="form-control" name="at" id="at" class="form-control" value="<?= $at ?>" required="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="row mb-4 align-items-center">
                            <div class="col-lg-4">
                                <label for="phone" class="fw-semibold">Зэрэг: </label>
                            </div>
                            <div class="col-lg-8">
                                <div class="input-group">
                                    <div class="input-group-text"><i class="feather-layers"></i></div>
                                    <select class="form-select" name="zereg">
                                        <?php while (_fetch($stmtz)) { ?>
                                            <option value="<?= $zid ?>" <?php echo $zid == $zereg ? " selected" : "" ?>><?= $zname ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <input type='submut' class="btn btn-success w-100" onclick="check()" value='Хадгалах' />
                    </div>
                </div>
            </form>
            <div id="table">

            </div>
        </div>
    </div>
</div>
<?php require ROOT . "/pages/main-end.php"; ?>
<?php
require ROOT . "/pages/footer.php"; ?>
<script>
    function check() {
        var form = $('#ajax');
        event.preventDefault();

        //SERIALIZE THE FORM DATA
        var formData = $(form).serialize();
        $("#table").html("");

        $.ajax({
            url: "/profile/ajax",
            type: "POST",
            data: formData,
            error: function(xhr, textStatus, errorThrown) {
                $("#table").html("<div class='alert alert-danger'>Алдаа гарлаа !</div>");
            },
            beforeSend: function() {
                $("#table").html("<div class='alert alert-warning'>Түр хүлээнэ үү ...</div>");
            },
            success: function(data) {
                $("#table").html(data);
            },
            async: true
        });

    }
</script>
<?php

require ROOT . "/pages/end.php";
?>