<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: administration.php');
}
$active='membre';
include('tete.php');
?>
<link rel="stylesheet" type="text/css" href="style/style_admin.css" />
</head>
<body>
    <div id="wrapper">
    	<?php
        include('menu_admin.php');
		if($developpeur==3)
		{
			header('Location: administration.php');
		}
		?>
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="administration">
                    <div id="titro_admin">
                    	Inscription
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                        <div class="panel panel-success">
                            <div class="panel-heading" id="connectez-vous">
                                Inscription par pseudo
                            </div>
                            <div class="panel-body">
                                <?php
                                if (isset($_POST['valider']))
                                {
                                    $pseudo=addslashes(($_POST['pseudo']));
                                    $date_mise=date('Y-m-d H:i:s');
                                    $sql = 'SELECT *, COUNT(*) FROM membre WHERE pseudo_membre="'.$pseudo.'"';
                                    $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                                    $data =$reponse->fetch();
                                    $nbr_pseudo=$data[0];
									
									$sql2= 'SELECT COUNT(*) FROM membre WHERE id_parain="'.$data[0].'"';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    $data2=$reponse2->fetch();
                                    $nbr_filleul=$data2[0];
									
                                    if (empty($pseudo))
                                    {
                                        echo '
                                        <div class="alert alert-danger">
                                            <strong>Erreur!</strong> Veuillez renseigner le pseudo
                                        </div>';
                                    }
                                    elseif($nbr_pseudo==0)
                                    {
                                        echo '
                                        <div class="alert alert-danger">
                                            <strong>Erreur!</strong> Pseudo saisi n\'est pas disponible
                                        </div>';
                                    }
									elseif($nbr_filleul>=5)
                                    {
                                        echo '
                                        <div class="alert alert-danger">
                                            <strong>Erreur!</strong> Nombre de filleul atteint <span id="span">'.$nbr_filleul.'</span>
                                        </div>';
                                    }
                                    else
                                    {
                                        ?> 
                                        <script type="text/javascript">document.location.href="ajouter-info.php?W9mvyDvFWE5=membre&id=<?php echo $data['id_membre']; ?>";</script>
                                        <?php
                                    }
                                }
                                ?>
                                <form role="form" method="post" action="" enctype="multipart/form-data">
                                    Pseudo du parrain *
                                    <input placeholder="" class="form-control" type="text" name="pseudo" value="<?php if (isset($_POST['valider']) ){echo $_POST['pseudo'];} ?>">
                                    <input type="submit" name="valider" value="VALIDER" class="btn btn-primary btn-lg btn-block" style="margin-top:10px;">
                                </form>
                            </div>
                        </div>
                    </div>
                    
                    
                    
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                        <div class="panel panel-success">
                            <div class="panel-heading" id="connectez-vous">
                                Inscription par Matricule
                            </div>
                            <div class="panel-body">
                                <?php
                                if (isset($_POST['valider2']))
                                {
                                    $matricule=addslashes(($_POST['matricule']));
                                    $date_mise=date('Y-m-d H:i:s');
                                    $sql = 'SELECT *, COUNT(*) FROM membre WHERE matricule_membre="'.$matricule.'"';
                                    $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                                    $data =$reponse->fetch();
                                    $nbr_matricule=$data[0];
                                    if (empty($matricule))
                                    {
                                        echo '
                                        <div class="alert alert-danger">
                                            <strong>Erreur!</strong> Veuillez renseigner le matricule
                                        </div>';
                                    }
                                    elseif($nbr_matricule==0)
                                    {
                                        echo '
                                        <div class="alert alert-danger">
                                            <strong>Erreur!</strong> Matricule saisi n\'est pas disponible
                                        </div>';
                                    }
                                    else
                                    {
                                        ?> 
                                        <script type="text/javascript">document.location.href="ajouter-info.php?W9mvyDvFWE5=membre&id=<?php echo $data['id_membre']; ?>";</script>
                                        <?php
                                    }
                                }
                                ?>
                                <form role="form" method="post" action="" enctype="multipart/form-data">
                                    Matricule du parrain *
                                    <input placeholder="" class="form-control" type="text" name="matricule" value="<?php if (isset($_POST['valider2']) ){echo $_POST['matricule'];} ?>">
                                    <input type="submit" name="valider2" value="VALIDER" class="btn btn-primary btn-lg btn-block" style="margin-top:10px;">
                                </form>
                            </div>
                        </div>
                    </div>





                </div>
            </div>
        </div>
    </div>
</body>
</html>