#!/usr/local/bin/perl
use lib $ENV{DOCUMENT_ROOT}.'/cgi-local';

# Para trabajo en local PC esta linea debe ir al principio del fichero
#!perl -w


# Para www.orchestra.es estas dos lineas deben ir al principio del fichero
#!/usr/local/bin/perl
# use lib $ENV{DOCUMENT_ROOT}.'/cgi-local';


# use strict;

require "./TME_doc_cfg.pl";
require "./TME_doc_lib.pl";

use CGI;

my $query = new CGI;

$isbatch=0;
$tipo=$query->param('TIPO');
if ($tipo eq "batch") {
	$isbatch=1;
} elsif ($tipo eq "online") {
	$isbatch=0;
} else {
	# Esto no puede ser, simepre debe llegar un parametro
	die("Esto es un error de invocacion");
}

my $new_process=0;
my $new_module=0;
my $process_file="";
my $services=0;

if (! $query->param('PROCESS_NAME_MENU') && $query->param('FORMULARIO')) {
	$new_process=1;
}
# if ($query->param('PROCESS_NAME_MENU') eq 'NUEVO') {
if ($query->param('NUEVO')) {
	$query->delete_all();
	$query->param(-name=>'TIPO',
					-value=>$tipo);
	$new_process=1;
} elsif ($query->param('CANCEL')) {
	$query->delete_all();
	$query->param(-name=>'TIPO',
					-value=>$tipo);
	$new_process=0;
} elsif ($query->param('PROCESS_NAME_MENU') && $query->param('PROCESS_NAME_MENU') eq 'INICIO') {
	$query->delete_all();
	$query->param(-name=>'TIPO',
					-value=>$tipo);
	$new_process=0;
} elsif ($query->param('SAVE')) {
	&SaveProcess($query);
	$new_process=0;
# Al salvar se sigue en el mismo documento
#	$query->delete_all();
} elsif ($query->param('NEWLINE')) {
} elsif ($query->param('NUEVO_MODULO')) {
} elsif ($query->param('NEWSERVICE')) {
} elsif ($query->param('PROCESS_NAME_MENU')) {
		#OJO CON ESTO. NO SE PUEDEN REPETIR CODIGOS DE PROCESO EN DISTINTOS MODULOS
		($process_file) = (glob($DIRECTORIO_ALMACENAMIENTO . '*' . $SEPARADOR . $query->param('PROCESS_NAME_MENU')));
#		$process_file=$DIRECTORIO_ALMACENAMIENTO . '*' . $SEPARADOR . $query->param('PROCESS_NAME_MENU');
		open (IN, "$process_file") || die("'" . $process_file . "' y" . "'" . $new_process . "'");
		$query=new CGI(IN);

		$tipo=$query->param('TIPO');
		if ($tipo eq "batch") {
			$isbatch=1;
		} elsif ($tipo eq "online") {
			$isbatch=0;
		} else {
			# Esto no puede ser, simepre debe llegar un parametro
			die("Esto es un error de invocacion");
		}

		close IN;
}

print $query->header;
#print $query->start_html(-title=>"Nombre de proceso",
#							-script=>{-language=>'JAVASCRIPT',
#							-src=>'/js/check.js'}
#						);

print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- Desarrollado por Orchestra Systems, S.L., Dic 2001 -->
<HTML><HEAD><TITLE>Nombre de proceso</TITLE>
END

print "<link rel=\"stylesheet\" href=\"". $STYLES_URI . "estilos.css\">";

print <<END;

<META content="text/html; charset=windows-1252" http-equiv=Content-Type>

END

print "<SCRIPT language=JAVASCRIPT src=\"". $JAVASCRIPT_URI . "check_procesos.js\"></SCRIPT>";

print <<END;


<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY bgColor=#ffffe3>
END

$action_anchor=$query->url(-relative=>1) . "#marca";
print $query->start_form(-name=>'formulario',
							-action=>"$action_anchor"
						);

