<?php

if ($this->editmode){
    echo '<style>h6{font-weight: bold; margin-top:20px}</style>';

    echo '<h6>cta</h6>';
    echo $this->input('cta');

    echo '<h6>heures-ouverture</h6>';
    echo $this->input('heures-ouverture');

    echo '<h6>respect-charte</h6>';
    echo $this->input('respect-charte');

    echo '<h6>temoignages</h6>';
    echo  $this->input('temoignages');

    echo '<h6>temoignage-positif</h6>';
    echo $this->input('temoignage-positif');

    echo '<h6>temoignages-positifs</h6>';
    echo $this->input('temoignages-positifs');

    echo '<h6>temoignage-non-classe</h6>';
    echo $this->input('temoignage-non-classe');

    echo '<h6>temoignages-non-classes</h6>';
    echo $this->input('temoignages-non-classes');

    echo '<h6>temoignage-negatif</h6>';
    echo $this->input('temoignage-negatif');

    echo '<h6>temoignages-negatifs</h6>';
    echo $this->input('temoignages-negatifs');

    return;
}

$agency = $this->agency;

$this->headTitle('RealAdvice | ' . $agency->getName() . ' | Comments');
$this->headLink()->appendStylesheet('/website/views/layouts/css/nps.css');
$this->headScript()->appendFile('https://maps.googleapis.com/maps/api/js?sensor=false&language=fr');
$this->headScript()->appendFile('/pimcore/static/css/fontello.css');

?>

