<?php
session_start();
include('db.php');

$ok=$db->prepare('INSERT INTO paiement(formation, user) VALUES(?,?)');
$ok->execute(array($_SESSION['formation_id'], $_SESSION['user_id']));

if($_SESSION['code_parrain']<>"vision million"){
    /*$nup=$db->prepare('SELECT pourcentage FROM param WHERE id=?');
    $nup->execute(array(1));
    while($nups=$nup->fetch()){
        $pourcentage=$nups['pourcentage'];
    }*/
    
    $col=$db->prepare('SELECT * FROM user WHERE code_perso=?');
    $col->execute(array($_SESSION['code_parrain']));
    while($cols=$col->fetch()){
        if($cols['strategieAcheter']==1){
            $mnt=6000;
        } elseif($cols['strategieAcheter']==0){
            $mnt=4000;
        }
        $bon=$db->prepare('INSERT INTO comission_parrainnage(beneficiaire,filleul,mnt,dat) VALUES(?,?,?,?)');
        $bon->execute(array($cols['id'], $_SESSION['user_id'], $mnt, date('Y-m-d')));
        if($bon){
            $wao=$db->prepare('UPDATE user SET solde=solde+? WHERE id=?');
            $wao->execute(array($mnt, $cols['id']));
            
        }
    }
    
}

if($_SESSION['mPay']=="fedapay"){
    $vw=$db->prepare('UPDATE user SET strategieAcheter=? WHERE id=?');
    $vw->execute(array(1, $_SESSION['user_id']));
}


?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Vision million</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script>
    <style>
        .btn-feda{
            color: #ffffff;
            background-color: #65214D;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-sm-4"></div>
            <div class="col-sm-4"><br><br><br>
                <div class="card">
                    <div class="card-body">
                        <div class="card-title">
                            
                            <center>
                              <i class="fa fa-check"></i>
                                <h5>Paiement effectué, cliquez sur <i class="fa fa-close"></i> pour retourner dans l'application</h5>
                                
                            </center>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-4"></div>
        </div>
    </div>

</body>
</html>