#!/usr/bin/perl

require 'ftestformulario.cgi';
require "ftestidiomas.cgi";

%acumulacion=();
$datosacumuados="";

&idioma();
&busca();
print "Content-type: text/html\n\n";
&cabeceradepagina();
print <<EOF;
<table border=0 cellpadding=5 cellspacing=3 width=100% align=center valign=top><tr><td colspan=2 bgcolor="#140059"><b><FONT FACE="Tahoma, arial,helvetica" size=3 color="#FFFFFF">LISTADO DE INVESTIGADORES AUTORIZADOS DE FETALTEST</b></td></tr></table></center>
<br><p>
<center>
<table class='bordernegro' width=50%><tr><td  width=100%>INVESTIGADORES CONSOLIDADOS</TD></TR></TABLE>
<table class='bordernegro' width=50%><tr><td  width=100%>
EOF
&compara();
print <<EOF;
</td></tr></table>
<br><p>
</center>
EOF
print <<EOF;
<br><p>
<center>
<table class='bordernegro' width=50%><tr><td  width=100%>INVESTIGADORES EN PROCESO DE CONSOLIDACION</TD></TR></TABLE>
<table class='bordernegro' width=50%><tr><td  width=100%>
EOF
&compara1();
print <<EOF;
</td></tr></table>
<br><p>
</center>
EOF
print <<EOF;
<br><p>
<center>
<table class='bordernegro' width=50%><tr><td  width=100%>INVESTIGADORES AUTORIZADOS</TD></TR></TABLE>
<table class='bordernegro' width=50%><tr><td  width=100%>
EOF
&compara2();
print <<EOF;
</td></tr></table>
<br><p>
</center>
EOF

&piedepagina();
exit;
##################################################################
sub busca{
$archivo = "ftest.db";
open(FILE,"$archivo");
flock(FILE, 1);
while(<FILE>) {
$linea= $_;	
@valores = split(/\|/, $linea);
&acumuladatos();
}
close(FILE);
$archivo = "ftestcerrados.db";
open(FILE,"$archivo");
flock(FILE, 1);
while(<FILE>) {
$linea= $_;	
@valores = split(/\|/, $linea);
&acumuladatos();
}
close(FILE);
}




sub compara{
$a="";
open (PASSWD, "<ftest.pass") || &cgierr("unable to open password file. Reason: $!\n");
			@passwds = <PASSWD>;			# Let's get the user id and passwords..
		close PASSWD;
		my ($view, $add, $mod, $del, $admin);


@valores=();
@valores = split(/\|/, $datosacumuados);

#getc;
for ($i=0;$i<=$numacumulados;$i++){

$sujeto=$valores[$i];

		PASS: foreach $pass (@passwds) {	# Go through each pass and see if we match..
			next PASS if ($pass =~ /^$/);	# Skip blank lines.
			next PASS if ($pass =~ /^#/);	# Skip Comment lines.
			chomp ($pass);
			($userid, $pw, $view, $add, $del, $mod, $admin, $nomusuario) = split (/:/, $pass);
		
if (!$admin){
if ($userid ne "mgallov"){
if ($acumulacion{$sujeto}>99){
if ($sujeto eq $userid) {
	    $nomusu=$nomusuario;
          $nomusu=~ s/8/ /g;
if ($nomusu2 ne $nomusu){
unless(!$nomusu){
$a+=1;
$nomusu2=$nomusu;
print <<EOF;
<b><li> $a .- Dr/a $nomusu </b>
EOF
}}}
}}}
}
}
}
sub compara1{
$a="";
open (PASSWD, "<ftest.pass") || &cgierr("unable to open password file. Reason: $!\n");
			@passwds = <PASSWD>;			# Let's get the user id and passwords..
		close PASSWD;
		my ($view, $add, $mod, $del, $admin);


@valores=();
@valores = split(/\|/, $datosacumuados);

#getc;
for ($i=0;$i<=$numacumulados;$i++){

$sujeto=$valores[$i];

		PASS: foreach $pass (@passwds) {	# Go through each pass and see if we match..
			next PASS if ($pass =~ /^$/);	# Skip blank lines.
			next PASS if ($pass =~ /^#/);	# Skip Comment lines.
			chomp ($pass);
			($userid, $pw, $view, $add, $del, $mod, $admin, $nomusuario) = split (/:/, $pass);
		
if (!$admin){
if ($userid ne "mgallov"){
if ($acumulacion{$sujeto}<100){
if ($sujeto eq $userid) {


	    $nomusu=$nomusuario;
          $nomusu=~ s/8/ /g;
if ($nomusu2 ne $nomusu){
unless(!$nomusu){
$a+=1;
$nomusu2=$nomusu;
print <<EOF;
<b><li> $a .- Dr/a $nomusu </b>
EOF
}}
}}}
}
}
}
}

sub compara2{
$a="";
open (PASSWD, "<ftest.pass") || &cgierr("unable to open password file. Reason: $!\n");
			@passwds = <PASSWD>;			# Let's get the user id and passwords..
		close PASSWD;
		my ($view, $add, $mod, $del, $admin);


		PASS: foreach $pass (@passwds) {	# Go through each pass and see if we match..
			next PASS if ($pass =~ /^$/);	# Skip blank lines.
			next PASS if ($pass =~ /^#/);	# Skip Comment lines.
			chomp ($pass);
			($userid, $pw, $view, $add, $del, $mod, $admin, $nomusuario) = split (/:/, $pass);
		


if (!$admin){
if ($userid ne "mgallov"){
if ($acumulacion{$userid}==0){

	    $nomusu=$nomusuario;
          $nomusu=~ s/8/ /g;
if ($nomusu2 ne $nomusu){
unless(!$nomusu){
$a+=1;
$nomusu2=$nomusu;
print <<EOF;
<b><li> $a .- Dr/a $nomusu </b>
EOF
}}}
}}

}
}




sub acumuladatos {

@valores2=@valores;
$anadido="";
$iden="";
$a="~";
$b=$valores2[1];
if ($b =~ /$a/){
@valores2 = split(/\~/, $b);
$valores2[1]=$valores2[0];
}
$a=$valores2[1];
if ($datosacumuados =~ /$a/){ 
$iden = $acumulacion{$a}; 
unless(!$iden){
$acumulacion{$a} = ($iden+1);
$anadido=1;
}}
if (!$anadido){
$datosacumuados = $datosacumuados.$a."|";
$acumulacion{$a} = 1;
$numacumulados +=1;
}
}





