<?php
include_once "header.php";

$db = new Db();
$destinationId = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
$rows = $db->select("SELECT `Name`,`Description` FROM `destinations` WHERE `Id`=" . $destinationId);
$exists = false;
if ($rows) {
    $exists = true;
    $destinationName = filter_var($rows[0]["Name"],FILTER_SANITIZE_STRING);
    $destinationDescription = filter_var($rows[0]["Description"],FILTER_SANITIZE_STRING);
}
?>
<!-- Main -->
<div id="main-wrapper">
    <div class="container">
        <div class="row 200%">
            <div class="4u 12u(medium)">
                <?php
                if ($exists) {
                    include_once "sidebar-destination.php";
                } else {
                    include_once "sidebar.php";
                }
                ?>
            </div>
            <div class="8u 12u(medium) important(medium)">
                <div id="content">

                    <!-- Content -->
                    <article>
                        <?php if ($exists) { ?>
                            <h2><?php echo $destinationName; ?></h2>
                            <?php echo $destinationDescription; ?>
                            <br><br>
                            <h3>List of restaurants:</h3>
                            <?php
                            $db = new Db();
                            $rows = $db->select("SELECT `Id`,`Name`,`imageURL`,`Recommended` FROM `restaurants` WHERE `destinationId`=" . filter_var($destinationId,FILTER_SANITIZE_NUMBER_INT) . " ORDER BY name ASC");
                            ?>
                            <div class="container">
                                <?php
                                foreach ($rows as $row) {
                                    echo $classFunctions->getGrid($row, 'restaurant');
                                }
                                ?>
                            </div>
                        <?php } else { ?>
                            <h2>Not found</h2>
                            Destination was not found!
                        <?php } ?>



                    </article>

                </div>
            </div>
        </div>
    </div>
</div>
<?php
include_once "footer.php";
?>