<?php
   
       $error = $_GET['error'];
       
       $payment_id = $_GET['payment_id']; 
        $bd = str_replace('_', ' ', $_GET['bd']);
        $id_cliente = "0";
        $id_servicio = str_replace('_', ' ', $_GET['plan']);
        $plan = str_replace('_', ' ', $_GET['plan']);
        $importe = str_replace('_', ' ', $_GET['importe']);
        $nombre = str_replace('_', ' ', $_GET['nombre']);
        $apellido = str_replace('_', ' ', $_GET['apellido']);
        $fechaN = str_replace('_', ' ', $_GET['fechaN']);
        $email = str_replace('_', ' ', $_GET['email']);
        $tel = str_replace('_', ' ', $_GET['telefono']);
        $domi = str_replace('_', ' ', $_GET['domi']);
        $col = str_replace('_', ' ', $_GET['colonia']);
        $cp = str_replace('_', ' ', $_GET['cp']);
        $genero = str_replace('_', ' ', $_GET['genero']);
        $fechaR = str_replace('_', ' ', $_GET['fechaR']);
        $sucursal = str_replace('_', ' ', $_GET['sucursal']);
        $qr = str_replace('_', ' ', $_GET['qr']);
        $msg;
        
        $bdC = "direct18_".$bd;
        
        $conn = new mysqli("directoriofitness.com.mx","direct18","L4LL4v3M@3str@","direct18_".$bd);
        
        $id_insert;
                $query_socio = "INSERT INTO socio_servicio(idServicio,idSocio,idSocioTitular,FechaSolicitud,FechaInscripcion) 
                VALUES('$id_servicio','$id_cliente','$id_cliente',CURDATE(),CURDATE())";
                
                if($conn->query($query_socio) === TRUE){
                    $q_select = "SELECT MAX(idSocio_Servicio) AS idInsert FROM socio_servicio WHERE idSocioTitular = '$id_cliente'";
    
                    $result = $conn->query($q_select);
    
                    $row = $result->fetch_assoc();
    
                    $id_insert = $row['idInsert'];
                    
                    $fecha_vencimiento = "DATE_ADD( '$fechaR', INTERVAL 1 DAY)";
                    
                    $query_pagos ="INSERT INTO pagos (idSocio_Servicio,Concepto,FechaPago,Importe,idUsuario,Pago,Descuento,Subtotal,
                    FechaInicio,Forma1,Importe1,Forma2,Importe2,idSucursal,Visible,FechaFin,Cancelado) 
                    VALUES ($id_insert,'00',NOW(),$importe,2,2,0.00,$importe,CURDATE(),'MP',0.00,'MP',0.00,$sucursal,0,$fecha_vencimiento,0)";
                    
                    
                    //$conn->insert_query($query_pagos,"directoriofitness.com.mx","direct18","L4LL4v3M@3str@",$bd);
                    
                    if($conn->query($query_pagos) === TRUE){
                        $query = "INSERT INTO prospectos (nombre_prospecto,apll_prospecto,fecha_nacimiento,genero,correo_prospecto,telefono_prospecto,
                        domicilio_prospecto,colonia_prospecto,cp_prospecto,notas_prospecto,fecha_registro,estatus_prospecto,qr) 
                        VALUES ('$nombre','$apellido','$fechaN',$genero,'$email','$tel',
                        '$domi','$col','$cp','visita',NOW(),6,'$qr')";
                        
                        $conn->query($query);
                        if($conn->query($query) === TRUE){
                            $msg = 'Pago Exitoso';
                        }else{
                            $msg ='Error al guardar tu pago, checa en la administracion <br> ID Pago: '.$conn->error."<br>".$query;
                        }
                    }else{
                        $msg ='Error al guardar tu pago, checa en la administracion <br> ID Pago: '.$conn->error."<br>".$query_pagos;
                    }
                
                }else{
                    $msg ='Error al guardar tu pago, checa en la administracion <br> ID Pago: '.$conn->error."<br>".$query_socio;
                }
        
        $conn->close();
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>

  <title>Mercado Pago</title>
</head>
<style>
    .padre {

    padding: 0 1rem;
    margin: 1rem;
    }

    .hijo {
        /* IMPORTANTE */
        width: 200px;
        margin-left: auto;
        margin-right: auto;
    }
    .recibo{
        border-style: ridge;
    }

    </style>
<body>
  <nav class="navbar navbar-dark bg-primary">
    <a class="navbar-brand" href="#" style="margin-left: 15px;">ProgymCloud</a>
  </nav>
  <div class="container">
    <div class="padre">
      <p class="hijo" style="text-align: center;">
        <img src="https://i.pinimg.com/originals/71/81/e8/7181e84d50cb87fa4ab9a5a8ab613dbe.jpg" alt="PayPal-Logo" width="130px">
      </p>
      <p class="hijo" style="text-align: center; color: #00E013; font-size: 70px;">
      <i class="fas fa-check-circle"></i>
      <h3 class="hijo" style="text-align: center;"><?= $msg ?></h3>
      </p>
      
    </div>
  </div>

</body>
</html>