#!/usr/bin/perl

use Pg;

require("../cgi-lib.pl");
require("./MenuPrincipal.lib");

&ReadParse;

$bib_id = $in{'bib_id'};
$dir_id = $in{'dir_id'};
$dep_id = $in{'dep_id'};
$ND = $in{'ND'};    $NB = $in{'NB'};    $area = $in{'area'};
$opt = $in{'opt'};  $dgb = $in{'dgb'};  $hx = $in{'hx'};
$Passwd = $in{'Passwd'};  
$cargo = $in{'cargo'}; $Dependencia = $in{'Dependencia'};  $Subsistema = $in{'Subsistema'};

print "Content-type: text/html\n\n";
print " <HTML><HEAD> ";
print " <link href=\"/Directorio/CascadeMenu.css\" rel=\"stylesheet\"> ";
print " <script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"/Directorio/stm31.js\"></script>\n ";
print " <script language=\"javascript\"> ";
print "function carga(){ ";

#print " if(document.forms[0].elements[1].value == \"0\" && document.forms[0].elements[2].value == \"0\"){ ";
#print " alert(\"Debe llenar un campo de los dos ultimos para continuar.\"); ";
#print " document.forms[0].elements[1].focus(); return;} ";
#print " if(document.forms[0].elements[1].value > \"\" && document.forms[0].elements[2].value > \"0\"){ ";
#print " alert(\"Solo debe seleccionar uno de los dos ultimos campos.\"); ";
#print " document.forms[0].elements[2].focus(); return;} ";

print " document.forms[0].action=\"BibEtiquetaSub.pl\"; ";
print " document.forms[0].submit(); } ";

print " </script> ";

# Colocar el nombre del campo
        open(EXPANDIR, ">EtiquetaSub.txt");
        print (EXPANDIR "Funcionario \t");
        print (EXPANDIR "Correo \t");
        print (EXPANDIR "Telfono 1 \t");
        print (EXPANDIR "Telfono 2 \t");
        print (EXPANDIR "Dependencia \t");
        print (EXPANDIR "Biblioteca \t");
        print (EXPANDIR "Ubicacin Dependencia \t");
        print (EXPANDIR "Localidad, Municipio - Dependencia \t");
        print (EXPANDIR "Ciudad, estado - Dependencia \t");
        print (EXPANDIR "Pas, Cdigo Postal - Dependencia \t");
        print (EXPANDIR "Ubicacin Biblioteca \t");
        print (EXPANDIR "Localidad, Municipio - Biblioteca \t");
        print (EXPANDIR "Ciudad, estado - Biblioteca \t ");
        print (EXPANDIR "Pas, Cdigo Postal - Biblioteca \t");
        print (EXPANDIR "Clave Hexadecimal \t");
        print (EXPANDIR "Clave DGB \t");
        print (EXPANDIR "Apartado Postal - Dependencia \t");
        print (EXPANDIR "Pas, Ciudad - Apartado Postal Dependencia \t");
        print (EXPANDIR "Localidad, Municipio - Apartado Postal Dependencia \t");
        print (EXPANDIR "Codigo Postal - Apartado Postal Dependencia \t");
        print (EXPANDIR "Apartado Postal - Biblioteca \t");
        print (EXPANDIR "Pas, Ciudad - Apartado Postal Biblioteca \t");
        print (EXPANDIR "Localidad, Municipio - Apartado Postal Biblioteca \t");
        print (EXPANDIR "Codigo Postal - Apartado Postal Biblioteca \t");
        print (EXPANDIR " \n");
        close EXPANDIR;
# Termina el nombre del campo



print " <TITLE>Sistema Bibliotecario de la UNAM</TITLE></HEAD> ";
print " <BODY bgColor=aliceblue> ";

Encabezado();

$conn = Pg::connectdb("dbname=directorio user=israeld password=Raia69*-+");

