<?php 

$bgcolor1 = "#68d038";
$bgcolor2 = "#FFFFFF";
$bgcolor3 = "#FFFFFF";
$font_color = "white";

//Anuncios
$bg_top_anuncios = "#68d038";
$bg_main_anuncios = "navy";
$font_top_anuncios = "white";
$border_anuncios = "#68d038";

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;
	}
}
// proteccion contre enlaces malos
if ($docid){
	if (is_numeric($docid)){
	}else{
		$refer_tab = explode(".php3", $HTTP_REFERER);
		$newpath = $refer_tab[1];
		$docid=406;
		if (strstr($newpath, "/")) {
			$p = substr($newpath, 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;
			}
		}
		echo "<h2>Enlace no valido / non valid link / lien non valide</h2>";
		if (is_numeric($docid)){
			$enviara = "siferror@funredes.org";
			$temamail = "Enlace Malo";
			$mensaje = "Problema en la pagina : $HTTP_REFERER \nhay un enlace a : $PHP_SELF";
			$extra = "From: Chequeo auto\n";
			mail($enviara, $temamail, $mensaje, $extra);
	//		echo $mensaje;
		}
	}
}
if ($docid){
	if (is_numeric($docid)){
	}else{
		$docid = "";
	}
}


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_mensaje_trad = "<table bgcolor=\"lightgreen\"><tr><td><b><font size=\"4\" color=\"red\"><center>El documento solicitado no esta disponible en espa&ntilde;ol entonces se lo monstramos en su idioma original</center></font></b>";
	$label_enlace_trad = "<b><font size=\"3\" color=\"red\"><center>Existe tambi&eacute;n una version de este documento en : <BR>&nbsp; &nbsp; &nbsp;";
	$label_seccion = "LOS EDITORIALES DE FUNREDES";
	$label_titulo = "LOS EDITORIALES DE FUNREDES";
	$label_descripcion = "Vean aqu&iacute; las palabras de Funredes m&aacute;s importantes.";
	$label_verpor = "Se puede ver todos los documentos organizados en varias maneras:";
	$label_overpor = "O, se puede ver los documentos organizados por una regi&oacute;n o tema:";
	$label_verdocs = "ver todos los editoriales por";
	$label_noenlinea = "Publicaciones no en-l&iacute;nea";
	$label_documento = "Documento";
	$label_sortfecha = "fecha de creaci&oacute;n";
	$label_sorttitulo = "t&iacute;tulo";
	$label_sortautor = "autor";
	$label_sortlengua = "lengua original";
	$label_sortpor = "por";
	$label_todos = "TODOS";
	$label_editorialnodisponible = "editorial no disponible";
	$label_verconexos = "Ver documentos relacionados";
	$label_lista_regiones = "&Iacute;NDICE POR REGI&Oacute;N";
	$label_lista_temas = "&Iacute;NDICE POR TEMA";

	$label_campo_lengua = "Lengua original";
	$label_campo_trads = "Traducciones";
	$label_campo_autorprinc = "Autores principales";
	$label_campo_autoressec = "Autores secundarios";
	$label_campo_fechadecreacion = "Fecha de creaci&oacute;n";
	$label_campo_fechamod = "Fecha de modificaci&oacute;n de HTML";
	$label_campo_regiones = "Regiones";
	$label_campo_temas = "Temas";
	$label_campo_proyectos = "Proyectos relacionados";
	$label_campo_lugar = "Lugar";
	$label_campo_editorial = "Editorial";
	$label_campo_tipo = "Tipo de documento";
	$label_campo_adjuntos = "Documentos adjuntos";

} else if ($lang == "fr") {
	$label_mensaje_trad = "<table bgcolor=\"lightgreen\"><tr><td><b><font size=\"4\" color=\"red\"><center>Le document que vous avez sollicit&eacute; n'est pas disponible en fran&ccedil;ais, nous vous le proposons donc dans sa langue originale.</center></font></b>";
	$label_enlace_trad = "<b><font size=\"3\" color=\"red\"><center>Il existe &eacute;galement une traduction de ce document en : <BR>&nbsp; &nbsp; &nbsp;";
	$label_seccion = "LES EDITORIAUX DE FUNREDES";
	$label_titulo = "LES EDITORIAUX DE FUNREDES";
	$label_descripcion = "Voir ici les mots les plus importants de Funredes...";
	$label_verpor = "Les documents sont organisés dans plusieurs façons:";
	$label_overpor = "Ou, les documents sont organizés par région ou sujet:";
	$label_verdocs = "voir les &eacute;ditoriaux par";
	$label_noenlinea = "Publications non en-lignes";
	$label_documento = "Document";
	$label_sortfecha = "date de publication";
	$label_sorttitulo = "titre";
	$label_sortautor = "auteur";
	$label_sortlengua = "langue d'origine";
	$label_sortpor = "par";
	$label_todos = "TOUS";
	$label_editorialnodisponible = "maison de publication non disponible";
	$label_verconexos = "Voir les documents connexes";
	$label_lista_regiones = "INDEX PAR R&Eacute;GION";
	$label_lista_temas = "INDEX PAR SUJET";

	$label_campo_lengua = "Langue d'origine";
	$label_campo_trads = "Traductions";
	$label_campo_autorprinc = "Auteurs principaux";
	$label_campo_autoressec = "Auteurs secondaires";
	$label_campo_fechadecreacion = "Date de publication";
	$label_campo_fechamod = "Date d'actualization du HTML";
	$label_campo_regiones = "Régions";
	$label_campo_temas = "Sujets";
	$label_campo_proyectos = "Projets connexes";
	$label_campo_lugar = "Lieu";
	$label_campo_editorial = "Maison de publication";
	$label_campo_tipo = "Typo de document";
	$label_campo_adjuntos = "Documents attachés";

} else if ($lang == "en") {
	$label_mensaje_trad = "<table bgcolor=\"lightgreen\"><tr><td><b><font size=\"4\" color=\"red\"><center>This document is not available in English so we displayed it in its original form.</center></font></b>";
	$label_enlace_trad = "<b><font size=\"3\" color=\"red\"><center>You can find another traduction of this document in:<BR>&nbsp; &nbsp; &nbsp;";	$label_seccion = "OUR PROJECTS";
	$label_seccion = "FUNREDES' EDITORIALS";
	$label_titulo = "FUNREDES' EDITORIALS";
	$label_descripcion = "See the latest and most important words from Funredes...";
	$label_verpor = "The documents are organized in various lists:";
	$label_overpor = "Or the documents are organized by region or subject of relevance:";
	$label_verdocs = "see editorials by";
	$label_noenlinea = "Publications not on-line";
	$label_documento = "Document";
	$label_sortfecha = "date of publication";
	$label_sorttitulo = "title";
	$label_sortautor = "author";
	$label_sortlengua = "original language";
	$label_sortpor = "by";
	$label_todos = "ALL";
	$label_editorialnodisponible = "publisher not available";
	$label_verconexos = "See Related Articles";
	$label_lista_regiones = "INDEX BY REGION";
	$label_lista_temas = "INDEX BY TOPIC";

	$label_campo_lengua = "Original Language";
	$label_campo_trads = "Translations";
	$label_campo_autorprinc = "Principal Authors";
	$label_campo_autoressec = "Secondary Authors";
	$label_campo_fechadecreacion = "Date of Publication";
	$label_campo_fechamod = "Date of HTML Modification";
	$label_campo_regiones = "Regions";
	$label_campo_temas = "Subjects";
	$label_campo_proyectos = "Related Projects";
	$label_campo_lugar = "Place of Publication";
	$label_campo_editorial = "Publishing House";
	$label_campo_tipo = "Type of Document";
	$label_campo_adjuntos = "Attachments";
}

