<?php
date_default_timezone_set('America/Sao_Paulo');
error_reporting(0);
ini_set("display_errors", 0 );
session_regenerate_id();
@session_name(str_replace(" ", "", "pae29072015"));
@session_cache_limiter("none");
@session_start();
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">



<head>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



<title>Untitled Document</title>







</head>







<body>



<?php
include("../include/dbcommon.php");
 


	function anti_injection($sql){
   $sql = preg_replace("/( from |select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/", "" ,$sql);
   $sql = trim($sql);
   $sql = strip_tags($sql);
   $sql = (get_magic_quotes_gpc()) ? $sql : addslashes($sql);
   return $sql;
}

function encryptor($action, $string) {
    $output = false;

    $encrypt_method = "AES-256-CBC";
    //pls set your unique hashing key
    $secret_key = 'zumbieducafro';
    $secret_iv = 'freidavid2015';

    // hash
    $key = hash('sha256', $secret_key);

    // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
    $iv = substr(hash('sha256', $secret_iv), 0, 16);

    //do the encyption given text/string/number
    if( $action == 'encrypt' ) {
        $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
        $output = base64_encode($output);
    }
    else if( $action == 'decrypt' ){
    	//decrypt the given text/string/number
        $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
    }

    return $output;
}



//$email=anti_injection($_SESSION["email"]);
$email = "eueliton@live.com";
$id_certificado=53;
//$cpf = '016.947.699-50';
//$tipo = '1';
//$idato = '15';



$ano=date("Y");



$dia=date("d");



$mes_num=date("m");



$data_insert=date("Y-m-d H:i:s");







$data=date("Y-m-d");



switch (date("m")) {



        case "01":    $mes = "Janeiro";     break;



        case "02":    $mes = "Fevereiro";   break;



        case "03":    $mes = "Março";       break;



        case "04":    $mes = "Abril";       break;



        case "05":    $mes = "Maio";        break;



        case "06":    $mes = "Junho";       break;



        case "07":    $mes = "Julho";       break;



        case "08":    $mes = "Agosto";      break;



        case "09":    $mes = "Setembro";    break;



        case "10":    $mes = "Outubro";     break;



        case "11":    $mes = "Novembro";    break;



        case "12":    $mes = "Dezembro";    break; 



 }



require_once('qrcode/qrcode.class.php');

//include "configbd.php";