if ($conn->status != 0)
{  print "No hay conexion a la base de datos";
}
else
{
	        Pg::doQuery ($conn, "SELECT * FROM normatividad                                                                                                  WHERE bib_id = $bib_id", \@aryNorm);

	print "<br><br><form>";
	print "<table align=\"center\" width=\"70%\" border=\"0\">";	
	print "<tr><td bgcolor=\"#ACBED8\">Cargo</td>";
	print "<td bgcolor=\"#C6DBF8\"><select name=\"cargo\" > ";
	print "<option value=\"1\">Director de la Dependencia </option>";
	print "<option value=\"2\">Unidad Administrativa de la Dependencia</Option>";
	print "<option value=\"3\">Unidad de Presupuesto de la Dependencia</Option>";
    print "<option value=\"8\">Director de la Sub Dependencia </option>";
    print "<option value=\"9\">Unidad Administrativa de la Sub Dependencia</Option>";
    print "<option value=\"10\">Unidad de Presupuesto de la Sub Dependencia</Option>";
	print "<option value=\"4\">Coordinador de la Biblioteca</Option>";
	print "<option value=\"5\">Responsable de la Biblioteca</Option>";	
    print "<option value=\"6\">Responsable de la Hemeroteca de la Biblioteca</Option>";
    print "<option value=\"7\">Responsable de Procesos Tcnicos</Option>";
    print "<option value=\"11\">Coordinador and Responsable</Option>";
	print "</select></td></tr>";
	print " <tr> <td width=\"122\" bgcolor=\"#ACBED8\"> Dependencia </td> ";
	print " <td width=\"219\" bgcolor=\"#C6DBF8\"> ";
	print " <select name=\"Dependencia\" > ";
	print " <option value=\"0\">----------------</option> ";
	print " <option value=\"999\">Todas</option> ";
	
	#Carga la dependencia 
	
	Pg::doQuery ($conn, "SELECT dep_id, nom_depen FROM datosdepen order by nom_depen", \@aryDepen);
	$i = 0;
	
        while ($i <= $#aryDepen)
	{
      		print " <option value=$aryDepen[$i][0]> $aryDepen[$i][1] </option> ";
      		$i = $i + 1;
	}
	print " </select> </td> </tr> ";

	#Carga la Subdependencia

	Pg::doQuery ($conn, "SELECT distinct(subsistema) FROM datosbiblio WHERE bib_id > 0", \@arySubsist);
	print " <tr> <td width=\"122\" bgcolor=\"#ACBED8\">Subsistema </td> <td width=\"219\" bgcolor=\"#C6DBF8\"> ";
	print " <select name=\"Subsistema\" > ";
	print " <option value=\"\">---------------------</option> ";
	$i = 0;
	while ($i <= $#arySubsist)
	{
        	print " <option value=\"$arySubsist[$i][0]\">$arySubsist[$i][0]</option>";
        	$i = $i + 1 ;
	}
	print " </select> </td> </tr> ";
	print " </table><br><br> ";

	#Carga los botones

print " <table border=\"0\" align=\"center\"> ";
print " <tr><td><a href=\"Index.pl?area=$area&Passwd=$Passwd\"><img src=\"/Directorio/Inicio.jpg\" border=\"0\"> </a></td> ";
print " <td><a href=\"download.pl\" border=\"0\"><img src=\"/Directorio/Bajar_Archivo.gif\" width=\"120\" height=\"30\"  border=\"0\"> </a></td> ";
print " <td><img src=\"/Directorio/Crear_Etiquetas.gif\" width=\"120\" height=\"30\"  border=\"0\"  onClick=\"carga()\"></td></tr>";
print " </table> ";

if ($Dependencia > 0 && $Subsistema eq "")
{
    if ($Dependencia < 999)
    {

	Pg::doQuery ($conn, "SELECT direccion.bib_id, direccion.dir_id, direccion.dep_id, datosbiblio.bib_id, datosbiblio.control_hx, 
			datosbiblio.control_dgb,datosdepen.nom_depen, datosbiblio.nombre
			FROM datosbiblio, direccion, datosdepen
                        WHERE datosbiblio.bib_id = direccion.bib_id
                        AND direccion.dep_id = datosdepen.dep_id
                        AND direccion.bib_id > 0
                        AND direccion.subdep_id >= 0
                        AND direccion.dep_id = $Dependencia
                        ORDER BY datosdepen.nom_depen", \@aryBibs);


        #Pg::doQuery ($conn, "SELECT bib_id, dir_id, dep_id 
	#		     FROM direccion 
	#		     WHERE dep_id = $Dependencia", \@aryBibs);
    }
    else
    {
	
	Pg::doQuery ($conn, "SELECT direccion.bib_id, direccion.dir_id, direccion.dep_id, datosbiblio.bib_id, datosbiblio.control_hx,   
                       datosbiblio.control_dgb,datosdepen.nom_depen, datosbiblio.nombre
                       FROM datosbiblio, direccion, datosdepen        
                       WHERE datosbiblio.bib_id = direccion.bib_id
                       AND direccion.dep_id = datosdepen.dep_id   
                       AND direccion.bib_id > 0
                       ORDER BY datosdepen.nom_depen", \@aryBibs);

	
	#Pg::doQuery ($conn, "SELECT bib_id, dir_id, dep_id 
	#		     FROM direccion
	#		     WHERE dep_id > 0
	#		     AND bib_id > 0 ", \@aryBibs);
    }

        $i = 0;
	$reg = $#aryBibs + 1;
                print " <br><center><b> Busqueda realizada por Dependencia  <br><br> ";
                print " Nmero de registros: $reg </b></center><br> ";
 

        while ($i <= $#aryBibs)

        {
                Pg::doQuery ($conn, "SELECT  datospersona.per_id, datospersona.grado, datospersona.nombre, datospersona.mail_1, datospersona.tel_1, datospersona.tel_2, datospersona.tel_3
                             	     FROM persona, datospersona
                                     WHERE persona.cargo = $cargo
                             	     AND persona.per_id = datospersona.per_id
                              	     AND persona.bib_id = $aryBibs[$i][0]", \@aryPer1);
		if ($cargo=11)
			{
				Pg::doQuery ($conn, "SELECT  datospersona.per_id, datospersona.grado, datospersona.nombre, datospersona.mail_1, datospersona.tel_1, datospersona.tel_2, datospersona.tel_3
                             	     FROM persona, datospersona
                                     WHERE persona.cargo = 4
                             	     AND persona.per_id = datospersona.per_id
                              	     AND persona.bib_id = $aryBibs[$i][0]", \@aryPer1);
				Pg::doQuery ($conn, "SELECT  datospersona.per_id, datospersona.grado, datospersona.nombre, datospersona.mail_1, datospersona.tel_1, datospersona.tel_2, datospersona.tel_3
                             	     FROM persona, datospersona
                                     WHERE persona.cargo = 5
                             	     AND persona.per_id = datospersona.per_id
                              	     AND persona.bib_id = $aryBibs[$i][0]", \@aryPer2);
			}
                Pg::doQuery ($conn, "SELECT  direccion.calle, direccion.localidad, direccion.municipio,
                                             direccion.ciudad, direccion.estado, direccion.pais, direccion.apdo_id,
                                             direccion.cod_post
                                     FROM direccion
                                     WHERE direccion.bib_id = 0
				     AND direccion.subdep_id = 0
				     AND dep_id = $aryBibs[$i][2]", \@aryDirD);

                Pg::doQuery ($conn, "SELECT  direccion.calle, direccion.localidad, direccion.municipio,
                                             direccion.ciudad, direccion.estado, direccion.pais, direccion.apdo_id, 
					     direccion.cod_post
                             	     FROM direccion, datosbiblio
                                     WHERE direccion.bib_id = $aryBibs[$i][0]", \@aryDir);

                Pg::doQuery ($conn, "SELECT *
                             	     FROM apdopost
                             	     WHERE apdo_id = $aryDir[0][6]", \@aryApdo);

                Pg::doQuery ($conn, "SELECT *
                                     FROM apdopost
                                     WHERE apdo_id = $aryDirD[0][6]", \@aryApdoD);

                Pg::doQuery ($conn, "SELECT datosdepen.nom_depen
                             	     FROM datosdepen, direccion, datosbiblio
                             	     WHERE direccion.dep_id = datosdepen.dep_id
                             	     AND direccion.bib_id = $aryBibs[$i][0]", \@aryNomI);

		Pg::doQuery ($conn, "SELECT nombre, control_hx, control_dgb
                                     FROM  datosbiblio
                                     WHERE bib_id = $aryBibs[$i][0]", \@aryHx);

                print " <table border=\"1\" width=\"75%\" align=\"center\" >";

	if ($cargo=11)
	{
		if($aryPer1[0][2] ne "")
		{
                print " <tr><td><b> Coordinador : </b><br> ";
                print "           $aryPer1[0][1]   $aryPer1[0][2] </td></tr> ";
                print "  <tr><td><b> Correo: </b><br> ";
                print "           $aryPer1[0][3] </td></tr> "; 
                print "  <tr><td><b> Tel&eacute;fono: </b><br> ";
                print "           $aryPer1[0][4] <br> "; 
                print "           $aryPer1[0][5] </td></tr> "; 
		}
		if($aryPer2[0][2] ne "")
		{
				print " <tr><td><b> Responsable : </b><br> ";
                print "           $aryPer2[0][1]   $aryPer2[0][2] </td></tr> ";
                print "  <tr><td><b> Correo: </b><br> ";
                print "           $aryPer2[0][3] </td></tr> "; 
                print "  <tr><td><b> Tel&eacute;fono: </b><br> ";
                print "           $aryPer2[0][4] <br> "; 
                print "           $aryPer2[0][5] </td></tr> "; 
		}
	}
	
	if($aryPer1[0][2] ne "" and not $cargo=11 )
	{
                print " <tr><td><b> Funcionario : </b><br> ";
                print "           $aryPer1[0][1]   $aryPer1[0][2] </td></tr> ";
                print "  <tr><td><b> Correo: </b><br> ";
                print "           $aryPer1[0][3] </td></tr> "; 
                print "  <tr><td><b> Tel&eacute;fono: </b><br> ";
                print "           $aryPer1[0][4] <br> "; 
                print "           $aryPer1[0][5] </td></tr> "; 
	}
                print " <tr><td><b> Dependencia : </b><br> ";
                print " <tr><td> $aryNomI[0][0] : </b><br> ";
		print "<tr><td><b>Biblioteca : </b><br> ";
		print " <tr><td> $aryHx[0][0] </td></tr> ";
                print " <tr><td><b> Ubicacin Dependencia : </b><br> ";
                print "          $aryDirD[0][0] ";
                print "          $aryDirD[0][1],     $aryDirD[0][2] <br>";
                print "          $aryDirD[0][3],     $aryDirD[0][4] <br>";
                print "          $aryDirD[0][5],     $aryDirD[0][7] </td></tr>";
                print " <tr><td><b> Ubicacin Biblioteca : </b><br> ";
                print "          $aryDir[0][0] ";
                print "          $aryDir[0][1],     $aryDir[0][2] <br>";
                print "          $aryDir[0][3],     $aryDir[0][4] <br>";
                print "          $aryDir[0][5],     $aryDir[0][7] </td></tr>";
                print " <tr><td><b> Clave Hexadecimal / Clave DGB : </b><br> ";
                print "          $aryHx[0][1] <br>";
                print "          $aryHx[0][2] </td></tr> ";
                print " <tr><td><b> Apartado Postal de la Dependencia : </b><br> ";
                print "          $aryApdoD[0][0] ";
                print "          $aryApdoD[0][3]     $aryApdoD[0][2] <br>";
                print "          $aryApdoD[0][5]     $aryApdoD[0][4] <br>";
                print "          $aryApdoD[0][1]     </td></tr>";
                print " <tr><td><b> Apartado Postal de la Biblioteca : </b><br> ";
                print "          $aryApdo[0][0] ";
                print "          $aryApdo[0][3]     $aryApdo[0][2] <br>";
                print "          $aryApdo[0][5]     $aryApdo[0][4] <br>";
                print "          $aryApdo[0][1]     </td></tr>";
                print " </table><br> ";

                open(EXPANDIR, ">>EtiquetaSub.txt");

if($aryPer1[0][2] ne "")
  {
                print (EXPANDIR "$aryPer1[0][1] $aryPer1[0][2] \t");
  }else{        
                print (EXPANDIR "-------- \t");
  }

if($aryPer1[0][2] ne "" and $cargo=11)
  {
                print (EXPANDIR "$aryPer1[0][1] $aryPer1[0][2] \t");
  }else{        
                print (EXPANDIR "-------- \t");
  }
  
if($aryPer1[0][3] ne "")
  {
                print (EXPANDIR "$aryPer1[0][3] \t");
  }else{
                print (EXPANDIR "-------- \t");
  }

if($aryPer1[0][3] ne "" and $cargo=11 )
  {
                print (EXPANDIR "$aryPer1[0][3] \t");
  }else{
                print (EXPANDIR "-------- \t");
  }

#                print (EXPANDIR "$aryPer1[0][1] $aryPer1[0][2] \t");
                print (EXPANDIR "$aryPer1[0][4] \t");
                print (EXPANDIR "$aryPer1[0][5] \t");
                print (EXPANDIR "$aryNomI[0][0] \t");
                print (EXPANDIR "$aryHx[0][0] \t");
                print (EXPANDIR "$aryDirD[0][0] \t");
                print (EXPANDIR "$aryDirD[0][1]     $aryDirD[0][2] \t");
                print (EXPANDIR "$aryDirD[0][3]     $aryDirD[0][4] \t");
                print (EXPANDIR "$aryDirD[0][5]     $aryDirD[0][7] \t");
                print (EXPANDIR "$aryDir[0][0] \t");
                print (EXPANDIR "$aryDir[0][1]     $aryDir[0][2] \t");
                print (EXPANDIR "$aryDir[0][3]     $aryDir[0][4] \t");
                print (EXPANDIR "$aryDir[0][5]     $aryDir[0][7] \t");
                print (EXPANDIR "$aryHx[0][1] \t");
                print (EXPANDIR "$aryHx[0][2] \t");
                print (EXPANDIR "$aryApdoD[0][0] \t");
                print (EXPANDIR "$aryApdoD[0][3] $aryApdoD[0][2] \t");
                print (EXPANDIR "$aryApdoD[0][4] $aryApdoD[0][5] \t");
                print (EXPANDIR "$aryApdoD[0][1] \t");
                print (EXPANDIR "$aryApdo[0][0] \t");
                print (EXPANDIR "$aryApdo[0][3] $aryApdo[0][2] \t");
                print (EXPANDIR "$aryApdo[0][4] $aryApdo[0][5] \t");
                print (EXPANDIR "$aryApdo[0][1] \t \n");
                close EXPANDIR;

		$i = $i + 1;
                
        }
}
if ($Subsistema ne "")
{

		 Pg::doQuery ($conn, "SELECT direccion.bib_id, direccion.dir_id, direccion.dep_id, datosbiblio.bib_id, 
			datosbiblio.control_hx, datosbiblio.control_dgb, datosdepen.nom_depen, datosbiblio.nombre, 
                        direccion.localidad, direccion.municipio, direccion.estado
                        FROM datosbiblio, direccion, datosdepen
                        WHERE datosbiblio.bib_id = direccion.bib_id
                        AND direccion.dep_id = datosdepen.dep_id
                        AND direccion.bib_id > 0
                        AND datosbiblio.subsistema = '$Subsistema'
                        ORDER BY datosdepen.nom_depen ", \@aryBibs);

		#Pg::doQuery ($conn, "SELECT direccion.bib_id, direccion.dir_id, direccion.dep_id 
          	#	     FROM  direccion, datosbiblio 
		#	     WHERE direccion.bib_id = datosbiblio.bib_id 
		#	     AND   subsistema = '$Subsistema' ", \@aryBibs);

        $i = 0;
        $reg = $#aryBibs + 1;
                print " <br><center><b> Busqueda realizada por Subsistema  <br><br> ";
                print " Nmero de registros: $reg </b></center><br> ";
        while ($i <= $#aryBibs)

        {
                Pg::doQuery ($conn, "SELECT  datospersona.per_id, datospersona.grado, datospersona.nombre, datospersona.mail_1, datospersona.tel_1, datospersona.tel_2, datospersona.tel_3
                                     FROM persona, datospersona
                                     WHERE persona.cargo = $cargo
                                     AND persona.per_id = datospersona.per_id
                                     AND persona.bib_id = $aryBibs[$i][0]", \@aryPer1);

                Pg::doQuery ($conn, "SELECT  direccion.calle, direccion.localidad, direccion.municipio,
                                             direccion.ciudad, direccion.estado, direccion.pais, direccion.apdo_id,
                                             direccion.cod_post
                                     FROM direccion
                                     WHERE direccion.bib_id = 0
                                     AND dep_id = $aryBibs[$i][2]", \@aryDirD);  #####TENIA 0

                Pg::doQuery ($conn, "SELECT  direccion.calle, direccion.localidad, direccion.municipio,
                                             direccion.ciudad, direccion.estado, direccion.pais, direccion.apdo_id,
                                             direccion.cod_post
                                     FROM direccion, datosbiblio
                                     WHERE direccion.bib_id = $aryBibs[$i][0]", \@aryDir);     ######TENIA 1

                Pg::doQuery ($conn, "SELECT *
                                     FROM direccion
                                     WHERE apdo_id = $aryDir[0][6]", \@aryApdo);

                Pg::doQuery ($conn, "SELECT *
                                     FROM direccion
                                     WHERE apdo_id = $aryDirD[0][6]", \@aryApdoD);

                Pg::doQuery ($conn, "SELECT datosdepen.nom_depen
                                     FROM datosdepen, direccion, datosbiblio
                                     WHERE direccion.dep_id = datosdepen.dep_id
                                     AND direccion.bib_id = $aryBibs[$i][0]", \@aryNomI);

                Pg::doQuery ($conn, "SELECT nombre, control_hx, control_dgb
                                     FROM  datosbiblio
                                     WHERE bib_id = $aryBibs[$i][0]", \@aryHx);

                print " <table border=\"1\" width=\"75%\" align=\"center\" >";

        if($aryPer1[0][2] ne "")
        {
                print " <tr><td><b> Funcionario : </b><br> ";
                print "           $aryPer1[0][1]   $aryPer1[0][2] </td></tr> ";
                print "  <tr><td><b> Correo: </b><br> ";
                print "           $aryPer1[0][3] </td></tr> ";
		print "  <tr><td><b> Tel&eacute;fono: </b><br> ";
                print "           $aryPer1[0][4] <br> "; 
                print "           $aryPer1[0][5] </td></tr> "; 
	}
                print "  <tr><td><b> Dependencia: </b><br> ";
		print " <tr><td> $aryNomI[0][0] : </b><br> ";
		print " <tr><td><b> Biblioteca : </b><br> ";
                print " <tr><td> $aryHx[0][0] </td></tr> ";  
                print " <tr><td><b> Ubicacin Dependencia :  </b><br> ";
                print "          $aryDirD[0][0] ";
                print "          $aryDirD[0][1],     $aryDirD[0][2] <br>";
                print "          $aryDirD[0][3],     $aryDirD[0][4] <br>";
                print "          $aryDirD[0][5],     $aryDirD[0][7] </td></tr>";
                print " <tr><td><b> Ubicacin Biblioteca : </b><br> ";
                print "           $aryDir[0][0] ";
                print "          $aryDir[0][1],     $aryDir[0][2] <br>";
                print "          $aryDir[0][3],     $aryDir[0][4] <br>";
                print "          $aryDir[0][5],     $aryDir[0][7] </td></tr>";
                print " <tr><td><b> Clave Hexadecimal / Clave DGB : </b><br> ";
                print "          $aryHx[0][1] <br>";
                print "          $aryHx[0][2] </td></tr> ";
                print " <tr><td><b> Apartado Postal de la Dependencia</b><br> ";
                print "          $aryApdoD[0][0] ";
                print "          $aryApdoD[0][3]     $aryApdoD[0][2] <br>";
                print "          $aryApdoD[0][5]     $aryApdoD[0][4] <br>";
                print "          $aryApdoD[0][1]     </td></tr>";
                print " <tr><td><b> Apartado Postal de la Biblioteca</b><br> ";
                print "          $aryApdo[0][0] ";
                print "          $aryApdo[0][3]     $aryApdo[0][2] <br>";
                print "          $aryApdo[0][5]     $aryApdo[0][4] <br>";
                print "          $aryApdo[0][1]     </td></tr>";
                print " </table><br> ";
                
                open(EXPANDIR, ">>EtiquetaSub.txt");
if($aryPer1[0][2] ne "")
  {
                print (EXPANDIR "$aryPer1[0][1] $aryPer1[0][2] \t");
  }else{
		print (EXPANDIR "-------- \t");
  }
       
if($aryPer1[0][3] ne "" )
  {
                print (EXPANDIR "$aryPer1[0][3] \t");
  }else{
                print (EXPANDIR "-------- \t");
  }



		print (EXPANDIR "$aryPer1[0][4] \t");
                print (EXPANDIR "$aryPer1[0][5] \t");
                print (EXPANDIR "$aryNomI[0][0] \t");
                print (EXPANDIR "$aryHx[0][0] \t");
                print (EXPANDIR "$aryDirD[0][0] \t");
                print (EXPANDIR "$aryDirD[0][1]     $aryDirD[0][2] \t");
                print (EXPANDIR "$aryDirD[0][3]     $aryDirD[0][4] \t");
                print (EXPANDIR "$aryDirD[0][5]     $aryDirD[0][7] \t");
                print (EXPANDIR "$aryDir[0][0] \t");
                print (EXPANDIR "$aryDir[0][1]     $aryDir[0][2] \t");
                print (EXPANDIR "$aryDir[0][3]     $aryDir[0][4] \t");
                print (EXPANDIR "$aryDir[0][5]     $aryDir[0][7] \t");
                print (EXPANDIR "$aryHx[0][1] \t");
                print (EXPANDIR "$aryHx[0][2] \t");
                print (EXPANDIR "$aryApdoD[0][0] \t");
                print (EXPANDIR "$aryApdoD[0][3] $aryApdoD[0][2] \t");
                print (EXPANDIR "$aryApdoD[0][4] $aryApdoD[0][5] \t");
                print (EXPANDIR "$aryApdoD[0][1] \t");
                print (EXPANDIR "$aryApdo[0][0] \t");
                print (EXPANDIR "$aryApdo[0][3] $aryApdo[0][2] \t");
                print (EXPANDIR "$aryApdo[0][4] $aryApdo[0][5] \t");
                print (EXPANDIR "$aryApdo[0][1] \t \n");
                close EXPANDIR;
                
                $i = $i + 1;
        }
}
$NB=~s/"/\'/g;
$ND=~s/"/\'/g;
print " <input type=\"hidden\" value=\"$bib_id\" name=\"bib_id\"> ";
print " <input type=\"hidden\" value=\"$dir_id\" name=\"dir_id\"> ";
print " <input type=\"hidden\" value=\"$dep_id\" name=\"dep_id\"> ";
print " <input type=\"hidden\" value=\"$ND\" name=\"ND\"> ";
print " <input type=\"hidden\" value=\"$NB\" name=\"NB\"> ";
print " <input type=\"hidden\" value=\"$area\" name=\"area\"> ";
print " <input type=\"hidden\" value=\"$dgb\" name=\"dgb\"> ";
print " <input type=\"hidden\" value=\"$hx\" name=\"hx\"> ";
print " <input type=\"hidden\" value=\"$Passwd\" name=\"Passwd\"> ";
print " <input type=\"hidden\" value=\"\" name=\"\"> ";
print " <input type=\"hidden\" value=\"\" name=\"\"> ";

print " </form> ";

}

#        print "<br><br><form method=post action=download.pl>";
#        print "<tr><td><input type=\"submit\" name=\"archivo\" value=\"Bajar Archivo\"  </tr>";
        print "</form>";
print " </body></html>";
