<?php
$date = implode("/", array_reverse(explode("-", $ad->getDate())));
?>
<p>
    <a href="?mod=annonce">&lt; retour à la liste des annonces sauvegardées</a> |
    <a href="?mod=annonce&amp;a=form-delete&amp;id=<?php echo $ad->getId(); ?>&amp;r=view"
        title="Supprimer l'annonce"><span class="fa fa-times"></span> supprimer l'annonce</a>
</p>

<h2>
    <?php if ($ad->isOnline()) : ?>
    <span class="status status-online">En ligne</span>
    <?php else: ?>
    <span class="status status-offline">Hors ligne</span>
    <?php endif; ?>
    <?php echo htmlspecialchars($ad->getTitle()); ?>
    <a href="<?php echo $ad->getLink(); ?>"
        target="_blank"
        title="Ouvrir sur <?php echo $ad_config->getOption("site_name");
        ?>"><span class="fa fa-external-link"></span></a>
</h2>
<div class="annonce">
    <div class="annonce-data">
        <ul>
            <li class="annonce-data-line">
                <span class="annonce-label">Auteur</span><span
                    class="annonce-value"><?php echo $ad->getAuthor(); ?></span>
            </li>
            <?php if ($value = $ad->getPrice()) : ?>
            <li class="annonce-data-line">
                <span class="annonce-label">Prix</span><span
                    class="annonce-value"><?php
                    echo number_format($value, 0, ",", " ")." ";
                    echo htmlspecialchars($ad->getCurrency());
                ?></span>
            </li>
            <?php endif; ?>
            <li class="annonce-data-line">
                <span class="annonce-label">Date</span><span
                    class="annonce-value"><?php
                    echo $date; ?></span>
            </li>
            <li class="annonce-data-line">
                <span class="annonce-label">Catégorie</span><span
                    class="annonce-value"><?php
                    echo htmlspecialchars($ad->getCategory()); ?></span>
            </li>
            <?php if ($value = $ad->getCity()) : ?>
            <li class="annonce-data-line">
                <span class="annonce-label">Ville</span><span
                    class="annonce-value">
                    <?php echo htmlspecialchars($ad->getZipCode()); ?>
                    <?php echo htmlspecialchars($value); ?>
                </span>
            </li>
            <?php endif; ?>

            <?php foreach ($ad->getProperties() AS $name => $value) : ?>
            <?php if ($value) : ?>
            <li class="annonce-data-line">
                <span class="annonce-label"><?php echo htmlspecialchars($name); ?></span><span
                    class="annonce-value">
                    <?php echo htmlspecialchars($value); ?>
                </span>
            </li>
            <?php endif; ?>
            <?php endforeach; ?>
        </ul>
        <div class="annonce-description">
            <span class="annonce-label">Description</span>
            <p><?php
                echo nl2br(htmlspecialchars($ad->getDescription())); ?></p>
        </div>
        <div class="annonce-comment">
            <span class="annonce-label">Note</span>
            <div>
                <p><?php echo nl2br(htmlspecialchars($note = $ad->getComment())); ?></p>
                <p><a href="?mod=annonce&amp;a=form-comment&amp;id=<?php echo $ad->getId(); ?>"
                    class="button">
                    <?php if (!$note) : ?>
                    Ajouter une note
                    <?php else: ?>
                    Modifier la note
                    <?php endif; ?>
                </a></p>
            </div>
        </div>
        <div id="tags" class="annonce-tags">
            <span class="annonce-label">Tags</span>
            <div>
                <?php foreach ($ad->getTags() AS $tag) : ?>
                <span class="annonce-tag">
                    <a href="?mod=annonce&amp;a=tag-delete&amp;id=<?php
                        echo $ad->getId(); ?>&amp;tag=<?php
                        echo htmlspecialchars($tag); ?>"
                       title="Supprimer ce tag"><span class="fa fa-times"></span></a>
                    <?php echo htmlspecialchars($tag); ?>
                </span>
                <?php endforeach; ?>

                <form action="?mod=annonce&amp;a=tag-add&amp;id=<?php
                        echo $ad->getId(); ?>" method="POST">
                    <p>
                        <input type="text" name="tags" value="" placeholder="Ajouter des tags (séparé par des virgules) ..." />
                        <input type="submit" value="Ajouter" />
                    </p>
                </form>
            </div>
        </div>
    </div>
    <?php $photos = $ad->getPhotos(); ?>
    <div class="annonce-photos">
        <?php foreach ($photos AS $photo) : ?>
        <div class="annonce-photo">
            <a href="<?php echo $adPhoto->getPublicDestination($photo["local"]);
                ?>" target="_blank"><img
                src="<?php echo $adPhoto->getPublicDestination($photo["local"]); ?>"
                alt="" class="annonce-photo-img" /></a>
        </div>
        <?php endforeach; ?>
    </div>
</div>
