<?php
require ('header.php');
include ('pagination/pagination.php');
if (isset($_GET['id']))
{
	$url=addslashes($_GET['url']);
	$id=addslashes($_GET['id']);
	if(!is_numeric($id))
	{
		header('Location: ./');
		?>
		<script type="text/javascript">document.location.href="./";</script>
        <?php
        exit();
	}
	$sql = 'SELECT * FROM type WHERE id_type="'.$id.'"';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$title=stripslashes($data['lib_type']);
	if($data[0]==NULL)
	{
		header('Location: ./');
		?>
		<script type="text/javascript">document.location.href="./"</script>
        <?php
        exit();
	}
	if($url!=$data['url_type'])
	{
		header('Location: '.$id.'-'.$data['url_type']);
		?>
		<script type="text/javascript">document.location.href="<?php echo $id.'-'.$data['url_type']; ?>"</script>
        <?php
        exit();
	}
	$active=$url;
    require ('call.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cabinet Acropole - <?= $title; ?></title>
</head>
<body>
	<?php include('tete.php'); ?>
    <div class="full-width-content">
    	<div class="container">
    		<div class="row" id="raquo">
            	<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                    <a href="./">Accueil</a> <i class="fa fa-chevron-circle-right"></i>
                    <?php echo $title ?>
                </div>
                <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12" align="right">
    				<?php
    				$sql2= 'SELECT COUNT(*) FROM information WHERE id_type='.$id.' AND visible_information="oui"';
                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                    $data2=$reponse2->fetch();
                    $total=$data2[0];
                    $nbPages = ceil($total/$epp); // calcul du nombre de pages $nbPages (on arrondit à l'entier supérieur avec la fonction ceil())
                    // Récupération du numéro de la page courante depuis l'URL avec la méthode GET
                    // S'il s'agit d'un nombre on traite, sinon on garde la valeur par défaut : 1
                    $current = 1;
                    if (isset($_GET['p']) && is_numeric($_GET['p'])) {
                        $pagin = intval($_GET['p']);
                        if ($pagin >= 1 && $id <= $nbPages) {
                            // cas normal
                            $current=$pagin;
                        } else if ($pagin < 1) {
                            // cas où le numéro de page est inférieure 1 : on affecte 1 à la page courante
                            $current=1;
                        } else {
                            //cas où le numéro de page est supérieur au nombre total de pages : on affecte le numéro de la dernière page à la page courante
                            $current = $nbPages;
                        }
                    }
                    // $start est la valeur de départ du LIMIT dans notre requête SQL (dépend de la page courante)
                    $start = ($current * $epp - $epp);
                    $i=$start;
        
                    echo $total;
                    if($total>1)
                    {
                        echo ' informations';
                    }
                    else
                    {
                        echo ' information';
                    }
                    echo ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Page '.$current.'/'.$nbPages; 
                    ?>
                </div>
            </div>
        </div>
    </div>
	<?php
    switch($id)
	{
        case 4:
        case 6:
        ?>
        <div class="latest" id="latest">
            <div class="container">
                <h3 class="heading"><?= $title; ?></h3>
                <div class="news_grids">
                    <?php
                    $sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$id.' ORDER BY rang_information ASC, 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'];
                        $sql2='SELECT * FROM image WHERE id_information='.$data[0].' AND defaut_image=1';
                        $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                        $data2=$reponse2->fetch();
                        if($data2[0]==NULL)
                        {
                            $sql2='SELECT * FROM image WHERE id_information='.$data[0];
                            $reponse2=$bdd->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                            $data2=$reponse2->fetch();
                        }
                        ?>
                        <div class="col-md-4">
                            <div class="news_grid1" style="background: url(upload/<?= stripslashes($data2['lib_image']); ?>) no-repeat 0px 0px;">
                                <div class="news_grid_info">
                                    <!-- <p class="date"><?php //strftime("%d %B %Y", strtotime($data['date_information'])); ?></p> -->
                                    <h3>
                                        <a href="<?= $url_type.'/'.$data['url_information'].'-'.$data[0]; ?>">
                                            <?= stripslashes($data['lib_information']); ?>
                                        </a>
                                    </h3>
                                    <p>
                                        <?php
                                        $descrip=strip_tags($data['descrip_information']);
                                        for($z=0; $z<=(strlen($descrip)-1); $z++)
                                        {
                                            echo $descrip[$z];
                                            if($z>=50 and $descrip[$z]==' ')
                                            {
                                                break;
                                            }
                                        }
                                        if(strlen($descrip)>50)
                                        {
                                            echo '...';
                                        }
                                        ?>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
                </div>
            </div>
        </div>
        <?php
        break;
        case 5:
        ?>
        <div class="services" id="services">
            <div class="container">
                <h2 class="heading"><?= $title; ?></h2>
                <div class="service-grids">
                    <div class="col-md-4 service_left_grid">
                        <img src="images/service-left.jpg" alt="" />
                    </div>
                    <div class="col-md-8 service_right_grid">
                        <?php
                        $sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$id.' ORDER BY rang_information ASC, 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-6">
                                <div class="innergrid1 picture margin">
                                    <span class="fa <?= stripslashes($data['fa_information']); ?>" aria-hidden="true"></span>
                                    <h3><?= stripslashes($data['lib_information']); ?></h3>
                                    <p>
                                        <?php
                                        $descrip=strip_tags($data['descrip_information']);
                                        for($z=0; $z<=(strlen($descrip)-1); $z++)
                                        {
                                            echo $descrip[$z];
                                            if($z>=105 and $descrip[$z]==' ')
                                            {
                                                break;
                                            }
                                        }
                                        if(strlen($descrip)>105)
                                        {
                                            echo '...';
                                        }
                                        ?>
                                    </p>
                                </div>
                            </div>
                            <?php
                        }
                        ?>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <?php
        break;
        case 7:
        ?>
        <div class="testimonals">
            <div class="container">
                <h3 class="heading"><?= $title; ?></h3>
                    <div class="section_1its-feedback-grids">
                        <div id="owl-demo" class="owl-carousel owl-theme">
                            <?php
                            $sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND visible_information="oui" AND type.id_type='.$id.' ORDER BY rang_information ASC, 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'];
                                $sql2='SELECT * FROM image WHERE id_information='.$data[0].' AND defaut_image=1';
                                $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                $data2=$reponse2->fetch();
                                if($data2[0]==NULL)
                                {
                                  $sql2='SELECT * FROM image WHERE id_information='.$data[0];
                                  $reponse2=$bdd->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                  $data2=$reponse2->fetch();
                                }
                                ?>
                                <div class="item">
                                    <div class="testimonal grid-1">
                                        <div class="first-grid">
                                            <?php
                                            if(!empty($data['lien_information']))
                                            {
                                                ?>
                                                <a href="<?= stripslashes($data['lien_information']); ?>" target="_blank">
                                                <?php
                                            }
                                            ?>
                                            <img src="upload/<?= $data2['lib_image']; ?>">
                                            <?php
                                            if(!empty($data['lien_information']))
                                            {
                                                ?>
                                                </a>
                                                <?php
                                            }
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        break;
        case 10:
        ?>
        <section class="fw-main-row "  >
            <div class="fw-container">
                <div class="fw-row">
                    <div class="fw-col-xs-12">
                        <div class="row">
                            <div class="in_blog_wrapper">
                                <div class="section_heading">
                                    <h2><?= $title; ?></h2>
                                </div>
                                <?php
                                $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 DESC LIMIT 6';
                                $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                                while($data=$reponse->fetch())
                                {
                                    $url_type=$data['url_type'];
                                    $sql2='SELECT * FROM image WHERE id_information='.$data[0].' AND defaut_image=1';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    $data2=$reponse2->fetch();
                                    if($data2[0]==NULL)
                                    {
                                      $sql2='SELECT * FROM image WHERE id_information='.$data[0];
                                      $reponse2=$bdd->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                      $data2=$reponse2->fetch();
                                    }
                                    ?>
                                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                                        <div class="in_blog_section">
                                            <div class="in_blog_img">
                                                <a href="<?= $url_type.'/'.$data['url_information'].'-'.$data[0]; ?>"><img src="img/1.png" alt="" class="img-responsive"></a> 
                                            </div>
                                            <div class="in_blog_content">
                                                <h4><a href="#"><?= stripslashes($data['lib_information']); ?></a></h4>
                                                <ul>
                                                    <li><i class="fa fa-calendar"></i><?= ($data['creation_information']); ?></li>
                                                </ul> 
                                                <p>
                                                    <?php 
                                                    $descrip=strip_tags($data['descrip_information']);
                                                    for($z=0; $z<=(strlen($descrip)-1); $z++)
                                                    {
                                                        echo $descrip[$z];
                                                        if($z>=50 and $descrip[$z]==' ')
                                                        {
                                                            break;
                                                        }
                                                    }
                                                    if(strlen($descrip)>50)
                                                    {
                                                        echo '...';
                                                    }
                                                    ?>
                                                </p>
                                                <a href="<?= $url_type.'/'.$data['url_information'].'-'.$data[0]; ?>" class="gs_read_m">Lire la suite</a>
                                            </div>    
                                        </div>
                                    </div>
                                    <?php
                                }
                                ?>
                            </div>   
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <?php
        break;
	}
	?>
    <?php include('footer.php'); ?>
</body>
</html>
<?php 
}
else
{
	header('Location: ./');
	?>
	<script type="text/javascript">document.location.href="./"</script>
    <?php
    exit();
}
?>