<?php
session_start();
include("conexion.php");


$idparticipante = $_SESSION['idparticipante'];

$sql144 = mysqli_query($con, "SELECT * FROM participantes WHERE id=$idparticipante ");
    //$row14 = mysqli_fetch_all($sql14,MYSQLI_ASSOC);
     while ($row14144 = $sql144->fetch_assoc()) {
    $row144[] = $row14144;
}
    $urlempresa = $row144[0]['urlempresa'];
    



$sqlForm = mysqli_query($con, "SELECT * FROM `respuestas` INNER JOIN preguntas ON respuestas.idpregunta=preguntas.id INNER JOIN reactivos ON respuestas.idreactivo=reactivos.id WHERE respuestas.idparticipante=$idparticipante");
    //$row14 = mysqli_fetch_all($sql14,MYSQLI_ASSOC);
     while ($rowForm = $sqlForm ->fetch_assoc()) {
    $rowFinal[] = $rowForm;
}




error_reporting(E_ALL ^ E_NOTICE); 
$idparticipante = $_SESSION['idparticipante'];
if($idparticipante == null){
    header("Location:index.php");	
}

$sql55 = mysqli_query($con, "SELECT * FROM cuestionario WHERE idparticipante=$idparticipante");
//$row55 = mysqli_fetch_all($sql55,MYSQLI_ASSOC);
 while ($row5555 = $sql55->fetch_assoc()) {
    $row55[] = $row5555;
}
$idcuestionario55 = $row55[0]['id'];
$sql77 = mysqli_query($con, "SELECT * FROM respuestas WHERE idpregunta='11' and idcuestionario=$idcuestionario55 and idparticipante=$idparticipante and paso=11");

  if(mysqli_num_rows($sql77) == 0){
      
    header("Location:paso11");
}

if($_POST['init']){
$urlempresa=$_POST['urlempresa'];
$correo = $_POST['email'];  
//$nombre = $_POST['nombre'];  
$idparticipante = $_SESSION['idparticipante'];

$sql14 = mysqli_query($con, "SELECT * FROM participantes WHERE id=$idparticipante ");
    //$row14 = mysqli_fetch_all($sql14,MYSQLI_ASSOC);
     while ($row1414 = $sql14->fetch_assoc()) {
    $row14[] = $row1414;
}
    $urlempresa = $row14[0]['urlempresa'];
    


$to = $correo;
$subject = "Resultado del test";
$headers = 'From: PsicoCentro <noreply@psicocentro.com>' . "\r\n" .
           'Bcc: consultas@psicocentrofc.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header .= "Content-Type: application/pdf; name=\"".$file."\"\r\n"; 
$message = "Los datos del participante son:"."<br>";
$message .= "Nombre:"." ".$urlempresa. "<br>";
$message .= "Correo:"." ".$correo. "<br>";
$message .= "Resultado del test:"."<br>";
$message .= "1.-".$rowFinal[0]['pregunta']." "."R=".$rowFinal[0]['reactivo']. "<br>";
$message .= "2.-".$rowFinal[1]['pregunta']." "."R=".$rowFinal[1]['reactivo']. "<br>";
$message .= "3.-".$rowFinal[2]['pregunta']." "."R=".$rowFinal[2]['reactivo']. "<br>";
$message .= "4.-".$rowFinal[3]['pregunta']." "."R=".$rowFinal[3]['reactivo']. "<br>";
$message .= "5.-".$rowFinal[4]['pregunta']." "."R=".$rowFinal[4]['reactivo']. "<br>";
$message .= "6.-".$rowFinal[5]['pregunta']." "."R=".$rowFinal[5]['reactivo']. "<br>";
$message .= "7.-".$rowFinal[6]['pregunta']." "."R=".$rowFinal[6]['reactivo']. "<br>";
$message .= "8.-".$rowFinal[7]['pregunta']." "."R=".$rowFinal[7]['reactivo']. "<br>";
$message .= "9.-".$rowFinal[8]['pregunta']." "."R=".$rowFinal[8]['reactivo']. "<br>";
$message .= "10.-".$rowFinal[9]['pregunta']." "."R=".$rowFinal[9]['reactivo']. "<br>";

$actualizar= mysqli_query($con,"UPDATE participantes SET email='$correo' WHERE id=$idparticipante");


mail($to, $subject, $message, $headers);


 $nombrecompleto = $urlempresa;

$ch = curl_init(); 
//$url="https://app.rdstation.com.br/api/1.2/conversions.json?token_rdstation=42c633f98f1c2051ef6d790ace6ea5a0&identificador=integracion_crm&_is=6&c_utmz=&traffic_source=encoded_eyJmaXJzdF9zZXNzaW9uIjp7InZhbHVlIjoiKG5vbmUpIiwiZXh0cmFfcGFyYW1zIjp7fX0sImN1cnJlbnRfc2Vzc2lvbiI6eyJ2YWx1ZSI6Iihub25lKSIsImV4dHJhX3BhcmFtcyI6e319LCJjcmVhdGVkX2F0IjoxNjAxOTIyOTIxOTM1fQ%3D%3D&client_id=25e3714e-2154-4308-9721-b496d41e1780&redirect_to=&_doe=&privacy_data%5Bbrowser%5D=&email=$email&emP7yF13ld=&sh0uldN07ch4ng3=should_not_change";
    //$url="token_rdstation=9f0b06505ceb2c34b1bf7137a26c1bea&identificador=quiz-integraciones&_is=6&c_utmz=190074282.1607623332.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)&traffic_source=encoded_eyJmaXJzdF9zZXNzaW9uIjp7InZhbHVlIjoiKG5vbmUpIiwiZXh0cmFfcGFyYW1zIjp7fX0sImN1cnJlbnRfc2Vzc2lvbiI6eyJ2YWx1ZSI6Iihub25lKSIsImV4dHJhX3BhcmFtcyI6e319LCJjcmVhdGVkX2F0IjoxNjA3NjIzNDI3MjE2fQ%3D%3D&client_id=88377809-8e3c-4594-8c88-25834f5ed8b8&redirect_to=&_doe=&privacy_data%5Bbrowser%5D=&name=$nombrecompleto&email=$correo&custom_fields%5B1243996%5D=quiz-ansiedad&emP7yF13ld=&sh0uldN07ch4ng3=should_not_change";
    $url="https://app.rdstation.com.br/api/1.2/conversions.json?token_rdstation=9f0b06505ceb2c34b1bf7137a26c1bea&identificador=quiz-integraciones&_is=6&c_utmz=190074282.1607623332.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)&traffic_source=encoded_eyJmaXJzdF9zZXNzaW9uIjp7InZhbHVlIjoiKG5vbmUpIiwiZXh0cmFfcGFyYW1zIjp7fX0sImN1cnJlbnRfc2Vzc2lvbiI6eyJ2YWx1ZSI6Iihub25lKSIsImV4dHJhX3BhcmFtcyI6e319LCJjcmVhdGVkX2F0IjoxNjA3NjIzNDI3MjE2fQ%3D%3D&client_id=88377809-8e3c-4594-8c88-25834f5ed8b8&redirect_to=&_doe=&privacy_data%5Bbrowser%5D=&name=$nombrecompleto&email=$correo&custom_fields%5B1243996%5D=quiz-ansiedad&emP7yF13ld=&sh0uldN07ch4ng3=should_not_change";
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    
//  curl_setopt($ch,CURLOPT_HEADER, false); 
 
    $output=curl_exec($ch);
 $json=json_decode($output, true);	
    curl_close($ch);

															

header("Location:https://valor.psicocentrofc.com/quiz-integracion-gracias");
															
															
}

       
?>