<?php if($agency->getDashboard_token() == '') {?>

    <div id="fb-root"></div>
    <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v2.5&appId=1476466219304155";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    </script>

    <div class="comment-report">
        <div class="report-header">
            <div class="container">
                <div class="header-block agency-logo">
                    <img src="<?=$agency->getLogoUrl() ?>" alt="">
                </div>
                <div class="coord header-block">
                    <table>
                        <?php if($agency->getAddress() != '') { ?>
                            <tr>
                                <td><i class="icon-home"></i></td>
                                <td id="address"><?= $agency->getAddress() ?><br><?= $agency->getCp() ?> <?= $agency->getCity() ?></td>
                            </tr>
                        <?php } if($agency->getPhone() != "") { ?>
                        <tr>
                            <td><i class="icon-phone"></i></td>
                            <td><?= $agency->getPhone() ?></td>
                        </tr>
                        <?php } if($agency->getEmail() != "") { ?>
                        <tr>
                            <td><i class="icon-mail"></i></td>
                            <td><?= $agency->getEmail() ?></td>
                        </tr>
                        <?php } if($agency->getWebsite() != "") { ?>
                        <tr>
                            <td><i class="icon-globe"></i></td>
                            <td><a target="_blank" href="<?= $agency->getWebsite() ?>">Website</a></td>
                        </tr>
                        <?php } ?>
                    </table><!--

                --><div class="widget"><?= \Website\Tool\RealAdvice::getWidget($agency, $this) ?></div>

                </div>

                <hr>
                <h2 itemprop="name"><?= $agency->getName() ?></h2>
                <div class="rating"><?= $this->partial('/public/partial/fancy-stars.php', array("quote" => $agency->getNps()*2)) ?></div>
                <div class="social">
                    <?php if(!is_null($agency->getFacebook()) && $agency->getFacebook() != "" ){
                        echo '<div class="fb-share-button" data-href="'. $agency->getFacebook() .'" data-layout="button"></div>'  ;
                        echo '<div class="fb-like" data-href="'. $agency->getFacebook() .'" data-show-faces="false" data-layout="button"></div>';
                    } ?>

                    <?php if(!is_null($agency->getLinkedin()) && $agency->getLinkedin() != "" ){
                        echo '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: fr_FR</script>';
                        echo '<script type="IN/Share" data-url="'. $agency->getLinkedin() .'"></script>';
                    }?>

                    <?php if(!is_null($agency->getTwitter()) && $agency->getTwitter() != "" ){ ?>
                        <a href="<?= $agency->getTwitter() ?>" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow</a>
                        <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
                    <?php }?>
                </div>

                <div class="v-spacer"></div>
                <div class="description"  itemprop="description" ><?= $agency->getLocalisedLongDescription($this->lang) ?></div>

                <?php if(!is_null($agency->getSeerus_key()) || ! $agency->getSeerus_key() == ''  ) { ?>
                <a href="#openModal" class="bt cta icon-phone" id="cta"><?= $this->input('cta') ?></a>
                <?php } ?>

                <hr>

                <div class="opening-hours">
                    <div class="title icon-clock"><?= $this->input('heures-ouverture') ?></div>
                    <div class="part1"><?= $this->partial('/public/partial/opening-hours.php', array('agency' => $agency, 'days' => array('monday','thuesday' , 'wednesday' ,'thursday'))) ?></div>
                    <div class="part2"><?= $this->partial('/public/partial/opening-hours.php', array('agency' => $agency, 'days' => array('friday','saturday' , 'sunday'))) ?></div>
                </div>

            </div>
        </div>
        <div class="comment-box container">

            <!--<div class="certification">
                <img src="/website/views/layouts/images/certification.png" alt="">
                <p><?/*= $this->input('respect-charte') */?></p>
            </div>

            <hr class="clear">
            -->
            <div class="comment-box-header">

                <div class="filter">
                    <?php
                        $filters = array("positive" => 0, "negative" => 0, "neutral" => 0);
                        foreach ($agency->getComments() as $c){
                            if ($c->getQuote() < 5) $filters["negative"] += 1;
                            elseif ($c->getQuote() > 7) $filters["positive"] += 1;
                            else $filters["neutral"] += 1;
                        }
                    ?>
                        <span class="filter negative"><i class="icon-frown"></i><span><?= $filters["negative"] ?> <?= ($filters["negative"] > 1)?$this->input('temoignages-negatifs'):$this->input('temoignage-negatif') ?></span></span>
                        <span class="filter neutral"><i class="icon-meh"></i><span><?= $filters["neutral"] ?>  <?= ($filters["neutral"] > 1)?$this->input('temoignages-non-classes'):$this->input('temoignage-non-classe') ?></span></span>
                        <span class="filter positive"><i class="icon-smile"></i><span><?= $filters["positive"] ?> <?= ($filters["positive"] > 1)?$this->input('temoignages-positifs'):$this->input('temoignage-positif') ?></span></span>


                </div>
                <h2><?= $this->input('temoignages') ?></h2>
                <div class="v-spacer"></div>
            </div>
            <!--<table class="comments">-->

                <?php

                if (!$this->editmode) foreach($agency->getComments() as $c) {
                    $mood = ($c->getQuote() > 7) ? 'positive' : (($c->getQuote() < 5) ? 'negative' : 'neutral');
                ?>

                    <div class="comment <?= $mood ?>">

                        <div class="comment-header"><span class="date"><?= $c->getDateFormat('d/m/Y') ?></span></div>
                        <div class="comment-body">
                            <img src="/website/views/layouts/images/profil.png" alt="">
                            <div class="quote"><?= $this->partial('/public/partial/fancy-stars.php', array('quote' => ($c->getQuote()))) ?></div>
                            <div class="texte"><?= $c->getText() ?></div>
                            <div class="clear"></div>
                        </div>
                    </div>


                <?php } ?>
        </div>
        <div id="map"></div>

    </div>

    <?php if(!is_null($agency->getSeerus_key()) || ! $agency->getSeerus_key() == ''  ) { ?>

    <div id="openModal" class="modalbg">
        <div class="dialog">
            <form action="/ajax/be-contacted" id="get_contacted" method="post">
                <a id="close" class="close" title="Close" href="#close">X</a>
                <h3>Demandez à l'agence de vous recontacter</h3>
                <input type="text" placeholder="Nom" name="name">
                <input type="text" placeholder="Prénom" name="surname">
                <input type="text" placeholder="Email" name="email">
                <input type="text" placeholder="Téléphone" name="phone">
                <input type="hidden" value="<?= $this->lang ?>" name="lang">
                <input type="hidden" value="<?=$agency->getUid() ?>" name="uid">
                <select name="subject" id="">
                    <option value="0">Je souhaite être recontacté(e) concernant:</option>
                    <option value="1">la location d'un bien</option>
                    <option value="2">l' achat d'un bien</option>
                    <option value="3">la mise en location d'un bien</option>
                    <option value="4">la  mise en vente d'un bien</option>
                    <option value="5">la mise en gestion locative d'un bien</option>
                    <option value="6">L'estimation de la valeur locative ou vénale d'un bien</option>
                    <option value="7 ">autre</option>
                </select>
                <textarea name="message" id="" cols="30" rows="10">Message</textarea>
                <input type="submit" value="Envoyer à l'agence">
                <div class="clear"></div>
            </form>
        </div>
    </div>

    <script>
        $('form#get_contacted').submit(function(event){
            event.preventDefault();

            var form = event.target,
                fd = new FormData( form );

            $.ajax({
                url : form.action,
                type : 'POST',
                data : $(this).serialize(),
                success : function(response){
                    document.location.href='#close';
                }
            });

            return false;
        });
    </script>

    <?php } ?>

    <?= $this->partial('/public/partial/schema.php', array("agency" => $agency)) ?>


    <script type="text/javascript">
        var geocoder;
        var map;
        // initialisation de la carte Google Map de départ
        function initialiserCarte() {
            geocoder = new google.maps.Geocoder();
            // Ici j'ai mis la latitude et longitude du vieux Port de Marseille pour centrer la carte de départ
            var latlng = new google.maps.LatLng(50.6375022,4.6626637);
            var mapOptions = {
                zoom      : 7,
                center    : latlng,
                mapTypeId : google.maps.MapTypeId.ROADMAP
            }
            // map-canvas est le conteneur HTML de la carte Google Map
            map = new google.maps.Map(document.getElementById('map'), mapOptions);
            TrouverAdresse();
        };

        function TrouverAdresse() {
            // Récupération de l'adresse tapée dans le formulaire
            var adresse = $('#address').html().replace('<br>', ' ');
            geocoder.geocode( { 'address': adresse}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    map.setZoom(14);
                    // Création du marqueur du lieu (épingle)
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                } else {
                    document.getElementById('map').style.display = 'none' ;
                }
            });
        }
        // Lancement de la construction de la carte google map
        google.maps.event.addDomListener(window, 'load', initialiserCarte);

    </script>

    <script>
        $('.filter').click(function(){
            if( $(this).hasClass('positive') ) {
                $('.comment.positive').show();
                $('.comment.negative').hide();
                $('.comment.neutral').hide();
                $('.filter.positive').addClass('active');
                $('.filter.neutral').removeClass('active');
                $('.filter.negative').removeClass('active');

            }else if( $(this).hasClass('neutral') ){
                $('.comment.neutral').show();
                $('.comment.negative').hide();
                $('.comment.positive').hide();
                $('.filter.neutral').addClass('active');
                $('.filter.positive').removeClass('active');
                $('.filter.negative').removeClass('active');
            }else if( $(this).hasClass('negative') ){
                $('.comment.negative').show();
                $('.comment.neutral').hide();
                $('.comment.positive').hide();
                $('.filter.negative').addClass('active');
                $('.filter.positive').removeClass('active');
                $('.filter.neutral').removeClass('active');
            }
        });
    </script>

<?php } else {?>

    <iframe src="http://www.seerus.com/fr/restitution/aGiDs6xILsIO2W40eoz7" frameborder="0" style="width: 100%; height: 5000px" id="iframe1" onLoad="autoResize('iframe1');"></iframe>


<?php } ?>
