<?php
    @session_start();
    if (!isset($_SESSION["admin"]["id"])) {
        echo "<script>location.href='index.php';</script>";
    }
    include "config/conf.php";
?>

<!DOCTYPE html>
<html>
<head>
	<title><?php echo $title; ?></title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="utf-8">
	<base href="<?php echo "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]; ?>" />

	<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>

	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/sb-admin.css">
	<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="css/jasny-bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css">
	<link rel="stylesheet" type="text/css" href="css/wysiwyg-color.css">

	<link rel="stylesheet" type="text/css" href="css/style.css">
	
    <link rel="shortcut icon" type="image/x-icon" href="<?=$base;?>/icone.png">

    <link href="summernote.css" rel="stylesheet">
   

	<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/jqBootstrapValidation.js"></script>
	<script type="text/javascript" src="js/bootstrap-inputmask.min.js"></script>
	<script type="text/javascript" src="js/jquery.maskMoney.min.js"></script>
	<script type="text/javascript" src="js/prettify.js"></script>
	<script type="text/javascript" src="js/jquery.colorbox-min.js"></script>

    <script src="js/jquery.complexify.js"></script> 
    <script src="summernote.min.js"></script>

	<link rel="stylesheet" type="text/css" href="colorbox.css">
	<script>
	  $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );
	</script>
</head>
<body>

<?php

    require 'PHPMailerAutoload.php';
    

    $sql = "select a.*, e.id eid, c.nome cliente, c.email 
    	from arquivo a
    	left join envio e on (a.id = e.arquivo_id) 
    	inner join cliente c on (c.id = a.cliente_id)
    	limit 1";
    $consulta = $db->prepare($sql);
	$consulta->execute();
	while ( $dados = $consulta->fetch( PDO::FETCH_OBJ ) ) {

		$email = "burnes@professorburnes.com";

		if ( empty ( $dados->eid ) ) {

			//Create a new PHPMailer instance
			$mail = new PHPMailer;
			//Tell PHPMailer to use SMTP
			$mail->isSMTP();
			//Enable SMTP debugging
			// 0 = off (for production use)
			// 1 = client messages
			// 2 = client and server messages
			$mail->SMTPDebug = 0;
			//Ask for HTML-friendly debug output
			$mail->Debugoutput = 'html';
			//Set the hostname of the mail server
			$mail->Host = 'mail.maxcredit.com.br';
			// use
			// $mail->Host = gethostbyname('smtp.gmail.com');
			// if your network does not support SMTP over IPv6
			//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
			$mail->Port = 25;
			//Set the encryption system to use - ssl (deprecated) or tls
			//$mail->SMTPSecure = 'ssl';
			//Whether to use SMTP authentication
			$mail->SMTPAuth = true;
			//Username to use for SMTP authentication - use full email address for gmail
			$mail->Username = "naoresponda@maxcredit.com.br";
			//Password to use for SMTP authentication
			$mail->Password = "maxserasa!%1";
			//Set who the message is to be sent from
			$mail->setFrom('naoresponda@maxcredit.com.br', 'MaxCredit');
			$mail->addAddress("financeiro01@maxcredit.com.br", "Thiago Alano");
			$mail->addAddress("burnes@professorburnes.com", "Burnes");
			//Set the subject line
			$mail->Subject = 'Teste de envio de e-mail - '. time();
			//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
			$mail->msgHTML("<p class='font:14px Verdana'>Prezado Cliente,<br>Segue boleto em anexo referente consultas SPC Brasil.<br>
	Caso haja o pagamento em atraso, atualizar o boleto pelo site https://www.itau.com.br/servicos/boletos/ .
	<br>Após o vencimento, caso o boleto não esteja pago, haverá a suspensão dos serviços.<br><br> 
	Atenciosamente</p>");
			//Replace the plain text body with one created manually
			$mail->AltBody = 'This is a plain-text message body';
			//Attach an image file
			$mail->addAttachment('../../downloads/'.$dados->arquivo);

			//send the message, check for errors
			if (!$mail->send()) {
			    echo "<p class='alert alert-danger'>Erro ao enviar e-mail $email : " . $mail->ErrorInfo."</p>";
			} else {
			    echo "<p class='alert alert-success'>Mensagem enviada com sucesso para $email!</p>";
			}
		}

		exit;
	}
?>

</body>
</html>