if (!$titulo) {
	$titulo = $label_seccion;
}

// 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 showadjuntos($queryname) {
	$rowcount = pg_numrows($queryname);
	if ($rowcount > 0) {
		$rownumber = 0;
		do {
			$getadjuntos = pg_fetch_row($queryname, $rownumber);
			echo "<a href=\"/adjuntos/$getadjuntos[1]\">$getadjuntos[1]</a> ($getadjuntos[2] kb)<br>";
			$rownumber++;
		} while ($rownumber < $rowcount);
		echo "</font>";
	}
}


function showtrads($fieldname, $queryname) {
	GLOBAL $SCRIPT_NAME, $docid;
	if (pg_numrows($queryname) > 0) {
	$fieldrow = 0;
	do {
		$getfield = pg_fetch_row($queryname, $fieldrow);
		if (($fieldrow == 0) || (pg_numrows($queryname) == 0)) {
			if ($docid) {
				echo "<br><b>Traducciones:  </b>";
			}
			echo "<a href=\"".$SCRIPT_NAME."/docid/$getfield[2]\">$getfield[1]</a>";	
		} else {
			echo ", <a href=\"".$SCRIPT_NAME."/docid/$getfield[2]\">$getfield[1]</a>";
		}
		$fieldrow++;
	} while ($fieldrow < pg_numrows($queryname));
	}
}

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) {

	$querydocinfo = pg_exec($conn, "SELECT DISTINCT p.docid, p.titulo_$lang, l.lengua, p.descripcion_$lang, p.fechadecreacion, p.fechamod, p.lugar_$lang, p.editorial_$lang, p.conferencia_$lang, p.conveniocon, e.estatus_$lang, p.especial, t.tipo_$lang, p.kb, p.lengua FROM principal p, lenguas l, estatuses e, tipos t WHERE p.lengua=l.lenguaid AND t.tipoid=p.tipo AND e.estatusid=p.estatus AND p.docid='$docid'");
	$queryregiones = pg_exec($conn, "SELECT DISTINCT r.docid, rl.region_$lang, r.regionid FROM regiones r, regionlista rl WHERE r.regionid=rl.regionid AND r.docid='$docid'");
	$querytemas = pg_exec($conn, "SELECT DISTINCT t.docid, tl.tema_$lang, t.temaid FROM temas t, temalista tl WHERE t.temaid=tl.temaid AND t.docid='$docid'");
	$queryautores = pg_exec($conn, "SELECT DISTINCT a.docid, al.autor FROM autores a, autorlista al WHERE a.docid='$docid' AND a.autorid=al.autorid");
	$queryautoressec = pg_exec($conn, "SELECT DISTINCT ac.docid, al.autor FROM autoressecundarios ac, autorlista al WHERE ac.docid='$docid' AND ac.autorid=al.autorid");
	$queryproyectos = pg_exec($conn, "SELECT DISTINCT p.docid, pl.proyecto FROM proyectos p, proyectolista pl WHERE p.proyectoid=pl.proyectoid AND p.docid='$docid'");
	$querytraducciones = pg_exec($conn, "SELECT DISTINCT t.docid, l.lengua, t.traduccionid FROM traducciones t, lenguas l, principal p WHERE t.traduccionid=p.docid AND l.lenguaid=p.lengua AND t.docid='$docid'");
	$queryadjuntos = pg_exec($conn, "SELECT DISTINCT * FROM adjuntos WHERE docid='$docid'");	

	include("header.php3"); 		

	$getdocinfo = pg_fetch_row($querydocinfo, 0);

// si la pagina no esta en el idioma selectado :
	$lenguacont = $lenguaid;

	$querycontlang = pg_exec($conn, "SELECT DISTINCT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$lenguacont'");

	if (pg_numrows($querycontlang) == 0) {
		$mensaje_trad = $label_mensaje_trad;
		$querynblang = pg_exec($conn, "SELECT DISTINCT lenguaid FROM lenguas");
		$y = $z = 0;
		for ($x=1; $x<(pg_numrows($querynblang))+1; $x++) {

			$querycontlang2 = pg_exec($conn, "SELECT DISTINCT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$x'");
			if (pg_numrows($querycontlang2) != 0) {
				if ($x==$getdocinfo[14]){
					$lenguacont = $x;			
					$y = 1;
				}
				else{
					$l = $l + $ltemp;
					$ltemp = "$ltemp"."X"."$x";
					$z = $x;
				}
			}
		}		
		if ($y==1){
			$l = $ltemp;
		}
		else{
			$lenguacont = $z;
			if ($z==0){
				$mensaje_trad = "";
			}
		}
		if ($l){
			$enlace_trad = $label_enlace_trad;
			$ltab = explode("X", $l);
			$lcnt = count($ltab);
			for ($i=1; $i<count($ltab); $i++){
				$queryenlace = pg_exec($conn, "SELECT DISTINCT lenguaid, lengua_$lang FROM lenguas WHERE lenguaid='$ltab[$i]'");
				$getenlace = pg_fetch_row($queryenlace, 0);
				switch ($getenlace[0]){
					case 1 :
						$enlace_trad = $enlace_trad."<a href=\"".$espanolurl."\">$getenlace[1]</a> &nbsp; &nbsp &nbsp";
						break;
					case 2 :
						$enlace_trad = $enlace_trad."<a href=\"".$francaisurl."\">$getenlace[1]</a> &nbsp; &nbsp &nbsp";
						break;
					case 3 :
						$enlace_trad = $enlace_trad."<a href=\"$englishurl\">$getenlace[1]</a> &nbsp; &nbsp &nbsp";
						break;
					default :
						$enlace_trad = $enlace_trad."$getenlace[1] &nbsp; &nbsp &nbsp";
						break;
				}
			}
			$enlace_trad = $enlace_trad."</center></font></b>";
		}
	}	


	$querycontenido = pg_exec($conn, "SELECT DISTINCT * FROM contenido WHERE docid='$docid' AND lenguaid='$lenguacont' ORDER BY chunkid");

	
	showspecial("autores", $queryautores);
	if (pg_numrows($queryautoressec) > 0) {
		showspecial("autoressec", $queryautoressec);
	}
	showspecial("regiones", $queryregiones);
	showspecial("temas", $querytemas);
	$descripcion = $getdocinfo[3];
	$titulo = $getdocinfo[1];
	$fechadecreacion = $getdocinfo[4];
	$fechamod = $getdocinfo[5];
	$tamano = $getdocinfo[13];

	echo "<br><font size=-1 face=\"verdana, arial, helvetica\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"/$dir/editoriales.php3\">$label_seccion</a> <b>: $label_documento</b></font><p>";
	echo "<center><font face=\"verdana, arial, helvetica\" size=+2>$getdocinfo[1]</font><font size=-1></center>";
	echo "<font size=-1 color=black>";
	echo "<blockquote>";
	echo "<b>$label_campo_autorprinc:</b> $autores";
	if (pg_numrows($queryautoressec) > 0) {
		echo "<br><b>$label_campo_autoressec:</b> $autoressec";
	}
	echo "<br><b>$label_campo_fechadecreacion:</b>  $fechadecreacion";
	echo "<br><b>$label_campo_fechamod:</b>  $fechamod";
	echo "<br><b>$label_campo_lengua:  </b>$getdocinfo[2]";
	showtrads($label_campo_trads, $querytraducciones);
	showdata($label_campo_regiones, $queryregiones);
	showdata($label_campo_temas, $querytemas);
	showdata($label_campo_proyectos, $queryproyectos);
	showmoredata($label_campo_lugar, "6");
	showmoredata($label_campo_editorial, "7");
	showmoredata($label_campo_tipo, "12");
	echo "<br><a href=\"/$dir/conexos.php3/docid/$docid\">$label_verconexos</a><br>";
	if (pg_numrows($queryadjuntos) > 0 && $getdocinfo[0] != "342") {
		echo "<p><b>$label_campo_adjuntos:</b><br>";	
		showadjuntos($queryadjuntos);
	}
	if ($mensaje_trad && $enlace_trad){
		echo "<BR>$mensaje_trad";
		echo "<BR>$enlace_trad </td></tr></table>";
	}
	if ($mensaje_trad && !$enlace_trad){
		echo "<BR>$mensaje_trad </td></tr></table>";
	}
	showcontenido($querycontenido);
		
}

