sub GetModuleDir {
	my ($module)=@_;
	my ($directory) = "";

#	print "mymodule=".$module . "\n";
	open(MOD_FILE_ID,"$FICHERO_MODULOS");
	foreach $linea_modulo (<MOD_FILE_ID>)
	{
		($directorio_item, $nombre_modulo_item) = split(/\|/, $linea_modulo);
		chop $nombre_modulo_item;
		if ($nombre_modulo_item eq $module)
		{
			$directory=$directorio_item;
		}
	}
	close MOD_FILE_ID;
	return $directory;
}

sub ListModules {
	open(MOD_FILE_ID,"$FICHERO_MODULOS");
	%lista_modulos=();
	foreach $linea_modulo (<MOD_FILE_ID>)
	{
#		print "linea=$linea_modulo";
		($directorio, $nombre_modulo) = split(/\|/, $linea_modulo);
		chop $nombre_modulo;
#		print "entrada=$linea_modulo $directorio, $nombre_modulo";
		$lista_modulos{"$nombre_modulo"}="$nombre_modulo";
	}
	close MOD_FILE_ID;
	return %lista_modulos;
}

sub ListModulesComplex {
	open(MOD_FILE_ID,"$FICHERO_MODULOS") || die();
	%lista_modulos_comp=();
	my ($directorio, $nombre_modulo);
	foreach $linea_modulo (<MOD_FILE_ID>)
	{
		($directorio, $nombre_modulo) = split(/\|/, $linea_modulo);
		chop $nombre_modulo;
		$lista_modulos_comp{"$nombre_modulo"}="$directorio";
	}
	close MOD_FILE_ID;
	return %lista_modulos_comp;
}

sub AddNewLine {
	my ($anchor_text, $query)=@_;
	$javascript_command="document.formulario.ANCHOR.value='" . $anchor_text ."'";
	print $query->submit(-name=>'NEWLINE',
						-onClick=>"$javascript_command",
						-value=>'Aņadir otra fila'
					);
}

sub RemoveLine {
	my ($element, $index, $anchor_text, $query)=@_;
	$javascript_command="document.formulario.$element" . $index . ".value='';document.formulario.ANCHOR.value='" . $anchor_text ."'";
	print $query->submit(-name=>'NEWLINE',
						-onClick=>"$javascript_command",
						-value=>'Borrar fila'
					);
}

sub GenerateAnchor {
	my ($anchor_text, $query)=@_;
	if ($query->param('ANCHOR') && $query->param('ANCHOR') eq $anchor_text) {
print <<END;
<A NAME="marca">&nbsp;</A>
END
	}
}

sub ListRows {
	my ($PATRON, $query)=@_;
	my $max=0;
	@elementos=();
	foreach $element ($query->param) {
		$_=$element;
		if (/$PATRON/ && $query->param($_) ne "") {
			s/$PATRON//;
			push @elementos, $_;
			if ($_ > $max) {
				$max=$_;
			}
		}
	}
	push @elementos, $max+1;
	return @elementos;
}

sub ListProcessesModule {
	my($module_name)=@_;
	@processes=();
	if (! defined($module_name)) {
		return @processes;
	}
	$directory=&GetModuleDir($module_name);
	foreach $process_file (glob($DIRECTORIO_ALMACENAMIENTO . $SEPARADOR . $directory . $SEPARADOR . '*')) {
		open (IN, "$process_file");
		my $process_reg=new CGI(IN);
		close IN;
		push @processes, $process_reg->param('NOMBRE_PROCESO');
	}
	return @processes;
}

sub SaveModule {
	my($query)=@_;
	my $module_name="";
	if ($query->param('MODULE_NAME_MENU') && $query->param('MODULE_NAME_MENU') ne "INICIO") {
		$dir_modulo=&GetModuleDir($query->param('MODULE_NAME_MENU'));
		$MODULE_FILENAME=$DIRECTORIO_ALMACENAMIENTO . $dir_modulo . ".txt";
		open(MODULE_FILEID,">$MODULE_FILENAME") || die ("$MODULE_FILENAME");
		$query->save(MODULE_FILEID);
		close(MODULE_FILEID);
	}
}

1;