<?php 

//colorscheme for main body
$bgcolor1 = "white";
$fontcolor1 = "#cc9900";
$fontcolor2 = "black";
$fontcolor3 = "navy";
$bgmaincells = "#FFFFFF";
$bgheadercells = "navy";
$fontheadercells = "white";

$bganuncios = "#68d038";
$bganuncios_body = "navy";
$fontanuncios_title = "white";
$bgindex = "navy";

//colorscheme for anuncios
$bgcolor4 = "black";
$fontcolor4 = "orange";
$fontcolor5 = "white";

if (strstr($PATH_INFO, "/")) {
	$p = substr($PATH_INFO, 1);
	$e_path = explode("/", $p);
	$i = 0;
	while ($i < count($e_path)) {
		$name = $e_path[$i];
		$val = $e_path[$i+1];
		$$name = $val;
		$i = $i+2;
	}
}

if (strstr($REQUEST_URI, "/espanol/")) {
	$lang = "es";
	$dir = "espanol";
	$lenguaid = "1";
} 
if (strstr($REQUEST_URI, "/francais/")) {
	$lang = "fr";
	$dir = "francais";
	$lenguaid = "2";
} 
if (strstr($REQUEST_URI, "/english/")) {
	$lang = "en";
	$dir = "english";
	$lenguaid = "3";
} 
if (strstr($REQUEST_URI, "/texto/")) {
	$dir = "texto/".$dir;
}


// descripcion por idioma

if ($lang == "es") {
	$label_seccion_main = "TRABAJOS HECHOS";
	$label_seccion_tema = "INDICE POR TEMA";
	$label_seccion_region = "INDICE POR REGI&Oacute;N";
	$label_seccion_sintesis = "PRESENTACI&Oacute;N SINT&Eacute;TICA";
	$label_seccion_datos = "DATOS DETALLADOS";
	$label_titulo_tema = "El trabajo de Funredes sobre ";
	$label_titulo_region = "El trabajo de Funredes en ";
	$label_anuncios = "ANUNCIOS";
	$label_datosenteros = "Regresar a la lista detallada de todos los trabajos hechos por Funredes sobre este tema o regi&oacute;n";
	$label_clickhere = "haga clic aqu&iacute;";
	$label_retour = "trabajos hechos";
	$label_historique = "Ver una presentaci&oacute;n sint&eacute;tica del trabajo hecho sobre este tema o regi&oacute;n";
	$label_top = "[ AL INICIO DE LA P&Aacute;GINA ]";
} else if ($lang == "fr") {
	$label_seccion_main = "TRAVAUX EFFECTU&Eacute;S";
	$label_seccion_tema = "INDEXE PAR SUJET";
	$label_seccion_region = "INDEXE PAR R&Eacute;GION";
	$label_seccion_sintesis = "L'HISTORIQUE";
	$label_seccion_datos = "LISTE D&Eacute;TAILL&Eacute;E";
	$label_titulo_tema = "Les travaux effectu&eacute;s sur ";
	$label_titulo_region = "Les travaux effectu&eacute;s en ";
	$label_anuncios = "ANNONCES";
	$label_datosenteros = "Retour &agrave; la liste d&eacute;taill&eacute;e des travaux effectu&eacute;s par Funredes &agrave; ce sujet ou dans cette r&eacute;gion";
	$label_clickhere = "cliquez ici";
	$label_retour = "travaux effectu&eacute;s";
	$label_historique = "Voir une synth&egrave;se des travaux &eacute;ffectu&eacute;es pour ce sujet ou cette r&eacute;gion";
	$label_top = "[ RETOUR EN HAUT ]";
} else if ($lang == "en") {
	$label_seccion_main = "OUR WORK";
	$label_seccion_tema = "INDEX BY TOPIC";
	$label_seccion_region = "INDEX BY REGION";
	$label_seccion_sintesis = "GENERAL OVERVIEW";
	$label_seccion_datos = "DETAILED LIST";
	$label_titulo_tema = "Our Work On ";
	$label_titulo_region = "Our Work In ";
	$label_anuncios = "HEADLINES";
	$label_datosenteros = "Return to the detailed list of all of Funredes' work on this topic or region";
	$label_clickhere = "click here";
	$label_retour = "back to our work";
	$label_historique = "See the overview of our work on this topic or region";
	$label_top = "[ RETURN TO TOP ]";
}

