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

if ($query->param('CANCEL')) {
	$query->delete_all();
} elsif ($query->param('SAVE')) {
	&SaveModule($query);
} elsif ($query->param('NEWLINE')) {
} elsif ($query->param('MODULE_NAME_MENU') && $query->param('MODULE_NAME_MENU') ne "INICIO") {
		$module_id=&GetModuleDir($query->param('MODULE_NAME_MENU'));
		$module_file=$DIRECTORIO_ALMACENAMIENTO . $module_id . ".txt";
		if (open (IN, "$module_file")) {
			$query=new CGI(IN);
			close IN;
		} 
}

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>Generador de Documentaci&oacute;n de M&oacute;dulos</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_modulos.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>
  <P><B><span class="flb">Generador de Documentación de M&oacute;dulos</span></B></P>
  <table border=0 width="727" cellpadding="0">
    <tr> 
      <td width="150" class="title"><font class="title">Nombre del Módulo: </font></td>
      <td width="570"> 
END

	%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 <<END;
      </td>
    </tr>
    <tbody> 
    <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 colspan="2" class="title">Lista de procesos:</td>
    </tr>
    <tr> 
      <td colspan="2" class="title">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="2" class="title" height="15">
END

	@PROCESS_NAME_KEYS=&ListProcessesModule($query->param('MODULE_NAME_MENU'));
	print $query->scrolling_list(-name=>'PROCESS_NAME_MENU',
								-values=> \@PROCESS_NAME_KEYS,
								-size=>10,
								-multiple=>'true',
								-style=>"font-size: 11px;font-family:tahoma,san-serif;"
						);
		
print <<END;
      </td>
    </tr>
    <tr> 
      <td colspan="2" class="title">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="2" class="title"> 
        <table border=0 width="300" bgcolor="#CCCCFF">
          <tbody> 
          <tr> 
            <td align=middle height="40"> 
              <div align="center">
END

print $query->submit(-name=>'SAVE',
						-onClick=>"MM_validateForm('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 <<END;
              </div>
            </td>
            <td align=middle height="40">&nbsp;</td>
            <td align=middle height="40">
END

print $query->submit(-name=>'GENERAR',
						-value=>'Generar Documento'
						);

print <<END;
            </td>
          </tr>
          </tbody> 
        </table>
      </td>
    </tr>
    </tbody> 
  </table>
    <hr noshade size="1">
  <P class="flb"><FONT face="Arial, Helvetica, sans-serif" size="+2" class="flb"><B>Descripci&oacute;n 
    General </B></FONT></P>
  <P class="flb"><font face="Arial, Helvetica, sans-serif"><b><font class="flx">Interlocutores</font></b></font></P>
END

&GenerateAnchor("INTERLOCUTORES", $query);

print <<END;
  <P class="flb"><font face="Arial, Helvetica, sans-serif" class="title"><b>Lista 
    de Interlocutores</b></font></P>
  <table border=0 cellpadding=0 cellspacing=2>
    <tbody> 
    <tr> 
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Nombre</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Departamento </font></div>
      </th>
<th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Tel&eacute;fono 1</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Tel&eacute;fono 2</font></div>
      </th>
      <td valign=top></td>
    </tr>
END

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

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

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

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

&RemoveLine('INTERLOCUTORES_NOMBRE_', $counter, "INTERLOCUTORES", $query);

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

&AddNewLine('INTERLOCUTORES', $query);

print <<END;
  <p> <font face="Arial, Helvetica, sans-serif"><b><font class="flx">Usuarios</font></b></font><FONT face="Arial, Helvetica, sans-serif" size="+2" class="flb"><B> 
    </B></FONT>
  <p>
  <table border=0 width="727">
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Protocolo:</font></td>
      <td width="70%"><b> 
END
print $query->textfield(-name=>'PROTOCOLO',
						-size=>40
					);

print <<END;
     </b></td>
    </tr>
    <tbody> 
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">N&uacute;mero 
        de usuarios concurrentes:&nbsp;&nbsp;</font></td>
      <td width="70%"><b> 
END
print $query->textfield(-name=>'NUM_USU',
						-size=>40
					);

print <<END;
      </b></td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap>&nbsp;</td>
      <td width="70%">&nbsp;</td>
    </tr>
    <tr> 
      <td width="20%" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Previsiones 
        de crecimiento:</font></td>
      <td width="70%"><b> </b></td>
    </tr>
    <tr> 
      <td colspan="2" class="title" nowrap><font face="Arial, Helvetica, sans-serif"><b> 
END

print $query->textarea(-name=>'FICHEROS',
					-default=>'<Introduzca aquí la previsión de crecimiento anual del número de usuarios>',
					-rows=>6,
					-columns=>140);

print <<END;
		</b></font></td>
    </tr>
    </tbody> 
  </table>
END
&GenerateAnchor("USUARIOS", $query);
print <<END;
  <P class="flb"><font face="Arial, Helvetica, sans-serif" class="title"><b>Lista 
    de usuarios del sistema</b></font></P>
  <table border=0 cellpadding=0 cellspacing=2>
    <tbody> 
    <tr> 
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Nombre</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Departamento </font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Ubicaci&oacute;n</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Modo de Acceso</font></div>
      </th>
      <td valign=top></td>
    </tr>
END

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

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

print $query->textfield(-name=>'USUARIOS_NOMBRE_'.$counter,
						-size=>30
					);
print <<END;
       </td>
      <td valign=top> 
END

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

&RemoveLine('USUARIOS_NOMBRE_', $counter, "USUARIOS", $query);

print <<END;
     </td>
    </tr>
    </tbody>
END
}
print <<END;
  </table>
      
  <span class="title">
