<!-- Content Header (Page header) -->
     <?php echo theme_view('content_header');?>
 
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
            
            <form name="crud-add" action="<?php echo base_url().'sistema/perfil/index/edit/'.$id_perfil;?>" method="post" >
            
                <div class="card card-accent-primary">
                    <div class="card-header">
                        <div class="form-group name_form_group">
                            <label class="col-md-2 control-label">Perfil</label>
                            <div class="col-md-10">
                                <?php if(isset($id_perfil) && !empty($id_perfil)){?>
                                <input id="field-id_perfil" class="form-control" name="id_perfil" type="hidden" value="<?php echo $id_perfil;?>" >
                                <?php }?>
                                <input id="field-perfil" class="form-control" name="perfil" type="text" value="<?php if(isset($perfil)){ echo $perfil->perfil; }?>" maxlength="255">
                            </div>
                        </div>
                    </div>
                
                    <div class="card-header">
                        <div class="form-group name_form_group">
                            <label class="col-md-2 control-label">Tipo de Menu</label>
                            <div class="col-md-10">
                                <div class="pretty-radio-buttons">
                                    <label>
                                        <input type="radio" <?php if(!isset($perfil->tipo_menu) || $perfil->tipo_menu == 1){ echo 'checked="checked"'; } ?> value="1" name="tipo_menu" class="radio-uniform"> Módulo &nbsp;&nbsp;
                                    </label>
                                    <label>
                                        <input type="radio" <?php if($perfil->tipo_menu == 2){ echo 'checked="checked"'; } ?> value="2" name="tipo_menu" class="radio-uniform"> Seção
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                
                    <div class="card-body no-padding">
                        <div class="table-responsive mailbox-messages">
                            <table class="table">
                                <tbody>
                                    <tr>
                                        <th>Módulos</th>
                                    </tr>                                 
                                    <?php if(!empty($result)){ ?>
                                    <?php foreach ($result as $modulo){ ?>                                    
                                    <tr>
                                        <td>
                                            <div id="top-box" class="card card-accent-success collapsed-box collapse show collapsed-checkbox chkpt chkpt-primary">
                                                <div class="card-header with-border">
                                                    <div class="form-group has-success d-flex align-items-center">
                                                        <input id="check-mod-<?php echo $modulo->id_module; ?>" name="modulo[<?php echo $modulo->id_module; ?>]" type="checkbox" value="" data-toggle="checkbox-y" data-level="1" data-theme="krajee-flatblue" data-size="sm">
                                                        <label class="cbx-label collapse-trigger" data-toggle="collapse" data-target="#box-<?php echo $modulo->id_module;?>">
                                                            <i class="<?php echo $modulo->icon; ?>"></i>
                                                            <h3 class="card-title"><?php echo $modulo->name; ?></h3>
                                                        </label>
 
 
                                                        <div class="box-tools pull-right">
                                                        <button data-toggle="collapse" data-target="#box-<?php echo $modulo->id_module; ?>" type="button" class="btn btn-box-tool toggle-collapse" data-widget="collapse">
                                                            <i id="box-<?php echo $modulo->id_module;?>-btn" class="fa fa-plus"></i></button>
                                                    </div><!-- /.box-tools -->
                                                    </div>
                                                </div><!-- /.box-header -->
                                                <?php if(!empty($modulo->secoes)){?>
                                                <div id="box-<?php echo $modulo->id_module; ?>" class="card-body collapse">
                                                    <?php foreach ($modulo->secoes as $secao) { ?>
                                                    
                                                    <?php if(isset($secao->subsecoes) && !empty($secao->subsecoes)){ $data_level = 2;} else {$data_level = 3;}?>
                                                    
                                                    <div class="card card-accent-info collapsed-box chkpt ">
                                                        <div class="card-header with-border">
                                                            <div class="form-group has-primary box-checkbox">
                                                                <input id="check-sec-<?php echo $secao->id_section;?>" type="checkbox" value="" name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>]" 
                                                                data-toggle="checkbox-y" data-level="<?php echo $data_level;?>" data-theme="krajee-flatblue" data-size="sm">
                                                                <label data-toggle="collapse" data-target="#sec-<?php echo $secao->id_section; ?>" class="cbx-label  collapse-trigger">
                                                                    <i class="<?php echo $secao->icon;?>"></i>
                                                                    <h3 class="card-title"><?php echo $secao->name;?></h3>
                                                                </label>
                                                            </div>
                                                            <div class="box-tools pull-right">
                                                                <button data-toggle="collapse" data-target="#sec-<?php echo $secao->id_section; ?>" type="button" class="btn btn-box-tool toggle-collapse" data-widget="collapse">
                                                                    <i id="sec-<?php echo $secao->id_section;?>-btn" class="fa fa-plus"></i>
                                                                </button>
                                                            </div>
                                                            <!-- /.box-tools -->
                                                        </div>
                                                        <!-- /.box-header -->
                                                        
                                                        <?php if(isset($secao->subsecoes) && !empty($secao->subsecoes)) {?>
                                                            <div id="sec-<?php echo $secao->id_section; ?>" class="card-body teste collapse">
                                                                <?php foreach ($secao->subsecoes as $subsecao){?>
                                                                    <div class="card card-accent-warning collapsed-box chkpt">
                                                                        <div class="card-header with-border">
                                                                            <div class="form-group has-warning">
                                                                                <input id="check-sub-1" type="checkbox" value="" 
                                                                                name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>][<?php echo $subsecao->id_subsection;?>]" 
                                                                                data-toggle="checkbox-y" data-level="3" data-theme="krajee-flatblue" data-size="sm">
                                                                                <label data-toggle="collapse" data-target="#sub-<?php echo $subsecao->id_subsection;?>" class="cbx-label collapse-trigger">
                                                                                    <i class="fa fa-chevron-right" style="font-size: 10px"></i>
                                                                                    <h3 class="card-title"><?php echo $subsecao->name;?></h3>
                                                                                </label>
                                                                            </div>
                                                                            <div class="box-tools pull-right">
                                                                                <button data-toggle="collapse" data-target="#sub-<?php echo $subsecao->id_subsection;?>" type="button" class="btn btn-box-tool toggle-collapse" data-widget="collapse">
                                                                                    <i id="sub-<?php echo $subsecao->id_subsection;?>-btn" class="fa fa-plus"></i></button>
                                                                            </div>
                                                                        </div>
                                                                        <div id="sub-<?php echo $subsecao->id_subsection;?>" class="card-body collapse">                                                                         
                                                                            <div class="card card-accent-secondary">
                                                                                <div class="card-header with-border">
                                                                                    <h3 class="card-title">Selecione as Ações</h3>
                                                                                </div>
                                                                                <div class="box-acoes">
                                                                                    <!-- text input -->
                                                                                    <div class="form-group">
                                                                                        <label>Ações</label>
                                                                                        <?php if (!empty($subsecao->acoes)){?>
                                                                                        <select name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>][<?php echo $subsecao->id_subsection;?>][]"  multiple data-level="4" class='chosen-select-95 field-acoes' data-placeholder='Selecione as Ações'>
                                                                                        <?php foreach ($subsecao->acoes as $acao) { ?>
                                                                                            <option value="<?php echo $acao->id_action; ?>" ><?php echo $acao->action; ?></option>
                                                                                        <?php }?>                                                                             
                                                                                        </select>
                                                                                        <?php } else { ?>                                                                             
                                                                                        <input type="text" name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>][<?php echo $subsecao->id_subsection;?>][]" value="0" class="form-control" placeholder="Nenhuma ação cadastrada para esta seção." readonly="readonly">
                                                                                        <?php }?>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>                                                            
                                                                 </div>
                                                                <?php }?>                                                             
                                                            </div><!-- /.box-body -->
                                                        <?php }?> 
                                                            
                                                        <?php if(!isset($secao->subsecoes)) {?>
                                                            
                                                            <div id="sec-<?php echo $secao->id_section; ?>" class="card-body collapse">
                                                                <div class="card card-accent-secondary">
                                                                    <div class="card-header with-border">
                                                                        <h3 class="card-title">Selecione as Ações</h3>
                                                                    </div>
                                                                    <div class="box-acoes">
                                                                        <!-- text input -->
                                                                        <div class="form-group">
                                                                            <label data-toggle="collapse" data-target="#box-<?php echo $modulo->id_module; ?>">Ações</label>
                                                                            <?php if (!empty($secao->acoes)){?>
                                                                            <select name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>][]" multiple data-level="4" class='chosen-select-95 field-acoes' data-placeholder='Selecione as Ações'>
                                                                            <?php foreach ($secao->acoes as $acao) { ?>
                                                                                <option value="<?php echo $acao->id_action; ?>" ><?php echo $acao->action; ?></option>
                                                                            <?php }?>                                                                             
                                                                            </select>
                                                                            <?php } else { ?>                                                                             
                                                                            <input type="text" class="form-control" name="modulo[<?php echo $modulo->id_module; ?>][<?php echo $secao->id_section;?>][]" value="0"  placeholder="Nenhuma ação cadastrada para esta seção." readonly="readonly">
                                                                            <?php }?>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        <?php }?>
                                                        </div><!-- /.box -->    
                                                    <?php } ?><!-- /foreach secao -->
                                                </div><!-- /.box-body -->
                                                <?php }?><!-- /if secao -->
                                            </div>
                                        </td>
                                    </tr><!-- /.modulo 1 -->
 
                                    <?php }?>
                                    <?php }?>                                 
                                </tbody>
                            </table>
                        </div>
 
                    </div>
                    <div class="card-footer">
                        <button class="btn btn-success b10" type="submit" id="form-button-save">
                            <i class="fa fa-rotate-left"></i> Salvar e voltar para a listagem
                        </button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </section><!-- Main content -->