// termina descripcion por idioma

$conn = pg_pconnect("dbname=sif user=mike");

function showmoredata($fieldname, $numero) {
	GLOBAL $getdocinfo;
	if (strlen($getdocinfo[$numero]) > 0) {
		echo "<br><b>$fieldname:  </b>$getdocinfo[$numero]";
	}
}

function showcontenido($queryname) {
	$rowcount = pg_numrows($queryname);
	if ($rowcount > 0) {
		$rownumber = 0;
		echo "<p>";
		do {
			$getcontenido = pg_fetch_row($queryname, $rownumber);
			echo $getcontenido[2];
			$rownumber++;
		} while ($rownumber < $rowcount);
		echo "</font>";
	}
}

function showdata($fieldname, $queryname) {
	if (pg_numrows($queryname) > 0) {
	$fieldrow = 0;
	do {
		$getfield = pg_fetch_row($queryname, $fieldrow);
		if (($fieldrow == 0) || (pg_numrows($queryname) == 0)) {
			echo "<br><b>$fieldname:  </b>$getfield[1]";
			$$fieldname = $getfield[1];	
		} else {
			echo ", $getfield[1]";
			$$fieldname = $$fieldname.$getfield[1];
		}
		$fieldrow++;
	} while ($fieldrow < pg_numrows($queryname));
	}
}

function showspecial($fieldname, $queryname) {
	if (pg_numrows($queryname) != 0) {
		GLOBAL $$fieldname;
		$fieldrow = 0;
		do {
				$getfield = pg_fetch_row($queryname, $fieldrow);
				if (($fieldrow == 0) || (pg_numrows($queryname) == 0)) {
					$$fieldname = $getfield[1];	
				} else {
					$$fieldname = $$fieldname.", ".$getfield[1];
				}
				$fieldrow++;
			} while ($fieldrow < pg_numrows($queryname));
	}
}

if ($docid) {
	$querytipo = pg_exec($conn, "SELECT tipo FROM principal WHERE docid=$docid");
	$gettipo = pg_fetch_row($querytipo, 0);
	if ($gettipo[0] == "16") {
		$queryid = pg_exec($conn, "SELECT regionid FROM regiones WHERE docid=$docid");
		$getid = pg_fetch_row($queryid, 0);
		$regionid = $getid[0];
	} else if ($gettipo[0] == "17") {
		$queryid = pg_exec($conn, "SELECT temaid FROM temas WHERE docid=$docid");
		$getid = pg_fetch_row($queryid, 0);
		$temaid = $getid[0];
	}
}

if ($temaid) {
	$query = pg_exec($conn, "SELECT tema_$lang FROM temalista WHERE temaid=$temaid");
	$queryifcont = pg_exec($conn, "SELECT p.docid, p.lengua FROM principal p, temas ta WHERE tipo=17 AND ta.temaid=$temaid AND ta.docid=p.docid");
} else if ($regionid) {
	$query = pg_exec($conn, "SELECT region_$lang FROM regionlista WHERE regionid=$regionid");
	$queryifcont = pg_exec($conn, "SELECT p.docid, p.lengua FROM principal p, regiones r WHERE tipo=16 AND r.regionid=$regionid AND r.docid=p.docid");
}
if (pg_numrows($query) != 0) {
	$get = pg_fetch_row($query, 0);
}
if (pg_numrows($queryifcont) != "0") {
	$ifcont = "si";
} else {
	$datos = "si";
}


