<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

// require '../vendor/autoload.php';
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
require_once('DataManager.Class.php');

class Correo {

    public $conn;
    public $mail;
    
    public $mailAsunto;

    function __construct($c) {
        try {
			if(isset($c)){
                $this->conn = $c;
			} else {
				$this->conn = DataManager::getInstance();
                
                $this->mail = new PHPMailer();
                $this->mail->isSMTP();
                $this->mail->isHTML(true);
                $this->mail->SMTPDebug = SMTP::DEBUG_OFF;
                $this->mail->CharSet = "UTF-8";

                require_once($_SERVER['DOCUMENT_ROOT'].'/clases/Configuracion.Class.php');
                $configuracion_obj  = new Configuracion(null);

                $configuracion_inf  = $configuracion_obj->muestraInformacionConfiguracion( 21, null, 0); 
                $this->mail->Host     = $configuracion_inf['conf_texto'];
                $configuracion_inf  = $configuracion_obj->muestraInformacionConfiguracion( 22, null, 0); 
                $this->mail->Port     = $configuracion_inf['conf_valor'];
                $configuracion_inf  = $configuracion_obj->muestraInformacionConfiguracion( 23, null, 0); 

                $this->mail->SMTPAuth = true;

                $this->mail->Username = $configuracion_inf['conf_texto'];
                $configuracion_inf    = $configuracion_obj->muestraInformacionConfiguracion( 24, null, 0); 
                $this->mail->Password = $configuracion_inf['conf_texto'];
                $configuracion_inf    = $configuracion_obj->muestraInformacionConfiguracion( 25, null, 0); 
                $fromCorreo           = $configuracion_inf['conf_texto'];
                $configuracion_inf    = $configuracion_obj->muestraInformacionConfiguracion( 26, null, 0); 
                $fromDenominacion     = $configuracion_inf['conf_texto'];

                $configuracion_obj->Close();

                $this->mail->setFrom($fromCorreo, $fromDenominacion);
                $this->mail->addReplyTo($fromCorreo, $fromDenominacion);
			}
		} catch(PDOException $e) {
			echo "Error en la conexión: " . $e->getMessage();
		}
    }

	public function correoAdmAceptacionSolicitudInscripcion($mail) {
		if (!$mail->send()) {
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message sent!';
        }
	}


    function Close() {

        $this->conn = null;

    }
}
?>