<?
/**********************************************************************
Copyright (C) 2003 Fábio Coelho
Class Pagina - versão 1.0 alfa beta gama
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
www.freesoftwarefoundation.org
************************************************************************
Mais abstração em cima da classe modelo, de modo a definir TODA uma página
em matrizes, com um mínimo de codificação pra decidir qual parte carregar
************************************************************************/
include("modelo.php");
class Pagina
{
var $Pagina_Inicial = null;
// Vai receber o objeto modelo
// Will receive de "modelo" object
var $Bloco_Principal = "";
// Determina o nome do Bloco Principal do modelo
// Set the name of de Bloco Principal (Main Block) of the "modelo" object
function Pagina($Caminho)
{
// $Caminho Determina o local dos arquivos de modelos HTML
// $Caminho set the local of the HTML Templates files
$this->Pagina_Inicial = New modelo($Caminho);
}
function Carrega_Modelo_Base($Arquivos_modelo)
{
// A primeira chave da estrutura define o nome da seção principal
// $Arquivos_Modelo é um array associativo com as chaves representando
// os nomes das seções e os valores contendo os nomes do modelo HTML
// correspondente.
// The first key of the structure defines the name of the main section
// $Arquivo_Modelo, is an associative array indexed by the names of the
// sections and the values have the names of the HTML Template files.
$this->Bloco_Principal = key($Arquivos_modelo);
$this->Pagina_Inicial->Define($Arquivos_modelo);
}
function Blocos_Dinamicos($Blocos)
{
// Determina a hierarquia de blocos interna de cada arquivo html carregado.
// Set hierarchy of internal blocks of each HTML Template file loaded.
if(is_array($Blocos))
{
foreach($Blocos as $Bloco_ID => $Bloco_Conteiner)
{
$this->Pagina_Inicial->Define_Dinamico($Bloco_ID,$Bloco_Conteiner);
}
return true;
}
else
{
return false;
}
}
function Passa_Valores($Bloco, $Valores_do_Bloco)
{
// Recebe um array de arrays $Valores_do_Bloco, cada posição no array
// principal é um array em que as chaves são as marcas do $Bloco a serem
// substituídas pelos valores. Cada nova posição nesse array implica na
// repetição do bloco.
// Se você passar uma posição "codigo" => "123456" para ser passada ao $Bloco
// "detalhes", ele procurará "detalhes_codigo" (e não "codigo") e substituirá
// por "123456'.
// Receive an array of arrays $Valores_do_Bloco, each position in the main
// array is an array where the keys are the "marcas" (tags) of the $Bloco,
// that will be replaced by the values. Each new position on the main array
// implies in the block repetition.
// If you pass one position "cod_cli" => "123456" to be passed to $Bloco
// "details", it will search by "details_cod_cli" (and not "cod_cli") and will
// replace by "123456".
if(is_array($Valores_do_Bloco[0]))
{
for($i=0;$i<sizeof($Valores_do_Bloco);$i++)
{
$Linha = $Valores_do_Bloco[$i];
foreach($Linha as $Marca => $Valor_a_Passar)
{
$this->Pagina_Inicial->Atribui($Bloco."_".$Marca,$Valor_a_Passar);
}
$this->Pagina_Inicial->Insere('SAIDA_'.$Bloco,'.'.$Bloco);
}
}
}
function Valor_Principal($Marca, $Valor_a_Passar)
{
// Passando valores para marcas que não estejam em nenhum bloco ou html
// associado, mas no corpo do modelo base.
// Pass values to marks outside the dynamic blocks and/or HTML templates that
// are not de main HTML template.
$this->Pagina_Inicial->Atribui($Marca,$Valor_a_Passar);
}
function Finaliza($Tela = 1)
{
// Imprime o conteúdo em forma de HTML, no caso de ser passado False como
// parâmetro, ele retorna sem imprimir, de modo que o html possa ser tratado
// ou feita uma avaliação.
// Print the content as HTML code, if you pass an extra parameter False, it pass
// the code as the function return, whithout print.
$this->Pagina_Inicial->Insere( strtoupper($this->Bloco_Principal), $this->Bloco_Principal);
if($Tela)
{
$this->Pagina_Inicial->Modelo_Imprime(strtoupper($this->Bloco_Principal));
}
else
{
$this->Pagina_Inicial->Retorna(strtoupper($this->Bloco_Principal));
}
}
}
?>