<?
if ( $user_auth && $user_level <= -1 )
{
 $blq1 ="pvp,descrCorta,descrLarga";

 $list = true;

 if ( isset( $sins ) )
 {
	displayForm( "./?dgo=adm/tdiscos.php&ins=new" );
	$list = false;
 }

 if ( isset( $smod ) ) 
 {	
	$res = @mysql_query( "SELECT id,$blq1  FROM TiposDiscos WHERE id=$smod", $conexion );
	$datos = @mysql_fetch_array( $res );

	list( $db_id, $db_pvp, $db_descrCorta, $db_descrLarga ) = $datos;

	displayForm( "./?dgo=adm/tdiscos.php&mod=$smod" );
	$list = false;
 }
 if ( isset( $mod ) )
 {
	$sql = "UPDATE TiposDiscos SET ".
		"pvp='$db_pvp' ".
		",descrCorta='$db_descrCorta' ".
		",descrLarga='".urlencode($db_descrLarga)."' ".
		" WHERE id=$mod";
	$res = @mysql_query( $sql, $conexion );

	$list = true;
 }

 if( isset( $ins ) )
 {
	$sql = "INSERT INTO TiposDiscos ($blq1) VALUES ('$db_pvp','$db_descrCorta','$db_descrLarga')";
	$res = @mysql_query( $sql, $conexion ) OR die( "Error<br>".@mysql_error($conexion) );

        echo "<h1>Nuevo tipo insertado</h1><br><br><br>";
        echo "<p class=remark>ID asignado = ".@mysql_insert_id($conexion)."</p>";
	$list = true;
 }

 if( isset( $del ) )
 {
	$res = @mysql_query( "DELETE FROM TiposDisco WHERE id=$del" );
	$list = true;
 }

 if ( isset( $list ) && $list )
 {
   displayList($conexion);
 }
 displayMenu();
}


function displayList($cnx)
{
 $thisLOCATION = "./?dgo=adm/tdiscos.php";
 $res = @mysql_query( "SELECT id, pvp, descrCorta FROM TiposDiscos", $cnx );

 echo "<br><br><br><table width=100% cellpadding=0 cellspacing=0 class=td_lista>";

 echo "<tr><td class=menuL>id</td>".
      "<td class=menuL>Descripci&oacute;n</td>".
      "<td class=menuL>PVP</td>".
      "<td>Borrar</td></tr>";

 while( $datos=@mysql_fetch_array($res) )
 {
  list ( $db_id, $db_pvp, $db_descrCorta )= $datos;
  echo "<tr><td><a href=\"./?dgo=adm/tdiscos.php&smod=$db_id\">$db_id</a></td>".
           "<td>$db_descrCorta</td>".
	   "<td>$db_pvp # $db_tlf2</td>".
	   "<td><a href=\"javascript::deleteUser($db_id)\">X</a></td></tr>";
 }
 echo "</table>";
 echo '<script language="JavaScript"> 
	function deleteUser( which )
	{
	  var submitOK = confirm("Atencion: Esta a punto de eliminar el Tipo de Disco.");
	  if ( submitOK )
		  document.location.href = "'.$thisLOCATION.'&del="+which;
	}
	</script>';
}

function displayMenu()
{
 echo '<hr noshade color="#800000">';
 echo '<p align="center"><a href="./?dgo=adm/tdiscos.php&sins=new">Insertar nuevo tipo</a></p>';
 echo '<hr noshade color="#800000">';
}

function displayForm( $form_action )
{
 global $db_id, $db_pvp, $db_descrCorta, $db_descrLarga;

 echo '<form action="'.$form_action.'" method="POST" name="register">';
 echo '<p align="center">&nbsp;</p><div align="center"><center>';
 echo '<table>';
 echo '<tr><td>Breve Descripci&oacute;n:</td><td><input type=text name=db_descrCorta value="'.$db_descrCorta.'"></td></tr>';
 echo '<tr><td>PVP</td><td><input type=text name=db_pvp value="'.$db_pvp.'"></td></tr>'; 
 echo '<tr><td valign=top>Descripci&oacute;n Larga:</td><td><textarea name=db_descrLarga rows=5 cols=20>'.urldecode($db_descrLarga).'</textarea></td></tr>';
 echo '</table>';
 echo  '<p align="center"><input type="button" name="btCancelar" value="Cancelar"><input
            type="submit" name="B2" value="Enviar &gt;&gt;"></p>';
 echo '</center></div></form>';
}
?>
