<?php
$conn=pg_pconnect("dbname=emecmistica user=postgres");
If  ($submit) {

$titulo_es=trim($titulo_es);
$longtitulo_es=strlen($titulo_es);
$titulo_es=addslashes($titulo_es);
$titulo_en=trim($titulo_en);
$longtitulo_en=strlen($titulo_en);
$titulo_en=addslashes($titulo_en);
$titulo_fr=trim($titulo_fr);
$longtitulo_fr=strlen($titulo_fr);
$titulo_fr=addslashes($titulo_fr);
$titulo_po=trim($titulo_po);
$longtitulo_po=strlen($titulo_po);
$titulo_po=addslashes($titulo_po);

//la date
$equidate = array(
    "jj"  => array("1"=>"01","2"=>"02","3"=>"03", "4"=>"04","5"=>"05", "6"=>"06","7"=>"07","8"=>"08","9"=>"09"),
 "cf"  => array("01"=>"1","02"=>"2","03"=>"3", "04"=>"4","05"=>"5", "06"=>"6","07"=>"7","08"=>"8","09"=>"9") ,   
"mm"  => array("Jan"=>"01","Feb"=>"02","Mar"=>"03", "Apr"=>"04","May"=>"05","Jun"=>"06","Jul"=>"07","Aug"=>"08","Sep"=>"09","Oct"=>"10", "Nov"=>"11", "Dec"=>"12"));


$datebrute=$fechfech;
$tableau=explode (" ", $datebrute);
$nbcase=count($tableau);

$case=$tableau[0];
$jour=$tableau[1];

$moisenlettres=$tableau[2];
$mois=$equidate ["mm"]["$moisenlettres"];
$an=$tableau[3];
$heurinterm=$tableau[4];
$tabheur=explode(":", $heurinterm);
$heure=$tabheur[0];
$min=$tabheur[1];
$sec=$tabheur[2];
$signe=substr("$tableau[5]", 0,1);
$autre=substr("$tableau[5]", 1);
$decal=$autre/100;
$heuredecalee="$heure, $min, $sec, $mois, $jour, $an";
$timestampdecale=mktime($heure, $min, $sec, $mois, $jour, $an);
$datar=date("D, d m Y H:i:s", $timestampdecale);


$query=pg_exec($conn, "insert into mensajes (id_mensaje, codigo_idioma_mensaje_original, id_creador, web, special, fecha, mail) values ('$id_mensaje', '$codigo_idioma_mensaje_original', '$creador', '0', '0', '$timestampdecale', '1')");

//determination des palabras_claves
$num=count($palabras_claves);
if (($num>0) && ($num <6)) {
$del= pg_exec($conn, "delete from grupo_palabras where id_mensaje='$id_mensaje'");
for ($n=0; $n<$num; $n++) {
$pacl=pg_exec ($conn, "insert into grupo_palabras (id_palabra, id_mensaje) values ('$palabras_claves[$n]', '$id_mensaje')");
//$get=pg_fetch_row($pacl,0); 
}

}

//determination du numero de synthese
$catnu=pg_exec($conn, "update mensajes set num_synthese='$numero' where id_mensaje='$id_mensaje'");

//determination de la date de der modif
$fecha_dia=trim($fecha_dia);
$catnu=pg_exec($conn, "update mensajes set fecha_dia='$fecha_dia' where id_mensaje='$id_mensaje'");

//saisie dates et auteur 


$queryca = pg_exec($conn,"update mensajes set id_categoria='$categoria' where id_mensaje='$id_mensaje'");
$querytete = pg_exec($conn,"update mensajes set id_tema='$tema' where id_mensaje='$id_mensaje'");

if ($longtitulo_es !=0) {
$queryties = pg_exec($conn,"update mensajes set titulo_es='$titulo_es' where id_mensaje='$id_mensaje'");
}
if ($longtitulo_en !=0) {
$querytien = pg_exec($conn,"update mensajes set titulo_en='$titulo_en' where id_mensaje='$id_mensaje'");
}
if ($longtitulo_fr !=0) {
$querytifr = pg_exec($conn,"update mensajes set titulo_fr='$titulo_fr' where id_mensaje='$id_mensaje'");
}
if ($longtitulo_po !=0) {
$querytipo = pg_exec($conn,"update mensajes set titulo_po='$titulo_po' where id_mensaje='$id_mensaje'");
}

//saisie fuente 
$nombre_fuente=trim($nombre_fuente);
$nombre_fuente=addslashes($nombre_fuente);
$longnomfuente=strlen($nombre_fuente);
$e_mail_fuente=trim($e_mail_fuente);
$e_mail_fuente=addslashes($e_mail_fuente);
$longmailfuente=strlen($e_mail_fuente);
$lista_fuente=trim($lista_fuente);
$lista_fuente=addslashes($lista_fuente);
$longlistafuente=strlen($lista_fuente);
$e_mail_lista=trim($e_mail_lista);
$e_mail_lista=addslashes($e_mail_lista);
$longelistafuente=strlen($e_mail_lista);

if ($longnomfuente !=0) {
$intfuente = pg_exec($conn,"update mensajes set nombre_fuente = '$nombre_fuente' where id_mensaje = '$id_mensaje'"); 
}
else {
$intfuente = pg_exec($conn,"update mensajes set nombre_fuente = NULL where id_mensaje = '$id_mensaje'");  
}
if ($longmailfuente !=0) {
$intfuente2 = pg_exec($conn,"update mensajes set e_mail_fuente = '$e_mail_fuente' where id_mensaje = '$id_mensaje'");  
}
else {
$intfuente2 = pg_exec($conn,"update mensajes set e_mail_fuente =NULL where id_mensaje = '$id_mensaje'");  
}
if ($longlistafuente !=0) {
$intfuente3 = pg_exec($conn,"update mensajes set lista_fuente = '$lista_fuente' where id_mensaje = '$id_mensaje'");  
}
else {
$intfuente3 = pg_exec($conn,"update mensajes set lista_fuente = NULL where id_mensaje = '$id_mensaje'");  
}
if ($longelistafuente !=0) {
$intfuente4 = pg_exec($conn,"update mensajes set e_mail_lista = '$e_mail_lista' where id_mensaje = '$id_mensaje'");  
}
else {
$intfuente4 = pg_exec($conn,"update mensajes set e_mail_lista = NULL where id_mensaje = '$id_mensaje'");  
}


//saisie reply
if ($reply) {
$intreply = pg_exec($conn,"update mensajes set reply = '$reply' where id_mensaje = '$id_mensaje'"); 
}
else {
$intreply = pg_exec($conn,"update mensajes set reply = NULL where id_mensaje = '$id_mensaje'");  
}



//saisie de notes sur un message
$notas_men=trim($notas_men);
$longnotas=strlen($notas_men);
if ($longnotas !=0) {
$notas_men=addslashes($notas_men);
$notas_men= htmlentities($notas_men);
$intnot = pg_exec($conn,"update mensajes set notas = '$notas_men' where id_mensaje = '$id_mensaje'");  
}
else {
$intnot = pg_exec($conn,"update mensajes set notas = NULL where id_mensaje = '$id_mensaje'");  
}


$men_es=trim($men_es);
$longmenes=strlen($men_es);
$querydelmenes= pg_exec($conn, "delete from mensaje_original where id_mensaje='$id_mensaje' and codigo_idioma='es'");
if ($longmenes!=0) {
$maxid = pg_exec($conn, "SELECT max(id_chunk_mensaje_original) FROM
mensaje_original");  
$maxget = pg_fetch_row($maxid, 0); 
$chunkid= $maxget[0]; 
$contenido=$men_es;
include ("transfo.php3");
$n=0;
do {
 $chunkid++;
$insertchunk=pg_exec($conn, "insert into mensaje_original(id_chunk_mensaje_original, codigo_idioma, id_mensaje, contenido) values('$chunkid', 'es', '$id_mensaje', '$chunk[$n]')");
$n++;
} while ($n < ($chunkcount - 1));
} 
$men_en=trim($men_en);
$longmenen=strlen($men_en);
$querydelsin= pg_exec($conn, "delete from mensaje_original where id_mensaje='$id_mensaje' and codigo_idioma='en'");
if ($longmenen!=0) {
$maxid = pg_exec($conn, "SELECT max(id_chunk_mensaje_original) FROM
mensaje_original");  
$maxget = pg_fetch_row($maxid, 0); 
$chunkid= $maxget[0]; 
$contenido=$men_en;
include ("transfo.php3");
$n=0;
do {
 $chunkid++;
$insertchunk=pg_exec($conn, "insert into mensaje_original
(id_chunk_mensaje_original, codigo_idioma, id_mensaje, contenido) values
('$chunkid', 'en', '$id_mensaje', '$chunk[$n]')");
$n++;
} while ($n < ($chunkcount - 1));
}
$men_fr=trim($men_fr);
$longmenfr=strlen($men_fr);
$querydelmenfr= pg_exec($conn, "delete from mensaje_original where id_mensaje='$id_mensaje' and codigo_idioma='fr'");
if ($longmenfr!=0) {
$maxid = pg_exec($conn, "SELECT max(id_chunk_mensaje_original) FROM
mensaje_original");  
$maxget = pg_fetch_row($maxid, 0); 
$chunkid= $maxget[0]; 
$contenido=$men_fr;
include ("transfo.php3");
$n=0;
do {
 $chunkid++;
$insertchunk=pg_exec($conn, "insert into mensaje_original
(id_chunk_mensaje_original, codigo_idioma, id_mensaje, contenido) values
('$chunkid', 'fr', '$id_mensaje', '$chunk[$n]')");
$n++;
} while ($n < ($chunkcount - 1));
}
$men_po=trim($men_po);
$longmenpo=strlen($men_po);
$querydelmenpo= pg_exec($conn, "delete from mensaje_original where id_mensaje='$id_mensaje' and codigo_idioma='po'");
if ($longmenpo!=0) {
$maxid = pg_exec($conn, "SELECT max(id_chunk_mensaje_original) FROM
mensaje_original");  
$maxget = pg_fetch_row($maxid, 0); 
$chunkid= $maxget[0]; 
$contenido=$men_po;
include ("transfo.php3");
$n=0;
do {
 $chunkid++;
$insertchunk=pg_exec($conn, "insert into mensaje_original(id_chunk_mensaje_original, codigo_idioma, id_mensaje, contenido) values
('$chunkid', 'po', '$id_mensaje', '$chunk[$n]')");
$n++;
} while ($n < ($chunkcount - 1));
}
//queryweb
$queryweb=pg_exec($conn, "select web from mensajes where id_mensaje='$id_mensaje'");
$getweb=pg_fetch_row($queryweb, 0);
$web=$getweb[0];


include "controlviejos.php3";

include "tete.php3";
?>
<FORM ACTION="/mistica/bdadmin/formu4.php3" METHOD="POST"> 
<INPUT TYPE=hidden NAME=id_mensaje VALUE="<?echo $id_mensaje?>">
<INPUT TYPE="Submit" name="submit" value="Incluir una asociacion">
</form>
<?
}

?>


