Personalização de documentos com PHP
Este script PHP serve basicamente para substituir vários textos que estejam em um banco de dados MySql por um texto dado e armazenado em uma tabela.Por Rene Sterling Neira
Publicado em: 26/6/09
GERAR CONTRATOS
Este script serve basicamente para substituir vários textos que estejam na banco de dados por umas respostas dadas e armazenadas em uma tabela.
<?
/* CABECA DO FORMULARIO FUNCTION*/
cabeca_selector();
/* SEGMENTO PARA SALVAR CLAUSULAS ASSOCIADAS ÀS RESPOSTAS EM UMA TEMPORARIA*/
$senha = mysql_query("select tem_senhas.id_resposta, tem_senhas.id_pergunta,
respostas.detalhe_resposta, questionario.pergunta from tem_senhas, respostas, questionario
where tem_senhas.senha_excluiente = $id and respostas.id_r_2 = tem_senhas.id_resposta and questionario.id = tem_senha.id_pergunta");
$numero = mysql_num_rows($senhas);
$senha2 = mysql_query("select tem_senhas.id_resposta, tem_senhas.id_pergunta,
respostas.detalhe_resposta, questionario.pergunta from tem_senhas, respostas, questionario
where tem_senhas.senha_excluiente = $id and respostas.id_r_2 = tem_senhas.id_resposta and questionario.id = tem_senhas.id_pergunta");
while($rowr = mysql_fetch_array($senhas2))
{
$clausulas = mysql_query("select * from associacao_clausulas, clausulas where
associacao_clausulas.id_resposta = '$rowr[0]' and clausulas.id = associacao_clausulas.id_clausula");
while($rowc = mysql_fetch_array($clausulas))
{
$ingressar = mysql_query("insert into tem_clausulas (id_clausula, id_resposta, clausula, senha_excluyente) values
($rowc[1], $rowr[0], '$rowc[5]', $id)");
}
}
/*SEGMENTO PARA SUBSTITUIR PARAGRAFOS,
1. ASSOCIAR OS PARAGRAFOS NO LUGAR DA CLAUSULA QUE SE DESEJE PARA QUE SEJA BUSCADA E SUBSTITUIDA PELA RESPOSTA
SELECIONADA
2. É IMPORTANTE CRIAR UMA SENHA IGUAL À RESPOSTA E INCLUIR ESTA SENHA NA CLAUSULA, DESTA MANERA O BUSCADOR ENCONTRARÁ ESTA SENHA, BUSCARÁ O PARÁGRAFO COM ID DA SENHA, O TRARÁ E O SUBTITUIRÁ PELO PARÁGRAFO
EXEMPLO: TEMOS UMA CLAUSULA PRELIMINAR QUE TEM QUE ESTAR ARMADA POR UM PARÁGRAFO, PORÉM ESTE PARÁGRAFO DEPENDE DE UMA RESPOSTA SELECIONADA
PRELIMINAR COM PARÁGRAFO 'ESTE É UM EXEMPLO' SE A RESPOSTA DADA É QUE EXEMPLO E ESTA RESPOSTA GERA A SENHA -1254-
ENTÃO NA CLAUSULA PRELIMINAR ASSOCIAMOS
01 PRELIMINAR
-1254-
*/
/* $senha2 = mysql_query("select distinct paragrafos.id, paragrafos.detalhe from tem_senhas, associar_paragrafos, paragrafos where tem_senhas.senha_excluiente = $id
and associar_paragrafos.id_resposta = tem_senhas.id_resposta and paragrafos.id =
associar_paragrafos.id_paragrafo");
*/
$senha2 = mysql_query("select distinct paragrafos.id, paragrafos.detalhe from paragrafos");
while($rowcl = mysql_fetch_array($senha2))
{
$modificar1 = mysql_query("select clausula from tem_clausulas where senha_excluiente = $id order by id_resposta");
$quantidade = mysql_num_rows($modificar1) -1;
$i = 0;
for($i;$i<= $quantidade;$i++)
{
$r = mysql_result($modificar1,$i);
$cm2 = str_replace('-par'.$rowcl[0].'-', $rowcl[1], $r);
$ing = mysql_query("update tem_clausulas set clausula = '$cm2' where senha_excluiente = $id and clausula = '$r'");
}
}
/* O RESULTADO É
01 PRELIMINAR
'ESTE É UM EXEMPLO'
DIGAMOS QUE O PARÁGRAFO E A CLAUSULA LHE ASSOCIAMOS UMA SENHA PARA SER SUBSTITUIDA POR OUTRA RESPOSTA
EXEMPLO
01 PRELIMINAR
-1684-
'ESTE É UM EXEMPLO -1896-'
E ESTAS SENHAS PERTENECEM A RESPOSTA:
-1684- = OLA
-1896- = MUNDO
/*SEGMENTO PARA SUBSTITUIR SENHAS
UMA VEZ INCLUIDO O PARAGRAFO
*/
$senha2 = mysql_query("select * from tem_senhas where senha_excluiente = $id");
while($rowcl = mysql_fetch_array($senha2))
{
$modificar1 = mysql_query("select clausula from tem_clausulas where senha_excluiente = $id order by id_resposta");
$quantidade = mysql_num_rows($modificar1) -1;
$i = 0;
for($i;$i<= $quantidade;$i++)
{
$r = mysql_result($modificar1,$i);
$cm2 = str_replace('-'.$rowcl[0].'-', $rowcl[2], $r);
$ing = mysql_query("update tem_clausulas set clausula = '$cm2' where senha_excluiente = $id and clausula = '$r'");
}
}
/* O RESULTADO É
01
01 PRELIMINAR
OLA
'ESTE É UM EXEMPLO MUNDO'
SEGMENTO PARA IMPRIMIR CONTRATO
*/
$gera_contrato= mysql_query("select distinct clausulas.numero_clausula, clausulas.titulo, clausulas.tipo_clausula,
tem_clausulas.clausula from tem_clausulas, clausulas
where tem_clausulas.senha_excluiente = $id
and clausulas.id = tem_clausulas.id_clausula order by clausulas.numero_clausula");
while($cont = mysql_fetch_array($gera_contrato))
{?>
<form method='POST' action='--WEBBOT-SELF--'>
<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='100%' id='AutoNumber1'>
<tr>
<td width='50%'><font color="#FF9933"><? echo $cont[0].' '.$cont[1]; ?></font></td>
</tr>
<tr>
<td width='50%'><? echo $cont[3];?>
</td>
</tr>
<tr>
<td width='50%' height="31"></td>
</tr>
<? } ?>
</table>
</form>
</form>
<?
rodape_selector();
?>