<?php $this->view('ajax_loading_v'); ?>

<?php if (isset($msg_text)): ?>
    <script type="text/javascript">
        $(function(){
            var msg_text = "<?php echo $msg_text; ?>";
            $.facebox(msg_text);
        });
    </script>
<?php endif; ?>

<script type="text/javascript">
    $(function(){
        $('#alert_frm').css('display', 'none');
        $("#myform").validate({
            onkeyup: false,
            messages: {
                password2: {
                    equalTo: "กรอกรหัสผ่านให้ตรงกัน"
                }
            }
        });
        
        $.metadata.setType("attr", "validate");
    });

    function save(){
        var p = {};
        p['id'] = $('#id').val();
        p['username'] = $('#username').val();
        $.ajax({
            data:p,
            url:"<?php echo site_url('member/ajax_validate') ?>",
            type:'POST',
            dataType:'json',
            success: function(data){
                if(data.msg=='1'){
                    $('#alert_frm').text(data.msg_text).show();
                }else{
                    $('#myform').submit();
                }
            },
            error:function(){
                alert('ไม่สามารถทำรายการได้ !!');
            }
        });
        return false;
    }
</script>
<div class="textbox">
    <div class="toolbar">
        <div class="pull-left title"><?php echo $page_title; ?></div>
        <div class="pull-right">
            <?php echo anchor('member/news', "<i class='icon-plus'></i> เพิ่มข้อมูล", array('class' => 'btn')); ?>
            <a href="#" class="btn" onclick="return save();"><i class="icon-hdd"></i> บันทึกข้อมูล</a>
            <?php echo anchor('member', "<i class='icon-remove-circle'></i> ปิด", array('class' => 'btn')); ?>
        </div>
        <div class="clear"></div>
    </div>
    <div class="textbox_content">
        <div class="alert alert-error" style="display:none" id="alert_frm"></div>
        <?php echo form_open('member/save', array('id' => 'myform')); ?>
        <input type="hidden" id="id" name="id" value="<?php echo @$row['id']; ?>"/>
        <table border="0" cellpadding="4" cellspacing="1" class="tblform">
            <tbody>
                <tr>
                    <td class="td1" width="120">ประเภทสมาชิก :</td>
                    <td>
                        <select name="mem_type">
                            <option value="0" <?php echo (@$row['mem_type'] == '0') ? 'selected' : ''; ?>>ผู้จองห้องประชุม</option>
                            <option value="2" <?php echo (@$row['mem_type'] == '2') ? 'selected' : ''; ?>>ผู้อนุมัติประจำแผนก</option>
                            <option value="1" <?php echo (@$row['mem_type'] == '1') ? 'selected' : ''; ?>>ผู้ดูแลระบบ</option>
                        </select>
                        &nbsp;&nbsp;
                        <strong>สถานะ :</strong>
                        <select name="status">
                            <option value="0" <?php echo (@$row['status'] == '0') ? 'selected' : ''; ?>>รออนุมัติ</option>
                            <option value="1" <?php echo (@$row['status'] == '1') ? 'selected' : ''; ?>>ใช้งาน</option>
                            <option value="2" <?php echo (@$row['status'] == '2') ? 'selected' : ''; ?>>ระงับการใช้งาน</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="td1" width="150">ชื่อ-นามสกุล :<span class="required">*</span></td>
                    <td class="td2"><input type="text" class="txt required" name="name" style="width: 350px" value="<?php echo @$row['name']; ?>" /></td>
                </tr>
                <tr>
                    <td class="td1" width="150">ชื่อเข้าใช้งาน :<span class="required">*</span></td>
                    <td class="td2"><input type="text" class="txt required" id="username" name="username" value="<?php echo @$row['username']; ?>" /></td>
                </tr>
                <tr>
                    <td class="td1" width="150">รหัสผ่าน :</td>
                    <td class="td2"><input type="text" class="txt" id="password1" name="password1" value="" /></td>
                </tr>
                <tr>
                    <td class="td1" width="150">ยืนยันรหัสผ่าน :</td>
                    <td class="td2"><input type="text" class="txt" id="password2" name="password2" equalTo="#password1" value="" /></td>
                </tr>
                <tr>
                    <td class="td1" width="150">ตำแหน่ง :<span class="required">*</span></td>
                    <td class="td2"><input type="text" class="txt required" name="position" style="width: 350px" value="<?php echo @$row['position']; ?>" /></td>
                </tr>
                <tr>
                    <td class="td1">สังกัดแผนก :<span class="required">*</span></td>
                    <td class="td2">
                        <select id="depart_id" name="depart_id" style="padding: 2px;" title="เลือกแผนก !" validate="required:true">
                            <option value="">*** เลือกแผนก ***</option>
                            <?php
                            foreach ($depart as $r):
                                $selected = ($r['id'] == @$row['depart_id']) ? 'selected' : '';
                                ?>

                                <option value="<?php echo $r['id']; ?>" <?php echo $selected; ?>><?php echo $r['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="td1" width="150">โทรศัพท์(มือถือ) :</td>
                    <td class="td2">
                        <input type="text" class="txt" name="mobile" value="<?php echo @$row['mobile']; ?>" />&nbsp;&nbsp; เบอร์ติดต่อภายใน
                        <input type="text" class="txt" name="tel" value="<?php echo @$row['tel']; ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="td1">อีเมลล์ :</td>
                    <td class="td2">
                        <input type="text" class="txt" name="email" value="<?php echo @$row['email']; ?>" style="width:350px"/>
                    </td>
                </tr>
            </tbody>
        </table>
        <?php echo form_close(); ?>
    </div>
</div>
