<commit_before><?php

/**
 * Classe Controle para testes.
 *
 * @author 61171
 */
class Teste 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,'idmenu ASC');
            return $this->view('cadastro',$data);
        }
        $this->index();
    }
    
    public function salvar(){
        $is_unique = $this->input->post('idnivel')==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)){
                foreach($this->input->post('idmenu') as $id){
                    $this->permissao_model = new Permissao_model();
                    $this->permissao_model->setId($this->input->post('idpermissao'.$id));
                    $this->permissao_model->idnivel     = $this->nivel_model->getId();
                    $this->permissao_model->idmenu      = $id;
                    $this->permissao_model->consultar   = (string) $this->input->post('consultar'.$id);
                    $this->permissao_model->incluir     = (string) $this->input->post('incluir'.$id);
                    $this->permissao_model->editar      = (string) $this->input->post('editar'.$id);
                    $this->permissao_model->excluir     = (string) $this->input->post('excluir'.$id);

                    echo '<h1>' . $id . '</h1>';
                    echo '<br /> consultar ' . $this->permissao_model->consultar;
                    echo '<br /> incluir ' . $this->permissao_model->incluir;
                    echo '<br /> editar ' . $this->permissao_model->editar;
                    echo '<br /> excluir ' . $this->permissao_model->excluir;
                    if($this->input->post('consultar'.$id)==1){
                        echo '<br /> Consultar = 1';
                    }
                    echo '<br /> post consultar ' . $this->input->post('consultar'.$id);
                    echo '<br /> post incluir ' . $this->input->post('incluir'.$id);
                    echo '<br /> post editar ' . $this->input->post('editar'.$id);
                    echo '<br /> post excluir ' . $this->input->post('excluir'.$id);
                    if(($this->permissao_model->consultar OR $this->permissao_model->incluir OR
                            $this->permissao_model->editar OR $this->permissao_model->excluir) OR  $this->permissao_model->getId()!=NULL){
                        echo '<br /> Passou no if';
                        //$this->permissao_model->salvar(FALSE);
                    }
                }
                //redirect('admin/usuario/nivel/editar/'.$this->nivel_model->getId());
            //}else{
               // $this->view('cadastro');
            //}
        }
    }
}<commit_msg>TESTE da classe MY_Controller<commit_after><?php

/**
 * Classe Controle para testes.
 *
 * @author 61171
 */
class Teste extends MY_Controller{
    public function __construct(){
        parent::__construct('admin/usuario/nivel/',TRUE);
    }
    
    public function index(){
        $this->view('busca');
    }
    
    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,'idmenu ASC');
            return $this->view('cadastro',$data);
        }
        $this->index();
    }
    
    public function salvar(){
        $is_unique = $this->input->post('idnivel')==NULL?"|is_unique[nivel.nome]":'';
        $this->form_validation->set_rules('nome', 'Nome', 'trim|required|min_length[3]|max_length[100]'.$is_unique);
        $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)){
                foreach($this->input->post('idmenu') as $id){
                    $this->permissao_model = new Permissao_model();
                    $this->permissao_model->setId($this->input->post('idpermissao'.$id));
                    $this->permissao_model->idnivel     = $this->nivel_model->getId();
                    $this->permissao_model->idmenu      = $id;
                    $this->permissao_model->consultar   = (string) $this->input->post('consultar'.$id);
                    $this->permissao_model->incluir     = (string) $this->input->post('incluir'.$id);
                    $this->permissao_model->editar      = (string) $this->input->post('editar'.$id);
                    $this->permissao_model->excluir     = (string) $this->input->post('excluir'.$id);
                    
                    if(($this->permissao_model->consultar OR $this->permissao_model->incluir OR
                            $this->permissao_model->editar OR $this->permissao_model->excluir) OR  $this->permissao_model->getId()!=NULL){
                        $this->permissao_model->salvar(FALSE);
                    }
                }
                $this->session->set_flashdata('alerta', 'success_save');
                redirect('admin/usuario/nivel/editar/'.$this->nivel_model->getId());
            }else{
                $this->session->set_flashdata('alerta', 'error_save');
                $this->view('cadastro');
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.18628481345244352, 'fraction_numerical': 0.004072517078297425, 'mean_word_length': 1.9937082186394022, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 208, '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': '1764080', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2400, 'n_words': 302}