if($email!="" ){

// GERA CÒDIGO

function codigo($length=10)
{
 $salt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 $len = strlen($salt);
 $pass = '';
 mt_srand(10000000*(double)microtime());
 for ($i = 0; $i < $length; $i++)
 {
   $pass .= $salt[mt_rand(0,$len - 1)];
 }
 return $pass;
}

$codigo=codigo(12);



 
	$sql10 = "SELECT count(*) as total,nome,cpf,id from associados where email='$email' order by id desc limit 1";
$resultado10 = CustomQuery($sql10);

while($dados2 = db_fetch_array($resultado10)){
$nome = $dados2['nome'];
$cpf = $dados2['cpf'];
$linhas2 = $dados2['total'];

}

//verifica se já há certificado para o ato em tela


$sql3= "select count(*) as total , codigo from certificados_pessoa where DATE(data)='".$data."' and idcertificado=".$id_certificado." and cpf='".$cpf."'";
$resultado3 = CustomQuery($sql3);
$dados3 = db_fetch_array($resultado3);

if($dados3['total']!=0){

$codigo = $dados3['codigo'];
}
else{
	
$sql4= "INSERT into certificados_pessoa (idcertificado,cpf,codigo,data) VALUES(".$id_certificado.", '".$cpf."','".$codigo."','".$data_insert."')" ;
$resultado4 = CustomQuery($sql4);
	
}





if($linhas2!=0){

$html = '



<html xmlns="http://www.w3.org/1999/xhtml">



<head>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



<title>DECLARAÇÂO</title>



<style type="text/css">



.logo {



	position: absolute;



	z-index: 3;



	top: 0px;



	left: 0px;



	clear: none;



	float: none;



}



</style>



</head>







<body>';





//==============================================================
//==============================================================
//==============================================================


$html .= '







<div>







  <p><img src="siedu.jpg" width="400" height="100" />
</p>

 <p><h2>REDE DE CURSINHOS <br>PRÉ-VESTIBULARES EDUCAFRO</h2>
</p>


 <table>



 <tr>



 <td><center>







   <td>



   <strong></td>



   </center>



 </td></table>



  <table cellspacing="0" cellpadding="0" width="100%">



    <tbody>



      <tr>



        <td><div v:shape="_x0000_s1032">



          <p> </p>



        </div></td>



      </tr>



    </tbody>



  </table>



  </p>



 <p></p>
  <p></p>
  <p></p>


 <h1 align="center"><u>DECLARAÇÃO DE ESTUDANTE</u> </h1>



  <h2 align="center"></h2>



  <p> </p>



  <p> </p>



  <p align="Justify"><h3>	Declaramos, para os devidos fins, que '.ucwords($nome).', CPF nº '.$cpf.', é estudante regularmente matriculado(a) em nossa Rede de Cursinhos Pré-Vestibulares. </h3></p>



      <p> </p>



  <p align="Justify"></b></p>




  <p> </p>


  



  <p><strong> </strong></p>



  
  <p><strong> </strong></p>



   <p><strong> </strong></p>



  



  <p align="center"><br>
</p>



  <p align="center"><strong><em></em></strong></p>



  <br clear="all" />



  











</div>






<div style="position:fixed; right: 0mm; top: 0mm; text-align: center;



padding: 0.5mm; padding-top: 2mm;">



<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 9pt; color: #000088;"><tr>
<td width="20%" style="text-align: right;">


<td width="43%"><span style="font-size:45pt;"> </span></td>
<td width="37%">

<center><barcode  size="1" height="1.75" code="'.$codigo.'" type="EAN128A" />
<span style="font-size:14pt; "><br>Código : '.$codigo.' </span><br><span style="font-size:12pt; "> Para verificar a autenticidade do documento basta acessar www.educafro.org.br/cdigital e inserir o código acima</span></center>
</td>




</tr></table>











<div style="font-family: ocrb;"> </div>



<br>



</div>

<div style="position:fixed; right: 60mm; top: 140mm; text-align: center;



padding: 0.5mm; padding-top: 2mm;">

<h4><center>São Paulo, '.$dia. ' de '.$mes.' de '.$ano.'</center></h4>
 
</div>


<div style="position:fixed; right: 30mm; top: 155mm; text-align: center;



padding: 0.5mm; padding-top: 2mm;">



<center><img src="assinatura_nova.png" width="386" height="124" /></center></div>



<div style="position:fixed; right: 66mm; top: 170mm;  text-align: center;



padding: 0.5mm; padding-top: 2mm;">



<center><p align="center">Frei David   Santos,OFM</p>



  <p align="center">Diretor da   Educafro</p></center></div>


<br><br>
<br><p>** Documento isento de carimbo e assinado apenas digitalmente</p>


<div style="position:fixed; left:500px;">

 <img  src="logoeducafro.jpg" width="189" height="149" />
</div>

<div style="position:fixed; top: 800px;">
   <img src="qr/php/qr_img.php?e=H&s=3&d=www.educafro.org.br/cdigital/index.php?res='.encryptor('encrypt','q='.$codigo).'" />  

</div>
 
';

$html .='



</body>



</html>



'



;


include("../../mpdf/mpdf.php");
$mpdf=new mPDF();



$mpdf->SetWatermarkImage('logoedu.png', 1, 'P', array(10,60));
$mpdf->showWatermarkImage = true;

$mpdf->watermarkImageAlpha = 0.1;
$mpdf->WriteHTML($html);


$content = $mpdf->Output('', 'S');


$content = chunk_split(base64_encode($content));
$mailto = $email;
$from_name = 'EDUCAFRO';
$from_mail = 'site@educafro.org.br';
$replyto = 'site@educafro.org.br';
$uid = md5(uniqid(time())); 
$subject = utf8_decode('EDUCAFRO - Declaração de Aluno');
$message = 'Parabéns '.strtoupper($nome).'! Sua declaração de aluno da Rede Educafro está anexo!

FAMILIA EDUCAFRO';
$filename = 'declaracaoo_educafro.pdf';

$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=utf-8\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
$is_sent = @mail($mailto, $subject, "", $header);

$mpdf->Output('declaracao_educafro.pdf','I');
exit;
//==============================================================
//==============================================================
//==============================================================
}}
else{
	
	exit;
	
}


 



?>
 
</body>



</html>