<?php
include("../Librerias/ConfNivel2.inc");
$Nivel=$_Nivel2;
$ObjSesion=new Sesiones();   //Clase Sesin
$ObjSesion->MVerifica($Nivel);
$Conexion=new DBAccess();
$Conexion->Acceso($Servidor,$UsuarioBD,$ClaveBD,$BaseDatos);
$Formulario=new Formulario();
//FEncabezado($Nivel);
/*Obtenemos los valores por get*/
 $numero = count($_GET);
     $tags = array_keys($_GET);	
	 $valores = array_values($_GET); 
	  // crea las variables y les asigna el valor 
      for($i=0;$i<$numero;$i++){
      $$tags[$i]=$valores[$i];
       }
	   
	   function FConviertePassword($Password)
{ $Sub1 = substr ($Password,0,10);
  $Sub2 = substr ($Password,10,10);
  $Sub3 = substr ($Password,20,6);
  $Sub4 = substr ($Password,26,6);
  $Password=$Sub2.$Sub1.$Sub4.$Sub3;
  $Password=md5($Password);
  return($Password);
}
	   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//ES" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
		<meta name="viewport" content="width=device-width, initial-scale=1, charset=ISO-8859-1">
		<link rel="stylesheet" type="text/css" href="<? echo $Nivel ?>bootstrap/css/bootstrap.css">    
         <?
	   if ($_JQuery == 1)
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>';
else
echo '<script src="'.$Nivel.'bootstrap/js/jquery.min.js"></script>';
 echo "<link rel='stylesheet' type='text/css' media='all' href='".$Nivel."Scripts/calendar-blue.css' title='win2k-1' />";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/calendar.js'></script>";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/calendar-es.js'></script>";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/funcionescalendario.js'></script>";
        echo "<script language='javascript'>var actual='$FechaActual';</script>";	
	   ?>
        <script src="<? echo $Nivel ?>bootstrap/js/bootstrap.min.js"></script>
        <script src="../Scripts/md5.js"  type=text/javascript></script>
        <link rel="stylesheet" type="text/css" href="<? echo $Nivel ?>Librerias/DataTables-1.10.4/media/css/jquery.dataTables.css">
        <script type="text/javascript" language="javascript" src="<? echo $Nivel ?>Librerias/DataTables-1.10.4/media/js/jquery.dataTables.js"></script>
        <script src="../Librerias/cronometro/js/jquery.countdown.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="<? echo $Nivel ?>Librerias/multicombos/chosen.css">
				 <style type="text/css" media="all">
				     .chosen-rtl .chosen-drop { left: -9000px; }
					 /* Hiding the checkbox, but allowing it to be focused */
.badgebox
{
    opacity: 0;
}

.badgebox + .badge
{
    /* Move the check mark away when unchecked */
    text-indent: -999999px;
    /* Makes the badge's width stay the same checked and unchecked */
    width: 27px;
}

.badgebox:focus + .badge
{
    /* Set something to make the badge looks focused */
    /* This really depends on the application, in my case it was: */
    
    /* Adding a light border */
    box-shadow: inset 0px 0px 5px;
    /* Taking the difference out of the padding */
}

.badgebox:checked + .badge
{
    /* Move the check mark back when checked */
	text-indent: 0;
}
                  </style>
		<title>Tipo de Apoyo</title>        
	</head>
	<body style="padding-top: 60px;">
     <? include $Nivel."menu1.php"; ?>
<SCRIPT language="JavaScript" type="text/JavaScript">
function EvaluaDatos(Accion){
if ((Formulario.Password.value=="") || (Formulario.Confirma.value=="") || (Formulario.Antiguo==""))
   alert("PROPORCIONE DATOS REQUERIDOS");
else {
Formulario.Password.value = hex_md5(Formulario.Password.value);
Formulario.Confirma.value = hex_md5(Formulario.Confirma.value);
Formulario.Antiguo.value = hex_md5(Formulario.Antiguo.value);
Formulario.Accion.value="Modificar";
        }
Formulario.submit();
}

function EvaluaDatos2(Accion){
if (Form.Nombre.value=="")
   alert("PROPORCIONE DATOS REQUERIDOS");
else {
Form.Accion.value="Actualizar";
        }
Form.submit();
}

</script>       
<?
include $Nivel."menu1.php";
 $Consulta="Select * from USUARIOS where IDUSUARIO=".$_SESSION["IdUsuario"];
 $Row=$Conexion->MSelectRegistro($Consulta);


if ($Accion=='Modificar'){ //Si es modificar
 $Password=FConviertePassword($Password);
 $Confirma=FConviertePassword($Confirma);
 $Antiguo=FConviertePassword($Antiguo);

 if ($Antiguo==$Row["PASSWORD"]){
  if ($Password==$Confirma){
    $Consulta="Update USUARIOS set PASSWORD='".$Password."' where IDUSUARIO=".$_SESSION["IdUsuario"];
    $Conexion->MEjecutarSQL($Consulta);
    FMensajeScript("CONTRASEŅA ACTUALIZADA","javascript:history.go(-1)");
    exit();
   }///Primer  IF
  else {
   FMensajeScript("CONTRASEŅAS NO COINCIDEN","javascript:history.go(-1)");
   exit();
  }////del 1er else
 }

 if ($Antiguo!=$Row["PASSWORD"]){////si no es el password
    FMensajeScript("CONTRASEŅA INCORRECTA","javascript:history.go(-1)");
    exit();
 }
} else if ($Accion=='Actualizar') {
  $Consulta="Update USUARIOS set NOMBRE='$Nombre' where IDUSUARIO=".$_SESSION["IdUsuario"];
  $Conexion->MEjecutarSQL($Consulta);
  FMensajeScript("NOMBRE ACTUALIZADO","CambiarPassword.php");

}

?>
<div class="container">
<div class="panel panel-primary">   
     <div class="panel-heading"><strong><i class="fa fa-key" aria-hidden="true"></i> Cambiar Password</strong></div>
      <div class="row" style="margin-left: 10px; margin-right: 10px; margin-top:10px; margin-bottom:10px">
<form action="CambiarPassword.php" method="get" name="Formulario">
<input type="hidden" name="Accion" value="">
   <div class="form-group col-sm-9">  
  <label class="col-lg-2 control-label">Usuario :</label>           
      <label class="col-lg-6 control-label"><?php echo $Row["USUARIO"];?></label>
      </div>
      <div class="form-group col-sm-6">
      <label for="Password" class="col-lg-4 control-label">Password :</label>     
      <?php $Formulario->MInputPassword("Password",32,'',"form-control");?>      
      </div>
      <div class="form-group col-sm-6">
      <label for="Confirma" class="col-lg-6 control-label">Confirmar Password :</label>     
      <?php $Formulario->MInputPassword("Confirma",32,'',"form-control");?>      
      </div>
      <div class="form-group col-sm-6">
      <label for="Antiguo" class="col-lg-6 control-label">Password Anterior :</label>     
      <?php $Formulario->MInputPassword("Antiguo",32,'',"form-control");?>      
      </div>
      <div class="form-group" align="center">  
       <div class="form-group col-sm-12">
      <?php 
	   $Formulario->MBotonScript('Actualizar','Actualizar',"EvaluaDatos('Modificar')","btn btn-primary btn3d", "glyphicon glyphicon-pencil");
	  //$Formulario->MBotonScript("Modificar","","EvaluaDatos('Modificar')",2);?>
      </div>
      </div>
</form>
</div>
</div>
</div>