<?php
$readonly = (strtolower(trim($groupById[0]['name'])) == 'dcv_super_admin') ? 'readonly' : null;
$input_name = array(
    'name' => 'name',
    'type' => 'text',
    'value' => ($name) ? $name : $groupById[0]['name'],
    'placeholder' => '',
    'class' => '',
    'style' => 'width: 100%'
);
$input_description = array(
    'name' => 'description',
    'type' => 'text',
    'value' => ($description) ? $description : $groupById[0]['description'],
    'placeholder' => '',
    'class' => '',
    'style' => 'width: 100%'
);
(strtolower(trim($groupById[0]['name'])) == 'dcv_super_admin') ? $input_name['readonly'] = true : null;
(strtolower(trim($groupById[0]['name'])) == 'dcv_super_admin') ? $input_description['readonly'] = true : null;
?>
<div class="row">
    <div class="widget-box">
        <div class="widget-header">
            <p class="widget-title">Thêm mới nhóm quản trị</p>
        </div>
        <div class="widget-body">
            <div class="widget-main">
                <?php
                $attributes = array('class' => 'form-horizontal', 'id' => 'myform');
                echo form_open(base_url().'backend/cmsSetting/editGroup/'.$groupById[0]['id'], $attributes);
                ?>
                <div class="form-group">
                    <label class="col-lg-3"></label>
                    <div class="col-lg-3">
                        <input type="hidden" name="id" value="<?php echo $groupById[0]['id']; ?>" />
                        <?php
                        if(validation_errors()){echo form_error('id', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div><div class="form-group">
                    <label class="col-lg-3">Mã nhóm (*)</label>
                    <div class="col-lg-3">
                        <?php
                        echo form_input($input_name);
                        if(validation_errors()){echo form_error('name', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3">Mô tả nhóm (*)</label>
                    <div class="col-lg-3">
                        <?php
                        echo form_input($input_description);
                        if(validation_errors()){echo form_error('description', '<div class="error">', '</div>');}
                        ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3">Kích hoạt</label>
                    <div class="col-lg-3">
                        <?php $isActive = ($is_active) ? $is_active : $groupById[0]['is_active'] ?>
                        <input name="is_active" type="checkbox" <?php if($isActive == 'on' || $isActive == 1) echo 'checked'; ?> <?php if(strtolower(trim($groupById[0]['name'])) == 'dcv_super_admin'){echo 'disabled';}?>>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3">Gán quyền Controller cho Nhóm</label>
                    <div class="col-lg-9">
                        <?php if(strtolower(trim($groupById[0]['name'])) != 'dcv_super_admin'): ?>
                        <div class="row">
                            <?php
                            $permissionListSelected = ($group_access_controller_submit) ? $group_access_controller_submit : $group_access_controller;
                            foreach($controllerList as $controllerItem): ?>
                                <div class="col-lg-6">
                                    <label>
                                        <input name="group_access_controller[]" type="checkbox" value="<?php echo $controllerItem['id']; ?>" <?php if($permissionListSelected && in_array($controllerItem['id'], $permissionListSelected)) echo ' checked ' ?>/>
                                        <?php echo $controllerItem['name'].' ('.$controllerItem['description'].')'; ?>
                                    </label>
                                </div>
                            <?php endforeach; ?>
                        </div>
                        <?php else: ?>
                        <div class="row">Full quyền truy cập.</div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-3">
                        <a href="<?php echo base_url().'backend/cmsSetting/listGroup'?>" onclick="return confirm('Bạn có chắc chắn muốn quay lại Danh sách không?')">
                            <button type="button" class="btn btn-sm btn-default">
                                <i class="ace-icon fa fa-arrow-left"></i>Quay lại
                            </button>
                        </a>
                    </div>
                    <?php if(strtolower(trim($groupById[0]['name'])) != 'dcv_super_admin'): ?>
                    <div class="col-lg-4">
                        <button class="btn btn-sm btn-primary" type="submit" name="btnSave">
                            <i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
                        </button>
                        <button class="btn btn-sm" type="reset">
                            <i class="ace-icon fa fa-undo bigger-110"></i>Xóa form
                        </button>
                    </div>
                    <?php endif; ?>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </div>
</div><!-- /.row -->