#!/usr/local/bin/perl
# use lib 'C:/orchestrasystems/sgdp_v1.0/producto/docroot/cgi-local/TME';
use lib $ENV{DOCUMENT_ROOT}.'/cgi-local/TME';

# 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;


print $query->header;
print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- Desarrollado por Orchestra Systems, S.L., Dic 2001 -->
<HTML><HEAD><TITLE>Herramienta de administración de módulos y procesos</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_admin.js\"></SCRIPT>";


if ($query->param('BORRAR_MOD')) {
	$texto_retorno=&DeleteModule($query->param('MODULE_NAME_MENU'));
	$query->delete('MODULE_NAME_MENU');
} elsif ($query->param('TRANSFER_MOD') && $query->param('MODULE_NAME_ORIG_MENU') ne "INICIO" && $query->param('MODULE_NAME_DEST_MENU') ne "INICIO")	 {
	if ($query->param('MODULE_NAME_ORIG_MENU') eq $query->param('MODULE_NAME_DEST_MENU')) {
		$texto_retorno="Elija dos módulos distintos, por favor";
	} else {
		@modulos=($query->param('MODULE_NAME_ORIG_MENU'), $query->param('MODULE_NAME_DEST_MENU'));
		$texto_retorno=&TransferProcesses(@modulos);
	}
} elsif ($query->param('BORRAR_PROC_MOD')) {
	@procesos=$query->param('PROCESS_NAME_MODULE');
	$texto_retorno=&DeleteProcesses(@procesos);
} elsif ($query->param('MOVER_MOD') && $query->param('MODULE_NAME_MENU_DEV') ne "INICIO") {
	$texto_retorno=&MoveModule($query->param('MODULE_NAME_MENU_DEV'));
	$query->delete('MODULE_NAME_MENU_DEV');
}	
print <<END;
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffe3>
  <P><FONT face="Arial, Helvetica, sans-serif">
END

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

print <<END;
</FONT></P>
  <P><B><span class="flb">Herramienta de administraci&oacute;n de m&oacute;dulos y procesos</span></B></P>
END

print $query->start_form(-name=>'formulario');

%MODULE_NAME=&ListModules();
@MODULE_NAME_KEYS=keys %MODULE_NAME;
$MODULE_NAME{'INICIO'}='<Seleccione el nombre del módulo>';
push @MODULE_NAME_KEYS, ('INICIO');
$MODULE_NAME_DEFAULT='INICIO';
print $query->popup_menu(-name=>'MODULE_NAME_MENU',
				-values=> \@MODULE_NAME_KEYS,
	                        -default=>$MODULE_NAME_DEFAULT,
				-onChange=>"document.formulario.submit()",	                        
				-style=>"font-size: 11px;font-family:tahoma,san-serif;",
	                        -labels=>\%MODULE_NAME
			);

print $query->submit(-name=>'BORRAR_MOD',
			-value=>'Borrar módulo y procesos asociados a él'
			);

print <<END;
<P>
END

# Saco la lista de procesos (del modulo o todos)
if ($query->param('MODULE_NAME_MENU') && $query->param('MODULE_NAME_MENU') ne "INICIO") {
	%PROCESS_NAME_MODULE=&ListProcessesModuleComplex($query->param('MODULE_NAME_MENU'));
} else {
	%PROCESS_NAME_MODULE=&ListProcessesModuleComplex();
}
		
	@PROCESS_NAME_MODULE_KEYS=keys %PROCESS_NAME_MODULE;
	print $query->scrolling_list(-name=>'PROCESS_NAME_MODULE',
					-values=> \@PROCESS_NAME_MODULE_KEYS,
					-size=>10,
					-multiple=>'true',
					-style=>"font-size: 11px;font-family:tahoma,san-serif;"
					);	
					
	print $query->submit(-name=>'BORRAR_PROC_MOD',
				-value=>'Borrar procesos seleccionados'
				);					
			
print <<END;
<P><hr><P>
END

# Saco  la lista de modulos
#%MODULE_NAME=&ListModules();
#@MODULE_NAME_KEYS=keys %MODULE_NAME;
$MODULE_NAME{'INICIO'}='<Seleccione el nombre del módulo origen>';
#<push @MODULE_NAME_KEYS, ('INICIO');
$MODULE_NAME_DEFAULT='INICIO';
print $query->popup_menu(-name=>'MODULE_NAME_ORIG_MENU',
				-values=> \@MODULE_NAME_KEYS,
	                        -default=>$MODULE_NAME_DEFAULT,
				-onChange=>"document.formulario.submit()",	                        
				-style=>"font-size: 11px;font-family:tahoma,san-serif;",
	                        -labels=>\%MODULE_NAME
			);

print $query->popup_menu(-name=>'MODULE_NAME_DEST_MENU',
				-values=> \@MODULE_NAME_KEYS,
	                        -default=>$MODULE_NAME_DEFAULT,                       
				-style=>"font-size: 11px;font-family:tahoma,san-serif;",
	       	                 -labels=>\%MODULE_NAME
			);
print $query->submit(-name=>'TRANSFER_MOD',
			-value=>'Transferir procesos entre módulos'
			);



print <<END;
<P>
END

# Saco la lista de procesos (del modulo o todos)
if ($query->param('MODULE_NAME_ORIG_MENU') && $query->param('MODULE_NAME_ORIG_MENU') ne "INICIO") {
	%PROCESS_NAME_MODULE=&ListProcessesModuleComplex($query->param('MODULE_NAME_ORIG_MENU'));		
	@PROCESS_NAME_MODULE_KEYS=keys %PROCESS_NAME_MODULE;
	print $query->scrolling_list(-name=>'PROCESS_NAME_ORIG_MODULE',
					-values=> \@PROCESS_NAME_MODULE_KEYS,
					-size=>10,
					-multiple=>'true',
					-style=>"font-size: 11px;font-family:tahoma,san-serif;"
					);	
}
					
print <<END;
<P><hr><P>
END
			
%MODULE_NAME=&ListModulesDev();
@MODULE_NAME_KEYS=keys %MODULE_NAME;
$MODULE_NAME{'INICIO'}='<Seleccione el nombre del módulo DEV>';
push @MODULE_NAME_KEYS, ('INICIO');
$MODULE_NAME_DEFAULT='INICIO';
print $query->popup_menu(-name=>'MODULE_NAME_MENU_DEV',
				-values=> \@MODULE_NAME_KEYS,
	                        -default=>$MODULE_NAME_DEFAULT,
				-style=>"font-size: 11px;font-family:tahoma,san-serif;",
	                        -labels=>\%MODULE_NAME
			);

print $query->submit(-name=>'MOVER_MOD',
			-value=>'Publicar módulo DEV'
			);

print <<END;
<P>
END


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