> Manuales > Gestión de archivos en PHP

Este script PHP sirve basicamente para remplazar varios textos que esten en una base de datos MySql por un texto dado y almacenado en una tabla.

GENERAR CONTRATOS

Este script sirve basicamente para remplazar varios textos que esten en la base de datos por unas respuestas dadas y almacenadas en una tabla.

<?
/* CABEZA DEL FORMULARIO FUNCTION*/
cabeza_selector();
/* SEGMENTO PARA GUARDAS CLAUSULAS ASOCIADAS A LAS RESPUESTAS EN UNA TEMPORAL*/

$claves = mysql_query("select tem_claves.id_respuesta, tem_claves.id_pregunta,
respuestas.detalle_respuesta, cuestionario.pregunta from tem_claves, respuestas, cuestionario
where tem_claves.clave_excluyente = $id and respuestas.id_r_2 = tem_claves.id_respuesta and cuestionario.id = tem_claves.id_pregunta");
$numero = mysql_num_rows($claves);

$claves2 = mysql_query("select tem_claves.id_respuesta, tem_claves.id_pregunta,
respuestas.detalle_respuesta, cuestionario.pregunta from tem_claves, respuestas, cuestionario
where tem_claves.clave_excluyente = $id and respuestas.id_r_2 = tem_claves.id_respuesta and cuestionario.id = tem_claves.id_pregunta");

while($rowr = mysql_fetch_array($claves2))
{
$clausulas = mysql_query("select * from asociacion_clausulas, clausulas where
asociacion_clausulas.id_respuesta = '$rowr[0]' and clausulas.id = asociacion_clausulas.id_clausula");

while($rowc = mysql_fetch_array($clausulas))
{
$ingresar = mysql_query("insert into tem_clausulas (id_clausula, id_respuesta, clausula, clave_excluyente) values
($rowc[1], $rowr[0], '$rowc[5]', $id)");
}
}

/*SEGMENTO PARA REEMPLAZAR PARRAFOS,
1. ASOCIAR LOS PARRAFOS EN EL LUGAR DE LA CLAUSULA QUE SE DESEE PARA QUE SEA BUSCADA Y REMPLAZA POR LA RESPUESTA SELECCIONADA

2. ES IMPORTANTE CREAR UNA CLAVE IGUAL A LA RESPUESTA E INCLUIR ESTA CLAVE EN LA CLAUSULA, DE ESTA MANERA EL BUSCADOR ENCONTRARA ESTA CLAVE, BUSCARA EL PARRAFO CON ID DE LA CLAVE LO TRAERA Y LO REEMPLAZARA POR EL PARRAFO

EJEMPLO: TENEMOS UNA CLAUSULA PREAMBULO LA CUAL TIENE QUE ESTAR ARMADA POR UN PARRAFO, PERO ESTE PARRAFO DEPENDE DE UNA RESPUESTA SELECCIONADA

PREAMBULO CON PARRAFO 'ESTE ES UN EJEMPLO' SI LA RESPUESTA DADA ES QUE EJEMPLO Y ESTA RESPUETA GENERA LA CLAVE -1254- ENTONCES EN LA CLAUSULA PREAMBULO ASOCIAMOS

01 PREAMBULO
-1254-

*/ /* $clave2 = mysql_query("select distinct parrafos.id, parrafos.detalle from tem_claves, asociar_parrafos, parrafos where tem_claves.clave_excluyente = $id
and asociar_parrafos.id_respuesta = tem_claves.id_respuesta and parrafos.id =
asociar_parrafos.id_parrafo"); */
$clave2 = mysql_query("select distinct parrafos.id, parrafos.detalle from parrafos");
while($rowcl = mysql_fetch_array($clave2))
{
$modificar1 = mysql_query("select clausula from tem_clausulas where clave_excluyente = $id order by id_respuesta");
$cantidad = mysql_num_rows($modificar1) -1;

$i = 0;
for($i;$i<= $cantidad;$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 clave_excluyente = $id and clausula = '$r'");
}
}
/* EL RESULTADO ES
01 PREAMBULO
'ESTE ES UN EJEMPLO'
DIGAMOS QUE EL PARRAFO Y LA CLAUSULA LE ASOCIAMOS UNA CLAVE PARA SER REEMPLAZADA POR OTRA RESPUESTA

EJEM
01 PREAMBULO
-1684-
'ESTE ES UN EJEMPLO -1896-'

Y ESTA CLAVES PERTENECEN AL RESPUESTA:
-1684- = HOLA
-1896- = MUNDO

/*SEGMENTO PARA REEMPLAZAR CLAVES
UNA VEZ INCLUIDO EL PARRAFO

*/ $clave2 = mysql_query("select * from tem_claves where clave_excluyente = $id");
while($rowcl = mysql_fetch_array($clave2))
{
$modificar1 = mysql_query("select clausula from tem_clausulas where clave_excluyente = $id order by id_respuesta");
$cantidad = mysql_num_rows($modificar1) -1;
$i = 0;
for($i;$i<= $cantidad;$i++)
{
$r = mysql_result($modificar1,$i);
$cm2 = str_replace('-'.$rowcl[0].'-', $rowcl[2], $r);
$ing = mysql_query("update tem_clausulas set clausula = '$cm2' where clave_excluyente = $id and clausula = '$r'");
}
}
/* EL RESULTADO ES

01
01 PREAMBULO
HOLA
'ESTE ES UN EJEMPLO MUNDO'

SEGMENTO PARA IMPRIMIR CONTRATO

*/
$genera_contrato= mysql_query("select distinct clausulas.numero_clausula, clausulas.titulo, clausulas.tipo_clausula,
tem_clausulas.clausula from tem_clausulas, clausulas
where tem_clausulas.clave_excluyente = $id
and clausulas.id = tem_clausulas.id_clausula order by clausulas.numero_clausula");

while($cont = mysql_fetch_array($genera_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>
<?
pie_selector();
?>

Rene Sterling Neira

Manual