<?
$id=$_SESSION['id'];
/*$q = mysql_query("select tematica_codigo from tematica", $link);
$n = mysql_num_rows($q);
mysql_free_result($q);

mysql_query("delete from orien_tem where insti_codigo=".$_SESSION['id'], $link);
for ($i=1; $i<=$n; $i++){
	$cad = "i029".$i;
	if(!empty($HTTP_POST_VARS[$cad])){
		mysql_query("insert into orien_tem(insti_codigo, tematica_codigo) values ($id ,$HTTP_POST_VARS[$cad])", $link);
	}
}*/
$q = mysql_query("select max(tematica_codigo) from tematica", $link);
$n = mysql_fetch_row($q);
mysql_free_result($q);
mysql_query("delete from orien_tem where insti_codigo=".$_SESSION['id'], $link);
for ($i=1; $i<=$n[0]; $i++){
	$cad = "i029".$i;
	if(!empty($_POST[$cad])){
		mysql_query("insert into orien_tem(insti_codigo, tematica_codigo, rank) values ($id , $i, $_POST[$cad])", $link);
	}
}

mysql_query("update insti set insti_presup_anual='$i030', insti_num_empl='$i032' where insti_codigo=$id", $link);

$q = mysql_query("select fuentes_fin_codigo from fuentes_fin", $link);
$n = mysql_num_rows($q);
mysql_free_result($q);
mysql_query("delete from insti_fin where insti_codigo=".$_SESSION['id'], $link);
for ($i=1; $i<=$n; $i++){
	$cad = "i031".$i;
	if(!empty($HTTP_POST_VARS[$cad])){
		mysql_query("insert into insti_fin(insti_codigo, fuentes_fin_codigo) values ($id ,$HTTP_POST_VARS[$cad])", $link);
	}
}
header("location:index4-1.htm");
?>