<?php
dbconnect();

$sql = "SELECT * FROM `".USERS_TABLE_NAME."` WHERE user_name='{$_SESSION['user_login']}'";
$stmt = $pdo->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
?>

<!--header start-->
      <header class="header white-bg">
            <div class="toggle-nav">
                <div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"></div>
            </div>

			<!--logo start-->
			<a href="<?php echo HOME_URL ?>">
			<img src="img/logo.png" alt="<?php echo WEB_NAME ?>" />
			</a>
            <!--logo end-->

            <div class="top-nav notification-row">
                <!-- notificatoin dropdown start-->
                <ul class="nav pull-right top-menu">
                    <!-- inbox notificatoin start-->
                    <li id="mail_notificatoin_bar" class="dropdown">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <i class="icon-envelope-l"></i>
                            <span class="badge bg-important">
							<?php
							$nMsgs = $pdo->query("SELECT COUNT(*) FROM `".MSGS_TABLE_NAME."` WHERE msg_rcvr='{$_SESSION['user_acc']}' AND msg_read='0'")->fetchColumn(); 
							echo $nMsgs;
							?>
							</span>
                        </a>
                        <ul class="dropdown-menu extended inbox">
                            <div class="notify-arrow notify-arrow-blue"></div>
                            <li>
                                <p class="blue">You have <?php echo $nMsgs; ?> new messages</p>
                            </li>
							
							<?php
								$msgs = recent_msgs($_SESSION['user_acc'], '0');
								foreach($msgs as $key)
								{ 
								echo '
								<li>
								<a href="message-details.php?msgid='.$key['msg_id'].'&acc='.$key['msg_rcvr'].'">
									<span class="subject">
									<span class="from">'.$key['msg_sender'].'</span>
                                    <span class="time">'.date('j/m/Y', strtotime($key['msg_date'])).'</span>
                                    </span>
									<span class="message">
                                        '.$key['msg_subject'].'
                                    </span>
                                </a>
								</li>
								';
								}
							?>      
                            
                            <li>
                                <a href="messages.php">See all messages</a>
                            </li>
                        </ul>
                    </li>
                    <!-- inbox notificatoin end -->
                    <!-- alert notification start-->
                    <li id="alert_notificatoin_bar" class="dropdown">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">

                            <i class="icon-bell-l"></i>
                            <span class="badge bg-important">
							<?php
							$nAlrts = $pdo->query("SELECT COUNT(*) FROM `".ALERT_TABLE_NAME."` WHERE alrt_rcvr='{$_SESSION['user_acc']}' AND alrt_read='0'")->fetchColumn(); 
							echo $nAlrts;
							?>
							</span>
                        </a>
                        <ul class="dropdown-menu extended notification">
                            <div class="notify-arrow notify-arrow-blue"></div>
                            <li>
                                <p class="blue">You have <?php echo $nAlrts; ?> new alerts</p>
                            </li>
							<?php
								$alrts = recent_alrts($_SESSION['user_acc'], '0');
								foreach($alrts as $key)
								{ 
								echo '
								<li>
								<a href="alerts.php">
									<span class="label label-danger"><i class="icon-warning-sign"></i></span>
									'.$key['alrt_subject'].'
									<span class="small italic pull-right">'.date('j/m/Y', strtotime($key['alrt_date'])).'</span>
                                </a>
								</li>
								';
								}
							?>                           
                            <li>
                                <a href="alerts.php">See all alerts</a>
                            </li>
                        </ul>
                    </li>
                    <!-- alert notification end-->
                    <!-- user login dropdown start-->
                    <li class="dropdown">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="profile-ava">
                                <img width="29" height="29" alt="<?php echo $row['first_name']; ?> <?php echo $row['last_name']; ?>" src="users/<?php echo user_photo(preg_replace('/\s/', '', $_SESSION['user_login'])); ?>">
                            </span>
                            <span class="username"><?php echo $row['first_name']; ?> <?php echo $row['last_name']; ?></span>
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu extended logout">
                            <div class="log-arrow-up"></div>
                            <li class="eborder-top">
								<a href="dashboard.php"><i class="icon-briefcase"></i> My Account</a>
							</li>
							<li>
								<a href="profile.php"><i class="icon-user"></i> My Profile</a>
							</li>
							<li>
								<a href="messages.php"><i class="icon-envelope"></i> My Messages</a>
							</li>
							<li>
								<a href="password.php"><i class="icon-lock"></i> Change Password</a>
							</li>
							<li>
								<a href="pin.php"><i class="icon-key"></i> Change PIN</a>
							</li>
							<li>
								<a href="signout.php"><i class="icon-key"></i> Sign Out</a>
							</li>
                        </ul>
                    </li>
                    <!-- user login dropdown end -->
                </ul>
                <!-- notificatoin dropdown end-->
            </div>
      </header>      
      <!--header end-->