if (!$noenlinea) {
	$tipoid = 11;
} else {
	$tipoid = 11;
	$label_todos = $label_noenlinea;
}
if ($sort) {
	if ($sort == "fecha") {	
		$sorter = "p.fechadecreacion DESC";
		$label_sort = $label_sortfecha;
	}
	if ($sort == "autor") {
		$sorter = "a.autorid";
		$label_sort = $label_sortautor;
	}
	if ($sort == "titulo") {
		$sorter = "p.titulo_$lang";
		$label_sort = $label_sorttitulo;
	}
	if ($sort == "lengua") {
		$sorter = "l.lenguaid";
		$label_sort = $label_sortlengua;
	}
} else {
	$sorter = "p.fechadecreacion DESC";
	$label_sort = $label_sortfecha;
}

if ($noenlinea) {

	$query = "SELECT p.docid, p.titulo_$lang, l.lengua, p.descripcion_$lang, al.autor, p.especial, p.fechadecreacion, p.kb, p.editorial_$lang, p.lugar_$lang FROM principal p, lenguas l, autorlista al, autores a WHERE al.autorid=a.autorid AND a.docid=p.docid AND l.lenguaid=p.lengua AND tipo='$tipoid' ORDER BY $sorter";
	$titleline = "<br><font size=-1 face=\"verdana, arial, helvetica\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"$SCRIPT_NAME\">$label_seccion</a> <b>: $label_todos : $label_sortpor $label_sort</b></font><br>";
	$sortline = "<font size=-2>$label_verdocs:  <a href=\"".$SCRIPT_NAME."/noenlinea/all/sort/fecha\">$label_sortfecha</a>  |  <a href=\"".$SCRIPT_NAME."/noenlinea/all/sort/titulo\">$label_sorttitulo</a>  |  <a href=\"".$SCRIPT_NAME."/noenlinea/all/sort/lengua\">$label_sortlengua</a>  |  <a href=\"".$SCRIPT_NAME."/noenlinea/all/sort/autor\">$label_sortautor</a><font size=-1><p>";

}

