

<!-- Content -->
<div class="container">
    <div class="row none-padding" id="content">
        <div class="" id="agenda"> <!-- Zone agenda -->
            <div class="row">
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <p class=""><img src="<?php bloginfo('template_url'); ?>/img/motif-graphique-1.png" class="img-motif" alt="">En ce moment</p>
                </div>
            </div>
            <div class="row">
                <?php
                /*                 * * Charge le client API Apidae ** */
                include __DIR__ . "/inc//vendor/autoload.php";

                $client = new \Sitra\ApiClient\Client([
                    'apiKey' => APIDAE_KEY,
                    'projectId' => APIDAE_PROJECT_ID,
                    'baseUrl' => 'http://api.apidae-tourisme.com/',
                ]);

                //afficher un événement en particulier ?
                if (isset($_GET['id'])) {
                    try {

                        $event = $client->getObjectById(['id' => (int) $_GET['id'], 'responseFields' => "@default,ouverture.periodesOuvertures"
                        ]);
                        echo '<div class="row xs-no-row">
                <div class="col-xs-12 col-md-8">
                    <div class="col-xs-12 col-md-1">
                        <div class="row">
                            <div class="bg--cod-gray padding-outer-section--medium offset-bottom--medium">';
                        $dateDebut = strtotime($event['ouverture']['periodesOuvertures'][0]['dateDebut']);
                        $dateDebutAffichJour = date_i18n('d', $dateDebut);
                        $dateDebutAffichMois = date_i18n('m', $dateDebut);
                        $dateFin = strtotime($event['ouverture']['periodesOuvertures'][0]['dateFin']);
                        $dateFinAffichJour = date_i18n('d', $dateFin);
                        $dateFinAffichMois = date_i18n('m', $dateFin);
                        if ($event['ouverture']['periodesOuvertures'][0]['dateFin'] == $event['ouverture']['periodesOuvertures'][0]['dateDebut']) {
                            $dateFinale = 'Le ' . date_i18n('d F Y', strtotime($event['ouverture']['periodesOuvertures'][0]['dateDebut']));
                        } else {
                            $dateFinale = 'Du ' . date_i18n('d F Y', strtotime($event['ouverture']['periodesOuvertures'][0]['dateDebut'])) . ' au ' . date_i18n('d F Y', strtotime($event['ouverture']['periodesOuvertures'][0]['dateDFin']));
                        }

                        echo '</div>
                    </div>
                    </div>
                    <div class="col-xs-12 col-md-11">
                        <!-- TITRE -->
                        <div class="bg--snow padding-outer-section--medium offset-bottom--medium agenda-single-margin-fix">
                            <h1>' . $event['nom']['libelleFr'] . '</h1>
                        </div>
                        <div>
                            ' . $dateFinale . '
                        </div>';
                        echo '<div class="">
                <img class="" src="' . $event['illustrations'][0]['traductionFichiers'][0]['urlDiaporama'] . '" alt="" />
                </div>';
                        echo '<div class="">';
                        echo '<p>' . $event['presentation']['descriptifCourt']['libelleFr'] . '</p>';
                        foreach ($event['informations']['moyensCommunication'] as $coordonnee) {
                            if ($coordonnee['type']['libelleFr'] == 'Mél')
                                echo $coordonnee['type']['libelleFr'] . ' : <a href="mailto:' . $coordonnee['coordonnees']['fr'] . '">' . $coordonnee['coordonnees']['fr'] . '</a><br />';

                            else if ($coordonnee['type']['libelleFr'] == 'Site web (URL)' || $coordonnee['type']['libelleFr'] == 'Page facebook')
                                echo $coordonnee['type']['libelleFr'] . ' : <a href="' . $coordonnee['coordonnees']['fr'] . '" target="_blank">' . $coordonnee['coordonnees']['fr'] . '</a><br />';
                            else
                                echo $coordonnee['type']['libelleFr'] . ' : ' . $coordonnee['coordonnees']['fr'] . '<br />';
                        }
                        echo '</div>';

                        $lng = $event['localisation']['geolocalisation']['geoJson']['coordinates'][0];
                        $lat = $event['localisation']['geolocalisation']['geoJson']['coordinates'][1];
                        $adresse = '';
                        if (!empty($event['localisation']['adresse']['adresse1']))
                            $adresse .= $event['localisation']['adresse']['adresse1'] . '<br />';

                        if (!empty($event['localisation']['adresse']['adresse2']))
                            $adresse .= $event['localisation']['adresse']['adresse2'] . '<br />';

                        if (!empty($event['localisation']['adresse']['adresse3']))
                            $adresse .= $event['localisation']['adresse']['adresse3'] . '<br />';

                        if (!empty($event['localisation']['adresse']['codePostal']))
                            $adresse .= $event['localisation']['adresse']['codePostal'] . '<br />';

                        if (!empty($event['localisation']['adresse']['commune']['nom']))
                            $adresse .= $event['localisation']['adresse']['commune']['nom'] . '<br />';

                        echo '<h3 class="">Localisation</h3>';
                        echo '<div class="">';
                        echo '<div id="map" style="width:100%;height:400px;">
                                    <div class="acf-map">
                                        <div class="marker" data-lat="' . $lat . '" data-lng="' . $lng . '">
                                            <h4>' . $adresse . '</h4>
                                        </div>
                                    </div>
                                </div>';
                    } catch (\Sitra\ApiClient\Exception\SitraException $e) {
                        echo $e->getMessage();
                        echo "\n";
                        echo $e->getPrevious()->getMessage();
                    }
                } else {
                    ?>
                    <div class="row xs-no-row">
                    <?php
                    try {

                        $search = $client->searchDetailedAgenda(['query' => [
                                "selectionIds" => [APIDAE_SELECTION_ID],
                                "dateDebut" => date('Y-m-d'),
                                "count" => 100,
                                "responseFields" => [
                                    "@default", "ouverture.periodesOuvertures"
                                ]
                        ]]);

                        $ids = array();

                        foreach ($search['objetsTouristiques'] as $events) {
                            foreach ($events as $event) {

                                if (!in_array($event['id'], $ids)) {
                                    echo '<div class="col-md-3 col-sm-6 col-xs-12 bandeau-haut-15 card-en-ce-moment">';

                                    if (sizeof($event['illustrations']) > 0 && array_key_exists('illustrations', $event)) {
                                        echo '<div class="img-en-ce-moment">';
                                        if ($event['illustrations'][0]['traductionFichiers'][0]['largeur'] >= $event['illustrations'][0]['traductionFichiers'][0]['hauteur']) {
                                            echo '<img class="img-sorties" src="' . $event['illustrations'][0]['traductionFichiers'][0]['urlFiche'] . '" alt="" style="width: 100%;height: auto" />';
                                        } else {
                                            echo '<img class="img-sorties" src="' . $event['illustrations'][0]['traductionFichiers'][0]['urlFiche'] . '" alt="" style="width: 100%;height: auto" />';
                                        }
                                        echo '</div>';
                                    } else {
                                        $img = content_url() . '/uploads/logos/img_generik.jpg';
                                        echo '<img class="img-sorties" src="' . $img . '" alt="Image pas défaut" style="width: 100%;" />';
                                    }
                                    echo'	<a title="' . $event['nom']['libelleFr'] . '" href="' . get_home_url() . '/en-ce-moment?id=' . $event['id'] . '">';

                                    echo '<div class="col-md-10 col-sm-10 col-xs-10">
                                        <div class="col-xs-10">
                                            <p class="">' . $event['nom']['libelleFr'] . '</p>
                                        </div>
                                        <div class="col-xs-2">
                                            <img class="" src="' . get_bloginfo('template_url') . '/img/arrow.png" alt="">
                                        </div>
                                    </div>';

                                    $ids[] = $event['id'];

                                    echo '</a>';
                                    echo '</div>';
                                }
                            }
                        }
                    } catch (\Sitra\ApiClient\Exception\SitraException $e) {
                        echo $e->getMessage();
                        echo "\n";
                        echo $e->getPrevious()->getMessage();
                    }
                }
                ?>
                </div>
                <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCU4wZUKqOe1iO983YrhYUTfokVAforfVc"></script>
                <script src="<?php bloginfo('template_url'); ?>/js/google_map.js"></script>
            </div>
        </div>
    </div>
</div>