function iniciarAnoLetivo()
 {
     /**
      * VERIFICA se nao existe ano em andamento
      */
     $obj_ano_letivo = new clsPmieducarEscolaAnoLetivo();
     $existe_ano_andamento = $obj_ano_letivo->lista($this->ref_cod_escola, null, null, null, 1, null, null, null, null, 1);
     if ($existe_ano_andamento) {
         echo "<script>\n\t\t\t\t\talert('Não foi possível iniciar ano letivo, já existe ano em andamento!');\n\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t  </script>";
         die;
     }
     /**
      *  INICIALIZA ano letivo
      */
     $obj_ano_letivo = new clsPmieducarEscolaAnoLetivo($this->ref_cod_escola, $this->ano, $this->pessoa_logada, $this->pessoa_logada, 1, null, null, 1);
     if (!$obj_ano_letivo->edita()) {
         echo "<script>\n\t\t\t\t\talert('Erro ao finalizar o ano letivo!');\n\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t  </script>";
     } else {
         // lista todos alunos desse Escola que tem a ultima matricula no ano anterior e situacao APROVADO
         $obj_matricula = new clsPmieducarMatricula();
         $lst_matricula = $obj_matricula->lista(null, null, $this->ref_cod_escola, null, null, null, null, 1, null, null, null, null, 1, $this->ano - 1, null, null, 1);
         if (is_array($lst_matricula)) {
             foreach ($lst_matricula as $key => $matricula) {
                 $obj_sequencia = new clsPmieducarSequenciaSerie();
                 $lst_sequencia = $obj_sequencia->lista($matricula['ref_ref_cod_serie'], null, null, null, null, null, null, null, 1);
                 // verifica qual eh a serie da sequencia
                 if (is_array($lst_sequencia) && count($lst_sequencia) == 1) {
                     //						echo "<pre>"; print_r($lst_sequencia);die;
                     $det_sequencia = array_shift($lst_sequencia);
                     $serie_destino = $det_sequencia["ref_serie_destino"];
                     $obj_serie = new clsPmieducarSerie($serie_destino);
                     $det_serie = $obj_serie->detalhe();
                     //verificar aqui se a escola possui o curso
                     //						echo "<pre>"; print_r($matricula); die();
                     $obj_escola_curso = new clsPmieducarEscolaCurso($this->ref_cod_escola, $det_serie["ref_cod_curso"]);
                     if (is_array($obj_escola_curso->detalhe())) {
                         $obj = new clsPmieducarMatricula($matricula['cod_matricula'], null, null, null, $this->pessoa_logada, null, null, null, null, null, 1, null, 0);
                         $editou = $obj->edita();
                         if ($editou) {
                             $obj = new clsPmieducarMatricula(null, null, $this->ref_cod_escola, $serie_destino, null, $this->pessoa_logada, $matricula['ref_cod_aluno'], 3, null, null, 1, $this->ano, 1, null, null, null, null, $det_serie["ref_cod_curso"]);
                             $cadastra = $obj->cadastra();
                             if (!$cadastra) {
                                 echo "<script>\n\t\t\t\t\t\t\t\t\t\t\talert('Erro ao matricular os alunos da Escola!');\n\t\t\t\t\t\t\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t\t\t\t\t\t\t  </script>";
                             }
                         }
                     }
                 }
             }
         }
         // lista todos alunos desse Escola que tem a ultima matricula no ano anterior e situacao REPROVADO
         $obj_matricula = new clsPmieducarMatricula();
         $lst_matricula = $obj_matricula->lista(null, null, $this->ref_cod_escola, null, null, null, null, 2, null, null, null, null, 1, $this->ano - 1, null, null, 1);
         if (is_array($lst_matricula)) {
             //				echo "<pre>"; print_r($lst_matricula);die;
             foreach ($lst_matricula as $key => $matricula) {
                 $obj_serie = new clsPmieducarSerie($matricula['ref_ref_cod_serie']);
                 $det_serie = $obj_serie->detalhe();
                 $obj = new clsPmieducarMatricula($matricula['cod_matricula'], null, null, null, $this->pessoa_logada, null, null, null, null, null, 1, null, 0);
                 $editou1 = $obj->edita();
                 if ($editou1) {
                     $obj = new clsPmieducarMatricula(null, null, $this->ref_cod_escola, $matricula['ref_ref_cod_serie'], null, $this->pessoa_logada, $matricula['ref_cod_aluno'], 3, null, null, 1, $this->ano, 1, null, null, null, null, $det_serie["ref_cod_curso"]);
                     $cadastra1 = $obj->cadastra();
                     if (!$cadastra1) {
                         echo "<script>\n\t\t\t\t\t\t\t\t\talert('Erro ao matricular os alunos da Escola!');\n\t\t\t\t\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t\t\t\t\t  </script>";
                     }
                 }
             }
         }
         echo "<script>\n\t\t\t\t\talert('Ano letivo inicializado com sucesso!');\n\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t  </script>";
     }
 }
            foreach ($lista as $registro) {
                $opcoes_escola["{$registro["cod_escola"]}"] = "{$registro['nome']}";
            }
        }
    }
    if ($get_biblioteca) {
        $this->campoLista("ref_cod_escola", "Escola", $opcoes_escola, $this->ref_cod_escola, "getBiblioteca(2);", null, null, null, $escola_desabilitado, $escola_obrigatorio);
    } else {
        $this->campoLista("ref_cod_escola", "Escola", $opcoes_escola, $this->ref_cod_escola, null, null, null, null, $escola_desabilitado, $escola_obrigatorio);
    }
}
if ($get_curso) {
    $opcoes_curso = array("" => "Selecione");
    // EDITAR
    if ($this->ref_cod_escola) {
        $obj_escola_curso = new clsPmieducarEscolaCurso();
        $lst_escola_curso = $obj_escola_curso->lista($this->ref_cod_escola, null, null, null, null, null, null, null, 1);
        if (is_array($lst_escola_curso) && count($lst_escola_curso)) {
            foreach ($lst_escola_curso as $escola_curso) {
                $opcoes_curso["{$escola_curso["ref_cod_curso"]}"] = $escola_curso['nm_curso'];
            }
        }
    } else {
        if ($this->ref_cod_instituicao) {
            $opcoes_curso = array("" => "Selecione");
            $obj_curso = new clsPmieducarCurso();
            $obj_curso->setOrderby("nm_curso ASC");
            if ($sem_padrao) {
                $lista = $obj_curso->lista(null, 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, 0);
            } else {
                $lista = $obj_curso->lista(null, 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);
Example #3
0
 function Editar()
 {
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     @session_write_close();
     $obj_permissoes = new clsPermissoes();
     $obj_permissoes->permissao_cadastra(561, $this->pessoa_logada, 3, "educar_escola_lst.php");
     //
     //		echo "<br>cep: ".$this->cep;
     //		echo "<br>cep_: ".$this->cep_;die;
     if ($this->cod_escola) {
         $obj = new clsPmieducarEscola($this->cod_escola, null, $this->pessoa_logada, $this->ref_cod_instituicao, $this->ref_cod_escola_localizacao, $this->ref_cod_escola_rede_ensino, $this->ref_idpes, $this->sigla, null, null, 1);
         $editou = $obj->edita();
     } else {
         $obj = new clsPmieducarEscola(null, $this->pessoa_logada, null, $this->ref_cod_instituicao, $this->ref_cod_escola_localizacao, $this->ref_cod_escola_rede_ensino, $this->ref_idpes, $this->sigla, null, null, 1);
         $editou = $obj->cadastra();
         $this->cod_escola = $editou;
     }
     if ($editou) {
         if ($this->com_cnpj) {
             $objPessoa = new clsPessoa_($this->ref_idpes, null, false, $this->p_http, false, $this->pessoa_logada, date("Y-m-d H:i:s", time()), $this->p_email);
             $editou1 = $objPessoa->edita();
             if ($editou1) {
                 $obj_pes_juridica = new clsJuridica($this->ref_idpes, $this->cnpj, $this->fantasia, false, false, false, $this->pessoa_logada);
                 $editou2 = $obj_pes_juridica->edita();
                 if ($editou2) {
                     $objTelefone = new clsPessoaTelefone($this->ref_idpes);
                     $objTelefone->excluiTodos();
                     $objTelefone = new clsPessoaTelefone($this->ref_idpes, 1, str_replace("-", "", $this->p_telefone_1), $this->p_ddd_telefone_1);
                     $objTelefone->cadastra();
                     $objTelefone = new clsPessoaTelefone($this->ref_idpes, 2, str_replace("-", "", $this->p_telefone_2), $this->p_ddd_telefone_2);
                     $objTelefone->cadastra();
                     $objTelefone = new clsPessoaTelefone($this->ref_idpes, 3, str_replace("-", "", $this->p_telefone_mov), $this->p_ddd_telefone_mov);
                     $objTelefone->cadastra();
                     $objTelefone = new clsPessoaTelefone($this->ref_idpes, 4, str_replace("-", "", $this->p_telefone_fax), $this->p_ddd_telefone_fax);
                     $objTelefone->cadastra();
                     $objEndereco = new clsPessoaEndereco($this->ref_idpes);
                     $detEndereco = $objEndereco->detalhe();
                     if ($this->cep) {
                         $this->cep_ = idFederal2int($this->cep);
                     }
                     $this->cep = $this->cep;
                     //echo "$this->ref_idpes, $this->cep_, $this->idlog, $this->idbai, $this->numero, $this->complemento, false, false, false, false, $this->andar ";die;
                     //echo "<pre>";print_r($this);die;
                     /*					$objEndereco2 = new clsPessoaEndereco( $this->ref_idpes, $this->cep_, $this->idlog, $this->idbai, $this->numero, $this->complemento, false, false, false, false, $this->andar );
                     						if ( $detEndereco && $this->cep_ && $this->idlog && $this->idbai )
                     							$objEndereco2->edita();
                     						elseif ( $this->cep_ && $this->idlog && $this->idbai )
                     							$objEndereco2->cadastra();
                     
                     						elseif ( $detEndereco )
                     						{
                     							$objEndereco2->exclui();
                     							//$this->cep = $this->cep;
                     							$objEnderecoExterno = new clsEnderecoExterno( $this->ref_idpes );
                     							$detEnderecoExterno = $objEnderecoExterno->detalhe();
                     
                     							//$this->cep = idFederal2int($this->cep) ;
                     							$objEnderecoExterno2 = new clsEnderecoExterno( $this->ref_idpes, "1", $this->idtlog, $this->logradouro, $this->numero, false, $this->complemento, $this->bairro, $this->cep_, $this->cidade, $this->sigla_uf, false, false, false, $this->andar );
                     							if( $detEnderecoExterno )
                     							{
                     								$objEnderecoExterno2->edita();
                     								if ( $detEndereco )
                     									$objEndereco->exclui();
                     							}
                     							else
                     							{
                     								$objEnderecoExterno2->cadastra();
                     								if ( $detEndereco )
                     									$objEndereco->exclui();
                     							}
                     						}
                     						else
                     						{
                     							$objEnderecoExterno = new clsEnderecoExterno( $this->ref_idpes );
                     							$detEnderecoExterno = $objEnderecoExterno->detalhe();
                     
                     							$objEnderecoExterno2 = new clsEnderecoExterno( $this->ref_idpes, "1", $this->idtlog, $this->logradouro, $this->numero, false, $this->complemento, $this->bairro, $this->cep_, $this->cidade, $this->sigla_uf, false, false, false, $this->andar );
                     							if( $detEnderecoExterno )
                     							{
                     								$objEnderecoExterno2->edita();
                     							}
                     							else
                     							{
                     								$objEnderecoExterno2->cadastra();
                     							}
                     						}*/
                     if (!$this->isEnderecoExterno) {
                         //							die("Interno");
                         //							echo "<br>cep: ".$this->cep_;
                         //							$this->cep = idFederal2Int( $this->cep );
                         $this->cep = $this->cep_;
                         //							echo "<br>cep: ".$this->cep;
                         //							echo "<br>clsPessoaEndereco( $this->ref_idpes, $this->cep, $this->idlog, $this->idbai, $this->numero, $this->complemento, false )";die;
                         $objEndereco = new clsPessoaEndereco($this->ref_idpes, $this->cep, $this->idlog, $this->idbai, $this->numero, $this->complemento, false);
                         if ($objEndereco->detalhe()) {
                             $objEndereco->edita();
                         } else {
                             $objEndereco->cadastra();
                         }
                     } else {
                         //							echo "<br>Externo";
                         //							echo "<br>cep_: ".$this->cep_;
                         $this->cep = idFederal2int($this->cep);
                         //							echo "<br>cep: ".$this->cep;
                         //							echo "<br>clsEnderecoExterno( $this->ref_idpes, 1, $this->idtlog, $this->logradouro, $this->numero, $this->letra, $this->complemento, $this->bairro, $this->cep, $this->cidade, $this->sigla_uf, false )";
                         $objEnderecoExterno = new clsEnderecoExterno($this->ref_idpes, "1", $this->idtlog, $this->logradouro, $this->numero, $this->letra, $this->complemento, $this->bairro, $this->cep, $this->cidade, $this->sigla_uf, false);
                         if ($objEnderecoExterno->existe()) {
                             //								echo "<br>editar";
                             $objEnderecoExterno->edita();
                         } else {
                             //								echo "<br>cadastra";
                             $objEnderecoExterno->cadastra();
                         }
                     }
                     //-----------------------EDITA CURSO------------------------//
                     $this->escola_curso = unserialize(urldecode($this->escola_curso));
                     $obj = new clsPmieducarEscolaCurso($this->cod_escola);
                     $excluiu = $obj->excluirTodos();
                     if ($excluiu) {
                         if ($this->escola_curso) {
                             //								die("com cnpj");
                             foreach ($this->escola_curso as $campo) {
                                 $obj = new clsPmieducarEscolaCurso($this->cod_escola, $campo, null, $this->pessoa_logada, null, null, 1);
                                 $cadastrou_ = $obj->cadastra();
                                 if (!$cadastrou_) {
                                     $this->mensagem = "Edi&ccedil;&atilde;o n&atilde;o realizada.<br>";
                                     echo "<!--\nErro ao editar clsPmieducarEscolaCurso\nvalores obrigat&oacute;rios\nis_numeric( {$this->cod_serie} ) && is_numeric( {$campo} ) && is_numeric( {$this->pessoa_logada} )\n-->";
                                     return false;
                                 }
                             }
                         }
                     }
                     //-----------------------FIM EDITA CURSO------------------------//
                     $this->mensagem .= "Edi&ccedil;&atilde;o efetuada com sucesso.<br>";
                     header("Location: educar_escola_lst.php");
                     die;
                     return true;
                 }
                 /*if($this->cep && $this->idbai && $this->idlog)
                 		{
                 			$objEndereco = new clsPessoaEndereco( $this->ref_idpes );
                 			$objEndereco2 = new clsPessoaEndereco($this->ref_idpes,$this->cep,$this->idlog,$this->idbai,$this->numero,$this->complemento, false,false, false, false, $this->andar);
                 			if( $objEndereco->detalhe() )
                 			{
                 				$objEndereco2->edita();
                 			}
                 			else
                 			{
                 				$objEndereco2->cadastra();
                 			}
                 			$objPessoa = new clsPessoaFj();
                 			list( $this->cidade, $this->bairro, $this->logradouro, $this->cep, $this->idtlog, $this->sigla_uf, $this->bloco, $this->apartamento, $this->andar ) = $objPessoa->queryRapida($this->ref_idpes, "cidade", "bairro", "logradouro", "cep", "idtlog", "sigla_uf", "bloco", "apartamento", "andar" );
                 		}
                 		else
                 		{
                 			$this->cep_ = idFederal2int($this->cep_);
                 			$objEnderecoExterno = new clsEnderecoExterno( $this->ref_idpes );
                 			$objEnderecoExterno2 = new clsEnderecoExterno( $this->ref_idpes,"1",$this->idtlog,$this->logradouro,$this->numero,false,$this->complemento,$this->bairro,$this->cep_,$this->cidade,$this->sigla_uf,false,false,false, $this->andar);
                 			if( $objEnderecoExterno->detalhe() )
                 			{
                 				$objEnderecoExterno2->edita();
                 			}
                 			else
                 			{
                 				$objEnderecoExterno2->cadastra();
                 			}
                 		}*/
             }
         } else {
             if ($this->sem_cnpj) {
                 $objComplemento = new clsPmieducarEscolaComplemento($this->cod_escola, $this->pessoa_logada, null, idFederal2int($this->cep_), $this->numero, $this->complemento, $this->p_email, $this->fantasia, $this->cidade, $this->bairro, $this->logradouro, $this->p_ddd_telefone_1, $this->p_telefone_1, $this->p_ddd_telefone_fax, $this->p_telefone_fax);
                 $editou1 = $objComplemento->edita();
                 if ($editou1) {
                     //-----------------------EDITA CURSO------------------------//
                     $this->escola_curso = unserialize(urldecode($this->escola_curso));
                     $obj = new clsPmieducarEscolaCurso($this->cod_escola);
                     $excluiu = $obj->excluirTodos();
                     if ($excluiu) {
                         if ($this->escola_curso) {
                             //							die("sem cnpj");
                             foreach ($this->escola_curso as $campo) {
                                 $obj = new clsPmieducarEscolaCurso($this->cod_escola, $campo, null, $this->pessoa_logada, null, null, 1);
                                 $cadastrou_ = $obj->cadastra();
                                 if (!$cadastrou_) {
                                     $this->mensagem = "Edi&ccedil;&atilde;o n&atilde;o realizada.<br>";
                                     echo "<!--\nErro ao editar clsPmieducarEscolaCurso\nvalores obrigat&oacute;rios\nis_numeric( {$this->cod_serie} ) && is_numeric( {$campo[$i]} ) && is_numeric( {$this->pessoa_logada} )\n-->";
                                     return false;
                                 }
                             }
                         }
                     }
                     //-----------------------FIM EDITA CURSO------------------------//
                     $this->mensagem .= "Edi&ccedil;&atilde;o efetuada com sucesso.<br>";
                     header("Location: educar_escola_lst.php");
                     die;
                     return true;
                 } else {
                     $this->mensagem = "Edi&ccedil;&atilde;o n&atilde;o realizada (clsPmieducarEscolaComplemento).<br>";
                     //					echo "<!--\nErro ao editar clsPmieducarEscola\nvalores obrigatorios\nif( is_numeric( $this->cod_escola ) && is_numeric( $this->pessoa_logada ) )\n-->";
                     return false;
                 }
             }
         }
     }
     $this->mensagem = "Edi&ccedil;&atilde;o n&atilde;o realizada.<br>";
     echo "<!--\nErro ao editar clsPmieducarEscola\nvalores obrigatorios\nif( is_numeric( {$this->cod_escola} ) && is_numeric( {$this->pessoa_logada} ) )\n-->";
     return false;
 }
 function rematricularAlunosAprovados()
 {
     $obj_matricula = new clsPmieducarMatricula();
     $lst_matricula = $obj_matricula->lista(null, null, $this->ref_cod_escola, null, null, null, null, 1, null, null, null, null, 1, $this->ano - 1, null, null, 1);
     if (!is_array($lst_matricula)) {
         return;
     }
     foreach ($lst_matricula as $key => $matricula) {
         $obj_sequencia = new clsPmieducarSequenciaSerie();
         $lst_sequencia = $obj_sequencia->lista($matricula['ref_ref_cod_serie'], null, null, null, null, null, null, null, 1);
         if (is_array($lst_sequencia) && count($lst_sequencia) == 1) {
             $det_sequencia = array_shift($lst_sequencia);
             $serie_destino = $det_sequencia["ref_serie_destino"];
             $obj_serie = new clsPmieducarSerie($serie_destino);
             $det_serie = $obj_serie->detalhe();
             $obj_escola_curso = new clsPmieducarEscolaCurso($this->ref_cod_escola, $det_serie["ref_cod_curso"]);
             if (is_array($obj_escola_curso->detalhe())) {
                 $obj = new clsPmieducarMatricula($matricula['cod_matricula'], null, null, null, $this->pessoa_logada, null, null, null, null, null, 1, null, 0);
                 $editou = $obj->edita();
                 if ($editou) {
                     $obj = new clsPmieducarMatricula(null, null, $this->ref_cod_escola, $serie_destino, null, $this->pessoa_logada, $matricula['ref_cod_aluno'], 3, null, null, 1, $this->ano, 1, null, null, null, null, $det_serie["ref_cod_curso"]);
                     $cadastra = $obj->cadastra();
                     if (!$cadastra) {
                         echo "<script>\n\t\t\t\t\t\t\t\t\talert('Erro ao matricular os alunos da Escola!');\n\t\t\t\t\t\t\t\t\twindow.location = 'educar_escola_det.php?cod_escola={$this->ref_cod_escola}#ano_letivo';\n\t\t\t\t\t\t\t\t  </script>";
                     }
                 }
             }
         }
     }
 }
 					{
 						foreach ( $lst_escola_curso as $escola_curso )
 						{
 							//$obj_curso = new clsPmieducarCurso( $escola_curso["ref_cod_curso"] );
 						//$det_curso = $obj_curso->he();
 							if(isset($curso_padrao_ano_escolar) && $det_curso['padrao_ano_escolar'] != $curso_padrao_ano_escolar)
 								continue;
 							$todos_cursos_escola .= "escola_curso[escola_curso.length] = new Array( {$escola_curso["ref_cod_curso"]}, '{$escola_curso['nm_curso']}', {$escola_curso["ref_cod_escola"]}, {$escola_curso["padrao_ano_escolar"]} );\n";
 						}
 					}
 				}
 				echo "<script>{$todos_cursos_escola}</script>";*/
 $opcoes_curso = array("" => "Selecione");
 // EDITAR
 if ($this->ref_cod_escola) {
     $obj_esc_cur = new clsPmieducarEscolaCurso();
     $lst_esc_cur = $obj_esc_cur->lista($this->ref_cod_escola, null, null, null, null, null, null, null, 1);
     if (is_array($lst_esc_cur) && count($lst_esc_cur)) {
         foreach ($lst_esc_cur as $detalhe) {
             //							$obj_curso = new clsPmieducarCurso( $detalhe["ref_cod_curso"] );
             //							$det_curso = $obj_curso->detalhe();
             //							if ( is_array( $det_curso ) && count( $det_curso ) )
             //							{
             $opcoes_curso["{$detalhe['ref_cod_curso']}"] = "{$detalhe['nm_curso']}";
             //							}
         }
     }
 }
 /*elseif($this->ref_cod_curso)
 				{
 					$obj_curso = new clsPmieducarCurso();
 function escreveEscolas($curso)
 {
     $fonte = 'arial';
     $corTexto = '#000000';
     $esquerda = 30;
     $direita = 782;
     $altura = 20;
     $espaco = 150.4;
     $this->novoCabecalho($curso);
     $ref_cod_escola_localizacao = 0;
     $primeiro_loop = true;
     $totais = array();
     $index = 0;
     $total_geral_curso = array();
     foreach ($this->lst_escola as $escola) {
         $obj_escola_curso = new clsPmieducarEscolaCurso($escola["cod_escola"], $curso["cod_curso"]);
         $det_escola_curso = $obj_escola_curso->detalhe();
         $index = 0;
         if (is_array($det_escola_curso)) {
             if ($ref_cod_escola_localizacao != $escola["ref_cod_escola_localizacao"] && !$primeiro_loop) {
                 $this->escreveTotal($totais, $total_geral_curso, $ref_cod_escola_localizacao);
                 $ref_cod_escola_localizacao = $escola["ref_cod_escola_localizacao"];
                 if ($this->page_y > $this->pdf->altura - 50) {
                     $this->pdf->ClosePage();
                     $this->pdf->OpenPage();
                     $this->addCabecalho();
                     $this->novoCabecalho($curso);
                     $fonte = 'arial';
                     $corTexto = '#000000';
                     $esquerda = 30;
                     $direita = 782;
                     $altura = 20;
                     $espaco = 150.4;
                     $primeiro_loop = true;
                 }
             }
             if ($primeiro_loop) {
                 $ref_cod_escola_localizacao = $escola["ref_cod_escola_localizacao"];
                 $primeiro_loop = false;
             }
             $this->pdf->quadrado_relativo($esquerda, $this->page_y, $direita, $altura);
             $this->pdf->escreve_relativo($this->substituiNomeEscola($escola["nome"]), $esquerda, $this->page_y, $espaco - 30, 100, $fonte, 8, $corTexto, 'center');
             $obj_serie = new clsPmieducarSerie();
             $obj_serie->setOrderby("nm_serie");
             $lst_serie = $obj_serie->lista(null, null, null, $curso["cod_curso"], null, null, null, null, null, null, null, null, 1);
             $esquerda = $espaco;
             foreach ($lst_serie as $serie) {
                 $horarios = array(0 => "6:00:00", 1 => "12:55:00", 2 => "17:55:00");
                 //, 3 => "TOTAL");
                 $espaco = 150.4;
                 $qtd_series = 0;
                 $qtd_series_relatorio = 4;
                 $esquerda_aux = 0;
                 $qtd_total_turmas = 0;
                 $qtd_total_alunos = 0;
                 for ($i = 0; $i < 4; $i++) {
                     $obj_turma = new clsPmieducarTurma();
                     $lst_turma = $obj_turma->lista(null, null, null, $serie["cod_serie"], $escola["cod_escola"], null, null, null, null, null, null, null, null, null, 1, null, $horarios[$i], $horarios[$i + 1]);
                     $qtd_turma = $obj_turma->_total;
                     $qtd_alunos = 0;
                     if (is_array($lst_turma) && count($lst_turma)) {
                         foreach ($lst_turma as $turma) {
                             $obj_matricula = new clsPmieducarMatricula();
                             $lst_matricula = $obj_matricula->lista(null, null, $escola["cod_escola"], $serie["cod_serie"], null, null, null, array(1, 2, 3), null, null, null, null, 1, $this->ano, $curso["cod_curso"], $this->ref_cod_instituicao, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, $turma["cod_turma"]);
                             $qtd_alunos += $obj_matricula->_total;
                         }
                     }
                     if ($i > 2) {
                         $qtd_turma = $qtd_total_turmas;
                         $qtd_alunos = $qtd_total_alunos;
                         $totais[$index++] += $qtd_turma;
                         $totais[$index++] += $qtd_alunos;
                         $total_geral_serie_escola["turma"] += $qtd_total_turmas;
                         $total_geral_serie_escola["aluno"] += $qtd_total_alunos;
                         $faz_quadrado = false;
                     } else {
                         $qtd_total_turmas += $qtd_turma;
                         $qtd_total_alunos += $qtd_alunos;
                         $totais[$index++] += $qtd_turma;
                         $totais[$index++] += $qtd_alunos;
                         if (!$qtd_turma) {
                             $qtd_turma = "";
                         }
                         if (!$qtd_alunos) {
                             $qtd_alunos = "";
                         }
                         $faz_quadrado = true;
                     }
                     $this->pdf->linha_relativa($esquerda + $esquerda_aux, $this->page_y, 0, $altura);
                     if (!empty($qtd_turma) || !$faz_quadrado) {
                         $this->pdf->escreve_relativo($qtd_turma, $esquerda + $esquerda_aux, $this->page_y + 4, $espaco / $qtd_series_relatorio / 2, 100, $fonte, 8, $corTexto, 'center');
                     } else {
                         $this->pdf->quadrado_relativo($esquerda + $esquerda_aux + 1, $this->page_y + 1, $espaco / $qtd_series_relatorio / 2 - 1, $altura - 1, 0.5, "#A1B3BD", "");
                     }
                     $this->pdf->linha_relativa($esquerda + $esquerda_aux + $espaco / $qtd_series_relatorio / 2, $this->page_y, 0, $altura);
                     if (!empty($qtd_alunos) || !$faz_quadrado) {
                         $this->pdf->escreve_relativo($qtd_alunos, $esquerda + $esquerda_aux + $espaco / $qtd_series_relatorio / 2, $this->page_y + 4, $espaco / $qtd_series_relatorio / 2, 100, $fonte, 8, $corTexto, 'center');
                     } else {
                         $this->pdf->quadrado_relativo($esquerda + $esquerda_aux + $espaco / $qtd_series_relatorio / 2 + 1, $this->page_y + 1, $espaco / $qtd_series_relatorio / 2 - 1, $altura - 1, 0.5, "#A1B3BD", "");
                     }
                     $this->pdf->linha_relativa($esquerda + $esquerda_aux + $espaco / $qtd_series_relatorio, $this->page_y, 0, $altura);
                     $esquerda_aux += $espaco / $qtd_series_relatorio;
                 }
                 $esquerda += $espaco;
             }
             $aux = 91;
             $total_geral_curso["turma"] += $total_geral_serie_escola["turma"];
             $total_geral_curso["aluno"] += $total_geral_serie_escola["aluno"];
             $this->pdf->escreve_relativo($total_geral_serie_escola["turma"], $esquerda, $this->page_y + 4, ($espaco + $aux) / $qtd_series_relatorio / 2, 100, $fonte, 8, $corTexto, 'center');
             $this->pdf->linha_relativa($esquerda + ($espaco - $aux) / 2, $this->page_y, 0, $altura);
             $this->pdf->escreve_relativo($total_geral_serie_escola["aluno"], $esquerda + ($espaco - $aux) / 2, $this->page_y + 4, ($espaco + $aux) / $qtd_series_relatorio / 2, 100, $fonte, 8, $corTexto, 'center');
             $this->pdf->linha_relativa($esquerda + $espaco - $aux, $this->page_y, 0, $altura);
             $total_geral_serie_escola = array();
             $this->page_y += 20;
             $esquerda = 30;
         }
         if ($this->page_y > $this->pdf->altura - 50) {
             $this->pdf->ClosePage();
             $this->pdf->OpenPage();
             $this->addCabecalho();
             $this->novoCabecalho($curso);
             $fonte = 'arial';
             $corTexto = '#000000';
             $esquerda = 30;
             $direita = 782;
             $altura = 20;
             $espaco = 150.4;
             $primeiro_loop = true;
         }
     }
     $this->escreveTotal($totais, $total_geral_curso, $ref_cod_escola_localizacao);
     $this->escreveTotalGeral();
 }
        $opcoes = array("" => "Erro na geracao");
    }
    $this->campoLista("ref_ref_cod_serie", "Série", $opcoes, $this->ref_ref_cod_serie, "", false, "", "", false, $obrigatorio);
} elseif ($privilegio == 1) {
    // foreign keys
    include "include/pmieducar/educar_pesquisa_instituicao_escola.php";
    $opcoes = array("" => "Selecione");
    if (class_exists("clsPmieducarEscola")) {
        $obj_escola = new clsPmieducarEscola(null, null, null, $permissoes->getInstituicao($this->pessoa_logada), null, null, null, null, null, null, 1);
        $lst_escola = $obj_escola->lista(null, null, null, $permissoes->getInstituicao($this->pessoa_logada), null, null, null, null, null, null, 1);
        if ($lst_escola) {
            $cursos = '';
            $series = '';
            foreach ($lst_escola as $escola) {
                if (class_exists("clsPmieducarEscolaCurso")) {
                    $objTemp = new clsPmieducarEscolaCurso();
                    $lista = $objTemp->lista($escola["cod_escola"], null, null, null, null, null, null, null, 1);
                    $cursos .= " escola['_{$escola["cod_escola"]}'] = new Array();\n";
                    if ($lista) {
                        foreach ($lista as $registro) {
                            if (class_exists("clsPmieducarCurso")) {
                                $objTemp = new clsPmieducarCurso($registro["ref_cod_curso"]);
                                $detalhe = $objTemp->detalhe();
                                $series .= " curso['_{$registro["ref_cod_curso"]}'] = new Array();\n";
                                $cursos .= " escola['_{$registro["ref_cod_escola"]}'][escola['_{$registro["ref_cod_escola"]}'].length] = new Array( {$detalhe["cod_curso"]}, '{$detalhe["nm_curso"]}' );\n";
                                if ($editar) {
                                    $opcoes["{$registro["ref_cod_curso"]}"] = "{$detalhe["nm_curso"]}";
                                } else {
                                    $opcoes[""] = "Selecione um curso";
                                }
                                if (class_exists("clsPmieducarSerie")) {