function renderHTML()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     session_write_close();
     $obj_permissoes = new clsPermissoes();
     if ($obj_permissoes->nivel_acesso($this->pessoa_logada) > 7) {
         $retorno .= '
     <table width="100%" height="40%" cellspacing="1" cellpadding="2" border="0" class="tablelistagem">
       <tbody>
         <tr>
           <td colspan="2" valig="center" height="50">
             <center class="formdktd">Usuário sem permissão para acessar esta página</center>
           </td>
         </tr>
       </tbody>
     </table>';
         return $retorno;
     }
     $retorno .= '
   <table width="100%" cellspacing="1" cellpadding="2" border="0" class="tablelistagem">
     <tbody>';
     if ($_POST) {
         $this->ref_cod_turma = $_POST['ref_cod_turma'] ? $_POST['ref_cod_turma'] : NULL;
         $this->ref_cod_serie = $_POST['ref_cod_serie'] ? $_POST['ref_cod_serie'] : NULL;
         $this->ref_cod_curso = $_POST['ref_cod_curso'] ? $_POST['ref_cod_curso'] : NULL;
         $this->ref_cod_escola = $_POST['ref_cod_escola'] ? $_POST['ref_cod_escola'] : NULL;
         $this->ref_cod_instituicao = $_POST['ref_cod_instituicao'] ? $_POST['ref_cod_instituicao'] : NULL;
         $this->busca = $_GET['busca'] ? $_GET['busca'] : NULL;
     } else {
         if ($_GET) {
             // Passa todos os valores obtidos no GET para atributos do objeto
             foreach ($_GET as $var => $val) {
                 $this->{$var} = $val === '' ? NULL : $val;
             }
         }
     }
     $nivel_usuario = $obj_permissoes->nivel_acesso($this->pessoa_logada);
     if (!$this->ref_cod_escola) {
         $this->ref_cod_escola = $obj_permissoes->getEscola($this->pessoa_logada);
     }
     if (!is_numeric($this->ref_cod_instituicao)) {
         $this->ref_cod_instituicao = $obj_permissoes->getInstituicao($this->pessoa_logada);
     }
     // Componente curricular
     $componenteMapper = new ComponenteCurricular_Model_ComponenteDataMapper();
     $obrigatorio = FALSE;
     $get_instituicao = TRUE;
     $get_escola = TRUE;
     $get_curso = TRUE;
     $get_serie = TRUE;
     $get_turma = TRUE;
     include 'educar_quadro_horarios_pesquisas.php';
     if ($this->busca == 'S') {
         if (is_numeric($this->ref_cod_turma)) {
             $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
             $det_turma = $obj_turma->detalhe();
             $obj_quadro = new clsPmieducarQuadroHorario(NULL, NULL, NULL, $this->ref_cod_turma, NULL, NULL, 1);
             $det_quadro = $obj_quadro->detalhe();
             if (is_array($det_quadro)) {
                 $quadro_horario = "<table class='calendar' cellspacing='0' cellpadding='0' border='0'><tr><td class='cal_esq' >&nbsp;</td><td background='imagens/i-educar/cal_bg.gif' width='100%' class='mes'>{$det_turma["nm_turma"]}</td><td align='right' class='cal_dir'>&nbsp;</td></tr><tr><td colspan='3' class='bordaM' style='border-bottom: 1px solid #8A959B;'  align='center'><table cellspacing='0' cellpadding='0'  border='0' ><tr class='header'><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>DOM</td><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>SEG</td><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>TER</td><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>QUA</td><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>QUI</td><td style='border-right: 1px dotted #FFFFFF;width: 100px;'>SEX</td><td style='width: 100px;'>SAB</td></tr>";
                 $texto = '<tr>';
                 for ($c = 1; $c <= 7; $c++) {
                     $obj_horarios = new clsPmieducarQuadroHorarioHorarios();
                     $resultado = $obj_horarios->retornaHorario($this->ref_cod_instituicao, $this->ref_cod_escola, $this->ref_cod_serie, $this->ref_cod_turma, $c);
                     $texto .= "<td valign=top align='center' width='100' style='cursor: pointer; ' onclick='envia( this, {$this->ref_cod_turma}, {$this->ref_cod_serie}, {$this->ref_cod_curso}, {$this->ref_cod_escola}, {$this->ref_cod_instituicao}, {$det_quadro["cod_quadro_horario"]}, {$c} );'>";
                     if (is_array($resultado)) {
                         foreach ($resultado as $registro) {
                             // Componente curricular
                             $componente = $componenteMapper->find($registro['ref_cod_disciplina']);
                             // Servidor
                             $obj_servidor = new clsPmieducarServidor();
                             $det_servidor = array_shift($obj_servidor->lista($registro['ref_servidor'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,  NULL, NULL, NULL, NULL, NULL, TRUE));
                             $det_servidor['nome'] = array_shift(explode(' ', $det_servidor['nome']));
                             //$texto .= "<div  style='text-align: center;background-color: #F6F6F6;font-size: 11px; width: 100px; margin: 3px; border: 1px solid #CCCCCC; padding:5px; '>". substr($registro['hora_inicial'], 0, 5) . ' - ' . substr($registro['hora_final'], 0, 5) . " <br> {$componente->abreviatura} <br> {$det_servidor["nome"]}</div>";
                             $detalhes = sprintf("%s - %s<br />%s<br />%s", substr($registro['hora_inicial'], 0, 5), substr($registro['hora_final'], 0, 5), $componente->abreviatura, $det_servidor['nome']);
                             $texto .= sprintf('<div style="text-align: center; background-color: #F6F6F6; font-size: 11px; width: 100px; margin: 3px; border: 1px solid #CCCCCC; padding:5px;">%s</div>', $detalhes);
                         }
                     } else {
                         $texto .= "<div  style='text-align: center;background-color: #F6F6F6;font-size: 11px; width: 100px; margin: 3px; border: 1px solid #CCCCCC; padding:5px; height: 85%;'></div>";
                     }
                     $texto .= '</td>';
                 }
                 $texto .= '<tr><td colspan="7">&nbsp;</td></tr>';
                 $quadro_horario .= $texto;
                 $quadro_horario .= '</table></td></tr></table>';
                 $retorno .= "<tr><td colspan='2' ><center><b></b>{$quadro_horario}</center></td></tr>";
             } else {
                 $retorno .= "<tr><td colspan='2' ><b><center>N&atilde;o existe nenhum quadro de hor&aacute;rio cadastrado para esta turma.</center></b></td></tr>";
             }
         }
     }
     if ($obj_permissoes->permissao_cadastra(641, $this->pessoa_logada, 7)) {
         $retorno .= "<tr><td>&nbsp;</td></tr><tr>\n            <td align=\"center\" colspan=\"2\">";
         if (!$det_quadro) {
             $retorno .= "<input type=\"button\" value=\"Novo Quadro de Hor&aacute;rios\" onclick=\"window.location='educar_quadro_horario_cad.php?ref_cod_turma={$this->ref_cod_turma}&ref_cod_serie={$this->ref_cod_serie}&ref_cod_curso={$this->ref_cod_curso}&ref_cod_escola={$this->ref_cod_escola}&ref_cod_instituicao={$this->ref_cod_instituicao};'\" class=\"botaolistagem\"/>";
         } else {
             if ($obj_permissoes->permissao_excluir(641, $this->pessoa_logada, 7)) {
                 $retorno .= "<input type=\"button\" value=\"Excluir Quadro de Hor&aacute;rios\" onclick=\"window.location='educar_quadro_horario_cad.php?ref_cod_turma={$this->ref_cod_turma}&ref_cod_serie={$this->ref_cod_serie}&ref_cod_curso={$this->ref_cod_curso}&ref_cod_escola={$this->ref_cod_escola}&ref_cod_instituicao={$this->ref_cod_instituicao}&ref_cod_quadro_horario={$det_quadro["cod_quadro_horario"]}'\" class=\"botaolistagem\"/>";
             }
         }
         $retorno .= "</td>\n            </tr>";
     }
     $retorno .= '</tbody>
   </table>';
     return $retorno;
 }
 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;
     }
     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($this->ref_cod_instituicao);
     $det_instituicao = $obj_instituicao->detalhe();
     $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     $fonte = 'arial';
     $corTexto = '#000000';
     $obj_curso = new clsPmieducarCurso();
     $obj_curso->setOrderby('nm_curso');
     $lst_curso = $obj_curso->lista($this->ref_cod_curso, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, $this->ref_cod_instituicao);
     if ($lst_curso) {
         foreach ($lst_curso as $curso) {
             $obj_serie = new clsPmieducarSerie();
             $obj_serie->setOrderby('nm_serie');
             $lst_serie = $obj_serie->lista($this->ref_cod_serie, NULL, NULL, $curso['cod_curso'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao, NULL, NULL, NULL, $this->ref_cod_escola);
             $quadro_horario = 0;
             if ($lst_serie) {
                 foreach ($lst_serie as $serie) {
                     $obj_turma = new clsPmieducarTurma();
                     $obj_turma->setOrderby('nm_turma');
                     $lst_turma = $obj_turma->lista($this->ref_cod_turma, NULL, NULL, $serie['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, $curso['cod_curso'], $this->ref_cod_instituicao);
                     if ($lst_turma) {
                         foreach ($lst_turma as $turma) {
                             $obj_quadro = new clsPmieducarQuadroHorario(NULL, NULL, NULL, $turma['cod_turma'], NULL, NULL, 1);
                             $det_quadro = $obj_quadro->detalhe();
                             if ($det_quadro) {
                                 if (!$this->pdf) {
                                     $this->pdf = new clsPDF('Quadro Horarios', 'Quadro Horarios', 'A4', '', FALSE, FALSE);
                                 }
                                 if ($quadro_horario % 3 == 0) {
                                     $this->page_y = 15;
                                     $this->pdf->OpenPage();
                                     $this->addCabecalho();
                                     $quadro_horario = 0;
                                 }
                                 $this->pdf->escreve_relativo($turma['nm_turma'] . ' -  ' . $serie['nm_serie'], 20, $this->page_y - 7, 550, 20, $fonte, 11, $corTexto, 'center');
                                 $this->page_y += 10;
                                 $this->pdf->quadrado_relativo(35, $this->page_y, 525, 20, 0.3, '#777777', '#777777');
                                 $inicio_x = 35;
                                 for ($dia_semana = 1; $dia_semana <= 7; $dia_semana++) {
                                     $this->pdf->linha_relativa($inicio_x, $this->page_y, 0, 20);
                                     $this->pdf->escreve_relativo($this->array_dias_semana[$dia_semana], $inicio_x, $this->page_y + 3, 75, 20, $fonte, 11, $corTexto, 'center');
                                     $inicio_x += 75;
                                 }
                                 $this->page_y += 20;
                                 $inicio_y = $this->page_y;
                                 $inicio_x = 35;
                                 $this->pdf->quadrado_relativo($inicio_x, $this->page_y, 525, 200, 0.3);
                                 for ($dia_semana = 1; $dia_semana <= 7; $dia_semana++) {
                                     $obj_horarios = new clsPmieducarQuadroHorarioHorarios();
                                     $resultado = $obj_horarios->retornaHorario($this->ref_cod_instituicao, $this->ref_cod_escola, $serie['cod_serie'], $turma['cod_turma'], $dia_semana);
                                     if (is_array($resultado)) {
                                         foreach ($resultado as $registro) {
                                             $this->pdf->quadrado_relativo($inicio_x, $this->page_y, 75, 50, 0.3);
                                             $componenteMapper = new ComponenteCurricular_Model_ComponenteDataMapper();
                                             $componente = $componenteMapper->find($registro['ref_cod_disciplina']);
                                             $obj_servidor = new clsPmieducarServidor();
                                             $det_servidor = array_shift($obj_servidor->lista($registro['ref_servidor'], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE));
                                             $det_servidor['nome'] = array_shift(explode(' ', $det_servidor['nome']));
                                             $texto = sprintf("%s - %s\n%s\n%s", substr($registro['hora_inicial'], 0, 5), substr($registro["hora_final"], 0, 5), $componente->abreviatura, $det_servidor['nome']);
                                             $this->pdf->escreve_relativo($texto, $inicio_x, $this->page_y + 12, 75, 50, $fonte, 10, $corTexto, 'center');
                                             $this->page_y += 50;
                                         }
                                     }
                                     $inicio_x += 75;
                                     $this->page_y = $inicio_y;
                                 }
                                 $this->page_y += 220;
                             }
                             $quadro_horario++;
                         }
                     }
                 }
             }
         }
     }
     if ($this->pdf) {
         $this->pdf->CloseFile();
         $this->get_link = $this->pdf->GetLink();
     } else {
         echo '
     <script>
       alert("A(s) turma(s) não possui(em) quadro de horário(s).");
       window.parent.fechaExpansivel("div_dinamico_" + (window.parent.DOM_divs.length-1));
     </script>';
         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>', $this->get_link);
 }