if ($todos) {
	
	$query = "SELECT p.docid, p.titulo_$lang, l.lengua, p.descripcion_$lang, al.autor, p.especial, p.fechadecreacion, p.kb, p.editorial_$lang, p.lugar_$lang FROM principal p, lenguas l, autorlista al, autores a WHERE al.autorid=a.autorid AND a.docid=p.docid AND l.lenguaid=p.lengua AND tipo='$tipoid' ORDER BY $sorter";
	$titleline = "<br><font size=-1 face=\"verdana, arial, helvetica\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"$SCRIPT_NAME\">$label_seccion</a> <b>: $label_todos : $label_sortpor $label_sort</b></font><br>";
	$sortline = "<font size=-2>$label_verdocs:  <a href=\"".$SCRIPT_NAME."/todos/all/sort/fecha\">$label_sortfecha</a>  |  <a href=\"".$SCRIPT_NAME."/todos/all/sort/titulo\">$label_sorttitulo</a>  |  <a href=\"".$SCRIPT_NAME."/todos/all/sort/lengua\">$label_sortlengua</a>  |  <a href=\"".$SCRIPT_NAME."/todos/all/sort/autor\">$label_sortautor</a><font size=-1><p>";

}

if ($regionid) {

	$regionquery = pg_exec($conn, "SELECT region_$lang FROM regionlista WHERE regionid='$regionid'");
	$getregiones = pg_fetch_row($regionquery, 0);
	
	$query = "SELECT DISTINCT p.docid, p.titulo_$lang, l.lengua, p.descripcion_$lang, al.autor, p.especial, p.fechadecreacion, p.kb, p.editorial_$lang, p.lugar_$lang FROM principal p, lenguas l, autorlista al, autores a, regionlista rl, regiones r WHERE al.autorid=a.autorid AND a.docid=p.docid AND l.lenguaid=p.lengua AND tipo='$tipoid' AND rl.regionid='$regionid' AND rl.regionid=r.regionid AND r.docid=p.docid ORDER BY $sorter";
	$titleline = "<br><font size=-1 face=\"verdana, arial, helvetica\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"$SCRIPT_NAME\">$label_seccion</a> <b>: $getregiones[0] : $label_sortpor $label_sort</b></font><br>";
	$sortline = "<font size=-2>$label_verdocs:  <a href=\"".$SCRIPT_NAME."/regionid/$regionid/sort/fecha\">$label_sortfecha</a>  |  <a href=\"".$SCRIPT_NAME."/regionid/$regionid/sort/titulo\">$label_sorttitulo</a>  |  <a href=\"".$SCRIPT_NAME."/regionid/$regionid/sort/lengua\">$label_sortlengua</a>  |  <a href=\"".$SCRIPT_NAME."/regionid/$regionid/sort/autor\">$label_sortautor</a><font size=-1><p>";

}

