<div class="title">課室詳情</div>
<ul class="table-toolbar"style="text-align: left;">
    <li><a class="toolbar-element btn btn-default btn-create" href="/room" ><i style="margin-right: 8px;"><span class="iconify" data-icon="typcn-arrow-back" data-inline="false"></span></i>返回</a></li>
</ul>

<div class="form-container">
    <form id="frmphp" class="form-horizontal" role="form" method="POST" action="/room/save">
        <input type="hidden" name="id" value="<?= $room['id']; ?>" />
        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="roomname">課室名稱</label></div>
            <div class="col-sm-9 text-center mas-title mas-box "><input id="roomname" name="name" type="text" class="form-control mas-input" value="<?= $room['name'] ?>" /></div>
        </div>      

        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="capacity">最多可容納人數</label></div>
            <div class="col-sm-9 text-center mas-title mas-box "><input id="capacity" name="capacity" type="number" class="form-control mas-input" value="<?= $room['capacity'] ?>" /></div>
        </div>

        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="status">狀態</label></div>
            <div class="col-sm-9 text-center mas-title mas-box ">
                <select class="select mas-select" name="status" id="status">
                    <?php
                        foreach ($status as $idx => $value) {
                            if ($idx == $room['status']) {
                                $selected = ' selected="selected"';
                            }
                            else {
                                $selected = '';
                            }
                            echo sprintf('<option value="%s"%s>%s</option>', $idx, $selected, $value);
                        }
                    ?>
                </select>
            </div>
        </div>

        <div class="form-group mas-col" style="background-color: #f9cccf;">
            <div class="col-sm-3 text-center mas-title"><label for="description">詳情</label></div>
            <div class="col-sm-9 mas-box"><textarea id="description"  class="form-control mas-textarea" rows="3" name="description" ><?=$room['description']?></textarea></div>
        </div>

        <div class="form-group mas-col" style="background-color: #f9cccf;">
            <div class="col-sm-3 text-center mas-title"><label for="remark">備註</label></div>
            <div class="col-sm-9 mas-box"><textarea id="remark"  class="form-control mas-textarea" rows="3" name="remark" ><?=$room['remark']?></textarea></div>
        </div>
        <div class="form-footer">
            <a class="btn btn-footer reset" href="javascript:window.location.reload(true)">重設</a>
            <button class="btn btn-footer submit" type="button" id='btnSubmit'>提交</button>
        </div>
    </form>

</div>

<script>
    $(document).ready(function () {
        $('#sidebar-menu').find('li:eq(11)').addClass('active open');
    });

    function validform() {
        var msg = '';
        if ($('#roomname').val() === '') {
            msg += "請輸入課室名稱\n";
        }
        if ($('#capacity').val() === '') {
            msg += "請輸入最多可容納人數\n";
        }
        if (msg !== '') {
            alert(msg);
            return false;
        }
        return true;
    }

    $(document).on('click','#btnSubmit', function () {
        if (validform()) {
            $('#frmphp').submit();
        }
    });

</script>