#!/usr/bin/perl
require "../../../librerias/rutinas.pl";
require "../../../librerias/base_datos.pl";
require "../../../librerias/seguridad.pl";
require "../../../librerias/utilerias.pl";
require "../../libIntranet/objetos.pl";
require "../../libIntranet/intranetTools.pl";
require "armazon.pl";

print "content-type:text/html \n\n";

#VALIDACION DE POST PARA SEGURIDAD Y PARSER DE INFORMACION DE LA FORMA ANTERIOR
&validaPost();
&ParseForma();

#RECUPERACION DE INFORMACION EN VARIABLES ESCALARES DEL ARREGLO VALORES RESULTADO DEL PARSER
$usuario=$valores{'usuario'};
$passwordEncriptado=$valores{'passwordEncriptado'};
$idInstitucion=$valores{'parametro'};
$alumnoFechaNac = $valores{'fecha_ini'};

#CONSTANTE DEFINIDA PARA CADA INTRANET, SE DEFINE INTERNAMENTE, NO NECESITA ENVIARSE COMO PARAMETRO, SE DECLARA EN CADA ARCHIVO CGI
$intranet="weblearning";

#--------------------------------------------------------------
#LECTURA DE PARAMETROS DE ARCHIVO DE CONFIGURACION
($numIntranet,$nombreIntranet,$rutacom,$rutacomcgi,$ruta,$rutacgi)=&fileRead($intranet);
#---------------------------------------------------
$BaseDeDatos="intranet";
&crear_conexion();
#---------------------------------------------------
#VERIFICANDO USUARIO
($nombreReal,$nombreInstitucion,$privilegio,$baseDeDatos)=&validaUESius($usuario,$passwordEncriptado,$numIntranet,$idInstitucion);
#---------------------------------------------------	
$sth->finish;
&cerrar_conexion();
#---------------------------------------------------

($rutaFotografica,$resto)=split('intranet/',$ruta);
$rutaFotografica=$rutaFotografica . $baseDeDatos . "/intranet/comunicacion/imagenes/archivoFotografico/";

#DETERMINAR VALORES INTERNOS DE CONSULTA


&encabezado($nombreReal,$nombreInstitucion,$nombreIntranet,"Web Learning: Alumno - Forma de alta");
#PARAMETROS MENU
&menu(1,0);
&defineButtonJs();
&tituloContenido("Instrucciones: Inserte la información que desea ingresar a la base de datos");
print <<pagina
<SCRIPT LANGUAGE=JavaScript>
function envia(tarea)
  {
   if (tarea == 1)
     {document.informacion.action="$rutacgi/alumnoAltaFrm.pl";
      //alert (document.informacion.action);
      document.informacion.submit()
     }
   if (tarea == 2 )
     {
    // alert("esta opcion no esta disponible para usted");
      document.informacion.action="$rutacgi/alumnoEliminaFrm.pl";
     document.informacion.submit()
     }
   if (tarea == 3)
     {document.informacion.action="$rutacgi/alumnoModificaFrm.pl";
     document.informacion.submit()
     }
   if (tarea == 4)
     {
    // alert("esta opcion no esta disponible para usted");
      document.informacion.action="$rutacgi/alumnoEliminaFrm.pl";
     document.informacion.submit()
     }

   //document.informacion.submit();
  }
</SCRIPT>
pagina
;
#CONTENIDO DE LA PAGINA
print <<pagina
<script LANGUAGE="JavaScript">

imagen=new Image();

function selecciona_foto(imgName)
{ if (imgName == '0.gif'){
  imagen.src=("$ruta/imagenes/" + imgName);}
  else
    {
     imagen.src=("$rutaFotografica" + imgName);
    }
  document.objetivo.src=imagen.src;

}

function envia_datos(forma)
{if (forma.nombreAlumno.value=='')
  { alert("Es necesario escribir el nombre del alumno");
   forma.nombre.focus();
  }
 else
 if (forma.apellidoPaterno.value=='')
  { alert("Es necesario escribir el apellido paterno del alumno") ;
    forma.apellidoPaterno.focus();
  }
 else
  if (forma.apellidoMaterno.value=='')
   { alert("Es necesario escribir el apellido materno del alumno");
     forma.contenido.focus();
   }
 else
  if (forma.sexoAlumno.value=='')
   { alert("Es necesario seleccionar el sexo del alumno");
     forma.sexoAlumno.focus();
   }

 else
  { forma.submit();
  }
}

</script>


<form name=formita ACTION="$rutacgi/alumnoAltaBd.pl" METHOD="POST">