if ($temaid) {

	$temaquery = pg_exec($conn, "SELECT tema_$lang FROM temalista WHERE temaid='$temaid'");
	$gettemas = pg_fetch_row($temaquery, 0);
	
	$query = "SELECT DISTINCT p.docid, p.titulo_$lang, l.lengua, p.descripcion_$lang, al.autor, p.especial, p.fechadecreacion, p.kb, p.editorial_$lang, p.lugar_$lang FROM principal p, lenguas l, autorlista al, autores a, temalista tl, temas t WHERE al.autorid=a.autorid AND a.docid=p.docid AND l.lenguaid=p.lengua AND tipo='$tipoid' AND tl.temaid='$temaid' AND tl.temaid=t.temaid AND t.docid=p.docid ORDER BY $sorter";
	$titleline = "<br><font size=-1 face=\"verdana, arial, helvetica\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"$SCRIPT_NAME\">$label_seccion</a> <b>: $gettemas[0] : $label_sortpor $label_sort</b></font><br>";
	$sortline = "<font size=-2>$label_verdocs:  <a href=\"".$SCRIPT_NAME."/temaid/$temaid/sort/fecha\">$label_sortfecha</a>  |  <a href=\"".$SCRIPT_NAME."/temaid/$temaid/sort/titulo\">$label_sorttitulo</a>  |  <a href=\"".$SCRIPT_NAME."/temaid/$temaid/sort/lengua\">$label_sortlengua</a>  |  <a href=\"".$SCRIPT_NAME."/temaid/$temaid/sort/autor\">$label_sortautor</a><font size=-1><p>";
	
}

