<?php
date_default_timezone_set('America/La_Paz');
if (!empty($_POST)){
   if (isset($_POST["username"]) &&isset($_POST["passwordact"])){
      if ($_POST["username"]!=""&&$_POST["passwordact"]!=""){
         session_start();
         if ($_POST["username"] != $_SESSION['user_id']) {
            print "<script>alert(\"Usuario no Corresponde.\");
            window.location='../menus.php';</script>";
         }
         $_SESSION["user_bd"]=chr(67).chr(104).chr(97).chr(121).chr(48).chr(51).chr(54).chr(53);
         include_once "../lib/fpdf/funci.php";
         $conex = conectar();
         $fehoy = date("Y-m-d");
         $local = mysql_query("select * from sapmt where sapmtfech >= '$fehoy'");
         $rowid = mysql_num_rows($local);
         if ($rowid == 0) {
            print "<script>alert(\"Sistema Caducado llamar al Administrador.\");
            window.location='../login.php';</script>";
         }
         $xusua = trim($_POST["username"]);
         $xpawd = trim($_POST["passwordact"]);
         $actpw =  f1000_clave($xpawd);
         $sql1= "select * from sausr
                 where  sausrusua = '$xusua'
                 and    sausrpawd = '$actpw'";
         $query = mysql_query($sql1);
         $linea = mysql_num_rows($query);
         if ($linea != 1){
            print "<script>alert(\"Clave Actual No Coincide.\");
            window.location='../menus.php';</script>";
         }else{
            $resul = mysql_fetch_assoc($query);
            $xpwdn = trim($_POST["passwordnvo"]);
            $newpw =  f1000_clave($xpwdn);
            $modif = "update sausr set sausrpawd = '$newpw' where sausrusua = '$xusua'";
            $confi = mysql_query($modif);
            print "<script>window.location='../menus.php';</script>";				
         }
      }
   }
}
?>
