<?php
require ('header.php');
if (isset($_GET['id']))
{
	$fixe=addslashes($_GET['fixe']);
	$page=addslashes($_GET['id']);
	$url=addslashes($_GET['url']);
	
	$sql = 'SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND id_information='.$page.'';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$title=stripslashes($data['lib_information']);
	
	if($data[0]==NULL)
	{
		header('Location: ./');
	}
	if($url!=$data['url_information'])
	{
		header('Location: '.$data['url_type'].'/'.$data['url_information'].'-'.$page);
	}
	
	if(!isset($_COOKIE['expiration'.$page]))
	{
		setcookie('expiration'.$page, 'oui', time()+4*60);
		$req='UPDATE information SET vue_information="'.($data['vue_information']+1).'" WHERE id_information='.$page.' AND visible_information="oui"';
		$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
		//echo 'vue agmentée';
	}
	$active=$data['url_type'];


	if (isset($_POST['valider']))
    {
        $nom=addslashes($_POST['nom']);
        $tel=(addslashes($_POST['tel']));
        $mail=(addslashes($_POST['mail']));
        $msg=(addslashes($_POST['msg']));
        $dat_contact=date('Y-m-d H:i:s');

        if (empty($nom))
        {
            $lemessage = '<div class="alert alert-danger">
                <strong>Erreur!</strong> Veuillez renseigner votre nom et prénoms
            </div>';
        }
        elseif (empty($mail))
        {
            $lemessage = '<div class="alert alert-danger">
                <strong>Erreur!</strong> Veuillez renseigner votre email
            </div>';
        }
        elseif (empty($msg))
        {
            $lemessage = '<div class="alert alert-danger">
                <strong>Erreur!</strong> Veuillez renseigner votre message
            </div>';
        }
        elseif (!filter_var($mail, FILTER_VALIDATE_EMAIL))
        {
            $lemessage = '<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.'","'.$dat_contact.'", '.$page.')';
            $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());
            }
            
                $message.='<body>
                    <div align="center">
                        <div class="panel panel-success">
                            <div class="panel-heading" id="connectez-vous">
                                Message visiteur : '.stripslashes($nom).' sur '.$title.'
                            </div>
                            <div class="panel-body" align="left">
                                <div align="center"><img src="http://'.$_SERVER['SERVER_NAME'].'/img/logo.png" width="200"></div>
                                <table width="100%" align="center">
                                    <tr><td align="right">Nom:</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 align="right">Date:</td><td><strong>'.date("d M Y à H:i", strtotime($dat_contact)).' GMT</strong></td></tr>
                                    <tr><td colspan="2" align="right"><a href="http://'.$_SERVER['SERVER_NAME'].'/celestadmin/afficher-table.php?W9mvyDvFWE5=Bien&QYtgoGbhhd='.$page.'">Plus de détails</a></td></tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </body>
            </html>';
            //mail("mordekhai.ngoran@gmail.com", "Un visiteur a reservé sur ".$_SERVER['SERVER_NAME']."", $message, $header);
            //mail("info@sie-technology.com", "Un visiteur a reservé sur ".$_SERVER['SERVER_NAME']."", $message, $header);
            $lemessage = '<div class="alert alert-success">
                Votre réservation a été prise en compte<br>L\'équipe de Cabinet Acropole vous contactera sous peu !!
            </div>';
            //header('Location: membre.php');
            ?> 
            <script type="text/javascript">window.setTimeout("location=('<?= $data['url_type'].'/'.$data['url_information'].'-'.$page; ?>');",15000);</script>
            <?php
        }
    }
	require ('call.php');
