<?php
/*################################################
@author: Code Tecnologia
@date: 25/03/2019
@version: 1.00
@purpose: Classe responsavel por aceitar Termo

Resposta esperada:
{
 "erro": false,
 "mensagem":"Você concordou com os termos de uso. Já pode usar o aplicativo."
}
*/
  
################################################*/

include_once("connect.php");

//Funcao para exibir o json
function exibir_json($json){
    $echo_json = json_encode($json);
    $json = array_map('utf8_encode', $json);
	echo $echo_json;
}

//Verificando se a mensagem foi transmitida por POST
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){  
    $status = array(
				'erro' => 'true',
				'mensagem' => 'O formato recebido nao e um POST');
    //$json = json_encode($status);
	exibir_json($status);
    exit(0);
}

//Verificando se o Content-type � 'application/json'
/*
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
    $status = array(
				'erro' => 'true',
				'mensagem' => 'O tipo da mensagem esta incorreto.');
    $json = json_encode($status);
	exibir_json($json);
    exit(0);
}
*/



//recebendo a requisicao
$content = file_get_contents("php://input");
$content = utf8_encode($content); //evita erros


  //obtendo informacoes do Header da mensagem
    $email = isset($_SERVER["HTTP_EMAIL"]) ? trim($_SERVER["HTTP_EMAIL"]) : '';
    
	//Caso o mobile passe a variavel sem valor para atualizacao.
	if (empty($email)){
		$status = array(
					'erro' => 'true',
					'mensagem' => 'E-mail nao informado');
		  //$json = json_encode($status);
		  //enviarCurl($url,$json);
		  exibir_json($status);
		  exit(0);
	}else{
		
		/*
		echo $manter_parceiro;
		exit(0);
		*/
		
		
		//JUAN: Escrever rotina para enviar e-mail de confirmacao para o e-mail cadastrado
		//No e-mail cliar um link para: http://parceria.codetecnologia.com.br/mobile/recuperar_senha?id=base64(campo).php
		//Criar a págiona com a informação
		
		$consulta_email = "select *
								from contabilidades
							   where ds_email = '$email'";
	
//	echo $consulta_email;
//	exit;
	
		$result_consulta_email = mysqli_query($conexao, $consulta_email) or die(mysqli_error($conexao));
        if(mysqli_num_rows($result_consulta_email)>0){
            while($row = mysqli_fetch_assoc($result_consulta_email)){
                $id_parceiro_email	= $row['id'];
                $nome = $row['ds_empresa'];
            }
        }
        else{
            $status = array(
					'erro' => 'true',
					'mensagem' => 'E-mail não cadastrado');
		  //$json = json_encode($status);
		  //enviarCurl($url,$json);
		  exibir_json($status);
		  exit(0);
        }
        
        $id_parceiro_email = base64_encode($id_parceiro_email);
//		echo "Meu id é:".$id_parceiro_email;
//		exit(0);
		
		$to = $email;
        $subject = "Alteração de senha para $nome";
        $message = "

            <!DOCTYPE html>
            <html style='padding: 0px; margin: 0px;' lang='pt_br'>
               <head> 
                   <meta charset='UTF-8' />
                    <style>
                       body{margin:
                            0;padding: 0;
                       }
                       @media only screen and (max-width:640px){
                           table, img[class='partial-image']{
                                width:100% !important;
                                height:auto !important;
                                min-width: 200px !important; 
                       }
                  </style>
               </head>
            <body>
            <table style='border-collapse: collapse; border-spacing:
               0; min-height: 418px;' cellpadding='0' cellspacing='0' width='100%' bgcolor='#f2f2f2'>
               <tbody>
                  <tr>
                     <td align='center' style='border-collapse: collapse;
                        padding-top: 30px; padding-bottom: 30px;'>
                        <table cellpadding='5' cellspacing='5' width='600' bgcolor='white' style='border-collapse: collapse;
                           border-spacing: 0;'>
                           <tbody>
                              <tr>
                                 <td style='border-collapse: collapse; padding: 0px;
                                    text-align: center; width: 600px;'>
                                    <table style='border-collapse: collapse;
                                       border-spacing: 0; box-sizing: border-box;
                                       min-height: 40px; position: relative; width:
                                       100%;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse:
                                                collapse; font-family: Arial; padding: 10px
                                                15px;'>
                                                <table width='100%' style='border-collapse: collapse; border-spacing:
                                                   0; font-family: Arial;'>
                                                   <tbody>
                                                      <tr>
                                                         <td style='border-collapse: collapse;'>
                                                            <hr style='border-color: rgb(255,255,255);
                                                               border-style:
                                                               dashed;'>
                                                         </td>
                                                      </tr>
                                                   </tbody>
                                                </table>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                    <table style='border-collapse: collapse; border-spacing:
                                       0; box-sizing: border-box; min-height: 40px;
                                       position: relative; width: 100%;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse: collapse; font-family:
                                                Arial; padding: 10px 15px; background:
                                                #fff;'>
                                                <table width='100%' style='border-collapse: collapse; border-spacing:
                                                   0; font-family: Arial;'>
                                                   <tbody>
                                                      <tr>
                                                         <td align='center' style='border-collapse:
                                                            collapse; line-height: 0px; padding: 0;
                                                            mso-line-height-rule: exactly;'><a target='_blank' style='display: block; text-decoration: none;
                                                            box-sizing: border-box; font-family: arial; width:
                                                            100%;'><img class='partial-image' width='245' style='box-sizing: border-box;
                                                            display: block; max-width: 600px; min-width:
                                                            160px;' dfsrc='http://parceria.codetecnologia.com.br/img1.png' src='http://parceria.codetecnologia.com.br/img1.png'></a></td>
                                                      </tr>
                                                   </tbody>
                                                </table>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                    
                                    <table style='border-collapse: collapse;
                                       border-spacing: 0; box-sizing: border-box;
                                       min-height: 40px; position: relative; width: 100%;
                                       font-family: Arial; font-size: 25px;
                                       padding-bottom: 20px; padding-top: 20px;
                                       text-align: center; vertical-align:
                                       middle;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse: collapse; font-family:
                                                Arial; padding: 10px 15px;'>
                                                <table width='100%' style='border-collapse: collapse; border-spacing:
                                                   0; font-family: Arial;'>
                                                   <tbody>
                                                      <tr>
                                                         <td style='border-collapse: collapse;'>
                                                            <h2 style='font-weight: normal; margin: 0px; padding:
                                                               0px; color: #666; word-wrap: break-word;'><a style='display: inline-block; text-decoration:
                                                               none; box-sizing: border-box; font-family: arial;
                                                               width: 100%; font-size: 25px; text-align: center;
                                                               word-wrap: break-word; color: rgb(102,102,102);' target='_blank'><span style='font-size: inherit;
                                                               text-align: center; width: 100%; color: #666;'>Altera&ccedil;&atilde;o de senha</span></a>
                                                            </h2>
                                                         </td>
                                                      </tr>
                                                   </tbody>
                                                </table>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                    
                                    
                                    <table style='border-collapse: collapse;
                                       border-spacing: 0; box-sizing: border-box;
                                       min-height: 40px; position: relative; width:
                                       100%;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse:
                                                collapse; font-family: Arial; padding: 10px
                                                15px;'>
                                                <table width='100%' style='border-collapse: collapse; border-spacing:
                                                   0; text-align: left; font-family:
                                                   Arial;'>
                                                   <tbody>
                                                      <tr>
                                                         <td style='border-collapse:
                                                            collapse;'>
                                                            <div style='font-family: Arial;
                                                               font-size: 15px; font-weight: normal; line-height:
                                                               170%; text-align: left; color: #666; word-wrap:
                                                               break-word;'>
                                                               <div style='text-align:
                                                                  center;'><br></div>
                                                               <div style='text-align:
                                                                  center;'>Clique no link abaixo para prosseguir com a altera&ccedil;&atilde;o da senha:<span style='line-height: 0; display:
                                                                     none;'></span><span style='line-height: 0;
                                                                     display:
                                                                     none;'></span>
                                                               </div>
                                                            </div>
                                                         </td>
                                                      </tr>
                                                   </tbody>
                                                </table>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                    <table style='border-collapse: collapse;
                                       border-spacing: 0; box-sizing: border-box;
                                       min-height: 40px; position: relative; width: 100%;
                                       padding-bottom: 10px; padding-top:
                                       10px;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse:
                                                collapse; font-family: Arial; padding: 10px 15px;
                                                padding-top: 20px; padding-bottom: 20px;'>
                                                <div style='font-family: Arial; text-align:
                                                   center;'>
                                                   <table style='border-collapse:
                                                      collapse; border-spacing: 0; background-color:
                                                      #63B8FF; border-radius: 10px; color:
                                                      rgb(255,255,255); display: inline-block;
                                                      font-family: Arial; font-size: 15px; font-weight:
                                                      bold; text-align: center;'>
                                                      <tbody style='display:
                                                         inline-block;'>
                                                         <tr style='display:
                                                            inline-block;'>
                                                            <td align='center' style='border-collapse: collapse; display:
                                                               inline-block; padding: 15px 20px;'><a href='http://parceria.codetecnologia.com.br/mobile/recuperar_senha_ws.php?id=$id_parceiro_email' style='display: inline-block;
                                                               text-decoration: none; box-sizing: border-box;
                                                               font-family: arial; color: #fff; font-size: 15px;
                                                               font-weight: bold; margin: 0px; padding: 0px;
                                                               text-align: center; word-wrap: break-word; width:
                                                               100%;'>Alterar senha</a>
                                                            </td>
                                                         </tr>
                                                      </tbody>
                                                   </table>
                                                </div>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                    <table style='border-collapse: collapse;
                                       border-spacing: 0; box-sizing: border-box;
                                       min-height: 40px; position: relative; width: 100%;
                                       display: table;'>
                                       <tbody>
                                          <tr>
                                             <td style='border-collapse:
                                                collapse;'>
                                                <div style='font-family: Arial;
                                                   font-size: 13px; font-weight: normal; line-height:
                                                   170%; text-align: left; color: #666; word-wrap:
                                                   break-word;'>
                                                   <div style='text-align:
                                                      center;'><br></div>
                                                   <div style='text-align:
                                                      center;'>* caso queira tirar alguma dúvida, estamos a disposição nos telefones: (11) 2629-0025 | (11) 2629-0024<span style='line-height: 0; display:
                                                         none;'></span><span style='line-height: 0;
                                                         display:
                                                         none;'></span>
                                                   </div>
                                                </div>
                                             </td>
                                          </tr>
                                       </tbody>
                                    </table>
                                  </td>
                              </tr>
                           </tbody>
                        </table>
                     </td>
                  </tr>
               </tbody>
            </table>
                    
                                 
            </body>
            </html>
                        
                        
                        
                        
                  ";
        
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: CODE Tecnologia <codecrm@codecrm.com.br>' . "\r\n";

        $sentmail = mail($to,$subject,$message,$headers);
		
	/*
	Informe sua nova senha:[     ]
	Confirme sua nova senha:[      ]
	
	*/
		
		
		
		
		}
		//mysqli_query($conexao, $confirmar_termo) or die ($conexao);
		
                
                $status = array( 'erro' => 'false'
    				    ,'mensagem' => 'Acesse seu e-mail e confirme sua identidade para usar nosso app.'
    				    );
                //$json = json_encode($status);
            	exibir_json($status);
                exit(0);
            
        
	


?>