[guest]
echo 'Чат только для зарегистрированных пользователей!!!';
[/guest]
[user]
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <!-- jQuery -->
    <title>Система живого чата</title>
    <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.2/css/font-awesome.min.css'>
    <link href="usr/blocks/chat/css/style.css" rel="stylesheet" id="bootstrap-css">
    <script src="usr/blocks/chat/js/chat.js"></script>
    <style>
        .modal-dialog {
            width: 400px;
            margin: 30px auto;
        }
    </style>

</head>
<body class="">
<div class="container" style="min-height:500px;">
    <div class=''>
    </div>
    <div class="container">';
        if (isset($_SESSION['userid']) && $_SESSION['userid']) {
        echo '<div class="chat">
            <div id="frame">
                <div id="sidepanel">
                    <div id="profile">';
                        $chat = new Chat();
                        $loggedUser = $chat->getUserDetails($_SESSION['userid']);
                        echo '<div class="wrap">';
                            $currentSession = '';
                            foreach ($loggedUser as $user) {
                            $currentSession = $user['current_session'];
                            echo '<img id="profile-img" src="userpics/' . $user['avatar'] . '" class="online" alt=""/>
                            <p>' . $user['username'] . '</p>
                           <i class="fa fa-chevron-down expand-button" aria-hidden="true"></i>
                            <div id="status-options">
                                <ul>
                                    <li id="status-online" class="active"><span class="status-circle"></span>
                                        <p>Онлайн</p></li>
                                    <li id="status-away"><span class="status-circle"></span>
                                        <p>Отошел</p></li>
                                    <li id="status-busy"><span class="status-circle"></span>
                                        <p>Занят</p></li>
                                    <li id="status-offline"><span class="status-circle"></span>
                                        <p>Не в сети</p></li>
                                   </ul>
                            </div>
                            <div id="expanded">
                               <a href="logout.php">Выход</a>
                            </div>';
                            }
                            echo '</div>
                    </div>
                    <div id="search">
                        <label for=""><i class="fa fa-search" aria-hidden="true"></i></label>
                        <label>
                            <input type="text" placeholder="Поиск контактов..."/>
                        </label>
                    </div>
                    <br/>
                    <div id="contacts">
                        <ul>';
                            $chatUsers = $chat->chatUsers($_SESSION['userid']);
                            foreach ($chatUsers as $user) {
                            $status = $user['online'] ? 'online' : 'offline';
                            $activeUser = $user['userid'] == $currentSession ? "active" : '';
                            echo '<li id="' . $user['userid'] . '" class="contact ' . $activeUser . '" data-touserid="' . $user['userid'] . '" data-tousername="' . $user['username'] . '">
                                <div class="wrap"><span id="status_' . $user['userid'] . '" class="contact-status ' . $status . '"></span>
                                   <img src="userpics/' . $user['avatar'] . '" alt=""/>
                                    <div class="meta"><p class="name">' . $user['username'] . '<span id="unread_' . $user['userid'] . '" class="unread">' . $chat->getUnreadMessageCount($user['userid'], $_SESSION['userid']) . '</span>
                                        </p><p class="preview"><span id="isTyping_' . $user['userid'] . '" class="isTyping"></span></p>
                                    </div>
                                </div>
                            </li>';
                            }
                            echo '</ul>
                    </div>
                    <div id="bottom-bar">
                        <button id="addcontact"><i class="fa fa-user-plus fa-fw" aria-hidden="true"></i> <span>Добавить контакт</span>
                        </button>
                        <button id="settings"><i class="fa fa-cog fa-fw" aria-hidden="true"></i>
                            <span>Настройки</span></button>
                    </div>
                </div>
                <div class="content" id="content">
                    <div class="contact-profile" id="userSection">';

                        $userDetails = $chat->getUserDetails($currentSession);
                        foreach ($userDetails as $user) {
                        echo '<img src="userpics/' . $user['avatar'] . '" alt=""/>
                        <p>' . $user['username'] . '</p>
                        <div class="social-media">
                            <i class="fa fa-facebook" aria-hidden="true"></i>
                            <i class="fa fa-twitter" aria-hidden="true"></i>
                          <i class="fa fa-instagram" aria-hidden="true"></i>
                        </div>';
                        }

                        echo'</div>
                    <div class="messages" id="conversation">';
                        $chat->getUserChat($_SESSION['userid'], $currentSession);
                        echo'</div>
                    <div class="message-input" id="replySection">
                        <div class="message-input" id="replyContainer">
                            <div class="wrap">
                                <label for="chatMessage<"></label><input type="text" class="chatMessage" id="chatMessage<"'. $currentSession.'">" placeholder="Напишите свое сообщение..."/>
                                <button class="submit chatButton" id="chatButton<"'. $currentSession.'">" title="Отправить"><i class="fa fa-paper-plane" aria-hidden="true"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>';
        } else {
        echo'<br>
        <br>';
        }
        echo' </div>
    <div class="insert-post-ads1" style="margin-top:20px;">
    </div>
</div>
</body>
</html>


[/user]
