function Excluir()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     @session_write_close();
     $obj_permissoes = new clsPermissoes();
     $obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7, 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
     if (!$this->desativaEnturmacoesMatricula($this->cod_matricula)) {
         return false;
     }
     $obj_matricula = new clsPmieducarMatricula($this->cod_matricula);
     $det_matricula = $obj_matricula->detalhe();
     $ref_cod_serie = $det_matricula['ref_ref_cod_serie'];
     $obj_sequencia = new clsPmieducarSequenciaSerie();
     $lst_sequencia = $obj_sequencia->lista(NULL, $ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     // Coloca as matrículas anteriores em andamento
     $obj_transferencia_antiga = new clsPmieducarTransferenciaSolicitacao();
     $lista_transferencia = $obj_transferencia_antiga->lista(null, null, null, null, null, $this->cod_matricula);
     if (is_array($lista_transferencia)) {
         foreach ($lista_transferencia as $transf) {
             $obj_mat = new clsPmieducarMatricula($transf['ref_cod_matricula_saida']);
             $obj_mat = $obj_mat->detalhe();
             if ($obj_mat['aprovado'] == 4) {
                 $obj_mat = new clsPmieducarMatricula($transf['ref_cod_matricula_saida'], null, null, null, $this->pessoa_logada, null, null, 3);
                 $obj_mat->edita();
                 $obj_transf = new clsPmieducarTransferenciaSolicitacao($transf['cod_transferencia_solicitacao']);
                 $obj_transf->desativaEntradaTransferencia();
             }
         }
     }
     // Verifica se a série da matrícula cancelada é sequência de alguma outra série
     if (is_array($lst_sequencia)) {
         $det_sequencia = array_shift($lst_sequencia);
         $ref_serie_origem = $det_sequencia['ref_serie_origem'];
         $obj_matricula = new clsPmieducarMatricula();
         $lst_matricula = $obj_matricula->lista(NULL, NULL, NULL, $ref_serie_origem, NULL, NULL, $this->ref_cod_aluno, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0);
         // Verifica se o aluno tem matrícula na série encontrada
         if (is_array($lst_matricula)) {
             $det_matricula = array_shift($lst_matricula);
             $ref_cod_matricula = $det_matricula['cod_matricula'];
             $obj = new clsPmieducarMatricula($ref_cod_matricula, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, 1, NULL, 1);
             $editou1 = $obj->edita();
             if (!$editou1) {
                 $this->mensagem = 'Não foi possível editar a "Última Matrícula da Sequência".<br />';
                 return FALSE;
             }
         }
     }
     $obj = new clsPmieducarMatricula($this->cod_matricula, NULL, NULL, NULL, $this->pessoa_logada, NULL, NULL, NULL, NULL, NULL, 0);
     $excluiu = $obj->excluir();
     if ($excluiu) {
         $this->mensagem .= 'Exclusão efetuada com sucesso.<br />';
         header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
         die;
     }
     $this->mensagem = 'Exclusão não realizada.<br />';
     return FALSE;
 }
 function Excluir()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     @session_write_close();
     $obj_permissoes = new clsPermissoes();
     $obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7, "educar_matricula_det.php?cod_matricula={$this->ref_cod_matricula}");
     $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
     $lst_transferencia = $obj_transferencia->lista(null, null, null, null, null, $this->ref_cod_matricula, null, null, null, null, null, 1, null, null, $this->ref_cod_aluno, false);
     if (is_array($lst_transferencia)) {
         $det_transferencia = array_shift($lst_transferencia);
         $this->cod_transferencia_solicitacao = $det_transferencia["cod_transferencia_solicitacao"];
         $obj = new clsPmieducarTransferenciaSolicitacao($this->cod_transferencia_solicitacao, null, $this->pessoa_logada, null, null, null, null, null, null, 0);
         $excluiu = $obj->excluir();
         if ($excluiu) {
             $this->mensagem .= "Exclus&atilde;o efetuada com sucesso.<br>";
             header("Location: educar_matricula_det.php?cod_matricula={$this->ref_cod_matricula}");
             die;
             return true;
         }
     } else {
         $this->mensagem = "N&atilde;o foi poss&iacute;vel encontrar a Solicita&ccedil;&atilde;o de Transfer&ecirc;ncia do Aluno.<br>";
         return false;
     }
     $this->mensagem = "Exclus&atilde;o n&atilde;o realizada.<br>";
     echo "<!--\nErro ao excluir clsPmieducarTransferenciaSolicitacao\nvalores obrigatorios\nif( is_numeric( {$this->cod_transferencia_solicitacao} ) && is_numeric( {$this->pessoa_logada} ) )\n-->";
     return false;
 }
 function renderHTML()
 {
     $ok = false;
     if (is_numeric($_GET['cod_matricula'])) {
         $this->ref_cod_matricula = $_GET['cod_matricula'];
         $obj_mat = new clsPmieducarMatricula($this->ref_cod_matricula);
         $det_matricula = $obj_mat->detalhe();
         $this->nm_aluno = $det_matricula['nome_upper'];
         if ($det_matricula['aprovado'] == 4) {
             $ok = true;
         }
         $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
         $lst_transferencia = $obj_transferencia->lista(null, null, null, null, null, $this->ref_cod_matricula, null, null, null, null, null, 1, null, null, $det_matricula['ref_cod_aluno'], false);
         // verifica se existe uma solicitacao de transferencia INTERNA
         if (is_array($lst_transferencia)) {
             $ok = true;
         }
     }
     if (!$ok) {
         echo "<script>alert('Não é possível gerar atestado de freqüência para esta matrícula');window.location='educar_index.php';</script>";
         die('Não é possível gerar atestado de freqüência para esta matrícula');
     }
     $obj_curso = new clsPmieducarCurso($det_matricula['ref_cod_curso']);
     $det_curso = $obj_curso->detalhe();
     $obj_serie = new clsPmieducarSerie($det_matricula['ref_ref_cod_serie']);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     $obj_instituicao = new clsPmieducarInstituicao($det_curso['ref_cod_instituicao']);
     $det_instituicao = $obj_instituicao->detalhe();
     $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     $obj_escola = new clsPmieducarEscola($det_matricula['ref_ref_cod_escola']);
     $det_escola = $obj_escola->detalhe();
     $this->nm_escola = $det_escola['nome'];
     $this->ref_cod_escola = $det_escola['cod_escola'];
     $obj_nivel_ensino = new clsPmieducarNivelEnsino($det_curso['ref_cod_nivel_ensino']);
     $det_nivel_ensino = $obj_nivel_ensino->detalhe();
     $this->nm_ensino = $det_nivel_ensino['nm_nivel'];
     $fonte = 'arial';
     $corTexto = '#000000';
     $this->pdf = new clsPDF("Atestado de Frequência - {$this->ano}", "Atestado de Frequência", "A4", "", false, false);
     $this->pdf->OpenPage();
     $obj_escola_complemento = new clsPmieducarEscolaComplemento($this->ref_cod_escola);
     $det_escola_complemento = $obj_escola_complemento->detalhe();
     if ($det_escola_complemento) {
         // NOME DA ESCOLA
         $nm_escola = str2upper($det_escola_complemento['nm_escola']);
         // ENDERECO DA ESCOLA
         $logradouro = str2upper($det_escola_complemento['logradouro']);
         $numero = $det_escola_complemento['numero'];
         $complemento = str2upper($det_escola_complemento['complemento']);
         $bairro = str2upper($det_escola_complemento['bairro']);
         $municipio = str2upper($det_escola_complemento['municipio']);
         $cep = $det_escola_complemento['cep'];
         $cep = int2CEP($cep);
         $this->endereco = "{$logradouro} {$complemento},{$numero} CEP {$cep} {$municipio}";
     } else {
         $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
         $det_escola = $obj_escola->detalhe();
         $obj_juridica = new clsJuridica($det_escola['ref_idpes']);
         $det_juridica = $obj_juridica->detalhe();
         $nm_escola = $det_juridica['fantasia'];
         if (!$nm_escola) {
             if ($det_escola['ref_idpes']) {
                 $obj_pessoa_ = new clsPessoa_($det_escola['ref_idpes']);
                 $det_pessoa_ = $obj_pessoa_->detalhe();
                 $nm_escola = $det_pessoa_['nome'];
             }
         }
         $this->nm_escola = $nm_escola;
         $obj_endereco = new clsPessoaEndereco($det_escola["ref_idpes"]);
         if ($det_escola["ref_idpes"]) {
             $tipo = 1;
             $endereco_lst = $obj_endereco->lista($det_escola["ref_idpes"]);
             if ($endereco_lst) {
                 foreach ($endereco_lst as $endereco) {
                     $cep = $endereco["cep"]->cep;
                     $idlog = $endereco["idlog"]->idlog;
                     $obj = new clsLogradouro($idlog);
                     $obj_det = $obj->detalhe();
                     $logradouro = $obj_det["nome"];
                     $idtlog = $obj_det["idtlog"]->detalhe();
                     $tipo_logradouro = strtoupper($idtlog["descricao"]);
                     $bairro = $idbai = $endereco["idbai"]->detalhe();
                     $idbai = $idbai['nome'];
                     $numero = $endereco["numero"];
                     $complemento = $endereco["complemento"];
                     $andar = $endereco["andar"];
                 }
                 $obj_log = new clsLogradouro($idlog);
                 $obj_log_det = $obj_log->detalhe();
                 if ($obj_log_det) {
                     $logradouro = str2upper($obj_log_det["nome"]);
                     $obj_mun = new clsMunicipio($obj_log_det["idmun"]);
                     $det_mun = $obj_mun->detalhe();
                     if ($det_mun) {
                         $municipio = str2upper($det_mun["nome"]);
                     }
                     $estado = $det_mun['sigla_uf']->sigla_uf;
                 }
                 $cep = int2CEP($cep);
                 $this->endereco = "{$tipo_logradouro} {$logradouro} {$complemento},{$numero} CEP {$cep} {$municipio} {$estado}";
             } else {
                 if (class_exists("clsEnderecoExterno")) {
                     $tipo = 2;
                     $obj_endereco = new clsEnderecoExterno();
                     $endereco_lst = $obj_endereco->lista(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, $det_escola["ref_idpes"]);
                     if ($endereco_lst) {
                         foreach ($endereco_lst as $endereco) {
                             $cep = $endereco["cep"];
                             $estado = $endereco["sigla_uf"]->sigla_uf;
                             $sigla_uf = $endereco["sigla_uf"]->detalhe();
                             $sigla_uf = $sigla_uf["nome"];
                             $cidade = $endereco["cidade"];
                             $idtlog = $endereco["idtlog"]->detalhe();
                             $tipo_logradouro = $idtlog["descricao"];
                             $logradouro = $endereco["logradouro"];
                             $bairro = $endereco["bairro"];
                             $numero = $endereco["numero"];
                             $complemento = $endereco["complemento"];
                             $andar = $endereco["andar"];
                             $municipio = str2upper($endereco['cidade']);
                             $bairro = str2upper($endereco_lst['bairro']);
                         }
                     }
                     $cep = int2CEP($cep);
                     $this->endereco = "{$tipo_logradouro} {$logradouro} {$complemento},{$numero}{$bairro} CEP {$cep} {$municipio} - {$sigla_uf}";
                 }
             }
         }
     }
     $this->addCabecalho();
     //titulo
     $this->pdf->escreve_relativo("Atestado de Freqüência", 30, 220, 535, 80, $fonte, 16, $corTexto, 'center');
     $texto = "Atesto para os devidos fins que o aluno {$this->nm_aluno}, código de aluno nº {$det_matricula['ref_cod_aluno']}, matriculado regularmente no {$this->nm_ensino}, frequentou a {$this->nm_serie} até a presente data.";
     $this->pdf->escreve_relativo($texto, 30, 350, 535, 80, $fonte, 14, $corTexto, 'justify');
     $mes = date('n');
     $mes = strtolower($this->meses_do_ano["{$mes}"]);
     $data = date('d') . " de {$mes} de " . date('Y');
     $this->pdf->escreve_relativo("Brasilia, {$data}", 30, 600, 535, 80, $fonte, 14, $corTexto, 'center');
     $this->rodape();
     $this->pdf->CloseFile();
     $this->get_link = $this->pdf->GetLink();
     //echo "<script>window.location='$this->get_link';</script>";
     //header("location:download.php?filename=".$this->get_link);
     //echo "location:download.php?filename=".$this->get_link;die;
     echo "<script>window.onload=function(){parent.EscondeDiv('LoadImprimir');window.location='download.php?filename=" . $this->get_link . "'}</script>";
     echo "<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\t\t\t<span style='font-size: 10px;'>Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>\n\n\t\t\tClique na Imagem para Baixar o instalador<br><br>\n\t\t\t<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\t\t\t</span>\n\t\t\t</center>";
 }
