


<?php


//date
//categorie
//theme
//mot-clef
//mot dans: titre, synthese, message, mots-clefs
//auteur
//un message avec ses reply
$sub=chr(13);
if (($submit)||($sub)) {
$conn=pg_pconnect("dbname=emecmistica user=postgres");
include "foo.php3";

$comp=0;


//initialisation
$pasderep=0;
if ((count($temi)==0) && (count($palabra)==0) && (!$palo) && (!$dia) && (count(!$totor)==0) && (!C2) && (!C3) && (!C4) && (!C5)) {
$pasderep=1;
}
else {
//par theme
if ((count($temi) !=0)&&($pasderep !=1)) {
for ($b=0; $b<count($temi); $b++) {
$phrac="$phrac id_tema='$temi[$b]' OR";
}
$phrac=substr($phrac, 0, -2);

$querytiti = pg_exec($conn,"select id_mensaje from mensajes where $phrac");
$wouv=pg_numrows($querytiti);
if ($wouv==0) {
$pasderep=1;
}
for ($z=0; $z<pg_numrows($querytiti);  $z++) {
$getiti=pg_fetch_row($querytiti, $z);
$arrayrep1[$comp]=$getiti[0];
$comp++;
}
}
$comp=0;

//categories
if ((($C2) || ($C3) || ($C4)||($C5)) &&($pasderep !=1)) { 
if ($C2) {
$phraxy="$phraxy id_categoria='C2' OR";
}
if ($C3) {
$phraxy="$phraxy id_categoria='C3' OR";
}
if ($C4) {
$phraxy="$phraxy id_categoria='C4' OR";
}
if ($C5) {
$phraxy="$phraxy special='t' OR";
}
$phraxy=substr($phraxy, 0, -2);

$wysir=count($arrayrep1);

if ($wysir !=0) {
$phrachin="";
for ($qr=0; $qr<count($arrayrep1); $qr++) {
$phrachin="$phrachin '$arrayrep1[$qr]',";
}
$phrachin=substr($phrachin, 0, -1);
$querycato = pg_exec($conn,"select distinct id_mensaje from mensajes where ($phraxy) and id_mensaje in ($phrachin)");
}
else {
$querycato= pg_exec($conn,"select distinct id_mensaje from mensajes where $phraxy");
}
if (pg_numrows($querycato)==0) {
$pasderep=1;
}

for ($zorro=0; $zorro<pg_numrows($querycato);  $zorro++) {
$getcato=pg_fetch_row($querycato, $zorro);
$arrayrep12[$zorro]=$getcato[0];
}
}

else {
$arrayrep12=$arrayrep1;
}



//liste de mots-clefs
$r=0;
$x=count($palabra);
if (($x !=0)&&($pasderep !=1)) {
for ($a=0; $a<count($palabra); $a++) {
$phra="$phra id_palabra='$palabra[$a]' OR";
}
$phra=substr($phra, 0, -2);

$wysiwyg=count($arrayrep12);

if ($wysiwyg !=0) {
$phrazin="";
for ($q=0; $q<count($arrayrep12); $q++) {
$phrazin="$phrazin '$arrayrep12[$q]',";
}
$phrazin=substr($phrazin, 0, -1);
$querypal = pg_exec($conn,"select distinct id_mensaje from grupo_palabras where ($phra) and id_mensaje in ($phrazin)");
}
else {
$querypal = pg_exec($conn,"select distinct id_mensaje from grupo_palabras where $phra");
}
if (pg_numrows($querypal)==0) {
$pasderep=1;
}

for ($z=0; $z<pg_numrows($querypal);  $z++) {
$getpal=pg_fetch_row($querypal, $z);
$arrayrep2[$z]=$getpal[0];
}
}

else {
$arrayrep2=$arrayrep12;
}

//palo

$palo=trim($palo);
$palo=stripslashes($palo);
$longpalo=strlen($palo);
if (($longpalo !=0)&&($paderep !=1)) {
if (count($arrayrep2) !=0) {
for ($p=0; $p<count($arrayrep2); $p++) {
$phrasin="$phrasin '$arrayrep2[$p]',";
}
$phrasin=substr($phrasin, 0, -1);
}
$arrpalito= explode (";", $palo);
for ($wf=0; $wf<count($arrpalito); $wf++) {
$palot1=$arrpalito[$wf];
$palot2=ucwords($arrpalito[$wf]);
$palot=foo($arrpalito[$wf]);
$palot3=strtoupper($palot);
$palot4=htmlentities($palot1);
$palot1=addslashes($palot1);
$palot2=addslashes($palot2);
$palot3=addslashes($palot3);
$palot4=addslashes($palot4);

if ($indice =="T") {
$tab="palabra_$idi";
$querypalabra=pg_exec($conn, "select distinct id_palabra from indice where $tab = '$palot1' or $tab='$palot2' or $tab ='$palot3'");
if (pg_numrows($querypalabra)==0) {
$querypalabra=pg_exec($conn, "select distinct id_palabra from indice where $tab like '%$palot1%' or $tab like '%$palot2%' or $tab like '%$palot3%'");
}
if (pg_numrows($querypalabra)!=0) {
for($t=0; $t<pg_numrows($querypalabra); $t++) {
$getidpala=pg_fetch_row($querypalabra, 0);
$palalala="$palalala $getidpala[0],";
}
$palalala=trim($palalala);
$longpalalala=strlen($palalala);
if ($longpalalala !=0) {
$palalala=substr($palalala,  0, -1);

if (count($arrayrep2) !=0) {
$querysipala=pg_exec($conn, "select distinct id_mensaje from grupo_palabras where id_palabra in ($palalala) and id_mensaje in ($phrasin)");
}
else {
$querysipala=pg_exec($conn, "select distinct id_mensaje from grupo_palabras where id_palabra in ($palalala)");
}
$zzre=count($arrayrep3);
$zzre++;
for ($zi=0; $zi<pg_numrows($querysipala);  $zi++) {
$getpala=pg_fetch_row($querysipala, $zi);
$arrayrep3[$zzre]=$getpala[0];
$zzre++;
}
}
}
}

if ($textintegral=="T") {
$contya=0;
if (count($arrayrep2) !=0) {
$queryintegral=pg_exec($conn, "select distinct id_mensaje from mensaje_original where codigo_idioma='$idi' and id_mensaje in ($phrasin) and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
}
else {
$queryintegral=pg_exec($conn, "select id_mensaje from mensaje_original where codigo_idioma='$idi' and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
}
$yy=count($arrayrep3);
$yy++;
for ($gb=0; $gb<pg_numrows($queryintegral); $gb++) {
$getgb=pg_fetch_row($queryintegral, $gb);
$arrayrep3[$yy]=$getgb[0];
$yy++;
}
}
if ($attacho=="T") {
$contati=0;
$titu="titu_$idi";
if (count($arrayrep2) !=0) {
$queryatti=pg_exec($conn, "select distinct asociacion.id_mensaje from asociacion, archi where archi.id_asociacion=asociacion.id_asociacion and asociacion.id_mensaje in ($phrasin) and archi.codigo_idioma='$idi' and (asociacion.$titu like '%$palot1%' or asociacion.$titu like '%$palot2%' or asociacion.$titu like '%$palot3%' or asociacion.$titu like '%$palot4%') or ((archi.contenido like '%$palot1%' or archi.contenido like '%$palot2%' or archi.contenido like '%palot3%' or archi.contenido like '%$palot4%') and archi.id_asociacion=asociacion.id_asociacion)");
}
else {
$queryatti=pg_exec($conn, "select distinct asociacion.id_mensaje from asociacion, archi where archi.id_asociacion=asociacion.id_asociacion and archi.codigo_idioma='$idi' and (asociacion.$titu like '%$palot1%' or asociacion.$titu like '%$palot2%' or asociacion.$titu like '%$palot3%' or asociacion.$titu like '%$palot4%') or ((archi.contenido like '%$palot1%' or archi.contenido like '%$palot2%' or archi.contenido like '%palot3%' or archi.contenido like '%$palot4%') and archi.id_asociacion=asociacion.id_asociacion)");
}

$nbatti=pg_numrows($queryatti);


$yy=count($arrayrep3);
$yy++;
for ($gu=0; $gu<pg_numrows($queryatti); $gu++) {
$getgu=pg_fetch_row($queryatti, $gu);
$arrayrep3[$yy]=$getgu[0];
$yy++;
}
}

if ($syntheses=="T") {
$contyaya=0;
if (count($arrayrep2) !=0) {
$querysist=pg_exec($conn, "select distinct id_mensaje from sintesis where codigo_idioma='$idi' and id_mensaje in ($phrasin) and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
$querysist2=pg_exec($conn, "select distinct id_mensaje from correos where codigo_idioma='$idi' and id_mensaje in ($phrasin) and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
}
else {
$querysist=pg_exec($conn, "select distinct id_mensaje from sintesis where codigo_idioma='$idi' and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
$querysist2=pg_exec($conn, "select distinct id_mensaje from correos where codigo_idioma='$idi' and (contenido like '%$palot1%' or contenido like '%$palot2%' or contenido like '%$palot3%')");
}
$cosist=pg_numrows($querysist);

$rezouy=count($arrayrep3);
$rezouy+1;
for ($gaga=0; $gaga<pg_numrows($querysist); $gaga++) {
$getsist=pg_fetch_row($querysist, $gaga);
$arrayrep3[$rezouy]=$getsist[0];
$rezouy++;
}
for ($gaga=0; $gaga<pg_numrows($querysist2); $gaga++) {
$getsist2=pg_fetch_row($querysist2, $gaga);
$arrayrep3[$rezouy]=$getsist2[0];
$rezouy++;
}
}

if ($titulos=="T") {
$contyo=0;
$titul="titulo_$idi";
if (count($arrayrep2) !=0) {
$querytitulos=pg_exec($conn, "select id_mensaje from mensajes where ($titul like '%$palot1%' or $titul like '%$palot2%' or $titul like '%$palot3%') and id_mensaje in ($phrasin)");
}
else {
$querytitulos=pg_exec($conn, "select id_mensaje from mensajes where ($titul like '%$palot1%' or $titul like '%$palot2%' or $titul like '%$palot3%')");
}
//}
$rezon=count($arrayrep3);
$rezon++;
for ($go=0; $go<pg_numrows($querytitulos); $go++) {
$getgo=pg_fetch_row($querytitulos, $go);
$arrayrep3[$rezon]=$getgo[0];
$rezon++;
}
}
}
if ((count($arrayrep3)==0)&&($longpalo !=0)) {
//if (((pg_numrows($querypala)==0)||(!$querypala)) && ((pg_numrows($queryintegral)==0)||(!$queryintegral)) && ((pg_numrows($querytitulos)==0)||(!$querytitulos))&& (((pg_numrows($querysist)==0)&&(pg_numrows($querysost)==0))||((!$querysist)&&(!$querysost)))) {
$pasderep=1;


}


}
if (($longpalo ==0)||($paderep ==1)) {
//else {
$arrayrep3=$arrayrep2;
}

//la date
if (($dia !="nacimiento")&& ($pasderep !=1)) {
$hui=time();
if ($dia=="8j") {
$datemin=$hui-604800;
}
elseif ($dia=="15j") {
$datemin=$hui-1209600;
}
elseif ($dia=="1m") {
$datemin=$hui-2592000;
}
elseif ($dia=="2m") {
$datemin=$hui-5184000;
}

if (count($arrayrep3) !=0) {
for ($p=0; $p<count($arrayrep3); $p++) {
$phragin="$phragin '$arrayrep3[$p]',";
}
$phragin=substr($phragin, 0, -1);
$querdate=pg_exec($conn, "select id_mensaje from mensajes where id_mensaje in ($phragin) and fecha>'$datemin'");
}
else {
$querdate=pg_exec($conn, "select id_mensaje from mensajes where fecha>'$datemin'");
}
$nbrep=pg_numrows($querdate);
if ($nbrep==0) {
$pasderep=1;
}
//echo "PASDEREP: $pasderep<br>";
for ($ds=0; $ds<pg_numrows($querdate); $ds++) {
$getfechi=pg_fetch_row($querdate, $ds);
$arrayrep4[$ds]=$getfechi[0];
}
}
else {
$arrayrep4=$arrayrep3;
}


//liste des auteurs
$ep=0;
$ryt=count($totor);

if (($ryt !=0)&& ($pasderep !=1)) {
for ($ji=0; $ji<count($totor); $ji++) {
$phrad="$phrad id_creador='$totor[$ji]' OR";
}
$phrad=substr($phrad, 0, -2);

$wysi=count($arrayrep4);
if ($wysi !=0) {
$phrakin="";
for ($qu=0; $qu<count($arrayrep4); $qu++) {
$phrakin="$phrakin '$arrayrep4[$qu]',";
}
$phrakin=substr($phrakin, 0, -1);
$queryto = pg_exec($conn,"select distinct id_mensaje from mensajes where ($phrad) and id_mensaje in ($phrakin)");
}
else {
$queryto = pg_exec($conn,"select distinct id_mensaje from mensajes where $phrad");
}
$wynx=pg_numrows($queryto);


for ($zou=0; $zou<pg_numrows($queryto);  $zou++) {
$gettori=pg_fetch_row($queryto, $zou);
$arrayrep5[$zou]=$gettori[0];
}
}

else {
$arrayrep5=$arrayrep4;
}
include "bibo.php3";
include "bibusc.php3";
include "head5.php3";
?>
<table width="640" border="0">
<tr>
<td>

<?

//affichage des resultats

$coord = array(
    "cm"  => array("es"=>"Coordinación Mistica","en"=>"Mistica Coordination","fr"=>"Coordination Mistica","po"=>"Coordenação Mistica"),
    "ce"  => array("es"=>"Coordinación EMEC","en"=>"EMEC Coordination","fr"=>"Coordination EMEC","po"=>"EMEC Coordenação"));

//retraitement des resultats
$contarr5=count($arrayrep5);
if ($contarr5 !=0) {
for ($d=0; $d<count($arrayrep5); $d++) {
$arrayrep5[$d]=trim($arrayrep5[$d]);
$lenstr=strlen($arrayrep5[$d]);
if ($lenstr !=0) {
$inmess="$inmess '$arrayrep5[$d]',";
}
}

$inmess=substr($inmess, 0, -1);
$querorder=pg_exec($conn, "select distinct id_mensaje from mensajes where id_mensaje in ( $inmess ) order by fecha desc");
for ($de=0; $de<pg_numrows($querorder); $de++) {
$getorder=pg_fetch_row($querorder, $de);
$arrayrepi[$de]=$getorder[0];

}
}
$corep=count($arrayrepi);

}
echo "<br><div align=\"center\" bgcolor=\"#FF9933\"><b><font face=\"Helvetica\" size=\"2\">$ticnum : $corep</font></b></div>";
echo "<HR>";
if ((count($arrayrepi) !=0)&&($pasderep !=1)) {
for ($ww=0; $ww<count($arrayrepi); $ww++) {
$quercat=pg_exec($conn, "select id_categoria, codigo_idioma_mensaje_original from mensajes where id_mensaje='$arrayrepi[$ww]'");
$rescat=pg_fetch_row($quercat, 0);
$catcat=$rescat[0];
$coi=$rescat[1];
if ($catcat=='C2') {
$tit="titulo_$coi";

$query=pg_exec($conn, "select id_mensaje, apellido_miembro, nombre_miembro, $tit, fecha, id_miembro from mensajes, communidad where mensajes.id_creador=communidad.id_miembro and id_mensaje='$arrayrepi[$ww]'"); 
}
elseif ($idi=="es") {
$query=pg_exec($conn, "select id_mensaje, apellido_miembro, nombre_miembro, titulo_es, fecha, id_miembro from mensajes, communidad where mensajes.id_creador=communidad.id_miembro and id_mensaje='$arrayrepi[$ww]'"); 
}
elseif ($idi=="en") {
$query=pg_exec($conn, "select id_mensaje, apellido_miembro, nombre_miembro, titulo_en, fecha, id_miembro from mensajes, communidad where mensajes.id_creador=communidad.id_miembro and id_mensaje='$arrayrepi[$ww]'"); 
}
elseif ($idi=="fr") {
$query=pg_exec($conn, "select id_mensaje, apellido_miembro, nombre_miembro, titulo_fr, fecha, id_miembro from mensajes, communidad where mensajes.id_creador=communidad.id_miembro and id_mensaje='$arrayrepi[$ww]'"); 
}
elseif ($idi=="po") {
$query=pg_exec($conn, "select id_mensaje, apellido_miembro, nombre_miembro, titulo_po, fecha, id_miembro from mensajes, communidad where mensajes.id_creador=communidad.id_miembro and id_mensaje='$arrayrepi[$ww]'"); 
}

for($h=0; $h<pg_numrows($query); $h++) {
$ref=pg_fetch_row($query, $h);
if ($ref[5]=="1") {
$autaut=$coord["cm"]["$idi"];
$autaut=htmlentities($autaut);
}
elseif ($ref[5]=="2") {
$autaut=$coord["ce"]["$idi"];
$autaut=htmlentities($autaut);
}
else {
$ref[1]=stripslashes($ref[1]);
$autortab=explode ("-", $ref[1]);
for ($erx=0; $erx<count($autortab); $erx++) {
$autortab[$erx]=ucwords($autortab[$erx]);
}
$ref[1]=implode ("-", $autortab);
$ref[1]=htmlentities($ref[1]);
$ref[2]=stripslashes($ref[2]);
$ref[2]=htmlentities($ref[2]);
$ref[2]=ucwords($ref[2]);
$autaut="$ref[1] $ref[2]";
}
$ref[3]=stripslashes($ref[3]);
$ref[3]=htmlentities($ref[3]);
$ref[4]=date("d/m/Y", $ref[4]);

$xxx=$ww+1;
$link="http://funredes.org/mistica/bdd/men.php3/idi/$idi/id/$ref[0]";
//echo "$ref[1] $ref[2], <a href=\"$link\">$ref[3]</a>, $ref[4]<br>";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"3\" 
cellpadding=\"3\"><tr><td width=\"10%\"><b>$xxx</b></td><td width=\"90%\">$autaut, <a href=\"$link\">$ref[3]</a>, $ref[4]</td></tr></table>"; 

}
}
}
else {
echo "<H2> $ticningun </H2><br>";
}
echo "<br><H3><DIV align=center><a href=\"http://funredes.org/mistica/bdd/search.php3/idi/$idi\">$ticotra</a></DIV></H3><br>"; 

}
?>
    </td>
    <td bgcolor="#41a13f" width="15" rowspan="2">&nbsp; </td>
  </tr>
  <tr>
    <td width="615">&nbsp;</td>
  </tr>
</table>
<table width="640" border="0">
        <tr>
                <td bgcolor="#5050d1">
                        <table width="630" border="0">
                                <tr>
                                        <td bgcolor="#eeeeee" align="center">
                                                <font face="helvetica, verdana, arial,  sans serif" size="2">
                                                &nbsp;
                                                </font>
                                        </td>   
                                </tr>
                        </table>
                </td>   
        </tr>
</table>

<!--pie--> 
<hr>
<table width="640" border="0" bgcolor="#eeeeee">
        <tr>
                <td>
                        <a HREF="javascript:history.go(-1)" onMouseOver="if (VersionNavigateur(3.0,4.0))img7.src='/mistica/bdd/img/backcolor.gif' " onMouseOut="img7.src='/mistica/bdd/img/backnegro.gif' "><img name="img7" src="/mistica/bdd/img/backnegro.gif" width="18" height="18" border="0" alt="<?echo $prev?>" onLoad="tempImg=new Image(0,0); tempImg.src='/mistica/bdd/img/backcolor.gif'"></a>
                        
                </td>
                <td align="center">
                        <a HREF="#top" onMouseOver="if (VersionNavigateur(3.0,4.0))img6.src='/mistica/bdd/img/topcolor.gif' " onMouseOut="img6.src='/mistica/bdd/img/topnegro.gif'"><img name="img6" src="/mistica/bdd/img/topnegro.gif" width="18" height="18" border="0" alt="<?echo $cabeza?>" onLoad="tempImg=new Image(0,0); tempImg.src='/mistica/bdd/img/topcolor.gif'"></a>
                </td>
                <td align="right">
                        
                        <a HREF="javascript:history.go(+1)" onMouseOver="if (VersionNavigateur(3.0,4.0))img8.src='/mistica/img/forwardcolor.gif' " onMouseOut="img8.src='/mistica/bdd/img/forwardnegro.gif' "><img name="img8" src="/mistica/bdd/img/forwardnegro.gif" width="18" height="18" border="0" alt="<?echo $prox?>" onLoad="tempImg=new Image(0,0); tempImg.src='/mistica/bdd/img/forwardcolor.gif'"></a>
                </td>
                
        </tr>
        
</table>

<table width="640" border="0">
        <tr>
                
                
    <td align="center"> <font face="helvetica, verdana, arial, sans serif" size="2"> 
      <?echo"$credit";?> | 
<?echo "$mapa";?> | <?echo"$correo"?>: <a HREF="MAILTO:webmistica@funredes.org">&lt;webmistica@funredes.org&gt;</a> 
      </font> </td>
        </tr>
        <tr>
<?
echo "<td align=\"center\"> <font face=\"helvetica, verdana, arial, sans serif\" size=\"2\">http://www.funredes.org/mistica$PHP_SELF<br>$modif: 18/04/2000</font>";
?>

        </tr>
</table>

</body>
</html>