if ($temaid) {
	$label_seccion = $label_seccion_tema;
	$label_titulo = $label_titulo_tema.$get[0];
	$label_sobre = $label_sobretema;
	$index = "tema";
	$navbarhelp = "temaid/$temaid";
	$sortquery = "SELECT DISTINCT p.docid, titulo_$lang, descripcion_$lang, fechadecreacion FROM principal p, temas t WHERE tipo=15 AND anuncio_carpetas>0 AND t.temaid=$temaid AND t.docid=p.docid";
	$dibujo = "dibujo_tema".".gif";
} else if ($regionid) {
	$index = "region";
	$navbarhelp = "regionid/$regionid";
	$label_seccion = $label_seccion_region;
	$label_titulo = $label_titulo_region.$get[0];
	$label_sobre = $label_sobreregion;
	$sortquery = "SELECT DISTINCT p.docid, titulo_$lang, descripcion_$lang, fechadecreacion FROM principal p, regiones r WHERE tipo=15 AND anuncio_carpetas>0 AND r.regionid=$regionid AND r.docid=p.docid ORDER BY anuncio_carpetas";
	$dibujo = "dibujo_region".".gif";
} 
if (!$titulo) {
	$titulo = $label_titulo;
}

$dibujo_filepath = "/home/httpd/html/images/".$dibujo;
$size_dibujo = GetImageSize($dibujo_filepath); 


$navbar = "<a href=\"http://".$HTTP_HOST."\">FUNREDES</a> <b>:</b> <a href=\"/$dir/brochure.php3\">$label_seccion_main</a> <b>:</b> ";
$navbar = $navbar."<a href=\"/$dir/brochure.php3/index/$index\">$label_seccion</a> <b>:</b> ";
if ($ifcont == "si") {
	if ($datos == "si") {
		$navbar = $navbar."<b>$label_seccion_datos</b>";
	} else {
		$navbar = $navbar."<a href=\"/$dir/carpeta.php3/$navbarhelp/datos/si\">$label_seccion_datos</a> <b>: $label_seccion_sintesis</b>";
	}
} else {
	$navbar = $navbar."<b>$label_seccion_datos</b>";
}



include("header.php3"); 	
?>
<table width=100% border=0 cellpadding=0 cellspacing=0>
	<tr>
		<td valign=top width=175>


<?php
// begin anuncios

	$queryanuncio = pg_exec($conn, $sortquery);
	if (pg_numrows($queryanuncio) != 0) {
?>
				<table width=100% cellpadding=3 cellspacing=0 bgcolor="<?php echo $bganuncios ?>" border=0><tr><td>
				<table width=100% cellpadding=3 cellspacing=0>
					<tr>
						<td bgcolor="<?php echo $bganuncios ?>"><font face="<?php echo $font1 ?>" color="<?php echo $fontanuncios_title ?>" size=-1>
							<center><b><?php echo $label_anuncios ?></b></center>
						</td>
					</tr>
					<tr>
						<td bgcolor="<?php echo $bganuncios_body ?>"><font face="<?php echo $font1 ?>" size=-1>
<?php
		$i = 0;
		while ($i < pg_numrows($queryanuncio)) {
			$getanuncio = pg_fetch_row($queryanuncio, $i);
			echo "<font size=-1>";
			if ($PHP_SELF != $getanuncio[2]) {
				echo "<a href=\"$getanuncio[2]\">$getanuncio[1]</a><p>\n";
			} else {
				echo "<font color=white>$getanuncio[1]<p>\n";
			}
			$i++;
		}
//end anuncios
?>
						</td>
					</tr>
				</table>
				</td></tr></table>
<?php
	}
?>
				<table width=100% cellpadding=3 cellspacing=0 bgcolor="<?php echo $bganuncios ?>" border=0><tr><td>
				<table width=100% cellpadding=3 cellspacing=0>
					</tr>
					<tr>
						<td bgcolor="<?php echo $bganuncios_body ?>"><font face="<?php echo $font1 ?>" size=-1 color="<?php echo $fontanuncios_title ?>">