print <<END;
  <P><FONT face="Arial, Helvetica, sans-serif">
END

print "<IMG height=70 src=\"".$IMAGES_URI."Telefonica%20logo.gif\" width=220>";

print <<END;
 </FONT></P>
END

if ($isbatch) {
print <<END;
  <P><B><span class="flb">Documentación de Procesos Batch</span></B></P>
END
} else {
print <<END;
  <P><B><span class="flb">Documentación de Procesos On-Line</span></B></P>
END
}

print <<END;
  <table border=0 cellpadding="0">
    <tbody> 
    <tr> 
      <td width="150"><font class="title">Nombre 
        del Proceso: </font></td>
END



if ($new_process) {
print <<END;
      <td colspan=2 width="230">
END
	print $query->textfield(-name=>'NOMBRE_PROCESO',
							-size=>80
							);
} else {
print <<END;
      <td width="230">
END
	%PROCESS_NAME=&ListProcesses($tipo);
	@PROCESS_NAME_KEYS=keys %PROCESS_NAME;

#	$PROCESS_NAME{'NUEVO'}='<NUEVO PROCESO>';
	$PROCESS_NAME{'INICIO'}='<Elija el proceso a modificar>';
#	push @PROCESS_NAME_KEYS, ('NUEVO', 'INICIO');
	push @PROCESS_NAME_KEYS, ('INICIO');
	if ($query->param('CODIGO')) {
		$PROCESS_NAME_DEFAULT=$query->param('CODIGO');
	} else {
		$PROCESS_NAME_DEFAULT='INICIO';
	}
	
	print $query->popup_menu(-name=>'PROCESS_NAME_MENU',
								-values=> \@PROCESS_NAME_KEYS,
	                            -default=>$PROCESS_NAME_DEFAULT,
								-onChange=>"document.formulario.submit()",
								-style=>"font-size: 11px;font-family:tahoma,san-serif;",
		                        -labels=>\%PROCESS_NAME
						);

	print $query->hidden(-name=>'NOMBRE_PROCESO',
							-default=>$query->param('PROCESS_NAME_MENU')
						);
print <<END;
      </td>
      <td width="70"> 
END
	print $query->submit(-name=>'NUEVO',
						-value=>'Proceso Nuevo'
						);
print <<END;
    </tr>
END
}

print <<END;
    <tr> 
      <td width="150"><font class="title"> 
        Nombre del Módulo: </font></td>
END

if (defined($query->param('NUEVO_MODULO')) || defined($query->param('MODULE_NAME')))
{
print <<END;
      <td colspan=2 width="230">
END
	print $query->textfield(-name=>'MODULE_NAME',
				-size=>40
				);
} else {	
print <<END;
      <td width="230">
END
	%MODULE_NAME=&ListModules();
	@MODULE_NAME_KEYS=keys(%MODULE_NAME);
#	print "claves=" . $MODULE_NAME_KEYS[0];
#	$PROCESS_NAME{'NUEVO'}='<NUEVO PROCESO>';
	$MODULE_NAME{'INICIO'}='<Módulo al que pertenece el proceso>';
#	push @PROCESS_NAME_KEYS, ('NUEVO', 'INICIO');
	push @MODULE_NAME_KEYS, ('INICIO');
#	if ($query->param('CODIGO')) {
#		$PROCESS_NAME_DEFAULT=$query->param('CODIGO');
#	} else {
		$MODULE_NAME_DEFAULT='INICIO';
#	}
	
	print $query->popup_menu(-name=>'MODULE_NAME_MENU',
								-values=> \@MODULE_NAME_KEYS,
	                            -default=>$MODULE_NAME_DEFAULT,
								-style=>"font-size: 11px;font-family:tahoma,san-serif;",
		                        -labels=>\%MODULE_NAME
						); 
print <<END;
      </td>
      <td width="70">
      
END
#        <input name=NUEVO_MODULO type=submit value=" M&oacute;dulo Nuevo ">
		print $query->submit(-name=>'NUEVO_MODULO',
							-value=>'Módulo Nuevo'
							);        
}
print <<END;

        

      </td>
    </tr>
    </tbody> 
  </table>
