<?php

    //error_reporting(E_ALL);
    //ini_set('display_errors', '1');

	use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    require 'PHPMailer/src/Exception.php';
    require 'PHPMailer/src/PHPMailer.php';
    require 'PHPMailer/src/SMTP.php';

	# Incluimos la clase conexion para poder heredar los metodos de ella.
	include_once 'conexion.php';

	
	class Usuario extends Conexion{

		public function Usuario()
		{
		}
		
		/*public function login($email, $clave)
		{
			$err_msg = '||-1||#r_login_div||Cuenta desactivada.';
			$err_msgb = '||-1||#r_login_div||Datos incorrectos, verificar credenciales.';
			$err_msgc = '||-1||#r_login_div||Fallo conexión, volver a intentar.';
			$success_msg = '||0||#r_login_div||Credenciales correctas. Accediendo a página principal...';

			parent::conectar();

			$email  = parent::salvar($email);
        	$clave = parent::salvar($clave);

        	//$consulta = 'SELECT * FROM user WHERE TID="'.$tid.'" AND PASSWORD = MD5("'.$clave.'") LIMIT 1';

        	/*$consulta = 'SELECT id, 
        	    email,
        		nombre, 
        		apellido, 
        		AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass,
        		status
        		FROM subscribers WHERE EMAIL ="' . $email .'"';*//*
        	$consulta = 'SELECT id, email, nombre, apellido, status,
        		    AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass
        		FROM subscribers WHERE EMAIL = ?';
        	parent::prepararConsulta($consulta);
			parent::bindingLogin($email);

        	//print $consulta;

        	//$verificar_usuario = parent::verificarConsulta($consulta);
        	$verificar_usuario = parent::verificarPreparedStatement();

        	if($verificar_usuario > 0){
        	 	//$user = parent::consultaArreglo($consulta);
        	 	$user = parent::arregloPreparedStatement();

        	 	if($user['pass'] == $clave){

	          		if($user['status'] == 1){
	          		    
	          		    session_start();
	          			$_SESSION['id'] = $user['id'];
	          			$_SESSION['email'] = $user['email'];
	          			$_SESSION['subscriber']  = $user['nombre'] . ' ' . $user['apellido'];
	          			//$_SESSION['status']  = $user['status'];
	          			$_SESSION['log_in'] = 1;
	          			
	          			//print_r($_SESSION);
	          			
	          			//echo $success_msg . '||https://manualesdigitales.fcamexico.com.mx/index.php/profile/';
	          			echo $success_msg . '||https://qa.manualesdigitales.stellantis.com.mx/index.php/home/';
	          		}else{  //El usuario esta inactivo
	        			echo 'error_4' . $err_msg;
	        		}
	        	}else{
	        		echo 'error_3' . $err_msgb; //Clave no hace match
	        	}
        	}else{ // El usuario y la clave son incorrectos
      		
      			//echo 'error_2' . $err_msgc;
      			echo 'error_2' . $err_msgb;
    		
    		}

		    parent::cerrar();
		}*/
		public function login($email, $clave)
		{
			//$err_msg = '||-1||#r_login_div||Cuenta desactivada.';
			$err_msg = array(
                "data-op"=>htmlentities("-1", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_login_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Cuenta desactivada.", ENT_QUOTES, 'utf-8' )
            );
			//$err_msgb = '||-1||#r_login_div||Datos incorrectos, verificar credenciales.';
			$err_msgb = array(
                "data-op"=>htmlentities("-1", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_login_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Datos incorrectos, verificar credenciales.", ENT_QUOTES, 'utf-8' )
            );
			//$err_msgc = '||-1||#r_login_div||Falló conexión, volver a intentar.';
			$err_msgc = array(
                "data-op"=>htmlentities("-1", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_login_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Falló conexión, volver a intentar.", ENT_QUOTES, 'utf-8' )
            );
			//$success_msg = '||0||#r_login_div||Credenciales correctas. Accediendo a página principal...';
			$success_msg = array(
                "data-desc"=>htmlentities("success", ENT_QUOTES, 'utf-8' ), 
                "data-op"=>htmlentities("0", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_login_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Credenciales correctas. Accediendo a página principal...", ENT_QUOTES, 'utf-8' )
            );

			parent::conectar();

			$email  = parent::salvar($email);
        	$clave = parent::salvar($clave);

        	//$consulta = 'SELECT * FROM user WHERE TID="'.$tid.'" AND PASSWORD = MD5("'.$clave.'") LIMIT 1';

        	/*$consulta = 'SELECT id, 
        	    email,
        		nombre, 
        		apellido, 
        		AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass,
        		status
        		FROM subscribers WHERE EMAIL ="' . $email .'"';*/
        	$consulta = 'SELECT id, email, nombre, apellido, status,
        		    AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass
        		FROM subscribers WHERE EMAIL = ?';
        	parent::prepararConsulta($consulta);
			parent::bindingLogin($email);

        	//print $consulta;

        	//$verificar_usuario = parent::verificarConsulta($consulta);
        	$verificar_usuario = parent::verificarPreparedStatement();

        	if($verificar_usuario > 0){
        	 	//$user = parent::consultaArreglo($consulta);
        	 	$user = parent::arregloPreparedStatement();

        	 	if($user['pass'] == $clave){

	          		if($user['status'] == 1){
	          		    
	          		    session_start();
	          			$_SESSION['id'] = $user['id'];
	          			$_SESSION['email'] = $user['email'];
	          			$_SESSION['subscriber']  = $user['nombre'] . ' ' . $user['apellido'];
	          			//$_SESSION['status']  = $user['status'];
	          			$_SESSION['log_in'] = 1;
	          			
	          			//print_r($_SESSION);
	          			
	          			//echo $success_msg . '||https://qa.manualesdigitales.fcamexico.com.mx/index.php/profile/';
	          			$success_msg["data-ref"] = htmlentities('https://qa.manualesdigitales.stellantis.com.mx/index.php/home/', ENT_QUOTES, 'utf-8' );
	          			echo json_encode($success_msg);
	          		}else{  //El usuario esta inactivo
	          			$err_msg["data-desc"] = htmlentities('error_4', ENT_QUOTES, 'utf-8' );
	        			echo json_encode($err_msg);
	        		}
	        	}else{
	        		$err_msgb["data-desc"] = htmlentities('error_3', ENT_QUOTES, 'utf-8' );
	        		echo json_encode($err_msgb); //Clave no hace match
	        	}
        	}else{ // El usuario y la clave son incorrectos
      		
      			//echo 'error_2' . $err_msgc;
      			$err_msgb["data-desc"] = htmlentities('error_2', ENT_QUOTES, 'utf-8' );
      			echo json_encode($err_msgb);
    		
    		}

		    parent::cerrar();
		}
		
		
    	/*public function recuperacion($email)
		{
			$err_msg = '||-1||#r_forgot_div||Falló petición, volver a intentar';
			$err_mail_msg = '||-1||#r_forgot_div||El email que ingresó no cuenta con registro previo';
			$success_msg = '||0||#r_forgot_div||Su petición a sido registrada. Se ha enviado un mensaje a su correo electrónico. <br><br>Revisar mensajes nuevos en su bandeja de entrada o en spam.';

			parent::conectar();

			$email = parent::filtrar($email);

			$consulta = 'SELECT email FROM subscribers WHERE email="'.$email.'" AND status = 1 LIMIT 1'; 

			$verificar_correo = parent::verificarConsulta($consulta);

			//print "verificar correo: " . $verificar_correo;

			if($verificar_correo)
			{
				//print 'existe correo';

				//$guid = parent::getGUID();

				$query = 'SELECT AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass FROM subscribers WHERE email = "'.$email.'"';

				//echo $query;

				$verificar_consulta = parent::verificarConsulta($query);

				if($verificar_consulta)
				{
					$result = parent::query($query);
					parent::cerrar();
					while($row = mysqli_fetch_assoc($result))
					{
						$pass = $row["pass"];
					}

					if($this->sendPassNotification($email, $pass))
					{
						exit('recovery requirement success'.$success_msg);
					}
					else
					{
						exit('error_4'.$err_msg); //falló envío de correo
					}
				}else
				{
					exit('error_3'.$err_msg); //falló consulta
				}

				//print "registro: " . $verificar_registro . "\n email: " . $email . " - guid: " . $guid;

			}else{
				exit('error_2'.$err_mail_msg); // no existe 
			}

			parent::cerrar();
		}*/
		
		public function recuperacion($email)
        {
        	//$err_msg = '||-1||#r_forgot_div||Falló petición, volver a intentar';
        	$err_msg = array(
                "data-op"=>htmlentities("-1", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_forgot_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Falló petición, volver a intentar", ENT_QUOTES, 'utf-8' )
            );
        	//$err_mail_msg = '||-1||#r_forgot_div||El email que ingresó no cuenta con registro previo';
        	$err_mail_msg = array(
                "data-op"=>htmlentities("-1", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_forgot_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("El email que ingresó no cuenta con registro previo", ENT_QUOTES, 'utf-8' )
            );
        	//$success_msg = '||0||#r_forgot_div||Su petición a sido registrada. Se ha enviado un mensaje a su correo electrónico. <br><br>Revisar mensajes nuevos en su bandeja de entrada o en spam.';
        	$success_msg = array(
                "data-desc"=>htmlentities("success", ENT_QUOTES, 'utf-8' ), 
                "data-op"=>htmlentities("0", ENT_QUOTES, 'utf-8' ), 
                "data-element"=>htmlentities("#r_forgot_div", ENT_QUOTES, 'utf-8' ), 
                "data-resp"=>htmlentities("Su petición a sido registrada. Se ha enviado un mensaje a su correo electrónico.\n\nRevisar mensajes nuevos en su bandeja de entrada o en spam.", ENT_QUOTES, 'utf-8' )
            );
        
        	parent::conectar();
        
        	$email = parent::filtrar($email);
        
        	//$consulta = 'SELECT email FROM subscribers WHERE email="'.$email.'" AND status = 1 LIMIT 1'; 
        	$consulta = 'SELECT email FROM subscribers WHERE email = ? AND status = 1 LIMIT 1'; 
        	parent::prepararConsulta($consulta);
        	parent::bindingRecuperacion($email);
        
        	//$verificar_correo = parent::verificarConsulta($consulta);
        	$verificar_correo = parent::verificarPreparedStatement();
        
        	//print "verificar correo: " . $verificar_correo;
        
        	if($verificar_correo)
        	{
        		//print 'existe correo';
        
        		//$guid = parent::getGUID();
        
        		//$query = 'SELECT AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass FROM subscribers WHERE email = "'.$email.'"';
        		$query = 'SELECT AES_DECRYPT(password, (SELECT PASSWORD_KEY FROM password_key)) AS pass FROM subscribers WHERE email = ? ';
        		parent::prepararConsulta($query);
        		parent::bindingRecuperacion($email);
        
        		//echo $query;
        
        		//$verificar_consulta = parent::verificarConsulta($query);
        		$verificar_consulta = parent::verificarPreparedStatement();
        
        		if($verificar_consulta)
        		{
        			//$result = parent::query($query);
        			$result = parent::executePrepared();
        			parent::cerrar();
        			while($row = mysqli_fetch_assoc($result))
        			{
        				$pass = $row["pass"];
        			}
        
        			if($this->sendPassNotification($email, $pass))
        			{
        				exit(json_encode($success_msg));
        			}
        			else
        			{
        				$err_msg["data-desc"] = htmlentities("error_4", ENT_QUOTES, 'utf-8' );
        				exit(json_encode($err_msg)); //falló envío de correo
        			}
        		}else
        		{
        			$err_msg["data-desc"] = htmlentities('error_3', ENT_QUOTES, 'utf-8' );
        			exit(json_encode($err_msg)); //falló consulta
        		}
        
        		//print "registro: " . $verificar_registro . "\n email: " . $email . " - guid: " . $guid;
        
        	}else{
        		$err_mail_msg["data-desc"] = htmlentities('error_2', ENT_QUOTES, 'utf-8' );
        		exit(json_encode($err_mail_msg)); // no existe 
        	}
        
        	parent::cerrar();
        }
		
		public function usrRegistration($name, $ap_paterno, $email, $password, $dterms)
		{
			$err_msg = '||-1||#r_reg_div?Falló Registro, volver a intentar.';
			$success_msg = '||0||#r_reg_div||Proceso de registro completo.';
			
			if($dterms == 0)
			{
			    $brands = '0';
			}
		    else
		    {
		        $brands = $dterms;
		    }

			$query ='INSERT INTO subscribers (
				nombre , 
				apellido,
				email, 
				password, 
				status, 
				brands) 
				VALUES (
				"'.htmlentities($name).'",
				"'.htmlentities($ap_paterno).'", 
				"'.$email.'",
				AES_ENCRYPT("'.$password.'", (SELECT password_key FROM password_key)), 
				1,  
				'.$brands.')';

			//echo $query;

			parent::conectar();
			$result = parent::verificarRegistro($query);
			parent::cerrar();

			if($result>0)
			{
				$nombre = $name . ' ' . $ap_paterno;
				$nombre = ucwords(strtolower($nombre));
				//usuario espera activacion.
				/*if($this->sendRegistrationlNotification($nombre, $email))
				{

					echo $success_msg;
				}
				else
				{
					//delete record
					echo 'error_2' . $err_msg; //falló envío de correo
				}*/
				echo $success_msg;
			}
			else
			{
				echo "error_1" . $err_msg;
			}
		}
		/*public function usrRegistration($name, $ap_paterno, $email, $password, $dterms)
		{
			$err_msg = '||-1||#r_reg_div?Falló Registroooooo, volver a intentar.';
			$success_msg = '||0||#r_reg_div||Proceso de registro completoooooo.';
			
			if($dterms == 0)
			{
			    $brands = '0';
			}
		    else
		    {
		        $brands = $dterms;
		    }
				
			$query ='INSERT INTO subscribers (
				nombre , 
				apellido,
				email, 
				password, 
				status, 
				brands) 
				VALUES (
				? ,
				? ,
				? ,
				AES_ENCRYPT( ? , (SELECT password_key FROM password_key)),
				1,  
				? )';

			//echo $query;

			parent::conectar();
			
			parent::prepararConsulta($query);
			parent::bindingRegistration($name, $ap_paterno, $email, $password, $brands);
			
			$result = parent::verificarPreparedInsert();
			//var_dump($result);
			
			parent::cerrar();

			if($result>0)
			{
				echo $success_msg;
			}
			else
			{
				echo "error_1" . $err_msg;
			}
		}*/
		
		/*private function sendRegistrationlNotification($nombre, $email)
		{	
			$mail = new PHPMailer(true);
            $mail->isSMTP();
            $mail->SMTPDebug = SMTP::DEBUG_SERVER;
            $mail->Host = 'jubilados.stellantis.com.mx';
            $mail->Port =465;
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = "ssl";
            $mail->Username = 'no-reply@jubilados.stellantis.com.mx';                 // SMTP username
            $mail->Password = 'Mexico2020';                           // SMTP password
            $mail->setFrom('manuales-digitales@stellantis.com.mx', 'Stellantis Mexico');
            $mail->addAddress($email);
            $mail->Subject = 'Registro de cuenta';
            
            $mail->IsHTML(true); 
            $mail->CharSet = 'UTF-8';
            
            date_default_timezone_set("America/Mexico_City");
			$req_date = date("F d, Y h:i:s A");
			
            //$content = "<h1>Manuales Digitales - Recuperación de contraseña</h1>";
			//$content .= "<h3>Se ha registrado en <b>".$req_date."</b> (CDMX) una solicitud para <b>Recuperar su Contraseña</b> para el portal de Manuales Digitales de FCA México. </h3><<br><br><p> Su contraseña es: " . $pass. "</p>";
            
            $mail->Body = $content; // Mensaje a enviar
            $mail->SMTPDebug = 0;
            if (!$mail->send()) {
                //echo 'Mailer Error: ' . $mail->ErrorInfo;
                return false;
            } else {
                //echo 'Message sent!';
                return true;
            }
		}*/
		
		public function extraerDatosExcel()
    	{
    		parent::conectar();
    		
    		$query = 'SELECT subscribers.id, 
                    subscribers.nombre,
                    subscribers.apellido, 
                    subscribers.email, 
                    favorito.id_usuario, 
                    favorito.url_favorito 
                FROM subscribers INNER JOIN favorito ON subscribers.id = favorito.id_usuario 
                WHERE brands = 0 
                ORDER BY subscribers.id';
    
    		$consulta = parent::query($query);
    		/*$consulta = parent::query('SELECT nombre,apellido,email FROM subscribers');*/
    		return $consulta;		
    
    		parent::cerrar(); 
    
    	}
    	
    	public function agregarFavorito($id_usuario, $url)
        {
            parent::conectar();
            
            $db_id_usuario  = parent::salvar($id_usuario);
            $db_url  = parent::salvar($url);
            
            $query = 'INSERT INTO favorito( id_usuario, url_favorito)
                VALUES ("'.$db_id_usuario.'", "'.$db_url.'")';
            
            
            parent::query($query);
            
            parent::cerrar();
       }
       
        public function getFavList($id_usuario){
            
            $data = [];
            
            //$data = "No tiene sitios agregados"; //!!DATA
            $query = 'SELECT DISTINCT idfavorito as id, url_favorito FROM favorito WHERE id_usuario = ' . $id_usuario;
            //$query = 'SELECT DISTINCT url_favorito FROM favorito WHERE id_usuario = 1';
		
            parent::conectar();
            $verificar_fav = parent::verificarConsulta($query);

        	if($verificar_fav > 0){
        	    //$data = '<table style="border:0">';//!!DATA
        	    
        		$result = parent::query($query);
        
        		while($row = mysqli_fetch_assoc($result))
        		{
        		    //$fav_url = $row["url_favorito"];
        		    $fav = $this->formatFav($row["url_favorito"]);
        		    //$id = $row["id"];
        		    
        		    /*$data .= '<tr>';
        			$data .= '<td style="text-align: left;"><a href="'.$fav_url.'">'.$fav.'</a></td>';
        			$data .= '<td class="remove" style="text-align: right; font-size:30px" data-rm="'.$id.'"><i class="fas fa-window-close"></i></td>';
        			$data .= '</tr>';*/
        			$current_row = json_encode(
        			    array("data_item"=>htmlentities($row["id"], ENT_QUOTES, 'utf-8' ),
        			        "data_fav"=>htmlentities($fav, ENT_QUOTES, 'utf-8' ),
        			        "data_fav_url"=>htmlentities($row["url_favorito"], ENT_QUOTES, 'utf-8' )
        		        )
        		    );
    			 
    			    array_push($data, $current_row);
        		}
        		//$data .= '</table>';//!!DATA
        	}
    		parent::cerrar();
    		echo json_encode($data);
    		//echo json_encode(array("data"=>$data));//echo $data;
    		
        }
       
        /*public function getFavList($id_usuario){
            
            $data = "No tiene sitios agregados";
            $query = 'SELECT DISTINCT idfavorito as id, url_favorito FROM favorito WHERE id_usuario = ' . $id_usuario;
            //$query = 'SELECT DISTINCT url_favorito FROM favorito WHERE id_usuario = 1';
		
            parent::conectar();
            $verificar_fav = parent::verificarConsulta($query);

        	if($verificar_fav > 0){
        	    $data = '<table style="border:0">';
        	    
        		$result = parent::query($query);
        
        		while($row = mysqli_fetch_assoc($result))
        		{
        		    $fav_url = $row["url_favorito"];
        		    $fav = $this->formatFav($fav_url);
        		    $id = $row["id"];
        		    
        		    $data .= '<tr>';
        			$data .= '<td style="text-align: left;"><a href="'.$fav_url.'">'.$fav.'</a></td>';
        			$data .= '<td class="remove" style="text-align: right; font-size:30px" data-rm="'.$id.'"><i class="fas fa-window-close"></i></td>';
        			$data .= '</tr>';
        		}
        		$data .= '</table>';
        	}
    		parent::cerrar();
    		
    		echo json_encode(array("data"=>$data));//echo $data;
    		
        }*/
        
        private function formatFav($fav_url){
            $url_path = explode("/", $fav_url);
            $size = sizeof($url_path);
            $fav = $url_path[$size-2];
            $fav = mb_ereg_replace('[-_]', ' ', $fav);
            
            return strtoupper($fav);
        }

        //Valid if $url is a fav url for $id_usuario
        //Return 1 is a valid new fav, return 0 if the url has already stored
        public function validFav($id_usuario, $url)
        {
            $valid = '0';//$valid = '||0';
            //$db_id  = parent::salvar($id);
            
            $query = 'SELECT idfavorito FROM favorito WHERE id_usuario=' . $id_usuario .' AND url_favorito="' .$url. '"';
            
            parent::conectar();
            
            $verificar_fav = parent::verificarConsulta($query);
            
            parent::cerrar();
            
            if($verificar_fav == 0){
                $valid = '1';//$valid = '||1';
            }
            
            //echo $query;
            echo json_encode(array("data"=>$valid));//echo $valid;
       }
       
        public function removeFav($id_item)
        {
            //$db_id  = parent::salvar($id_item);
            
            $query = 'DELETE FROM favorito WHERE idfavorito=' . $id_item;
            
            parent::conectar();
            
            parent::query($query);
            
            parent::cerrar();
            //echo $query;
       }
       
       
        /*private function sendPassNotification($email, $pass){
			$from = "manuales-digitales@fcamexico.com.mx";
			$header = "From: Manuales Digítales - FCA México <" . $from . ">\r\n";
		    $header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
		    $header .= "MIME-Version: 1.0 \r\n";
		    $header .= "Content-Type: text/html;charset=UTF-8"; 

			$subject = "Recuperación de contraseña";

			date_default_timezone_set("America/Mexico_City");
			$req_date = date("F d, Y h:i:s A");

            $content = "<h1>Manuales Digitales - Recuperación de contraseña</h1>";
			$content .= "<h3>Se ha registrado en <b>".$req_date."</b> (CDMX) una solicitud para <b>Recuperar su Contraseña</b> para el portal de Manuales Digitales de FCA México. </h3><<br><br><p> Su contraseña es: " . $pass. "</p>";

		    //if(mail($email, $subject, utf8_decode($content), $header))
		    if(mail("antoniosinuhe.yanezmorales@external.fcagroup.com", $subject, utf8_decode($content), $header))
		    	return true;
			else
				return false;
		}*/
		
		public function sendPassNotification($email, $pass)
		{
		    $mail = new PHPMailer(true);
            $mail->isSMTP();
            $mail->SMTPDebug = SMTP::DEBUG_SERVER;
            $mail->Host = 'jubilados.stellantis.com.mx';
            $mail->Port =465;
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = "ssl";
            $mail->Username = 'no-reply@jubilados.stellantis.com.mx';                 // SMTP username
            $mail->Password = 'Mexico2020';                           // SMTP password
            $mail->setFrom('manuales-digitales@stellantis.com.mx', 'Stellantis Mexico');
            $mail->addAddress($email);
            $mail->Subject = 'Recuperación de contraseña';
            
            $mail->IsHTML(true); 
            $mail->CharSet = 'UTF-8';
            
            date_default_timezone_set("America/Mexico_City");
			$req_date = date("F d, Y h:i:s A");
			
            $content = "<h1>Manuales Digitales - Recuperación de contraseña</h1>";
			$content .= "<h3>Se ha registrado en <b>".$req_date."</b> (CDMX) una solicitud para <b>Recuperar su Contraseña</b> para el portal de Manuales Digitales de FCA México. </h3><<br><br><p> Su contraseña es: " . $pass. "</p>";
            
            $mail->Body = $content; // Mensaje a enviar
            $mail->SMTPDebug = 0;
            if (!$mail->send()) {
                //echo 'Mailer Error: ' . $mail->ErrorInfo;
                return false;
            } else {
                //echo 'Message sent!';
                return true;
            }
            
		}

	}