END

&AddNewLine('USUARIOS', $query);

print <<END;
  </span>
  <p> <font face="Arial, Helvetica, sans-serif"><b> </b></font> </p>
  <table border=0 width="727">
    <tbody> 
    <tr> 
      <td colspan="2" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Tipo 
        de procesos cliente:</font><b> </b></td>
    </tr>
    <tr> 
      <td colspan="2" class="title" nowrap><font face="Arial, Helvetica, sans-serif"><b> 
END

print $query->textarea(-name=>'PROCESOS',
					-default=>'<Indique aquí los tipos de clientes y la forma de identificación de cada usuario>',
					-rows=>6,
					-columns=>140);

print <<END;
		</b></font></td>
    </tr>
    </tbody> 
  </table>
  <P><font face="Arial, Helvetica, sans-serif"><b><font class="flx">Administradores 
    de la aplicaci&oacute;n</font></b></font><font face="Arial, Helvetica, sans-serif" size="+2" class="flb"><b> 
    </b></font> </P>
  <p> 
  <table border=0 width="727">
    <tbody> 
    <tr> 
      <td colspan="2" class="title" nowrap><font face="Arial, Helvetica, sans-serif">Perfil:</font><b> 
        </b></td>
    </tr>
    <tr> 
      <td colspan="2" class="title" nowrap><font face="Arial, Helvetica, sans-serif"><b> 
END

print $query->textarea(-name=>'ADMIN_PERFIL',
					-default=>'<Introduzca aquí la lista de acciones que puede realizar el administrador>',
					-rows=>6,
					-columns=>140);

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

&GenerateAnchor("ADMINISTRADORES", $query);

print <<END;
  <p class="flb"><font face="Arial, Helvetica, sans-serif" class="title"><b>Lista 
    de administradores del sistema</b></font></p>
  <table border=0 cellpadding=0 cellspacing=2>
    <tbody> 
    <tr> 
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Nombre</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Departamento </font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Tel&eacute;fono 1</font></div>
      </th>
      <th bgcolor=#E1E1FF valign=top> 
        <div align="center"><font 
      face="Arial, Helvetica, sans-serif">Tel&eacute;fono 2</font></div>
      </th>
      <td valign=top></td>
    </tr>
END

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

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

print $query->textfield(-name=>'ADMINISTRADORES_NOMBRE_'.$counter,
						-size=>30
					);
print <<END;
       </td>
      <td valign=top> 
END
if ($query->param('ADMINISTRADORES_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'ADMINISTRADORES_DEP_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'ADMINISTRADORES_DEP_'.$counter,
						-size=>30
					);
print <<END;
      </td>
      <td valign=top> 
END
if ($query->param('ADMINISTRADORES_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'ADMINISTRADORES_TELEF1_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'ADMINISTRADORES_TELEF1_'.$counter,
						-size=>20
					);
print <<END;
      </td>
      <td valign=top> 
END
if ($query->param('ADMINISTRADORES_NOMBRE_'.$counter) eq "") {
	$query->param(-name=>'ADMINISTRADORES_TELEF2_'.$counter,
					-value=>"");
}
print $query->textfield(-name=>'ADMINISTRADORES_TELEF2_'.$counter,
						-size=>20
					);
print <<END;
       </td>
      <td valign=top>
END
		   
&RemoveLine('ADMINISTRADORES_NOMBRE_', $counter, "ADMINISTRADORES", $query);

print <<END;
      </td>
    </tr>
    </tbody>
END
}
print <<END;
  </table>
  <span class="title"> 
END

&AddNewLine('ADMINISTRADORES', $query);

print <<END;
  </span> 
  <p> <font face="Arial, Helvetica, sans-serif"><b> </b></font> </p>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td> 
        <hr noshade size="1" align="left">
      </td>
    </tr>
    <tr> 
      <td> 
        <table border=0 width="300" bgcolor="#CCCCFF">
          <tbody> 
          <tr> 
            <td align=middle height="40"> 
              <div align="center"> 
END

print $query->submit(-name=>'SAVE',
						-onClick=>"MM_validateForm('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 <<END;
             </div>
            </td>
            <td align=middle height="40">&nbsp;</td>
            <td align=middle height="40"> 
END

print $query->submit(-name=>'GENERAR',
						-value=>'Generar Documento'
						);

print <<END;
           </td>
          </tr>
          </tbody> 
        </table>
      </td>
    </tr>
   </table>
  <p>
    <INPUT name=ANCHOR type=hidden>
  </p>
END
print $query->endform;
print $query->end_html;