function renderHTML()
 {
     if ($_POST) {
         foreach ($_POST as $key => $value) {
             $this->{$key} = $value;
         }
     }
     if ($this->ref_ref_cod_serie) {
         $this->ref_cod_serie = $this->ref_ref_cod_serie;
     }
     $fonte = 'arial';
     $corTexto = '#000000';
     if (empty($this->ref_cod_turma)) {
         echo '
     <script>
       alert("Erro ao gerar relatório!\\nNenhuma turma selecionada!");
       window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
     </script>';
         return TRUE;
     }
     if ($this->ref_cod_escola) {
         $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
         $det_escola = $obj_escola->detalhe();
         $this->nm_escola = $det_escola['nome'];
         $obj_instituicao = new clsPmieducarInstituicao($det_escola['ref_cod_instituicao']);
         $det_instituicao = $obj_instituicao->detalhe();
         $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     }
     $obj_calendario = new clsPmieducarEscolaAnoLetivo();
     $lista_calendario = $obj_calendario->lista($this->ref_cod_escola, $this->ano, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL);
     $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
     $det_turma = $obj_turma->detalhe();
     $this->nm_turma = $det_turma['nm_turma'];
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     $obj_pessoa = new clsPessoa_($det_turma['ref_cod_regente']);
     $det = $obj_pessoa->detalhe();
     $this->nm_professor = $det['nome'];
     if (!$lista_calendario) {
         echo '
     <script>
       alert("Escola não possui calendário definido para este ano");
       window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
     </script>';
         return TRUE;
     }
     $titulo = 'Diário de Classe - ' . $this->ano;
     $prox_mes = $this->mes + 1;
     $this->pdf = new clsPDF($titulo, $titulo, 'A4', '', FALSE, FALSE);
     $altura_linha = 15;
     $inicio_escrita_y = 175;
     $altura_pagina = 760;
     $obj = new clsPmieducarSerie();
     $obj->setOrderby('cod_serie, etapa_curso');
     $lista_serie_curso = $obj->lista(NULL, NULL, NULL, $this->ref_cod_curso, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao);
     $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
     $det_curso = $obj_curso->detalhe();
     $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
     $det_curso = $obj_curso->detalhe();
     // Recupera a lista de componentes curriculares da escola/série
     $componentes = App_Model_IedFinder::getEscolaSerieDisciplina($this->ref_cod_serie, $this->ref_cod_escola);
     if (0 == count($componentes)) {
         echo '
     <script>
       alert("Turma não possui matriculas");
       window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
     </script>';
         return;
     } else {
         foreach ($componentes as $id => $componente) {
             $this->nm_disciplina = $componente->nome;
             $this->page_y = 139;
             // Número de semanas dos meses
             $obj_quadro = new clsPmieducarQuadroHorario();
             $obj_quadro->setCamposLista('cod_quadro_horario');
             $quadro_horario = $obj_quadro->lista(NULL, NULL, NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, 1);
             if (!$quadro_horario && $det_curso['avaliacao_globalizada'] == 't') {
                 echo '
         <script>
           alert("Turma não possui quadro de horários");
           window.location = "educar_relatorio_diario_classe.php";
         </script>';
                 break;
             }
             $obj_quadro_horarios = new clsPmieducarQuadroHorarioHorarios();
             $obj_quadro_horarios->setCamposLista('dia_semana');
             $obj_quadro_horarios->setOrderby('1 asc');
             $lista_quadro_horarios = $obj_quadro_horarios->lista($quadro_horario, $this->ref_cod_serie, $this->ref_cod_escola, $disciplina, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
             if (!$this->em_branco) {
                 $obj_matricula_turma = new clsPmieducarMatriculaTurma();
                 $obj_matricula_turma->setOrderby('nome_ascii');
                 $lista_matricula = $obj_matricula_turma->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_serie, $this->ref_cod_curso, $this->ref_cod_escola, $this->ref_cod_instituicao, NULL, NULL, array(1, 2, 3), NULL, NULL, $this->ano, NULL, TRUE, NULL, NULL, TRUE);
             }
             $num_aluno = 1;
             if ($lista_matricula || $this->em_branco) {
                 $this->pdf->OpenPage();
                 $this->addCabecalho();
                 if ($this->em_branco) {
                     $lista_matricula = array();
                     $this->numero_registros = $this->numero_registros ? $this->numero_registros : 20;
                     for ($i = 0; $i < $this->numero_registros; $i++) {
                         $lista_matricula[] = '';
                     }
                 }
                 foreach ($lista_matricula as $matricula) {
                     if ($this->page_y > $altura_pagina) {
                         $this->desenhaLinhasVertical();
                         $this->pdf->ClosePage();
                         $this->pdf->OpenPage();
                         $this->page_y = 139;
                         $this->addCabecalho();
                     }
                     $this->pdf->quadrado_relativo(30, $this->page_y, 540, $altura_linha);
                     $this->pdf->escreve_relativo($num_aluno, 38, $this->page_y + 4, 30, 15, $fonte, 7, $corTexto, 'left');
                     $this->pdf->escreve_relativo($matricula['nome_aluno'], 55, $this->page_y + 4, 160, 15, $fonte, 7, $corTexto, 'left');
                     $num_aluno++;
                     $this->page_y += $altura_linha;
                 }
                 $this->desenhaLinhasVertical();
                 $this->rodape();
                 $this->pdf->ClosePage();
             }
         }
         $this->pdf->CloseFile();
         $this->get_link = $this->pdf->GetLink();
     }
     echo sprintf('
   <script>
     window.onload=function()
     {
       parent.EscondeDiv("LoadImprimir");
       window.location="download.php?filename=%s"
     }
   </script>', $this->get_link);
     echo sprintf('
   <html>
     <center>
       Se o download não iniciar automaticamente <br>
       <a target="blank" href="%s" style="font-size: 16px; color: #000000; text-decoration: underline;">clique aqui!</a><br><br>
       <span style="font-size: 10px;">
         Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>
         Clique na Imagem para Baixar o instalador<br><br>
         <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>
       </span>
     </center>
   </html>', $this->get_link);
 }
 function renderHTML()
 {
     global $coreExt;
     if ($_POST) {
         foreach ($_POST as $key => $value) {
             $this->{$key} = $value;
         }
     }
     $this->temporario = isset($_POST['temporario']) ? TRUE : FALSE;
     if ($this->ref_ref_cod_serie) {
         $this->ref_cod_serie = $this->ref_ref_cod_serie;
     }
     $fonte = 'arial';
     $corTexto = '#000000';
     if (empty($this->ref_cod_turma)) {
         echo '
     <script>
       alert("Erro ao gerar relatório!\\nNenhuma turma selecionada!");
       window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
     </script>';
         return TRUE;
     }
     $modulo_sequencial = explode('-', $this->ref_cod_modulo);
     $this->ref_cod_modulo = $modulo_sequencial[0];
     $this->sequencial = $modulo_sequencial[1];
     if ($this->ref_cod_escola) {
         $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
         $det_escola = $obj_escola->detalhe();
         $this->nm_escola = $det_escola['nome'];
         $obj_instituicao = new clsPmieducarInstituicao($det_escola['ref_cod_instituicao']);
         $det_instituicao = $obj_instituicao->detalhe();
         $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     }
     $obj_calendario = new clsPmieducarEscolaAnoLetivo();
     $lista_calendario = $obj_calendario->lista($this->ref_cod_escola, $this->ano, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL);
     $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
     $det_turma = $obj_turma->detalhe();
     $this->nm_turma = $det_turma['nm_turma'];
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     $regraId = $det_serie['regra_avaliacao_id'];
     $obj_pessoa = new clsPessoa_($det_turma['ref_cod_regente']);
     $det = $obj_pessoa->detalhe();
     $this->nm_professor = $det['nome'];
     if (!$lista_calendario) {
         echo '
     <script>
       alert("Escola não possui calendário definido para este ano");
       window.parent.fechaExpansivel(\'div_dinamico_\' + (window.parent.DOM_divs.length - 1));
     </script>';
         return TRUE;
     }
     $altura_linha = 23;
     $inicio_escrita_y = 175;
     $obj = new clsPmieducarSerie();
     $obj->setOrderby('cod_serie, etapa_curso');
     $lista_serie_curso = $obj->lista(NULL, NULL, NULL, $this->ref_cod_curso, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao);
     $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
     $det_curso = $obj_curso->detalhe();
     // Seleciona a regra para verificar se a presença é geral
     $regraMapper = new RegraAvaliacao_Model_RegraDataMapper();
     $regra = $regraMapper->find($regraId);
     $presencaGeral = $regra->get('tipoPresenca') == RegraAvaliacao_Model_TipoPresenca::GERAL;
     // Seleciona o curso para ver se é padrão e decidir qual ano letivo pesquisar
     $db = new clsBanco();
     $consulta = sprintf('SELECT padrao_ano_escolar FROM pmieducar.curso WHERE cod_curso = \'%d\'', $this->ref_cod_curso);
     $padrao_ano_escolar = $db->CampoUnico($consulta);
     $total_semanas = 0;
     if ($padrao_ano_escolar) {
         // Seleciona o módulo do ano letivo da escola
         $data = $this->getDatasModulo($this->ref_cod_modulo, $this->sequencial, $this->ano, $this->ref_cod_escola);
     } else {
         // Seleciona o módulo do ano letivo da turma
         $data = $this->getDatasModulo($this->ref_cod_modulo, $this->sequencial, $this->ano, NULL, $this->ref_cod_turma);
     }
     $meses = $data['meses'];
     $dias = $data['dias'];
     if (!$this->data_ini) {
         $this->data_ini = $data['dataInicial'];
     }
     if (!$this->data_fim) {
         $this->data_fim = $data['dataFinal'];
     }
     $total_semanas = 0;
     for ($mes = $meses[0]; $mes <= $meses[1]; $mes++) {
         $mes_final = FALSE;
         if ($mes == $meses[0]) {
             $dia = $dias[0];
         } elseif ($mes == $meses[1]) {
             $dia = $dias[1];
             $mes_final = TRUE;
         } else {
             $dia = 1;
         }
         $total_semanas += $this->getNumeroDiasMes($this->ref_cod_turma, $dia, $mes, $this->ano, $mes_final);
         $total_semanas += $ndm;
     }
     $this->pdf = new clsPDF('Diário de Classe - ' . $this->ano, sprintf('Diário de Classe - %s até %s de %s', $this->data_ini, $this->data_fim, $this->ano), 'A4', '', FALSE, FALSE);
     $this->mes_inicial = (int) $meses[0];
     $this->mes_final = (int) $meses[1];
     $this->pdf->largura = 842.0;
     $this->pdf->altura = 595.0;
     $this->total = $total_semanas;
     if (!$this->em_branco) {
         $obj_matricula_turma = new clsPmieducarMatriculaTurma();
         $obj_matricula_turma->setOrderby('nome_ascii');
         $matriculaSituacao = array(App_Model_MatriculaSituacao::APROVADO, App_Model_MatriculaSituacao::REPROVADO, App_Model_MatriculaSituacao::EM_ANDAMENTO);
         $lista_matricula = $obj_matricula_turma->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_serie, $this->ref_cod_curso, $this->ref_cod_escola, $this->ref_cod_instituicao, NULL, NULL, $matriculaSituacao, NULL, NULL, $this->ano, NULL, TRUE, NULL, NULL, TRUE);
     }
     if ($this->em_branco) {
         $lista_matricula = array();
         $this->numero_registros = $this->numero_registros ? $this->numero_registros : 20;
         for ($i = 0; $i < $this->numero_registros; $i++) {
             $lista_matricula[] = '';
         }
     }
     // Seleciona os componentes da escola/série
     $componentes = App_Model_IedFinder::getEscolaSerieDisciplina($this->ref_cod_serie, $this->ref_cod_escola);
     if (0 < count($componentes) && FALSE == $presencaGeral) {
         $this->total = $total_semanas = 0;
         foreach ($componentes as $componente) {
             $this->nm_disciplina = $componente->nome;
             $this->page_y = 125;
             if (FALSE == $presencaGeral) {
                 // Número de semanas dos meses
                 $obj_quadro = new clsPmieducarQuadroHorario();
                 $obj_quadro->setCamposLista('cod_quadro_horario');
                 $quadro_horario = $obj_quadro->lista(NULL, NULL, NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, 1);
                 $total_semanas = 0;
                 $this->indefinido = FALSE;
                 if (!$quadro_horario) {
                     echo '
           <script>
             alert(\'Turma não possui quadro de horários\');
             window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
           </script>';
                     die;
                 }
                 $obj_quadro_horarios = new clsPmieducarQuadroHorarioHorarios();
                 $obj_quadro_horarios->setCamposLista('dia_semana');
                 $obj_quadro_horarios->setOrderby('1 asc');
                 $lista_quadro_horarios = $obj_quadro_horarios->lista($quadro_horario[0], $this->ref_cod_serie, $this->ref_cod_escola, $componente->id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
                 // Se não for retornado horário e o diário não for temporário, gera
                 // a lista para o próximo componente
                 if (FALSE == $lista_quadro_horarios && FALSE == $this->temporario) {
                     continue;
                 }
                 // Caso o diário seja temporário, gera lista de alunos para 30 dias
                 // por padrão
                 if (FALSE == $lista_quadro_horarios && TRUE == $this->temporario) {
                     $this->indefinido = TRUE;
                     $total_semanas = $coreExt['Config']->get($coreExt['Config']->report->diario_classe->dias_temporarios, 30);
                 }
                 for ($mes_ = $meses[0]; $mes_ <= $meses[1] && FALSE != $lista_quadro_horarios; $mes_++) {
                     $mes_final = FALSE;
                     foreach ($lista_quadro_horarios as $dia_semana) {
                         if ($mes_ == $meses[0]) {
                             $dia = $dias[0];
                         } elseif ($mes_ == $meses[1]) {
                             $dia = $dias[1];
                             $mes_final = TRUE;
                         } else {
                             $dia = 1;
                         }
                         $total_semanas += $this->getDiasSemanaMes($this->ref_cod_turma, $dia, $mes_, $this->ano, $dia_semana, $mes_final);
                     }
                 }
                 $this->total = $total_semanas;
             }
             if (!$this->total) {
                 continue;
             }
             $this->gerarListaAlunos($lista_matricula);
         }
     } else {
         $this->gerarListaAlunos($lista_matricula);
     }
     if ($this->total) {
         $this->pdf->CloseFile();
         $this->get_link = $this->pdf->GetLink();
     } else {
         $this->mensagem = 'Não existem dias letivos cadastrados para esta turma';
         return;
     }
     echo sprintf('
   <script>
     window.onload = function()
     {
       parent.EscondeDiv("LoadImprimir");
       window.location="download.php?filename=%s"
     }
   </script>', $this->get_link);
     echo sprintf('
   <html>
     <center>
       Se o download não iniciar automaticamente <br /><a target="blank" href="%s" style="font-size: 16px; color: #000000; text-decoration: underline;">clique aqui!</a><br><br>
       <span style="font-size: 10px;">Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>
         Clique na Imagem para Baixar o instalador<br><br>
         <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>
       </span>
     </center>
   </html>', $this->get_link);
 }