<?
  require("addons/open_db.php");
  if ( ( !empty( $db_asunto ) && !empty( $db_noticia ) ) || isset( $del ) )
  {
	session_name( "INFDJwebsite" );
		$v1="user_id";
		$v2="user_auth";
		$v3="user_level";
		session_register($v1,$v2,$v3);
	session_start();

   if ( isset( $del ) && $user_auth && $user_level == -2 )
	    $res = mysql_query( "DELETE FROM news WHERE id=$del", $conexion ) OR die("No puedo eliminar la noticia");
   if ( isset( $add ) && $user_auth && $user_level <= -1 )
	    $res = mysql_query( "INSERT INTO news (fecha, uid, asunto, noticia) VALUES (CURDATE(), '$user_id', '".addslashes($db_asunto)."','".addslashes($db_noticia)."')", $conexion ) OR die("No puedo insertar la noticia");
   if ( isset( $mod ) && $user_auth && $user_level == -2 )
	    $res = mysql_query( "UPDATE news SET uid='$user_id', asunto='".addslashes($db_asunto)."', noticia='".addslashes($db_noticia)."' WHERE id=$mod", $conexion ) OR die("No puedo modificar la noticia");
  }
  if ( !isset( $go ) )
	$go = 1;
  $go--;
  $res = mysql_query( "SELECT fecha, asunto, noticia, id FROM news ORDER BY fecha+id DESC LIMIT $go, 1", $conexion ) OR die("No puedo realizar la consulta<br>$sql_upd<br>".mysql_error($conexion)); 
  $numrows = mysql_num_rows( $res ); 
  if (  $numrows > 0 ) 
   $datos = mysql_fetch_array($res);
?>


<html>

<head></head>

<body bgcolor="#2067BE" text="#B4CCE9" topmargin="0"
leftmargin="0" style="scrollbar-base-color: #000000; 
scrollbar-arrow-color: #FFFFFF;
scrollbar-face-color: #gray; 
scrollbar-shadow-color: #444444;">
<?
 if ( isset( $sdel ) ) {

 echo "<script languaje=\"javascript\">
	   if ( confirm(\"Atencion: Esta a punto de eliminar la noticia.\") )
		document.location.href = \"noticias.php?del=$datos[3]\"
	</script>";
 } else 
 if ( isset( $sadd ) || isset( $smod ) ) { ?>
<form method="post" action="<? echo "$PHP_SELF?"; if ( isset( $sadd ) ) echo "add=this"; else echo "mod=$datos[3]"; ?>"><p>
<input type=text maxlength=60 name="db_asunto" <? if (isset($smod)) echo "value=\"$datos[1]\""; ?>
 style="width: 100%; font-family: arial, serif;font-size: 8pt;background-color: #5088CC;border: 1px solid #97B8E1;">
<textarea name="db_noticia" style="overflow: auto;
background-color:#2067BE;
LAYER-BACKGROUND-COLOR:#2067BE;
color: #FFFACD;
font-family: arial, serif;
font-size: 8pt;
line-height: 105%;
left: 0px;
font-weight: medium;
scrollbar-base-color: #000000; 
scrollbar-arrow-color: #FFFFFF;
scrollbar-face-color: #gray; 
scrollbar-shadow-color: #444444;
border: 0px solid black; height: 100px; width: 100%;
CLIP: rect(0,100%,100,0)"><? if (isset($smod)) echo "$datos[2]"; ?></textarea>
<input type="image" name src="images/enviar.gif" border="0" width="71" height="14"></p>
</form>
<?} else {

 echo '<p style="font-family: verdana, arial, serif; font-size: 8pt;">';
//  $numrows = mysql_num_rows( $res ); 
  if (  $numrows > 0 ) 
  { 
//   $datos = mysql_fetch_array($res);

     echo "$datos[0]<br>"; 
     echo "<font color=\"#00FF00\">".stripslashes($datos[1])."</font>";
     echo "<br>".nl2br(stripslashes($datos[2]))."<br><br>";

  } else { 
    echo "No hay noticias en el sistema"; 
  }
  mysql_free_result($res);
  mysql_close($conexion); 
 echo "</p>";
}
?>
</body>
</html>