<?php 
	if (!$datos) {
		echo $label_datosenteros;
?>
							<p align=right><a href="http://<?php echo $HTTP_HOST.$REQUEST_URI ?>/datos/si"><?php echo $label_clickhere ?></a><p align=right>
<?php 
	} else {
		if ($ifcont == "si") {
			echo $label_historique;
			if ($temaid) {
				$newfilename = "carpeta.php3/temaid/$temaid";
			}
			if ($regionid) {
				$newfilename = "carpeta.php3/regionid/$regionid";
			}
?>
							<p align=right><a href="http://<?php echo $HTTP_HOST."/".$dir."/".$newfilename ?>"><?php echo $label_clickhere ?></a><p align=right>
<?php
		}
	}
?>
							<a href="/<?php echo $dir ?>/brochure.php3"><?php echo $label_retour ?></a>
							</p>
						</td>
					</tr>
				</table>
				</td></tr></table><p>
				<img src="/images/<?php echo $dibujo ?>" <?php echo $size_dibujo[3] ?> ><p>

			</td>
			<td valign=top>
				<table width=100% cellpadding=3 cellspacing=0>
					<tr>
						<td valign=top align=left colspan=2>
							<p align=left>
							<?php
							echo "<a name=\"top\"></a><font size=-2 face=\"$font1\">$navbar</font><p>";
							?>
							<font face="<?php echo $font1 ?>" size=+3><?php echo $label_titulo ?>
							</p><br>
						</td>
					</tr>
					<tr>
						<td colspan=2><font size=-1 face="<?php echo $font1 ?>">

<?php