if ($temaid || $regionid || $todos || $noenlinea) {
	
	include("header.php3"); 
	echo "<center>";	
	echo $titleline;
	echo $sortline;
	echo "</center>";

	//display all titles

	$querytitles = pg_exec($conn, $query);
	$row = 0;
	include("displayeditoriales.inc");

}

if (!$docid && !$sort && !$temaid && !$regionid && !$noenlinea && !$todos) {

	include("header.php3"); 

	$queryregiones = pg_exec($conn, "SELECT DISTINCT rl.regionid, rl.region_$lang FROM regionlista rl, principal p, regiones r WHERE p.tipo=$tipoid AND p.docid=r.docid AND r.regionid=rl.regionid ORDER BY rl.regionid");
	$regionrow = 0;
	$querytemas = pg_exec($conn, "SELECT DISTINCT tl.temaid, tl.tema_$lang FROM temalista tl, principal p, temas t WHERE p.tipo=$tipoid AND p.docid=t.docid AND t.temaid=tl.temaid ORDER BY tl.temaid");
	$temarow = 0;
	$titulo = "Documentos de referencia";

	?>
	<table border=0 cellpadding=0 cellspacing=0 align=center width=100%>
	<tr>
	<td width="175" align=left valign=top>
	
		<table width=100% cellpadding=3 cellspacing=0 bgcolor="<?php echo $border_anuncios ?>" border=0><tr><td>
		<table width=100% border=0 cellpadding=3 cellspacing=0>
<?php
// begin anuncios

if ($lang == "es") {
	$label_anuncios = "ANUNCIOS";
	$label_fullstory = "conocer el asunto";
} else if ($lang == "fr") {
	$label_anuncios = "ANNONCES";
	$label_fullstory = "voir l'historique";
} else if ($lang == "en") {
	$label_anuncios = "HEADLINES";
	$label_fullstory = "see the full story";
}

	$queryanuncio = pg_exec($conn, "SELECT docid, titulo_$lang, descripcion_$lang, fechadecreacion FROM principal WHERE tipo=15 AND anuncio_editoriales>0 ORDER BY anuncio_editoriales");
	if (pg_numrows($queryanuncio) != 0) {
		?>
		<tr>
		<td colspan=2 align=center bgcolor="<?php echo $bg_top_anuncios ?>">
		<font face="verdana, arial, helvetica" color="<?php echo $font_top_anuncios ?>" size=-1><b><?php echo $label_anuncios ?></b></font>
		</td>
		</tr>
		<tr>
		<td colspan=2 bgcolor="<?php echo $bg_main_anuncios ?>" valign=top><font face="verdana, arial, helvetica"><p></p>

		<?php
		$i = 0;
		while ($i < pg_numrows($queryanuncio)) {
			$getanuncio = pg_fetch_row($queryanuncio, $i);
			echo "<font size=-1><a href=\"$getanuncio[2]\">$getanuncio[1]</a><p>\n";
			$i++;
		}
		echo "<br></br><p>\n</td>\n</tr>\n\n";
	}

//end anuncios
?>
		</table>
		</td></tr></table>
	</td>
	
	<td>
	<blockquote>
	<font face="verdana, arial, helvetica"><font size=+2><b><br>

	<?php echo $label_seccion ?></b>
	
	<p><font size=-1>
	<?php echo $label_descripcion."<br>".$label_verpor ?><p>
	
	<font size=+0>
	<b>
	<?php echo $label_lista_regiones ?>
	</b>
	<font size=-1>

	<br>

	<?php
	
	do {
		$getregiones = pg_fetch_row($queryregiones, $regionrow);
		echo "<a href=\"".$SCRIPT_NAME."/regionid/$getregiones[0]\">$getregiones[1]</a><br>";
		$regionrow++;
	} while ($regionrow < pg_numrows($queryregiones));
	
	?>
	<p>

	<font size=+0>
	<b>
	<?php echo $label_lista_temas ?>
	</b>
	<font size=-1>
	
	<br>

	<?php
	
	do {
		$gettemas = pg_fetch_row($querytemas, $temarow);
		echo "<a href=\"".$SCRIPT_NAME."/temaid/$gettemas[0]\">$gettemas[1]</a><br>";
		$temarow++;
	} while ($temarow < pg_numrows($querytemas));
	
	?>
	<p><br></br>

	</blockquote>

	</td>
	</tr>
	</table>
	
 	<?php 
}
include("footer.php3");
?>
