<?php
require_once("db/functions.php");
require_once("db/db-const.php");

$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
    echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
    exit();
}

$unreadMessages = array_values(mysqli_fetch_array($mysqli->query("SELECT COUNT(*) as total FROM messages where isRead=0")))[0];
$allMessages = array_values(mysqli_fetch_array($mysqli->query("SELECT COUNT(*) as total FROM messages")))[0];


?>


<section class="menu-section">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="navbar-collapse collapse ">
                    <ul id="menu-top" class="nav navbar-nav navbar-right">
                        <li><a href="index.php">Accueil</a></li>

                        <?php
                        if (logged_in() == true) { ?>
                               <li><a href="messages.php">Messages  <span class="badge"><?=$unreadMessages.' / '.$allMessages?></span></a></li>
                        <?php } ?>

                        <!--li><a href="images.php">Photothèques</a></li-->

                        <li>
                            <a href="#" class="dropdown-toggle" id="ddlmenuItem" data-toggle="dropdown">Photothèques <i
                                        class="fa fa-angle-down"></i></a>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="ddlmenuItem">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="organes.php"> › Par organe</a>
                                </li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="pathologie.php"> › Par pathologie</a></li>
                                <?php
                                if (logged_in() == true) { ?>
                                    <li><a href="upload.php"> › Transférer des photos</a></li>
                                <?php } ?>
                            </ul>
                        </li>

                        <!-- Presentation -->
                        <?php
                        if (logged_in() == true) { ?>
                        <li>
                            <a href="#" class="dropdown-toggle" id="ddlmenuItem" data-toggle="dropdown">Presentations <i
                                        class="fa fa-angle-down"></i></a>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="ddlmenuItem">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="presentations.php"> › liste des presentations</a></li>
                                <li><a href="uploadP.php"> › Transférer une presentation</a></li>

                            </ul>
                        </li>
                        <?php } ?>


                        <li><a href="contact.php">Nous contacter</a></li>

                        <!--li><a href="form.html">FORMS</a></li>
                        <li>
                            <a href="#" class="dropdown-toggle" id="ddlmenuItem" data-toggle="dropdown">UI ELEMENTS <i
                                        class="fa fa-angle-down"></i></a>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="ddlmenuItem">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="ui.html">UI ELEMENTS</a>
                                </li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">EXAMPLE LINK</a></li>
                            </ul>
                        </li>
                        <li><a href="tab.html">TABS & PANELS</a></li>
                        <li><a href="table.html">TABLES</a></li>
                        <li><a href="index.php" class="menu-top-active">BLANK PAGE</a></li-->

                    </ul>
                </div>
            </div>

        </div>
    </div>
</section>