function Novo()
 {
     session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     if ($this->passo == 2) {
         return true;
     }
     $obj_reserva_vaga = new clsPmieducarReservaVaga(NULL, $this->ref_cod_escola, $this->ref_cod_serie, NULL, $this->pessoa_logada, $this->ref_cod_aluno, NULL, NULL, 1, $this->nm_aluno_ext, idFederal2int($this->cpf_responsavel));
     $cadastrou = $obj_reserva_vaga->cadastra();
     if ($cadastrou) {
         $this->mensagem .= 'Reserva de Vaga efetuada com sucesso.<br>';
         header('Location: educar_reservada_vaga_det.php?cod_reserva_vaga=' . $cadastrou);
         die;
     }
     $this->mensagem = 'Reserva de Vaga n&atilde;o realizada.<br>';
     return FALSE;
 }
    function Novo()
    {
        $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno;
        $this->nome_url_cancelar = 'Cancelar';
        @session_start();
        $this->pessoa_logada = $_SESSION['id_pessoa'];
        @session_write_close();
        $obj_permissoes = new clsPermissoes();
        $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
        //novas regras matricula aluno
        $this->ano = $_POST['ano'];
        $anoLetivoEmAndamentoEscola = new clsPmieducarEscolaAnoLetivo();
        $anoLetivoEmAndamentoEscola = $anoLetivoEmAndamentoEscola->lista($this->ref_cod_escola, $this->ano, null, null, 2, null, null, null, null, 1);
        if (is_array($anoLetivoEmAndamentoEscola)) {
            require_once 'include/pmieducar/clsPmieducarSerie.inc.php';
            $db = new clsBanco();
            $db->Consulta("select ref_ref_cod_serie, ref_cod_curso from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola = {$this->ref_cod_escola} and ref_cod_curso = {$this->ref_cod_curso} and ref_cod_aluno = {$this->ref_cod_aluno} and aprovado not in (1,2,4,5,6,7,8,9)");
            $db->ProximoRegistro();
            $m = $db->Tupla();
            if (is_array($m) && count($m)) {
                $curso = $this->getCurso($this->ref_cod_curso);
                if ($m['ref_ref_cod_serie'] == $this->ref_cod_serie) {
                    $this->mensagem .= "Este aluno já está matriculado nesta série e curso, não é possivel matricular um aluno mais de uma vez na mesma série.<br />";
                    return false;
                } elseif ($curso['multi_seriado'] != 1) {
                    $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']);
                    $serie = $serie->detalhe();
                    if (is_array($serie) && count($serie)) {
                        $nomeSerie = $serie['nm_serie'];
                    } else {
                        $nomeSerie = '';
                    }
                    $this->mensagem .= "Este aluno já está matriculado no(a) '{$nomeSerie}' deste curso e escola. Como este curso não é multi seriado, não é possivel manter mais de uma matricula em andamento para o mesmo curso.<br />";
                    return false;
                }
            } else {
                $db->Consulta("select ref_ref_cod_escola, ref_cod_curso, ref_ref_cod_serie from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola != {$this->ref_cod_escola} and ref_cod_aluno = {$this->ref_cod_aluno} and aprovado not in (1,2,4,5,6,7,8,9) and not exists (select 1 from pmieducar.transferencia_solicitacao as ts where ts.ativo = 1 and ts.ref_cod_matricula_saida = matricula.cod_matricula)");
                $db->ProximoRegistro();
                $m = $db->Tupla();
                if (is_array($m) && count($m)) {
                    if ($m['ref_cod_curso'] == $this->ref_cod_curso || $GLOBALS['coreExt']['Config']->app->matricula->multiplas_matriculas == 0) {
                        require_once 'include/pmieducar/clsPmieducarEscola.inc.php';
                        require_once 'include/pessoa/clsJuridica.inc.php';
                        $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']);
                        $serie = $serie->detalhe();
                        if (is_array($serie) && count($serie)) {
                            $serie = $serie['nm_serie'];
                        } else {
                            $serie = '';
                        }
                        $escola = new clsPmieducarEscola($m['ref_ref_cod_escola']);
                        $escola = $escola->detalhe();
                        if (is_array($escola) && count($escola)) {
                            $escola = new clsJuridica($escola['ref_idpes']);
                            $escola = $escola->detalhe();
                            if (is_array($escola) && count($escola)) {
                                $escola = $escola['fantasia'];
                            } else {
                                $escola = '';
                            }
                        } else {
                            $escola = '';
                        }
                        $curso = new clsPmieducarCurso($m['ref_cod_curso']);
                        $curso = $curso->detalhe();
                        if (is_array($curso) && count($curso)) {
                            $curso = $curso['nm_curso'];
                        } else {
                            $curso = '';
                        }
                        $this->mensagem .= "Este aluno já está matriculado no(a) '{$serie}' do curso '{$curso}' na escola '{$escola}', para matricular este aluno na sua escola solicite transferência ao secretário(a) da escola citada.<br />";
                        return false;
                    }
                }
            }
            $obj_reserva_vaga = new clsPmieducarReservaVaga();
            $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, $this->ref_cod_serie, NULL, NULL, $this->ref_cod_aluno, NULL, NULL, NULL, NULL, 1);
            // Verifica se existe reserva de vaga para o aluno
            if (is_array($lst_reserva_vaga)) {
                $det_reserva_vaga = array_shift($lst_reserva_vaga);
                $this->ref_cod_reserva_vaga = $det_reserva_vaga['cod_reserva_vaga'];
                $obj_reserva_vaga = new clsPmieducarReservaVaga($this->ref_cod_reserva_vaga, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, 0);
                $editou = $obj_reserva_vaga->edita();
                if (!$editou) {
                    $this->mensagem = 'Edição não realizada.<br />';
                    return FALSE;
                }
            }
            $vagas_restantes = 1;
            if (!$this->ref_cod_reserva_vaga) {
                $obj_turmas = new clsPmieducarTurma();
                $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_cod_serie, $this->ref_cod_escola, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
                if (is_array($lst_turmas)) {
                    $total_vagas = 0;
                    foreach ($lst_turmas as $turmas) {
                        $total_vagas += $turmas['max_aluno'];
                    }
                } else {
                    $this->mensagem = 'A série selecionada não possui turmas cadastradas.<br />';
                    return FALSE;
                }
                $obj_matricula = new clsPmieducarMatricula();
                $lst_matricula = $obj_matricula->lista(NULL, NULL, $this->ref_cod_escola, $this->ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1, $this->ano, $this->ref_cod_curso, $this->ref_cod_instituicao, 1);
                if (is_array($lst_matricula)) {
                    $matriculados = count($lst_matricula);
                }
                $obj_reserva_vaga = new clsPmieducarReservaVaga();
                $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, $this->ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao, $this->ref_cod_curso);
                if (is_array($lst_reserva_vaga)) {
                    $reservados = count($lst_reserva_vaga);
                }
                $vagas_restantes = $total_vagas - ($matriculados + $reservados);
            }
            if ($vagas_restantes <= 0) {
                echo sprintf('
          <script>
            var msg = \'\';
            msg += \'Excedido o número de total de vagas para Matricula!\\n\';
            msg += \'Número total de matriculados: %d\\n\';
            msg += \'Número total de vagas reservadas: %d\\n\';
            msg += \'Número total de vagas: %d\\n\';
            msg += \'Deseja mesmo assim realizar a Matrícula?\';

            if (! confirm(msg)) {
              window.location = \'educar_aluno_det.php?cod_aluno=%d\';
            }
          </script>', $matriculados, $reservados, $total_vagas, $this->ref_cod_aluno);
            }
            $obj_matricula_aluno = new clsPmieducarMatricula();
            $lst_matricula_aluno = $obj_matricula_aluno->lista(NULL, NULL, NULL, NULL, NULL, NULL, $this->ref_cod_aluno);
            if (!$lst_matricula_aluno) {
                // Primeira matrícula do sistema, consistência (?)
                $this->matricula_transferencia = $this->matricula_transferencia == 'on' ? TRUE : FALSE;
            } else {
                $this->matricula_transferencia = FALSE;
            }
            if ($this->is_padrao == 1) {
                $this->semestre = NULL;
            }
            if (!$this->removerFlagUltimaMatricula($this->ref_cod_aluno)) {
                return false;
            }
            $this->data_matricula = Portabilis_Date_Utils::brToPgSQL($this->data_matricula);
            $obj = new clsPmieducarMatricula(NULL, $this->ref_cod_reserva_vaga, $this->ref_cod_escola, $this->ref_cod_serie, NULL, $this->pessoa_logada, $this->ref_cod_aluno, 3, NULL, NULL, 1, $this->ano, 1, NULL, NULL, NULL, NULL, $this->ref_cod_curso, $this->matricula_transferencia, $this->semestre, $this->data_matricula);
            $cadastrou = $obj->cadastra();
            // turma
            $cod_matricula = $cadastrou;
            $this->enturmacaoMatricula($cod_matricula, $this->ref_cod_turma);
            if ($cadastrou) {
                $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
                #Se encontrar solicitações de transferencia externa (com data de transferencia sem codigo de matricula de entrada), inativa estas
                /*$lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL,
                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL,
                          $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, TRUE, FALSE);
                
                        if (is_array($lst_transferencia)) {
                          echo 'Encontrou solicitações de transferencia externa (saida) com data de transferencia';
                          $det_transferencia = array_shift($lst_transferencia);
                
                          $obj_transferencia = new clsPmieducarTransferenciaSolicitacao(
                            $det_transferencia['cod_transferencia_solicitacao'], NULL,
                            $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, NULL, 0);
                
                          $editou2 = $obj_transferencia->edita();
                
                          if ($editou2) {
                            $obj = new clsPmieducarMatricula($det_transferencia['ref_cod_matricula_saida'],
                              NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, 4, NULL, NULL, 1, NULL, 0);
                
                            $editou3 = $obj->edita();
                
                            if (! $editou3) {
                              $this->mensagem = 'Edição não realizada.<br />';
                              return FALSE;
                            }
                          }
                          else {
                            $this->mensagem = 'Edição não realizada.<br />';
                            return FALSE;
                          }
                        }
                        #senão pega as solicitacoes de transferencia internas (sem data de transferencia e sem codigo de matricula de entrada) e
                        #seta a data de transferencia e codigo de matricula de entrada, atualiza a situacao da matricula para transferido e inativa a matricula turma
                        else {
                        */
                $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
                $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, FALSE, FALSE);
                #TODO interna ?
                // Verifica se existe solicitação de transferência (interna) do aluno
                if (is_array($lst_transferencia)) {
                    #echo 'Encontrou solicitações de transferencia interna  (saida) com data de transferencia';
                    // Verifica cada solicitação de transferência do aluno
                    foreach ($lst_transferencia as $transferencia) {
                        $obj_matricula = new clsPmieducarMatricula($transferencia['ref_cod_matricula_saida']);
                        $det_matricula = $obj_matricula->detalhe();
                        // Se a matrícula anterior estava em andamento, copia as notas/faltas/pareceres
                        if ($det_matricula['aprovado'] == 3) {
                            $db->Consulta(" SELECT modules.copia_notas_transf({$det_matricula['cod_matricula']},{$cod_matricula})");
                        }
                        // Caso a solicitação seja para uma mesma série
                        if ($det_matricula['ref_ref_cod_serie'] == $this->ref_cod_serie) {
                            $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                            break;
                        } else {
                            $obj_sequencia = new clsPmieducarSequenciaSerie($det_matricula['ref_ref_cod_serie'], $this->ref_cod_serie, NULL, NULL, NULL, NULL, 1);
                            if ($obj_sequencia->existe()) {
                                $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                                break;
                            }
                        }
                        $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                    }
                    if ($ref_cod_transferencia) {
                        $obj_transferencia = new clsPmieducarTransferenciaSolicitacao($ref_cod_transferencia, NULL, $this->pessoa_logada, NULL, $cadastrou, NULL, NULL, NULL, NULL, 1, date('Y-m-d'));
                        $editou2 = $obj_transferencia->edita();
                        if ($editou2) {
                            $obj_transferencia = new clsPmieducarTransferenciaSolicitacao($ref_cod_transferencia);
                            $det_transferencia = $obj_transferencia->detalhe();
                            $matricula_saida = $det_transferencia['ref_cod_matricula_saida'];
                            $obj_matricula = new clsPmieducarMatricula($matricula_saida);
                            $det_matricula = $obj_matricula->detalhe();
                            // Caso a situação da matrícula do aluno esteja em andamento
                            if ($det_matricula['aprovado'] == 3) {
                                $obj_matricula = new clsPmieducarMatricula($cadastrou, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $det_matricula['modulo']);
                                if ($obj_matricula->edita() && !$this->desativaEnturmacoesMatricula($matricula_saida)) {
                                    return false;
                                }
                            }
                            $obj = new clsPmieducarMatricula($matricula_saida, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, 4, NULL, NULL, 1, NULL, 0);
                            $editou3 = $obj->edita();
                            if (!$editou3) {
                                $this->mensagem = 'Edição não realizada.<br />';
                                return FALSE;
                            }
                        } else {
                            $this->mensagem = 'Edição não realizada.<br />';
                            return FALSE;
                        }
                    }
                }
                //}
                #TODO set in $_SESSION['flash'] 'Aluno matriculado com sucesso'
                $this->mensagem .= 'Cadastro efetuado com sucesso.<br />';
                header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
                #die();
                #return true;
            }
            $this->mensagem = 'Cadastro não realizado.<br />';
            return FALSE;
        } else {
            $this->mensagem = 'O ano (letivo) selecionado não esta em andamento na escola selecionada.<br />';
            return FALSE;
        }
    }
 /**
  * Sobrescreve clsListagem::Gerar().
  * @see clsListagem::Gerar()
  */
 function Gerar()
 {
     session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $this->titulo = 'Vagas Reservadas - Listagem';
     // Passa todos os valores obtidos no GET para atributos do objeto
     foreach ($_GET as $var => $val) {
         $this->{$var} = $val === '' ? NULL : $val;
     }
     $lista_busca = array('Aluno', 'S&eacute;rie', 'Curso');
     // Recupera ní­vel de acesso do usuário logado
     $obj_permissao = new clsPermissoes();
     $nivel_usuario = $obj_permissao->nivel_acesso($this->pessoa_logada);
     if ($nivel_usuario == 1) {
         $lista_busca[] = 'Escola';
         $lista_busca[] = 'Institui&ccedil;&atilde;o';
     } elseif ($nivel_usuario == 2) {
         $lista_busca[] = 'Escola';
     }
     $this->addCabecalhos($lista_busca);
     // Lista de opçõees para o formulário de pesquisa rápida
     $get_escola = TRUE;
     $get_curso = TRUE;
     $get_escola_curso_serie = TRUE;
     include 'include/pmieducar/educar_campo_lista.php';
     // Referência de escola
     if ($this->ref_cod_escola) {
         $this->ref_ref_cod_escola = $this->ref_cod_escola;
     } elseif (isset($_GET['ref_cod_escola'])) {
         $this->ref_ref_cod_escola = intval($_GET['ref_cod_escola']);
     }
     // Referência de série
     if ($this->ref_cod_serie) {
         $this->ref_ref_cod_serie = $this->ref_cod_serie;
     } elseif (isset($_GET['ref_cod_serie'])) {
         $this->ref_ref_cod_serie = intval($_GET['ref_cod_serie']);
     }
     // Campos do formulário
     $this->campoTexto('nm_aluno', 'Aluno', $this->nm_aluno, 30, 255, FALSE, FALSE, FALSE, '', '<img border="0" onclick="pesquisa_aluno();" id="ref_cod_aluno_lupa" name="ref_cod_aluno_lupa" src="imagens/lupa.png" />');
     // Código do aluno (retornado de pop-up de busca da pesquisa de alunos - lupa)
     $this->campoOculto('ref_cod_aluno', $this->ref_cod_aluno);
     // Paginador
     $this->limite = 20;
     $this->offset = $_GET["pagina_{$this->nome}"] ? $_GET["pagina_{$this->nome}"] * $this->limite - $this->limite : 0;
     // Instância objeto de mapeamento relacional com o tabela pmieducar.reserva_vaga
     $obj_reserva_vaga = new clsPmieducarReservaVaga();
     $obj_reserva_vaga->setOrderby('data_cadastro ASC');
     $obj_reserva_vaga->setLimite($this->limite, $this->offset);
     // Lista os registros usando os valores passados pelos filtros
     $lista = $obj_reserva_vaga->lista($this->cod_reserva_vaga, $this->ref_ref_cod_escola, $this->ref_ref_cod_serie, NULL, NULL, $this->ref_cod_aluno, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao, $this->ref_cod_curso);
     // Pega o total de registros encontrados
     $total = $obj_reserva_vaga->_total;
     // Itera sobre resultados montando a lista de apresentação
     if (is_array($lista) && count($lista)) {
         foreach ($lista as $registro) {
             // Recupera nome da série da reserva de vaga
             $obj_serie = new clsPmieducarSerie($registro['ref_ref_cod_serie']);
             $det_serie = $obj_serie->detalhe();
             $nm_serie = $det_serie['nm_serie'];
             // Recupera o nome do curso da reserva de vaga
             $obj_curso = new clsPmieducarCurso($registro['ref_cod_curso']);
             $det_curso = $obj_curso->detalhe();
             $registro['ref_cod_curso'] = $det_curso['nm_curso'];
             // Recupera o nome da escola da reserva de vaga
             $obj_escola = new clsPmieducarEscola($registro['ref_ref_cod_escola']);
             $det_escola = $obj_escola->detalhe();
             $nm_escola = $det_escola['nome'];
             // Recupera o nome da instituição da reserva de vaga
             $obj_ref_cod_instituicao = new clsPmieducarInstituicao($registro['ref_cod_instituicao']);
             $det_ref_cod_instituicao = $obj_ref_cod_instituicao->detalhe();
             $registro['ref_cod_instituicao'] = $det_ref_cod_instituicao['nm_instituicao'];
             /*
              * Se for um aluno previamente cadastrado, procuramos seu nome, primeiro
              * buscando a referência de Pessoa e depois pesquisando a tabela para
              * carregar o nome
              */
             if ($registro['ref_cod_aluno']) {
                 // Pesquisa por aluno para pegar o identificador de Pessoa
                 $obj_aluno = new clsPmieducarAluno($registro['ref_cod_aluno']);
                 $det_aluno = $obj_aluno->detalhe();
                 $ref_idpes = $det_aluno['ref_idpes'];
                 // Pesquisa a tabela de pessoa para recuperar o nome
                 $obj_pessoa = new clsPessoa_($ref_idpes);
                 $det_pessoa = $obj_pessoa->detalhe();
                 $registro['ref_cod_aluno'] = $det_pessoa['nome'];
             } else {
                 $registro['ref_cod_aluno'] = $registro['nm_aluno'] . ' (aluno externo)';
             }
             // Array de dados formatados para apresentação
             $lista_busca = array("<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$registro["ref_cod_aluno"]}</a>", "<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$nm_serie}</a>", "<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$registro["ref_cod_curso"]}</a>");
             // Verifica por permissões
             if ($nivel_usuario == 1) {
                 $lista_busca[] = "<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$nm_escola}</a>";
                 $lista_busca[] = "<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$registro["ref_cod_instituicao"]}</a>";
             } elseif ($nivel_usuario == 2) {
                 $lista_busca[] = "<a href=\"educar_reservada_vaga_det.php?cod_reserva_vaga={$registro["cod_reserva_vaga"]}\">{$nm_escola}</a>";
             }
             $this->addLinhas($lista_busca);
         }
     }
     $this->addPaginador2('educar_reservada_vaga_lst.php', $total, $_GET, $this->nome, $this->limite);
     $this->largura = '100%';
     $localizacao = new LocalizacaoSistema();
     $localizacao->entradaCaminhos(array($_SERVER['SERVER_NAME'] . "/intranet" => "In&iacute;cio", "educar_index.php" => "i-Educar - Escola", "" => "Listagem de vagas reservadas"));
     $this->enviaLocalizacao($localizacao->montar());
 }
 function Gerar()
 {
     session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $this->titulo = 'Reserva Vaga - Detalhe';
     $this->addBanner('imagens/nvp_top_intranet.jpg', 'imagens/nvp_vert_intranet.jpg', 'Intranet');
     $this->ref_cod_serie = $_GET['ref_cod_serie'];
     $this->ref_cod_escola = $_GET['ref_cod_escola'];
     $tmp_obj = new clsPmieducarEscolaSerie();
     $lst_obj = $tmp_obj->lista($this->ref_cod_escola, $this->ref_cod_serie);
     $registro = array_shift($lst_obj);
     if (!$registro) {
         header('Location: educar_reserva_vaga_lst.php');
         die;
     }
     // Instituição
     $obj_ref_cod_instituicao = new clsPmieducarInstituicao($registro['ref_cod_instituicao']);
     $det_ref_cod_instituicao = $obj_ref_cod_instituicao->detalhe();
     $registro['ref_cod_instituicao'] = $det_ref_cod_instituicao['nm_instituicao'];
     // Escola
     $obj_ref_cod_escola = new clsPmieducarEscola($registro['ref_cod_escola']);
     $det_ref_cod_escola = $obj_ref_cod_escola->detalhe();
     $nm_escola = $det_ref_cod_escola['nome'];
     // Série
     $obj_ref_cod_serie = new clsPmieducarSerie($registro['ref_cod_serie']);
     $det_ref_cod_serie = $obj_ref_cod_serie->detalhe();
     $nm_serie = $det_ref_cod_serie['nm_serie'];
     // Curso
     $obj_curso = new clsPmieducarCurso($registro['ref_cod_curso']);
     $det_curso = $obj_curso->detalhe();
     $registro['ref_cod_curso'] = $det_curso['nm_curso'];
     // Matrícula
     $obj_matricula = new clsPmieducarMatricula();
     $lst_matricula = $obj_matricula->lista(NULL, NULL, $registro['ref_cod_escola'], $registro['ref_cod_serie'], NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1);
     if (is_array($lst_matricula)) {
         $matriculados = count($lst_matricula);
     }
     // Detalhes da reserva
     $obj_reserva_vaga = new clsPmieducarReservaVaga();
     $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $registro['ref_cod_escola'], $registro['ref_cod_serie'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     if (is_array($lst_reserva_vaga)) {
         $reservados = count($lst_reserva_vaga);
     }
     // Permissões
     $obj_permissao = new clsPermissoes();
     $nivel_usuario = $obj_permissao->nivel_acesso($this->pessoa_logada);
     if ($nivel_usuario == 1) {
         if ($registro['ref_cod_instituicao']) {
             $this->addDetalhe(array('Institui&ccedil;&atilde;o', $registro['ref_cod_instituicao']));
         }
     }
     if ($nivel_usuario == 1 || $nivel_usuario == 2) {
         if ($nm_escola) {
             $this->addDetalhe(array('Escola', $nm_escola));
         }
     }
     if ($registro['ref_cod_curso']) {
         $this->addDetalhe(array('Curso', $registro['ref_cod_curso']));
     }
     if ($nm_serie) {
         $this->addDetalhe(array('S&eacute;rie', $nm_serie));
     }
     $obj_turmas = new clsPmieducarTurma();
     $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_cod_serie, $this->ref_cod_escola, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     if (is_array($lst_turmas)) {
         $cont = 0;
         $total_vagas = 0;
         $html = "\n        <table width='50%' cellspacing='0' cellpadding='0' border='0'>\n          <tr>\n            <td bgcolor=#A1B3BD>Nome</td>\n            <td bgcolor=#A1B3BD>N&uacute;mero Vagas</td>\n          </tr>";
         foreach ($lst_turmas as $turmas) {
             $total_vagas += $turmas['max_aluno'];
             if ($cont % 2 == 0) {
                 $class = ' formmdtd ';
             } else {
                 $class = ' formlttd ';
             }
             $cont++;
             $html .= "\n          <tr>\n            <td class={$class} width='35%'>{$turmas["nm_turma"]}</td>\n            <td class={$class} width='15%'>{$turmas["max_aluno"]}</td>\n          </tr>";
         }
         $html .= '</tr></table>';
         $this->addDetalhe(array('Turma', $html));
         if ($total_vagas) {
             $this->addDetalhe(array('Total Vagas', $total_vagas));
         }
         if ($matriculados) {
             $this->addDetalhe(array('Matriculados', $matriculados));
         }
         if ($reservados) {
             $this->addDetalhe(array('Reservados', $reservados));
         }
         $vagas_restantes = $total_vagas - ($matriculados + $reservados);
         $this->addDetalhe(array('Vagas Restantes', $vagas_restantes));
     }
     if ($obj_permissao->permissao_cadastra(639, $this->pessoa_logada, 7)) {
         $this->array_botao = array('Reservar Vaga', 'Vagas Reservadas');
         $this->array_botao_url = array("educar_reserva_vaga_cad.php?ref_cod_escola={$registro["ref_cod_escola"]}&ref_cod_serie={$registro["ref_cod_serie"]}", 'educar_reservada_vaga_lst.php?ref_cod_escola=' . $registro['ref_cod_escola'] . '&ref_cod_serie=' . $registro['ref_cod_serie']);
     }
     $this->url_cancelar = 'educar_reserva_vaga_lst.php';
     $this->largura = '100%';
 }
 /**
  * Desativa o pedido de reserva de vaga.
  * @return bool Retorna FALSE em caso de erro
  */
 private function _desativar()
 {
     $obj = new clsPmieducarReservaVaga($this->cod_reserva_vaga, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, 0);
     $excluiu = $obj->excluir();
     if ($excluiu) {
         $this->mensagem .= 'Exclus&atilde;o efetuada com sucesso.<br>';
         header('Location: educar_reservada_vaga_lst.php?ref_cod_escola=' . $this->ref_cod_escola . '&ref_cod_serie=' . $this->ref_cod_serie);
         die;
     }
     $this->mensagem = 'Exclus&atilde;o n&atilde;o realizada.<br>';
     return FALSE;
 }
 /**
  * Sobrescreve clsCadastro::renderHTML().
  * @see clsCadastro::renderHTML()
  */
 function renderHTML()
 {
     $ok = FALSE;
     $obj_reserva_vaga = new clsPmieducarReservaVaga();
     $this->cod_reserva_vaga = $_GET['cod_reserva_vaga'];
     $lst_reserva_vaga = $obj_reserva_vaga->lista($this->cod_reserva_vaga);
     $registro = array_shift($lst_reserva_vaga);
     if (is_numeric($_GET['cod_reserva_vaga']) && is_array($registro)) {
         $this->data_solicitacao = $registro['data_cadastro'];
         $ok = TRUE;
     }
     if (!$ok) {
         echo "<script>alert('Não é possível gerar documento para reserva de vaga para esta matrícula');window.location='educar_index.php';</script>";
         die('Não é possível gerar documento para reserva de vaga para esta matrícula');
     }
     // Nome do aluno
     if ($registro['nm_aluno']) {
         $this->nm_aluno = $registro['nm_aluno'];
     } elseif ($registro['ref_cod_aluno']) {
         $obj_aluno = new clsPmieducarAluno();
         $det_aluno = array_shift($obj_aluno->lista($registro['ref_cod_aluno']));
         $this->nm_aluno = $det_aluno['nome_aluno'];
     }
     // Nome da escola
     $obj_escola = new clsPmieducarEscola($registro['ref_ref_cod_escola']);
     $det_escola = $obj_escola->detalhe();
     $this->nm_escola = $det_escola['nome'];
     // Cidade da escola
     $escolaComplemento = new clsPmieducarEscolaComplemento($registro['ref_ref_cod_escola']);
     $escolaComplemento = $escolaComplemento->detalhe();
     $this->escola_municipio = $escolaComplemento['municipio'];
     // Nome da série
     $obj_serie = new clsPmieducarSerie($registro['ref_ref_cod_serie']);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     // Nome do curso
     $obj_curso = new clsPmieducarCurso($registro['ref_cod_curso']);
     $det_curso = $obj_curso->detalhe();
     $this->nm_curso = $det_curso['nm_curso'];
     $fonte = 'arial';
     $corTexto = '#000000';
     $this->pdf = new clsPDF('Diário de Classe - ' . $this->ano, "Diário de Classe - {$this->meses_do_ano[$this->mes]} e {$this->meses_do_ano[$prox_mes]} de {$this->ano}", 'A4', '', FALSE, FALSE);
     $this->pdf->OpenPage();
     $this->addCabecalho();
     // Título
     $this->pdf->escreve_relativo('Reserva de Vaga', 30, 220, 535, 80, $fonte, 16, $corTexto, 'justify');
     $texto = "Atesto para os devidos fins que o aluno {$this->nm_aluno}, solicitou reserva de vaga na escola {$this->nm_escola}, para o curso {$this->nm_curso}, na série {$this->nm_serie} e que a mesma possui a validade de 48 horas a partir da data de solicitação da mesma, " . dataFromPgToBr($this->data_solicitacao) . ".";
     $this->pdf->escreve_relativo($texto, 30, 350, 535, 80, $fonte, 14, $corTexto, 'center');
     $mes = date('n');
     $mes = strtolower($this->meses_do_ano["{$mes}"]);
     $data = date('d') . " de {$mes} de " . date('Y');
     $this->pdf->escreve_relativo($this->escola_municipio . ', ' . $data, 30, 600, 535, 80, $fonte, 14, $corTexto, 'center');
     $this->rodape();
     $this->pdf->CloseFile();
     $this->get_link = $this->pdf->GetLink();
     echo "<script>window.onload=function(){parent.EscondeDiv('LoadImprimir');window.location='download.php?filename=" . $this->get_link . "'}</script>";
     echo "\n      <center><a target='blank' href='" . $this->get_link . "' style='font-size: 16px; color: #000000; text-decoration: underline;'>Clique aqui para visualizar o arquivo!</a><br><br>\n        <span style='font-size: 10px;'>Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>\n          Clique na Imagem para Baixar o instalador<br><br>\n          <a href=\"http://www.adobe.com.br/products/acrobat/readstep2.html\" target=\"new\"><br><img src=\"imagens/acrobat.gif\" width=\"88\" height=\"31\" border=\"0\"></a>\n        </span>\n      </center>";
     return;
 }
    function Novo()
    {
        @session_start();
        $this->pessoa_logada = $_SESSION['id_pessoa'];
        @session_write_close();
        $obj_permissoes = new clsPermissoes();
        $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
        $obj_escola_ano_letivo = new clsPmieducarEscolaAnoLetivo();
        $lst_escola_ano_letivo = $obj_escola_ano_letivo->lista($this->ref_cod_escola, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, 1);
        if (is_array($lst_escola_ano_letivo)) {
            $det_escola_ano_letivo = array_shift($lst_escola_ano_letivo);
            $this->ano = $det_escola_ano_letivo['ano'];
            $obj_reserva_vaga = new clsPmieducarReservaVaga();
            $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL, NULL, $this->ref_cod_aluno, NULL, NULL, NULL, NULL, 1);
            // Verifica se existe reserva de vaga para o aluno
            if (is_array($lst_reserva_vaga)) {
                $det_reserva_vaga = array_shift($lst_reserva_vaga);
                $this->ref_cod_reserva_vaga = $det_reserva_vaga['cod_reserva_vaga'];
                $obj_reserva_vaga = new clsPmieducarReservaVaga($this->ref_cod_reserva_vaga, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, 0);
                $editou = $obj_reserva_vaga->edita();
                if (!$editou) {
                    $this->mensagem = 'Edição não realizada.<br />';
                    return FALSE;
                }
            }
            $vagas_restantes = 1;
            if (!$this->ref_cod_reserva_vaga) {
                $obj_turmas = new clsPmieducarTurma();
                $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_ref_cod_serie, $this->ref_cod_escola, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
                if (is_array($lst_turmas)) {
                    $total_vagas = 0;
                    foreach ($lst_turmas as $turmas) {
                        $total_vagas += $turmas['max_aluno'];
                    }
                } else {
                    $this->mensagem = 'Série não possui turmas cadastradas.<br />';
                    return FALSE;
                }
                $obj_matricula = new clsPmieducarMatricula();
                $lst_matricula = $obj_matricula->lista(NULL, NULL, $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1, $this->ano, $this->ref_cod_curso, $this->ref_cod_instituicao, 1);
                if (is_array($lst_matricula)) {
                    $matriculados = count($lst_matricula);
                }
                $obj_reserva_vaga = new clsPmieducarReservaVaga();
                $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao, $this->ref_cod_curso);
                if (is_array($lst_reserva_vaga)) {
                    $reservados = count($lst_reserva_vaga);
                }
                $vagas_restantes = $total_vagas - ($matriculados + $reservados);
            }
            if ($vagas_restantes <= 0) {
                echo sprintf('
          <script>
            var msg = \'\';
            msg += \'Excedido o número de total de vagas para Matricula!\\n\';
            msg += \'Número total de matriculados: %d\\n\';
            msg += \'Número total de vagas reservadas: %d\\n\';
            msg += \'Número total de vagas: %d\\n\';
            msg += \'Deseja mesmo assim realizar a Matrícula?\';

            if (! confirm(msg)) {
              window.location = \'educar_matricula_lst.php?ref_cod_aluno=%d\';
            }
          </script>', $matriculados, $reservados, $total_vagas, $this->ref_cod_aluno);
            }
            $obj_matricula_aluno = new clsPmieducarMatricula();
            $lst_matricula_aluno = $obj_matricula_aluno->lista(NULL, NULL, NULL, NULL, NULL, NULL, $this->ref_cod_aluno);
            if (!$lst_matricula_aluno) {
                // Primeira matrícula do sistema, consistência (?)
                $this->matricula_transferencia = $this->matricula_transferencia == 'on' ? TRUE : FALSE;
            } else {
                $this->matricula_transferencia = FALSE;
            }
            if ($this->is_padrao == 1) {
                $this->semestre = NULL;
            }
            $obj = new clsPmieducarMatricula(NULL, $this->ref_cod_reserva_vaga, $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL, $this->pessoa_logada, $this->ref_cod_aluno, 3, NULL, NULL, 1, $this->ano, 1, NULL, NULL, NULL, NULL, $this->ref_cod_curso, $this->matricula_transferencia, $this->semestre);
            $cadastrou = $obj->cadastra();
            if ($cadastrou) {
                $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
                $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, TRUE, FALSE);
                // Verifica se existe solicitação de transferência de aluno
                if (is_array($lst_transferencia)) {
                    $det_transferencia = array_shift($lst_transferencia);
                    $obj_transferencia = new clsPmieducarTransferenciaSolicitacao($det_transferencia['cod_transferencia_solicitacao'], NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, NULL, 0);
                    $editou2 = $obj_transferencia->edita();
                    if ($editou2) {
                        $obj = new clsPmieducarMatricula($det_transferencia['ref_cod_matricula_saida'], NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, 4, NULL, NULL, 1, NULL, 0);
                        $editou3 = $obj->edita();
                        if (!$editou3) {
                            $this->mensagem = 'Edição não realizada.<br />';
                            return FALSE;
                        }
                    } else {
                        $this->mensagem = 'Edição não realizada.<br />';
                        return FALSE;
                    }
                } else {
                    $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
                    $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, FALSE, FALSE);
                    // Verifica se existe solicitação de transferência do aluno
                    if (is_array($lst_transferencia)) {
                        // Verifica cada solicitação de transferência do aluno
                        foreach ($lst_transferencia as $transferencia) {
                            $obj_matricula = new clsPmieducarMatricula($transferencia['ref_cod_matricula_saida']);
                            $det_matricula = $obj_matricula->detalhe();
                            // Caso a solicitação seja para uma mesma série
                            if ($det_matricula['ref_ref_cod_serie'] == $this->ref_ref_cod_serie) {
                                $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                                break;
                            } else {
                                $obj_sequencia = new clsPmieducarSequenciaSerie($det_matricula['ref_ref_cod_serie'], $this->ref_ref_cod_serie, NULL, NULL, NULL, NULL, 1);
                                if ($obj_sequencia->existe()) {
                                    $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                                    break;
                                }
                            }
                            $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
                        }
                        if ($ref_cod_transferencia) {
                            $obj_transferencia = new clsPmieducarTransferenciaSolicitacao($ref_cod_transferencia, NULL, $this->pessoa_logada, NULL, $cadastrou, NULL, NULL, NULL, NULL, 1, date('Y-m-d'));
                            $editou2 = $obj_transferencia->edita();
                            if ($editou2) {
                                $obj_transferencia = new clsPmieducarTransferenciaSolicitacao($ref_cod_transferencia);
                                $det_transferencia = $obj_transferencia->detalhe();
                                $matricula_saida = $det_transferencia['ref_cod_matricula_saida'];
                                $obj_matricula = new clsPmieducarMatricula($matricula_saida);
                                $det_matricula = $obj_matricula->detalhe();
                                // Caso a situação da matrícula do aluno esteja em andamento
                                if ($det_matricula['aprovado'] == 3) {
                                    $obj_matricula = new clsPmieducarMatricula($cadastrou, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $det_matricula['modulo']);
                                    $editou_mat = $obj_matricula->edita();
                                    if ($editou_mat) {
                                        $obj_matricula_turma = new clsPmieducarMatriculaTurma();
                                        $lst_matricula_turma = $obj_matricula_turma->lista($matricula_saida, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
                                        if (is_array($lst_matricula_turma)) {
                                            $det_matricula_turma = array_shift($lst_matricula_turma);
                                            $obj_matricula_turma = new clsPmieducarMatriculaTurma($matricula_saida, $det_matricula_turma['ref_cod_turma'], $this->pessoa_logada, NULL, NULL, NULL, 0, NULL, $det_matricula_turma['sequencial']);
                                            $editou_mat_turma = $obj_matricula_turma->edita();
                                            if (!$editou_mat_turma) {
                                                $this->mensagem = 'Não foi possível editar a Matrícula Turma.<br />';
                                                return FALSE;
                                            }
                                        }
                                    }
                                }
                                $obj = new clsPmieducarMatricula($matricula_saida, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, 4, NULL, NULL, 1, NULL, 0);
                                $editou3 = $obj->edita();
                                if (!$editou3) {
                                    $this->mensagem = 'Edição não realizada.<br />';
                                    return FALSE;
                                }
                            } else {
                                $this->mensagem = 'Edição não realizada.<br />';
                                return FALSE;
                            }
                        }
                    }
                }
                $this->mensagem .= 'Cadastro efetuado com sucesso.<br />';
                header('Location: educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
                die;
            }
            $this->mensagem = 'Cadastro não realizado.<br />';
            return FALSE;
        } else {
            $this->mensagem = 'Não foi possível encontrar o "Ano Letivo" em andamento da Escola.<br />';
            return FALSE;
        }
    }