END


print <<END;
  <table border=0 width="727" cellpadding="0">
    <tbody> 
    <tr> 
      <td width="150" class="title">Nombre del fichero: </td>
      <td width="570"> 
END

print $query->textfield(-name=>'FICHERO',
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr> 
      <td width="150" class="title">Código: </td>
      <td width="570"> 
END

print $query->textfield(-name=>'CODIGO',
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr> 
      <td width="150" class="title"> 
        <p>Autor: </p>
      </td>
      <td width="570"> 
END

print $query->textfield(-name=>'AUTOR',
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr> 
      <td width="150" class="title">Fecha: </td>
      <td width="570"> 
END

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$fecha_actual_string=$mday . "/" . ($mon+1) . "/" . ($year+1900);
print $query->textfield(-name=>'FECHA',
						-default=>$fecha_actual_string,
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr> 
      <td width="150" class="title">Versión: </td>
      <td width="570"> 
END

print $query->textfield(-name=>'VERSION',
						-default=>"1.0",
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr> 
      <td width="150" class="title">&nbsp;</td>
      <td width="570">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="2" class="title"> 
        <table border=0 width="200" bgcolor="#CCCCFF">
          <tbody> 
          <tr> 
            <td align=middle height="40"> 
              <div align="center"> 
END

print $query->submit(-name=>'SAVE',
						-onClick=>"MM_validateForm('NOMBRE_PROCESO','','R','CODIGO','','R','NOMBRE_MODULO','','R','AUTOR','','R','FECHA','','R','VERSION','','R');return document.MM_returnValue",
						-value=>'Guardar'
						);

print <<END;
			  </div>
            </td>
            <td height="40">&nbsp;</td>
            <td align=middle height="40"> 
              <div align="center"> 
END

#print $query->submit(-name=>'CANCEL',
#						-value=>'Cancelar'
#
#);
print $query->button(-name=>'CANCEL',
                          -value=>'Cancelar',
                          -onClick=>"document.location='".$HOME_URI."';"
						  );
print <<END;
              </div>
            </td>
          </tr>
          </tbody> 
        </table>
      </td>
    </tr>
    </tbody> 
  </table>
    <hr noshade size="1">
END


print <<END;
  <P class="flb"><FONT face="Arial, Helvetica, sans-serif" size="+2" class="flb"><B>Descripción 
    </B></FONT></P>
  <P><FONT face="Arial, Helvetica, sans-serif"><B>
END

print $query->textarea(-name=>'DESCRIPCION',
					-default=>'<Introduzca aquí la descripción del proceso>',
					-rows=>6,
					-columns=>140);

# Los procesos online no tienen arranque y parada
if ($isbatch) {
print <<END;
</B></FONT></P>
  <P><FONT face="Arial, Helvetica, sans-serif" size="+2" class="flb"><B>Arranque, 
    Parada y Monitorización</B></FONT></P>
<P><FONT face="Arial, Helvetica, sans-serif"><B>
END

print $query->textarea(-name=>'ARRANQUE',
					-default=>'<Introduzca aquí la forma de arranque y parada>
- Menús de arranque, parada y monitorización
-¿Es un proceso que se arranca y se para de forma automática cuando se inicializa el sistema operativo?',
					-rows=>6,
					-columns=>140);
}

print <<END;
</B></FONT></P>
  <p><font face="Arial, Helvetica, sans-serif"><b><font class="flb">Informaci&oacute;n 
    para Gesti&oacute;n de Entradas</font><br>
    </b></font><font face="Arial, Helvetica, sans-serif"><b> </b></font></p>
  <table border=0 width="727">
    <tbody> 
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Archivo:</font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'EN_ARCHIVO',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Ubicaci&oacute;n:</font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'EN_UBICACION',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Procedencia:</font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'EN_PROCEDENCIA',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Contenido: 
        </font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'EN_CONTENIDO',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    </tbody> 
  </table>
  <p><font face="Arial, Helvetica, sans-serif"><b><font class="flb">Informaci&oacute;n 
    para Gesti&oacute;n de Salidas</font><br>
    </b></font><font face="Arial, Helvetica, sans-serif"><b> </b></font></p>
  <table border=0 width="727">
    <tbody> 
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Archivo:</font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'SAL_ARCHIVO',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Ubicaci&oacute;n:</font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'SAL_UBICACION',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Contenido: 
        </font></td>
      <td width="70%"><b> 
END
        
print $query->textfield(-name=>'SAL_CONTENIDO',
						-size=>40
					);        
        
print <<END;
        </b></td>
    </tr>
    </tbody> 
  </table>
END

print <<END;
  <p><font face="Arial, Helvetica, sans-serif"><b><font size=+2><span class="flb">Descripción 
    de Mensajes (Ficheros de Log)</span></font></b><br>
    </font></p>
  <p><font face="Arial, Helvetica, sans-serif"><b> 
END

print $query->textarea(-name=>'FICHEROS',
					-default=>'<Introduzca aquí el nombre, localización y tamaño máximo previsto del fichero de log>',
					-rows=>6,
					-columns=>140);

print <<END;
	</b></font></p>
END

&GenerateAnchor("MENSAJES", $query);

print <<END;
  <table border=0 cellpadding=0 cellspacing=2>
    <tbody> 
    <tr> 
      <th bgcolor=#E1E1FF valign=top align="left"> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Código mensaje </font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top align="left"> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Descripción </font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top align="left"> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Acción a tomar </font></div>
      </th>
END

#Los procesos online no tienen tivoli ni exit-code
if ($isbatch) {
print <<END;
      <th bgcolor=#E1E1FF valign=top align="left"> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Envío a Tivoli</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top align="left"> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Exit-code </font></div>
      </th>
END
}

print <<END;
      <td valign=top></td>
    </tr>
END

foreach $counter (&ListRows("MENSAJES_CODIGO_", $query)) {

print <<END;

    <tr> 
      <td valign=top> 
END

print $query->textfield(-name=>'MENSAJES_CODIGO_'.$counter,
						-size=>20
					);
print <<END;
      </td>
      <td valign=top> 
END
if ($query->param('MENSAJES_CODIGO_'.$counter) eq "") {
	$query->param(-name=>'MENSAJES_DESC_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'MENSAJES_DESC_'.$counter,
						-size=>30
					);
print <<END;
      </td>
      <td valign=top> 
END
if ($query->param('MENSAJES_CODIGO_'.$counter) eq "") {
	$query->param(-name=>'MENSAJES_ACCION_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'MENSAJES_ACCION_'.$counter,
						-size=>30
					);

#Los procesos online no tienen tivoli ni exit-code
if ($isbatch) {
print <<END;
      </td>
      <td valign=top nowrap><font face="Arial, Helvetica, sans-serif"> 
END
if ($query->param('MENSAJES_CODIGO_'.$counter) eq "") {
	$query->param(-name=>'MENSAJES_TIVOLI_'.$counter,
					-value=>"-");
}
print $query->radio_group(-name=>'MENSAJES_TIVOLI_'.$counter,
							-values=>['Si', 'No'],
							-default=>'-',
							-labels=> );

print <<END;
  </font></td>
      <td valign=top> 
END
if ($query->param('MENSAJES_CODIGO_'.$counter) eq "") {
	$query->param(-name=>'MENSAJES_EXITCODE_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'MENSAJES_EXITCODE_'.$counter,
						-size=>10
					);
}

print <<END;
      </td>
      <td> 
END

&RemoveLine('MENSAJES_CODIGO_', $counter, "MENSAJES", $query);

print <<END;
      </td>
    </tr>
    </tbody> 
END
}
print <<END;
  </table>
END

&AddNewLine('MENSAJES', $query);

print <<END;
  <p><font face="Arial, Helvetica, sans-serif"><b><font class="flb">Recursos de 
    Base de Datos</font><br>
    </b></font></p>
  <p><font face="Arial, Helvetica, sans-serif"><b><font class="flx">Recursos Adquiridos 
    de RDBMS:</font> </b></font></p>
  <table border=0 width="100%">
    <tbody> 
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Segmentos 
        de Rollbacks específicos:</font></td>
      <td width="70%"><b>
END

print $query->textfield(-name=>'SEGMENTOS',
						-size=>40
					);

print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Nivel 
        de Commit:</font></td>
      <td width="70%"><b>
END

print $query->textfield(-name=>'COMMIT',
						-size=>40
					);

print <<END;
        </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Espacios 
        temporales específicos: </font></td>
      <td width="70%"><b>
END

print $query->textfield(-name=>'ESPACIOS',
						-size=>40
					);

print <<END;
        </b></td>
    </tr>
    </tbody>
  </table>
END

$num_servicios=0;

if (!$isbatch) {

print <<END;
    <hr noshade size="1">
END

@servicios=&ListServices($query);
$num_servicios=@servicios;

&GenerateAnchor("SERVICIOS", $query);

print <<END;
  <p><font class="flb">Servicios Ofrecidos por el Proceso</font></p>
  <table width="300" border="0" bgcolor=#CCCCFF cellspacing="0" cellpadding="0">
    <tr> 
      <td colspan="3">&nbsp;</td>
    </tr>
END

if ($num_servicios==0) {

print <<END;
    <tr> 
      <td width="20">&nbsp;</td>
      <td class="Title" colspan="2">&lt;El proceso no incluye ning&uacute;n servicio&gt; 
      </td>
    </tr>
END
} else {
	$counter=0;
	foreach $service_id (@servicios) {
		$counter++;	
print <<END;
      <td width="20">&nbsp;</td>
      <td class="Title"> 
        <div align="center" >
END
	  print '<li><a href="#servicio'.$counter. '">Servicio '.$counter. '</a></li>';

print <<END;
        </div>
      </td>
      <td>
END
			
&RemoveService('NOMBRE_SRV_', $service_id, "SERVICIOS", $query);			
			
print <<END;
      </td>
    </tr>
END
	}
}
print <<END;
    <tr> 
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr valign="middle"> 
      <td colspan="3" height="40"> 
        <div align="center"> 
END

&AddService($query);

print <<END;
      </div>
      </td>
    </tr>
  </table>
END

}

if ($num_servicios==0) {

#No pongo la "linea" en los de tipo batch
if (!$isbatch) {
print <<END;
  <hr noshade size="1">
END
}

print <<END;
  <P class="flb">Objetos de Base de Datos Referenciados por el Proceso</P>
END

&GenerateAnchor("TABLAS", $query);

print <<END;
  <P><FONT face="Arial, Helvetica, sans-serif" class="title"><B>Tablas</B></FONT></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2 width="727">
    <TBODY> 
    <TR> 
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre Tabla</FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">BBDD </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">S </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">D </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">U </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">I </FONT></div>
      </th>
      <th bgColor=#E1E1FF colSpan=4 vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Operación </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Filas Afectadas </FONT></div>
      </th>
      <TD vAlign=top></TD>
    </TR>
    <TR> 
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Order by </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Group by </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Distinct </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Union </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("TABLAS_PROC_NOMBRE_", $query)) {

print <<END;
    <TR> 
      <TD vAlign=top> 
END

print $query->textfield(-name=>'TABLAS_PROC_NOMBRE_'.$counter,
						-size=>20
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_BBDD_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_BBDD_'.$counter,
						-size=>20
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_S_'.$counter,
					-value=>"");
}
print $query->checkbox(-name=>'TABLAS_PROC_S_'.$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_D_'.$counter,
					-value=>"");
}
print $query->checkbox(-name=>'TABLAS_PROC_D_'.$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_U_'.$counter,
					-value=>"");
}
print $query->checkbox(-name=>'TABLAS_PROC_U_'.$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_I_'.$counter,
					-value=>"");
}
print $query->checkbox(-name=>'TABLAS_PROC_I_'.$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_ORDERBY_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_ORDERBY_'.$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_GROUPBY_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_GROUPBY_'.$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_DISTINCT_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_DISTINCT_'.$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_UNION_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_UNION_'.$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_PROC_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'TABLAS_PROC_FILAS_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'TABLAS_PROC_FILAS_'.$counter,
						-size=>8
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END

&RemoveLine('TABLAS_PROC_NOMBRE_', $counter, "TABLAS", $query);

print <<END;
      </TD>
    </TR>
END

} 

print <<END;
    </TBODY> 
  </TABLE>
END

&AddNewLine('TABLAS', $query);




print <<END;
  <P>
END
	  
&GenerateAnchor("CLAVES", $query);
	  
print <<END;
  <P><span class="title">Claves / Índices</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de las Claves o Índices</FONT> 
        </div>
      </th>  
      <td vAlign=top></td>
    </TR>
END

foreach $counter (&ListRows("CLAVES_PROC_", $query)) {

print <<END;
  <TR>
    <TD vAlign=top>
END

print $query->textfield(-name=>'CLAVES_PROC_'.$counter,
						-size=>40
					);

print <<END;
</TD>
    <TD>
END

&RemoveLine('CLAVES_PROC_', $counter, "CLAVES", $query);

print <<END;
    </TD></TR>
END

}

print <<END;
	</TBODY></TABLE>
  <span class="flx">
END

&AddNewLine('CLAVES', $query);

print <<END;
  </span>
  <P> 
END

&GenerateAnchor("SECUENCIAS", $query);

print <<END;
  <P><span class="title">Secuencias</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de Secuencias</FONT></div>
      </th>  
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("SECUENCIAS_PROC_", $query)) {

print <<END;
  <TR>
      <TD vAlign=top> 
END

	print $query->textfield(-name=>'SECUENCIAS_PROC_'.$counter,
						-size=>40
					);

print <<END;
 </TD>
      <TD> 
END

&RemoveLine('SECUENCIAS_PROC_', $counter, "SECUENCIAS", $query);

print <<END;
    </TD></TR>
END
}
print <<END;
		</TBODY></TABLE>
END

&AddNewLine('SECUENCIAS', $query);

print <<END;
<P> 
END

&GenerateAnchor("VISTAS", $query);

print <<END;
  <P><span class="Title">Vistas</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de Vistas</FONT></div>
      </th>  
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("VISTAS_PROC_", $query)) {

print <<END;
    <TR>
    <TD vAlign=top>
END

print $query->textfield(-name=>'VISTAS_PROC_'.$counter,
						-size=>40
					);

print <<END;
</TD>
    <TD>
END

&RemoveLine('VISTAS_PROC_', $counter, "VISTAS", $query);

print <<END;
    </TD>
    </TR>
END
}
print <<END;
</TBODY>
</TABLE>
END

&AddNewLine('VISTAS', $query);

} else {

$counter=0;
foreach $service_id (@servicios) {
$counter++;
print <<END;
  <hr noshade size="1">
 <P class="flb"><u>
END
print '<a name="servicio'.$counter.'"></a>Servicio '.$counter;
print <<END;
 </u></P>
  <table border=0 width="727" cellpadding="0">
    <tbody> 
    <tr> 
      <td width="150" class="title">Nombre del servicio: </td>
      <td width="570"> 
END

print $query->textfield(-name=>'NOMBRE_SRV_'.$service_id,
						-size=>40
					);

print <<END;
      </td>
    </tr>
    <tr>
      <td width="150" class="title"><font face="Arial, Helvetica, sans-serif" class="title">Descripción: 
        </font></td>
      <td width="570">&nbsp;</td>
    </tr>
    </tbody> 
  </table>
END

print $query->textarea(-name=>'DESC_SRV_'.$service_id,
					-default=>'<Introduzca aquí la descripción del servicio>',
					-rows=>6,
					-columns=>140);


print <<END;
  <P class="flb">Objetos de Base de Datos Referenciados por el Servicio</P>
END

&GenerateAnchor("TABLAS_".$service_id, $query);

print <<END;
  <P><FONT face="Arial, Helvetica, sans-serif" class="title"><B>Tablas</B></FONT></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2 width="727">
    <TBODY> 
    <TR> 
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre Tabla</FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">BBDD </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">S </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">D </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">U </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">I </FONT></div>
      </th>
      <th bgColor=#E1E1FF colSpan=4 vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Operación </FONT></div>
      </th>
      <th bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Filas Afectadas </FONT></div>
      </th>
      <TD vAlign=top></TD>
    </TR>
    <TR> 
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Order by </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Group by </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Distinct </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top> 
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Union </FONT></div>
      </TD>
      <TD bgColor=#E1E1FF vAlign=top>&nbsp;</TD>
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("TABLAS_SRV_NOMBRE_".$service_id."_", $query)) {

print <<END;
    <TR> 
      <TD vAlign=top> 
END

print $query->textfield(-name=>"TABLAS_SRV_NOMBRE_".$service_id."_".$counter,
						-size=>20
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_BBDD_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_BBDD_".$service_id."_".$counter,
						-size=>20
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_S_'.$service_id."_".$counter,
					-value=>"");
}
print $query->checkbox(-name=>"TABLAS_SRV_S_".$service_id."_".$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_D_'.$service_id."_".$counter,
					-value=>"");
}
print $query->checkbox(-name=>"TABLAS_SRV_D_".$service_id."_".$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_U_'.$service_id."_".$counter,
					-value=>"");
}
print $query->checkbox(-name=>"TABLAS_SRV_U_".$service_id."_".$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_I_'.$service_id."_".$counter,
					-value=>"");
}
print $query->checkbox(-name=>"TABLAS_SRV_I_".$service_id."_".$counter,
                           -value=>'X',
                           -label=>'');

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_ORDERBY_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_ORDERBY_".$service_id."_".$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_GROUPBY_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_GROUPBY_".$service_id."_".$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_DISTINCT_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_DISTINCT_".$service_id."_".$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_UNION_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_UNION_".$service_id."_".$counter,
						-size=>10
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END
if ($query->param('TABLAS_SRV_NOMBRE_'.$service_id."_".$counter) eq "") {
	$query->param(-name=>'TABLAS_SRV_FILAS_'.$service_id."_".$counter,
					-value=>"");
}
print $query->textfield(-name=>"TABLAS_SRV_FILAS_".$service_id."_".$counter,
						-size=>8
					);

