<?
 require( "../addons/open_db.php" );
 require( "../addons/autenticate.php" );
 if ( ! $user_auth ) die( "<META CONTENT=\"0; URL=..\error.htm\" HTTP-EQUIV=\"REFRESH\"> ");

 $showF = "";

 
 if ( isset( $delFt ) )
 {
  `rm -rf db/discos/$idd_c_$smod_$delFt_*`;
  @mysql_query( "UPDATE cancionesDisco SET $FIELD_T='' WHERE id=$smod");
 }

 if ( isset( $idd ) )
 {
  if ( isset( $sins ) )
   $showF = "$PHP_SELF?idd=$idd&ins=new";
  if ( isset( $ins ) )
  {
   $FIELDS = "idd, posicion, duracion, titulo, autorMusica, autorLetra";
   $FVALUES= "'$idd', '$db_posicion', '$db_duracion', '$db_titulo', '$db_autorMusica', '$db_autorLetra'"; 
   $res = @mysql_query( "INSERT INTO cancionesDisco ($FIELDS) VALUES ($FVALUES)", $conexion );
   $ins = @mysql_insert_id($conexion);
   $showF = "$PHP_SELF?idd=$idd&mod=$ins";   
   $smod = $ins;
  }
  if ( isset( $mod ) )
  {
   $VALUES = "posicion='$db_posicion', duracion='$db_duracion', titulo='$db_titulo', autorMusica='$db_autorMusica', autorLetra='$db_autorLetra'";
   $res = @mysql_query( "UPDATE cancionesDisco SET $VALUES WHERE id=$mod", $conexion )  OR Die("error ".mysql_error($conexion));
   $smod = $mod; 
  }
  if ( isset( $smod ) )
  {
   $res = @mysql_query( "SELECT id, posicion, titulo, duracion, autorMusica, autorLetra, f_partitura, f_audio, f_letra, f_midi FROM cancionesDisco WHERE id=$smod", $conexion );
   $datos = @mysql_fetch_array($res);
   $showF = "$PHP_SELF?idd=$idd&mod=$smod";
  }
  if ( isset( $del ) )
  { 
   `rm -rf db/discos/$idd_c_*`;
   @mysql_query( "DELETE FROM cancionesDisco WHERE id=$del", $conexion );
   echo "<html><head><script>self.close();</script></head></html>";
  }
 }

 if ( !empty( $showF ) )
 {
   print_header();
   showForm($showF, $datos);
   print_footer();
 }
mysql_close($conexion);

function showForm( $action, $datos )
{
 global $idd;
 list( $db_id, $db_posicion, $db_titulo, $db_duracion, $db_autorMusica, $db_autorLetra, $db_fp, $db_fa, $db_fl, $db_fm ) = $datos;
 echo '<form method="POST" action="'.$action.'">
    <p><strong><u>Datos de la canción:</u></strong></p>
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>Posición:</td>
            <td><input type="text" size="15" name="db_posicion" value="'.$db_posicion.'"></td>
        </tr>
        <tr>
            <td>Titulo:</td>
            <td><input type="text" size="15" name="db_titulo" value="'.$db_titulo.'"></td>
        </tr>
        <tr>
            <td>Duración</td>
            <td><input type="text" size="15" name="db_duracion" value="'.$db_duracion.'"></td>
        </tr>
        <tr>
            <td>Autor Letra</td>
            <td><input type="text" size="15" name="db_autorLetra" value="'.$db_autorLetra.'"></td>
        </tr>
        <tr>
            <td>Autor Musica</td>
            <td><input type="text" size="15" name="db_autorMusica" value="'.$db_autorMusica.'"></td>
        </tr>

        <tr>
            <td align="center" colspan="2"><br><center>';
 if ( !empty($db_fp) ) echo "[ <a href='$PHP_SELF?idd=$idd&mod=$db_id&delFt=P'>-</a>".
                             " <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=P', 320, 200);\">+</a>".
			     " <a href='../db/discos/$idd"."_c_".$db_id."_P_"."$db_fp' target='_blank'>Partitura</a>".
			    "] ";
  else if ( isset( $db_id ) )
  		       echo "[ - ".
			    	"  <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft==P', 320, 200);\">+</a>".
			    " Partitura ".
			   " ] ";
 if ( !empty($db_fa) ) echo "[ <a href='$PHP_SELF?idd=$idd&mod=$db_id&delFt=A'>-</a>".
                             " <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=A', 320, 200 );\">+</a>".
			     " <a href='../db/discos/$idd"."_c_".$db_id."_A_"."$db_fa' target='_blank'>Audio</a>".
			    "] ";
  else if ( isset( $db_id) )
  		       echo "[ - ".
			    "  <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=A', 320, 200 );\">+</a>".
			    " Audio ".
			   " ] ";

 if ( !empty($db_fl) ) echo "[ <a href='$PHP_SELF?idd=$idd&mod=$db_id&delFt=L'>-</a>".
                             " <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=L', 320, 200 );\">+</a>".
			     " <a href='../db/discos/$idd"."_c_".$db_id."_L_"."$db_fl' target='_blank'>Letra</a>".
			    "] "; 
  else if ( isset( $db_id ) )
  		       echo "[ - ".
			    "  <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=L', 320, 200 );\">+</a>".
			    " Letra ".
			   " ] ";

 if ( !empty($db_fm) ) echo "[ <a href='$PHP_SELF?idd=$idd&mod=$db_id&delFt=M'>-</a>".
                             " <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=M', 320, 200 );\">+</a>".
			     " <a href='../db/discos/$idd"."_c_".$db_id."_M_"."$db_fm' target='_blank'>Midi</a>".
			    "] "; 
  else if ( isset( $db_id ) )
  		       echo "[ - ".
			    "  <a href=\"javascript:abreVentana( selectFT, 'insertFC.php?idd=$idd&idc=$db_id&ft=M', 320, 200 );\">+</a>".
			    " Midi ".
			   " ] ";
 echo '</center></td>
        </tr>
    </table><br><center><input type="submit" value="enviar &gt;&gt;"></center>
</form>'; 

}

function print_header()
{
echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>Portal -web- --------------------------------------------------------------www.infdj.com-----------------------------------------------------------------------------------------------------</title>
      <link rel="stylesheet" type="text/css" href="../addons/estilo.css" body="../addons/estilo.css">
      <script language="JavaScript" src="../addons/misc.js"></script>
      <script language="JavaScript">var selectFT="selectFT";</script>
	</head>
      <body background="../images/bg.gif" text="#000000">';
}

function print_footer()
{
echo '</body></html>';
}
