<?php $ci = get_instance();?>
<header class="top-head container-fluid">
	<button type="button" onClick="menu_collapse();" class="navbar-toggle pull-left">
		<span class="sr-only">Toggle navigation</span>
		<span class="icon-bar"></span>
		<span class="icon-bar"></span>
		<span class="icon-bar"></span>
	</button>
	
	<!-- Count Down Modal -->
	<div id="count_down_modal" class="modal fade" style="z-index: 9999;" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
		<div id="countdown_message_dialog" class="modal-dialog" style="width: 300px;">
			<div class="modal-content">
				<div class="modal-header">
					<h3 class="panel-title" style="color: #cb2a2a;"><i class="fa fa-exclamation-triangle"></i> Reminder</h3> 
				</div>
				<div class="modal-body"> 
					<p>Your session is about to expire.</p>
					<p>You will be logged out in <strong id="timer" style="font-size: 20px;"></strong> seconds.<p>
				</div>
			</div>
		</div>
	</div>
	<!--  -->
	
	<ul class="list-inline navbar-right top-menu top-right-menu pull-right">
<!--		<li class="dropdown">-->
<!--			<a data-toggle="dropdown" class="dropdown-toggle" href="#">-->
<!--				<i class="fa fa-envelope-o "></i>-->
<!--				<span class="badge badge-sm up bg-purple count">4</span>-->
<!--			</a>-->
<!--			<ul class="dropdown-menu extended fadeInUp animated nicescroll" tabindex="5001">-->
<!--				<li>-->
<!--					<p>Messages</p>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><img src="img/avatar-2.jpg" class="img-circle thumb-sm m-r-15" alt="img"></span>-->
<!--						<span class="block"><strong>John smith</strong></span>-->
<!--						<span class="media-body block">New tasks needs to be done<br><small class="text-muted">10 seconds ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><img src="img/avatar-3.jpg" class="img-circle thumb-sm m-r-15" alt="img"></span>-->
<!--						<span class="block"><strong>John smith</strong></span>-->
<!--						<span class="media-body block">New tasks needs to be done<br><small class="text-muted">3 minutes ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><img src="img/avatar-4.jpg" class="img-circle thumb-sm m-r-15" alt="img"></span>-->
<!--						<span class="block"><strong>John smith</strong></span>-->
<!--						<span class="media-body block">New tasks needs to be done<br><small class="text-muted">10 minutes ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				<li>-->
<!--					<p><a href="inbox.html" class="text-right">See all Messages</a></p>-->
<!--				</li>-->
<!--			</ul>-->
<!--		</li>-->
<!--		<li class="dropdown">-->
<!--			<a data-toggle="dropdown" class="dropdown-toggle" href="#">-->
<!--				<i class="fa fa-bell-o"></i>-->
<!--				<span class="badge badge-sm up bg-pink count">3</span>-->
<!--			</a>-->
<!--			<ul class="dropdown-menu extended fadeInUp animated nicescroll" tabindex="5002">-->
<!--				<li class="noti-header">-->
<!--					<p>Notifications</p>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><i class="fa fa-user-plus fa-2x text-info"></i></span>-->
<!--						<span>New user registered<br><small class="text-muted">5 minutes ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><i class="fa fa-diamond fa-2x text-primary"></i></span>-->
<!--						<span>Use animate.css<br><small class="text-muted">5 minutes ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				<li>-->
<!--					<a href="#">-->
<!--						<span class="pull-left"><i class="fa fa-bell-o fa-2x text-danger"></i></span>-->
<!--						<span>Send project demo files to client<br><small class="text-muted">1 hour ago</small></span>-->
<!--					</a>-->
<!--				</li>-->
<!--				-->
<!--				<li>-->
<!--					<p><a href="#" class="text-right">See all notifications</a></p>-->
<!--				</li>-->
<!--			</ul>-->
<!--		</li>-->
		
		<li class="dropdown text-center">
			<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<!--				<img alt="" src="<?php echo base_url("assets/img/avatar.jpg");?>" class="img-circle profile-img thumb-sm">-->
				<span class="username" style="max-width: 155px; white-space: nowrap; text-align: right; display: inline-block; overflow: hidden !important; text-overflow: ellipsis; margin-right: 5px;">
					<?php 
						$user = $ci->fm->get_current_user();
						
						if($user != NULL){
							echo $user->NAME;
						}
						else{
							redirect(base_url("logout"));
						}
					?>
				</span>
				<span class="fa fa-caret-down"></span>
			</a>
			<ul class="dropdown-menu extended pro-menu fadeInUp animated" tabindex="5003" style="overflow: hidden; outline: none; left: auto; right: 0;">
				<li>
					<a href="<?php echo base_url("profile");?>">
						<i class="fa fa-user fa-fw"></i>
						Profile
					</a>
				</li>
				<li>
					<a href="<?php echo base_url("logout?by_user=1");?>">
						<i class="fa fa-sign-out fa-fw"></i>
						Sign Out
					</a>
				</li>
			</ul>
		</li>
	</ul>
</header>

<script type="text/javascript">
	//Interval checking -----
	setInterval(function(){
		$.ajax({
            type: "POST",
            url: "<?php echo base_url("api/check_inactive");?>",
            data: {},
            success: function(result, status, xhr){
            	if(result == 1){
                    $.ajax({
			            type: "POST",
			            url: "<?php echo base_url("api/force_logout");?>",
			            data: {},
			            success: function(result, status, xhr){
			            	window.location.href = "<?php echo base_url();?>";
			            },
			            error: function(xhr,status,error){},
			            complete: function(xhr,status){},
			        });
                }
            },
            error: function(xhr,status,error){
            	//alert("Lost connection.");
            	$("#lost_connection_modal").modal("show");
            },
            complete: function(xhr,status){},
        });
	}, 1000);//1 secs
	//-------------------
</script>