<?php 

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 = "LAS PUBLICACIONES DE FUNREDES";
	$label_titulo = "LAS PUBLICACIONES DE FUNREDES";
	$label_descripcion = "FUNREDES pone a su disposición todos sus documentos de publicaciones e investigaciones.";
	$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 documentos 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 = "Ver documentos por regi&oacute;n de relevancia:";
	$label_lista_temas = "Ver documentos 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 PUBLICATIONS DE FUNREDES";
	$label_titulo = "LES PUBLICATIONS DE FUNREDES";
	$label_descripcion = "FUNREDES met ŕ votre disposition tous ses documents de publications et de recherches...";
	$label_verpor = "Les documents sont organizés dans plusieurs façons:";
	$label_overpor = "Ou, les documents sont organizés par région ou sujet:";
	$label_verdocs = "voir les documents 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 = "Voir les documents par région:";
	$label_lista_temas = "Voir les documents 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 = "FUNREDES' PUBLICATIONS";
	$label_titulo = "FUNREDES' PUBLICATIONS";
	$label_descripcion = "FUNREDES makes available to you all our publications and research documents...";
	$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 documents 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 = "See Documents Organized by Region:";
	$label_lista_temas = "See Documents Organized by Subject:";

	$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 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 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 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 a.docid, al.autor FROM autores a, autorlista al WHERE a.docid='$docid' AND a.autorid=al.autorid");
	$queryautoressec = pg_exec($conn, "SELECT ac.docid, al.autor FROM autoressecundarios ac, autorlista al WHERE ac.docid='$docid' AND ac.autorid=al.autorid");
	$queryproyectos = pg_exec($conn, "SELECT p.docid, pl.proyecto FROM proyectos p, proyectolista pl WHERE p.proyectoid=pl.proyectoid AND p.docid='$docid'");
	$querytraducciones = pg_exec($conn, "SELECT 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 * FROM adjuntos WHERE docid='$docid'");	

	$getdocinfo = @pg_fetch_row($querydocinfo, 0);
	include("../header.php3"); 		

// si la pagina no esta en el idioma selectado :
	$lenguacont = $lenguaid;

	$querycontlang = pg_exec($conn, "SELECT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$lenguacont'");

	if (pg_numrows($querycontlang) == 0) {
		$mensaje_trad = $label_mensaje_trad;
		$querynblang = pg_exec($conn, "SELECT lenguaid FROM lenguas");
		$y = $z = 0;
		for ($x=1; $x<(pg_numrows($querynblang))+1; $x++) {

			$querycontlang2 = pg_exec($conn, "SELECT 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 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 * 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/publicaciones/index.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) {
		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 = 1;
} else {
	$tipoid = 7;
	$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 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 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("displaypublicaciones.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";

	?>
	<font face="verdana, arial, helvetica"><font size=+1><br><center>

	<?php echo $label_seccion ?>
	
	<p><font size=-1>

	<?php echo $label_descripcion."<br>".$label_verpor ?><p>
	
	</center>
	<blockquote>	
	<table cellpadding=5 align=center>
	<tr>

<?php
if (strstr($REQUEST_URI, "/texto/")) {
	?>
	<td></td>
	<td valign=top><font face="verdana, arial, helvetica" size=-1>
	<a href="<?php echo $SCRIPT_NAME ?>/todos/all/sort/titulo">
	<?php echo $label_sorttitulo ?>
	</a><br>
	<a href="<?php echo $SCRIPT_NAME ?>/todos/all/sort/fecha">
	<?php echo $label_sortfecha ?>
	</a><br>
	<a href="<?php echo $SCRIPT_NAME ?>/todos/all/sort/lengua">
	<?php echo $label_sortlengua ?>
	</a><br>
	<a href="<?php echo $SCRIPT_NAME ?>/todos/all/sort/autor">
	<?php echo $label_sortautor ?>
	</a><br>
	</td>
	<?php
} else {
	echo "<td colspan=2><center>";
	$size_fecha = GetImageSize("/home/httpd/html/images/publicaciones_fecha_$lang.gif"); 
	$size_titulo = GetImageSize("/home/httpd/html/images/publicaciones_titulo_$lang.gif"); 
	$size_autor = GetImageSize("/home/httpd/html/images/publicaciones_autor_$lang.gif"); 
	$size_lengua = GetImageSize("/home/httpd/html/images/publicaciones_lengua_$lang.gif"); 
	echo "<a href=\"$SCRIPT_NAME/todos/all/sort/fecha\"><img src=\"/images/publicaciones_fecha_$lang.gif\" border=0 alt=\"$label_sortfecha\" $size_fecha[3]></a>";
	echo "<a href=\"$SCRIPT_NAME/todos/all/sort/titulo\"><img src=\"/images/publicaciones_titulo_$lang.gif\" border=0 alt=\"$label_sorttitulo\" $size_titulo[3]></a><br>";
	echo "<a href=\"$SCRIPT_NAME/todos/all/sort/autor\"><img src=\"/images/publicaciones_autor_$lang.gif\" border=0 alt=\"$label_sortautor\" $size_autor[3]></a>";
	echo "<a href=\"$SCRIPT_NAME/todos/all/sort/lengua\"><img src=\"/images/publicaciones_lengua_$lang.gif\" border=0 alt=\"$label_sortlengua\" $size_lengua[3]></a><br>";
	echo "</td>";
}

?>		
	</tr>

	<tr>
	<td valign=top align=right>
	<b><font face="verdana, arial, helvetica" size=-1>

	<?php echo $label_lista_regiones ?>

	</b></td><td valign=top><font face="verdana, arial, helvetica" size=-1> 
	 <?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));
	
	?>
	</td></tr><tr><td valign=top align=right><font face="verdana, arial, helvetica" size=-1><b>

	<?php echo $label_lista_temas ?>

	</b></td><td valign=top><font face="verdana, arial, helvetica" size=-1> 
	<?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));
	
	?>
	</td></tr></table></blockquote>
	<p><br></br>
	
 	<?php 
}
include("../footer.php3");
?>

