<?php
include ('header.php');
include ('call.php');
$active='contact';
?>
<meta charset="utf-8">
<title>Génération dorée - Contact</title>
</head>
<body>
<?php require('tete.php'); ?>
<!-- contact -->
<div class="latest" id="contact">
    <div class="container">
        <h2 class="heading"> Nous <span>Contacter</span> </h2>
    </div>
        
    <div class="section_1-contact-form">
        <div class="col-md-6 contact-form-left">
            <div class="contact-info">
                <div class="contact-form-top">
                    <h3>Nos Contacts</h3>
                </div>
                <?php
                $numtype = 2;
                $i=0;
                $sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$numtype.' ORDER BY rang_information ASC, id_information ASC';
                $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                while($data=$reponse->fetch())
                {
                    ?>
                    <p><i class="fa <?= $data['fa_information']; ?>"></i> <?= stripslashes($data['lib_information']); ?></p>
                    <?php
                }
                ?>
                <div class="contact-form-top" style="margin-top: 30px;">
                    <h3>Suivez nous sur</h3>
                </div>
                <?php
                $numtype = 3;
                $sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$numtype.' ORDER BY rang_information ASC, id_information ASC';
                $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                while($data=$reponse->fetch())
                {
                    $url_type=$data['url_type'];
                    if($data['lien_information']!='')
                    {
                        echo '<a title="'.stripslashes($data['lib_information']).'" href="'.stripslashes($data['lien_information']).'" target="_blank" style="text-decoration:none;">';
                    }
                    echo ' <i class="fa fa-3x '.stripslashes($data['fa_information']).'"></i> &nbsp; &nbsp; &nbsp;';
                    if($data['lien_information']!='')
                    {
                        echo '</a>';
                    }
                }
                ?>
            </div>
        </div>
        <div class="col-md-6 contact-form-right">
            <div class="contact-form-top">
                <h3>Notre localisation</h3>
            </div>
            <div class="map">
                <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d387142.84010033106!2d-74.25819252532891!3d40.70583163828471!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89c24fa5d33f083b%3A0xc80b8f06e177fe62!2sNew+York%2C+NY%2C+USA!5e0!3m2!1sen!2sin!4v1475140387172" style="border:0"></iframe>
            </div>
        </div>
        <div class="clearfix"> </div>
    </div>
    <div class="contact-form" id="le-contact">
        <div class="container">
            <div class="contact-form-top">
                <h3>Envoyer un email</h3>
            </div>
            <div class="section_1its_section_1_about_mail">
                <?php
                if (isset($_POST['valider']))
                {
                    $nom=addslashes($_POST['nom']);
                    //$sujet=(addslashes($_POST['sujet']));
                    $tel=(addslashes($_POST['tel']));
                    $mail=(addslashes($_POST['mail']));
                    $msg=(addslashes($_POST['msg']));
                    $dat_contact=date('Y-m-d H:i:s');

                    if (empty($nom))
                    {
                        echo '
                        <div class="alert alert-danger">
                            <strong>Erreur!</strong> Veuillez renseigner votre nom et prénoms
                        </div>';
                    }
                    /*elseif (empty($sujet))
                    {
                        echo '
                        <div class="alert alert-danger">
                            <strong>Erreur!</strong> Veuillez renseigner l\'objet
                        </div>';
                    }*/
                    elseif (empty($mail))
                    {
                        echo '
                        <div class="alert alert-danger">
                            <strong>Erreur!</strong> Veuillez renseigner votre email
                        </div>';
                    }
                    elseif (empty($msg))
                    {
                        echo '
                        <div class="alert alert-danger">
                            <strong>Erreur!</strong> Veuillez renseigner votre message
                        </div>';
                    }
                    elseif (!filter_var($mail, FILTER_VALIDATE_EMAIL))
                    {
                        echo '
                        <div class="alert alert-danger">
                            <strong>Erreur!</strong> Votre E-mail n\'est pas valide
                        </div>';
                    }
                    else
                    {
                        $req='INSERT INTO contact VALUES (NULL,"'.$nom.'","'.$mail.'","'.$tel.'","","'.$msg.'","'.$dat_contact.'", NULL)';
                        $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                        
                        $sql9= 'SELECT count(*) FROM newsletter WHERE lib_newsletter="'.$mail.'"';
                        $reponse9=$bdd-> query($sql9) or die('Erreur SQL !<br />'.$sql9.'<br />'.mysql_error());
                        $data9=$reponse9->fetch();
                        $nbr_mail=$data9[0];
                        
                        if($nbr_mail==0)
                        {
                            $req='INSERT INTO newsletter VALUES (NULL, "'.$mail.'", "'.$dat_contact.'")';
                            $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                        }
                        
                        $sql9= 'SELECT MAX(id_contact) FROM contact';
                        $reponse9=$bdd-> query($sql9) or die('Erreur SQL !<br />'.$sql9.'<br />'.mysql_error());
                        $data9=$reponse9->fetch();
                        $message='<body style="padding: 0; margin: 0;">
                            <div style="background: #f1f1f1; padding: 0px 0px 0px 0px;">
                                <div style="background: #fb6f0b; font-size: 22px; text-align: center; color: #fff; margin: 0 auto; padding: 5px 20px;">
                                    Message visiteur : '.stripslashes($nom).'
                                </div>
                                <div style="padding: 15px; border: 1px solid #ccc;">
                                    <div align="center">
                                        <a href="http://'.$_SERVER['SERVER_NAME'].'">
                                            <img src="http://'.$_SERVER['SERVER_NAME'].'/img/logo.png" width="200">
                                        </a>
                                    </div>
                                    <table width="100%" align="center">
                                        <tr><td align="right">Nom & Prénoms:</td><td><strong>'.stripslashes($nom).'</strong></td></tr>
                                        <tr><td align="right">E-mail:</td><td><strong>'.$mail.'</strong></td></tr>
                                        <tr><td align="right">N° téléphone:</td><td><strong>'.$tel.'</strong></td></tr>
                                        <tr><td colspan="2" align="center">'.stripslashes($msg).'</td></tr>
                                        <tr><td colspan="2" align="right"><a href="http://'.$_SERVER['SERVER_NAME'].'/celestadmin/afficher-info.php?W9mvyDvFWE5=contact&QYtgoGbhhd='.$data9[0].'">Plus de détails</a></td></tr>
                                    </table>
                                </div>
                            </div>
                        </body>';
                        //mail("mordekhai.ngoran@gmail.com", "Un visiteur vous a contacté sur '.$_SERVER['SERVER_NAME'].'", $message, $header);
                        echo '
                        <div class="alert alert-success">
                            Votre message a bien été envoyé
                        </div>';
                        //header('Location: membre.php');
                        ?> 
                        <script type="text/javascript">//window.setTimeout("location=('contact');",10000);</script>
                        <?php
                    }
                }
                ?>
                <form action="contact#le-contact" method="post">
                    <div class="section_1its_section_1_about_mail_left">
                        <input type="text" name="nom" placeholder="Votre nom *" required="">
                        <input type="email" name="mail" placeholder="Votre email *" required="">
                        <input type="text" name="tel" class="last" placeholder="Votre Téléphone *" required="">
                        <div class="clearfix"> </div>
                    </div>
                    <textarea name="msg" placeholder="Votre Message... *" required=""></textarea>
                    <div class="submit">
                        <input type="submit" name="valider" value="Envoyer">
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- //contact -->
<?php require('footer.php'); ?>
</body>
</html>