<?php

$query = $db->prepare("SELECT * FROM `tickets` WHERE user_id = ? ORDER BY ticket_id DESC");

$query->execute([session("user_id")]);

$tickets = $query->fetchAll(PDO::FETCH_ASSOC);

foreach ($tickets as $ticket) {
	if ($ticket['client_read'] == 0 && $ticket['client_read'] != null) {
		$unread++;							
	}
}
$date = time();
$query = $db->prepare("UPDATE `users` SET last_date = $date WHERE user_id = ?");
$query->execute([session("user_id")]);
?>

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <?php if(@$meta): ?>
	<title><?php if($meta['title']): ?><?=$meta['title']?><?php else: ?>{PAGE_TITLE} | {SITE_TITLE}<?php endif; ?></title>
	<meta name="description" content="<?php if($meta['desc']): ?><?=$meta['desc']?><?php else: ?>{SITE_DESC}<?php endif; ?>"/>
	<meta name="keywords" content="<?php if($meta['keyw']): ?><?=$meta['keyw']?><?php else: ?>{SITE_KEYW}<?php endif; ?>"/>	
	<?php else: ?>
	<title>{PAGE_TITLE} | {SITE_TITLE}</title>
	<meta name="description" content="{SITE_DESC}"/>
	<meta name="keywords" content="{SITE_KEYW}"/>
	<?php endif; ?>

	<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>

	<meta name="msapplication-TileColor" content="#206bc4"/>

	<meta name="theme-color" content="#206bc4"/>

	<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>

	<meta name="apple-mobile-web-app-capable" content="yes"/>

	<meta name="mobile-web-app-capable" content="yes"/>

	<meta name="HandheldFriendly" content="True"/>

	<meta name="MobileOptimized" content="320"/>

	<link rel="shortcut icon" href="{SITE_FAVO}" />

	<link rel="apple-touch-icon-precomposed" href="{SITE_FAVO}" />

    <link rel="canonical" href="https://getbootstrap.com/docs/3.3/examples/navbar-fixed-top/">

	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">

	<link rel="stylesheet" href="<?=theme("assets/css/panelcss.css");?>?v=<?=time()?>">

	<link rel="stylesheet" href="<?=public_url("system/css/alertify.css");?>">

	<script src="https://www.google.com/recaptcha/api.js" async defer></script>



    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->

    <!--[if lt IE 9]>

      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>

      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

    <![endif]-->



    <?= htmlspecialchars_decode($settings['header_code']); ?>



	<script type="text/javascript">

		var _url = "{LINK_POST}";

	</script>



	<style>

		.hide{

			display:none;

		}

	</style>



  </head>



  <body>



    <!-- Fixed navbar -->

    <nav class="navbar navbar-default">

      <div class="container-fluid">

        <div class="navbar-header">

          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">

            <span class="sr-only">Toggle navigation</span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

          </button>

          	<a class="navbar-brand" href="{LINK_HOMEPAGE}" style="padding-top:0;">

          		<img src="{SITE_DARKLOGO}" height="50" style="margin-top:0;">

      		</a>

        </div>

        <div id="navbar" class="navbar-collapse collapse">

          	<?php if(session('user_id')): ?>

          	<ul class="nav navbar-nav">

	            <?php foreach($mainmenus as $row): if($row['menu_type'] == 1):?>
	            
	                <?php
                        if($row['menu_link'] == "tickets"){
                            if ($unread > 0) {
							echo '<li><a href="{LINK_TICKETS}">
										<i style="color:#dc123c;" class="align-middle fas fa-ticket-alt"></i> <span style="color:#dc123c;" class="align-middle">{NAVBAR_TICKETS} <span style="background: #dc123c;color: #fff;padding: 2px 8px;border-radius: 10px;font-weight: bold;text-align: center;margin: auto;">'.$unread.'</span></span>
									</a></li>';
						    }else{
							echo '<li>
									<a href="{LINK_TICKETS}">
										<i class="align-middle fas fa-ticket-alt"></i> <span class="align-middle">{NAVBAR_TICKETS} </span>
									</a>
								  </li>';
						    }
                        }else{ ?>
	            	<li><a href="<?=isset($siteLinks[$row['menu_link']]['url']) ? $siteLinks[$row['menu_link']]['url'] : $row['menu_link'] ?>"><i class="align-middle <?=$row['menu_icon']?>"></i> <?=$row['menu_title']?></a></li>
	            	<?php } ?>
	            	
				<?php endif; endforeach; ?>

          	</ul>

            <?php endif; ?>

          	<ul class="nav navbar-nav navbar-right">

          		<?php if(session('user_id')): ?>

          		<li><a><span class="badge">{USER_BALANCE} <?=CURRENCY_SYMBOL?></span></a></li>

	            <li><a href="{LINK_ACCOUNT}">{MY_ACCOUNT}</a></li>

	            <li><a href="{LINK_LOGOUT}">{LOGOUT_TITLE}</a></li>

	            <?php else: ?>
	            
	            <?php foreach($mainmenus as $row): if($row['menu_type'] == 2):?>
	            	<li><a href="<?=isset($siteLinks[$row['menu_link']]['url']) ? $siteLinks[$row['menu_link']]['url'] : $row['menu_link'] ?>"><i class="<?=$row['menu_icon']?>"></i> <?=$row['menu_title']?></a></li>
				<?php endif; endforeach; ?>

	            <?php endif; ?>

          	</ul>

        </div><!--/.nav-collapse -->

      </div>

    </nav>