print <<END;
      </TD>
      <TD vAlign=top> 
END

&RemoveLine("TABLAS_SRV_NOMBRE_".$service_id."_", $counter, "TABLAS_".$service_id, $query);

print <<END;
      </TD>
    </TR>
END

} 

print <<END;
    </TBODY> 
  </TABLE>
END

&AddNewLine('TABLAS_'.$service_id, $query);

print <<END;
  <P> 
END

&GenerateAnchor("CLAVES_".$service_id, $query);

print <<END;
  <P><span class="title">Claves / Índices</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de las Claves o Índices</FONT> 
        </div>
      </th>  
      <td vAlign=top></td>
    </TR>
END

foreach $counter (&ListRows("CLAVES_SRV_".$service_id.'_', $query)) {

print <<END;
  <TR>
    <TD vAlign=top>
END

print $query->textfield(-name=>'CLAVES_SRV_'.$service_id.'_'.$counter,
						-size=>40
					);

print <<END;
</TD>
    <TD>
END

&RemoveLine('CLAVES_SRV_'.$service_id.'_', $counter, "CLAVES_".$service_id, $query);

print <<END;
    </TD></TR>
END

}

print <<END;
	</TBODY></TABLE>
  <span class="flx">
END

&AddNewLine('CLAVES_'.$service_id, $query);

