<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description of Nivel
 *
 * @author <NAME>
 */
class Nivel extends CI_Controller{
    
    public function __construct(){
        parent::__construct();

        if($this->usuario_model->verificaUsuario()){
            $this->usuario_model->validarPermissaoDeAcesso('admin-usuario-nivel');
        }
    }
    
    public function index(){
        $this->view('busca');
    }
    
    public function view($page = 'busca',$data = array()){
	if ( ! file_exists(APPPATH.'/views/admin/usuario/nivel/'.$page.'.php')){
            // Whoops, we don't have a page for that!
            show_404();
        }

        $data['title'] = ucfirst($page); // Capitalize the first letter
        $data['page'] = $page;
        
        $alerta = $this->session->flashdata('alerta');
        if ($alerta !== NULL) {
            $data[separa_str($alerta, '_', FALSE)] = $this->lang->line($alerta);
        }
        
        $this->load->view('templates/header', $data);
	$this->load->view('templates/top_bar_menu', $data);
        $this->load->view('admin/usuario/nivel/'.$page, $data);
        $this->load->view('templates/scripts',$data);
    }
    
    public function editar($id = NULL){
        $data = array();
        if($id!==NULL){
            $this->nivel_model->selecionar('*','id =' . $id);
            $query = $this->nivel_model->getQuery();
            $data = $query->row_array();
            $data['idnivel'] = $id;
            $data['permissoes'] = $this->permissao_model->selecionar('*','idnivel = ' . $id,'nome ASC');
            $this->form_validation->set_data($data);
            return $this->view('cadastro',$data);
        }
        $this->index();
    }
    
    public function salvar(){
        $is_unique = $this->input->post('id')==NULL?"|is_unique[nivel.nome]":'';
        $this->form_validation->set_rules('nome', 'Nome', 'trim|required|min_length[3]|max_length[100]'.$is_unique,array('is_unique'=>'Este nome já foi cadastrado, tente outro.'));
        $this->form_validation->set_rules('email', 'Email', 'trim|max_length[300]');
        
        if ($this->form_validation->run() == FALSE) {
            $this->view('cadastro');
        }else{
            $this->nivel_model->setId($this->input->post('idnivel'));
            $this->nivel_model->nome = $this->input->post('nome');
            $this->nivel_model->descricao = $this->input->post('descricao');
            if($this->nivel_model->salvar(FALSE)){
                $i = 0;
                foreach($this->input->post('idmenu') as $id){
                    $this->permissao_model->setId($this->input->post('idpermissao['.$i.']'));
                    $this->permissao_model->idnivel = $this->nivel_model->getId();
                    $this->permissao_model->idmenu = $id;
                    $this->permissao_model->consultar = $this->input->post('consultar['.$i.']');
                    $this->permissao_model->incluir = $this->input->post('incluir['.$i.']');
                    $this->permissao_model->editar = $this->input->post('editar['.$i.']');
                    $this->permissao_model->excluir = $this->input->post('excluir['.$i.']');
                    $this->permissao_model->salvar(FALSE);
                    $i++;
                }
                $this->view('busca');
            }else{
                $this->view('cadastro');
            }
        }
    }
}
<commit_msg>[UPD] remoção do set_data e adição do campo nome para as permissoes<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description of Nivel
 *
 * @author <NAME>
 */
class Nivel extends CI_Controller{
    
    public function __construct(){
        parent::__construct();

        if($this->usuario_model->verificaUsuario()){
            $this->usuario_model->validarPermissaoDeAcesso('admin-usuario-nivel');
        }
    }
    
    public function index(){
        $this->view('busca');
    }
    
    public function view($page = 'busca',$data = array()){
	if ( ! file_exists(APPPATH.'/views/admin/usuario/nivel/'.$page.'.php')){
            // Whoops, we don't have a page for that!
            show_404();
        }

        $data['title'] = ucfirst($page); // Capitalize the first letter
        $data['page'] = $page;
        
        $alerta = $this->session->flashdata('alerta');
        if ($alerta !== NULL) {
            $data[separa_str($alerta, '_', FALSE)] = $this->lang->line($alerta);
        }
        
        $this->load->view('templates/header', $data);
	$this->load->view('templates/top_bar_menu', $data);
        $this->load->view('admin/usuario/nivel/'.$page, $data);
        $this->load->view('templates/scripts',$data);
    }
    
    public function editar($id = NULL){
        $data = array();
        if($id!==NULL){
            $this->nivel_model->selecionar('*','id =' . $id);
            $query = $this->nivel_model->getQuery();
            $data = $query->row_array();
            $data['idnivel'] = $id;
            $data['permissoes'] = $this->permissao_model->selecionar('*','idnivel = ' . $id,'nome ASC');
            return $this->view('cadastro',$data);
        }
        $this->index();
    }
    
    public function salvar(){
        $is_unique = $this->input->post('id')==NULL?"|is_unique[nivel.nome]":'';
        $this->form_validation->set_rules('nome', 'Nome', 'trim|required|min_length[3]|max_length[100]'.$is_unique,array('is_unique'=>'Este nome já foi cadastrado, tente outro.'));
        $this->form_validation->set_rules('email', 'Email', 'trim|max_length[300]');
        
        if ($this->form_validation->run() == FALSE) {
            $this->view('cadastro');
        }else{
            $this->nivel_model->setId($this->input->post('idnivel'));
            $this->nivel_model->nome = $this->input->post('nome');
            $this->nivel_model->descricao = $this->input->post('descricao');
            if($this->nivel_model->salvar(FALSE)){
                $i = 0;
                foreach($this->input->post('idmenu') as $id){
                    $this->permissao_model->setId($this->input->post('idpermissao['.$i.']'));
                    $this->permissao_model->idnivel = $this->nivel_model->getId();
                    $this->permissao_model->idmenu = $id;
                    $this->permissao_model->nome = $this->input->post('nome_permissao['.$i.']');
                    $this->permissao_model->consultar = $this->input->post('consultar['.$i.']');
                    $this->permissao_model->incluir = $this->input->post('incluir['.$i.']');
                    $this->permissao_model->editar = $this->input->post('editar['.$i.']');
                    $this->permissao_model->excluir = $this->input->post('excluir['.$i.']');
                    if($this->permissao_model->nome!==NULL){
                        $this->permissao_model->salvar(FALSE);
                    }
                    $i++;
                }
                $this->view('busca');
            }else{
                $this->view('cadastro');
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.19425745294683336, 'fraction_numerical': 0.003022393185877181, 'mean_word_length': 2.033333333333333, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 177, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2294, 'n_words': 293}