<table BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=2 WIDTH="668" >
<tr>
<td WIDTH="338" valign=top>
<table widt=338 border=0 cellpadding=2 cellspacing=2>
 <tr>
    <td colspan=2><p><b>Capture los datos del alumno</b><br><br></td>
 </tr>
 <tr>
    <td><b>Nombre :</b></td><td><input name="nombre" size=40 value="" maxlength=300></td>
 </tr>
 <tr>
<td><b>Apellido Paterno :</b></td><td><input name="apellidoPaterno" size=40 value="" maxlength=300></td>
 </tr>
 <tr>
<td><b>Apellido Materno :</b></td><td><input name="apellidoMaterno" size=40 value="" maxlength=300></td>
 </tr>
 <tr>
  <td><font class=FontSmall><b>Sexo :</b></font></td>
  <td><select name="sexoAlumno">
      <option VALUE="" selected>
      <option VALUE=1>M</option>
      <option VALUE=2>F</option>
      </select</td>
 </tr>

 <tr><td><font class=FontSmall><b>Fecha de Nac :</b></td><td><input type=text name=alumnoFechaNac size=10 id=publicacion><INPUT TYPE=RESET VALUE=" ... " ONCLICK="return showCalendar('publicacion', 'y-m-d');"></td></tr>
 <tr>
  <td><b>CURP :</b></td><td><input name="curpAlumno" size=16 value="" maxlength=16></td>
 </td>
 </tr>
 <tr>  <td><b>Email :</b></td><td><input name="emailAlumno" size=25 value="" maxlength=300></td>
 </td> </tr>
 <tr>  <td><b>Password :</b></td><td><input type=password name="passwordAlumno" size=16 value="" maxlength=16></td>
 </td> </tr>
 <tr>  <td><b>Verifica Password :</b></td><td><input type=password name="verificaPasswordAlumno" size=16 value="" maxlength=16></td> </td> </tr>

</table>

<BR>&nbsp;
<BR>&nbsp;
<p><b>Seleccione una imagen para el documento</b>
<br><b>Imagen :</b> <select  name="foto" onChange="selecciona_foto(this.options[this.selectedIndex].value)">
<option value="0.gif" selected>Sin foto
pagina
;

##EJECUCION DE LA CONSULTA
$Consulta="select nombre, titulo from imagen where home='s' and activo <> 'n'";
($elementos,$rs)=&ejecuta_SQL($Consulta,$manejador1);

#RECUPERACION DE INFORMACION DEL RECORDSET
while ($apuntador=$rs->fetchrow_hashref)
  {
print <<pagina
<OPTION VALUE=$apuntador->{'nombre'}>$apuntador->{'titulo'}</OPTION>
pagina
;
  }


#$SQL="select nombre, titulo from imagen where home='s' and activo <> 'n'";
#($encontrados,$sth1)=&do_SQL;

# while ($pointer = $sth1->fetchrow_hashref){
#   $t_nombre = $pointer->{'nombre'};
#   $t_titulo = $pointer->{'titulo'};

#   print "<option value=\"$t_nombre\">$t_titulo\n";
#   }
print "</select>\n";
#&cerrar_conexion;
#DESCONEXION A LA BASE DE DATOS
$manejador1->disconnect;
print <<pagina

<br>&nbsp;
<br>&nbsp;
<BR><B>Seleccione la alineaci&oacute;n de la imagen.</B>
<BR><input type="radio" name="alineacion" value="I" checked> <B>Izquierda</B>
<BR><input type="radio" name="alineacion" value="D"> <B>Derecha</B>
<br>&nbsp;
</td>

<td WIDTH="330" valign=top><B>Escriba una s&iacute;ntesis para el documento: </B>
<BR><center><textarea name="sintesis" rows=3 cols=35></textarea></center>
<p><b>Contenido del documento :</b>
<BR><center><textarea name="contenido" rows=7 cols=35></textarea></center>
<BR>&nbsp;
<P> &nbsp;&nbsp;&nbsp;<img src="$ruta/imagenes/0.gif" name="objetivo" BORDER=1 WIDTH=145 HEIGHT=132>

</td>
</tr>
</table>
<BR>&nbsp;
<BR>&nbsp;
<table border=0>
<tr><td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type=button value="Enviar Datos" onClick="envia_datos(formita)">&nbsp;&nbsp;&nbsp;
<input type=reset value="Limpiar Datos">
<INPUT TYPE=HIDDEN NAME=usuario  VALUE=$usuario>
<INPUT TYPE=HIDDEN NAME=passwordEncriptado VALUE=$passwordEncriptado>
<INPUT TYPE=HIDDEN NAME=parametro VALUE="$idInstitucion">

</td></tr>
</table>
</form>
pagina
;
&cierrePagina;