<?php include("header.php"); ?>
    
    
    <style>
        html,
body {
  height: 100%;
}

header {
  overflow: hidden;
  padding: 50px 10px;
}
#page-content {
  flex: 1 0 auto;
}

#sticky-footer {
  flex-shrink: none;
}

.h1, h1 {
    font-size: 2.5rem;
}

.copyright{
        color: gray;
    font-size: 0.7rem;
}

.btn:hover {
  background-color: #7252bb;
  color: white;
}

.btn {
  background-color: #7252bb;
  color:white;
}

.previous {
  background-color: #7252bb;
  color: black;
}

.next {
  background-color: #7252bb;
  color: white;
}

.round {
  border-radius: 50%;
}
@media (max-width: 768px) {
  .mobile{
      position:relative;
      
  }
  .h1, h1 {
    font-size: 1.5rem !important;
}
.botonMobile{
    width: 70% !important;
    left: 15% !important;
}

.mobile2{
      display:none;
      
  }
  
  .h2, h2 {
    font-size: 1.5rem;
}
}

@media (min-width: 769px) {
  .mobile{
      display:none;
      
  }
   .escritorio{
      background-image:url('images/Back_encuesta_Psicocentro.jpg');background-repeat: no-repeat; /* Este es el codigo para el background para mobile */
    background-size: cover;
  }
  .fixed-top {
    top: 0px !important;
    right: 0;
    left: 0;
    z-index: 1030;
}

.bg-dark {
    background-color: transparent !important;
}
}
    </style>

    

    
  </head>

  <body class="d-flex flex-column text-center escritorio "  >
      <?php include("body.php"); ?>
    
   <header>
      <nav  class="navbar navbar-expand-sm navbar-dark bg-dark fixed-top">

      <div style="float:left;" class="collapse navbar-collapse" id="navbarsExampleDefault">
        
       
 <img style="position:relative;left: 43%;" class="mobile2" width="15%" src="logo.png">         
      </div>
    </nav> 
     <img class="mobile" src="logo.png">         

   </header>
    

    <main role="main"  class="container" style="position:relative;top:1%;">
        <form method="post" action="" id="paso1" >
        <section style="text-align:center;">
           <div class="col-12">
        <h1 style="color:#5f5093;">¡GENIAL!</h1>
        <h2 style="color:#5f5093;">Enviaremos tus resultados al correo que nos proporciones</h2>
      <br>
      <!---p>Para enviarte tu reporte y una guía paso a paso para <br> incrementar tus resultados 
      solo escribe tu nombre y email.</p -->
      <input  type="hidden" name="init" value="1"> 
      
     
        <input style="width: 50%;
    position: relative;
    left: 25%;background-color: #f9f9f9;" type="text" name="nombre" readonly value="<?php echo $urlempresa; ?>" class="form-control botonMobile"> 
    <br>
    <input style="width: 50%;
    position: relative;
    left: 25%;background-color: #f9f9f9;" type="email" name="email" placeholder="EMAIL" class="form-control botonMobile">
    <br>
    <div class="form-check">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="" required>
    Me gustaría recibir mis resultados e información relacionada a mi correo electrónico. 
    
  </label>
</div>     
     
      
      
      </div> 
            
        </section>
        <br>
        <section style="position:relative;top:20%;">
<button class="btn btn-lg" style="width: 50%;" type="submit">Enviar</button>


        </section>
</form> 
  

    </main><!-- /.container -->
    <br>
    <footer class="mastfoot mt-auto">
    <div class="inner">
      <p class="copyright">© 2020 PsicoCentro® Todos los derechos reservados.</p>
    </div>
  </footer>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

<script>
$(document).ready(function(){
  //window.setTimeout(function() {
  //  window.location.href = 'https://sistemex.com/quiz';
//}, 5000);
  });
</script>



  </body>
</html>