?>
<title>Cabinet Acropole - <?= $title; ?></title>
</head>
<body>
	<?php
	include('tete.php');
	if($fixe!=$data['url_type'])
	{
		?>
        <script type="text/javascript">document.location.href="<?= $data['url_type'].'/'.$data['url_information'].'-'.$page; ?>"</script>
        <?php
		exit();
	}
	?>
	<div class="welcome" id="welcome">
	    <div class="container">
	        <div class="section_heading">
				<h2 class="heading"><?= $title; ?></h2>
				<?php
				if($data['id_type'] == 4)
				{
					if (isset($_POST['valider']))
					{
					    ?>
					    <script type="text/javascript">
					        $(document).ready(function(){
					            $("#myModal").modal('show');
					        });
					    </script>
					    <?php
					}
					?>
					<div style="float: right;">
						<a data-toggle="modal" data-target="#myModal" href="#" class="btn btn-lg btn-success">
                            <i class="fa fa-trash-o" style="color: #fff;"></i> Commandez ce service
                        </a>
                    </div>
                    <div class="modal ab fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog sign" role="document">
                            <div class="modal-content about">
                                <div class="modal-header one">
                                    <button type="button" class="close sg" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
                                    <div class="discount one">
                                        <h3>Reservez ce service maintenant</h3>
                                    </div>
                                </div>
                                <div class="modal-body about">
                                    <div class="login-top sign-top one">
                                    	<?php if(isset($lemessage)) echo $lemessage; ?>
                                        <form role="form" method="post" action="">
			                                <div class="row">
			                                    <div class="col-lg-12" id="bas_contact">
			                                    <input placeholder="Nom & Prénoms *" class="form-control" type="text" name="nom" value="<?php if (isset($_POST['valider']) ){echo $_POST['nom'];} ?>"></div>
			                                    <div class="col-lg-12" id="bas_contact">
			                                    <input placeholder="N° Téléphone" class="form-control" type="text" name="tel" value="<?php if (isset($_POST['valider']) ){echo $_POST['tel'];} ?>"></div>
			                                    <div class="col-lg-12" id="bas_contact">
			                                    <input placeholder="E-mail *" class="form-control" type="text" name="mail" value="<?php if (isset($_POST['valider']) ){echo $_POST['mail'];} ?>"></div>
			                                    <div class="col-lg-12" id="bas_contact">
			                                        <textarea placeholder="Votre message *" style="height:150px;" class="form-control" name="msg"><?php if (isset($_POST['valider']) ){echo $_POST['msg'];} ?></textarea>
			                                    </div><br>
			                                    <div class="col-lg-12" id="bas_contact">
			                                        <input type="submit" name="valider" value="Envoyer" class="btn btn-primary btn-lg">
			                                    </div>
			                                </div>
			                            </form>
                                        <button class="btn btn-lg btn-default" type="button" class="close sg" data-dismiss="modal" aria-label="Close">Non</button> 
                                    </div>
                                 </div>
                            </div>
                        </div>
                    </div>
					<?php
				}
				?>
			</div>
	        <div class="skill-grids">
	            <div class="row">
		        	<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
			            <?php
						$sql2='SELECT COUNT(*) FROM image WHERE id_information="'.$page.'"';
						$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
						$data2=$reponse2->fetch();
						$nbr_image=$data2[0];
						
						$sql2='SELECT COUNT(*) FROM video WHERE id_information="'.$page.'"';
						$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
						$data2=$reponse2->fetch();
						$nbr_video=$data2[0];
						
						$sql2='SELECT * FROM image WHERE id_information="'.$page.'"';
						$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
						$data2=$reponse2->fetch();

						$sql3='SELECT * FROM fichier WHERE id_information='.$page;
		                $reponse3=$bdd-> query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
		                $data3=$reponse3->fetch();
		                if(!empty($data3[0]))
		                {
		                    include('audio.php');
		                }
						if($nbr_video==0)
						{
							if($nbr_image==1)
							{
								echo $limg='
								<p align="center"><img src="upload/'.$data2['lib_image'].'" class="img-responsive img-thumbnail"/></p>';
							}
						}
			            if($nbr_video!=0)
			            {
							$sql2='SELECT * FROM video WHERE id_information="'.$page.'"';
			                $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
			                $data2=$reponse2->fetch();

			                if(substr($data2['lib_video'], 0, 19) == 'https://www.youtube')
		                    {
		                        ?>
		                        <iframe width="100%" height="400" src="<?php echo $data2['lib_video']; ?>" frameborder="0" allowfullscreen></iframe>
		                        <?php
		                    }
		                    else
		                    {
		                    	echo '<div class="fb-video" data-href="'.$data2['lib_video'].'" data-width="500" data-show-text="false"><blockquote cite="'.$data2['lib_video'].'" class="fb-xfbml-parse-ignore"><a href="'.$data2['lib_video'].'"></p>Publié par <a href="https://www.facebook.com/GroupeManeky/">Maneky Groupe</a></blockquote></div>';
		                    }
			            }
			            if($nbr_image>1)
			            {
			                //include('gallery.php');
			                ?>
			                <div class="w3ls_gallery_grids">
								<?php
								$numtype = 6;
								$sql='SELECT * FROM information, type, image WHERE image.id_information = information.id_information AND type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$numtype.' ORDER BY rang_information ASC, information.id_information DESC';
								$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
								while($data=$reponse->fetch())
								{
									$url_type=$data['url_type'];
									?>
									<div class="col-md-3 w3_section_1_gallery_grid">
										<div class="section_1_gallery_grid">
											<a title="<?= stripslashes($data['lib_information']); ?>" href="upload/<?= stripslashes($data['lib_image']); ?>">
												<div class="section_1_gallery_grid1">
													<img src="upload/<?= stripslashes($data['lib_image']); ?>" alt=" " class="img-responsive" />
													<div class="w3layouts_gallery_grid1_pos"></div>
												</div>
											</a>
										</div>
									</div>
									<?php
								}
								?>
								<div class="clearfix"></div>
							</div>
			                <?php
			            }
			            ?>
			        </div>
			        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
		        		<p align="justify"><?= $data['descrip_information']; ?></p>
		        	</div>
		        </div>
		    </div>
        </div>
	</div>
    <?php include('footer.php'); ?>
</body>
</html>
<?php 
}
else
{
	header('Location: ../');
	?>
	<script type="text/javascript">document.location.href="../"</script>
    <?php
    exit();
}
?>