print <<END;
  </span>
  <P> 
END

&GenerateAnchor("SECUENCIAS_".$service_id, $query);

print <<END;
  <P><span class="title">Secuencias</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de Secuencias</FONT></div>
      </th>  
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("SECUENCIAS_SRV_".$service_id.'_', $query)) {

print <<END;
  <TR>
      <TD vAlign=top> 
END

	print $query->textfield(-name=>'SECUENCIAS_SRV_'.$service_id.'_'.$counter,
						-size=>40
					);

print <<END;
 </TD>
      <TD> 
END

&RemoveLine('SECUENCIAS_SRV_'.$service_id.'_', $counter, "SECUENCIAS_".$service_id, $query);

print <<END;
    </TD></TR>
END
}
print <<END;
		</TBODY></TABLE>
END

&AddNewLine('SECUENCIAS_'.$service_id, $query);

print <<END;
<P> 
END

&GenerateAnchor("VISTAS_".$service_id, $query);

print <<END;
  <P><span class="Title">Vistas</span></P>
  <TABLE border=0 cellPadding=0 cellSpacing=2>
    <TBODY> 
    <TR>
      <th bgColor=#E1E1FF vAlign=top align="left">
        <div align="center"><FONT 
      face="Arial, Helvetica, sans-serif">Nombre de Vistas</FONT></div>
      </th>  
      <TD vAlign=top></TD>
    </TR>
