Exemplo n.º 1
0
 public function cadastrar_registro()
 {
     $msg = null;
     $data = $this->getParametroVisao();
     $data['page'] = 'home';
     $data['tema'] != '' ? $this->load->setTheme($data['tema']) : '';
     $data['msg'] = $msg;
     $data['abaAtiva'] = 23;
     $data['abaPage'] = 'cadastrar_registro';
     $data['alias'] = 'cadastrar_registro';
     $data['total_professores'] = 0;
     $data['title'] = isset($_GET['tipo_registro']) && $_GET['tipo_registro'] == 1 ? 'Inclusão de registros - Educação Infantil' : 'Inclusão de registros - Educação Integral';
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         try {
             // View::validarFormAntInjection($alias);
             $sqlGrade = new SqlGrade();
             $result = $sqlGrade->get_turma($this->input->post('pk_turma'));
             $_SESSION['age_turma_nome'] = $result[0]['turma_nome'];
             $sqlUsuario = new SqlUsuario();
             $result = $sqlUsuario->get_nome_professor($this->input->post('pk_usuario_professor'));
             $_SESSION['age_nome_professor'] = $result[0]['nome'];
             $_SESSION['age_data'] = $this->input->post('data_evento');
             $_SESSION['age_pk_turma'] = $this->input->post('pk_turma');
             $_SESSION['age_pk_usuario_professor'] = $this->input->post('pk_usuario_professor');
             $_SESSION['tipo_registro'] = $this->input->post('tipo_registro');
             $sqlAgenda = new SqlAgenda();
             $result = $sqlAgenda->checa_insert_aula($this->input->post('pk_turma'), View::converteDataEUA($this->input->post('data_evento')), $this->input->post('tipo_registro'));
             if ($result['total'] == 1) {
                 $_SESSION['age_pk_aula'] = $result['registros'][0]['pk_age_aula'];
             } else {
                 $sqlAgenda = new SqlAgenda();
                 $pk_age_aula = $sqlAgenda->cadastrar_aula($this->input->post('pk_turma'), View::converteDataEUA($this->input->post('data_evento')), $this->input->post('pk_usuario_professor'), $this->input->post('tipo_registro'));
                 $_SESSION['age_pk_aula'] = $pk_age_aula;
                 $sqlAgenda = new SqlAgenda();
                 $result = $sqlAgenda->get_alunos($this->input->post('pk_turma'), $data['ano_letivo']);
                 foreach ($result as $row) {
                     $sqlAgenda = new SqlAgenda();
                     $sqlAgenda->cadastrar_registro($pk_age_aula, $row['fk_usuario_aluno']);
                 }
             }
             redirect(base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/cadastrar_registros_faltas/' . $_SESSION['age_pk_aula'] . '?pk_turma=' . $this->input->post('pk_turma') . '&tipo_registro=' . $this->input->post('tipo_registro'));
             return false;
         } catch (Exception $e) {
             $msg = '<p class="alert erro">' . $e->getMessage() . '</p>';
         }
     }
     // pega as turmas do coordenador
     $sqlAgenda = new SqlAgenda();
     $result = $sqlAgenda->get_turmas($data['idUsuario'], $data['ano_letivo']);
     $turma = explode("&pk_turma=", $_SERVER['QUERY_STRING']);
     $turma_url = base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . '?' . $turma[0];
     $select = '<select name="jumpMenu" id="jumpMenu" class="w300" onchange="MM_jumpMenu(\'parent\',this,0)">';
     $select .= '<option value=""></option>';
     foreach ($result as $row) {
         $selected = isset($_GET['pk_turma']) && $_GET['pk_turma'] == $row['pk_turma'] ? 'selected' : '';
         $select .= '<option value="' . $turma_url . '&pk_turma=' . $row['pk_turma'] . '" ' . $selected . '>' . $row['turma_nome'] . '</option>';
     }
     $select .= '</select>';
     $data['turmas'] = $select;
     if (isset($_GET['pk_turma']) && $_GET['pk_turma'] != '') {
         // pega as turmas do coordenador
         $sqlUsuario = new SqlUsuario();
         $result = $sqlUsuario->listar_professores_turma();
         if ($result['total'] > 0) {
             $select = '<select name="pk_usuario_professor" class="required w300" onchange=\'this.form.submit()\'>';
             $select .= '<option value=""></option>';
             foreach ($result['registros'] as $row) {
                 $select .= '<option value="' . $row['fk_usuario_professor'] . '">' . $row['nome'] . ' - ' . $row['materia_nome'] . '</option>';
             }
             $select .= '</select>';
             $data['professores'] = $select;
             $data['total_professores'] = $result['total'];
         } else {
             $data['msg'] = '<div class="alert atencao">Nenhum professor encontrado</div>';
         }
     }
     $this->load->view($this->load->getUrlTema(), $data);
 }