<h3 class="text-left">創建用戶帳號</h3>

<ul class="table-toolbar" style="text-align: left;">
    <li><a class="toolbar-element btn btn-default btn-create" href="/user"><i class="fa fa-chevron-left" style="margin-right: 8px;"></i>返回</a></li>
</ul>

<?php echo form_open('user/add', array('id' => 'frmuser', "class" => "form-horizontal form-container")); ?>

<div class="form-group">
    <label for="status" class="col-sm-4 control-label">狀態</label>
    <div class="col-sm-8">
        <input type="checkbox" name="status" value="1" id="status" checked />
    </div>
</div>
<div class="form-group">
    <label for="firstname" class="col-sm-4 control-label"><span class="text-danger">*</span>名稱</label>
    <div class="col-sm-8">
        <input type="text" name="firstname" value="<?php echo $this->input->post('firstname'); ?>" class="form-control" id="firstname" />
        <span class="text-danger"><?php echo form_error('firstname'); ?></span>
    </div>
</div>
<div class="form-group">
    <label for="lastname" class="col-sm-4 control-label"><span class="text-danger">*</span>姓氏</label>
    <div class="col-sm-8">
        <input type="text" name="lastname" value="<?php echo $this->input->post('lastname'); ?>" class="form-control" id="lastname" />
        <span class="text-danger"><?php echo form_error('lastname'); ?></span>
    </div>
</div>
<div class="form-group">
    <label for="firstname" class="col-sm-4 control-label"><span class="text-danger"></span>帳號名稱</label>
    <div class="col-sm-8">
        <input type="text" name="username" class="form-control" id="username" autocomplete="off" />

    </div>
</div>
<div class="form-group">
    <label for="password" class="col-sm-4 control-label"><span class="text-danger"></span>帳號密碼</label>
    <div class="col-sm-8">
        <input type="password" name="password" value="" class="form-control" id="password" autocomplete="off" />
    </div>
</div>
<div class="form-group">
    <label for="confirmpassword" class="col-sm-4 control-label"><span class="text-danger"></span>確認帳號密碼</label>
    <div class="col-sm-8">
        <input type="password" value="" class="form-control" id="confirmpassword" autocomplete="nope" />
    </div>
</div>

<div class="form-group">
    <label for="id" class="col-sm-4 control-label">用戶角色</label>
    <div class="col-sm-8">
        <?php foreach ($roles as $k => $v) : ?>
            <div class="form-check">
                <input class="form-check-input" type="checkbox" name="roles[]" value="<?php echo  $v['id'] ?>" id="<?php echo  $v['id'] ?>">
                <label class="form-check-label" for="<?php echo  $v['id'] ?>">
                    <?php echo  $v['name'] ?>
                </label>
            </div>
        <?php endforeach ?>
    </div>
</div>

<!--<div class="form-group">
    <label for="createdate" class="col-sm-4 control-label">Createdate</label>
    <div class="col-sm-8">
        <input type="text" name="createdate" value="<?php echo $this->input->post('createdate'); ?>" class="form-control" id="createdate" />
    </div>
</div>
<div class="form-group">
    <label for="updatedate" class="col-sm-4 control-label">Updatedate</label>
    <div class="col-sm-8">
        <input type="text" name="updatedate" value="<?php echo $this->input->post('updatedate'); ?>" class="form-control" id="updatedate" />
    </div>
</div>-->

<div class="form-group">
    <div class="">
        <button id="btnsubmit" type="submit" class="btn btn-success">提交</button>
        <a href="/user" class="btn btn-cancel">取消</a>
    </div>
</div>

<?php echo form_close(); ?>

<script>
    $(document).ready(function() {

        $('#confirmpassword').on('change', function() {
            if ($(this).val() !== $('#password').val()) {
                alert('帳號密碼與確認帳號密碼不相符！');
                $(this).addClass('error');
            }
        });

        $('#btnsubmit').on('click', function() {
            if ($('.error').length === 0) {
                $('#frmuser').submit();
            }
        });

    });
</script>