END

foreach $counter (&ListRows("VISTAS_SRV_".$service_id.'_', $query)) {

print <<END;
    <TR>
    <TD vAlign=top>
END

print $query->textfield(-name=>'VISTAS_SRV_'.$service_id.'_'.$counter,
						-size=>40
					);

print <<END;
</TD>
    <TD>
END

&RemoveLine('VISTAS_SRV_'.$service_id.'_', $counter, "VISTAS_".$service_id, $query);

print <<END; 
    </TD>
    </TR>
END
}
print <<END;
</TBODY>
</TABLE>
END

&AddNewLine('VISTAS_'.$service_id, $query);

}

}
print <<END;
  <P>&nbsp; </P>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td> 
        <hr noshade size="1" align="left">
      </td>
    </tr>
    <tr> 
      <td>
        <table align=left bgcolor=#CCCCFF border=0 width="202" height="40">
          <tbody> 
          <tr> 
            <td align=middle height="40"> 
END

print $query->submit(-name=>'SAVE',
						-onClick=>"MM_validateForm('NOMBRE_PROCESO','','R','CODIGO','','R','NOMBRE_MODULO','','R','AUTOR','','R','FECHA','','R','VERSION','','R');return document.MM_returnValue",
						-value=>'Guardar'
						);

print <<END;
            </td>
            <td height="40">&nbsp;</td>
            <td align=middle height="40"> 
END

#print $query->submit(-name=>'CANCEL',
#						-value=>'Cancelar'
#						);

print $query->button(-name=>'CANCEL',
                          -value=>'Cancelar',
                          -onClick=>"document.location='".$HOME_URI."';"
						  );
print <<END;
            </td>
          </tr>
          </tbody> 
        </table>
		</td>
    </tr>
   </table>
END
$query->param(-name=>'ANCHOR', -value=>'');
print $query->hidden(-name=>'ANCHOR');

print $query->hidden(-name=>'FORMULARIO',
						-value=>'YES');
print $query->hidden(-name=>'TIPO',
						-value=>$tipo);
# print $query->Dump;

print $query->endform;
print $query->end_html;