<?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_seccion = "LA INSTITUCIÓN";
	$label_titulo = "Convenios de FUNREDES";
	$label_descripcion = "Esta es una lista de los convenios oficiales que FUNREDES tiene con otras organizaciones.";

	$label_campo_lengua = "Lengua original";
	$label_campo_fechadecreacion = "Fecha de creaci&oacute;n";
	$label_campo_fechamod = "Fecha de modificaci&oacute;n de HTML";
	$label_campo_adjuntos = "Documentos adjuntos";
} else if ($lang == "fr") {
	$label_seccion = "L'INSTITUTION";
	$label_titulo = "Conventions de FUNREDES";
	$label_descripcion = "Ceci est une liste des conventions officielles entre FUNREDES et d'autres organisations.";

	$label_campo_lengua = "Langue d'origine";
	$label_campo_fechadecreacion = "Date de publication";
	$label_campo_fechamod = "Date d'actualization du HTML";
	$label_campo_adjuntos = "Documents attach&eacute;s";
} else if ($lang == "en") {
	$label_seccion = "OUR INSTITUTION";
	$label_titulo = "Funredes' Agreements";
	$label_descripcion = "Following is a list of the formal agreements Funredes has with other organizations.";

	$label_campo_lengua = "Original Language";
	$label_campo_fechadecreacion = "Date of Publication";
	$label_campo_fechamod = "Date of HTML Modification";
	$label_campo_adjuntos = "Attachments";
}

if (!$docid) {
	$titulo = $label_titulo;
}

// termina descripcion por idioma

echo "<font face=\"verdana, arial, helvetica\" size=-1>";
$conn = pg_pconnect("dbname=sif user=mike");

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>";
	}
}

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'");
	$getdocinfo = pg_fetch_row($querydocinfo, 0);
	$querycontlang = pg_exec($conn, "SELECT DISTINCT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$lenguaid'");
	if (pg_numrows($querycontlang) == 0) {
		$querycontlang2 = pg_exec($conn, "SELECT DISTINCT lenguaid FROM contenido WHERE docid='$docid' AND lenguaid='$getdocinfo[14]'");
		if (pg_numrows($querycontlang2) == 0) {
			$lenguaid = 1;
		} else {
			$lenguaid = $getdocinfo[14];
		}
	}	
	$querycontenido = pg_exec($conn, "SELECT DISTINCT * FROM contenido WHERE docid='$docid' AND lenguaid='$lenguaid' ORDER BY chunkid");
	$queryadjuntos = pg_exec($conn, "SELECT DISTINCT * FROM adjuntos WHERE docid='$docid'");	

	$descripcion = $getdocinfo[3];
	$titulo = $getdocinfo[1];
	$fechadecreacion = $getdocinfo[4];
	$fechamod = $getdocinfo[5];
	$tamano = $getdocinfo[13];
	
	include("../header.php3");

	include("institucion_mapa.inc");
?>
	<table width=100% border=0 cellpadding=0 cellspacing=0 onDblClick="location.href='http://funredes.org/admin/cambiar.php3'">
		<tr>
			<td width=175 valign=top>
				<table width=100% cellpadding=3 cellspacing=0 bgcolor="<?php echo $bg_menu ?>" border=0><tr><td>
				<table width=100% cellpadding=3 cellspacing=0>
					<tr>
						<td bgcolor="<?php echo $bg_menu ?>"><font face="<?php echo $font1 ?>" color="<?php echo $font_menu_title ?>" size=-1>
							<center><b><?php echo $label_seccion ?></b></center>
						</td>
					</tr>
					<tr>
						<td bgcolor="<?php echo $bg_menu_body ?>"><font face="<?php echo $font1 ?>" color="<?php echo $font_menu_body ?>" size=-2>
<?php 
							$i = 1;
							while ($i <= $total) {
								$temp = "label_$i";
								$label = "label_".$$temp;
								$url = "url_".$$temp;
								if ($REQUEST_URI != $$url) {
									echo "<a href=\"".$$url."\">".$$label."</a>\n<p>\n";
								}
								$i++;
							}
?>
							<br></br>
						</td>
					</tr>
				</table>
				</td></tr></table>
			</td>
			<td>

				<table width=100% cellpadding=3 cellspacing=0 border=0>
					<tr>
						<td valign=top>
<?php



	echo "<font size=-2 face=\"$font1\"><a href=\"/\">FUNREDES</a> <b>:</b> <a href=\"/$dir/institucion/\">$label_seccion</a> <b>: $titulo</b><p>";
	echo "<center><font face=\"$font1\" size=+2>$getdocinfo[1]</font><font size=-1></center>";
	echo "<font size=-1 color=black>";
	if (pg_numrows($queryadjuntos) > 0) {
		echo "<p><b>$label_campo_adjuntos:</b><br>";	
		showadjuntos($queryadjuntos);
	}
//	echo "<b>$label_campo_lengua:</b>  $getdocinfo[2]<p>";
	showcontenido($querycontenido);

?>
						</td>
					</tr>
				</table>
	</td></tr></table>
<?php

}


// empieza informacion basica




include("../footer.php3");
?>