//show contenido

	if (!$datos && $ifcont == "si") {
		$getdocid = pg_fetch_row($queryifcont, 0);
		$docid = $getdocid[0];
		$querycontlang = pg_exec($conn, "SELECT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$lenguaid'");
		if (pg_numrows($querycontlang) == 0) {
			$querycontlang2 = pg_exec($conn, "SELECT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$getdocid[1]'");
			if (pg_numrows($querycontlang2) == 0) {
				$lenguaid = 1;
			} else {
				$lenguaid = $getdocid[1];
			}
		}	
		$querycontenido = pg_exec($conn, "SELECT * FROM contenido WHERE docid='$docid' AND lenguaid='$lenguaid' ORDER BY chunkid");
		showcontenido($querycontenido);
	} else {

//show regions by topic or topics by region

include("../incluir/filepathandname.inc");

if ($temaid) {
	$string = "select rl.region_$lang, p.tipo, t.tipo_$lang, p.docid, al.autor, p.titulo_$lang, conferencia_$lang, p.descripcion_$lang, p.editorial_$lang, p.lugar_$lang, p.fechadecreacion FROM principal p, regiones r, regionlista rl, temas ta, tipos t, autores a, autorlista al WHERE al.autorid=a.autorid AND a.docid=p.docid AND p.docid=r.docid AND r.regionid=rl.regionid AND p.docid=ta.docid AND ta.temaid=$temaid AND t.tipoid=p.tipo ORDER BY rl.region_$lang, t.tipo_$lang, p.fechadecreacion DESC";
}
if ($regionid) {
	$string = "select tl.tema_$lang, p.tipo, t.tipo_$lang, p.docid, al.autor, p.titulo_$lang, conferencia_$lang, p.descripcion_$lang, p.editorial_$lang, p.lugar_$lang, p.fechadecreacion FROM principal p, regiones r, temalista tl, temas ta, tipos t, autores a, autorlista al WHERE al.autorid=a.autorid AND a.docid=p.docid AND p.docid=ta.docid AND ta.temaid=tl.temaid AND p.docid=r.docid AND r.regionid=$regionid AND t.tipoid=p.tipo ORDER BY tl.tema_$lang, t.tipo_$lang, p.fechadecreacion DESC";
}


	$querylong = pg_exec($conn, $string);
	if (pg_numrows($querylong) != 0) {
		$rt = 0;
		echo "<br></br><table width=90% cellpadding=3 cellspacing=0 align=center bgcolor=\"$bgcolor1\">\n";
		//echo "<tr><td colspan=2><font size=+0 face=\"$font1\" color=\"$fontcolor1\"><center><b>$label_titulo:</b><font size=-1>";
		while ($rt < pg_numrows($querylong)) {
			$getthis = pg_fetch_row($querylong, $rt);
			$tipoid = $getthis[1];
			if ($rt != pg_numrows($querylong)-1) {
				$getnext = pg_fetch_row($querylong, $rt+1);		
			}
			if ($rt != 0) {
				$getprev = pg_fetch_row($querylong, $rt-1);		
			}
			
			if ($getprev[0] != $getthis[0]) {
				echo "<tr><td colspan=2 height=30 bgcolor=\"$bgheadercells\">\n<font size=-1 face=\"$font1\" color=\"$fontheadercells\">\n";
				echo "<b>$getthis[0]</b>\n\n";
				echo "</td></tr>\n";
				$newfield = "si";
			}
			if (($getnext && $getprev[1] != $getthis[1]) || $newfield == "si") {
				echo "<tr>\n";
				echo "<td valign=top bgcolor=\"$bgmaincells\"><font size=-1 face=\"$font1\" color=\"$fontcolor2\">\n";
				echo "<b>$getthis[2]:</b>\n";
				echo "</td>\n";
				echo "<td valign=top bgcolor=\"$bgmaincells\"><font size=-1 face=\"$font1\" color=\"$fontcolor2\">\n";
			}
			if ($getprev[5] != $getthis[5]) {
				echo "<a href=\"/$dir/$filepathandname[$tipoid]/docid/$getthis[3]\">";
				if ($tipoid == "3" || $tipoid == "4") {
					echo $getthis[6];
				} else {
					echo "$getthis[5]";
				}
				echo "</a>";
				if ($tipoid == "1" || $tipoid == "2" || $tipoid == "11") {
					echo " $getthis[4]";
				}
			} else if (($getprev[5] == $getthis[5]) && ($tipoid == "1" || $tipoid == "2" || $tipoid == "11")) {
				echo ", $getthis[4]";
			}
			if ($getthis[5] != $getnext[5]) {
				if ($tipoid == "1" || $tipoid == "2" || $tipoid == "11" || $tipoid == "3" || $tipoid == "4") {
					if ($getthis[8]) {
						echo ", $getthis[8]";
					}
					if ($getthis[9]) {
						echo ", $getthis[9]";
					}
					if ($getthis[10]) {
						echo ", $getthis[10]";
					}
				}
				echo "<br>\n";
			}
			if (($getnext[0] != $getthis[0]) || $rt == pg_numrows($querylong)-1) {
				echo "</td></tr>\n<tr><td valign=top height=40 align=right colspan=2><font size=-2 face=\"$font1\"><a href=\"#top\">$label_top</a></td></tr>\n\n";
			}
			$rt++;
			$newfield = "";
		}
		echo "</table><p>\n\n";
	}

}
?>
				<table width=350 align=center cellpadding=3 cellspacing=0 bgcolor="<?php echo $bganuncios ?>" border=0><tr><td>
				<table width=100% cellpadding=3 cellspacing=0>
					</tr>
					<tr>
						<td bgcolor="<?php echo $bganuncios_body ?>"><font face="<?php echo $font1 ?>" size=-1 color="<?php echo $fontanuncios_title ?>">
<?php 
	if (!$datos) {
		echo $label_datosenteros;
?>
							<p align=right><a href="http://<?php echo $HTTP_HOST.$REQUEST_URI ?>/datos/si"><?php echo $label_clickhere ?></a><p align=right>
<?php 
	} else {
		if ($ifcont == "si") {
			echo $label_historique;
			if ($temaid) {
				$newfilename = "carpeta.php3/temaid/$temaid";
			}
			if ($regionid) {
				$newfilename = "carpeta.php3/regionid/$regionid";
			}
?>
							<p align=right><a href="http://<?php echo $HTTP_HOST."/".$dir."/".$newfilename ?>"><?php echo $label_clickhere ?></a><p align=right>
<?php
		}
	}
?>
							<a href="/<?php echo $dir ?>/brochure.php3"><?php echo $label_retour ?></a>
							</p>
						</td>
					</tr>
				</table>
				</td></tr></table><p>




						</td>
					</tr>
				</table>

			</td>
		</tr>
	</table>
<?php
	

include("footer.php3");
?>