Example #4
0
 function Gerar()
 {
     // carrega estilo para feedback messages, exibindo msgs da api.
     $style = "/modules/Portabilis/Assets/Stylesheets/Frontend.css";
     Portabilis_View_Helper_Application::loadStylesheet($this, $style);
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $this->titulo = "Matrícula - Detalhe";
     $this->addBanner("imagens/nvp_top_intranet.jpg", "imagens/nvp_vert_intranet.jpg", "Intranet");
     $this->ref_cod_matricula = $_GET["cod_matricula"];
     $obj_matricula = new clsPmieducarMatricula();
     $lst_matricula = $obj_matricula->lista($this->ref_cod_matricula);
     if ($lst_matricula) {
         $registro = array_shift($lst_matricula);
     }
     if (!$registro) {
         header("Location: educar_aluno_det.php?cod_aluno=" . $registro['ref_cod_aluno']);
         die;
     }
     // Curso
     $obj_ref_cod_curso = new clsPmieducarCurso($registro['ref_cod_curso']);
     $det_ref_cod_curso = $obj_ref_cod_curso->detalhe();
     $registro['ref_cod_curso'] = $det_ref_cod_curso['nm_curso'];
     // Série
     $obj_serie = new clsPmieducarSerie($registro['ref_ref_cod_serie']);
     $det_serie = $obj_serie->detalhe();
     $registro['ref_ref_cod_serie'] = $det_serie['nm_serie'];
     // Nome da instituição
     $obj_cod_instituicao = new clsPmieducarInstituicao($registro['ref_cod_instituicao']);
     $obj_cod_instituicao_det = $obj_cod_instituicao->detalhe();
     $registro['ref_cod_instituicao'] = $obj_cod_instituicao_det['nm_instituicao'];
     // Nome da escola
     $obj_ref_cod_escola = new clsPmieducarEscola($registro['ref_ref_cod_escola']);
     $det_ref_cod_escola = $obj_ref_cod_escola->detalhe();
     $registro['ref_ref_cod_escola'] = $det_ref_cod_escola['nome'];
     // Nome do aluno
     $obj_aluno = new clsPmieducarAluno();
     $lst_aluno = $obj_aluno->lista($registro['ref_cod_aluno'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     if (is_array($lst_aluno)) {
         $det_aluno = array_shift($lst_aluno);
         $nm_aluno = $det_aluno['nome_aluno'];
     }
     if ($registro['cod_matricula']) {
         $this->addDetalhe(array('Número Matrícula', $registro['cod_matricula']));
     }
     if ($nm_aluno) {
         $this->addDetalhe(array('Aluno', $nm_aluno));
     }
     if ($registro['ref_cod_instituicao']) {
         $this->addDetalhe(array('Instituição', $registro['ref_cod_instituicao']));
     }
     if ($registro['ref_ref_cod_escola']) {
         $this->addDetalhe(array('Escola', $registro['ref_ref_cod_escola']));
     }
     if ($registro['ref_cod_curso']) {
         $this->addDetalhe(array('Curso', $registro['ref_cod_curso']));
     }
     if ($registro['ref_ref_cod_serie']) {
         $this->addDetalhe(array('Série', $registro['ref_ref_cod_serie']));
     }
     // Nome da turma
     $enturmacoes = new clsPmieducarMatriculaTurma();
     $enturmacoes = $enturmacoes->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     $nomesTurmas = array();
     foreach ($enturmacoes as $enturmacao) {
         $turma = new clsPmieducarTurma($enturmacao['ref_cod_turma']);
         $turma = $turma->detalhe();
         $nomesTurmas[] = $turma['nm_turma'];
     }
     $nomesTurmas = implode('<br />', $nomesTurmas);
     if ($nomesTurmas) {
         $this->addDetalhe(array('Turma', $nomesTurmas));
     } else {
         $this->addDetalhe(array('Turma', ''));
     }
     if ($registro['ref_cod_reserva_vaga']) {
         $this->addDetalhe(array('Número Reserva Vaga', $registro['ref_cod_reserva_vaga']));
     }
     $campoObs = false;
     if ($registro['aprovado']) {
         if ($registro['aprovado'] == 1) {
             $aprovado = 'Aprovado';
         } elseif ($registro['aprovado'] == 2) {
             $aprovado = 'Reprovado';
         } elseif ($registro['aprovado'] == 3) {
             $aprovado = 'Em Andamento';
         } elseif ($registro['aprovado'] == 4) {
             $aprovado = 'Transferido';
         } elseif ($registro['aprovado'] == 5) {
             $aprovado = 'Reclassificado';
         } elseif ($registro['aprovado'] == 6) {
             $aprovado = 'Abandono';
             $campoObs = true;
         } elseif ($registro['aprovado'] == 7) {
             $aprovado = 'Em Exame';
         }
         $this->addDetalhe(array('Situação', $aprovado));
     }
     if ($campoObs) {
         $this->addDetalhe(array('Observação', $registro['observacao']));
     }
     $this->addDetalhe(array('Formando', $registro['formando'] == 0 ? 'N&atilde;o' : 'Sim'));
     $obj_permissoes = new clsPermissoes();
     if ($obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) {
         // verifica se existe transferencia
         if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) {
             $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
             $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, $registro['cod_matricula'], NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $registro['ref_cod_aluno'], FALSE);
             // verifica se existe uma solicitacao de transferencia INTERNA
             if (is_array($lst_transferencia)) {
                 $det_transferencia = array_shift($lst_transferencia);
             }
             $data_transferencia = $det_transferencia['data_transferencia'];
         }
         if ($registro['aprovado'] == 3 && (!is_array($lst_transferencia) && !isset($data_transferencia))) {
             $this->array_botao[] = 'Cancelar Matrícula';
             $this->array_botao_url_script[] = "if(confirm(\"Deseja realmente cancelar esta matrícula?\"))go(\"educar_matricula_cad.php?cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
             $this->array_botao[] = 'Ocorrências Disciplinares';
             $this->array_botao_url_script[] = "go(\"educar_matricula_ocorrencia_disciplinar_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             // Apenas libera a dispensa de disciplina quando o aluno estiver enturmado
             if ($registro['ref_ref_cod_serie'] && $nomesTurmas) {
                 $this->array_botao[] = 'Dispensa de Componentes Curriculares';
                 $this->array_botao_url_script[] = "go(\"educar_dispensa_disciplina_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             }
             $this->array_botao[] = 'Enturmar';
             $this->array_botao_url_script[] = "go(\"educar_matricula_turma_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             $this->array_botao[] = 'Abandono';
             $this->array_botao_url_script[] = "go(\"educar_abandono_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\");";
             if ($registro['ref_ref_cod_serie']) {
                 $this->array_botao[] = 'Reclassificar';
                 $this->array_botao_url_script[] = "go(\"educar_matricula_reclassificar_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
             }
         }
         if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) {
             if (is_array($lst_transferencia) && !isset($data_transferencia)) {
                 $this->array_botao[] = 'Cancelar Solicitação Transferência (escola do sistema)';
                 $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true\")";
             } else {
                 if ($registro['ref_ref_cod_serie']) {
                     $this->array_botao[] = 'Solicitar Transferência';
                     $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
                 }
             }
             if ($registro['aprovado'] == 3 && (!is_array($lst_transferencia) && !isset($data_transferencia))) {
                 if ($registro['formando'] == 0) {
                     $this->array_botao[] = 'Formando';
                     $this->array_botao_url_script[] = "if(confirm(\"Deseja marcar a matrícula como formando?\"))go(\"educar_matricula_formando_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&formando=1\")";
                 } else {
                     $this->array_botao[] = "Desmarcar como Formando";
                     $this->array_botao_url_script[] = "if(confirm(\"Deseja desmarcar a matrícula como formando?\"))go(\"educar_matricula_formando_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&formando=0\")";
                 }
             }
         }
         if ($registro['aprovado'] == 4 && $this->canCancelTransferenciaExterna($registro['cod_matricula'], $registro['ref_cod_aluno'])) {
             $this->array_botao[] = 'Cancelar transferência (escola externa)';
             # TODO ver se código, seta matricula como em andamento, ativa ultima matricula_turma for matricula, e desativa transferencia solicitacao
             $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true&reabrir_matricula=true\")";
         }
         if ($registro['aprovado'] == App_Model_MatriculaSituacao::ABANDONO) {
             $this->array_botao[] = "Desfazer abandono";
             $this->array_botao_url_script[] = "deleteAbandono({$registro['cod_matricula']})";
         }
     }
     $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $registro['ref_cod_aluno'];
     $this->largura = '100%';
     // js
     Portabilis_View_Helper_Application::loadJQueryLib($this);
     $scripts = array('/modules/Portabilis/Assets/Javascripts/Utils.js', '/modules/Portabilis/Assets/Javascripts/ClientApi.js', '/modules/Cadastro/Assets/Javascripts/MatriculaShow.js');
     Portabilis_View_Helper_Application::loadJavascript($this, $scripts);
 }
    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;
        }
    }
 function Gerar()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $this->titulo = "Matrícula - Detalhe";
     $this->addBanner("imagens/nvp_top_intranet.jpg", "imagens/nvp_vert_intranet.jpg", "Intranet");
     $this->ref_cod_matricula = $_GET["cod_matricula"];
     $obj_matricula = new clsPmieducarMatricula();
     $lst_matricula = $obj_matricula->lista($this->ref_cod_matricula);
     if ($lst_matricula) {
         $registro = array_shift($lst_matricula);
     }
     if (!$registro) {
         header("Location: educar_matricula_lst.php?ref_cod_aluno=" . $registro['ref_cod_aluno']);
         die;
     }
     // Curso
     $obj_ref_cod_curso = new clsPmieducarCurso($registro['ref_cod_curso']);
     $det_ref_cod_curso = $obj_ref_cod_curso->detalhe();
     $registro['ref_cod_curso'] = $det_ref_cod_curso['nm_curso'];
     // Série
     $obj_serie = new clsPmieducarSerie($registro['ref_ref_cod_serie']);
     $det_serie = $obj_serie->detalhe();
     $registro['ref_ref_cod_serie'] = $det_serie['nm_serie'];
     // Nome da instituição
     $obj_cod_instituicao = new clsPmieducarInstituicao($registro['ref_cod_instituicao']);
     $obj_cod_instituicao_det = $obj_cod_instituicao->detalhe();
     $registro['ref_cod_instituicao'] = $obj_cod_instituicao_det['nm_instituicao'];
     // Nome da escola
     $obj_ref_cod_escola = new clsPmieducarEscola($registro['ref_ref_cod_escola']);
     $det_ref_cod_escola = $obj_ref_cod_escola->detalhe();
     $registro['ref_ref_cod_escola'] = $det_ref_cod_escola['nome'];
     // Nome do aluno
     $obj_aluno = new clsPmieducarAluno();
     $lst_aluno = $obj_aluno->lista($registro['ref_cod_aluno'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     if (is_array($lst_aluno)) {
         $det_aluno = array_shift($lst_aluno);
         $nm_aluno = $det_aluno['nome_aluno'];
     }
     // Nome da turma
     $obj_mat_turma = new clsPmieducarMatriculaTurma();
     $det_mat_turma = $obj_mat_turma->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
     if ($det_mat_turma) {
         $det_mat_turma = array_shift($det_mat_turma);
         $obj_turma = new clsPmieducarTurma($det_mat_turma['ref_cod_turma']);
         $det_turma = $obj_turma->detalhe();
         $nm_turma = $det_turma['nm_turma'];
     }
     if ($registro['cod_matricula']) {
         $this->addDetalhe(array('Número Matrícula', $registro['cod_matricula']));
     }
     if ($nm_aluno) {
         $this->addDetalhe(array('Aluno', $nm_aluno));
     }
     if ($registro['ref_cod_instituicao']) {
         $this->addDetalhe(array('Instituição', $registro['ref_cod_instituicao']));
     }
     if ($registro['ref_ref_cod_escola']) {
         $this->addDetalhe(array('Escola', $registro['ref_ref_cod_escola']));
     }
     if ($registro['ref_cod_curso']) {
         $this->addDetalhe(array('Curso', $registro['ref_cod_curso']));
     }
     if ($registro['ref_ref_cod_serie']) {
         $this->addDetalhe(array('Série', $registro['ref_ref_cod_serie']));
     }
     if ($nm_turma) {
         $this->addDetalhe(array('Turma', $nm_turma));
     }
     if ($registro['ref_cod_reserva_vaga']) {
         $this->addDetalhe(array('Número Reserva Vaga', $registro['ref_cod_reserva_vaga']));
     }
     if ($registro['aprovado']) {
         if ($registro['aprovado'] == 1) {
             $aprovado = 'Aprovado';
         } elseif ($registro['aprovado'] == 2) {
             $aprovado = 'Reprovado';
         } elseif ($registro['aprovado'] == 3) {
             $aprovado = 'Em Andamento';
         } elseif ($registro['aprovado'] == 4) {
             $aprovado = 'Transferido';
         } elseif ($registro['aprovado'] == 5) {
             $aprovado = 'Reclassificado';
         } elseif ($registro['aprovado'] == 6) {
             $aprovado = 'Abandono';
         } elseif ($registro['aprovado'] == 7) {
             $aprovado = 'Em Exame';
         }
         $this->addDetalhe(array('Situação', $aprovado));
     }
     $this->addDetalhe(array('Formando', $registro['formando'] == 0 ? 'N&atilde;o' : 'Sim'));
     $obj_permissoes = new clsPermissoes();
     if ($obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) {
         // verifica se existe transferencia
         if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) {
             $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
             $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, $registro['cod_matricula'], NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $registro['ref_cod_aluno'], FALSE);
             // verifica se existe uma solicitacao de transferencia INTERNA
             if (is_array($lst_transferencia)) {
                 $det_transferencia = array_shift($lst_transferencia);
             }
             $data_transferencia = $det_transferencia['data_transferencia'];
         }
         if ($registro['aprovado'] == 3 && (!is_array($lst_transferencia) && !isset($data_transferencia))) {
             $this->array_botao[] = 'Cancelar Matrícula';
             $this->array_botao_url_script[] = "if(confirm(\"Deseja realmente cancelar esta matrícula?\"))go(\"educar_matricula_cad.php?cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
             $this->array_botao[] = 'Ocorrências Disciplinares';
             $this->array_botao_url_script[] = "go(\"educar_matricula_ocorrencia_disciplinar_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             // Apenas libera a dispensa de disciplina quando o aluno estiver enturmado
             if ($registro['ref_ref_cod_serie'] && isset($nm_turma)) {
                 $this->array_botao[] = 'Dispensa de Componentes Curriculares';
                 $this->array_botao_url_script[] = "go(\"educar_dispensa_disciplina_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             }
             $this->array_botao[] = 'Enturmar';
             $this->array_botao_url_script[] = "go(\"educar_matricula_turma_lst.php?ref_cod_matricula={$registro['cod_matricula']}\")";
             $this->array_botao[] = 'Abandono';
             $this->array_botao_url_script[] = "if(confirm(\"Deseja confirmar o abandono desta matrícula?\"))go(\"educar_matricula_abandono_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\");";
             if ($registro['ref_ref_cod_serie']) {
                 $this->array_botao[] = 'Reclassificar';
                 $this->array_botao_url_script[] = "go(\"educar_matricula_reclassificar_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
             }
         }
         if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) {
             if (is_array($lst_transferencia) && !isset($data_transferencia)) {
                 $this->array_botao[] = 'Cancelar Solicitação Transferência';
                 $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true\")";
             } else {
                 if ($registro['ref_ref_cod_serie']) {
                     $this->array_botao[] = 'Solicitar Transferência';
                     $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}\")";
                 }
             }
             if ($registro['aprovado'] == 3 && (!is_array($lst_transferencia) && !isset($data_transferencia))) {
                 if ($registro['formando'] == 0) {
                     $this->array_botao[] = 'Formando';
                     $this->array_botao_url_script[] = "if(confirm(\"Deseja marcar a matrícula como formando?\"))go(\"educar_matricula_formando_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&formando=1\")";
                 } else {
                     $this->array_botao[] = "Desmarcar como Formando";
                     $this->array_botao_url_script[] = "if(confirm(\"Deseja desmarcar a matrícula como formando?\"))go(\"educar_matricula_formando_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&formando=0\")";
                 }
             }
         }
         if ($registro['aprovado'] == 4 || $det_transferencia) {
             $this->array_botao[] = 'Imprimir Atestado Frequência';
             $this->array_botao_url_script[] = "showExpansivelImprimir(400, 200,  \"educar_relatorio_atestado_frequencia.php?cod_matricula={$registro['cod_matricula']}\",[], \"Relatório Atestado de Freqüência\")";
         }
     }
     $this->url_cancelar = 'educar_matricula_lst.php?ref_cod_aluno=' . $registro['ref_cod_aluno'];
     $this->largura = '100%';
 }